fix package selection with classes in IE8, RT#12377
[freeside.git] / httemplate / elements / tr-select-cust-part_pkg.html
1 %if ( scalar(@pkg_class) > 1 && ! $conf->exists('disable-cust-pkg_class') ) {
2
3   <% include('/elements/xmlhttp.html',
4                 'url'  => $p.'misc/cust-part_pkg.cgi',
5                 'subs' => [ 'get_part_pkg' ],
6             )
7   %>
8
9   <SCRIPT TYPE="text/javascript">
10
11     function part_pkg_opt(what,value,text,can_discount) {
12       var optionName = new Option(text, value, false, false);
13       optionName.setAttribute('data-can_discount', can_discount);
14       var length = what.length;
15       what.options[length] = optionName;
16     }
17
18     function classnum_changed(what) {
19
20       what.form.pkgpart.disabled = 'disabled'; //disable part_pkg dropdown
21       var submitButton = what.form.submitButton; // || what.form.submit;
22       if ( submitButton ) {
23         submitButton.disabled = true; //disable the submit button
24       }
25       var discountnum = what.form.discountnum;
26       if ( discountnum ) {
27         discountnum.disabled = true; //disable discount dropdown
28       }
29
30       classnum = what.options[what.selectedIndex].value;
31
32       function update_part_pkg(part_pkg) {
33
34         // blank the current packages
35         for ( var i = what.form.pkgpart.length; i>= 0; i-- )
36           what.form.pkgpart.options[i] = null;
37
38         // add the new packages
39         opt(what.form.pkgpart, '', 'Select package');
40         var packagesArray = eval('(' + part_pkg + ')' );
41         for ( var s = 0; s < packagesArray.length; s=s+3 ) {
42           var packagesLabel = packagesArray[s+1];
43           var can_discount  = packagesArray[s+2];
44           part_pkg_opt(
45             what.form.pkgpart, packagesArray[s], packagesLabel, can_discount
46           );
47         }
48
49         what.form.pkgpart.disabled = ''; //re-enable part_pkg dropdown
50
51       }
52
53       get_part_pkg( <% $cust_main->custnum %>, classnum, update_part_pkg );
54     
55     }
56
57   </SCRIPT>
58
59   <TR>
60     <TH ALIGN="right">Package Class</TH>
61     <TD COLSPAN=7>
62       <% include('/elements/select-cust-pkg_class.html',
63                    'curr_value' => $opt{'classnum'},
64                    'pkg_class'  => \@pkg_class,
65                    'onchange'   => 'classnum_changed',
66                 )
67       %>
68     </TD>
69   </TR>
70
71 %}
72
73 <TR>
74   <TH ALIGN="right">Package</TH>
75   <TD COLSPAN=7>
76     <% include('/elements/select-cust-part_pkg.html',
77                  'curr_value' => $opt{'curr_value'}, #$pkgpart
78                  'classnum'   => $opt{'classnum'},
79                  'cust_main'  => $opt{'cust_main'},  #$cust_main
80                  'onchange'   => 'enable_order_pkg',
81               )
82     %>
83   </TD>
84 </TR>
85
86 <%init>
87
88 my $conf = new FS::Conf;
89
90 my %opt = @_;
91
92 my $pre_label = $opt{'pre_label'} || '';
93 $pre_label .= ' ' if length($pre_label) && $pre_label =~ /\S$/;
94
95 my $cust_main = $opt{'cust_main'}
96   or die "cust_main not specified";
97
98 #my @pkg_class = sort { $a->classname cmp $b->classname }
99 #                     qsearch( 'pkg_class', { 'disabled' => '' } );
100
101 #"normal" part_pkg agent virtualization (agentnum or type)
102 my @part_pkg = qsearch({
103   'select'    => 'DISTINCT classnum',
104   'table'     => 'part_pkg',
105   'hashref'   => { 'disabled' => '' },
106   'extra_sql' =>
107     ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql( 'null'=>1 ).
108     ' AND '. FS::part_pkg->agent_pkgs_sql( $opt{'cust_main'}->agent ),
109 });
110
111 my @pkg_class =
112   sort { $a->classname cmp $b->classname } #should get a sort order in config
113   map  { $_->pkg_class || new FS::pkg_class { 'classnum'  => '',
114                                               'classname' => '(none)' }
115        }
116   @part_pkg;
117
118 </%init>