From 09e0dfd00de838f8e9ad7d021484135db23a4e48 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Mon, 15 May 2017 17:21:14 -0400 Subject: [PATCH] webstaff: Add the ability to edit the holding code, type, and pub date of an issuance Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton --- Open-ILS/src/templates/staff/serials/index.tt2 | 3 ++ .../templates/staff/serials/t_view_items_grid.tt2 | 10 ++-- .../staff/serials/directives/view-items-grid.js | 56 +++++++++++++++++++++- .../js/ui/default/staff/serials/services/core.js | 15 ++++-- 4 files changed, 74 insertions(+), 10 deletions(-) diff --git a/Open-ILS/src/templates/staff/serials/index.tt2 b/Open-ILS/src/templates/staff/serials/index.tt2 index c50b432a6b..c95ed7463c 100644 --- a/Open-ILS/src/templates/staff/serials/index.tt2 +++ b/Open-ILS/src/templates/staff/serials/index.tt2 @@ -19,8 +19,11 @@ 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') %]"; }]); [% END %] diff --git a/Open-ILS/src/templates/staff/serials/t_view_items_grid.tt2 b/Open-ILS/src/templates/staff/serials/t_view_items_grid.tt2 index 33712010f6..bb7ce17364 100644 --- a/Open-ILS/src/templates/staff/serials/t_view_items_grid.tt2 +++ b/Open-ILS/src/templates/staff/serials/t_view_items_grid.tt2 @@ -6,12 +6,12 @@ grid-controls="itemGridControls" persist-key="serials.view_item_grid"> - - + + + label="[% l('Delete items') %]"> diff --git a/Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js b/Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js index 25910551dc..9944d14d59 100644 --- a/Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js +++ b/Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js @@ -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) diff --git a/Open-ILS/web/js/ui/default/staff/serials/services/core.js b/Open-ILS/web/js/ui/default/staff/serials/services/core.js index c935fcc79a..d2e93fdf16 100644 --- a/Open-ILS/web/js/ui/default/staff/serials/services/core.js +++ b/Open-ILS/web/js/ui/default/staff/serials/services/core.js @@ -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); }); } -- 2.11.0