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