diff options
| -rw-r--r-- | httemplate/edit/phone_device.html | 17 | ||||
| -rw-r--r-- | httemplate/elements/select-mac.html | 2 | ||||
| -rw-r--r-- | httemplate/misc/macinventory.cgi | 9 | ||||
| -rw-r--r-- | httemplate/view/elements/svc_devices.html | 159 | 
4 files changed, 88 insertions, 99 deletions
diff --git a/httemplate/edit/phone_device.html b/httemplate/edit/phone_device.html index 4aec63e5a..7bc88a8c7 100644 --- a/httemplate/edit/phone_device.html +++ b/httemplate/edit/phone_device.html @@ -32,12 +32,11 @@  %>  <%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 @deviceparts_with_inventory = +  map $_->devicepart, +    qsearch({ 'table'     => 'part_device', +              'extra_sql' => 'WHERE inventory_classnum IS NOT NULL', +           });  my $html_foot = sub {      my $js = " @@ -72,9 +71,9 @@ my $html_foot = sub {  	var devicepart = what.options[what.selectedIndex].value; -	var deviceparts_with_inventory = new Array(\""; -$js .= join("\",\"",@deviceparts_with_inventory); -$js .= "\"); +	var deviceparts_with_inventory = new Array("; +$js .= join(',', map qq("$_"), @deviceparts_with_inventory); +$js .= ");  	var hasInventory = false;  	for ( i = 0; i < deviceparts_with_inventory.length; i++ ) { diff --git a/httemplate/elements/select-mac.html b/httemplate/elements/select-mac.html index 8b1c71fea..4b406fce0 100644 --- a/httemplate/elements/select-mac.html +++ b/httemplate/elements/select-mac.html @@ -7,7 +7,7 @@  <% include( '/elements/input-text.html', %opt, 'type'=>'text' ) %>  <SELECT ID="<% $opt{'prefix'} %>sel_mac_addr" NAME="<% $opt{'prefix'} %>sel_mac_addr"  -    notonChange="<% $opt{'prefix'} %>mac_addr_changed(this); <% $opt{'onchange'} %>" +%#    notonChange="<% $opt{'prefix'} %>mac_addr_changed(this); <% $opt{'onchange'} %>"      <% $opt{'disabled'} %> STYLE="display: none">    <OPTION VALUE="">Select MAC address</OPTION>  </SELECT> diff --git a/httemplate/misc/macinventory.cgi b/httemplate/misc/macinventory.cgi index b07da9726..7ed5c6607 100644 --- a/httemplate/misc/macinventory.cgi +++ b/httemplate/misc/macinventory.cgi @@ -13,13 +13,8 @@ die "unknown devicepart $devicepart" unless $part_device;  my $inventory_class = $part_device->inventory_class;  die "devicepart $devicepart has no inventory" unless $inventory_class; -my @inventory_item = +my @macs = +  map $_->item,      qsearch('inventory_item', { 'classnum' => $inventory_class->classnum } ); -my @macs; - -foreach my $inventory_item ( @inventory_item ) { -    push @macs, $inventory_item->item; -} -  </%init> diff --git a/httemplate/view/elements/svc_devices.html b/httemplate/view/elements/svc_devices.html index d71c82f07..38c6d0919 100644 --- a/httemplate/view/elements/svc_devices.html +++ b/httemplate/view/elements/svc_devices.html @@ -12,91 +12,86 @@           )  </%doc> -<% $devices %> +%if ( @devices || $num_part_device || $table eq 'dsl_device' ) { +%  my $svcnum = $svc_x->svcnum; + +   Devices +   (<A HREF="<%$p%>edit/<%$table%>.html?svcnum=<%$svcnum%>">Add device</A>) +   <BR> + +%  if ( @devices ) { + +     <SCRIPT> +       function areyousure(href) { +        if (confirm("Are you sure you want to delete this device?") == true) +          window.location.href = href; +       } +     </SCRIPT> + +     <& /elements/table-grid.html &> +       <TR> +%        if ( $table eq 'phone_device' ) { +           <TH CLASS="grid" BGCOLOR="#cccccc">Type</TH> +%        } +         <TH CLASS="grid" BGCOLOR="#cccccc">MAC Addr</TH> +         <TH CLASS="grid" BGCOLOR="#cccccc"></TH> +         <TH CLASS="grid" BGCOLOR="#cccccc"></TH> +       </TR> + +%      my $bgcolor1 = '#eeeeee'; +%      my $bgcolor2 = '#ffffff'; +%      my $bgcolor = ''; +% +%      foreach my $device ( @devices ) { +% +%        if ( $bgcolor eq $bgcolor1 ) { +%          $bgcolor = $bgcolor2; +%        } else { +%          $bgcolor = $bgcolor1; +%        } +% +%        my $td = qq(<TD CLASS="grid" BGCOLOR="$bgcolor">); +% +%        my $devicenum = $device->devicenum; +%        my $export_links = ''; +%        $export_links = join( '<BR>', @{ $device->export_links } ) +%          if $device->can('export_links'); + +        <TR> +%         if ( $table eq 'phone_device' ) { #$devices->can('part_device') +            <% $td %><% $device->part_device->devicename |h %></TD> +%         } +          <% $td %><% $device->mac_addr %></TD> +          <% $td %><% $export_links %></TD> +          <% $td %>( +%           unless ( $opt{'no_edit'} ) { +              <A HREF="<%$p%>edit/<%$table%>.html?<%$devicenum%>">edit</A> | +%           } +            <A HREF="javascript:areyousure('<%$p%>misc/delete-<%$table%>.html?<%$devicenum%>')">delete</A> +          )</TD> +        </TR> +%     } +      </TABLE> +      <BR> + +%  } +   <BR> +%}  <%init> -  my %opt = @_; -  my $table = $opt{'table'}; #part_device, dsl_device -  my $svc_x = $opt{'svc_x'}; - -  my $devices = ''; - -  my $num_part_device = 0; -  if ( $table eq 'phone_device' )  { -    my $sth = dbh->prepare("SELECT COUNT(*) FROM part_device") -                              #WHERE disabled = '' OR disabled IS NULL;"); -      or die dbh->errstr; -    $sth->execute or die $sth->errstr; -    $num_part_device = $sth->fetchrow_arrayref->[0]; +my %opt = @_; +my $table = $opt{'table'}; #part_device, dsl_device +my $svc_x = $opt{'svc_x'}; + +my $num_part_device = 0; +if ( $table eq 'phone_device' ) { +  my $sth = dbh->prepare("SELECT COUNT(*) FROM part_device") +                            #WHERE disabled = '' OR disabled IS NULL;"); +    or die dbh->errstr; +  $sth->execute or die $sth->errstr; +  $num_part_device = $sth->fetchrow_arrayref->[0];  } -  my @devices = $svc_x->$table(); - -  #should move the below to proper mason code above instead of making $devices -  if ( @devices || $num_part_device || $table eq 'dsl_device' ) { -    my $svcnum = $svc_x->svcnum; -    $devices .= -      qq[Devices (<A HREF="${p}edit/$table.html?svcnum=$svcnum">Add device</A>)<BR>]; -    if ( @devices ) { - -      $devices .= qq! -        <SCRIPT> -          function areyousure(href) { -           if (confirm("Are you sure you want to delete this device?") == true) -             window.location.href = href; -          } -        </SCRIPT> -      !; - - -      $devices .=  -        include('/elements/table-grid.html'). -          '<TR>'; - -      $devices .= -            '<TH CLASS="grid" BGCOLOR="#cccccc">Type</TH>' -        if $table eq 'phone_device'; - -      $devices .= -            '<TH CLASS="grid" BGCOLOR="#cccccc">MAC Addr</TH>'. -            '<TH CLASS="grid" BGCOLOR="#cccccc"></TH>'. -            '<TH CLASS="grid" BGCOLOR="#cccccc"></TH>'. -          '</TR>'; -      my $bgcolor1 = '#eeeeee'; -      my $bgcolor2 = '#ffffff'; -      my $bgcolor = ''; - -      foreach my $device ( @devices ) { - -        if ( $bgcolor eq $bgcolor1 ) { -          $bgcolor = $bgcolor2; -        } else { -          $bgcolor = $bgcolor1; -        } -        my $td = qq(<TD CLASS="grid" BGCOLOR="$bgcolor">); - -        my $devicenum = $device->devicenum; -        my $export_links = join( '<BR>', @{ $device->export_links } ) -          if $device->can('export_links'); - -        $devices .= '<TR>'; -        $devices .= $td. $device->part_device->devicename. '</TD>' -          if $table eq 'phone_device'; #$devices->can('part_device'); - -        $devices .=   $td. $device->mac_addr. '</TD>'. -                      $td. $export_links. '</TD>'. -                      "$td( "; - -        $devices .= qq(<A HREF="${p}edit/$table.html?$devicenum">edit</A> | ) -          unless $opt{'no_edit'}; - -        $devices .= qq(<A HREF="javascript:areyousure('${p}misc/delete-$table.html?$devicenum')">delete</A>). -                      ' )</TD>'. -                    '</TR>'; -      } -      $devices .= '</TABLE><BR>'; -    } -    $devices .= '<BR>'; -  } +my @devices = $svc_x->$table();  </%init>  | 
