I have a script which type is="text/x-tmpl"
This script generates the rows and columns into the tbody.
What I try to do is to create a column which have a input to show the number of row of each item.
example:
row 1: thumbnail - Filename - 1
row 2: thumbnail - Filenaem - 2
...
...
I want that the user can change his row number.
The problem is that always show "0".
Here is the code:
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade">
<td><input type="text" value="{%=[i]%}"></td> /**My input to show the number of row**/
</tr>
{% } %}
Related
I am dynamically creating SQLs for each table via macro.Details of column and table name is stored in a seed file.
select table,
columns,
flag
from {{ file }}
I am using run_query to execute the above query and assigning it to a list.
{%- set results = run_query(query) -%}
{%- if execute -%}
{%- set table_names,columns,flag = [results.columns[0],results.columns[1],results.columns[2]] -%}
{%- endif -%}
Depending on the column flag, I have to group the CTEs and create two union CTEs separately:
flag_true as ( select * from tab1
union
select * from tab2) ,
flag_false as ( select * from tab3
union
select * from tab4)
I tried the below code but the problem is since my table_names loop have all flag values both true and false there is an extra union coming in the end.
I am unable to figure out a way to reduce the loop to only tables having flag == true.
flag_true as (
{% for tab_name in table_names %}
{%- if flag[loop.index-1] %}
select * from {{tab_name}} {% if not loop.last %}union{% endif %}
{% endif %}
{% endfor %}
),
By creating your three lists table_names, columns and flag, based on your table columns, you are complicating the matter, as you are later treating them back as rows.
A better approach would be to filter your rows based on an attribute value, and this could be achieved with the selectattr filter or its opposite, rejectattr filter.
I believe you can use those filters on agate.Table.rows, and since run_query returns a Table object, on results.rows, in your code.
So, something like:
{%- set results = run_query(query) -%}
{%- if execute -%}
{%- set rows = results.rows -%}
{%- endif -%}
flag_true as (
{% for row in rows | selectattr('flag') %}
select * from {{ row.table }} {% if not loop.last %}union{% endif %}
{% endif %}
% endfor %}
),
flag_false as (
{% for row in rows | rejectattr('flag') %}
select * from {{ row.table }} {% if not loop.last %}union{% endif %}
{% endif %}
)
I want to create a table in DokuWiki which has two rows.
On the left side is a code block (old code), and on the right side there is an other code block (new code).
How to format this in dokuwiki?
If it would be html, it would be easy:
<table>
<tr>
<td>
<pre>
...
</pre>
</td>
<td>
<pre>
...
</pre>
</td>
</tr>
</table>
Optional: Syntax highlighting for Python would be nice.
This should do the work:
| <code>Row 1 Col 1</code> | <code>Row 1 Col 2</code> |
Or for a simple monospaced text use '':
| ''%%Row 1 Col 1%%'' | ''%%Row 1 Col 2%%'' |
EDIT Add %% %% makes string to be not interpreted as DokuWiki syntax.
Here the documentation: https://www.dokuwiki.org/wiki:syntax
||border=1
||!Table heading 1||!Table heading 2||
||Cell 1.1||Cell 1.2||
||Cell 2.1||Cell 2.2||
I have a SharePoint List with some columns. I have following scenario:
ColA: Test1, Test2, Test3
ColB: 0, 10, 55
ColC: $0, $12, $60
Col A is a dropdown. Col B and C are calculated fields. Based on the value selected in ColA, ColB and ColC values will be auto populate.
Since ColB and C are calculate columns, they are displayed in the list as well as in SharePoint display form. I want to show ColB and C fields in read only mode on SharePoint new and Edit form for users. I am using SharePoint List form not Infopath form.
Looking for suggestions to achieve this functionality.
You could use jquery to append readonly input to work as lookup column.
Here is simple demo script for your reference, you need update the update logic based on your logic.
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript">
$(function () {
var lookupValue = $('input[title="TxTField"]').val();
$('table.ms-formtable').append('<tr id="LookupColumnTR"><td class="ms-formlabel" nowrap="true" valign="top"><h3 class="ms-standardheader"><nobr>LookupColumn</nobr></h3></td><td><input disabled="disabled" type="value" value="' + lookupValue + '" class="text_box" /></td></tr>');
$('input[title="TxTField"]').change(function () {
var lookupValue = $(this).val();
$('table.ms-formtable tr#LookupColumnTR').remove();
$('table.ms-formtable').append('<tr id="LookupColumnTR"><td class="ms-formlabel" nowrap="true" valign="top"><h3 class="ms-standardheader"><nobr>LookupColumn</nobr></h3></td><td><input disabled="disabled" type="value" value="' + lookupValue + '" class="text_box" /></td></tr>');
})
})
</script>
I am trying to replace certain text with other text in PostgreSQL.
To be more specific, I am trying to replace image path and anchor href in article (table blog_posts) from relative to absolute path. Some of the images and anchors already have an absolute path that should not get disturbed.
I tried to select the records which I need to modify:
SELECT
bp.id,
bp.article,
FROM
blog_posts bp
WHERE
bp.article LIKE '%src=%"/fixed_word/%'
OR
bp.article LIKE '%src="/fixed_word/%'
OR
bp.article LIKE '%href="/fixed_word/%'
OR
bp.article LIKE '%href=%"/fixed_word/%'
now I am not sure how to proceed further to update. Please help to get right solution.
My data is something like this:
MyTable: blog_posts
id article
1 any text <img any-atribute src="/fixed_word/variable_word1/something.png"/> any text
2 any text <a any-attribute href="/fixed_word/variable_word2/something2.png"><img src="/fixed_word/variable_word2/something2.png"/> </a>any text
3 any text <img src="https://mydomain.subdomain.com/fixed_word/variable_word1/something.png"/> any text
4 any text <img any-attribute src=\"/fixed_word/variable_word1/something.png"/> any text
5 any text <a any-attribute href=\"/fixed_word/variable_word2/something2.png"><img src=\"/fixed_word/variable_word2/something2.png"/> </a>any text
6 any text <img any-attribute src="https://mydomain.subdomain.com/fixed_word/variable_word6/something6.png"/> any text
OutPut should be:
id article
1 any text <img any-atribute src="https://mydomain.subdomain.com/fixed_word/variable_word1/something.png"/> any text
2 any text <a any-attribute href="https://mydomain.subdomain.com/fixed_word/variable_word2/something2.png"><img src="https://mydomain.subdomain.com/fixed_word/variable_word2/something2.png"/> </a>any text
3 any text <img src="https://mydomain.subdomain.com/fixed_word/variable_word1/something.png"/> any text
4 any text <img any-attribute src="https://mydomain.subdomain.com/fixed_wordvariable_word1/something.png"/> any text
5 any text <a any-attribute href="https://mydomain.subdomain.com/fixed_word/variable_word2/something2.png">
6 any text <img any-attribute src="https://mydomain.subdomain.com/fixed_word/variable_word6/something6.png"/> any text
This can be a starting point:
UPDATE blog_posts
SET article = regexp_replace(
article,
E'(src|href)=[^"]*"/fixed_word/([^"]*)',
E'\\1="https://mydomain.subdomain.com/fixed_word/\\2',
'g'
)
WHERE article ~ E'(src|href)=[^"]*"/fixed_word/([^"]*)';
I have a form processing that I am sure can be done more efficiently and there is an error in the result set although not "life threatening" just not correct.
The purpose of the page is to associate an item with a program and at the same time associate a designation within the program -- B and F fields are checkboxes allowing the item to be associated with multiple programs and designations within that specific program. (edited for clarity)
Example:
Item: Lightsaber
Program: Jedi Training
Designation: Tool(b) (yes)
Designation: Weapon(f) (no)
Program: Jedi Master
Designation: Tool(b) (yes)
Designation: Weapon(f) (yes)
Program: Smuggler
Designation: Tool(b) (no)
Designation: Weapon(f) (no)
Form:
<form action="#CGI.SCRIPT_NAME#" method="post" name="program">
<label>Item</label>
<select id="item" name="item">
<!---//loop through and display items --->
<cfloop query="getitems">
<option value="#itemid#">#itemname#</option>
</cfloop>
</select>
<table>
<!---//loop through and display programs --->
<cfloop query="getprogram">
<tr>
<td>#programname#</td>
<td><input type="checkbox" id="B#programid#" name="B#programid#"></td>
<td><input type="checkbox" id="F#programid#" name="F#programid#"></td>
</tr>
</cfloop>
</table>
<input type="submit">
</form>
Action Page:
<!---// is there is a form being processed --->
<cfif #CGI.REQUEST_METHOD# is 'post'>
<!---// create program list from query --->
<cfset pl = ValueList(query.var, ','>
<!---// set addtl form var's --->
<cfset listassid = 'form.item'>
<!---// loop over program list --->
<cfloop list="#pl#" index="i">
<!---// loop over form fields --->
<cfloop list="form.fieldnames" index="field">
<cfif #field# EQ 'B'&#i#>
<!---// if field is B and var, set designation true --->
<cfset b = 1>
<cfelse>
<!---// it's not, set to null --->
<cfset b = 'null'>
</cfif>
<cfif #field# EQ 'F'&#i#>
<!---// if field is F and var, set designation true --->
<cfset f = 1>
<cfelse>
<!---// it's not, set to null --->
<cfset f = 'null'>
</cfif>
<cfif b EQ 'null' AND f EQ 'null'>
<!---// if both are null then skip --->
//do nothing
<cfelse>
<!---//insert record into table --->
insert into table (table fields)
(#i#, #listassid#, #b#, #f# )
</cfif>
</cfloop>
</cfloop>
</cfif>
The result should be:
id item_id program_id B F
1 24 1 x
2 32 2 x x
The actual result is:
id item_id program_id B F
1 24 1 x
2 32 2 x
3 32 2 x
Thank you in advance for any clarification and efficiencies you can suggest.
I think a slightly different naming convention would help resolve the current issue, and improve the readability of the code.
One option is to store all of the project id's in a hidden form field. Be sure to use the same "name", so the id's are submitted as a CSV list. Also, I would recommend more meaningful names for the checkboxes, to improve readability. For example, "isSomething" rather than just "B" or "F":
<select id="item" name="itemID">
<cfoutput query="getitems">
<option value="#itemid#">#itemname#</option>
</cfoutput>
</select>
...
<cfoutput query="getPrograms">
<input type="hidden" name="programIDList" value="#programID#">
...
<!--- Set checkbox values to 1 / Yes --->
<td><input type="checkbox" name="isTool_#programID#" value="1"></td>
<td><input type="checkbox" name="isWeapon_#programID#" value="1"></td>
...
</cfoutput>
When the form is submitted, loop through the list of project id's and use the current id to extract the values of each set of checkboxes. If either box was checked, insert a record into the database.
* Note: Checkboxes are only submitted when "checked". Before accessing the field, either use structKeyExists to verify the field exists OR use cfparam to set a default value for the field.
<!--- Loop through list of available program id's --->
<cfloop list="#form.programIDList#" index="variables.programID">
<!--- Ensure fields exist. Set default value = 0 / No --->
<cfparam name="form.isTool_#variables.programID#" default="0">
<cfparam name="form.isWeapon_#variables.programID#" default="0">
<!--- Extract the current values --->
<cfset variables.isTool = FORM["isTool_"& variables.programID ] >
<cfset variables.isWeapon = FORM["isWeapon_"& variables.programID ] >
<!--- DEBUG ONLY: Display current values --->
<cfoutput>
<hr>variables.programID = #variables.programID#
<br>variables.isTool = #variables.isTool#
<br>variables.isWeapon = #variables.isWeapon#
<br>form.itemID = #form.itemID#
</cfoutput>
<!--- If either box was checked, save to database --->
<cfif variables.isTool || variables.isWeapon>
... run cfquery here
</cfif>
</cfloop>
Two important notes about database queries:
Never use raw client values in SQL. Instead use cfqueryparam. It helps protects your database against sql injection. It also improves query performance when a statement is executed multiple times (as in this case)
When executing multiple (related) queries, be sure to wrap them in a cftransaction to ensure consistency, ie All statements succeed or fail as a unit.