LP1693580 Marc editor notify and API changes
authorBill Erickson <berickxx@gmail.com>
Fri, 15 Mar 2019 15:29:59 +0000 (11:29 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 22 May 2019 20:56:46 +0000 (16:56 -0400)
1. Indicate in the interface when a bib/auth MARC record edit failed or
succeeded.

2. Handle permission failures on MARC edit by displaying the permission
override dialog.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Dan Pearl <dpearl@cwmars.org>
Open-ILS/src/templates/staff/cat/share/marcedit_strings.tt2
Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js

index 8067b96..295078c 100644 (file)
@@ -13,5 +13,9 @@ angular.module('egCoreMod').run(['egStrings', function(s) {
     s.CONFIRM_DELETE_ARE_MSG    = "[% l('Are you sure you want to delete authority record [_1] from the catalog?', '{{id}}') %]";
     s.ALERT_DELETE_FAILED       = "[% l('Could not delete record [_1]: [_2]', '{{id}}', '{{desc}}') %]";
     s.DIRTY_MARC_WARNING        = "[% l('There is unsaved data in this record.') %]"
+    s.MARC_ALERT_CREATE_SUCCESS = "[% l('Successfully created new record') %]";
+    s.MARC_ALERT_CREATE_FAILED  = "[% l('Failed to create new record: [_1]', '{{error}}') %]";
+    s.MARC_ALERT_UPDATE_SUCCESS = "[% l('Successfully updated record') %]";
+    s.MARC_ALERT_UPDATE_FAILED  = "[% l('Failed to update record: [_1]', '{{error}}') %]";
 }]);
 </script>
index c41b1d5..71cf44b 100644 (file)
@@ -696,8 +696,10 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
             });
 
         },
-        controller : ['$timeout','$scope','$q','$window','egCore', 'egTagTable','egConfirmDialog','egAlertDialog',
-            function ( $timeout , $scope , $q,  $window , egCore ,  egTagTable , egConfirmDialog , egAlertDialog ) {
+        controller : ['$timeout','$scope','$q','$window','egCore', 'egTagTable',
+                      'egConfirmDialog','egAlertDialog','ngToast','egStrings',
+            function ( $timeout , $scope , $q,  $window , egCore ,  egTagTable , 
+                       egConfirmDialog , egAlertDialog , ngToast , egStrings) {
 
 
                 $scope.onSaveCallback = $scope.onSave;
@@ -1384,6 +1386,69 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                     return deferred.resolve($scope.recordId)
                 };
 
+                // Returns a promise 
+                function createOrUpdateRecord() {
+
+                    var promise;
+                    if ($scope.recordId) {  
+
+                        var method = $scope.record_type === 'bre' ?
+                            'open-ils.cat.biblio.record.marc.replace' :
+                            'open-ils.cat.authority.record.overlay';
+
+                        promise = egCore.net.request(
+                            'open-ils.cat', method,
+                            egCore.auth.token(), $scope.recordId, 
+                            $scope.Record().marc(), $scope.Record().source()
+                        );
+
+                    } else {
+
+                        var method = $scope.record_type === 'bre' ?
+                            'open-ils.cat.biblio.record.xml.create' :
+                            'open-ils.cat.authority.record.import';
+
+                        promise = egCore.net.request(
+                            'open-ils.cat', method,
+                            egCore.auth.token(), 
+                            $scope.Record().marc(),
+                            $scope.Record().source()
+                        );
+                    }
+
+                    return promise.then(handleCreateOrUpdateResult);
+                }
+
+                function handleCreateOrUpdateResult(result) {
+
+                    var evt = egCore.evt.parse(result)
+                    var mode = $scope.recordId ? 'update' : 'create';
+
+                    if (evt) {
+                        var msg = mode === 'update' ? 
+                            egStrings.MARC_ALERT_UPDATE_FAILED :
+                            egStrings.MARC_ALERT_CREATE_FAILED;
+                        ngToast.warning(msg, {error: '' + evt});
+                        return $q.reject();
+                    }
+
+                    var msg = mode === 'update' ? 
+                        egStrings.MARC_ALERT_UPDATE_SUCCESS :
+                        egStrings.MARC_ALERT_CREATE_SUCCESS;
+                    ngToast.create(msg);
+
+                    console.debug('MARC create/update returned', result);
+
+                    // synchronize values 
+                    if (!$scope.recordId) {
+                        $scope.recordId = $scope.caretRecId = result.id(); 
+                    }
+
+                    $scope.dirtyFlag = false;
+
+                    return result;
+                }
+
                 $scope.saveRecord = function () {
                     
                     if ($scope.inPlaceMode) {
@@ -1397,77 +1462,42 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                     }
 
                     $scope.mangle_005();
-                    $scope.Record().editor(egCore.auth.user().id());
-                    $scope.Record().edit_date('now');
                     $scope.record.pruneEmptyFieldsAndSubfields();
                     $scope.Record().marc($scope.record.toXmlString());
-                    if ($scope.recordId) {
-                        return egCore.pcrud.update(
-                            $scope.Record()
-                        ).then(function() { // success
+
+                    var updating = Boolean($scope.recordId);
+                    return createOrUpdateRecord().then(function(record) {
+
+                        if (updating) {
                             $scope.save_stack_depth = $scope.record_undo_stack.length;
-                            $scope.dirtyFlag = false;
-                            if ($scope.enable_fast_add) {
-                                egCore.net.request(
-                                    'open-ils.actor',
-                                    'open-ils.actor.anon_cache.set_value',
-                                    null, 'edit-these-copies', {
-                                        record_id: $scope.recordId,
-                                        raw: [{
-                                            label : $scope.fast_item_callnumber,
-                                            barcode : $scope.fast_item_barcode,
-                                            fast_add : true
-                                        }],
-                                        hide_vols : false,
-                                        hide_copies : false
-                                    }
-                                ).then(function(key) {
-                                    if (key) {
-                                        var url = egCore.env.basePath + 'cat/volcopy/' + key;
-                                        $timeout(function() { $window.open(url, '_blank') });
-                                    } else {
-                                        alert('Could not create anonymous cache key!');
-                                    }
-                                });
-                            }
-                        }, function() { // failure
-                            alert('Could not save the record!');
-                        }).then(loadRecord).then(processOnSaveCallbacks);
-                    } else {
-                        $scope.Record().creator(egCore.auth.user().id());
-                        $scope.Record().create_date('now');
-                        return egCore.pcrud.create(
-                            $scope.Record()
-                        ).then(function(bre) {
-                            $scope.dirtyFlag = false;
-                            $scope.recordId = bre.id(); 
-                            $scope.caretRecId = $scope.recordId;
-                            if ($scope.enable_fast_add) {
-                                egCore.net.request(
-                                    'open-ils.actor',
-                                    'open-ils.actor.anon_cache.set_value',
-                                    null, 'edit-these-copies', {
-                                        record_id: $scope.recordId,
-                                        raw: [{
-                                            label : $scope.fast_item_callnumber,
-                                            barcode : $scope.fast_item_barcode,
-                                        }],
-                                        hide_vols : false,
-                                        hide_copies : false
-                                    }
-                                ).then(function(key) {
-                                    if (key) {
-                                        var url = egCore.env.basePath + 'cat/volcopy/' + key;
-                                        $timeout(function() { $window.open(url, '_blank') });
-                                    } else {
-                                        alert('Could not create anonymous cache key!');
-                                    }
-                                });
-                            }
-                        }).then(loadRecord).then(processOnSaveCallbacks);
-                    }
+                        }
 
+                        if (!$scope.enable_fast_add) {
+                            return record;
+                        }
 
+                        egCore.net.request(
+                            'open-ils.actor',
+                            'open-ils.actor.anon_cache.set_value',
+                            null, 'edit-these-copies', {
+                                record_id: $scope.recordId,
+                                raw: [{
+                                    label : $scope.fast_item_callnumber,
+                                    barcode : $scope.fast_item_barcode,
+                                    fast_add : true
+                                }],
+                                hide_vols : false,
+                                hide_copies : false
+                            }
+                        ).then(function(key) {
+                            if (key) {
+                                var url = egCore.env.basePath + 'cat/volcopy/' + key;
+                                $timeout(function() { $window.open(url, '_blank') });
+                            } else {
+                                alert('Could not create anonymous cache key!');
+                            }
+                        });
+                    }).then(loadRecord).then(processOnSaveCallbacks);
                 };
 
                 $scope.seeBreaker = function () {