From 1f70f36f74660213ed5eb4240cca84f5e59c9641 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 17 Jul 2015 22:10:15 +0000 Subject: [PATCH] webstaff: teach MARC editor how to initialize itself from a MARCXML blob Signed-off-by: Galen Charlton Signed-off-by: Jason Stephenson --- .../templates/staff/cat/share/t_marcedit.tt2 | 4 +- .../ui/default/staff/cat/services/marcedit.js | 45 ++++++++++++++----- 2 files changed, 37 insertions(+), 12 deletions(-) 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 e49d83d140..68a9ac57fa 100644 --- a/Open-ILS/src/templates/staff/cat/share/t_marcedit.tt2 +++ b/Open-ILS/src/templates/staff/cat/share/t_marcedit.tt2 @@ -1,5 +1,5 @@
-
+
@@ -23,7 +23,7 @@
-
+
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 24b401f5af..fe358d919c 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 @@ -428,6 +428,7 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) scope: { dirtyFlag : '=', recordId : '=', + marcXml : '@', recordType : '@', maxUndo : '@' }, @@ -445,12 +446,13 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) }); }, - controller : ['$timeout','$scope','egCore', 'egTagTable', - function ( $timeout , $scope , egCore , egTagTable ) { + controller : ['$timeout','$scope','$q','egCore', 'egTagTable', + function ( $timeout , $scope , $q, egCore , egTagTable ) { MARC21.Record.delimiter = '$'; $scope.flatEditor = false; + $scope.brandNewRecord = false; $scope.bib_source = null; $scope.record_type = $scope.recordType || 'bre'; $scope.max_undo = $scope.maxUndo || 100; @@ -803,9 +805,22 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) } function loadRecord() { - return egCore.pcrud.retrieve( - $scope.record_type, $scope.recordId - ).then(function(rec) { + return (function() { + var deferred = $q.defer(); + if ($scope.recordId) { + egCore.pcrud.retrieve( + $scope.record_type, $scope.recordId + ).then(function(rec) { + deferred.resolve(rec); + }); + } else { + var bre = new egCore.idl.bre(); + bre.marc($scope.marcXml); + deferred.resolve(bre); + $scope.brandNewRecord = true; + } + return deferred.promise; + })().then(function(rec) { $scope.in_redo = true; $scope[$scope.record_type] = rec; $scope.record = new MARC21.Record({ marcxml : $scope.Record().marc() }); @@ -903,7 +918,6 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) $scope.Record = function () { return $scope[$scope.record_type]; - return $scope.saveRecord(); }; $scope.deleteRecord = function () { @@ -921,9 +935,19 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) $scope.Record().editor(egCore.auth.user().id()); $scope.Record().edit_date('now'); $scope.Record().marc($scope.record.toXmlString()); - return egCore.pcrud.update( - $scope.Record() - ).then(loadRecord); + if ($scope.recordId) { + return egCore.pcrud.update( + $scope.Record() + ).then(loadRecord); + } else { + $scope.Record().creator(egCore.auth.user().id()); + $scope.Record().create_date('now'); + return egCore.pcrud.create( + $scope.Record() + ).then(function(bre) { + $scope.recordId = bre.id(); + }).then(loadRecord); + } }; $scope.seeBreaker = function () { @@ -938,8 +962,9 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) } ); - if ($scope.recordId) + if ($scope.recordId || $scope.marcXml) { loadRecord(); + } $scope.mangle_005 = function () { var now = new Date(); -- 2.43.2