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: '=', contextMenuEvent: '=' },
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.css('borderTop','solid 1px');
20 $scope.setContent = function (v, a) {
28 $scope.$parent.$parent.content,
29 $scope.contextMenuEvent
33 if (typeof replace_with !== 'undefined') {
35 $scope.$parent.$parent.$apply(function(){
36 $scope.$parent.$parent.content = replace_with
40 $($element).parent().css({display: 'none'});
47 .directive("egMarcEditEditable", ['$timeout', '$compile', '$document', function ($timeout, $compile, $document) {
52 'style="font-family: \'Lucida Console\', Monaco, monospace;" '+
53 'ng-model="content" '+
54 'size="{{content.length * 1.1}}" '+
55 'maxlength="{{max}}" '+
64 contextItemContainer: '@',
65 contextItemGenerator: '=',
69 advanceFocusAfterInput: '='
71 controller : ['$scope',
74 if ($scope.contextItemContainer && angular.isArray($scope.$parent[$scope.contextItemContainer]))
75 $scope.item_container = $scope.$parent[$scope.contextItemContainer];
76 else if ($scope.contextItemGenerator)
77 $scope.item_generator = $scope.contextItemGenerator;
79 $scope.showContext = function (event) {
80 $scope.item_list = [];
81 if ($scope.item_container) {
82 $scope.item_list = $scope.item_container;
83 } else if ($scope.item_generator) {
84 // always recalculate; tag and/or subfield
85 // codes may have changed
87 var generator = $scope.item_generator;
88 if (!angular.isArray(generator)) generator = [generator];
91 angular.forEach(generator, function (g) {
96 else if (Boolean(sub_list[0]))
97 sub_list[0].divider = true;
99 $scope.item_list = $scope.item_list.concat(sub_list);
106 if (angular.isArray($scope.item_list) && $scope.item_list.length > 0) { // we have a list of values or transforms
107 console.log('Showing context menu...');
108 $('body').trigger('click');
110 $scope.contextMenuEvent = event;
112 '<ul class="dropdown-menu scrollable-menu" role="menu" style="z-index: 2000;">'+
113 '<eg-context-menu-item context-menu-event="contextMenuEvent" ng-repeat="item in item_list" item="item" content="content"/>'+
116 var tnode = angular.element(tmpl);
117 $document.find('body').append(tnode);
125 $timeout(function() {
126 var e = $compile(tnode)($scope);
130 $('body').on('click.context_menu',function() {
131 $(tnode).css('display','none');
132 $('body').off('click.context_menu');
143 link: function (scope, element, attrs) {
145 if (scope.onKeydown) element.bind('keydown', {scope : scope}, scope.onKeydown);
147 if (Boolean(scope.selectOnFocus)) {
148 element.addClass('noSelection');
149 element.bind('focus', function () { element.select() });
152 function findCaretTarget(id, itype) {
154 if (itype == 'tag') {
155 tgt = id.replace(/tag$/, 'i1');
156 } else if (itype == 'ind') {
157 if (id.match(/i1$/)) {
158 tgt = id.replace(/i1$/, 'i2');
159 } else if (id.match(/i2$/)) {
160 tgt = id.replace(/i2$/, 's0code');
162 } else if (itype == 'sfc') {
163 tgt = id.replace(/code$/, 'value');
167 if (Boolean(scope.advanceFocusAfterInput)) {
168 element.bind('input', function (e) {
169 if (scope.content.length == scope.max) {
170 var tgt = findCaretTarget(e.currentTarget.id, scope.itype);
172 var element = $('#' + tgt).get(0);
181 element.bind('change', function (e) { element.size = scope.max || parseInt(scope.content.length * 1.1) });
183 element.bind('contextmenu', {scope : scope}, scope.showContext);
188 .directive("egMarcEditFixedField", ['$timeout', '$compile', '$document', function ($timeout, $compile, $document) {
192 template: '<div class="col-md-2">'+
193 '<div class="col-md-1"><label name="{{fixedField}}" for="{{fixedField}}_ff_input">{{fixedField}}</label></div>'+
194 '<div class="col-md-1"><input type="text" style="padding-left: 5px; margin-left: 1em" size="4" id="{{fixedField}}_ff_input"/></div>'+
196 scope: { record: "=", fixedField: "@" },
198 controller : ['$scope', '$element', 'egTagTable',
199 function ( $scope , $element , egTagTable) {
200 $($element).children().css({ display : 'none' });
202 $scope.content = null; // this is where context menus dump their values
203 $scope.item_container = [];
204 $scope.in_handler = false;
205 $scope.ready = false;
207 $scope.$watch('content', function (newVal, oldVal) {
208 var input = $($element).find('input');
210 input.trigger('keyup'); // cascade the update
213 $scope.$watch('record.ready', function (newVal, oldVal) { // wait for the record to be loaded
214 if (newVal && !$scope.ready) {
215 $scope.rtype = $scope.record.recordType();
217 egTagTable.fetchFFPosTable( $scope.rtype ).then(function (ff_list) {
218 angular.forEach(ff_list, function (ff) {
220 if (ff.fixed_field == $scope.fixedField && ff.rec_type == $scope.rtype) {
223 $($element).children().css({ display : 'inline' });
225 var input = $($element).find('input');
226 input.attr('maxlength', $scope.me.length);
227 input.val($scope.record.extractFixedField($scope.me.fixed_field));
228 input.on('keyup', function(e) {
229 $scope.in_handler = true;
230 $scope.record.setFixedField($scope.me.fixed_field, input.val());
231 try { $scope.$parent.$digest(); } catch(e) {};
237 }).then(function (me) {
241 return $scope.record.extractFixedField($scope.fixedField);
243 function (newVal, oldVal) {
244 if ($scope.in_handler) {
245 $scope.in_handler = false;
246 } else if (oldVal != newVal) {
247 $($element).find('input').val(newVal);
252 }).then(function () {
253 return egTagTable.fetchFFValueTable( $scope.rtype );
254 }).then(function (vlist) {
255 if (vlist[$scope.fixedField]) {
256 vlist[$scope.fixedField].forEach(function (v) {
257 if (v[0].length <= v[2]) {
258 $scope.item_container.push({ value : v[0], label : v[0] + ': ' + v[1] });
262 }).then(function () {
263 if ($scope.item_container && $scope.item_container.length)
264 $($element).bind('contextmenu', $scope.showContext);
270 $scope.showContext = function (event) {
271 if ($scope.context_menu_element) {
272 console.log('Reshowing context menu...');
273 $('body').trigger('click');
274 $($scope.context_menu_element).css({ display: 'block', top: event.pageY, left: event.pageX });
275 $('body').on('click.context_menu',function() {
276 $($scope.context_menu_element).css('display','none');
277 $('body').off('click.context_menu');
282 if (angular.isArray($scope.item_container)) { // we have a list of values or transforms
283 console.log('Showing context menu...');
284 $('body').trigger('click');
287 '<ul class="dropdown-menu scrollable-menu" role="menu" style="z-index: 2000;">'+
288 '<eg-context-menu-item ng-repeat="item in item_container" item="item" content="content"/>'+
291 var tnode = angular.element(tmpl);
292 $document.find('body').append(tnode);
300 $scope.context_menu_element = tnode;
302 $timeout(function() {
303 var e = $compile(tnode)($scope);
307 $('body').on('click.context_menu',function() {
308 $(tnode).css('display','none');
309 $('body').off('click.context_menu');
323 .directive("egMarcEditSubfield", function () {
328 '<span><label class="marcedit marcsfcodedelimiter"'+
329 'for="r{{field.record.subfield(\'901\',\'c\')[1]}}f{{field.position}}s{{subfield[2]}}code" '+
330 '>‡</label><eg-marc-edit-editable '+
332 'select-on-focus="true" '+
333 'advance-focus-after-input="true" '+
334 'class="marcedit marcsf marcsfcode" '+
336 'subfield="subfield" '+
337 'content="subfield[0]" '+
339 'on-keydown="onKeydown" '+
340 'context-item-generator="sf_code_options" '+
341 'id="r{{field.record.subfield(\'901\',\'c\')[1]}}f{{field.position}}s{{subfield[2]}}code" '+
343 '<span><eg-marc-edit-editable '+
345 'class="marcedit marcsf marcsfvalue" '+
347 'subfield="subfield" '+
348 'content="subfield[1]" '+
349 'on-keydown="onKeydown" '+
350 'context-item-generator="sf_val_options" '+
351 'id="r{{field.record.subfield(\'901\',\'c\')[1]}}f{{field.position}}s{{subfield[2]}}value" '+
354 scope: { field: "=", subfield: "=", onKeydown: '=' },
356 controller : ['$scope', 'egTagTable',
357 function ( $scope , egTagTable) {
359 $scope.sf_code_options = function () {
360 return egTagTable.getSubfieldCodes($scope.field.tag);
362 $scope.sf_val_options = function () {
363 return egTagTable.getSubfieldValues($scope.field.tag, $scope.subfield[0]);
370 .directive("egMarcEditInd", function () {
374 template: '<span><eg-marc-edit-editable '+
376 'class="marcedit marcind" '+
377 'select-on-focus="true" '+
378 'advance-focus-after-input="true" '+
382 'on-keydown="onKeydown" '+
383 'context-item-generator="ind_val_options" '+
384 'id="r{{field.record.subfield(\'901\',\'c\')[1]}}f{{field.position}}i{{indNumber}}"'+
386 scope: { ind : '=', field: '=', onKeydown: '=', indNumber: '@' },
388 controller : ['$scope', 'egTagTable',
389 function ( $scope , egTagTable) {
391 $scope.ind_val_options = function () {
392 return egTagTable.getIndicatorValues($scope.field.tag, $scope.indNumber);
399 .directive("egMarcEditTag", function () {
403 template: '<span><eg-marc-edit-editable '+
405 'class="marcedit marctag" '+
406 'select-on-focus="true" '+
407 'advance-focus-after-input="true" '+
411 'on-keydown="onKeydown" '+
412 'context-item-generator="tag_options" '+
413 'id="r{{field.record.subfield(\'901\',\'c\')[1]}}f{{field.position}}tag"'+
415 scope: { tag : '=', field: '=', onKeydown: '=', contextFunctions: '=' },
417 controller : ['$scope', 'egTagTable', 'egCore',
418 function ( $scope , egTagTable, egCore) {
420 $scope.tag_options = [
423 { label : egCore.strings.ADD_006, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.add006(e) } },
424 { label : egCore.strings.ADD_007, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.add007(e) } },
425 { label : egCore.strings.ADD_REPLACE_008, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.reify008(e) } },
428 if (!$scope.field.isControlfield()) {
429 options = options.concat([
430 { label : egCore.strings.INSERT_FIELD_AFTER, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.addDatafield(e) } },
431 { label : egCore.strings.INSERT_FIELD_BEFORE, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.addDatafield(e,true) } },
435 options.push({ label : egCore.strings.DELETE_FIELD, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.deleteDatafield(e) } });
438 function () { return egTagTable.getFieldTags() }
446 .directive("egMarcEditDatafield", function () {
451 '<span><eg-marc-edit-tag context-functions="contextFunctions" field="field" tag="field.tag" on-keydown="onKeydown"/></span>'+
452 '<span><eg-marc-edit-ind field="field" ind="field.ind1" on-keydown="onKeydown" ind-number="1"/></span>'+
453 '<span><eg-marc-edit-ind field="field" ind="field.ind2" on-keydown="onKeydown" ind-number="2"/></span>'+
454 '<span><eg-marc-edit-subfield ng-class="{ \'unvalidatedheading\' : field.heading_checked && !field.heading_valid, \'marcedit_stacked_subfield\' : stackSubfields.enabled }" ng-repeat="subfield in field.subfields" subfield="subfield" field="field" on-keydown="onKeydown"/></span>'+
455 // FIXME: template should probably be moved to file to improve
457 '<span ng-class="{ \'marcedit_stacked_subfield\' : stackSubfields.enabled }">' +
458 '<button class="btn btn-info btn-xs" '+
459 'aria-label="Manage authority record links" '+
460 'ng-show="isAuthorityControlled(field)"'+
461 'ng-click="spawnAuthorityLinker()"'+
463 '<span class="glyphicon glyphicon-link"></span>'+
465 '<span ng-show="field.heading_checked && field.heading_valid" class="glyphicon glyphicon-ok-sign"></span>'+
466 '<span ng-show="field.heading_checked && !field.heading_valid" class="glyphicon glyphicon-question-sign"></span>'+
469 scope: { field: "=", onKeydown: '=', contextFunctions: '=' },
471 controller : ['$scope','$modal',
472 function ( $scope, $modal ) {
473 $scope.stackSubfields = $scope.$parent.$parent.stackSubfields;
474 $scope.isAuthorityControlled = function () {
475 return ($scope.$parent.$parent.record_type == 'bre') &&
476 $scope.$parent.$parent.controlSet.bibFieldByTag($scope.field.tag);
478 $scope.spawnAuthorityLinker = function() {
479 // intentionally making a clone in case
480 // user decides to abandon the linking
481 var fieldCopy = new MARC21.Field({
482 tag : $scope.field.tag,
483 ind1 : $scope.field.ind1,
484 ind2 : $scope.field.ind2
486 angular.forEach($scope.field.subfields, function(sf) {
487 fieldCopy.subfields.push(sf.slice(0));
489 var cs = $scope.$parent.$parent.controlSet;
490 var args = { changed : false };
492 templateUrl: './cat/share/t_authority_link_dialog',
494 controller: ['$scope', '$modalInstance', function($scope, $modalInstance) {
495 $scope.controlSet = cs;
496 $scope.bibField = fieldCopy;
497 $scope.focusMe = true;
499 $scope.ok = function(args) { $modalInstance.close(args) };
500 $scope.cancel = function () { $modalInstance.dismiss() };
502 }).result.then(function (args) {
504 $scope.field.subfields.length = 0;
505 angular.forEach(fieldCopy.subfields, function(sf) {
506 $scope.field.addSubfields(sf[0], sf[1]);
516 .directive("egMarcEditControlfield", function () {
521 '<span><eg-marc-edit-tag context-functions="contextFunctions" field="field" tag="field.tag" on-keydown="onKeydown"/></span>'+
522 '<span><eg-marc-edit-editable '+
525 'class="marcedit marcdata" '+
526 'content="field.data" '+
527 'on-keydown="onKeydown" '+
528 'id="r{{field.record.subfield(\'901\',\'c\')[1]}}f{{field.position}}data"'+
530 // TODO: move to TT2 template
531 '<button class="btn btn-info btn-xs" '+
532 'aria-label="Physical Characteristics Wizard" '+
533 'ng-show="showPhysCharLink()"'+
534 'ng-click="spawnPhysCharWizard()"'+
536 '<span class="glyphicon glyphicon-link"></span>'+
539 scope: { field: "=", onKeydown: '=', contextFunctions: '=' },
540 controller : ['$scope','$modal',
541 function ( $scope, $modal) {
542 $scope.showPhysCharLink = function () {
543 return ($scope.$parent.$parent.record_type == 'bre')
544 && $scope.field.tag == '007';
546 $scope.spawnPhysCharWizard = function() {
549 field : $scope.field,
550 orig_value : $scope.field.data
553 templateUrl: './cat/share/t_physchar_dialog',
554 controller: ['$scope','$modalInstance',
555 function( $scope , $modalInstance) {
556 $scope.focusMe = true;
558 $scope.ok = function(args) { $modalInstance.close(args) };
559 $scope.cancel = function () {
560 $modalInstance.dismiss();
561 args.field.data = args.orig_value;
564 }).result.then(function (args) {
565 // $scope.field.data is changed within the
566 // wizard. Nothing left to do on submit.
575 .directive("egMarcEditLeader", function () {
580 '<span><eg-marc-edit-editable '+
581 'class="marcedit marctag" '+
583 'on-keydown="onKeydown" '+
585 'disabled="disabled"'+
587 '<span><eg-marc-edit-editable '+
588 'class="marcedit marcdata" '+
590 'max="{{record.leader.length}}" '+
591 'content="record.leader" '+
592 'id="r{{record.subfield(\'901\',\'c\')[1]}}leaderdata" '+
593 'on-keydown="onKeydown"'+
596 controller : ['$scope',
597 function ( $scope ) {
601 scope: { record: "=", onKeydown: '=' }
605 /// TODO: fixed field editor and such
606 .directive("egMarcEditRecord", function () {
608 templateUrl : './cat/share/t_marcedit',
616 // in-place mode means that the editor is being
617 // used just to munge some MARCXML client-side, rather
618 // than to (immediately) update the database
626 link: function (scope, element, attrs) {
628 element.bind('mouseup', function(e) {;
629 scope.current_event_target = $(e.target).attr('id');
630 if (scope.current_event_target && $(e.target).hasClass('noSelection')) {
636 element.bind('click', function(e) {;
637 scope.current_event_target = $(e.target).attr('id');
638 if (scope.current_event_target) {
639 console.log('Recording click event on ' + scope.current_event_target);
640 scope.current_event_target_cursor_pos =
641 e.target.selectionDirection=='backward' ?
642 e.target.selectionStart :
643 e.target.selectionEnd;
648 controller : ['$timeout','$scope','$q','$window','egCore', 'egTagTable',
649 function ( $timeout , $scope , $q, $window , egCore , egTagTable ) {
652 $scope.onSaveCallback = $scope.onSave;
653 if (typeof $scope.onSaveCallback !== 'undefined' && !angular.isArray($scope.onSaveCallback))
654 $scope.onSaveCallback = [ $scope.onSaveCallback ];
656 MARC21.Record.delimiter = '$';
658 $scope.enable_fast_add = false;
659 $scope.fast_item_callnumber = '';
660 $scope.fast_item_barcode = '';
661 $scope.flatEditor = $scope.flatOnly ? true : false;
662 $scope.brandNewRecord = false;
663 $scope.bib_source = null;
664 $scope.record_type = $scope.recordType || 'bre';
665 $scope.max_undo = $scope.maxUndo || 100;
666 $scope.record_undo_stack = [];
667 $scope.record_redo_stack = [];
668 $scope.in_undo = false;
669 $scope.in_redo = false;
670 $scope.record = new MARC21.Record();
671 $scope.save_stack_depth = 0;
672 $scope.controlfields = [];
673 $scope.datafields = [];
674 $scope.controlSet = egTagTable.getAuthorityControlSet();
675 $scope.showHelp = false;
676 $scope.stackSubfields = { enabled : false };
677 egCore.hatch.getItem('cat.marcedit.stack_subfields').then(function(val) {
678 $scope.stackSubfields.enabled = val;
680 $scope.$watch('stackSubfields.enabled', function (newVal, oldVal) {
681 if (newVal != oldVal) egCore.hatch.setItem('cat.marcedit.stack_subfields', newVal);
684 egTagTable.loadTagTable({ marcRecordType : $scope.record_type });
686 $scope.saveFlatTextMARC = function () {
687 $scope.record = new MARC21.Record({ marcbreaker : $scope.flat_text_marc });
690 $scope.refreshVisual = function () {
691 if (!$scope.flatEditor) {
692 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
693 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
697 var addDatafield = function (e,before) {
698 var element = $(e.target);
700 var index_field = e.data.scope.field.position;
701 var new_field_index = index_field;
703 var new_field = new MARC21.Field({
705 subfields : [[' ','',0]]
708 if (Boolean(before)) {
709 e.data.scope.field.record.insertFieldsBefore(
714 e.data.scope.field.record.insertFieldsAfter(
721 $scope.current_event_target = 'r' + $scope.recordId +
722 'f' + new_field_index + 'tag';
724 $scope.current_event_target_cursor_pos = 0;
725 $scope.current_event_target_cursor_pos_end = 3;
726 $scope.force_render = true;
728 $timeout(function(){$scope.$digest()}).then(setCaret);
731 var deleteDatafield = function (e) {
732 var del_field = e.data.scope.field.position;
734 var sf901c = e.data.scope.field.record.subfield('901','c');
735 var recId = (sf901c === null) ? '' : sf901c[1];
736 var domnode = $('#r' + recId + 'f' + del_field);
738 e.data.scope.field.record.deleteFields(
742 domnode.scope().$destroy();
745 $scope.current_event_target = 'r' + $scope.recordId +
746 'f' + del_field + 'tag';
748 $scope.current_event_target_cursor_pos = 0;
749 $scope.current_event_target_cursor_pos_end = 0
750 $scope.force_render = true;
752 $timeout(function(){$scope.$digest()}).then(setCaret);
755 var add006 = function (e) {
756 e.data.scope.field.record.insertOrderedFields(
763 $scope.force_render = true;
764 $timeout(function(){$scope.$digest()}).then(setCaret);
767 var add007 = function (e) {
768 e.data.scope.field.record.insertOrderedFields(
775 $scope.force_render = true;
776 $timeout(function(){$scope.$digest()}).then(setCaret);
779 var reify008 = function (e) {
780 var new_008_data = e.data.scope.field.record.generate008();
783 var old_008s = e.data.scope.field.record.field('008',true);
784 old_008s.forEach(function(o) {
785 var domnode = $('#r'+o.record.subfield('901','c')[1] + 'f' + o.position);
786 domnode.scope().$destroy();
788 e.data.scope.field.record.deleteFields(o);
791 e.data.scope.field.record.insertOrderedFields(
798 $scope.force_render = true;
799 $timeout(function(){$scope.$digest()}).then(setCaret);
802 $scope.context_functions = {
803 addDatafield : addDatafield,
804 deleteDatafield : deleteDatafield,
810 $scope.onKeydown = function (event) {
811 var event_return = true;
814 'keydown: which='+event.which+
815 ', ctrlKey='+event.ctrlKey+
816 ', shiftKey='+event.shiftKey+
817 ', altKey='+event.altKey+
818 ', metaKey='+event.altKey
821 if (event.which == 89 && event.ctrlKey) { // ctrl+y, redo
822 event_return = $scope.processRedo();
823 } else if (event.which == 90 && event.ctrlKey) { // ctrl+z, undo
824 event_return = $scope.processUndo();
825 } else if ((event.which == 68 || event.which == 73) && event.ctrlKey) { // ctrl+d or ctrl+i, insert subfield
827 var element = $(event.target);
828 var new_sf, index_sf, move_data;
830 if (element.hasClass('marcsfvalue')) {
831 index_sf = event.data.scope.subfield[2];
832 new_sf = index_sf + 1;
834 var start = event.target.selectionStart;
835 var end = event.target.selectionEnd - event.target.selectionStart ?
836 event.target.selectionEnd :
837 event.target.value.length;
839 move_data = event.target.value.substring(start,end);
841 } else if (element.hasClass('marcsfcode')) {
842 index_sf = event.data.scope.subfield[2];
843 new_sf = index_sf + 1;
844 } else if (element.hasClass('marctag') || element.hasClass('marcind')) {
849 $scope.current_event_target = 'r' + $scope.recordId +
850 'f' + event.data.scope.field.position +
851 's' + new_sf + 'code';
853 event.data.scope.field.subfields.forEach(function(sf) {
854 if (sf[2] >= new_sf) sf[2]++;
855 if (sf[2] == index_sf) sf[1] = event.target.value.substring(0,start) + event.target.value.substring(end);
857 event.data.scope.field.subfields.splice(
860 [' ', move_data, new_sf ]
863 $scope.current_event_target_cursor_pos = 0;
864 $scope.current_event_target_cursor_pos_end = 1;
866 $timeout(function(){$scope.$digest()}).then(setCaret);
868 event_return = false;
870 } else if (event.which == 117 && event.shiftKey) { // shift + F6, insert 006
872 event_return = false;
874 } else if (event.which == 118 && event.shiftKey) { // shift + F7, insert 007
876 event_return = false;
878 } else if (event.which == 119 && event.shiftKey) { // shift + F8, insert/replace 008
880 event_return = false;
882 } else if (event.which == 13 && event.ctrlKey) { // ctrl+enter, insert datafield
883 addDatafield(event, event.shiftKey); // shift key inserts before
884 event_return = false;
886 } else if (event.which == 46 && event.ctrlKey) { // ctrl+del, remove field
887 deleteDatafield(event);
888 event_return = false;
890 } else if (event.which == 46 && event.shiftKey && $(event.target).hasClass('marcsf')) { // shift+del, remove subfield
892 var sf = event.data.scope.subfield[2] - 1;
893 if (sf == -1) sf = 0;
895 event.data.scope.field.deleteExactSubfields(
896 event.data.scope.subfield
899 if (!event.data.scope.field.subfields[sf]) {
900 $scope.current_event_target = 'r' + $scope.recordId +
901 'f' + event.data.scope.field.position +
904 $scope.current_event_target = 'r' + $scope.recordId +
905 'f' + event.data.scope.field.position +
909 $scope.current_event_target_cursor_pos = 0;
910 $scope.current_event_target_cursor_pos_end = 0;
911 $scope.force_render = true;
913 $timeout(function(){$scope.$digest()}).then(setCaret);
915 event_return = false;
917 } else if (event.keyCode == 38) {
918 if (event.ctrlKey) { // copy the field up
919 var index_field = event.data.scope.field.position;
922 if (event.data.scope.field.isControlfield()) {
923 field_obj = new MARC21.Field({
924 tag : event.data.scope.field.tag,
925 data : event.data.scope.field.data
929 for (var i in event.data.scope.field.subfields) {
930 sf_clone.push(event.data.scope.field.subfields[i].slice());
932 field_obj = new MARC21.Field({
933 tag : event.data.scope.field.tag,
934 ind1 : event.data.scope.field.ind1,
935 ind2 : event.data.scope.field.ind2,
941 event.data.scope.field.record.insertFieldsBefore(
942 event.data.scope.field,
946 $scope.current_event_target = 'r' + $scope.recordId +
947 'f' + index_field + 'tag';
949 $scope.current_event_target_cursor_pos = 0;
950 $scope.current_event_target_cursor_pos_end = 3;
951 $scope.force_render = true;
953 $timeout(function(){$scope.$digest()}).then(setCaret);
955 } else { // jump to prev field
956 if (event.data.scope.field.position > 0) {
958 $scope.current_event_target_cursor_pos = 0;
959 $scope.current_event_target_cursor_pos_end = 0;
960 $scope.current_event_target = 'r' + $scope.recordId +
961 'f' + (event.data.scope.field.position - 1) +
967 event_return = false;
969 } else if (event.keyCode == 40) { // down arrow...
970 if (event.ctrlKey) { // copy the field down
972 var index_field = event.data.scope.field.position;
973 var new_field = index_field + 1;
976 if (event.data.scope.field.isControlfield()) {
977 field_obj = new MARC21.Field({
978 tag : event.data.scope.field.tag,
979 data : event.data.scope.field.data
983 for (var i in event.data.scope.field.subfields) {
984 sf_clone.push(event.data.scope.field.subfields[i].slice());
986 field_obj = new MARC21.Field({
987 tag : event.data.scope.field.tag,
988 ind1 : event.data.scope.field.ind1,
989 ind2 : event.data.scope.field.ind2,
994 event.data.scope.field.record.insertFieldsAfter(
995 event.data.scope.field,
999 $scope.current_event_target = 'r' + $scope.recordId +
1000 'f' + new_field + 'tag';
1002 $scope.current_event_target_cursor_pos = 0;
1003 $scope.current_event_target_cursor_pos_end = 3;
1004 $scope.force_render = true;
1006 $timeout(function(){$scope.$digest()}).then(setCaret);
1008 } else { // jump to next field
1009 if (event.data.scope.field.record.fields[event.data.scope.field.position + 1]) {
1010 $timeout(function(){
1011 $scope.current_event_target_cursor_pos = 0;
1012 $scope.current_event_target_cursor_pos_end = 0;
1013 $scope.current_event_target = 'r' + $scope.recordId +
1014 'f' + (event.data.scope.field.position + 1) +
1020 event_return = false;
1022 } else { // Assumes only marc editor elements have IDs that can trigger this event handler.
1023 $scope.current_event_target = $(event.target).attr('id');
1024 if ($scope.current_event_target) {
1025 $scope.current_event_target_cursor_pos =
1026 event.target.selectionDirection=='backward' ?
1027 event.target.selectionStart :
1028 event.target.selectionEnd;
1032 return event_return;
1035 function setCaret() {
1036 if ($scope.current_event_target) {
1037 console.log("Putting caret in " + $scope.current_event_target);
1038 if (!$scope.current_event_target_cursor_pos_end)
1039 $scope.current_event_target_cursor_pos_end = $scope.current_event_target_cursor_pos
1041 var element = $('#'+$scope.current_event_target).get(0);
1044 if (element.setSelectionRange) {
1045 element.setSelectionRange(
1046 $scope.current_event_target_cursor_pos,
1047 $scope.current_event_target_cursor_pos_end
1050 $scope.current_event_cursor_pos_end = null;
1051 $scope.current_event_target = null;
1056 function loadRecord() {
1057 return (function() {
1058 var deferred = $q.defer();
1059 if ($scope.recordId) {
1060 egCore.pcrud.retrieve(
1061 $scope.record_type, $scope.recordId
1062 ).then(function(rec) {
1063 deferred.resolve(rec);
1066 if ($scope.recordType == 'bre') {
1067 var bre = new egCore.idl.bre();
1068 bre.marc($scope.marcXml);
1069 deferred.resolve(bre);
1070 } else if ($scope.recordType == 'are') {
1071 var are = new egCore.idl.are();
1072 are.marc($scope.marcXml);
1073 deferred.resolve(are);
1075 $scope.brandNewRecord = true;
1077 return deferred.promise;
1078 })().then(function(rec) {
1079 $scope.in_redo = true;
1080 $scope[$scope.record_type] = rec;
1081 $scope.record = new MARC21.Record({ marcxml : $scope.Record().marc() });
1082 $scope.calculated_record_type = $scope.record.recordType();
1083 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
1084 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
1085 $scope.save_stack_depth = $scope.record_undo_stack.length;
1086 $scope.flat_text_marc = $scope.record.toBreaker();
1088 if ($scope.record_type == 'bre') {
1089 $scope.bib_source = $scope.Record().source();
1093 return egTagTable.fetchFFPosTable($scope.calculated_record_type)
1095 return egTagTable.fetchFFValueTable($scope.calculated_record_type)
1099 $scope.$watch('record.toBreaker()', function (newVal, oldVal) {
1100 if (!$scope.in_undo && !$scope.in_redo && oldVal != newVal) {
1101 $scope.record_undo_stack.push({
1103 target: $scope.current_event_target,
1104 pos: $scope.current_event_target_cursor_pos
1107 if ($scope.force_render) {
1108 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
1109 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
1110 $scope.force_render = false;
1113 $scope.flat_text_marc = newVal;
1116 if ($scope.record_undo_stack.length != $scope.save_stack_depth) {
1117 $scope.dirtyFlag = true;
1119 $scope.dirtyFlag = false;
1122 if ($scope.record_undo_stack.length > $scope.max_undo)
1123 $scope.record_undo_stack.shift();
1125 console.log('undo stack is ' + $scope.record_undo_stack.length + ' deep');
1126 $scope.in_redo = false;
1127 $scope.in_undo = false;
1130 $scope.processUndo = function () {
1131 if ($scope.record_undo_stack.length) {
1132 $scope.in_undo = true;
1134 var undo_item = $scope.record_undo_stack.pop();
1135 $scope.record_redo_stack.push(undo_item);
1137 $scope.record = new MARC21.Record({ marcbreaker : undo_item.breaker });
1138 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
1139 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
1141 $scope.current_event_target = undo_item.target;
1142 $scope.current_event_target_cursor_pos = undo_item.pos;
1143 console.log('Undo targeting ' + $scope.current_event_target + ' position ' + $scope.current_event_target_cursor_pos);
1145 $timeout(function(){$scope.$digest()}).then(setCaret);
1152 $scope.processRedo = function () {
1153 if ($scope.record_redo_stack.length) {
1154 $scope.in_redo = true;
1156 var redo_item = $scope.record_redo_stack.pop();
1157 $scope.record_undo_stack.push(redo_item);
1159 $scope.record = new MARC21.Record({ marcbreaker : redo_item.breaker });
1160 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
1161 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
1163 $scope.current_event_target = redo_item.target;
1164 $scope.current_event_target_cursor_pos = redo_item.pos;
1165 console.log('Redo targeting ' + $scope.current_event_target + ' position ' + $scope.current_event_target_cursor_pos);
1167 $timeout(function(){$scope.$digest()}).then(setCaret);
1174 $scope.Record = function () {
1175 return $scope[$scope.record_type];
1178 $scope.deleteRecord = function () {
1179 $scope.Record().deleted(true);
1180 return $scope.saveRecord();
1183 $scope.undeleteRecord = function () {
1184 $scope.Record().deleted(false);
1185 return $scope.saveRecord();
1188 $scope.validateHeadings = function () {
1189 if ($scope.record_type != 'bre') return;
1190 var chain = $q.when();
1191 angular.forEach($scope.record.fields, function(f) {
1192 if (!$scope.controlSet.bibFieldByTag(f.tag)) return;
1193 // if heading already has a $0, assume it's good
1194 if (f.subfield('0', true).length) {
1195 f.heading_checked = true;
1196 f.heading_valid = true;
1199 var auth_match = $scope.controlSet.bibToAuthorities(f);
1200 chain = chain.then(function() {
1201 var promise = egCore.net.request(
1203 'open-ils.search.authority.simple_heading.from_xml.batch.atomic',
1205 ).then(function (matches) {
1206 f.heading_valid = false;
1207 if (matches[0]) { // probably set
1208 for (var cset in matches[0]) {
1209 var arr = matches[0][cset];
1211 // protect against errant empty string values
1212 if (arr.length == 1 && arr[0] == '')
1214 f.heading_valid = true;
1219 f.heading_checked = true;
1226 processOnSaveCallbacks = function() {
1227 var deferred = $q.defer();
1228 if (typeof $scope.onSaveCallback !== 'undefined') {
1229 var promise = deferred.promise;
1231 angular.forEach($scope.onSaveCallback, function (f) {
1232 if (angular.isFunction(f)) promise = promise.then(f);
1236 return deferred.resolve($scope.recordId)
1239 $scope.saveRecord = function () {
1240 if ($scope.inPlaceMode) {
1241 $scope.marcXml = $scope.record.toXmlString();
1242 return processOnSaveCallbacks();
1244 $scope.mangle_005();
1245 $scope.Record().editor(egCore.auth.user().id());
1246 $scope.Record().edit_date('now');
1247 $scope.record.pruneEmptyFieldsAndSubfields();
1248 $scope.Record().marc($scope.record.toXmlString());
1249 if ($scope.recordId) {
1250 return egCore.pcrud.update(
1253 if ($scope.enable_fast_add) {
1256 'open-ils.actor.anon_cache.set_value',
1257 null, 'edit-these-copies', {
1258 record_id: $scope.recordId,
1260 label : $scope.fast_item_callnumber,
1261 barcode : $scope.fast_item_barcode,
1267 ).then(function(key) {
1269 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1270 $timeout(function() { $window.open(url, '_blank') });
1272 alert('Could not create anonymous cache key!');
1276 }).then(loadRecord).then(processOnSaveCallbacks);
1278 $scope.Record().creator(egCore.auth.user().id());
1279 $scope.Record().create_date('now');
1280 return egCore.pcrud.create(
1282 ).then(function(bre) {
1283 $scope.recordId = bre.id();
1284 if ($scope.enable_fast_add) {
1287 'open-ils.actor.anon_cache.set_value',
1288 null, 'edit-these-copies', {
1289 record_id: $scope.recordId,
1291 label : $scope.fast_item_callnumber,
1292 barcode : $scope.fast_item_barcode,
1297 ).then(function(key) {
1299 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1300 $timeout(function() { $window.open(url, '_blank') });
1302 alert('Could not create anonymous cache key!');
1306 }).then(loadRecord).then(processOnSaveCallbacks);
1312 $scope.seeBreaker = function () {
1313 alert($scope.record.toBreaker());
1316 $scope.$watch('recordId',
1317 function(newVal, oldVal) {
1318 if (newVal && newVal !== oldVal) {
1323 $scope.$watch('marcXml',
1324 function(newVal, oldVal) {
1325 if (newVal && newVal !== oldVal) {
1331 var unregister = $scope.$watch(function() {
1332 return egTagTable.initialized();
1336 if ($scope.recordId || $scope.marcXml) {
1342 $scope.mangle_005 = function () {
1343 var now = new Date();
1344 var y = now.getUTCFullYear();
1346 var m = now.getUTCMonth() + 1;
1347 if (m < 10) m = '0' + m;
1349 var d = now.getUTCDate();
1350 if (d < 10) d = '0' + d;
1352 var H = now.getUTCHours();
1353 if (H < 10) H = '0' + H;
1355 var M = now.getUTCMinutes();
1356 if (M < 10) M = '0' + M;
1358 var S = now.getUTCSeconds();
1359 if (S < 10) S = '0' + S;
1361 var stamp = '' + y + m + d + H + M + S + '.0';
1362 var f = $scope.record.field('005',true)[0];
1366 $scope.record.insertOrderedFields(
1381 .directive("egMarcEditBibsource", ['$timeout',function ($timeout) {
1385 template: '<span class="nullable">'+
1386 '<select class="form-control" ng-model="bib_source" ng-options="s.id() as s.source() for s in bib_sources">'+
1387 '<option value="">Select a Source</option>'+
1390 controller: ['$scope','egCore',
1391 function ($scope , egCore) {
1393 egCore.pcrud.retrieveAll('cbs', {}, {atomic : true})
1394 .then(function(list) { $scope.bib_sources = list; });
1396 $scope.$watch('bib_source',
1397 function(newVal, oldVal) {
1398 if (newVal !== oldVal) {
1399 $scope.bre.source(newVal);
1409 .directive("egMarcEditAuthorityLinker", function () {
1413 templateUrl: './cat/share/t_authority_linker',
1419 controller: ['$scope','$modal','egCore','egAuth',
1420 function ($scope , $modal, egCore, egAuth) {
1422 $scope.searchStr = '';
1423 var cni = egCore.env.aous['cat.marc_control_number_identifier'] ||
1424 'Set cat.marc_control_number_identifier in Library Settings';
1426 var axis_list = $scope.controlSet.bibFieldBrowseAxes($scope.bibField.tag);
1427 $scope.axis = axis_list[0];
1429 $scope._controlled_sf_list = {};
1430 $scope._controlled_auth_sf_list = {};
1432 angular.forEach($scope.controlSet.controlSetList(), function(acs_id) {
1433 if ($scope.controlSet.controlSet(acs_id).control_map[$scope.bibField.tag])
1434 found_acs.push(acs_id);
1436 if (found_acs.length) {
1437 angular.forEach($scope.controlSet.controlSet(found_acs[0]).control_map[$scope.bibField.tag],
1438 function(value, sf_label) {
1439 $scope._controlled_sf_list[ sf_label ] = 1;
1440 angular.forEach($scope.controlSet.controlSet(found_acs[0]).control_map[$scope.bibField.tag][sf_label],
1441 function(auth_sf, auth_tag) {
1442 if (!$scope._controlled_auth_sf_list[auth_tag]) {
1443 $scope._controlled_auth_sf_list[auth_tag] = { };
1445 $scope._controlled_auth_sf_list[auth_tag][auth_sf] = 1;
1452 $scope.bibField.subfields.forEach(function (sf) {
1453 if (sf[0] in $scope._controlled_sf_list) {
1455 sf.selectable = true;
1457 sf.selectable = false;
1460 $scope.summarizeField = function() {
1462 'tag': $scope.bibField.tag,
1463 'ind1': $scope.bibField.ind1,
1464 'ind2': $scope.bibField.ind2,
1467 $scope.bibField.subfields.forEach(function(sf) {
1469 source_f.subfields.push([ sf[0], sf[1] ]);
1474 $scope.getSearchString = function() {
1475 var source_f = $scope.summarizeField();
1477 angular.forEach(source_f.subfields, function(val) {
1478 values.push(val[1]);
1480 return values.join(' ');
1482 $scope.searchStr = $scope.getSearchString();
1483 $scope.$watch(function() {
1485 angular.forEach($scope.bibField.subfields, function(sf) {
1486 if (sf.selected) ct++
1490 function(newVal, oldVal) {
1491 $scope.searchStr = $scope.getSearchString();
1494 $scope.updateSubfieldZero = function(value) {
1495 $scope.changed = true;
1496 $scope.bibField.deleteSubfield({ code : ['0'] });
1497 $scope.bibField.subfields.push([
1498 '0', '(' + cni + ')' + value
1502 $scope.applyHeading = function(headingField) {
1503 // TODO: move the MARC21 rules for copying indicators
1505 if (headingField.tag == '130' && $scope.bibField.tag == '130') {
1506 $scope.bibField.ind1 = headingField.ind2;
1508 $scope.bibField.ind1 = headingField.ind1;
1510 // deal with 4xx and 5xx
1511 var authFallbackTag = '1' + headingField.tag.substr(1, 2);
1512 var _valid_auth_sfs = (headingField.tag in $scope._controlled_auth_sf_list) ?
1513 $scope._controlled_auth_sf_list[headingField.tag] :
1514 (authFallbackTag in $scope._controlled_auth_sf_list) ?
1515 $scope._controlled_auth_sf_list[authFallbackTag] :
1517 // save the $0 for later use
1519 if (headingField.subfield('0')) {
1520 sfZero = headingField.subfield('0')[1];
1522 // grab any bib subfields not under authority control
1523 // TODO do something about uncontrolled subdivisions
1524 var uncontrolledBibSf = [];
1525 angular.forEach($scope.bibField.subfields, function(sf) {
1526 if (!(sf[0] in $scope._controlled_sf_list) && (sf[0] != '0')) {
1527 uncontrolledBibSf.push([ sf[0], sf[1] ]);
1530 // grab the authority subfields
1531 var authoritySf = [];
1532 angular.forEach(headingField.subfields, function(sf) {
1533 if (sf[0] in _valid_auth_sfs) {
1534 authoritySf.push([ sf[0], sf[1] ]);
1537 $scope.bibField.subfields.length = 0;
1538 angular.forEach(authoritySf, function(sf) {
1539 $scope.bibField.addSubfields(sf[0], sf[1]);
1541 angular.forEach(uncontrolledBibSf, function(sf) {
1542 $scope.bibField.addSubfields(sf[0], sf[1]);
1545 $scope.bibField.addSubfields('0', sfZero);
1547 $scope.bibField.subfields.forEach(function (sf) {
1548 if (sf[0] in $scope._controlled_sf_list) {
1549 // intentionally not selecting any subfields
1550 // after we've applied an authority heading
1551 sf.selected = false;
1552 sf.selectable = true;
1554 sf.selectable = false;
1557 $scope.changed = true;
1560 $scope.createAuthorityFromBib = function(spawn_editor) {
1561 var source_f = $scope.summarizeField();
1563 var args = { authority_id : 0 };
1564 var method = (spawn_editor) ?
1565 'open-ils.cat.authority.record.create_from_bib.readonly' :
1566 'open-ils.cat.authority.record.create_from_bib';
1573 ).then(function(newAuthority) {
1576 templateUrl: './cat/share/t_edit_new_authority',
1579 ['$scope', '$modalInstance', function($scope, $modalInstance) {
1580 $scope.focusMe = true;
1582 $scope.dirty_flag = false;
1583 $scope.marc_xml = newAuthority,
1584 $scope.ok = function(args) { $modalInstance.close(args) }
1585 $scope.cancel = function () { $modalInstance.dismiss() }
1587 }).result.then(function (args) {
1588 if (!args || !args.authority_id) return;
1589 $scope.updateSubfieldZero(args.authority_id);
1592 $scope.updateSubfieldZero(newAuthority.id());
1602 .directive("egPhyscharWizard", function () {
1606 templateUrl: './cat/share/t_physchar_wizard',
1610 controller: ['$scope','$q','egTagTable',
1611 function ($scope , $q , egTagTable) {
1613 // $scope.step is the 1-based position in the list of
1614 // subfields for the currently selected type.
1615 // step==0 means we are currently selecting the type
1618 if (!$scope.field.data)
1619 $scope.field.data = '';
1621 // currently selected subfield value selector option
1622 $scope.selected_option = null;
1624 function current_ptype() {
1625 return $scope.field.data.substr(0, 1);
1628 function current_subfield() {
1629 return egTagTable.getPhysCharSubfieldMap(current_ptype())
1630 .then(function(sf_list) {return sf_list[$scope.step-1]});
1633 $scope.values_for_step = [];
1634 function set_values_for_step() {
1637 if ($scope.step == 0) {
1638 promise = egTagTable.getPhysCharTypeMap();
1640 promise = current_subfield().then(
1641 function(subfield) {
1643 .getPhysCharValueMap(subfield.id());
1648 return promise.then(function(list) {
1649 $scope.values_for_step = list;
1650 set_selected_option_from_field();
1651 set_label_for_step();
1655 $scope.change_ptype = function(option) {
1656 $scope.selected_option = option;
1657 var new_val = option.ptype_key();
1658 if (current_ptype() != new_val) {
1659 $scope.field.data = new_val; // total reset
1663 $scope.change_option = function(option) {
1664 $scope.selected_option = option;
1665 var new_val = option.value();
1666 get_step_slot().then(function(slot) {
1667 var value = $scope.field.data;
1668 while (value.length < (slot[0] + slot[1]))
1670 var before = value.substr(0, slot[0]);
1671 var after = value.substr(slot[0] + slot[1]);
1673 before + new_val.substr(0, slot[1]) + after;
1677 function get_step_slot() {
1678 if ($scope.step == 0) return $q.when([0, 1]);
1679 return current_subfield().then(function(sf) {
1680 return [sf.start_pos(), sf.length()]
1684 $scope.is_last_step = function() {
1685 // This one is called w/ every digest, so avoid async
1686 // calls. Wait until we have loaded the current ptype
1687 // subfields to determine if this is the last step.
1690 egTagTable.phys_char_sf_map[current_ptype()] &&
1691 egTagTable.phys_char_sf_map[current_ptype()].length
1696 $scope.label_for_step = '';
1697 function set_label_for_step() {
1698 if ($scope.step > 0) {
1699 current_subfield().then(function(sf) {
1700 $scope.label_for_step = sf.label();
1705 $scope.next_step = function() {
1707 set_values_for_step();
1710 $scope.prev_step = function() {
1712 set_values_for_step();
1715 function set_selected_option_from_field() {
1716 if ($scope.step == 0) {
1717 $scope.selected_option = $scope.values_for_step
1718 .filter(function(opt) {
1719 return (opt.ptype_key() == current_ptype())})[0];
1721 get_step_slot().then(function(slot) {
1722 var val = String.prototype.substr.apply(
1723 $scope.field.data, slot);
1725 $scope.selected_option = $scope.values_for_step
1726 .filter(function(opt) {
1727 return (opt.value() == val)})[0];
1729 $scope.selected_option = null;
1734 set_values_for_step();
1741 .directive("egMarcEditAuthorityBrowser", function () {
1745 templateUrl: './cat/share/t_authority_browser',
1752 controller: ['$scope','$http',
1753 function ($scope , $http) {
1757 $scope.main_headings = [];
1759 function getHeadingString(headingField) {
1761 angular.forEach(headingField.subfields, function (sf) {
1762 if (['x', 'y', 'z'].indexOf(sf[0]) > -1) {
1773 $scope.doBrowse = function() {
1774 $scope.main_headings.length = 0;
1775 if ($scope.searchString.length == 0) return;
1776 var type = 'authority.'
1777 var url = '/opac/extras/browse/marcxml/'
1778 + 'authority.' + $scope.axis + '.refs'
1779 + '/1' // OU - currently unscoped
1780 + '/' + $scope.searchString
1782 + '/' + $scope.limit;
1786 transformResponse : function(data) {
1787 // use a bit of jQuery to deal with the XML
1788 var $xml = $( $.parseXML(data) );
1790 $xml.find('record').each(function() {
1791 var rec = new MARC21.Record();
1792 rec.fromXmlDocument($(this)[0].outerHTML);
1797 }).then(function(response) {
1798 angular.forEach(response.data, function(rec) {
1799 var authId = rec.subfield('901', 'c')[1];
1801 if (rec.field('003')) {
1802 auth_org = rec.field('003').data;
1804 var headingField = rec.field('1..');
1805 var seeFroms = rec.field('4..', true);
1806 var seeAlsos = rec.field('5..', true);
1808 var main_heading = {
1809 authority_id : authId,
1810 heading : getHeadingString(headingField),
1811 seealso_headings : [ ],
1812 seefrom_headings : [ ],
1817 sfZero = '(' + auth_org + ')';
1820 headingField.addSubfields('0', sfZero);
1822 main_heading['headingField'] = headingField;
1823 angular.forEach(seeAlsos, function(headingField) {
1824 main_heading.seealso_headings.push({
1825 heading : getHeadingString(headingField),
1826 headingField : headingField
1829 angular.forEach(seeFroms, function(headingField) {
1830 main_heading.seefrom_headings.push({
1831 heading : getHeadingString(headingField),
1832 headingField : headingField
1835 $scope.main_headings.push(main_heading);
1840 $scope.$watch('searchString',
1841 function(newVal, oldVal) {
1842 if (newVal !== oldVal) {
1847 $scope.$watch('page',
1848 function(newVal, oldVal) {
1849 if (newVal !== oldVal) {