v4 style
[freeside.git] / httemplate / elements / tr-select-cust-part_pkg.html
index 8431beb..f4af405 100644 (file)
@@ -1,5 +1,3 @@
-%if ( scalar(@pkg_class) > 1 && ! $conf->exists('disable-cust-pkg_class') ) {
-
   <& /elements/xmlhttp.html,
                 'url'  => $p.'misc/cust-part_pkg.cgi',
                 'subs' => [ 'get_part_pkg' ],
@@ -7,9 +5,10 @@
 
   <SCRIPT TYPE="text/javascript">
 
-    function part_pkg_opt(what, value, text, can_discount, can_start_date, start_date) {
+    function part_pkg_opt(what, value, text, can_discount, start_on_hold, can_start_date, start_date) {
       var optionName = new Option(text, value, false, false);
       optionName.setAttribute('data-can_discount',   can_discount);
+      optionName.setAttribute('data-start_on_hold',  start_on_hold);
       optionName.setAttribute('data-can_start_date', can_start_date);
       optionName.setAttribute('data-start_date',     start_date || '');
       var length = what.length;
@@ -28,7 +27,7 @@
         discountnum.disabled = true; //disable discount dropdown
       }
 
-      classnum = what.options[what.selectedIndex].value;
+      classnum = what.value;
 
       function update_part_pkg(part_pkg) {
 
         // add the new packages
         opt(what.form.pkgpart, '', 'Select package');
         var packagesArray = eval('(' + part_pkg + ')' );
-        for ( var s = 0; s < packagesArray.length; s=s+5 ) {
+        while (packagesArray.length > 0) {
           //surely this should be some kind of JSON structure
-          var packagesLabel  = packagesArray[s+1];
-          var can_discount   = packagesArray[s+2];
-          var can_start_date = packagesArray[s+3];
-          var start_date     = packagesArray[s+4];
+          var pkgpart        = packagesArray.shift();
+          var label          = packagesArray.shift();
+          var can_discount   = packagesArray.shift();
+          var start_on_hold  = packagesArray.shift();
+          var can_start_date = packagesArray.shift();
+          var start_date     = packagesArray.shift();
           part_pkg_opt(
-            what.form.pkgpart, packagesArray[s], packagesLabel, can_discount, can_start_date, start_date
+            what.form.pkgpart, pkgpart, label, can_discount, start_on_hold, can_start_date, start_date
           );
         }
 
         what.form.pkgpart.disabled = ''; //re-enable part_pkg dropdown
 %       if ( $opt{'curr_value'} ) {
-        what.form.pkgpart.value = <% $opt{'curr_value'} %>;
+          what.form.pkgpart.value = <% $opt{'curr_value'} %>;
 %       }
 
+        pkg_changed();
+
       }
 
       get_part_pkg( <% $cust_main     ? $cust_main->custnum         : '0' %>,
@@ -70,6 +73,7 @@
 
   </SCRIPT>
 
+% if ( scalar(@pkg_class) > 1 && ! $conf->exists('disable-cust-pkg_class') ) {
   <TR>
     <TH ALIGN="right"><% mt('Package Class') |h %></TH>
     <TD COLSPAN=7>
     </TD>
   </TR>
 
-%}
+% } else { # so that the rest of the page works correctly
+  <INPUT TYPE="hidden" ID="classnum" NAME="classnum" VALUE="-1">
+% }
 
 <TR>
   <TH ALIGN="right"><% mt('Package') |h %></TH>
   <TD COLSPAN=7>
     <& /elements/select-cust-part_pkg.html,
-                 'curr_value'    => $opt{'curr_value'}, #$pkgpart
-                 'classnum'      => $opt{'classnum'},
-                 'cust_main'     => $opt{'cust_main'},  #$cust_main
-                 'prospect_main' => $opt{'prospect_main'},  #$prospect_main
-                 'onchange'      => 'pkg_changed',
+                 'curr_value'     => $opt{'curr_value'}, #$pkgpart
+                 'classnum'       => $opt{'classnum'},
+                 'cust_main'      => $opt{'cust_main'},  #$cust_main
+                 'prospect_main'  => $opt{'prospect_main'},  #$prospect_main
+                 'onchange'       => 'pkg_changed',
+                 'label_callback' => sub { shift->pkg_comment },
     &>
   </TD>
 </TR>