diff options
author | Jonathan Prykop <jonathan@freeside.biz> | 2015-09-10 21:33:37 -0500 |
---|---|---|
committer | Jonathan Prykop <jonathan@freeside.biz> | 2015-09-10 21:33:37 -0500 |
commit | 8eeac13d3a8b231efd786eca0555087de5dbb17e (patch) | |
tree | 6b84175ec9906e27b343e77774b3967419c701a8 /httemplate/misc | |
parent | ffa5a5ba5f1e75ad5e7545f5c8e303e079014f2f (diff) |
RT#33410: Package GB add-ons
Diffstat (limited to 'httemplate/misc')
-rwxr-xr-x | httemplate/misc/change_pkg.cgi | 23 | ||||
-rw-r--r-- | httemplate/misc/cust_pkg_usageprice.html | 121 | ||||
-rw-r--r-- | httemplate/misc/order_pkg.html | 21 | ||||
-rw-r--r-- | httemplate/misc/xmlhttp-part_pkg_usageprice.html | 18 |
4 files changed, 155 insertions, 28 deletions
diff --git a/httemplate/misc/change_pkg.cgi b/httemplate/misc/change_pkg.cgi index e74747e82..b562d24cd 100755 --- a/httemplate/misc/change_pkg.cgi +++ b/httemplate/misc/change_pkg.cgi @@ -19,13 +19,13 @@ <& /elements/tr-select-cust-part_pkg.html, 'pre_label' => emt('New'), - 'curr_value' => scalar($cgi->param('pkgpart')), + 'curr_value' => scalar($cgi->param('pkgpart')) || $cust_pkg->pkgpart, 'classnum' => $part_pkg->classnum, 'cust_main' => $cust_main, &> <& /elements/tr-input-pkg-quantity.html, - 'curr_value' => $cust_pkg->quantity + 'curr_value' => scalar($cgi->param('quantity')) || $cust_pkg->quantity &> % if ($use_contract_end) { @@ -39,6 +39,11 @@ </TABLE> <BR> +<% include('/misc/cust_pkg_usageprice.html', + 'pkgpart' => (scalar($cgi->param('pkgpart')) || $cust_pkg->pkgpart), + 'pkgnum' => ($cust_pkg->change_to_pkgnum || $pkgnum), + ) %> +<BR> <FONT CLASS="fsinnerbox-title"><% mt('Change') |h %></FONT> <% ntable('#cccccc') %> @@ -49,8 +54,16 @@ document.getElementById('start_date_text').disabled = !enable; document.getElementById('start_date_button').style.display = (enable ? '' : 'none'); - document.getElementById('start_date_button_disabled').style.display = - (enable ? 'none' : ''); + if (document.getElementById('start_date_button_disabled')) { // does this ever exist anymore? + document.getElementById('start_date_button_disabled').style.display = + (enable ? 'none' : ''); + } + if (enable) { + usageprice_disable(1); + } else { + var form = document.OrderPkgForm; + usageprice_disable(0,form.pkgpart.options[form.pkgpart.selectedIndex].value); + } } <&| /elements/onload.js &> delay_changed(); @@ -96,7 +109,7 @@ TYPE = "button" VALUE = "<% mt("Change package") |h %>" onClick = "this.disabled=true; standardize_new_location();" - <% scalar($cgi->param('pkgpart')) ? '' : 'DISABLED' %> + <% #scalar($cgi->param('pkgpart')) ? '' : 'DISABLED' %> > </FORM> diff --git a/httemplate/misc/cust_pkg_usageprice.html b/httemplate/misc/cust_pkg_usageprice.html new file mode 100644 index 000000000..f2e0f57e6 --- /dev/null +++ b/httemplate/misc/cust_pkg_usageprice.html @@ -0,0 +1,121 @@ +<%doc> +Sets up the xmlhttp, javascript and initial (empty) table for selecting cust_pkg_usageprice. +Available values are based on pkgpart, and can be updated when changing pkgpart +by passing the new pkgpart to the following javascript: + + usageprice_pkg_changed( pkgpart, pkgnum ) + +The pkgnum input is optional, and will be used to set initial selected values. + +If pkgpart is passed as an option to this element, will run usageprice_pkg_changed +once to initialize table; pkgnum can be passed as an option along with this. + +You can disable usageprice selection temporarily (remove the fields from the form) +with the javascript usageprice_disable(1), and restore it with usageprice_disable(0,pkgnum). +While disabled, calling usageprice_pkg_changed will have no effect. +</%doc> + +<& /elements/xmlhttp.html, + 'url' => $p.'misc/xmlhttp-part_pkg_usageprice.html', + 'subs' => [ 'get_part_pkg_usageprice' ], +&> + +<FONT CLASS = "fsinnerbox-title" + ID = "cust_pkg_usageprice_title" + STYLE = "display:none" +><% mt('Usage add-ons') |h %></FONT> +<TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 ID="cust_pkg_usageprice_table"> + +</TABLE> + +<SCRIPT> + +var usagepriceCache = {}; +var usagepriceDisabled = 0; + +function usageprice_disable (disabled, pkgpart) { + if (disabled) { + usageprice_pkg_changed(0); + usagepriceDisabled = 1; + } else { + usagepriceDisabled = 0; + usageprice_pkg_changed(pkgpart); + } +} + +// main function to invoke when pkgpart changes +function usageprice_pkg_changed (pkgpart, pkgnum) { + if (usagepriceDisabled) return; + clear_part_pkg_usageprice(); + + if (pkgpart) { + if (usagepriceCache[pkgpart]) { + update_part_pkg_usageprice(pkgpart); + } else { + get_part_pkg_usageprice( pkgpart || 0, pkgnum || 0, download_part_pkg_usageprice ); + } + } +} + +// removes table rows & hides table title +function clear_part_pkg_usageprice () { + var table = document.getElementById('cust_pkg_usageprice_table'); + for ( var r = table.rows.length - 1; r >= 0; r-- ) { + table.deleteRow(r); + } + document.getElementById('cust_pkg_usageprice_title').style.display = 'none'; +} + +// catches response from xmlhttp request, updates cache & calls update function +function download_part_pkg_usageprice (part_pkg_usageprice) { + var usagepriceArray = JSON.parse(part_pkg_usageprice); + var pkgpart = usagepriceArray[0]; + usagepriceCache[pkgpart] = usagepriceArray; + update_part_pkg_usageprice(pkgpart); +} + +// updates from cache +function update_part_pkg_usageprice (pkgpart) { + if (usagepriceDisabled) return; + clear_part_pkg_usageprice(); + + var usagepriceArray = usagepriceCache[pkgpart]; + var table = document.getElementById('cust_pkg_usageprice_table'); + + // add the new usage price rows + var rownum = 0; + for ( var s = 1; s < usagepriceArray.length; s=s+2 ) { + var html = usagepriceArray[s]; + var javascript = usagepriceArray[s+1]; + + var row = table.insertRow(rownum++); + + var widget_cell = document.createElement('TD'); + widget_cell.style.paddingTop = "3px"; + widget_cell.colSpan = "2"; + widget_cell.innerHTML = html; + row.appendChild(widget_cell); + + } + + if ( rownum > 0 ) { + document.getElementById('cust_pkg_usageprice_title').style.display = ''; + } else { + document.getElementById('cust_pkg_usageprice_title').style.display = 'none'; + } + +} + +% if ($opt{'pkgpart'}) { +<&| /elements/onload.js &> +usageprice_pkg_changed(<% $opt{'pkgpart'} %>, <% $opt{'pkgnum'} %>); +</&> +% } + +</SCRIPT> + +<%init> +my %opt = @_; +</%init> + + diff --git a/httemplate/misc/order_pkg.html b/httemplate/misc/order_pkg.html index 799165fe0..cb2bd4832 100644 --- a/httemplate/misc/order_pkg.html +++ b/httemplate/misc/order_pkg.html @@ -5,11 +5,6 @@ } &> -<& /elements/xmlhttp.html, - 'url' => $p.'misc/xmlhttp-part_pkg_usageprice.html', - 'subs' => [ 'get_part_pkg_usageprice' ], -&> - <& /elements/init_calendar.html &> <SCRIPT TYPE="text/javascript" SRC="../elements/order_pkg.js"></SCRIPT> @@ -121,19 +116,9 @@ </TABLE><BR> -%#so: -%# - hide until you selecdt a pacakge with add-ons -%# -lookup and display the available add-ons when -%# -add them to the (recur if there is one, otherwise setup) price and display magically like processing fees do on edit/cust_pay.cgi - -%# better label? -<FONT CLASS = "fsinnerbox-title" - ID = "cust_pkg_usageprice_title" - STYLE = "display:none" -><% mt('Usage add-ons') |h %></FONT> -<TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 ID="cust_pkg_usageprice_table"> - -</TABLE> +<% include('/misc/cust_pkg_usageprice.html', + 'pkgpart' => $pkgpart + ) %> <BR> % my $discount_cust_pkg = $curuser->access_right('Discount customer package'); diff --git a/httemplate/misc/xmlhttp-part_pkg_usageprice.html b/httemplate/misc/xmlhttp-part_pkg_usageprice.html index d4e2d8469..9decdeff9 100644 --- a/httemplate/misc/xmlhttp-part_pkg_usageprice.html +++ b/httemplate/misc/xmlhttp-part_pkg_usageprice.html @@ -1,24 +1,32 @@ <% encode_json( \@return ) %>\ <%init> -my( $pkgpart ) = $cgi->param('arg'); +my( $pkgpart, $pkgnum ) = $cgi->param('arg'); #could worry about agent-virting this so you can't see the add-on pricing of # other agents, but not a real-world big worry my $part_pkg = qsearchs( 'part_pkg', { pkgpart=>$pkgpart } ); +my %curr_quantity; +if ($pkgnum) { + my $cust_pkg = qsearchs( 'cust_pkg', { pkgnum=>$pkgnum } ); + %curr_quantity = map { $_->usagepricepart, $_->quantity } $cust_pkg->cust_pkg_usageprice; +} + my $num = 0; -my @return = map { +# probably don't need to be returning js_only anymore? +my @return = ($pkgpart, map { + my $usagepricepart = $_->usagepricepart; my @inc = ('/elements/cust_pkg_usageprice.html', - 'usagepricepart' => $_->usagepricepart, + 'usagepricepart' => $usagepricepart, ); - + push(@inc,'curr_quantity',($curr_quantity{$usagepricepart} || 0)); ( include(@inc, field=>'usagepricenum'.$num, html_only=>1 ), include(@inc, field=>'usagepricenum'.$num++, js_only=>1 ), ); } - $part_pkg->part_pkg_usageprice; + $part_pkg->part_pkg_usageprice); </%init> |