webstaff: teach MARC editor how to initialize itself from a MARCXML blob
authorGalen Charlton <gmc@esilibrary.com>
Fri, 17 Jul 2015 22:10:15 +0000 (22:10 +0000)
committerJason Stephenson <jstephenson@mvlc.org>
Wed, 19 Aug 2015 17:39:19 +0000 (13:39 -0400)
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/src/templates/staff/cat/share/t_marcedit.tt2
Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js

index e49d83d..68a9ac5 100644 (file)
@@ -1,5 +1,5 @@
 <div>
-  <div ng-if="bre" class="row col-md-12 pad-vert marcfastitemadd">
+  <div ng-if="bre" class="row col-md-12 pad-vert marcfastitemadd" ng-hide="brandNewRecord">
     <input id="mfiacn" type="text" placeholder="[% l('Call Number') %]" ng-model="fast_item_callnumber"/>
     <input id="mfiabc" type="text" placeholder="[% l('Barcode') %]" ng-model="fast_item_barcode"/>
     <button class="btn btn-default" ng-click="saveFastItem()">Add Item</button>
@@ -23,7 +23,7 @@
     <div class="col-md-1">
       <button class="btn btn-default" ng-click="seeBreaker()">Breaker</button>
     </div>
-    <div class="col-md-1">
+    <div class="col-md-1" ng-hide="brandNewRecord">
       <button ng-hide="Record().deleted()" class="btn btn-default" ng-click="deleteRecord()">Delete</button>
       <button ng-show="Record().deleted()" class="btn btn-default" ng-click="undeleteRecord()">Undelete</button>
     </div>
index 24b401f..fe358d9 100644 (file)
@@ -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();