LP#1888518: fix authority delete/undelete in AngularJS editor user/gmcharlt/lp1888518_angjs_authority_delete_undelete
authorGalen Charlton <gmc@equinoxinitiative.org>
Wed, 22 Jul 2020 15:05:34 +0000 (11:05 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Wed, 22 Jul 2020 15:05:34 +0000 (11:05 -0400)
This patch ensures that authority record deletion and undeletion
works in the AngularJS editor.

To test
-------
[1] Go to Manage Authorities -> search -> edit a hit, then
    click the delete button in the editor window.
[2] Note that the record is not deleted.
[3] Apply the patch.
[4] Repeat step 1; this time, the record should be deleted, as
    can be verified by rerunning the search in the authorities
    window.
[5] Click the undelete button; verify that the record shows
    up again.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js

index 0a6a0dd..d77b737 100644 (file)
@@ -1323,7 +1323,20 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                                     loadRecord().then(processOnSaveCallbacks);
                                 }
                             });
+                        } else if ($scope.record_type == 'are') {
+                            egCore.pcrud.remove($scope.Record()).then(function(resp) {
+                                var evt = egCore.evt.parse(resp);
+                                if (evt) {
+                                    return egAlertDialog.open(
+                                        egCore.strings.ALERT_DELETE_FAILED,
+                                        { id : $scope.recordId, desc : evt.desc }
+                                    );
+                                } else {
+                                    loadRecord().then(processOnSaveCallbacks);
+                                }
+                            });
                         } else {
+                            // fallback for sre?
                             $scope.Record().deleted(true);
                             return $scope.saveRecord();
                         }
@@ -1348,6 +1361,26 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                                 loadRecord().then(processOnSaveCallbacks);
                             }
                         });
+                    } else if ($scope.record_type = 'are') {
+                        $scope.Record().deleted(false);
+                        $scope.mangle_005(); // force an update of the 005 upon
+                                             // undelete to ensure that the MARC record
+                                             // is different, thereby forcing a
+                                             // a full reingest of the authority record
+                        $scope.record.pruneEmptyFieldsAndSubfields();
+                        $scope.Record().marc($scope.record.toXmlString());
+                        egCore.pcrud.update($scope.Record()).then(function(resp) {
+                            var evt = egCore.evt.parse(resp);
+                            if (evt) {
+                                return egAlertDialog.open(
+                                    egCore.strings.ALERT_UNDELETE_FAILED,
+                                    { id : $scope.recordId, desc : evt.desc }
+                                );
+                            } else {
+                                ngToast.create(egCore.strings.SUCCESS_UNDELETE_RECORD);
+                                loadRecord().then(processOnSaveCallbacks);
+                            }
+                        });
                     }
                 };