webstaff: improve editing issuances
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 2 Jun 2017 22:06:09 +0000 (18:06 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 2 Jun 2017 22:06:09 +0000 (18:06 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
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 d7fc34f..329c7e1 100644 (file)
@@ -99,12 +99,12 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider , orderByF
                     type     : item.issuance.type ? item.issuance.type : 'basic',
                     can_change_adhoc : true
                 }).then(function(result) {
-                    if (result.adhoc) {
+                    if (!result.adhoc) {
                         item.issuance.holding_code = JSON.stringify(result.holding_code);
                         item.issuance.holding_type = result.type;
                     } else {
                         item.issuance.label = result.label;
-                        item.issuance.holding_type = null;
+                        item.issuance.holding_type = result.type;
                     }
 
                     item.issuance.date_published = result.date.toISOString();
@@ -112,7 +112,7 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider , orderByF
                     item.issuance.edit_date = 'now';
 
                     var iss = egCore.idl.fromHash('siss',item.issuance);
-                    if (iss.holding_type()) { // not an ad hoc issuance, get predicted label
+                    if (!result.adhoc) { // not an ad hoc issuance, get predicted label
                         return egCore.net.request(
                             'open-ils.serial',
                             'open-ils.serial.make_prediction_values',
index 1d13fa8..ec10939 100644 (file)
@@ -298,6 +298,7 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm
         var curr_iss = args.curr_iss;
         var adhoc = false;
         var link = '1.1';
+        var current_values = {};
 
         var sub = service.get_ssub(service.subId);
         if (!sub) return args;
@@ -332,6 +333,14 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm
             }
             if (!curr_iss.holding_code()) {
                 adhoc = true;
+            } else {
+                var tmp = JSON.parse(curr_iss.holding_code());
+                for (var i = 2; i < tmp.length; i += 2) {
+                    // we're intentionally being a bit sloppy here, as
+                    // the only subfields we are about in this context
+                    // are the ones that are not repeatable
+                    current_values[tmp[i]] = tmp[i + 1];
+                }
             }
 
             date = new Date(curr_iss.date_published());
@@ -378,11 +387,15 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm
                 };
 
                 var chron_part = val.replace(/[)(]+/g,'');
-                try {
-                    pat_part.value = service.get_chron_part[chron_part](date);
-                } catch (e) {
-                    // not a chron part
-                    pat_part.value = '';
+                if (sf in current_values) {
+                    pat_part.value = current_values[sf];
+                } else {
+                    try {
+                        pat_part.value = service.get_chron_part[chron_part](date);
+                    } catch (e) {
+                        // not a chron part
+                        pat_part.value = '';
+                    }
                 }
 
                 if (sf.match(/[a-f]/)) {