fix new page logging
[freeside.git] / httemplate / edit / phone_device.html
1 <% include( 'elements/edit.html',
2                  'name'   => 'Phone device',
3                  'table'  => 'phone_device',
4                  'labels' => { 
5                                'devicenum'  => 'Device',
6                                'devicepart' => 'Device type',
7                                'mac_addr'   => 'MAC address',
8                              },
9                  'fields' => [ { 'field'    => 'devicepart',
10                                  'type'     => 'select-table',
11                                  'table'    => 'part_device',
12                                  'name_col' => 'devicename',
13                                  'onchange' => 'devicepart_changed',
14                                  'empty_label' =>'Select device type',
15                                  #'hashref'        =>{ disabled => '' },
16                                },
17                                { field => 'mac_addr',
18                                  type => 'select-mac',
19                                },
20                                { 'field' => 'svcnum',
21                                  'type'  => 'hidden',
22                                },
23                              ],
24                  'menubar' => [], #disable viewall
25                  #'viewall_dir' => 'browse',
26                  'new_callback' => sub {
27                                      my( $cgi, $object ) = @_;
28                                      $object->svcnum( $cgi->param('svcnum') );
29                                    },
30                  'html_foot' => $html_foot,
31            )
32 %>
33 <%init>
34
35 my @deviceparts_with_inventory =
36   map $_->devicepart,
37     qsearch({ 'table'     => 'part_device',
38               'extra_sql' => 'WHERE inventory_classnum IS NOT NULL',
39            });
40
41 my $html_foot = sub {
42     my $js = "
43 <SCRIPT TYPE=\"text/javascript\">
44
45   function opt(what,value,text) {
46     var optionName = new Option(text, value, false, false);
47     var length = what.length;
48     what.options[length] = optionName;
49   }
50
51     function devicepart_changed(what){
52         
53         var macsel = document.getElementById('sel_mac_addr');
54         var mac = document.getElementById('mac_addr');
55         
56         function update_macs(macs) {
57             for ( var i = macsel.length; i >= 0; i-- )
58               macsel.options[i] = null;
59             
60             var macArray = eval('(' + macs + ')' );
61             if(macArray.length == 0) 
62                 opt(macsel,'','No MAC addresses found in inventory for this device type');
63             else
64                 opt(macsel,'','Select MAC address');
65
66             for ( var i = 0; i < macArray.length; i++ ) {
67                 opt(macsel,macArray[i],macArray[i]);
68             }
69
70         }
71
72         var devicepart = what.options[what.selectedIndex].value;
73
74         var deviceparts_with_inventory = new Array(";
75 $js .= join(',', map qq("$_"), @deviceparts_with_inventory);
76 $js .= ");
77
78         var hasInventory = false;
79         for ( i = 0; i < deviceparts_with_inventory.length; i++ ) {
80             if ( deviceparts_with_inventory[i] == devicepart ) 
81                 hasInventory = true;
82         }
83         
84
85         if(hasInventory) { // do the AJAX thing, disable text field
86             macsel.style.display = 'inline';
87             mac.style.display = 'none';
88             mac.value = '';
89             get_macs( devicepart, update_macs );
90         } else { // clear & display text field only, clear/hide select
91             mac.style.display = 'inline';
92             macsel.style.display = 'none';
93             macsel.selectedIndex = 0;
94         }
95
96     }
97
98     devicepart_changed(document.getElementById('devicepart'));
99 </SCRIPT>";
100
101   $js;
102 };
103
104 # :/  needs agent-virt so you can't futz with arbitrary devices
105
106 die "access denied"
107   unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?
108
109
110 </%init>