webstaff: Confirm before deleting; Allow prediction from empty list
authorMike Rylander <mrylander@gmail.com>
Tue, 16 May 2017 18:40:02 +0000 (14:40 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 30 May 2017 16:06:45 +0000 (12:06 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/serials/index.tt2
Open-ILS/src/templates/staff/serials/t_view_items_grid.tt2
Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js

index 0555ed4..efa0b0a 100644 (file)
@@ -26,6 +26,9 @@ angular.module('egCoreMod').run(['egStrings', function(s) {
     s.SERIALS_EDIT_SISS_HC = "[% l('Edit issue information') %]";
     s.SERIALS_ISSUANCE_PREDICT = "[% l('Predict New Issues: Initial Values') %]";
     s.SERIALS_ISSUANCE_ADD = "[% l('Add folloing issue') %]";
+    s.CONFIRM_DELETE_ITEMS = "[% l('Delete selected items?') %]";
+    s.CONFIRM_DELETE_ITEMS_MESSAGE = "[% l('Will delete {{items}} items') %]";
+
 }]);
 </script>
 [% END %]
index 0fed1a1..22afd4a 100644 (file)
 
     <eg-grid-field label="[% l('Distribution Library') %]" path="stream.distribution.holding_lib.name" visible></eg-grid-field>
     <eg-grid-field label="[% l('Issuance') %]" path="issuance.label" visible></eg-grid-field>
-    <eg-grid-field label="[% l('Publication Date') %]" path="issuance.date_published" visible></eg-grid-field>
+    <eg-grid-field label="[% l('Publication Date') %]" path="issuance.date_published" visible>{{item.issuance.date_published|date:'shortDate'}}</eg-grid-field>
+    <eg-grid-field label="[% l('Status') %]" path="status" visible></eg-grid-field>
+    <eg-grid-field label="[% l('Date Expected') %]" path="date_expected" visible>{{item.date_expected|date:'shortDate'}}</eg-grid-field>
+    <eg-grid-field label="[% l('Date Received') %]" path="date_received" visible>{{item.date_received|date:'shortDate'}}</eg-grid-field>
     <eg-grid-field label="[% l('Holding Type') %]" path="issuance.holding_type" visible></eg-grid-field>
     <eg-grid-field label="[% l('Route To') %]" path="stream.routing_label"></eg-grid-field>
     <eg-grid-field label="[% l('Receiving Template') %]" path="stream.distribution.receive_unit_template.name" visible></eg-grid-field>
index 9b854bd..745d2dc 100644 (file)
@@ -11,9 +11,9 @@ angular.module('egSerialsAppDep')
         templateUrl: './serials/t_view_items_grid',
         controller:
        ['$scope','$q','egSerialsCoreSvc','egCore','egGridDataProvider',
-        '$uibModal','ngToast',
+        '$uibModal','ngToast','egConfirmDialog',
 function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
-         $uibModal , ngToast) {
+         $uibModal , ngToast , egConfirmDialog) {
 
     $scope.svc = egSerialsCoreSvc; // just for debugging
 
@@ -37,6 +37,38 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
         }
     });
 
+    $scope.delete_items = function (items) {
+        var list = [];
+
+        angular.forEach(items, function (i) {
+            var obj = egCore.idl.fromHash('sitem',i);
+            obj.isdeleted(1);
+            obj.stream(obj.stream().id); // API wants scalar or FM object
+            list.push(obj);
+        });
+
+        egConfirmDialog.open(
+            egCore.strings.CONFIRM_DELETE_ITEMS,
+            egCore.strings.CONFIRM_DELETE_ITEMS_MESSAGE,
+            {items : list.length}
+        ).result.then(function () {
+            return egCore.net.request(
+                'open-ils.serial',
+                'open-ils.serial.item.fleshed.batch.update',
+                egCore.auth.token(),
+                list
+            ).then( function(resp) {
+                var evt = egCore.evt.parse(resp);
+                if (evt) { // any way to just throw or return this to the error handler?
+                    ngToast.danger(egCore.strings.SERIALS_ISSUANCE_FAIL_SAVE);
+                } else {
+                    ngToast.success(egCore.strings.SERIALS_ISSUANCE_SUCCESS_SAVE);
+                    return reload($scope.ssubId);
+                }
+            });
+        });
+    }
+
     $scope.edit_issuance_holding_code = function (items) {
         var promises = [];
         var edits = [];
@@ -140,19 +172,7 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
     $scope.add_issuances = function () {
         var lastItem = egSerialsCoreSvc.itemList[egSerialsCoreSvc.itemList.length - 1];
 
-        var base_iss;
-        if (lastItem) {
-            lastItem = egCore.idl.fromHash('siss', lastItem.issuance);
-        } else {
-            base_iss = new egCore.idl.siss();
-            base_iss.creator( egCore.auth.user().id() );
-            base_iss.editor( egCore.auth.user().id() );
-            base_iss.date_published( hc.date );
-            base_iss.subscription( $scope.ssubId );
-            base_iss.caption_and_pattern( hc.scap );
-            base_iss.holding_code( JSON.stringify(hc.holding_code) );
-            base_iss.holding_type( hc.type );
-        }
+        if (lastItem) lastItem = egCore.idl.fromHash('siss', lastItem.issuance);
 
         return egSerialsCoreSvc.new_holding_code({
             title : egCore.strings.SERIALS_ISSUANCE_PREDICT,
@@ -160,6 +180,22 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
             prev_iss : lastItem
         }).then(function(hc) {
             console.log(hc)
+
+            var base_iss;
+            if (!lastItem) {
+                base_iss = new egCore.idl.siss();
+                base_iss.creator( egCore.auth.user().id() );
+                base_iss.editor( egCore.auth.user().id() );
+                base_iss.date_published( hc.date );
+                base_iss.subscription( $scope.ssubId );
+                base_iss.caption_and_pattern( hc.scap );
+                base_iss.holding_code( JSON.stringify(hc.holding_code) );
+                base_iss.holding_type( hc.type );
+            }
+
+            // if we're predicting without a preexisting holding, reduce the count
+            if (!lastItem) hc.count--;
+
             return egCore.net.request(
                 'open-ils.serial',
                 'open-ils.serial.make_predictions',