webstaff: Add the ability to edit the holding code, type, and pub date of an issuance
authorMike Rylander <mrylander@gmail.com>
Mon, 15 May 2017 21:21:14 +0000 (17:21 -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
Open-ILS/web/js/ui/default/staff/serials/services/core.js

index c50b432..c95ed74 100644 (file)
 angular.module('egCoreMod').run(['egStrings', function(s) {
     s.SERIALS_SUBSCRIPTION_SUCCESS_CLONE = "[% l('Cloned serial subscription') %]";
     s.SERIALS_SUBSCRIPTION_FAIL_CLONE = "[% l('Failed to clone serial subscription') %]";
+    s.SERIALS_ISSUANCE_FAIL_SAVE = "[% l('Failed to save issuance') %]";
+    s.SERIALS_ISSUANCE_SUCCESS_SAVE = "[% l('Issuance saved') %]";
     s.SERIALS_DISTRIBUTION_SUCCESS_LINK_MFHD = "[% l('Distribution linked to MFHD') %]";
     s.SERIALS_DISTRIBUTION_FAIL_LINK_MFHD = "[% l('Failed to link distribution to MFHD') %]";
+    s.SERIALS_EDIT_SISS_HC = "[% l('Edit issuance information') %]";
 }]);
 </script>
 [% END %]
index 3371201..bb7ce17 100644 (file)
@@ -6,12 +6,12 @@
     grid-controls="itemGridControls"
     persist-key="serials.view_item_grid">
 
-    <eg-grid-action handler="add_issuance"
-      label="[% l('following issuance') %]"></eg-grid-action>
-    <eg-grid-action handler="edit_items"
-      label="[% l('Edit Items') %]"></eg-grid-action>
+    <eg-grid-action handler="add_issuance" disabled="need_one_selected"
+      label="[% l('Add following issuance') %]"></eg-grid-action>
+    <eg-grid-action handler="edit_issuance_holding_code"
+      label="[% l('Edit issuance holding codes') %]"></eg-grid-action>
     <eg-grid-action handler="delete_items"
-      label="[% l('Delete Items') %]"></eg-grid-action>
+      label="[% l('Delete items') %]"></eg-grid-action>
 
     <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>
index 2591055..9944d14 100644 (file)
@@ -11,9 +11,9 @@ angular.module('egSerialsAppDep')
         templateUrl: './serials/t_view_items_grid',
         controller:
        ['$scope','$q','egSerialsCoreSvc','egCore','egGridDataProvider',
-        '$uibModal',
+        '$uibModal','ngToast',
 function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
-         $uibModal) {
+         $uibModal , ngToast) {
 
     $scope.svc = egSerialsCoreSvc; // just for debugging
 
@@ -37,6 +37,58 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
         }
     });
 
+    $scope.edit_issuance_holding_code = function (items) {
+        var promises = [];
+        var edits = [];
+        angular.forEach(items, function (item) {
+            promises.push( egSerialsCoreSvc.new_holding_code({
+                    title    : egCore.strings.SERIALS_EDIT_SISS_HC,
+                    curr_iss : egCore.idl.fromHash('siss',item.issuance)
+                }).then(function(result) {
+                    item.issuance.holding_code = JSON.stringify(result.holding_code);
+                    item.issuance.holding_type = result.type;
+                    item.issuance.date_published = result.date.toISOString();
+
+                    // TODO: fetch label with make_predictions
+
+                    edits.push( egCore.idl.fromHash('siss',item.issuance) );
+                })
+            );
+        });
+        return $q.all(promises)
+            .finally(function() {
+                return update_issuances(edits);
+            });
+    }
+
+
+    function update_issuances (list) {
+        if (!angular.isArray(list)) list = [list];
+
+        return egCore.net.request(
+            'open-ils.serial',
+                'open-ils.serial.issuance.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?
+                        console.log('failure',resp);
+                        ngToast.danger(egCore.strings.SERIALS_ISSUANCE_FAIL_SAVE);
+                    } else {
+                        console.log('success',resp);
+                        ngToast.success(egCore.strings.SERIALS_ISSUANCE_SUCCESS_SAVE);
+                    }
+                },
+                function(resp) {
+                    console.log('failure',resp);
+                    ngToast.danger(egCore.strings.SERIALS_ISSUANCE_FAIL_SAVE);
+                }
+            );
+    }
+
+
     $scope.add_issuance = function (items) {
         egSerialsCoreSvc.new_holding_code({
             prev_iss : egCore.idl.fromHash('siss',items[0].issuance)
index c935fcc..d2e93fd 100644 (file)
@@ -169,6 +169,7 @@ function(egCore , orderByFilter , $q , $filter , $uibModal) {
         var type = args.type;
         var date = args.date;
         var prev_iss = args.prev_iss;
+        var curr_iss = args.curr_iss;
 
         var sub = service.get_ssub(service.subId);
         if (!sub) return $q.reject();
@@ -190,7 +191,7 @@ function(egCore , orderByFilter , $q , $filter , $uibModal) {
         }
 
         var link = '1.1';
-        if (prev_iss) {
+        if (prev_iss) { // we're predicting
             var old_link_parts = JSON.parse(prev_iss.holding_code())[3].split('.');
             var olink = old_link_parts[0];
             var oseq = parseInt(old_link_parts[1]) + 1;
@@ -199,6 +200,8 @@ function(egCore , orderByFilter , $q , $filter , $uibModal) {
             date = new Date(
                 new Date(prev_iss.date_published()).getTime() + service.freq_offset[freq]
             );
+        } else if (curr_iss) { // we're editing
+            date = new Date(curr_iss.date_published());
         }
         
         if (!date) date = new Date();
@@ -252,6 +255,7 @@ function(egCore , orderByFilter , $q , $filter , $uibModal) {
 
         return {
             holding_code : ["4","1","8",link],
+            type         : type,
             date         : date,
             enums        : enums,
             chrons       : chrons,
@@ -272,6 +276,7 @@ function(egCore , orderByFilter , $q , $filter , $uibModal) {
                 ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
                 $scope.focusMe = true;
                 $scope.title = options.title;
+                $scope.save_label = options.save_label;
                 $scope.pubdate = options.date || new Date();
                 $scope.type = options.type || 'basic';
                 $scope.args = {};
@@ -281,11 +286,15 @@ function(egCore , orderByFilter , $q , $filter , $uibModal) {
                         $scope.args = service.prep_new_holding_code({
                             type : $scope.type,
                             date : $scope.pubdate,
-                            prev_iss : options.prev_iss
+                            prev_iss : options.prev_iss,
+                            curr_iss : options.curr_iss
                         });
+                        if ($scope.args.type && $scope.type != $scope.args.type)
+                            $scope.type = $scope.args.type;
                         if ($scope.args.date)
                             $scope.pubdate = $scope.args.date;
                         delete options.prev_iss; // only use this once
+                        delete options.curr_iss; // only use this once
                     }
                 }
 
@@ -306,7 +315,7 @@ function(egCore , orderByFilter , $q , $filter , $uibModal) {
                 }
             );
 
-            return $q.when(args.holding_code);
+            return $q.when(args);
         });
     }