From 978862f11a10e6a0a8b6010d22be3f15bf7ea8f5 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Wed, 6 Mar 2013 16:32:44 -0800 Subject: [PATCH] cleanup phone devices, RT#21623 --- httemplate/edit/phone_device.html | 17 ++-- httemplate/elements/select-mac.html | 2 +- httemplate/misc/macinventory.cgi | 9 +- 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' ) %> 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; -} - 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 @@ ) -<% $devices %> +%if ( @devices || $num_part_device || $table eq 'dsl_device' ) { +% my $svcnum = $svc_x->svcnum; + + Devices + (Add device) +
+ +% if ( @devices ) { + + + + <& /elements/table-grid.html &> + +% if ( $table eq 'phone_device' ) { + Type +% } + MAC Addr + + + + +% my $bgcolor1 = '#eeeeee'; +% my $bgcolor2 = '#ffffff'; +% my $bgcolor = ''; +% +% foreach my $device ( @devices ) { +% +% if ( $bgcolor eq $bgcolor1 ) { +% $bgcolor = $bgcolor2; +% } else { +% $bgcolor = $bgcolor1; +% } +% +% my $td = qq(); +% +% my $devicenum = $device->devicenum; +% my $export_links = ''; +% $export_links = join( '
', @{ $device->export_links } ) +% if $device->can('export_links'); + + +% if ( $table eq 'phone_device' ) { #$devices->can('part_device') + <% $td %><% $device->part_device->devicename |h %> +% } + <% $td %><% $device->mac_addr %> + <% $td %><% $export_links %> + <% $td %>( +% unless ( $opt{'no_edit'} ) { + edit | +% } + delete + ) + +% } + +
+ +% } +
+%} <%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 (Add device)
]; - if ( @devices ) { - - $devices .= qq! - - !; - - - $devices .= - include('/elements/table-grid.html'). - ''; - - $devices .= - 'Type' - if $table eq 'phone_device'; - - $devices .= - 'MAC Addr'. - ''. - ''. - ''; - my $bgcolor1 = '#eeeeee'; - my $bgcolor2 = '#ffffff'; - my $bgcolor = ''; - - foreach my $device ( @devices ) { - - if ( $bgcolor eq $bgcolor1 ) { - $bgcolor = $bgcolor2; - } else { - $bgcolor = $bgcolor1; - } - my $td = qq(); - - my $devicenum = $device->devicenum; - my $export_links = join( '
', @{ $device->export_links } ) - if $device->can('export_links'); - - $devices .= ''; - $devices .= $td. $device->part_device->devicename. '' - if $table eq 'phone_device'; #$devices->can('part_device'); - - $devices .= $td. $device->mac_addr. ''. - $td. $export_links. ''. - "$td( "; - - $devices .= qq(edit | ) - unless $opt{'no_edit'}; - - $devices .= qq(delete). - ' )'. - ''; - } - $devices .= '
'; - } - $devices .= '
'; - } +my @devices = $svc_x->$table(); -- 2.11.0