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>'+
367 // FIXME: template should probably be moved to file to improve
369 '<button class="btn btn-info btn-xs" '+
370 'aria-label="Manage authority record links" '+
371 'ng-show="isAuthorityControlled(field)"'+
372 'ng-click="spawnAuthorityLinker()"'+
374 '<span class="glyphicon glyphicon-link"></span>'+
377 scope: { field: "=", onKeydown: '=' },
379 controller : ['$scope','$modal',
380 function ( $scope, $modal ) {
381 $scope.isAuthorityControlled = function () {
382 return ($scope.$parent.$parent.record_type == 'bre') &&
383 $scope.$parent.$parent.controlSet.bibFieldByTag($scope.field.tag);
385 $scope.spawnAuthorityLinker = function() {
386 // intentionally making a clone in case
387 // user decides to abandon the linking
388 var fieldCopy = new MARC21.Field({
389 tag : $scope.field.tag,
390 ind1 : $scope.field.ind1,
391 ind2 : $scope.field.ind2
393 angular.forEach($scope.field.subfields, function(sf) {
394 fieldCopy.subfields.push(sf.slice(0));
396 var cs = $scope.$parent.$parent.controlSet;
397 var args = { changed : false };
399 templateUrl: './cat/share/t_authority_link_dialog',
401 controller: ['$scope', '$modalInstance', function($scope, $modalInstance) {
402 $scope.controlSet = cs;
403 $scope.bibField = fieldCopy;
404 $scope.focusMe = true;
406 $scope.ok = function(args) { $modalInstance.close(args) };
407 $scope.cancel = function () { $modalInstance.dismiss() };
409 }).result.then(function (args) {
411 $scope.field.subfields.length = 0;
412 angular.forEach(fieldCopy.subfields, function(sf) {
413 $scope.field.addSubfields(sf[0], sf[1]);
423 .directive("egMarcEditControlfield", function () {
428 '<span><eg-marc-edit-tag field="field" tag="field.tag" on-keydown="onKeydown"/></span>'+
429 '<span><eg-marc-edit-editable '+
432 'class="marcedit marcdata" '+
433 'content="field.data" '+
434 'on-keydown="onKeydown" '+
435 'id="r{{field.record.subfield(\'901\',\'c\')[1]}}f{{field.position}}data"'+
438 scope: { field: "=", onKeydown: '=' }
442 .directive("egMarcEditLeader", function () {
447 '<span><eg-marc-edit-editable '+
448 'class="marcedit marctag" '+
450 'on-keydown="onKeydown" '+
452 'disabled="disabled"'+
454 '<span><eg-marc-edit-editable '+
455 'class="marcedit marcdata" '+
457 'max="{{record.leader.length}}" '+
458 'content="record.leader" '+
459 'id="r{{record.subfield(\'901\',\'c\')[1]}}leaderdata" '+
460 'on-keydown="onKeydown"'+
463 controller : ['$scope',
464 function ( $scope ) {
468 scope: { record: "=", onKeydown: '=' }
472 /// TODO: fixed field editor and such
473 .directive("egMarcEditRecord", function () {
475 templateUrl : './cat/share/t_marcedit',
482 // in-place mode means that the editor is being
483 // used just to munge some MARCXML client-side, rather
484 // than to (immediately) update the database
489 link: function (scope, element, attrs) {
491 element.bind('click', function(e) {;
492 scope.current_event_target = $(e.target).attr('id');
493 if (scope.current_event_target) {
494 console.log('Recording click event on ' + scope.current_event_target);
495 scope.current_event_target_cursor_pos =
496 e.target.selectionDirection=='backward' ?
497 e.target.selectionStart :
498 e.target.selectionEnd;
503 controller : ['$timeout','$scope','$q','egCore', 'egTagTable',
504 function ( $timeout , $scope , $q, egCore , egTagTable ) {
506 MARC21.Record.delimiter = '$';
508 $scope.flatEditor = false;
509 $scope.brandNewRecord = false;
510 $scope.bib_source = null;
511 $scope.record_type = $scope.recordType || 'bre';
512 $scope.max_undo = $scope.maxUndo || 100;
513 $scope.record_undo_stack = [];
514 $scope.record_redo_stack = [];
515 $scope.in_undo = false;
516 $scope.in_redo = false;
517 $scope.record = new MARC21.Record();
518 $scope.save_stack_depth = 0;
519 $scope.controlfields = [];
520 $scope.datafields = [];
521 $scope.controlSet = new egTagTable.authorityControlSet();
523 egTagTable.loadTagTable({ marcRecordType : $scope.record_type });
525 $scope.saveFlatTextMARC = function () {
526 $scope.record = new MARC21.Record({ marcbreaker : $scope.flat_text_marc });
529 $scope.refreshVisual = function () {
530 if (!$scope.flatEditor) {
531 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
532 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
536 $scope.onKeydown = function (event) {
537 var event_return = true;
540 'keydown: which='+event.which+
541 ', ctrlKey='+event.ctrlKey+
542 ', shiftKey='+event.shiftKey+
543 ', altKey='+event.altKey+
544 ', metaKey='+event.altKey
547 if (event.which == 89 && event.ctrlKey) { // ctrl+y, redo
548 event_return = $scope.processRedo();
549 } else if (event.which == 90 && event.ctrlKey) { // ctrl+z, undo
550 event_return = $scope.processUndo();
551 } else if ((event.which == 68 || event.which == 73) && event.ctrlKey) { // ctrl+d or ctrl+i, insert subfield
553 var element = $(event.target);
554 var new_sf, index_sf, move_data;
556 if (element.hasClass('marcsfvalue')) {
557 index_sf = event.data.scope.subfield[2];
558 new_sf = index_sf + 1;
560 var start = event.target.selectionStart;
561 var end = event.target.selectionEnd - event.target.selectionStart ?
562 event.target.selectionEnd :
563 event.target.value.length;
565 move_data = event.target.value.substring(start,end);
567 } else if (element.hasClass('marcsfcode')) {
568 index_sf = event.data.scope.subfield[2];
569 new_sf = index_sf + 1;
570 } else if (element.hasClass('marctag') || element.hasClass('marcind')) {
575 $scope.current_event_target = 'r' + $scope.recordId +
576 'f' + event.data.scope.field.position +
577 's' + new_sf + 'code';
579 event.data.scope.field.subfields.forEach(function(sf) {
580 if (sf[2] >= new_sf) sf[2]++;
581 if (sf[2] == index_sf) sf[1] = event.target.value.substring(0,start) + event.target.value.substring(end);
583 event.data.scope.field.subfields.splice(
586 [' ', move_data, new_sf ]
589 $scope.current_event_target_cursor_pos = 0;
590 $scope.current_event_target_cursor_pos_end = 1;
592 $timeout(function(){$scope.$digest()}).then(setCaret);
594 event_return = false;
596 } else if (event.which == 117 && event.shiftKey) { // shift + F6, insert 006
597 event.data.scope.field.record.insertOrderedFields(
604 $scope.force_render = true;
605 $timeout(function(){$scope.$digest()}).then(setCaret);
607 event_return = false;
609 } else if (event.which == 118 && event.shiftKey) { // shift + F7, insert 007
610 event.data.scope.field.record.insertOrderedFields(
617 $scope.force_render = true;
618 $timeout(function(){$scope.$digest()}).then(setCaret);
620 event_return = false;
622 } else if (event.which == 119 && event.shiftKey) { // shift + F8, insert/replace 008
623 var new_008_data = event.data.scope.field.record.generate008();
626 var old_008s = event.data.scope.field.record.field('008',true);
627 old_008s.forEach(function(o) {
628 var domnode = $('#r'+o.record.subfield('901','c')[1] + 'f' + o.position);
629 domnode.scope().$destroy();
631 event.data.scope.field.record.deleteFields(o);
634 event.data.scope.field.record.insertOrderedFields(
641 $scope.force_render = true;
642 $timeout(function(){$scope.$digest()}).then(setCaret);
644 event_return = false;
646 } else if (event.which == 13 && event.ctrlKey) { // ctrl+enter, insert datafield
648 var element = $(event.target);
650 var index_field = event.data.scope.field.position;
651 var new_field = index_field + 1;
653 event.data.scope.field.record.insertFieldsAfter(
654 event.data.scope.field,
657 subfields : [[' ','',0]]
661 $scope.current_event_target = 'r' + $scope.recordId +
662 'f' + new_field + 'tag';
664 $scope.current_event_target_cursor_pos = 0;
665 $scope.current_event_target_cursor_pos_end = 3;
666 $scope.force_render = true;
668 $timeout(function(){$scope.$digest()}).then(setCaret);
670 event_return = false;
672 } else if (event.which == 46 && event.ctrlKey) { // ctrl+del, remove field
674 var del_field = event.data.scope.field.position;
676 var domnode = $('#r'+event.data.scope.field.record.subfield('901','c')[1] + 'f' + del_field);
678 event.data.scope.field.record.deleteFields(
679 event.data.scope.field
682 domnode.scope().$destroy();
685 $scope.current_event_target = 'r' + $scope.recordId +
686 'f' + del_field + 'tag';
688 $scope.current_event_target_cursor_pos = 0;
689 $scope.current_event_target_cursor_pos_end = 0
690 $scope.force_render = true;
692 $timeout(function(){$scope.$digest()}).then(setCaret);
694 event_return = false;
696 } else if (event.which == 46 && event.shiftKey && $(event.target).hasClass('marcsf')) { // shift+del, remove subfield
698 var sf = event.data.scope.subfield[2] - 1;
699 if (sf == -1) sf = 0;
701 event.data.scope.field.deleteExactSubfields(
702 event.data.scope.subfield
705 if (!event.data.scope.field.subfields[sf]) {
706 $scope.current_event_target = 'r' + $scope.recordId +
707 'f' + event.data.scope.field.position +
710 $scope.current_event_target = 'r' + $scope.recordId +
711 'f' + event.data.scope.field.position +
715 $scope.current_event_target_cursor_pos = 0;
716 $scope.current_event_target_cursor_pos_end = 0;
717 $scope.force_render = true;
719 $timeout(function(){$scope.$digest()}).then(setCaret);
721 event_return = false;
723 } else if (event.keyCode == 38) {
724 if (event.ctrlKey) { // copy the field up
725 var index_field = event.data.scope.field.position;
728 if (event.data.scope.field.isControlfield()) {
729 field_obj = new MARC21.Field({
730 tag : event.data.scope.field.tag,
731 data : event.data.scope.field.data
735 for (var i in event.data.scope.field.subfields) {
736 sf_clone.push(event.data.scope.field.subfields[i].slice());
738 field_obj = new MARC21.Field({
739 tag : event.data.scope.field.tag,
740 ind1 : event.data.scope.field.ind1,
741 ind2 : event.data.scope.field.ind2,
747 event.data.scope.field.record.insertFieldsBefore(
748 event.data.scope.field,
752 $scope.current_event_target = 'r' + $scope.recordId +
753 'f' + index_field + 'tag';
755 $scope.current_event_target_cursor_pos = 0;
756 $scope.current_event_target_cursor_pos_end = 3;
757 $scope.force_render = true;
759 $timeout(function(){$scope.$digest()}).then(setCaret);
761 } else { // jump to prev field
762 if (event.data.scope.field.position > 0) {
764 $scope.current_event_target_cursor_pos = 0;
765 $scope.current_event_target_cursor_pos_end = 0;
766 $scope.current_event_target = 'r' + $scope.recordId +
767 'f' + (event.data.scope.field.position - 1) +
773 event_return = false;
775 } else if (event.keyCode == 40) { // down arrow...
776 if (event.ctrlKey) { // copy the field down
778 var index_field = event.data.scope.field.position;
779 var new_field = index_field + 1;
782 if (event.data.scope.field.isControlfield()) {
783 field_obj = new MARC21.Field({
784 tag : event.data.scope.field.tag,
785 data : event.data.scope.field.data
789 for (var i in event.data.scope.field.subfields) {
790 sf_clone.push(event.data.scope.field.subfields[i].slice());
792 field_obj = new MARC21.Field({
793 tag : event.data.scope.field.tag,
794 ind1 : event.data.scope.field.ind1,
795 ind2 : event.data.scope.field.ind2,
800 event.data.scope.field.record.insertFieldsAfter(
801 event.data.scope.field,
805 $scope.current_event_target = 'r' + $scope.recordId +
806 'f' + new_field + 'tag';
808 $scope.current_event_target_cursor_pos = 0;
809 $scope.current_event_target_cursor_pos_end = 3;
810 $scope.force_render = true;
812 $timeout(function(){$scope.$digest()}).then(setCaret);
814 } else { // jump to next field
815 if (event.data.scope.field.record.fields[event.data.scope.field.position + 1]) {
817 $scope.current_event_target_cursor_pos = 0;
818 $scope.current_event_target_cursor_pos_end = 0;
819 $scope.current_event_target = 'r' + $scope.recordId +
820 'f' + (event.data.scope.field.position + 1) +
826 event_return = false;
828 } else { // Assumes only marc editor elements have IDs that can trigger this event handler.
829 $scope.current_event_target = $(event.target).attr('id');
830 if ($scope.current_event_target) {
831 $scope.current_event_target_cursor_pos =
832 event.target.selectionDirection=='backward' ?
833 event.target.selectionStart :
834 event.target.selectionEnd;
841 function setCaret() {
842 if ($scope.current_event_target) {
843 console.log("Putting caret in " + $scope.current_event_target);
844 if (!$scope.current_event_target_cursor_pos_end)
845 $scope.current_event_target_cursor_pos_end = $scope.current_event_target_cursor_pos
847 var element = $('#'+$scope.current_event_target).get(0);
850 if (element.setSelectionRange) {
851 element.setSelectionRange(
852 $scope.current_event_target_cursor_pos,
853 $scope.current_event_target_cursor_pos_end
856 $scope.current_event_cursor_pos_end = null;
857 $scope.current_event_target = null;
862 function loadRecord() {
864 var deferred = $q.defer();
865 if ($scope.recordId) {
866 egCore.pcrud.retrieve(
867 $scope.record_type, $scope.recordId
868 ).then(function(rec) {
869 deferred.resolve(rec);
872 if ($scope.recordType == 'bre') {
873 var bre = new egCore.idl.bre();
874 bre.marc($scope.marcXml);
875 deferred.resolve(bre);
876 } else if ($scope.recordType == 'are') {
877 var are = new egCore.idl.are();
878 are.marc($scope.marcXml);
879 deferred.resolve(are);
881 $scope.brandNewRecord = true;
883 return deferred.promise;
884 })().then(function(rec) {
885 $scope.in_redo = true;
886 $scope[$scope.record_type] = rec;
887 $scope.record = new MARC21.Record({ marcxml : $scope.Record().marc() });
888 $scope.calculated_record_type = $scope.record.recordType();
889 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
890 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
891 $scope.save_stack_depth = $scope.record_undo_stack.length;
892 $scope.flat_text_marc = $scope.record.toBreaker();
894 if ($scope.record_type == 'bre') {
895 $scope.bib_source = $scope.Record().source();
899 return egTagTable.fetchFFPosTable($scope.calculated_record_type)
901 return egTagTable.fetchFFValueTable($scope.calculated_record_type)
905 $scope.$watch('record.toBreaker()', function (newVal, oldVal) {
906 if (!$scope.in_undo && !$scope.in_redo && oldVal != newVal) {
907 $scope.record_undo_stack.push({
909 target: $scope.current_event_target,
910 pos: $scope.current_event_target_cursor_pos
913 if ($scope.force_render) {
914 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
915 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
916 $scope.force_render = false;
919 $scope.flat_text_marc = newVal;
922 if ($scope.record_undo_stack.length != $scope.save_stack_depth) {
923 $scope.dirtyFlag = true;
925 $scope.dirtyFlag = false;
928 if ($scope.record_undo_stack.length > $scope.max_undo)
929 $scope.record_undo_stack.shift();
931 console.log('undo stack is ' + $scope.record_undo_stack.length + ' deep');
932 $scope.in_redo = false;
933 $scope.in_undo = false;
936 $scope.processUndo = function () {
937 if ($scope.record_undo_stack.length) {
938 $scope.in_undo = true;
940 var undo_item = $scope.record_undo_stack.pop();
941 $scope.record_redo_stack.push(undo_item);
943 $scope.record = new MARC21.Record({ marcbreaker : undo_item.breaker });
944 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
945 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
947 $scope.current_event_target = undo_item.target;
948 $scope.current_event_target_cursor_pos = undo_item.pos;
949 console.log('Undo targeting ' + $scope.current_event_target + ' position ' + $scope.current_event_target_cursor_pos);
951 $timeout(function(){$scope.$digest()}).then(setCaret);
958 $scope.processRedo = function () {
959 if ($scope.record_redo_stack.length) {
960 $scope.in_redo = true;
962 var redo_item = $scope.record_redo_stack.pop();
963 $scope.record_undo_stack.push(redo_item);
965 $scope.record = new MARC21.Record({ marcbreaker : redo_item.breaker });
966 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
967 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
969 $scope.current_event_target = redo_item.target;
970 $scope.current_event_target_cursor_pos = redo_item.pos;
971 console.log('Redo targeting ' + $scope.current_event_target + ' position ' + $scope.current_event_target_cursor_pos);
973 $timeout(function(){$scope.$digest()}).then(setCaret);
980 $scope.Record = function () {
981 return $scope[$scope.record_type];
984 $scope.deleteRecord = function () {
985 $scope.Record().deleted(true);
986 return $scope.saveRecord();
989 $scope.undeleteRecord = function () {
990 $scope.Record().deleted(false);
991 return $scope.saveRecord();
994 $scope.saveRecord = function () {
995 if ($scope.inPlaceMode) {
996 $scope.marcXml = $scope.record.toXmlString();
1000 $scope.Record().editor(egCore.auth.user().id());
1001 $scope.Record().edit_date('now');
1002 $scope.Record().marc($scope.record.toXmlString());
1003 if ($scope.recordId) {
1004 return egCore.pcrud.update(
1008 $scope.Record().creator(egCore.auth.user().id());
1009 $scope.Record().create_date('now');
1010 return egCore.pcrud.create(
1012 ).then(function(bre) {
1013 $scope.recordId = bre.id();
1014 }).then(loadRecord);
1018 $scope.seeBreaker = function () {
1019 alert($scope.record.toBreaker());
1022 $scope.$watch('recordId',
1023 function(newVal, oldVal) {
1024 if (newVal && newVal !== oldVal) {
1030 if ($scope.recordId || $scope.marcXml) {
1034 $scope.mangle_005 = function () {
1035 var now = new Date();
1036 var y = now.getUTCFullYear();
1038 var m = now.getUTCMonth() + 1;
1039 if (m < 10) m = '0' + m;
1041 var d = now.getUTCDate();
1042 if (d < 10) d = '0' + d;
1044 var H = now.getUTCHours();
1045 if (H < 10) H = '0' + H;
1047 var M = now.getUTCMinutes();
1048 if (M < 10) M = '0' + M;
1050 var S = now.getUTCSeconds();
1051 if (S < 10) S = '0' + S;
1053 var stamp = '' + y + m + d + H + M + S + '.0';
1054 var f = $scope.record.field('005',true)[0];
1058 $scope.record.insertOrderedFields(
1073 .directive("egMarcEditBibsource", ['$timeout',function ($timeout) {
1077 template: '<span class="nullable">'+
1078 '<select class="form-control" ng-model="bib_source" ng-options="s.id() as s.source() for s in bib_sources">'+
1079 '<option value="">Select a Source</option>'+
1082 controller: ['$scope','egCore',
1083 function ($scope , egCore) {
1085 egCore.pcrud.retrieveAll('cbs', {}, {atomic : true})
1086 .then(function(list) { $scope.bib_sources = list; });
1088 $scope.$watch('bib_source',
1089 function(newVal, oldVal) {
1090 if (newVal !== oldVal) {
1091 $scope.bre.source(newVal);
1101 .directive("egMarcEditAuthorityLinker", function () {
1105 templateUrl: './cat/share/t_authority_linker',
1111 controller: ['$scope','$modal','egCore','egAuth',
1112 function ($scope , $modal, egCore, egAuth) {
1114 var cni = egCore.env.aous['cat.marc_control_number_identifier'] ||
1115 'Set cat.marc_control_number_identifier in Library Settings';
1117 $scope._controlled_sf_list = {};
1119 angular.forEach($scope.controlSet.controlSetList(), function(acs_id) {
1120 if ($scope.controlSet.controlSet(acs_id).control_map[$scope.bibField.tag])
1121 found_acs.push(acs_id);
1123 if (found_acs.length) {
1125 $scope.controlSet.controlSet(found_acs[0]).control_map[$scope.bibField.tag], function(sf) {
1126 $scope._controlled_sf_list[ sf[$scope.bibField.tag] ] = 1;
1131 $scope.bibField.subfields.forEach(function (sf) {
1132 if (sf[0] in $scope._controlled_sf_list) {
1134 sf.selectable = true;
1136 sf.selectable = false;
1139 $scope.summarizeField = function() {
1141 'tag': $scope.bibField.tag,
1142 'ind1': $scope.bibField.ind1,
1143 'ind2': $scope.bibField.ind2,
1146 $scope.bibField.subfields.forEach(function(sf) {
1148 source_f.subfields.push([ sf[0], sf[1] ]);
1154 $scope.updateSubfieldZero = function(value) {
1155 $scope.changed = true;
1156 $scope.bibField.deleteSubfield({ code : ['0'] });
1157 $scope.bibField.subfields.push([
1158 '0', '(' + cni + ')' + value
1162 $scope.createAuthorityFromBib = function(spawn_editor) {
1163 var source_f = $scope.summarizeField();
1165 var args = { authority_id : 0 };
1166 var method = (spawn_editor) ?
1167 'open-ils.cat.authority.record.create_from_bib.readonly' :
1168 'open-ils.cat.authority.record.create_from_bib';
1175 ).then(function(newAuthority) {
1178 templateUrl: './cat/share/t_edit_new_authority',
1181 ['$scope', '$modalInstance', function($scope, $modalInstance) {
1182 $scope.focusMe = true;
1184 $scope.dirty_flag = false;
1185 $scope.marc_xml = newAuthority,
1186 $scope.ok = function(args) { $modalInstance.close(args) }
1187 $scope.cancel = function () { $modalInstance.dismiss() }
1189 }).result.then(function (args) {
1190 if (!args || !args.authority_id) return;
1191 $scope.updateSubfieldZero(args.authority_id);
1194 $scope.updateSubfieldZero(newAuthority.id());