diff options
author | Ivan Kohler <ivan@freeside.biz> | 2013-08-25 16:23:17 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2013-08-25 16:23:17 -0700 |
commit | c14b35ce12141287e201bba8489b202a1b34b38f (patch) | |
tree | d897217561389649f4b4777e480ab2e115668d54 /httemplate/elements | |
parent | d29b455cf176358089f98e2970beaab88195bc62 (diff) |
continue sales person work: customer and package selection, commissions, reporting. RT#23402
Diffstat (limited to 'httemplate/elements')
-rw-r--r-- | httemplate/elements/tr-select-sales.html | 89 | ||||
-rw-r--r-- | httemplate/elements/xmlhttp.html | 12 |
2 files changed, 92 insertions, 9 deletions
diff --git a/httemplate/elements/tr-select-sales.html b/httemplate/elements/tr-select-sales.html index 2a2edf03c..b69b3d8b6 100644 --- a/httemplate/elements/tr-select-sales.html +++ b/httemplate/elements/tr-select-sales.html @@ -13,7 +13,8 @@ Example: 'label' => 'Sales Person', 'empty_label' => 'Select sales person', #override default - #on already# 'disable_empty' => 1, + 'disable_empty' => 0, #on byd efault, pass 0 to disable + 'field' => 'salesnum', #HTML element name and ID &> @@ -21,8 +22,8 @@ Example: % if ( scalar(@sales) == 0 || $opt{'fixed'} ) { <INPUT TYPE = "hidden" - NAME = "<% $opt{'field'} || 'salesnum' %>" - ID = "<% $opt{'field'} || 'salesnum' %>" + NAME = "<% $field %>" + ID = "<% $id %>" VALUE = "<% $salesnum %>" > @@ -63,19 +64,99 @@ Example: % } +<& /elements/xmlhttp.html, + 'url' => $p.'misc/sales.cgi', + 'subs' => [ 'get_sales' ], +&> +<SCRIPT TYPE="text/javascript"> + +% # false laziness w/ elements/tr-select-cust-part_pkg.html + + function <% $field %>_opt(what, value, text) { + var optionName = new Option(text, value, false, false); + var length = what.length; + what.options[length] = optionName; + } + + function <% $field %>_agentnum_changed(what) { + what.form.<% $field %>.disabled = 'disabled'; //disable sales dropdown + + agentnum = what.options[what.selectedIndex].value; + + function update_<% $field %>(sales) { + + if ( what.form.<% $field %>.type == 'hidden' ) { + what.form.<% $field %>.disabled = ''; //re-enable sales dropdown + return; + } + + // save the current salesnum + var salesnum = what.form.<% $field %>.value; + + // blank the current sales people + for ( var i = what.form.<% $field %>.length; i>= 0; i-- ) + what.form.<% $field %>.options[i] = null; + + // add the new sales people + +% my @pre_options = $opt{pre_options} ? @{ $opt{pre_options} } : (); +% while ( @pre_options ) { +% my $pre_opt = shift(@pre_options); +% my $pre_label = shift(@pre_options); +% #my $selected = ( $salesnum eq $pre_opt ); + <% $field %>_opt( what.form.<% $field %>, + <% $pre_opt |js_string %>, + <% $pre_label |js_string %> + ); +% } + +% unless ( $opt{'disable_empty'} ) { + <% $field %>_opt( what.form.<% $field %>, + '', + <% $opt{'empty_label'} || '(none)' |js_string %> + ); +% } + + var salesArray = eval('(' + sales + ')' ); + for ( var s = 0; s < salesArray.length; s=s+2 ) { + //surely this should be some kind of JSON structure + var salesLabel = salesArray[s+1]; + <% $field %>_opt( what.form.<% $field %>, salesArray[s], salesLabel ); + } + + what.form.<% $field %>.disabled = ''; //re-enable sales dropdown + + //restore salesnum if possible + what.form.<% $field %>.value = salesnum; + + } + + get_sales( agentnum, + update_<% $field %> + ); + } + + <&| /elements/onload.js &> + <% $field %>_agentnum_changed(document.getElementById('agentnum')); + </&> + +</SCRIPT> + <%init> my $curuser = $FS::CurrentUser::CurrentUser; my %opt = @_; my $salesnum = $opt{'curr_value'} || $opt{'value'}; +my $field = $opt{'element_name'} || $opt{'field'} || 'salesnum'; +my $id = $opt{'id'} || $opt{'field'} || 'salesnum'; my @sales = qsearch({ 'table' => 'sales', 'hashref' => { 'disabled' => '' }, 'extra_sql' => ' AND '. $curuser->agentnums_sql, + 'order_by' => 'ORDER BY salesperson', }); my $colspan = $opt{'colspan'} ? 'COLSPAN="'.$opt{'colspan'}.'"' : ''; - </%init> diff --git a/httemplate/elements/xmlhttp.html b/httemplate/elements/xmlhttp.html index a9e65c790..2f4f0d555 100644 --- a/httemplate/elements/xmlhttp.html +++ b/httemplate/elements/xmlhttp.html @@ -14,17 +14,19 @@ Example: ); </%doc> +<%shared> +my %initialized = ();#won't work if component is "preloaded"... so don't do that +</%shared> <& /elements/rs_init_object.html &> <& /elements/init_overlib.html &> <SCRIPT TYPE="text/javascript"> % foreach my $func ( @{$opt{'subs'}} ) { % -% my $furl = $url; -% $furl =~ s/\"/\\\\\"/; #javascript escape -%#" -% - +% next if $initialized{$key.$func}++; +% +% my $furl = $url; +% $furl =~ s/\"/\\\\\"/; #javascript escape (fix gvim syntax: ") function <%$key%><%$func%>() { // count args; build URL |