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 %]
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>
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
}
});
+ $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)
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();
}
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;
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();
return {
holding_code : ["4","1","8",link],
+ type : type,
date : date,
enums : enums,
chrons : chrons,
['$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 = {};
$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
}
}
}
);
- return $q.when(args.holding_code);
+ return $q.when(args);
});
}