summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2007-09-11 14:00:28 +0000
committertetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2007-09-11 14:00:28 +0000
commit2d45373a520993b33e18b28db6a9db71bc3bd8e4 (patch)
treea11b676683706d4cc89e91eb05104fe1b5b30e5b
parent6f337cb15990f8b8dcf5862f1a8a8c127964ae6f (diff)
Adding elements.html (name-value ids for radios variant from patch 1791319)
Adjusting the GL report to not require HTML no_escape git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1561 4979c152-3d1c-0410-bac9-87ea11338e46
-rw-r--r--UI/elements.html200
-rw-r--r--UI/gl-report.csv4
-rw-r--r--UI/gl-report.html36
-rw-r--r--bin/gl.pl146
4 files changed, 293 insertions, 93 deletions
diff --git a/UI/elements.html b/UI/elements.html
new file mode 100644
index 00000000..19570e62
--- /dev/null
+++ b/UI/elements.html
@@ -0,0 +1,200 @@
+<?lsmb
+ default_keys = ['id', 'class', 'title'] # Defaults for all attributes
+ input_keys = ['type', 'name', 'disabled', 'size', 'value'] # Defaults for input attributes
+
+ # ELEMENT DEFAULTS
+
+ #checkbox
+ checkbox_defaults = {
+ value = '1'
+ }
+
+ #file
+ file_defaults = {
+ size => '60'
+ }
+
+ #password
+ password_defaults = {
+ size = '60'
+ }
+
+ # text
+ text_defaults = {
+ size = '60',
+ maxlength = '255'
+ }
+
+ # textarea
+ textarea_defaults = {
+ rows = '5',
+ cols = '60'
+ }
+
+ #button
+ button_defaults = {
+ type = 'submit'
+ }
+
+?>
+
+<?lsmb # INPUT ELEMENT ?>
+<?lsmb BLOCK input ?>
+ <?lsmb input_defaults = {} # Some inputs have no defaults, so make sure everything is empty to start with. ?>
+ <?lsmb SWITCH element_data.type; # Merge in type-specific attributes.
+ CASE 'file';
+ input_type_keys = input_keys.merge(['accept']);
+ input_defaults = file_defaults;
+ CASE 'image';
+ input_type_keys = input_keys.merge(['alt', 'src']);
+ CASE ['checkbox'];
+ input_type_keys = input_keys.merge(['checked']);
+ input_defaults = checkbox_defaults;
+ CASE ['radio'];
+ input_type_keys = input_keys.merge(['checked']);
+ CASE ['password'];
+ input_defaults = password_defaults;
+ CASE 'text';
+ input_type_keys = input_keys.merge(['maxlength', 'readonly']);
+ input_defaults = text_defaults;
+ CASE;
+ input_type_keys = input_keys;
+ END;
+ ?>
+ <?lsmb PROCESS attributes # Process regular attributes.
+ attribute_data = element_data
+ attribute_defaults = input_defaults
+ element_keys = input_type_keys
+ element_type = 'input'
+ ?>
+ <?lsmb PROCESS custom_attributes # Process custom attributes.
+ custom_attribute_data=element_data.attributes
+ ?>
+ <input<?lsmb all_attributes ?><?lsmb all_custom_attributes ?> />
+<?lsmb END ?>
+
+<?lsmb # TEXTAREA ELEMENT ?>
+<?lsmb BLOCK textarea ?>
+ <?lsmb PROCESS attributes # Process regular attributes.
+ attribute_data=element_data
+ attribute_defaults = textarea_defaults
+ element_keys = ['name', 'cols', 'rows', 'disabled', 'readonly', 'tabindex', 'accesskey', 'value'] # Attributes that apply to textareas.
+ element_type = 'textarea'
+ ?>
+ <?lsmb PROCESS custom_attributes # Process custom attributes.
+ custom_attribute_data=element_data.attributes
+ ?>
+ <textarea<?lsmb all_attributes ?><?lsmb all_custom_attributes ?>><?lsmb element_data.text ?></textarea>
+<?lsmb END ?>
+
+<?lsmb # SELECT ELEMENT ?>
+<?lsmb BLOCK select ?>
+ <?lsmb PROCESS attributes # Process regular attributes.
+ attribute_data=element_data
+ attribute_defaults = {} # Make sure old defaults are cleared out.
+ element_keys=['name', 'size', 'multiple', 'disabled', 'accesskey', 'tabindex'] # Attributes that apply to selects.
+ element_type = 'select'
+ ?>
+ <?lsmb PROCESS custom_attributes # Process custom attributes.
+ custom_attribute_data=element_data.attributes
+ ?>
+ <select<?lsmb all_attributes ?><?lsmb all_custom_attributes ?>>
+ <?lsmb # Build options.
+ FOREACH option_data IN element_data.options;
+ PROCESS option;
+ END;
+ ?>
+ </select>
+<?lsmb END ?>
+
+<?lsmb # OPTION ELEMENT ?>
+<?lsmb BLOCK option ?>
+ <?lsmb # Selected is a special case -- no attribute key, so it's handled here.
+ IF option_data.defined('selected');
+ option_data.selected = " selected";
+ ELSE;
+ option_data.selected = "";
+ END;
+ ?>
+ <?lsmb PROCESS attributes # Process regular attributes.
+ attribute_data=option_data
+ element_keys=['tabindex', 'disabled', 'value'] # Attributes that apply to options.
+ element_type = 'option'
+ ?>
+ <?lsmb PROCESS custom_attributes # Process custom attributes.
+ custom_attribute_data=option_data.attributes
+ ?>
+ <option<?lsmb all_attributes ?><?lsmb all_custom_attributes ?><?lsmb option_data.selected ?>><?lsmb option_data.text ?></option>
+<?lsmb END ?>
+
+<?lsmb # BUTTON ELEMENT ?>
+<?lsmb BLOCK button ?>
+ <?lsmb PROCESS attributes # Process regular attributes.
+ attribute_data=element_data
+ attribute_defaults = button_defaults
+ element_keys=['name', 'value', 'accesskey', 'type', 'disabled', 'tabindex'] # Attributes that apply to buttons.
+ element_type = 'button'
+ ?>
+ <?lsmb PROCESS custom_attributes # Process custom attributes.
+ custom_attribute_data=element_data.attributes
+ ?>
+ <button<?lsmb all_attributes ?><?lsmb all_custom_attributes ?>><?lsmb element_data.text ?></button>
+<?lsmb END ?>
+
+<?lsmb # LABEL ELEMENT ?>
+<?lsmb BLOCK label ?>
+ <?lsmb PROCESS attributes
+ attribute_data=element_data
+ attribute_defaults = {} # Make sure old defaults are cleared out.
+ element_keys=['for'] # Attributes that apply to labels.
+ element_type = 'label'
+ ?>
+ <?lsmb PROCESS custom_attributes
+ custom_attribute_data=element_data.attributes
+ ?>
+ <label<?lsmb all_attributes ?><?lsmb all_custom_attributes ?>><?lsmb element_data.text ?></label>
+<?lsmb END ?>
+
+<?lsmb # REGULAR ATTRIBUTE PROCESSING -- all explicitly allowed attributes are processed here. ?>
+<?lsmb BLOCK attributes ?>
+ <?lsmb
+ all_attributes = ""
+ all_keys = default_keys.merge(element_keys) # Merge in attributes that apply to this element.
+ ?>
+ <?lsmb FOREACH element_attribute IN all_keys # Loop through each allowed attribute. ?>
+ <?lsmb
+ IF attribute_data.defined(element_attribute); # Add the attribute to the element if it's been set.
+ all_attributes = all_attributes _ " " _ element_attribute _ '="' _ attribute_data.${element_attribute} _ '"';
+ ELSIF attribute_defaults.defined(element_attribute); # Fall back to default value if one is supplied.
+ all_attributes = all_attributes _ " " _ element_attribute _ '="' _ attribute_defaults.${element_attribute} _ '"';
+ END;
+ ?>
+ <?lsmb END ?>
+ <?lsmb UNLESS attribute_data.defined('id') # id attribute should always be set, so auto-set it if it's not defined. ?>
+ <?lsmb element_id = "" ?>
+ <?lsmb # Labal id's default to [for]-label.
+ IF element_type == 'label' AND attribute_data.defined('for');
+ element_id = attribute_data.for _ "-label";
+ ELSIF ((element_type == 'input' AND attribute_data.type == 'radio') OR element_type == 'button') AND attribute_data.defined('name') AND attribute_data.defined('value');
+ element_id = attribute_data.name _ "-" _ attribute_data.value; # radios and buttons get name-value for uniqueness.
+ ELSIF (element_type == 'input' OR element_type == 'textarea' OR element_type == 'select') AND attribute_data.defined('name');
+ element_id = attribute_data.name;
+ END;
+ ?>
+ <?lsmb # Add the id if it's been generated. Replace underscores with dashes -- nicer CSS.
+ IF element_id;
+ all_attributes = ' id="' _ element_id.replace('[_]', '-') _ '"' _ all_attributes;
+ END;
+ ?>
+ <?lsmb END ?>
+<?lsmb END ?>
+
+<?lsmb # CUSTOM ATTRIBUTE PROCESSING -- any other attributes passed in the 'attributes' key are processed here. ?>
+<?lsmb BLOCK custom_attributes ?>
+ <?lsmb all_custom_attributes = "" ?>
+ <?lsmb # Loop through each attribute and add it to the custom attribute string.
+ FOREACH element_attribute IN custom_attribute_data;
+ all_custom_attributes = all_custom_attributes _ " " _ element_attribute.key _ '="' _ element_attribute.value _ '"';
+ END;
+ ?>
+<?lsmb END ?> \ No newline at end of file
diff --git a/UI/gl-report.csv b/UI/gl-report.csv
index 83dc27ce..fc2e4b16 100644
--- a/UI/gl-report.csv
+++ b/UI/gl-report.csv
@@ -1,3 +1,3 @@
-<?lsmb FOREACH column IN columns ?><?lsmb heading.$column ?><?lsmb IF NOT loop.last ?>~<?lsmb END ?><?lsmb END ?>
-<?lsmb FOREACH row IN rows ?><?lsmb FOREACH column IN columns ?><?lsmb row.$column ?><?lsmb IF NOT loop.last ?>~<?lsmb END ?><?lsmb END ?>
+<?lsmb FOREACH column IN columns ?><?lsmb IF heading.$column.text; heading.$column.text; ELSE; heading.$column; END ?><?lsmb IF NOT loop.last ?>~<?lsmb END ?><?lsmb END ?>
+<?lsmb FOREACH row IN rows ?><?lsmb FOREACH column IN columns ?><?lsmb IF row.$column.text; row.$column.text; ELSE; row.$column; END ?><?lsmb IF NOT loop.last ?>~<?lsmb END ?><?lsmb END ?>
<?lsmb END ?><?lsmb FOREACH column IN columns ?><?lsmb totals.$column ?><?lsmb IF NOT loop.last ?>~<?lsmb END ?><?lsmb END ?>
diff --git a/UI/gl-report.html b/UI/gl-report.html
index 69e2d866..031ef009 100644
--- a/UI/gl-report.html
+++ b/UI/gl-report.html
@@ -11,9 +11,7 @@
<meta name="robots" content="noindex,nofollow" />
</head>
-
-
-
+<?lsmb PROCESS elements.html ?>
<body>
<table width=100%>
@@ -28,8 +26,11 @@
<td>
<table width=100%>
<tr class="listheading">
-<?lsmb FOREACH column IN columns ?>
-<?lsmb heading.$column ?>
+<?lsmb FOREACH column IN columns ?><?lsmb IF heading.$column.href ?>
+<th class="listheading"><a class="listheading" href="<?lsmb heading.$column.href ?>"><?lsmb heading.$column.text ?></a></th>
+<?lsmb ELSE ?>
+<th class="listheading"><?lsmb heading.$column ?></th>
+<?lsmb END ?>
<?lsmb END ?>
</tr>
@@ -52,7 +53,12 @@
<?lsmb ELSE ?>
<td>
<?lsmb END ?>
- <?lsmb row.$column ?></td>
+<?lsmb IF row.$column.href ?>
+ <a href="<?lsmb row.$column.href?>"><?lsmb row.$column.text ?></a>
+<?lsmb ELSE ?>
+ <?lsmb row.$column ?>
+<?lsmb END ?>
+ </td>
<?lsmb END ?>
</tr>
<?lsmb END ?>
@@ -73,19 +79,13 @@
<br />
<form method=post action=gl.pl>
-<?lsmb FOREACH pair IN form.callback.split('&') ?>
-<?lsmb hidden = pair.split('=') ?>
+<?lsmb FOREACH pair IN form.callback.split('&') ?><?lsmb hidden = pair.split('=') ?>
<?lsmb IF NOT loop.first ?>
-<input type="hidden" name="<?lsmb hidden.0 ?>" value="<?lsmb hidden.1 ?>" />
-<?lsmb END ?>
-<?lsmb END ?>
-<input type="hidden" name="callback" value="<?lsmb form.callback ?>" />
-<?lsmb FOREACH button IN buttons ?>
-<?lsmb button ?>
-<?lsmb END ?>
-<button type="submit" class="submit" name="action" value="csv_gl_report">
-<?lsmb text('CSV Report') ?>
-</button>
+<?lsmb PROCESS input element_data={type => 'hidden', name => hidden.0, value => hidden.1} ?>
+<?lsmb END ?><?lsmb END ?>
+<?lsmb PROCESS input element_data={type => 'hidden', name => 'callback', value => form.callback} ?>
+
+<?lsmb FOREACH button IN buttons ?><?lsmb PROCESS button element_data=button ?><?lsmb END ?>
</form>
</body>
diff --git a/bin/gl.pl b/bin/gl.pl
index 16871f25..11476444 100644
--- a/bin/gl.pl
+++ b/bin/gl.pl
@@ -597,49 +597,28 @@ sub generate_report {
$href .= "&category=$form->{category}";
$column_header{id} =
- "<th><a class=listheading href=$href&sort=id>"
- . $locale->text('ID')
- . "</a></th>";
+ {text => $locale->text('ID'), href=> "$href&sort=id"};
$column_header{transdate} =
- "<th><a class=listheading href=$href&sort=transdate>"
- . $locale->text('Date')
- . "</a></th>";
+ {text => $locale->text('Date'), href=> "$href&sort=transdate"};
$column_header{reference} =
- "<th><a class=listheading href=$href&sort=reference>"
- . $locale->text('Reference')
- . "</a></th>";
+ {text => $locale->text('Reference'), href=> "$href&sort=reference"};
$column_header{source} =
- "<th><a class=listheading href=$href&sort=source>"
- . $locale->text('Source')
- . "</a></th>";
+ {text => $locale->text('Source'), href=> "$href&sort=source"};
$column_header{memo} =
- "<th><a class=listheading href=$href&sort=memo>"
- . $locale->text('Memo')
- . "</a></th>";
+ {text => $locale->text('Memo'), href=> "$href&sort=memo"};
$column_header{description} =
- "<th><a class=listheading href=$href&sort=description>"
- . $locale->text('Description')
- . "</a></th>";
+ {text => $locale->text('Description'), href=> "$href&sort=description"};
$column_header{department} =
- "<th><a class=listheading href=$href&sort=department>"
- . $locale->text('Department')
- . "</a></th>";
- $column_header{notes} =
- "<th class=listheading>" . $locale->text('Notes') . "</th>";
- $column_header{debit} =
- "<th class=listheading>" . $locale->text('Debit') . "</th>";
- $column_header{credit} =
- "<th class=listheading>" . $locale->text('Credit') . "</th>";
+ {text => $locale->text('Department'), href=> "$href&sort=department"};
+ $column_header{notes} = $locale->text('Notes');
+ $column_header{debit} = $locale->text('Debit');
+ $column_header{credit} = $locale->text('Credit');
$column_header{accno} =
- "<th><a class=listheading href=$href&sort=accno>"
- . $locale->text('Account')
- . "</a></th>";
+ {text => $locale->text('Account'), href=> "$href&sort=accno"};
$column_header{gifi_accno} =
- "<th><a class=listheading href=$href&sort=gifi_accno>"
- . $locale->text('GIFI')
- . "</a></th>";
- $column_header{balance} = "<th>" . $locale->text('Balance') . "</th>";
- $column_header{cleared} = qq|<th>| . $locale->text('R') . qq|</th>|;
+ {text => $locale->text('GIFI'), href=> "$href&sort=gifi_accno"};
+ $column_header{balance} = $locale->text('Balance');
+ $column_header{cleared} = $locale->text('R');
# add sort to callback
$form->{callback} = "$callback&sort=$form->{sort}";
@@ -691,16 +670,17 @@ sub generate_report {
$totalcredit += $ref->{credit};
$ref->{debit} =
- $form->format_amount( \%myconfig, $ref->{debit}, 2, "&nbsp;" );
+ $form->format_amount( \%myconfig, $ref->{debit}, 2, " " );
$ref->{credit} =
- $form->format_amount( \%myconfig, $ref->{credit}, 2, "&nbsp;" );
+ $form->format_amount( \%myconfig, $ref->{credit}, 2, " " );
for (qw(id transdate)) { $column_data{$_} = "$ref->{$_}" }
$column_data{reference} =
-"<a href=$ref->{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{reference}";
+ {href => "$ref->{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback",
+ text => $ref->{reference}};
- $ref->{notes} =~ s/\r?\n/<br>/g;
+ #$ref->{notes} =~ s/\r?\n/<br>/g;
for (qw(description source memo notes department)) {
$column_data{$_} = "$ref->{$_} ";
}
@@ -709,9 +689,11 @@ sub generate_report {
$column_data{credit} = "$ref->{credit}";
$column_data{accno} =
-"<a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{accno}</a> $ref->{accname}";
+ {href => "$href&accno=$ref->{accno}&callback=$callback",
+ text => "$ref->{accno} $ref->{accname}"};
$column_data{gifi_accno} =
-"<a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a> ";
+ {href => "$href&gifi_accno=$ref->{gifi_accno}&callback=$callback",
+ text => $ref->{gifi_accno}};
$column_data{balance} = $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml,
2, 0 );
$column_data{cleared} =
@@ -731,41 +713,52 @@ sub generate_report {
for (@column_index) { $column_data{$_} = " " }
- $column_data{debit} = $form->format_amount( \%myconfig, $totaldebit, 2, "&nbsp;" );
- $column_data{credit} = $form->format_amount( \%myconfig, $totalcredit, 2, "&nbsp;" );
+ $column_data{debit} = $form->format_amount( \%myconfig, $totaldebit, 2, " " );
+ $column_data{credit} = $form->format_amount( \%myconfig, $totalcredit, 2, " " );
$column_data{balance} = $form->format_amount( \%myconfig, $form->{balance} * $ml * $cml, 2, 0 );
$i = 1;
+ my %button;
if ( $myconfig{acs} !~ /General Ledger--General Ledger/ ) {
- $button{'General Ledger--Add Transaction'}{code} =
-qq|<button class="submit" type="submit" name="action" value="gl_transaction">|
- . $locale->text('GL Transaction')
- . qq|</button> |;
- $button{'General Ledger--Add Transaction'}{order} = $i++;
+ $button{'General Ledger--Add Transaction'} = {
+ name => 'action',
+ value => 'gl_transaction',
+ text => $locale->text('GL Transaction'),
+ type => 'submit',
+ class => 'submit',
+ order => $i++};
}
if ( $myconfig{acs} !~ /AR--AR/ ) {
- $button{'AR--Add Transaction'}{code} =
-qq|<button class="submit" type="submit" name="action" value="ar_transaction">|
- . $locale->text('AR Transaction')
- . qq|</button> |;
- $button{'AR--Add Transaction'}{order} = $i++;
- $button{'AR--Sales Invoice'}{code} =
-qq|<button class="submit" type="submit" name="action" value="sales_invoice_">|
- . $locale->text('Sales Invoice')
- . qq|</button> |;
- $button{'AR--Sales Invoice'}{order} = $i++;
+ $button{'AR--Add Transaction'} = {
+ name => 'action',
+ value => 'ar_transaction',
+ text => $locale->text('AR Transaction'),
+ type => 'submit',
+ class => 'submit',
+ order => $i++};
+ $button{'AR--Sales Invoice'} = {
+ name => 'action',
+ value => 'sales_invoice_',
+ text => $locale->text('Sales Invoice'),
+ type => 'submit',
+ class => 'submit',
+ order => $i++};
}
if ( $myconfig{acs} !~ /AP--AP/ ) {
- $button{'AP--Add Transaction'}{code} =
-qq|<button class="submit" type="submit" name="action" value="ap_transaction">|
- . $locale->text('AP Transaction')
- . qq|</button> |;
- $button{'AP--Add Transaction'}{order} = $i++;
- $button{'AP--Vendor Invoice'}{code} =
-qq|<button class="submit" type="submit" name="action" value="vendor_invoice_">|
- . $locale->text('Vendor Invoice')
- . qq|</button> |;
- $button{'AP--Vendor Invoice'}{order} = $i++;
+ $button{'AP--Add Transaction'} = {
+ name => 'action',
+ value => 'ap_transaction',
+ text => $locale->text('AP Transaction'),
+ type => 'submit',
+ class => 'submit',
+ order => $i++};
+ $button{'AP--Vendor Invoice'} = {
+ name => 'action',
+ value => 'vendor_invoice_',
+ text => $locale->text('Vendor Invoice'),
+ type => 'submit',
+ class => 'submit',
+ order => $i++};
}
foreach $item ( split /;/, $myconfig{acs} ) {
@@ -773,9 +766,16 @@ qq|<button class="submit" type="submit" name="action" value="vendor_invoice_">|
}
my @buttons;
- foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
- push @buttons, $item->{code};
+ foreach my $item ( sort { $a->{order} <=> $b->{order} } %button ) {
+ push @buttons, $item if ref $item;
}
+ push @buttons, {
+ name => 'action',
+ value => 'csv_gl_report',
+ text => $locale->text('CSV Report'),
+ type => 'submit',
+ class => 'submit',
+ };
##SC: Taking this out for now...
## if ( $form->{lynx} ) {
@@ -799,7 +799,7 @@ qq|<button class="submit" type="submit" name="action" value="vendor_invoice_">|
path => 'UI',
template => 'gl-report',
format => 'HTML',
- no_escape => 1
+ # no_escape => 1
);
}
$template->render({
@@ -820,9 +820,9 @@ sub gl_subtotal_tt {
my %column_data;
$subtotaldebit =
- $form->format_amount( \%myconfig, $subtotaldebit, 2, "&nbsp;" );
+ $form->format_amount( \%myconfig, $subtotaldebit, 2, " " );
$subtotalcredit =
- $form->format_amount( \%myconfig, $subtotalcredit, 2, "&nbsp;" );
+ $form->format_amount( \%myconfig, $subtotalcredit, 2, " " );
for (@column_index) { $column_data{$_} = " " }
$column_data{'is_subtotal'} = 1;