lp#1724321 Web Client -- existence of record with duplicate TCN does not prevent...
authorblake <blake@mobiusconsortium.org>
Thu, 9 Nov 2017 15:35:07 +0000 (15:35 +0000)
committerJason Etheridge <jason@EquinoxInitiative.org>
Mon, 18 Dec 2017 02:30:49 +0000 (21:30 -0500)
This routes the MARC import execution back to the z39.50 code instead of using the generic
MARC editor. This will make use of open-ils.cat.biblio.record.xml.import instead of pcrud.

Test
1. Edit global flag variable "Cat: Use Internal ID for TCN Value" = false
2. Perform a z39.50 search, click a result and click "import"
3. Step two should be successful, now import it again and you should get an error
4. Click the same result but use "Edit then import"
5. From the MARC editor, make no changes and click "Import"
6. It won't complain about duplicate TCNs
7. Apply the patch
8. Perform steps 4 and 5
9. Notice that the editor does not allow you to import the record

Signed-off-by: blake <blake@mobiusconsortium.org>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Signed-off-by: Jason Etheridge <jason@EquinoxInitiative.org>

Open-ILS/src/templates/staff/cat/z3950/t_marc_edit.tt2
Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js
Open-ILS/web/js/ui/default/staff/cat/z3950/app.js

index 8e55ebf..bcbe41f 100644 (file)
@@ -7,7 +7,7 @@
   <div class="modal-body">
     <eg-marc-edit-record dirty-flag="dirty_flag" record-id="record_id" marc-xml="marc_xml"
                          record-type="bre" save-label="{{save_label}}"
-                         on-save="import_record_callback" fast-add="true"
+                         on-save="import_record_callback" fast-add="true" in-place-mode="in_place_mode"
     />
   </div>
   <div class="modal-footer">
index d525a90..bce2ba7 100644 (file)
@@ -624,7 +624,14 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
             // in-place mode means that the editor is being
             // used just to munge some MARCXML client-side, rather
             // than to (immediately) update the database
-            inPlaceMode : '@',
+            //
+            // In short, we can use inPlaceMode as a way to skip
+            // "normal" bre saving and then process the MARC ourselves
+            // via a callback
+            //
+            // inPlaceMode is r/w to allow our Z39.50 import editor to be
+            // switched back into a normal editor after the initial import
+            inPlaceMode : '=',
             fastAdd : '@',
             flatOnly : '@',
             embedded : '@',
index 09bf70f..83be9ce 100644 (file)
@@ -212,20 +212,25 @@ function($scope , $q , $location , $timeout , $window,  egCore , egGridDataProvi
         });
         return groups;
     };
+
     $scope.import = function() {
-        var deferred = $q.defer();
         var items = $scope.gridControls.selectedItems();
+        return $scope._import(items[0]['marcxml']);
+    };
+
+    $scope._import = function(marc_xml) {
+        var deferred = $q.defer();
         egCore.net.request(
             'open-ils.cat',
             'open-ils.cat.biblio.record.xml.import',
             egCore.auth.token(),
-            items[0]['marcxml'],
+            marc_xml,
             null, // FIXME bib source
             null,
             null,
             $scope.selectFieldStripGroups()
         ).then(
-            function() { deferred.resolve() },
+            function(result) { deferred.resolve(result) },
             null, // onerror
             function(result) {
                 var evt = egCore.evt.parse(result);
@@ -265,6 +270,7 @@ function($scope , $q , $location , $timeout , $window,  egCore , egGridDataProvi
     $scope.spawn_editor = function() {
         var items = $scope.gridControls.selectedItems();
         var recId = 0;
+        var _import = $scope._import;
         $uibModal.open({
             templateUrl: './cat/z3950/t_marc_edit',
             backdrop: 'static',
@@ -278,9 +284,23 @@ function($scope , $q , $location , $timeout , $window,  egCore , egGridDataProvi
                 $scope.ok = function(args) { $uibModalInstance.close(args) }
                 $scope.cancel = function () { $uibModalInstance.dismiss() }
                 $scope.save_label = egCore.strings.IMPORT_BUTTON_LABEL;
-                $scope.import_record_callback = function (record_id) {
-                    recId = record_id;
-                    $scope.save_label = egCore.strings.SAVE_BUTTON_LABEL;
+                // Wiring up angular inPlaceMode for editing later
+                $scope.in_place_mode = true;
+                $scope.import_record_callback = function () {
+                    if($scope.in_place_mode) {
+                        // This timeout is required to allow angular to finish variable assignments
+                        // in the marcediter app. Allowing marc_xml to propigate here.
+                        $timeout( function() {
+                            _import($scope.marc_xml).then( function(record_obj) {
+                                if( record_obj.id ) {
+                                    $scope.record_id = record_obj.id();
+                                    $scope.save_label = egCore.strings.SAVE_BUTTON_LABEL;
+                                    // Successful import, no longer want this special z39.50 callback to execute.
+                                    $scope.in_place_mode = undefined;
+                                }
+                            });
+                        });
+                    }
                 };
             }]
         }).result.then(function () {