diff options
author | mark <mark> | 2010-07-22 00:11:56 +0000 |
---|---|---|
committer | mark <mark> | 2010-07-22 00:11:56 +0000 |
commit | 342e2bfbe6aad470ab9dee40640f8ac7d9653003 (patch) | |
tree | bf350b2d3876651ee0c4487b0e321ec21f839f0c /httemplate/elements | |
parent | c26fea8a168f255412a8065c0a04758c9b0d340d (diff) |
cdr rating by day and time, part 2, RT#4763
Diffstat (limited to 'httemplate/elements')
-rw-r--r-- | httemplate/elements/auto-table.html | 77 | ||||
-rw-r--r-- | httemplate/elements/menu.html | 1 |
2 files changed, 47 insertions, 31 deletions
diff --git a/httemplate/elements/auto-table.html b/httemplate/elements/auto-table.html index 89d6eacb9..9c7dfd09a 100644 --- a/httemplate/elements/auto-table.html +++ b/httemplate/elements/auto-table.html @@ -28,6 +28,12 @@ Example: 'records' => [ qsearch('item', { } ) ], # or any other array of FS::Record objects + 'select' => [ '', + [ 1 => 'option 1', + 2 => 'option 2', ... + ], # options for second field + '' ], + 'prefix' => 'mytable_', ) %> @@ -47,6 +53,17 @@ Values will be passed through as "mytable_id1", etc. % for ( $col = 0; $col < scalar @fields; $col++ ) { % my $id = $prefix . $fields[$col] . $row; <TD> +% my @o = @{ $select[$col] }; +% if( @o ) { + <SELECT NAME="<% $id %>" ID="<% $id %>"> +% while(@o) { +% my $val = shift @o; + <OPTION VALUE=<% $val %><% +$val eq $data[$row][$col] ? ' SELECTED' : ''%>><% shift @o %></OPTION> +% } + </SELECT> +% } +% else { <INPUT TYPE = "text" NAME = "<% $id %>" ID = "<% $id %>" @@ -54,63 +71,58 @@ Values will be passed through as "mytable_id1", etc. MAXLENGTH = <% $maxl[$col] %> STYLE = "text-align:<% $align[$col] %>" VALUE = "<% $data[$row][$col] %>" - onchange = "possiblyAddRow();" +% if( $opt{'autoadd'} ) { + onchange = "possiblyAddRow(this);" +% } > </TD> +% } % } <TD> <IMG SRC = "<% "${p}images/cross.png" %>" ALT = "X" - onclick = "deleteThisRow(this);" + onclick = "deleteRow(this);" > </TD> </TR> % } </TABLE> +% if( !$opt{'autoadd'} ) { +<INPUT TYPE="button" VALUE="Add" onclick="<% $prefix %>addRow();"><BR> +% } <SCRIPT TYPE="text/javascript"> var <% $prefix %>rownum = <% $row %>; var <% $prefix %>table = document.getElementById('<% $prefix %>AutoTable'); + // last row is initially blank, clone it and remove it + var <% $prefix %>_blank = + <% $prefix %>table.rows[<% $prefix %>table.rows.length-1].cloneNode(true); +% if( !$opt{'autoadd'} ) { + <% $prefix %>table.deleteRow(<% $prefix %>table.rows.length-1); +% } + + function rownum_of(obj) { return (obj.parentNode.parentNode.sectionRowIndex); } - function possiblyAddRow() { - if ( <% $prefix %>rownum == rownum_of(this) ) { + function <% $prefix %>possiblyAddRow(obj) { + if ( <% $prefix %>rownum == rownum_of(obj) ) { <% $prefix %>addRow(); } } function <% $prefix %>addRow() { - var row = <% $prefix %>table.insertRow(<% $prefix %>rownum + 1); -% my $col = 0; -% for( $col = 0; $col < scalar @fields; $col++ ) { -% my $field = $prefix.$fields[$col]; - var <% $field %>_cell = document.createElement('TD'); - var <% $field %>_input = document.createElement('INPUT'); - <% $field %>_input.setAttribute('name', '<% $field %>'+<% $prefix %>rownum); - <% $field %>_input.setAttribute('id', '<% $field %>'+<% $prefix %>rownum); - <% $field %>_input.setAttribute('type', 'text'); - <% $field %>_input.setAttribute('size', <% $size[$col] %>); - <% $field %>_input.setAttribute('maxlength', <% $maxl[$col] %>); - <% $field %>_input.style.textAlign = '<% $align[$col] %>'; - <% $field %>_input.onchange = possiblyAddRow; - <% $field %>_cell.appendChild(<% $field %>_input); - row.appendChild(<% $field %>_cell); -% } - var delcell = document.createElement('TD'); - var delinput = document.createElement('IMG'); - delinput.setAttribute('src', '<% "${p}images/cross.png" %>'); - delinput.setAttribute('alt', 'X'); - delinput.setAttribute('onclick', 'deleteThisRow(this);'); - delcell.appendChild(delinput); - row.appendChild(delcell); - + var row = <% $prefix %>table.insertRow(-1); + var cells = <% $prefix %>_blank.cells; + for (i=0; i<cells.length; i++) { + row.appendChild(cells[i].cloneNode(true)); + } <% $prefix %>rownum++; } - function deleteThisRow(obj) { + function deleteRow(obj) { if(<% $prefix %>rownum == rownum_of(obj)) { <% $prefix %>addRow(); } @@ -119,7 +131,6 @@ Values will be passed through as "mytable_id1", etc. return(false); } - <% $prefix %>addRow(); </SCRIPT> <%init> @@ -137,10 +148,14 @@ elsif($opt{'records'}) { } } # else @data = (); +push @data, [ map {''} @fields ]; # make a blank row my $prefix = $opt{'prefix'}; my @size = $opt{'size'} ? @{ $opt{'size'} } : (map {16} @fields); my @maxl = $opt{'maxl'} ? @{ $opt{'maxl'} } : @size; my @align = $opt{'align'} ? @{ $opt{'align'} } : (map {'right'} @fields); - +my @select = @{ $opt{'select'} || [] }; +foreach (0..scalar(@fields)-1) { + $select[$_] ||= []; +} </%init> diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index 1eaefe231..da2dcaa4c 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -421,6 +421,7 @@ tie my %config_billing_rates, 'Tie::IxHash', 'Rate plans' => [ $fsurl.'browse/rate.cgi', 'Manage rate plans' ], 'Regions and prefixes' => [ $fsurl.'browse/rate_region.html', 'Manage regions and prefixes' ], 'Usage classes' => [ $fsurl.'browse/usage_class.html', 'Usage classes define groups of usage for taxation.' ], + 'Time periods' => [ $fsurl.'browse/rate_time.html', 'Time periods define days and hours for rate plans' ], 'Edit rates with Excel' => [ $fsurl.'misc/rate_edit_excel.html', 'Download and edit rates with Excel, then upload changes.' ], #"Edit with Excel" ? ; |