webstaff: receiving fixes, proceeding
authorMike Rylander <mrylander@gmail.com>
Thu, 18 May 2017 23:58:07 +0000 (19:58 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 30 May 2017 16:06:47 +0000 (12:06 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js

index 7a1c4b3..7210974 100644 (file)
@@ -11,9 +11,9 @@ angular.module('egSerialsAppDep')
         templateUrl: './serials/t_view_items_grid',
         controller:
        ['$scope','$q','egSerialsCoreSvc','egCore','egGridDataProvider',
-        '$uibModal','ngToast','egConfirmDialog',
+        '$uibModal','ngToast','egConfirmDialog','egPromptDialog',
 function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
-         $uibModal , ngToast , egConfirmDialog) {
+         $uibModal , ngToast , egConfirmDialog , egPromptDialog) {
 
     $scope.svc = egSerialsCoreSvc;
 
@@ -209,13 +209,12 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
     }
 
     $scope.receive_selected = function (list) {
-        console.log(list);
-        return process_next('bind', list.map(function(item) {
+        return process_next('receive', list.map(function(item) {
             return egSerialsCoreSvc.itemMap[item.id];
         }));
     }
 
-    $scope.bind_selected = function () {
+    $scope.bind_selected = function (list) {
         $scope.receive_and_bind = true;
         return process_next('bind', list.map(function(item) {
             return egSerialsCoreSvc.itemMap[item.id];
@@ -247,21 +246,17 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
         var call_numbers = {};
         var call_numbers_by_siss_and_sdist = {};
 
+        $scope.r_and_b_barcode = '';
+
         var prompt_promises = [];
         if ($scope.receive_and_barcode || $scope.receive_and_bind) { // supplying a barcode (unit) to new items
-            var new_unit_barcode = '';
-            var new_unit_call_number = '';
+
             angular.forEach(list, function (item) {
-                if (new_unit_barcode) {
-                    barcodes[item.id()] = new_unit_barcode;
-                    call_numbers[item.id()] = new_unit_call_number;
-                    continue;
-                }
 
                 // TODO: I18N
                 var prompt_text = 'for '+
                     item.issuance().label()+
-                    ' from Distribution: '+obj.sdist_map[item.stream().distribution()].label()+
+                    ' from Distribution: '+item.stream().distribution().label()+
                     '/'+item.stream().id()+':';
 
                 if ($scope.receive_and_bind) {
@@ -269,86 +264,86 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
                 }
 
                 prompt_promises.push(
-                    egPromptDialog.open(
-                        'Please enter a barcode ' + prompt_text, '@@AUTO',
-                        {ok : function(barcode) {
-                            if (barcode) {
-                                barcode = String( barcode ).replace(/\s/g,'');
-                                if (!barcode || barcode == 'null') {
-                                    barcode = '@@AUTO';
-/*
- *                                } else {
- *                                    // XXX test for barcode in use
- *                                    // disable alarm sound temporarily
- *                                    var sound_setting = obj.data.no_sound;
- *                                    if (!sound_setting) { // undefined or false
- *                                         obj.data.no_sound = true; obj.data.stash('no_sound');
- *                                    }
- *                                    var test = obj.network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ barcode ]);
- *                                    if (typeof test.ilsevent == 'undefined') {
- *                                         alert('Another copy has barcode "' + barcode + '", defaulting to system-generated.');
- *                                         barcode = '@@AUTO';
- *                                    }
- *                                    if (!sound_setting) {
- *                                         obj.data.no_sound = sound_setting; obj.data.stash('no_sound');
- *                                    }
- */
+                    $q(function() {
+                        if ($scope.receive_and_bind && $scope.r_and_b_barcode) {
+                            barcodes[item.id()] = $scope.r_and_b_barcode;
+                            return $q.when();
+                        }
+
+                        return egPromptDialog.open(
+                            'Please enter a barcode ' + prompt_text, '@@AUTO',
+                            {ok : function(barcode) {
+                                if (barcode) {
+                                    barcode = String( barcode ).replace(/\s/g,'');
+                                    if (!barcode || barcode == 'null') {
+                                        barcode = '@@AUTO';
+    /*
+     *                                } else {
+     *                                    // XXX test for barcode in use
+     *                                    // disable alarm sound temporarily
+     *                                    var sound_setting = obj.data.no_sound;
+     *                                    if (!sound_setting) { // undefined or false
+     *                                         obj.data.no_sound = true; obj.data.stash('no_sound');
+     *                                    }
+     *                                    var test = obj.network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ barcode ]);
+     *                                    if (typeof test.ilsevent == 'undefined') {
+     *                                         alert('Another copy has barcode "' + barcode + '", defaulting to system-generated.');
+     *                                         barcode = '@@AUTO';
+     *                                    }
+     *                                    if (!sound_setting) {
+     *                                         obj.data.no_sound = sound_setting; obj.data.stash('no_sound');
+     *                                    }
+     */
+                                    }
+                                    barcodes[item.id()] = barcode;
+                                    if ($scope.receive_and_bind && $scope.r_and_b_barcode)
+                                        $scope.r_and_b_barcode = barcode;
+                                } else {
+                                    barcodes[item.id()] = '@@AUTO';
                                 }
-                                barcodes[item.id()] = barcode;
-                            }
-                        }}
-                    ).result
+                            }}
+                        ).result;
+                    })
                 );
 
                 // now call numbers
-                if (typeof call_numbers_by_siss_and_sdist[item.issuance().id() + '@' + item.stream().distribution().id()] == 'undefined') {
-                    var default_cn = 'DEFAULT';
-                    // if they defined a *_call_number, honor it as the default
-                    var preset_cn = item.stream().distribution()[mode + '_call_number']();
-                    if (preset_cn) {
-                        default_cn = preset_cn.label();
-
-/* XXX default to previous, as in xul?
- *
- *                   } else {
- *                       // for now, let's default to the last created call number if there is one
- *                       var acn_list = obj.network.request(
- *                               'open-ils.pcrud',
- *                               'open-ils.pcrud.search.acn',
- *                               [ ses(),
- *                                {   "record" : obj.docid,
- *                                    "owning_lib" : obj.sdist_map[item.stream().distribution()].holding_lib().id(),
- *                                    "deleted" : 'f'
- *                                }, {"order_by" : {"acn" : "create_date DESC"}, "limit" : "1" } ]
- *                       );
- *
- *                       if (acn_list) {
- *                           default_cn = acn_list.label();
- *                       }
- */
-
-                    }
+                prompt_promises.push(
+                    $q(function() {
+                        if ($scope.receive_and_bind && $scope.r_and_b_callnumber) {
+                            call_numbers[item.id()] = $scope.r_and_b_callnumber;
+                            return $q.when();
+                        }
 
-                    prompt_promises.push(egPromptDialog.open('Please enter/adjust a call number'+prompt_text, default_cn,
-                        {ok : function(call_number) {
-                            if (call_number) {
-                                call_number = String( call_number ).replace(/\s/g,'');
-                                if (!call_number || call_number == 'null')
-                                    call_number = 'DEFAULT';
-                                call_numbers[item.id()] = call_number;
-                                call_numbers_by_siss_and_sdist[item.issuance().id() + '@' + item.stream().distribution().id()] = call_number;
+                        if (typeof call_numbers_by_siss_and_sdist[item.issuance().id() + '@' + item.stream().distribution().id()] == 'undefined') {
+                            var default_cn = 'DEFAULT';
+                            // if they defined a *_call_number, honor it as the default
+                            var preset_cn = item.stream().distribution()[mode + '_call_number']();
+                            if (preset_cn) {
+                                default_cn = preset_cn.label();
                             }
-                        }}
-                    ).result);
-                } else {
-                    // we have already seen this same issuance and distribution combo, so use the same call number
-                    call_numbers[item.id()] = call_numbers_by_siss_and_sdist[item.issuance().id() + '@' + item.stream().distribution().id()];
-                }
+                        } else {
+                            // we have already seen this same issuance and distribution combo, so use the same call number
+                            call_numbers[item.id()] = call_numbers_by_siss_and_sdist[item.issuance().id() + '@' + item.stream().distribution().id()];
+                        }
+
+                        return egPromptDialog.open('Please enter/adjust a call number'+prompt_text, default_cn,
+                            {ok : function(call_number) {
+                                if (call_number) {
+                                    call_number = String( call_number ).replace(/\s/g,'');
+                                    if (!call_number || call_number == 'null')
+                                        call_number = 'DEFAULT';
+                                    call_numbers[item.id()] = call_number;
+                                    call_numbers_by_siss_and_sdist[item.issuance().id() + '@' + item.stream().distribution().id()] = call_number;
+                                    if ($scope.receive_and_bind && $scope.r_and_b_callnumber)
+                                        $scope.r_and_b_callnumber = callnumber;
+                                } else {
+                                    call_numbers[item.id()] = 'DEFAULT';
+                                }
+                            }}
+                        ).result;
+                    })
+                );
 
-                if ($scope.receive_and_bind) {
-                    new_unit_barcode = barcode;
-                    new_unit_call_number = call_number;
-                }
             });
         } else {
             prompt_promises.push($q.when());