webstaff: add 'Add Special Issue' button for non-predicted issues
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 2 Jun 2017 21:47:53 +0000 (17:47 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 2 Jun 2017 21:47:53 +0000 (17:47 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/serials/t_holding_code_dialog.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 f792a9c..8346f0c 100644 (file)
@@ -25,7 +25,7 @@
       </select>
     </div>
   </div>
-  <div class="row">
+  <div class="row" ng-show="can_change_adhoc">
     <div class="col-md-3">
       <b>[% l('Ad hoc issue?') %]</b>
     </div>
index ce3e6ed..36f6bb2 100644 (file)
@@ -29,6 +29,8 @@
     <eg-grid-menu-item handler="add_issuances" standalone="true"
         label="[% l('Predict New Issues') %]"></eg-grid-menu-item>
 
+    <eg-grid-menu-item handler="add_special_issuance" standalone="true"
+        label="[% l('Add Special Issue') %]"></eg-grid-menu-item>
 
     <eg-grid-menu-item handler="checkbox_handler"
       label="[% l('Barcode on receive') %]"
index d7250fc..d7fc34f 100644 (file)
@@ -96,7 +96,8 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider , orderByF
                     title    : egCore.strings.SERIALS_EDIT_SISS_HC,
                     curr_iss : egCore.idl.fromHash('siss',item.issuance),
                     label    : item.issuance.label,
-                    type     : item.issuance.type ? item.issuance.type : 'basic'
+                    type     : item.issuance.type ? item.issuance.type : 'basic',
+                    can_change_adhoc : true
                 }).then(function(result) {
                     if (result.adhoc) {
                         item.issuance.holding_code = JSON.stringify(result.holding_code);
@@ -171,7 +172,8 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider , orderByF
     $scope.following_issuance = function (items) {
         return egSerialsCoreSvc.new_holding_code({
             title : egCore.strings.SERIALS_ISSUANCE_ADD,
-            prev_iss : egCore.idl.fromHash('siss',items[0].issuance)
+            prev_iss : egCore.idl.fromHash('siss',items[0].issuance),
+            can_change_adhoc : true
         }).then(function(hc) {
             if (hc.adhoc) {
                 var new_iss = new egCore.idl.siss();
@@ -226,6 +228,50 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider , orderByF
         });
     }
 
+    $scope.add_special_issuance = function() {
+        return egSerialsCoreSvc.new_holding_code({
+            title : egCore.strings.SERIALS_ISSUANCE_ADD,
+            can_change_adhoc : false,
+            adhoc       : true
+        }).then(function(hc) {
+            // perforce add hoc
+            var new_iss = new egCore.idl.siss();
+            new_iss.creator( egCore.auth.user().id() );
+            new_iss.editor( egCore.auth.user().id() );
+            new_iss.date_published( hc.date.toISOString() );
+            new_iss.subscription( $scope.ssubId );
+            new_iss.label( hc.label );
+            new_iss.holding_type( hc.type );
+
+            return egCore.pcrud.create(new_iss).then(function(issuance) {
+                var new_items = [];
+                var sub = egSerialsCoreSvc.get_ssub($scope.ssubId);
+                angular.forEach(sub.distributions(), function(dist) {
+                    angular.forEach(dist.streams(), function(stream) {
+                        var new_item = new egCore.idl.sitem();
+                        new_item.creator( egCore.auth.user().id() );
+                        new_item.editor( egCore.auth.user().id() );
+                        new_item.issuance( issuance.id() );
+                        new_item.stream( stream.id() );
+                        new_item.date_expected( hc.date.toISOString() ); // XXX do we have interval math?
+                        new_items.push(new_item);
+                    });
+                });
+                var promises = [];
+                angular.forEach(new_items, function(item) {
+                    promises.push(egCore.pcrud.create(item));
+                });
+
+                $q.all(promises).then(function() {
+                    ngToast.success(egCore.strings.SERIALS_ISSUANCE_SUCCESS_SAVE);
+                    return reload($scope.ssubId,_paging_filter);
+                },function (error) {
+                    ngToast.danger(egCore.strings.SERIALS_ISSUANCE_FAIL_SAVE);
+                });
+            });
+        });
+    }
+
     $scope.do_print_routing_lists = false;
     egCore.hatch.getItem('eg.serials.items.do_print_routing_lists').then(function(val) {
         $scope.do_print_routing_lists = val;
index 82c6e1c..1d13fa8 100644 (file)
@@ -449,6 +449,7 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm
                 $scope.type = options.type || 'basic';
                 $scope.args = { adhoc : false };
                 if (options.adhoc) $scope.args.adhoc = true;
+                $scope.can_change_adhoc = options.can_change_adhoc;
 
                 function refresh (n,o) {
                     if (n && o && n !== o) {
@@ -458,6 +459,7 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm
                             prev_iss : options.prev_iss,
                             curr_iss : options.curr_iss,
                         });
+                        if (!options.can_change_adhoc && options.adhoc) $scope.args.adhoc = true;
 
                         if ($scope.args.type && $scope.type != $scope.args.type)
                             $scope.type = $scope.args.type;
@@ -1022,7 +1024,8 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm
             return service.new_holding_code({
                 title : egCore.strings.SERIALS_ISSUANCE_PREDICT,
                 request_count : true,
-                prev_iss : lastItem
+                prev_iss : lastItem,
+                allow_adhoc : false
             }).then(function(hc) {
     
                 var base_iss;