<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>
<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>
scope: {
dirtyFlag : '=',
recordId : '=',
+ marcXml : '@',
recordType : '@',
maxUndo : '@'
},
});
},
- 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;
}
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() });
$scope.Record = function () {
return $scope[$scope.record_type];
- return $scope.saveRecord();
};
$scope.deleteRecord = function () {
$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 () {
}
);
- if ($scope.recordId)
+ if ($scope.recordId || $scope.marcXml) {
loadRecord();
+ }
$scope.mangle_005 = function () {
var now = new Date();