From a2b8f7b5d0d2c14b36ab3c4da6d6af1445da9bee Mon Sep 17 00:00:00 2001
From: Bill Erickson <berickxx@gmail.com>
Date: Thu, 14 Mar 2019 12:03:58 -0400
Subject: [PATCH] LP1776736 Record merge marc edit repairs

1. Fixes issues where edits to MARC records would fail to save during
   merge.

2. Provide options to select flat or non-flat text editor in edit mode
   for record merges.

3. Allow record editor action buttons/selectors to flow down
   horizontally when they don't fit in a narrow space.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Dan Wells <dbw2@calvin.edu>
---
 .../staff/cat/bucket/record/t_merge_records.tt2    |  3 +-
 .../src/templates/staff/cat/share/t_marcedit.tt2   | 14 ++++----
 Open-ILS/src/templates/staff/css/cat.css.tt2       |  1 +
 .../js/ui/default/staff/cat/bucket/record/app.js   | 42 ++++++++++++++--------
 .../js/ui/default/staff/cat/services/marcedit.js   |  2 +-
 5 files changed, 37 insertions(+), 25 deletions(-)

diff --git a/Open-ILS/src/templates/staff/cat/bucket/record/t_merge_records.tt2 b/Open-ILS/src/templates/staff/cat/bucket/record/t_merge_records.tt2
index 1a5ee26272..cdfed1973c 100644
--- a/Open-ILS/src/templates/staff/cat/bucket/record/t_merge_records.tt2
+++ b/Open-ILS/src/templates/staff/cat/bucket/record/t_merge_records.tt2
@@ -42,8 +42,7 @@
               <button class="btn btn-default btn-sm" ng-class="{disabled : editing_inplace}" 
                 ng-click="edit_lead()">[% l('Edit using full editor') %]</button>
               <eg-marc-edit-record dirty-flag="dirty_flag" marc-xml="lead.marc_xml"
-                 in-place-mode="true"
-                 record-type="bre" flat-only="true" embedded="true" 
+                 in-place-mode="true" record-type="bre" embedded="true" 
                  ng-show="editing_inplace" on-save="post_edit_inplace">
               </eg-marc-edit-record>
               <eg-record-breaker record-id="lead_id" marc-xml="lead.marc_xml" 
diff --git a/Open-ILS/src/templates/staff/cat/share/t_marcedit.tt2 b/Open-ILS/src/templates/staff/cat/share/t_marcedit.tt2
index dc6b11d145..5ba785945b 100644
--- a/Open-ILS/src/templates/staff/cat/share/t_marcedit.tt2
+++ b/Open-ILS/src/templates/staff/cat/share/t_marcedit.tt2
@@ -11,29 +11,29 @@
     </div>
   </div>
 
-  <div class="pad-vert row marctypesource">
-    <div class="col-md-2 form-group" ng-show="!flatOnly">
+  <div class="pad-vert pad-left row flex-row marctypesource">
+    <div class="form-group pad-horiz" ng-show="!flatOnly">
       <label>
         <input type="checkbox" ng-model="flatEditor.isEnabled" ng-change="refreshVisual()"/>
         [% l('Flat Text Editor') %]
       </label>
     </div>
-    <div class="col-md-2 form-group" ng-show="!flatOnly">
+    <div class="form-group pad-horiz" ng-show="!flatOnly">
       <label>
         <input type="checkbox" ng-model="stackSubfields.enabled" />
         [% l('Stack subfields') %]
       </label>
     </div>
-    <div class="col-md-3">
-      <div class="input-group">
+    <div class="">
+      <div class="input-group pad-horiz">
         <span class="input-group-addon"><b>[% l('Record Type') %]</b></span>
         <span class="input-group-addon">{{calculated_record_type}}</span>
       </div>
     </div>
-    <div ng-if="bre" class="col-md-2">
+    <div ng-if="bre" class="pad-horiz">
       <eg-marc-edit-bibsource/>
     </div>
-    <div class="col-md-3">
+    <div class="pad-horiz">
       <div class="btn-group">
         <span class="btn-group">
           <button class="btn btn-default" ng-show="record_type == 'bre' && !flatOnly" ng-click="validateHeadings()">[% l('Validate') %]</button>
diff --git a/Open-ILS/src/templates/staff/css/cat.css.tt2 b/Open-ILS/src/templates/staff/css/cat.css.tt2
index cbbdfbaadf..4a05b28002 100644
--- a/Open-ILS/src/templates/staff/css/cat.css.tt2
+++ b/Open-ILS/src/templates/staff/css/cat.css.tt2
@@ -18,6 +18,7 @@
 
 .marcfastitemadd, .marctypesource {
     border-bottom: solid thin gray;
+    flex-wrap: wrap;
 }
 
 .marcedit {
diff --git a/Open-ILS/web/js/ui/default/staff/cat/bucket/record/app.js b/Open-ILS/web/js/ui/default/staff/cat/bucket/record/app.js
index 769f9f8bbb..a9fa25e132 100644
--- a/Open-ILS/web/js/ui/default/staff/cat/bucket/record/app.js
+++ b/Open-ILS/web/js/ui/default/staff/cat/bucket/record/app.js
@@ -557,6 +557,25 @@ function($scope,  $q , $routeParams,  bucketSvc,  egCore,  $window,
         egHolds.transfer_all_bib_holds_to_marked_title(bib_ids);
     }
 
+    // Refresh and update a single bib record.
+    // Returns a promise.
+    function updateOneRecord(recId, marcXml) {
+
+        return egCore.net.request(
+            'open-ils.cat',
+            'open-ils.cat.biblio.record.xml.update',
+            egCore.auth.token(), recId, marcXml
+        ).then(function(result) {
+            var evt = egCore.evt.parse(result);
+            if (evt) {
+                alert(evt);
+                return $q.reject(evt);
+            } else {
+                return result; // bib record
+            }
+        });
+    }
+
     // opens the record merge dialog
     $scope.openRecordMergeDialog = function(records) {
         $uibModal.open({
@@ -642,19 +661,15 @@ function($scope,  $q , $routeParams,  bucketSvc,  egCore,  $window,
                 }
                 $scope.post_edit_inplace = function() {
                     $scope.editing_inplace = false;
+                    updateOneRecord($scope.lead_id, $scope.lead.marc_xml);
                 }
+
                 $scope.edit_lead_inplace = function() {
                     $scope.editing_inplace = true;
                 }
                 $scope.edit_lead = function() {
                     var lead = { marc_xml : $scope.lead.marc_xml };
-
-                    // passing the on-save callback this way is a
-                    // hack - this invocation of the MARC editor doesn't
-                    // need it, but for some reason using this stomps
-                    // over the callback set by the other MARC editor
-                    // instance
-                    var callback = $scope.post_edit_inplace;
+                    var parentScope = $scope;
 
                     $uibModal.open({
                         templateUrl: './cat/bucket/record/t_edit_lead_record',
@@ -667,7 +682,10 @@ function($scope,  $q , $routeParams,  bucketSvc,  egCore,  $window,
                             $scope.dirty_flag = false;
                             $scope.ok = function() { $uibModalInstance.close() }
                             $scope.cancel = function () { $uibModalInstance.dismiss() }
-                            $scope.on_save = callback;
+                            $scope.on_save = function() {
+                                parentScope.lead.marc_xml = $scope.lead.marc_xml;
+                                parentScope.post_edit_inplace();
+                            }
                         }]
                     }).result.then(function() {
                         $scope.lead.marc_xml = lead.marc_xml;
@@ -680,13 +698,7 @@ function($scope,  $q , $routeParams,  bucketSvc,  egCore,  $window,
 
             function update_bib() {
                 if (args.merge_profile) {
-                    return egCore.pcrud.retrieve('bre', args.lead_id)
-                    .then(function(rec) {
-                        rec.marc(args.lead.marc_xml);
-                        rec.edit_date('now');
-                        rec.editor(egCore.auth.user().id());
-                        return egCore.pcrud.update(rec);
-                    });
+                    return updateOneRecord(args.lead_id, args.lead.marc_xml);
                 } else {
                     return $q.when();
                 }
diff --git a/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js b/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js
index d288669533..4d2f9c97a5 100644
--- a/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js
+++ b/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js
@@ -709,7 +709,7 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                 $scope.enable_fast_add = false;
                 $scope.fast_item_callnumber = '';
                 $scope.fast_item_barcode = '';
-                
+
                 $scope.flatEditor = { isEnabled : $scope.flatOnly ? true : false };
                 
                 egCore.hatch.getItem('cat.marcedit.flateditor').then(function(val) {
-- 
2.11.0