[freeside-commits] freeside/httemplate/edit part_device.html, 1.4, 1.5 phone_device.html, 1.1, 1.2

Erik Levinson levinse at wavetail.420.am
Sat Jan 22 12:03:52 PST 2011


Update of /home/cvs/cvsroot/freeside/httemplate/edit
In directory wavetail.420.am:/tmp/cvs-serv30702/httemplate/edit

Modified Files:
	part_device.html phone_device.html 
Log Message:
populate MAC address from inventory for svc_phone devices, RT7794

Index: phone_device.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/edit/phone_device.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- phone_device.html	30 Jun 2009 01:42:55 -0000	1.1
+++ phone_device.html	22 Jan 2011 20:03:50 -0000	1.2
@@ -10,10 +10,13 @@
                                  'type'     => 'select-table',
                                  'table'    => 'part_device',
                                  'name_col' => 'devicename',
+				 'onchange' => 'devicepart_changed',
                                  'empty_label' =>'Select device type',
                                  #'hashref'        =>{ disabled => '' },
                                },
-                               'mac_addr',
+			       { field => 'mac_addr',
+			         type => 'select-mac',
+			       },
                                { 'field' => 'svcnum',
                                  'type'  => 'hidden',
                                },
@@ -24,10 +27,79 @@
                                      my( $cgi, $object ) = @_;
                                      $object->svcnum( $cgi->param('svcnum') );
                                    },
+		 'html_foot' => $html_foot,
            )
 %>
 <%init>
 
+my @deviceparts_with_inventory;
+my @part_device = qsearch('part_device', {} );
+foreach my $part_device ( @part_device ) {
+    push @deviceparts_with_inventory, $part_device->devicepart
+	if $part_device->inventory_classnum;
+}
+
+my $html_foot = sub {
+    my $js = "
+<SCRIPT TYPE=\"text/javascript\">
+
+  function opt(what,value,text) {
+    var optionName = new Option(text, value, false, false);
+    var length = what.length;
+    what.options[length] = optionName;
+  }
+
+    function devicepart_changed(what){
+	
+	var macsel = document.getElementById('sel_mac_addr');
+	var mac = document.getElementById('mac_addr');
+	
+	function update_macs(macs) {
+	    for ( var i = macsel.length; i >= 0; i-- )
+	      macsel.options[i] = null;
+	    
+	    var macArray = eval('(' + macs + ')' );
+	    if(macArray.length == 0) 
+		opt(macsel,'','No MAC addresses found in inventory for this device type');
+	    else
+		opt(macsel,'','Select MAC address');
+
+	    for ( var i = 0; i < macArray.length; i++ ) {
+		opt(macsel,macArray[i],macArray[i]);
+	    }
+
+	}
+
+	var devicepart = what.options[what.selectedIndex].value;
+
+	var deviceparts_with_inventory = new Array(\"";
+$js .= join("\",\"", at deviceparts_with_inventory);
+$js .= "\");
+
+	var hasInventory = false;
+	for ( i = 0; i < deviceparts_with_inventory.length; i++ ) {
+	    if ( deviceparts_with_inventory[i] == devicepart ) 
+		hasInventory = true;
+	}
+	
+
+	if(hasInventory) { // do the AJAX thing, disable text field
+	    macsel.style.display = 'inline';
+	    mac.style.display = 'none';
+	    mac.value = '';
+	    get_macs( devicepart, update_macs );
+	} else { // clear & display text field only, clear/hide select
+	    mac.style.display = 'inline';
+	    macsel.style.display = 'none';
+	    macsel.selectedIndex = 0;
+	}
+
+    }
+</SCRIPT>";
+
+  $js;
+};
+
 # :/  needs agent-virt so you can't futz with arbitrary devices
 
 die "access denied"

Index: part_device.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/edit/part_device.html,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -d -r1.4 -r1.5
--- part_device.html	5 Mar 2010 19:02:41 -0000	1.4
+++ part_device.html	22 Jan 2011 20:03:50 -0000	1.5
@@ -4,7 +4,9 @@
                  'labels' => { 
                                'devicepart' => 'Part number',
                                'devicename' => 'Device name',
+			       'inventory_classnum' => 'Inventory class',
                              },
+		 'fields' => \@fields,
                  'viewall_dir' => 'browse',
                  'html_bottom' => $html_bottom_sub,
            )
@@ -20,6 +22,24 @@
       );
 $extra_sql = $extra_sql ? " WHERE ( $extra_sql ) " : " WHERE 0 = 1 ";
 
+my @inventory_classnums;
+push @inventory_classnums, '';
+my %inventory_classnum_labels;
+$inventory_classnum_labels{''} = '';
+my @inventory_classes = qsearch('inventory_class', {} );
+foreach my $inventory_class ( @inventory_classes ) {
+    push @inventory_classnums, $inventory_class->classnum;
+    $inventory_classnum_labels{$inventory_class->classnum} = $inventory_class->classname;
+}
+			
+my @fields;
+push @fields, 'devicename',
+	      { field => 'inventory_classnum', 
+		type => 'select',
+		options => \@inventory_classnums,
+		labels => \%inventory_classnum_labels,
+	      };
+
 my $html_bottom_sub = sub {
   my $part_device = shift;
 



More information about the freeside-commits mailing list