5 angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
7 .directive("egContextMenuItem", ['$timeout',function ($timeout) {
11 template: '<li><a ng-click="setContent(item.value,item.action)">{{item.label}}</a></li>',
12 scope: { item: '=', content: '=' },
13 controller: ['$scope','$element',
14 function ($scope , $element) {
15 if (!$scope.item.label) $scope.item.label = $scope.item.value;
16 if ($scope.item.divider) {
17 $element.style.borderTop = 'solid 1px';
20 $scope.setContent = function (v, a) {
22 if (a) replace_with = a($scope,$element,$scope.item.value,$scope.$parent.$parent.content);
24 $scope.$parent.$parent.$apply(function(){
25 $scope.$parent.$parent.content = replace_with
28 $($element).parent().css({display: 'none'});
35 .directive("egMarcEditEditable", ['$timeout', '$compile', '$document', function ($timeout, $compile, $document) {
40 'style="font-family: \'Lucida Console\', Monaco, monospace;" '+
41 'ng-model="content" '+
42 'size="{{content.length * 1.1}}" '+
43 'maxlength="{{max}}" '+
52 contextItemContainer: '@',
53 contextItemGenerator: '=',
57 controller : ['$scope',
60 if ($scope.contextItemContainer && angular.isArray($scope.$parent[$scope.contextItemContainer]))
61 $scope.item_container = $scope.$parent[$scope.contextItemContainer];
62 else if ($scope.contextItemGenerator)
63 $scope.item_generator = $scope.contextItemGenerator;
65 $scope.showContext = function (event) {
66 $scope.item_list = [];
67 if ($scope.item_container) {
68 $scope.item_list = $scope.item_container;
69 } else if ($scope.item_generator) {
70 // always recalculate; tag and/or subfield
71 // codes may have changed
72 $scope.item_list = $scope.item_generator();
77 if (angular.isArray($scope.item_list) && $scope.item_list.length > 0) { // we have a list of values or transforms
78 console.log('Showing context menu...');
79 $('body').trigger('click');
82 '<ul class="dropdown-menu" role="menu" style="z-index: 2000;">'+
83 '<eg-context-menu-item ng-repeat="item in item_list" item="item" content="content"/>'+
86 var tnode = angular.element(tmpl);
87 $document.find('body').append(tnode);
96 var e = $compile(tnode)($scope);
100 $('body').on('click.context_menu',function() {
101 $(tnode).css('display','none');
102 $('body').off('click.context_menu');
113 link: function (scope, element, attrs) {
115 if (scope.onKeydown) element.bind('keydown', {scope : scope}, scope.onKeydown);
117 element.bind('change', function (e) { element.size = scope.max || parseInt(scope.content.length * 1.1) });
119 element.bind('contextmenu', scope.showContext);
124 .directive("egMarcEditFixedField", ['$timeout', '$compile', '$document', function ($timeout, $compile, $document) {
128 template: '<div class="col-md-2">'+
129 '<div class="col-md-1"><label name="{{fixedField}}" for="{{fixedField}}_ff_input">{{fixedField}}</label></div>'+
130 '<div class="col-md-1"><input type="text" style="padding-left: 5px; margin-left: 1em" size="4" id="{{fixedField}}_ff_input"/></div>'+
132 scope: { record: "=", fixedField: "@" },
134 controller : ['$scope', '$element', 'egTagTable',
135 function ( $scope , $element , egTagTable) {
136 $($element).children().css({ display : 'none' });
138 $scope.content = null; // this is where context menus dump their values
139 $scope.item_container = [];
140 $scope.in_handler = false;
141 $scope.ready = false;
143 $scope.$watch('content', function (newVal, oldVal) {
144 var input = $($element).find('input');
146 input.trigger('keyup'); // cascade the update
149 $scope.$watch('record.ready', function (newVal, oldVal) { // wait for the record to be loaded
150 if (newVal && !$scope.ready) {
151 $scope.rtype = $scope.record.recordType();
153 egTagTable.fetchFFPosTable( $scope.rtype ).then(function (ff_list) {
154 angular.forEach(ff_list, function (ff) {
156 if (ff.fixed_field == $scope.fixedField && ff.rec_type == $scope.rtype) {
159 $($element).children().css({ display : 'inline' });
161 var input = $($element).find('input');
162 input.attr('maxlength', $scope.me.length);
163 input.val($scope.record.extractFixedField($scope.me.fixed_field));
164 input.on('keyup', function(e) {
165 $scope.in_handler = true;
166 $scope.record.setFixedField($scope.me.fixed_field, input.val());
167 try { $scope.$parent.$digest(); } catch(e) {};
173 }).then(function (me) {
177 return $scope.record.extractFixedField($scope.fixedField);
179 function (newVal, oldVal) {
180 if ($scope.in_handler) {
181 $scope.in_handler = false;
182 } else if (oldVal != newVal) {
183 $($element).find('input').val(newVal);
188 }).then(function () {
189 return egTagTable.fetchFFValueTable( $scope.rtype );
190 }).then(function (vlist) {
191 if (vlist[$scope.fixedField]) {
192 vlist[$scope.fixedField].forEach(function (v) {
193 if (v[0].length <= v[2]) {
194 $scope.item_container.push({ value : v[0], label : v[0] + ': ' + v[1] });
198 }).then(function () {
199 if ($scope.item_container && $scope.item_container.length)
200 $($element).bind('contextmenu', $scope.showContext);
206 $scope.showContext = function (event) {
207 if ($scope.context_menu_element) {
208 console.log('Reshowing context menu...');
209 $('body').trigger('click');
210 $($scope.context_menu_element).css({ display: 'block', top: event.pageY, left: event.pageX });
211 $('body').on('click.context_menu',function() {
212 $($scope.context_menu_element).css('display','none');
213 $('body').off('click.context_menu');
218 if (angular.isArray($scope.item_container)) { // we have a list of values or transforms
219 console.log('Showing context menu...');
220 $('body').trigger('click');
223 '<ul class="dropdown-menu" role="menu" style="z-index: 2000;">'+
224 '<eg-context-menu-item ng-repeat="item in item_container" item="item" content="content"/>'+
227 var tnode = angular.element(tmpl);
228 $document.find('body').append(tnode);
236 $scope.context_menu_element = tnode;
238 $timeout(function() {
239 var e = $compile(tnode)($scope);
243 $('body').on('click.context_menu',function() {
244 $(tnode).css('display','none');
245 $('body').off('click.context_menu');
259 .directive("egMarcEditSubfield", function () {
264 '<span><label class="marcedit marcsfcodedelimiter"'+
265 'for="r{{field.record.subfield(\'901\',\'c\')[1]}}f{{field.position}}s{{subfield[2]}}code" '+
266 '>‡</label><eg-marc-edit-editable '+
268 'class="marcedit marcsf marcsfcode" '+
270 'subfield="subfield" '+
271 'content="subfield[0]" '+
273 'on-keydown="onKeydown" '+
274 'context-item-generator="sf_code_options" '+
275 'id="r{{field.record.subfield(\'901\',\'c\')[1]}}f{{field.position}}s{{subfield[2]}}code" '+
277 '<span><eg-marc-edit-editable '+
279 'class="marcedit marcsf marcsfvalue" '+
281 'subfield="subfield" '+
282 'content="subfield[1]" '+
283 'on-keydown="onKeydown" '+
284 'context-item-generator="sf_val_options" '+
285 'id="r{{field.record.subfield(\'901\',\'c\')[1]}}f{{field.position}}s{{subfield[2]}}value" '+
288 scope: { field: "=", subfield: "=", onKeydown: '=' },
290 controller : ['$scope', 'egTagTable',
291 function ( $scope , egTagTable) {
293 $scope.sf_code_options = function () {
294 return egTagTable.getSubfieldCodes($scope.field.tag);
296 $scope.sf_val_options = function () {
297 return egTagTable.getSubfieldValues($scope.field.tag, $scope.subfield[0]);
304 .directive("egMarcEditInd", function () {
308 template: '<span><eg-marc-edit-editable '+
310 'class="marcedit marcind" '+
314 'on-keydown="onKeydown" '+
315 'context-item-generator="ind_val_options" '+
316 'id="r{{field.record.subfield(\'901\',\'c\')[1]}}f{{field.position}}i{{indNumber}}"'+
318 scope: { ind : '=', field: '=', onKeydown: '=', indNumber: '@' },
320 controller : ['$scope', 'egTagTable',
321 function ( $scope , egTagTable) {
323 $scope.ind_val_options = function () {
324 return egTagTable.getIndicatorValues($scope.field.tag, $scope.indNumber);
331 .directive("egMarcEditTag", function () {
335 template: '<span><eg-marc-edit-editable '+
337 'class="marcedit marctag" '+
341 'on-keydown="onKeydown" '+
342 'context-item-generator="tag_options" '+
343 'id="r{{field.record.subfield(\'901\',\'c\')[1]}}f{{field.position}}tag"'+
345 scope: { tag : '=', field: '=', onKeydown: '=' },
347 controller : ['$scope', 'egTagTable',
348 function ( $scope , egTagTable) {
350 $scope.tag_options = function () {
351 return egTagTable.getFieldTags();
358 .directive("egMarcEditDatafield", function () {
363 '<span><eg-marc-edit-tag field="field" tag="field.tag" on-keydown="onKeydown"/></span>'+
364 '<span><eg-marc-edit-ind field="field" ind="field.ind1" on-keydown="onKeydown" ind-number="1"/></span>'+
365 '<span><eg-marc-edit-ind field="field" ind="field.ind2" on-keydown="onKeydown" ind-number="2"/></span>'+
366 '<span><eg-marc-edit-subfield ng-repeat="subfield in field.subfields" subfield="subfield" field="field" on-keydown="onKeydown"/></span>'+
368 scope: { field: "=", onKeydown: '=' },
373 .directive("egMarcEditControlfield", function () {
378 '<span><eg-marc-edit-tag field="field" tag="field.tag" on-keydown="onKeydown"/></span>'+
379 '<span><eg-marc-edit-editable '+
382 'class="marcedit marcdata" '+
383 'content="field.data" '+
384 'on-keydown="onKeydown" '+
385 'id="r{{field.record.subfield(\'901\',\'c\')[1]}}f{{field.position}}data"'+
388 scope: { field: "=", onKeydown: '=' }
392 .directive("egMarcEditLeader", function () {
397 '<span><eg-marc-edit-editable '+
398 'class="marcedit marctag" '+
400 'on-keydown="onKeydown" '+
402 'disabled="disabled"'+
404 '<span><eg-marc-edit-editable '+
405 'class="marcedit marcdata" '+
407 'max="{{record.leader.length}}" '+
408 'content="record.leader" '+
409 'id="r{{record.subfield(\'901\',\'c\')[1]}}leaderdata" '+
410 'on-keydown="onKeydown"'+
413 controller : ['$scope',
414 function ( $scope ) {
418 scope: { record: "=", onKeydown: '=' }
422 /// TODO: fixed field editor and such
423 .directive("egMarcEditRecord", function () {
425 templateUrl : './cat/share/t_marcedit',
432 // in-place mode means that the editor is being
433 // used just to munge some MARCXML client-side, rather
434 // than to (immediately) update the database
439 link: function (scope, element, attrs) {
441 element.bind('click', function(e) {;
442 scope.current_event_target = $(e.target).attr('id');
443 if (scope.current_event_target) {
444 console.log('Recording click event on ' + scope.current_event_target);
445 scope.current_event_target_cursor_pos =
446 e.target.selectionDirection=='backward' ?
447 e.target.selectionStart :
448 e.target.selectionEnd;
453 controller : ['$timeout','$scope','$q','egCore', 'egTagTable',
454 function ( $timeout , $scope , $q, egCore , egTagTable ) {
456 MARC21.Record.delimiter = '$';
458 $scope.flatEditor = false;
459 $scope.brandNewRecord = false;
460 $scope.bib_source = null;
461 $scope.record_type = $scope.recordType || 'bre';
462 $scope.max_undo = $scope.maxUndo || 100;
463 $scope.record_undo_stack = [];
464 $scope.record_redo_stack = [];
465 $scope.in_undo = false;
466 $scope.in_redo = false;
467 $scope.record = new MARC21.Record();
468 $scope.save_stack_depth = 0;
469 $scope.controlfields = [];
470 $scope.datafields = [];
471 $scope.controlSet = new egTagTable.authorityControlSet();
473 egTagTable.loadTagTable({ marcRecordType : $scope.record_type });
475 $scope.saveFlatTextMARC = function () {
476 $scope.record = new MARC21.Record({ marcbreaker : $scope.flat_text_marc });
479 $scope.refreshVisual = function () {
480 if (!$scope.flatEditor) {
481 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
482 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
486 $scope.onKeydown = function (event) {
487 var event_return = true;
490 'keydown: which='+event.which+
491 ', ctrlKey='+event.ctrlKey+
492 ', shiftKey='+event.shiftKey+
493 ', altKey='+event.altKey+
494 ', metaKey='+event.altKey
497 if (event.which == 89 && event.ctrlKey) { // ctrl+y, redo
498 event_return = $scope.processRedo();
499 } else if (event.which == 90 && event.ctrlKey) { // ctrl+z, undo
500 event_return = $scope.processUndo();
501 } else if ((event.which == 68 || event.which == 73) && event.ctrlKey) { // ctrl+d or ctrl+i, insert subfield
503 var element = $(event.target);
504 var new_sf, index_sf, move_data;
506 if (element.hasClass('marcsfvalue')) {
507 index_sf = event.data.scope.subfield[2];
508 new_sf = index_sf + 1;
510 var start = event.target.selectionStart;
511 var end = event.target.selectionEnd - event.target.selectionStart ?
512 event.target.selectionEnd :
513 event.target.value.length;
515 move_data = event.target.value.substring(start,end);
517 } else if (element.hasClass('marcsfcode')) {
518 index_sf = event.data.scope.subfield[2];
519 new_sf = index_sf + 1;
520 } else if (element.hasClass('marctag') || element.hasClass('marcind')) {
525 $scope.current_event_target = 'r' + $scope.recordId +
526 'f' + event.data.scope.field.position +
527 's' + new_sf + 'code';
529 event.data.scope.field.subfields.forEach(function(sf) {
530 if (sf[2] >= new_sf) sf[2]++;
531 if (sf[2] == index_sf) sf[1] = event.target.value.substring(0,start) + event.target.value.substring(end);
533 event.data.scope.field.subfields.splice(
536 [' ', move_data, new_sf ]
539 $scope.current_event_target_cursor_pos = 0;
540 $scope.current_event_target_cursor_pos_end = 1;
542 $timeout(function(){$scope.$digest()}).then(setCaret);
544 event_return = false;
546 } else if (event.which == 117 && event.shiftKey) { // shift + F6, insert 006
547 event.data.scope.field.record.insertOrderedFields(
554 $scope.force_render = true;
555 $timeout(function(){$scope.$digest()}).then(setCaret);
557 event_return = false;
559 } else if (event.which == 118 && event.shiftKey) { // shift + F7, insert 007
560 event.data.scope.field.record.insertOrderedFields(
567 $scope.force_render = true;
568 $timeout(function(){$scope.$digest()}).then(setCaret);
570 event_return = false;
572 } else if (event.which == 119 && event.shiftKey) { // shift + F8, insert/replace 008
573 var new_008_data = event.data.scope.field.record.generate008();
576 var old_008s = event.data.scope.field.record.field('008',true);
577 old_008s.forEach(function(o) {
578 var domnode = $('#r'+o.record.subfield('901','c')[1] + 'f' + o.position);
579 domnode.scope().$destroy();
581 event.data.scope.field.record.deleteFields(o);
584 event.data.scope.field.record.insertOrderedFields(
591 $scope.force_render = true;
592 $timeout(function(){$scope.$digest()}).then(setCaret);
594 event_return = false;
596 } else if (event.which == 13 && event.ctrlKey) { // ctrl+enter, insert datafield
598 var element = $(event.target);
600 var index_field = event.data.scope.field.position;
601 var new_field = index_field + 1;
603 event.data.scope.field.record.insertFieldsAfter(
604 event.data.scope.field,
607 subfields : [[' ','',0]]
611 $scope.current_event_target = 'r' + $scope.recordId +
612 'f' + new_field + 'tag';
614 $scope.current_event_target_cursor_pos = 0;
615 $scope.current_event_target_cursor_pos_end = 3;
616 $scope.force_render = true;
618 $timeout(function(){$scope.$digest()}).then(setCaret);
620 event_return = false;
622 } else if (event.which == 46 && event.ctrlKey) { // ctrl+del, remove field
624 var del_field = event.data.scope.field.position;
626 var domnode = $('#r'+event.data.scope.field.record.subfield('901','c')[1] + 'f' + del_field);
628 event.data.scope.field.record.deleteFields(
629 event.data.scope.field
632 domnode.scope().$destroy();
635 $scope.current_event_target = 'r' + $scope.recordId +
636 'f' + del_field + 'tag';
638 $scope.current_event_target_cursor_pos = 0;
639 $scope.current_event_target_cursor_pos_end = 0
640 $scope.force_render = true;
642 $timeout(function(){$scope.$digest()}).then(setCaret);
644 event_return = false;
646 } else if (event.which == 46 && event.shiftKey && $(event.target).hasClass('marcsf')) { // shift+del, remove subfield
648 var sf = event.data.scope.subfield[2] - 1;
649 if (sf == -1) sf = 0;
651 event.data.scope.field.deleteExactSubfields(
652 event.data.scope.subfield
655 if (!event.data.scope.field.subfields[sf]) {
656 $scope.current_event_target = 'r' + $scope.recordId +
657 'f' + event.data.scope.field.position +
660 $scope.current_event_target = 'r' + $scope.recordId +
661 'f' + event.data.scope.field.position +
665 $scope.current_event_target_cursor_pos = 0;
666 $scope.current_event_target_cursor_pos_end = 0;
667 $scope.force_render = true;
669 $timeout(function(){$scope.$digest()}).then(setCaret);
671 event_return = false;
673 } else if (event.keyCode == 38) {
674 if (event.ctrlKey) { // copy the field up
675 var index_field = event.data.scope.field.position;
678 if (event.data.scope.field.isControlfield()) {
679 field_obj = new MARC21.Field({
680 tag : event.data.scope.field.tag,
681 data : event.data.scope.field.data
685 for (var i in event.data.scope.field.subfields) {
686 sf_clone.push(event.data.scope.field.subfields[i].slice());
688 field_obj = new MARC21.Field({
689 tag : event.data.scope.field.tag,
690 ind1 : event.data.scope.field.ind1,
691 ind2 : event.data.scope.field.ind2,
697 event.data.scope.field.record.insertFieldsBefore(
698 event.data.scope.field,
702 $scope.current_event_target = 'r' + $scope.recordId +
703 'f' + index_field + 'tag';
705 $scope.current_event_target_cursor_pos = 0;
706 $scope.current_event_target_cursor_pos_end = 3;
707 $scope.force_render = true;
709 $timeout(function(){$scope.$digest()}).then(setCaret);
711 } else { // jump to prev field
712 if (event.data.scope.field.position > 0) {
714 $scope.current_event_target_cursor_pos = 0;
715 $scope.current_event_target_cursor_pos_end = 0;
716 $scope.current_event_target = 'r' + $scope.recordId +
717 'f' + (event.data.scope.field.position - 1) +
723 event_return = false;
725 } else if (event.keyCode == 40) { // down arrow...
726 if (event.ctrlKey) { // copy the field down
728 var index_field = event.data.scope.field.position;
729 var new_field = index_field + 1;
732 if (event.data.scope.field.isControlfield()) {
733 field_obj = new MARC21.Field({
734 tag : event.data.scope.field.tag,
735 data : event.data.scope.field.data
739 for (var i in event.data.scope.field.subfields) {
740 sf_clone.push(event.data.scope.field.subfields[i].slice());
742 field_obj = new MARC21.Field({
743 tag : event.data.scope.field.tag,
744 ind1 : event.data.scope.field.ind1,
745 ind2 : event.data.scope.field.ind2,
750 event.data.scope.field.record.insertFieldsAfter(
751 event.data.scope.field,
755 $scope.current_event_target = 'r' + $scope.recordId +
756 'f' + new_field + 'tag';
758 $scope.current_event_target_cursor_pos = 0;
759 $scope.current_event_target_cursor_pos_end = 3;
760 $scope.force_render = true;
762 $timeout(function(){$scope.$digest()}).then(setCaret);
764 } else { // jump to next field
765 if (event.data.scope.field.record.fields[event.data.scope.field.position + 1]) {
767 $scope.current_event_target_cursor_pos = 0;
768 $scope.current_event_target_cursor_pos_end = 0;
769 $scope.current_event_target = 'r' + $scope.recordId +
770 'f' + (event.data.scope.field.position + 1) +
776 event_return = false;
778 } else { // Assumes only marc editor elements have IDs that can trigger this event handler.
779 $scope.current_event_target = $(event.target).attr('id');
780 if ($scope.current_event_target) {
781 $scope.current_event_target_cursor_pos =
782 event.target.selectionDirection=='backward' ?
783 event.target.selectionStart :
784 event.target.selectionEnd;
791 function setCaret() {
792 if ($scope.current_event_target) {
793 console.log("Putting caret in " + $scope.current_event_target);
794 if (!$scope.current_event_target_cursor_pos_end)
795 $scope.current_event_target_cursor_pos_end = $scope.current_event_target_cursor_pos
797 var element = $('#'+$scope.current_event_target).get(0);
800 if (element.setSelectionRange) {
801 element.setSelectionRange(
802 $scope.current_event_target_cursor_pos,
803 $scope.current_event_target_cursor_pos_end
806 $scope.current_event_cursor_pos_end = null;
807 $scope.current_event_target = null;
812 function loadRecord() {
814 var deferred = $q.defer();
815 if ($scope.recordId) {
816 egCore.pcrud.retrieve(
817 $scope.record_type, $scope.recordId
818 ).then(function(rec) {
819 deferred.resolve(rec);
822 var bre = new egCore.idl.bre();
823 bre.marc($scope.marcXml);
824 deferred.resolve(bre);
825 $scope.brandNewRecord = true;
827 return deferred.promise;
828 })().then(function(rec) {
829 $scope.in_redo = true;
830 $scope[$scope.record_type] = rec;
831 $scope.record = new MARC21.Record({ marcxml : $scope.Record().marc() });
832 $scope.calculated_record_type = $scope.record.recordType();
833 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
834 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
835 $scope.save_stack_depth = $scope.record_undo_stack.length;
836 $scope.flat_text_marc = $scope.record.toBreaker();
838 if ($scope.record_type == 'bre') {
839 $scope.bib_source = $scope.Record().source();
843 return egTagTable.fetchFFPosTable($scope.calculated_record_type)
845 return egTagTable.fetchFFValueTable($scope.calculated_record_type)
849 $scope.$watch('record.toBreaker()', function (newVal, oldVal) {
850 if (!$scope.in_undo && !$scope.in_redo && oldVal != newVal) {
851 $scope.record_undo_stack.push({
853 target: $scope.current_event_target,
854 pos: $scope.current_event_target_cursor_pos
857 if ($scope.force_render) {
858 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
859 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
860 $scope.force_render = false;
863 $scope.flat_text_marc = newVal;
866 if ($scope.record_undo_stack.length != $scope.save_stack_depth) {
867 $scope.dirtyFlag = true;
869 $scope.dirtyFlag = false;
872 if ($scope.record_undo_stack.length > $scope.max_undo)
873 $scope.record_undo_stack.shift();
875 console.log('undo stack is ' + $scope.record_undo_stack.length + ' deep');
876 $scope.in_redo = false;
877 $scope.in_undo = false;
880 $scope.processUndo = function () {
881 if ($scope.record_undo_stack.length) {
882 $scope.in_undo = true;
884 var undo_item = $scope.record_undo_stack.pop();
885 $scope.record_redo_stack.push(undo_item);
887 $scope.record = new MARC21.Record({ marcbreaker : undo_item.breaker });
888 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
889 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
891 $scope.current_event_target = undo_item.target;
892 $scope.current_event_target_cursor_pos = undo_item.pos;
893 console.log('Undo targeting ' + $scope.current_event_target + ' position ' + $scope.current_event_target_cursor_pos);
895 $timeout(function(){$scope.$digest()}).then(setCaret);
902 $scope.processRedo = function () {
903 if ($scope.record_redo_stack.length) {
904 $scope.in_redo = true;
906 var redo_item = $scope.record_redo_stack.pop();
907 $scope.record_undo_stack.push(redo_item);
909 $scope.record = new MARC21.Record({ marcbreaker : redo_item.breaker });
910 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
911 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
913 $scope.current_event_target = redo_item.target;
914 $scope.current_event_target_cursor_pos = redo_item.pos;
915 console.log('Redo targeting ' + $scope.current_event_target + ' position ' + $scope.current_event_target_cursor_pos);
917 $timeout(function(){$scope.$digest()}).then(setCaret);
924 $scope.Record = function () {
925 return $scope[$scope.record_type];
928 $scope.deleteRecord = function () {
929 $scope.Record().deleted(true);
930 return $scope.saveRecord();
933 $scope.undeleteRecord = function () {
934 $scope.Record().deleted(false);
935 return $scope.saveRecord();
938 $scope.saveRecord = function () {
939 if ($scope.inPlaceMode) {
940 $scope.marcXml = $scope.record.toXmlString();
944 $scope.Record().editor(egCore.auth.user().id());
945 $scope.Record().edit_date('now');
946 $scope.Record().marc($scope.record.toXmlString());
947 if ($scope.recordId) {
948 return egCore.pcrud.update(
952 $scope.Record().creator(egCore.auth.user().id());
953 $scope.Record().create_date('now');
954 return egCore.pcrud.create(
956 ).then(function(bre) {
957 $scope.recordId = bre.id();
962 $scope.seeBreaker = function () {
963 alert($scope.record.toBreaker());
966 $scope.$watch('recordId',
967 function(newVal, oldVal) {
968 if (newVal && newVal !== oldVal) {
974 if ($scope.recordId || $scope.marcXml) {
978 $scope.mangle_005 = function () {
979 var now = new Date();
980 var y = now.getUTCFullYear();
982 var m = now.getUTCMonth() + 1;
983 if (m < 10) m = '0' + m;
985 var d = now.getUTCDate();
986 if (d < 10) d = '0' + d;
988 var H = now.getUTCHours();
989 if (H < 10) H = '0' + H;
991 var M = now.getUTCMinutes();
992 if (M < 10) M = '0' + M;
994 var S = now.getUTCSeconds();
995 if (S < 10) S = '0' + S;
997 var stamp = '' + y + m + d + H + M + S + '.0';
998 var f = $scope.record.field('005',true)[0];
1002 $scope.record.insertOrderedFields(
1017 .directive("egMarcEditBibsource", ['$timeout',function ($timeout) {
1021 template: '<span class="nullable">'+
1022 '<select class="form-control" ng-model="bib_source" ng-options="s.id() as s.source() for s in bib_sources">'+
1023 '<option value="">Select a Source</option>'+
1026 controller: ['$scope','egCore',
1027 function ($scope , egCore) {
1029 egCore.pcrud.retrieveAll('cbs', {}, {atomic : true})
1030 .then(function(list) { $scope.bib_sources = list; });
1032 $scope.$watch('bib_source',
1033 function(newVal, oldVal) {
1034 if (newVal !== oldVal) {
1035 $scope.bre.source(newVal);