delete inventory items, #24386
authorMark Wells <mark@freeside.biz>
Tue, 6 Aug 2013 23:27:28 +0000 (16:27 -0700)
committerMark Wells <mark@freeside.biz>
Tue, 6 Aug 2013 23:27:28 +0000 (16:27 -0700)
httemplate/misc/inventory_item-move.cgi
httemplate/search/elements/checkbox-foot.html
httemplate/search/inventory_item.html

index 4d53beb..6b2ab14 100644 (file)
@@ -1,21 +1,37 @@
 <% '',$cgi->redirect(popurl(2). "search/inventory_item.html?$browse_opts") %>
 <%init>
 <% '',$cgi->redirect(popurl(2). "search/inventory_item.html?$browse_opts") %>
 <%init>
+die "access denied" unless $FS::CurrentUser::CurrentUser->access_right(
+    [ 'Edit inventory', 'Edit global inventory' ]
+  );
 
 
-# Shamelessly copied from misc/cust_attachment.cgi.
 
 my $browse_opts = join(';', map { $_.'='.$cgi->param($_) }
     qw( classnum avail )
     );
 
 
 my $browse_opts = join(';', map { $_.'='.$cgi->param($_) }
     qw( classnum avail )
     );
 
-my $move_agentnum = $cgi->param('move_agentnum') or 
-  die "No agent selected";
-foreach my $itemnum (
-  map { /^itemnum(\d+)$/; $1; } grep /^itemnum\d+$/, $cgi->param ) {
-  my $item = qsearchs('inventory_item', { 'itemnum' => $itemnum });
+
+my $move_agentnum;
+if ( $cgi->param('move') ) {
+ $move_agentnum = $cgi->param('move_agentnum') or 
+    die "No agent selected";
+} elsif ( $cgi->param('delete') ) {
+  # don't need it in this case
+} else {
+  die "No action selected";
+}
+
+foreach my $itemnum ( grep /^\d+$/, $cgi->param('itemnum') )
+{
+  my $item = FS::inventory_item->by_key($itemnum) or next;
+#  UI disallows this
 #  die "Can't move assigned inventory item $itemnum" if $item->svcnum;
   my $error;
 #  die "Can't move assigned inventory item $itemnum" if $item->svcnum;
   my $error;
-  $item->agentnum($move_agentnum);
-  $error = $item->replace;
+  if ( $cgi->param('move') ) {
+    $item->agentnum($move_agentnum);
+    $error = $item->replace;
+  } elsif ( $cgi->param('delete') ) {
+    $error = $item->delete;
+  }
   die $error if $error;
 }
 
   die $error if $error;
 }
 
index be1caab..cc4bac6 100644 (file)
@@ -26,7 +26,8 @@ array is a hashref of either:
 of "submit" becomes the "value" property of the button (and thus its label).
 If "confirm" is specified, the button will have an onclick handler that 
 displays the value of "confirm" in a popup message box and asks the user to 
 of "submit" becomes the "value" property of the button (and thus its label).
 If "confirm" is specified, the button will have an onclick handler that 
 displays the value of "confirm" in a popup message box and asks the user to 
-confirm the choice.
+confirm the choice.  The hashref may also have a "name" property, which 
+sets the name of the submit button.
 
 - "onclick" and "label".  Creates a non-submit button that executes the 
 Javascript code in "onclick".  "label" is used as the text of the button.
 
 - "onclick" and "label".  Creates a non-submit button that executes the 
 Javascript code in "onclick".  "label" is used as the text of the button.
index 0e4251f..d827734 100644 (file)
                               '',
                               FS::UI::Web::cust_styles(),
                             ],
                               '',
                               FS::UI::Web::cust_styles(),
                             ],
-                  'html_form' => 
-                    qq!
-<FORM NAME="itemForm" ACTION="$p/misc/inventory_item-move.cgi" METHOD="POST">
-<INPUT TYPE="hidden" NAME="classnum" VALUE="$classnum">
-<INPUT TYPE="hidden" NAME="avail"    VALUE="! .$cgi->param('avail') . '">', #'
-                  'html_foot' => $sub_foot,
+                  'html_init' => $html_form,
+                  'html_foot' => $html_foot,
              
 &>
 <%init>
              
 &>
 <%init>
@@ -158,41 +154,39 @@ my $addl_from = ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
                 ' LEFT JOIN part_svc  USING ( svcpart ) '.
                 ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
                 FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg');
                 ' LEFT JOIN part_svc  USING ( svcpart ) '.
                 ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
                 FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg');
-my $areboxes = 0;
 
 my $sub_checkbox = sub {
   my $item = $_[0];
   my $itemnum = $item->itemnum;
 
 my $sub_checkbox = sub {
   my $item = $_[0];
   my $itemnum = $item->itemnum;
-  #return '' if $item->svcnum;
-  $areboxes = 1;
-  return qq!<INPUT NAME="itemnum$itemnum" TYPE="checkbox" VALUE="1">!;
-};
+  return '' if $item->svcnum;
 
 
-my $sub_foot = sub {
-  return if !$areboxes;
-  my $foot =
-'<BR><INPUT TYPE="button" VALUE="Select all" onClick="setAll(true)">
-<INPUT TYPE="button" VALUE="Unselect all" onClick="setAll(false)">
-<BR><INPUT TYPE="submit" NAME="action" VALUE="Move to agent">
-<SELECT NAME="move_agentnum">';
-  foreach my $agent ($curuser->agents) {
-    $foot .= '<OPTION VALUE="'.$agent->agentnum.'">'.
-             $agent->agent . '</OPTION>
-             ';
-  }
-  $foot .= '</SELECT>
-<SCRIPT TYPE="text/javascript">
- function setAll(setTo) {
-   theForm = document.itemForm;
-   for (i=0,n=theForm.elements.length;i<n;i++)
-     if (theForm.elements[i].name.indexOf("itemnum") != -1)
-       theForm.elements[i].checked = setTo;
- }
-</SCRIPT>';
-  $foot;
+  return qq!<INPUT NAME="itemnum" TYPE="checkbox" VALUE="$itemnum">!;
 };
 };
-    
 
 
-  
+my $html_form = qq!
+<FORM NAME="itemForm" ACTION="$p/misc/inventory_item-move.cgi" METHOD="POST">
+<INPUT TYPE="hidden" NAME="classnum" VALUE="$classnum">
+<INPUT TYPE="hidden" NAME="avail"    VALUE="! .$cgi->param('avail') . '">';
+#'
+
+my $html_foot = include('elements/checkbox-foot.html',
+      actions => [
+          { submit  => 'Delete',
+            confirm => 'Delete the selected items?',
+            name    => 'delete',
+          },
+          { submit  => 'Move to',
+            name    => 'move',
+          },
+      ],
+);
+
+$html_foot =~ s[</DIV>][];
+$html_foot .= 
+  include('/elements/select-agent.html',
+    'field'         => 'move_agentnum',
+    'disable_empty' => 1,
+  ) .
+  '</DIV></FORM>';
 
 </%init>
 
 </%init>