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;
206 $element.find('input').bind('focus', function (e) { e.target.select() });
207 $element.find('input').bind('mouseup', function(e) {
212 $scope.$watch('content', function (newVal, oldVal) {
213 var input = $($element).find('input');
215 input.trigger('keyup'); // cascade the update
218 $scope.$watch('record.ready', function (newVal, oldVal) { // wait for the record to be loaded
219 if (newVal && !$scope.ready) {
220 $scope.rtype = $scope.record.recordType();
222 egTagTable.fetchFFPosTable( $scope.rtype ).then(function (ff_list) {
223 angular.forEach(ff_list, function (ff) {
225 if (ff.fixed_field == $scope.fixedField && ff.rec_type == $scope.rtype) {
228 $($element).children().css({ display : 'inline' });
230 var input = $($element).find('input');
231 input.attr('maxlength', $scope.me.length);
232 input.val($scope.record.extractFixedField($scope.me.fixed_field));
233 input.on('keyup', function(e) {
234 $scope.in_handler = true;
235 $scope.record.setFixedField($scope.me.fixed_field, input.val());
236 try { $scope.$parent.$digest(); } catch(e) {};
242 }).then(function (me) {
246 return $scope.record.extractFixedField($scope.fixedField);
248 function (newVal, oldVal) {
249 if ($scope.in_handler) {
250 $scope.in_handler = false;
251 } else if (oldVal != newVal) {
252 $($element).find('input').val(newVal);
257 }).then(function () {
258 return egTagTable.fetchFFValueTable( $scope.rtype );
259 }).then(function (vlist) {
260 if (vlist[$scope.fixedField]) {
261 vlist[$scope.fixedField].forEach(function (v) {
262 if (v[0].length <= v[2]) {
263 $scope.item_container.push({ value : v[0], label : v[0] + ': ' + v[1] });
267 }).then(function () {
268 if ($scope.item_container && $scope.item_container.length)
269 $($element).bind('contextmenu', $scope.showContext);
275 $scope.showContext = function (event) {
276 if ($scope.context_menu_element) {
277 console.log('Reshowing context menu...');
278 $('body').trigger('click');
279 $($scope.context_menu_element).css({ display: 'block', top: event.pageY, left: event.pageX });
280 $('body').on('click.context_menu',function() {
281 $($scope.context_menu_element).css('display','none');
282 $('body').off('click.context_menu');
287 if (angular.isArray($scope.item_container)) { // we have a list of values or transforms
288 console.log('Showing context menu...');
289 $('body').trigger('click');
292 '<ul class="dropdown-menu scrollable-menu" role="menu" style="z-index: 2000;">'+
293 '<eg-context-menu-item ng-repeat="item in item_container" item="item" content="content"/>'+
296 var tnode = angular.element(tmpl);
297 $document.find('body').append(tnode);
305 $scope.context_menu_element = tnode;
307 $timeout(function() {
308 var e = $compile(tnode)($scope);
312 $('body').on('click.context_menu',function() {
313 $(tnode).css('display','none');
314 $('body').off('click.context_menu');
328 .directive("egMarcEditSubfield", function () {
333 '<span><label class="marcedit marcsfcodedelimiter"'+
334 'for="r{{field.record.subfield(\'901\',\'c\')[1] || 0}}f{{field.position}}s{{subfield[2]}}code" '+
335 '>‡</label><eg-marc-edit-editable '+
337 'select-on-focus="true" '+
338 'advance-focus-after-input="true" '+
339 'class="marcedit marcsf marcsfcode" '+
341 'subfield="subfield" '+
342 'content="subfield[0]" '+
344 'on-keydown="onKeydown" '+
345 'context-item-generator="sf_code_options" '+
346 'id="r{{field.record.subfield(\'901\',\'c\')[1] || 0}}f{{field.position}}s{{subfield[2]}}code" '+
348 '<span><eg-marc-edit-editable '+
350 'class="marcedit marcsf marcsfvalue" '+
352 'subfield="subfield" '+
353 'content="subfield[1]" '+
354 'on-keydown="onKeydown" '+
355 'context-item-generator="sf_val_options" '+
356 'id="r{{field.record.subfield(\'901\',\'c\')[1] || 0}}f{{field.position}}s{{subfield[2]}}value" '+
359 scope: { field: "=", subfield: "=", onKeydown: '=' },
361 controller : ['$scope', 'egTagTable',
362 function ( $scope , egTagTable) {
364 $scope.sf_code_options = function () {
365 return egTagTable.getSubfieldCodes($scope.field.tag);
367 $scope.sf_val_options = function () {
368 return egTagTable.getSubfieldValues($scope.field.tag, $scope.subfield[0]);
375 .directive("egMarcEditInd", function () {
379 template: '<span><eg-marc-edit-editable '+
381 'class="marcedit marcind" '+
382 'select-on-focus="true" '+
383 'advance-focus-after-input="true" '+
387 'on-keydown="onKeydown" '+
388 'context-item-generator="ind_val_options" '+
389 'id="r{{field.record.subfield(\'901\',\'c\')[1] || 0}}f{{field.position}}i{{indNumber}}"'+
391 scope: { ind : '=', field: '=', onKeydown: '=', indNumber: '@' },
393 controller : ['$scope', 'egTagTable',
394 function ( $scope , egTagTable) {
396 $scope.ind_val_options = function () {
397 return egTagTable.getIndicatorValues($scope.field.tag, $scope.indNumber);
404 .directive("egMarcEditTag", function () {
408 template: '<span><eg-marc-edit-editable '+
410 'class="marcedit marctag" '+
411 'select-on-focus="true" '+
412 'advance-focus-after-input="true" '+
416 'on-keydown="onKeydown" '+
417 'context-item-generator="tag_options" '+
418 'id="r{{field.record.subfield(\'901\',\'c\')[1] || 0}}f{{field.position}}tag"'+
420 scope: { tag : '=', field: '=', onKeydown: '=', contextFunctions: '=' },
422 controller : ['$scope', 'egTagTable', 'egCore',
423 function ( $scope , egTagTable, egCore) {
425 $scope.tag_options = [
428 { label : egCore.strings.ADD_006, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.add006(e) } },
429 { label : egCore.strings.ADD_007, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.add007(e) } },
430 { label : egCore.strings.ADD_REPLACE_008, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.reify008(e) } },
433 if (!$scope.field.isControlfield()) {
434 options = options.concat([
435 { label : egCore.strings.INSERT_FIELD_AFTER, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.addDatafield(e) } },
436 { label : egCore.strings.INSERT_FIELD_BEFORE, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.addDatafield(e,true) } },
440 options.push({ label : egCore.strings.DELETE_FIELD, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.deleteDatafield(e) } });
443 function () { return egTagTable.getFieldTags() }
451 .directive("egMarcEditDatafield", function () {
456 '<span><eg-marc-edit-tag context-functions="contextFunctions" field="field" tag="field.tag" on-keydown="onKeydown"/></span>'+
457 '<span><eg-marc-edit-ind field="field" ind="field.ind1" on-keydown="onKeydown" ind-number="1"/></span>'+
458 '<span><eg-marc-edit-ind field="field" ind="field.ind2" on-keydown="onKeydown" ind-number="2"/></span>'+
459 '<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>'+
460 // FIXME: template should probably be moved to file to improve
462 '<span ng-class="{ \'marcedit_stacked_subfield\' : stackSubfields.enabled }">' +
463 '<button class="btn btn-info btn-xs" '+
464 'aria-label="Manage authority record links" '+
465 'ng-show="isAuthorityControlled(field)"'+
466 'ng-click="spawnAuthorityLinker()"'+
468 '<span class="glyphicon glyphicon-link"></span>'+
470 '<span ng-show="field.heading_checked && field.heading_valid" class="glyphicon glyphicon-ok-sign"></span>'+
471 '<span ng-show="field.heading_checked && !field.heading_valid" class="glyphicon glyphicon-question-sign"></span>'+
474 scope: { field: "=", onKeydown: '=', contextFunctions: '=' },
476 controller : ['$scope','$modal',
477 function ( $scope, $modal ) {
478 $scope.stackSubfields = $scope.$parent.$parent.stackSubfields;
479 $scope.isAuthorityControlled = function () {
480 return ($scope.$parent.$parent.record_type == 'bre') &&
481 $scope.$parent.$parent.controlSet.bibFieldByTag($scope.field.tag);
483 $scope.spawnAuthorityLinker = function() {
484 // intentionally making a clone in case
485 // user decides to abandon the linking
486 var fieldCopy = new MARC21.Field({
487 tag : $scope.field.tag,
488 ind1 : $scope.field.ind1,
489 ind2 : $scope.field.ind2
491 angular.forEach($scope.field.subfields, function(sf) {
492 fieldCopy.subfields.push(sf.slice(0));
494 var cs = $scope.$parent.$parent.controlSet;
495 var args = { changed : false };
497 templateUrl: './cat/share/t_authority_link_dialog',
499 controller: ['$scope', '$modalInstance', function($scope, $modalInstance) {
500 $scope.controlSet = cs;
501 $scope.bibField = fieldCopy;
502 $scope.focusMe = true;
504 $scope.ok = function(args) { $modalInstance.close(args) };
505 $scope.cancel = function () { $modalInstance.dismiss() };
507 }).result.then(function (args) {
509 $scope.field.subfields.length = 0;
510 angular.forEach(fieldCopy.subfields, function(sf) {
511 $scope.field.addSubfields(sf[0], sf[1]);
521 .directive("egMarcEditControlfield", function () {
526 '<span><eg-marc-edit-tag context-functions="contextFunctions" field="field" tag="field.tag" on-keydown="onKeydown"/></span>'+
527 '<span><eg-marc-edit-editable '+
530 'class="marcedit marcdata" '+
531 'content="field.data" '+
532 'on-keydown="onKeydown" '+
533 'id="r{{field.record.subfield(\'901\',\'c\')[1] || 0}}f{{field.position}}data"'+
535 // TODO: move to TT2 template
536 '<button class="btn btn-info btn-xs" '+
537 'aria-label="Physical Characteristics Wizard" '+
538 'ng-show="showPhysCharLink()"'+
539 'ng-click="spawnPhysCharWizard()"'+
541 '<span class="glyphicon glyphicon-link"></span>'+
544 scope: { field: "=", onKeydown: '=', contextFunctions: '=' },
545 controller : ['$scope','$modal',
546 function ( $scope, $modal) {
547 $scope.showPhysCharLink = function () {
548 return ($scope.$parent.$parent.record_type == 'bre')
549 && $scope.field.tag == '007';
551 $scope.spawnPhysCharWizard = function() {
554 field : $scope.field,
555 orig_value : $scope.field.data
558 templateUrl: './cat/share/t_physchar_dialog',
559 controller: ['$scope','$modalInstance',
560 function( $scope , $modalInstance) {
561 $scope.focusMe = true;
563 $scope.ok = function(args) { $modalInstance.close(args) };
564 $scope.cancel = function () {
565 $modalInstance.dismiss();
566 args.field.data = args.orig_value;
569 }).result.then(function (args) {
570 // $scope.field.data is changed within the
571 // wizard. Nothing left to do on submit.
580 .directive("egMarcEditLeader", function () {
585 '<span><eg-marc-edit-editable '+
586 'class="marcedit marctag" '+
588 'on-keydown="onKeydown" '+
590 'disabled="disabled"'+
592 '<span><eg-marc-edit-editable '+
593 'class="marcedit marcdata" '+
595 'max="{{record.leader.length}}" '+
596 'content="record.leader" '+
597 'id="r{{record.subfield(\'901\',\'c\')[1] || 0}}leaderdata" '+
598 'on-keydown="onKeydown"'+
601 controller : ['$scope',
602 function ( $scope ) {
606 scope: { record: "=", onKeydown: '=' }
610 /// TODO: fixed field editor and such
611 .directive("egMarcEditRecord", function () {
613 templateUrl : './cat/share/t_marcedit',
621 // in-place mode means that the editor is being
622 // used just to munge some MARCXML client-side, rather
623 // than to (immediately) update the database
632 link: function (scope, element, attrs) {
634 element.bind('mouseup', function(e) {;
635 scope.current_event_target = $(e.target).attr('id');
636 if (scope.current_event_target && $(e.target).hasClass('noSelection')) {
642 element.bind('click', function(e) {;
643 scope.current_event_target = $(e.target).attr('id');
644 if (scope.current_event_target) {
645 console.log('Recording click event on ' + scope.current_event_target);
646 scope.current_event_target_cursor_pos =
647 e.target.selectionDirection=='backward' ?
648 e.target.selectionStart :
649 e.target.selectionEnd;
654 controller : ['$timeout','$scope','$q','$window','egCore', 'egTagTable','egConfirmDialog','egAlertDialog',
655 function ( $timeout , $scope , $q, $window , egCore , egTagTable , egConfirmDialog , egAlertDialog ) {
658 $scope.onSaveCallback = $scope.onSave;
659 if (typeof $scope.onSaveCallback !== 'undefined' && !angular.isArray($scope.onSaveCallback))
660 $scope.onSaveCallback = [ $scope.onSaveCallback ];
662 MARC21.Record.delimiter = '$';
664 $scope.enable_fast_add = false;
665 $scope.fast_item_callnumber = '';
666 $scope.fast_item_barcode = '';
667 $scope.flatEditor = $scope.flatOnly ? true : false;
668 $scope.brandNewRecord = false;
669 $scope.bib_source = null;
670 $scope.record_type = $scope.recordType || 'bre';
671 $scope.max_undo = $scope.maxUndo || 100;
672 $scope.record_undo_stack = [];
673 $scope.record_redo_stack = [];
674 $scope.in_undo = false;
675 $scope.in_redo = false;
676 $scope.record = new MARC21.Record();
677 $scope.save_stack_depth = 0;
678 $scope.controlfields = [];
679 $scope.datafields = [];
680 $scope.controlSet = egTagTable.getAuthorityControlSet();
681 $scope.showHelp = false;
682 $scope.stackSubfields = { enabled : false };
683 egCore.hatch.getItem('cat.marcedit.stack_subfields').then(function(val) {
684 $scope.stackSubfields.enabled = val;
686 $scope.$watch('stackSubfields.enabled', function (newVal, oldVal) {
687 if (newVal != oldVal) egCore.hatch.setItem('cat.marcedit.stack_subfields', newVal);
690 egTagTable.loadTagTable({ marcRecordType : $scope.record_type });
692 $scope.saveFlatTextMARC = function () {
693 $scope.record = new MARC21.Record({ marcbreaker : $scope.flat_text_marc });
696 $scope.refreshVisual = function () {
697 if (!$scope.flatEditor) {
698 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
699 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
703 var addDatafield = function (e,before) {
704 var element = $(e.target);
706 var index_field = e.data.scope.field.position;
707 var new_field_index = index_field;
709 var new_field = new MARC21.Field({
711 subfields : [[' ','',0]]
714 if (Boolean(before)) {
715 e.data.scope.field.record.insertFieldsBefore(
720 e.data.scope.field.record.insertFieldsAfter(
727 $scope.current_event_target = 'r' + $scope.recordId +
728 'f' + new_field_index + 'tag';
730 $scope.current_event_target_cursor_pos = 0;
731 $scope.current_event_target_cursor_pos_end = 3;
732 $scope.force_render = true;
734 $timeout(function(){$scope.$digest()}).then(setCaret);
737 var deleteDatafield = function (e) {
738 var del_field = e.data.scope.field.position;
740 var sf901c = e.data.scope.field.record.subfield('901','c');
741 var recId = (sf901c === null) ? '' : sf901c[1];
742 var domnode = $('#r' + recId + 'f' + del_field);
744 e.data.scope.field.record.deleteFields(
748 domnode.scope().$destroy();
751 $scope.current_event_target = 'r' + $scope.recordId +
752 'f' + del_field + 'tag';
754 $scope.current_event_target_cursor_pos = 0;
755 $scope.current_event_target_cursor_pos_end = 0
756 $scope.force_render = true;
758 $timeout(function(){$scope.$digest()}).then(setCaret);
761 var add006 = function (e) {
762 e.data.scope.field.record.insertOrderedFields(
769 $scope.force_render = true;
770 $timeout(function(){$scope.$digest()}).then(setCaret);
773 var add007 = function (e) {
774 e.data.scope.field.record.insertOrderedFields(
781 $scope.force_render = true;
782 $timeout(function(){$scope.$digest()}).then(setCaret);
785 var reify008 = function (e) {
786 var new_008_data = e.data.scope.field.record.generate008();
789 var old_008s = e.data.scope.field.record.field('008',true);
790 old_008s.forEach(function(o) {
791 var domnode = $('#r'+o.record.subfield('901','c')[1] + 'f' + o.position);
792 domnode.scope().$destroy();
794 e.data.scope.field.record.deleteFields(o);
797 e.data.scope.field.record.insertOrderedFields(
804 $scope.force_render = true;
805 $timeout(function(){$scope.$digest()}).then(setCaret);
808 $scope.context_functions = {
809 addDatafield : addDatafield,
810 deleteDatafield : deleteDatafield,
816 $scope.onKeydown = function (event) {
817 var event_return = true;
820 'keydown: which='+event.which+
821 ', ctrlKey='+event.ctrlKey+
822 ', shiftKey='+event.shiftKey+
823 ', altKey='+event.altKey+
824 ', metaKey='+event.altKey
827 if (event.which == 89 && event.ctrlKey) { // ctrl+y, redo
828 event_return = $scope.processRedo();
829 } else if (event.which == 90 && event.ctrlKey) { // ctrl+z, undo
830 event_return = $scope.processUndo();
831 } else if ((event.which == 68 || event.which == 73) && event.ctrlKey) { // ctrl+d or ctrl+i, insert subfield
833 var element = $(event.target);
834 var new_sf, index_sf, move_data;
836 if (element.hasClass('marcsfvalue')) {
837 index_sf = event.data.scope.subfield[2];
838 new_sf = index_sf + 1;
840 var start = event.target.selectionStart;
841 var end = event.target.selectionEnd - event.target.selectionStart ?
842 event.target.selectionEnd :
843 event.target.value.length;
845 move_data = event.target.value.substring(start,end);
847 } else if (element.hasClass('marcsfcode')) {
848 index_sf = event.data.scope.subfield[2];
849 new_sf = index_sf + 1;
850 } else if (element.hasClass('marctag') || element.hasClass('marcind')) {
855 $scope.current_event_target = 'r' + $scope.recordId +
856 'f' + event.data.scope.field.position +
857 's' + new_sf + 'code';
859 event.data.scope.field.subfields.forEach(function(sf) {
860 if (sf[2] >= new_sf) sf[2]++;
861 if (sf[2] == index_sf) sf[1] = event.target.value.substring(0,start) + event.target.value.substring(end);
863 event.data.scope.field.subfields.splice(
866 [' ', move_data, new_sf ]
869 $scope.current_event_target_cursor_pos = 0;
870 $scope.current_event_target_cursor_pos_end = 1;
872 $timeout(function(){$scope.$digest()}).then(setCaret);
874 event_return = false;
876 } else if (event.which == 117 && event.shiftKey) { // shift + F6, insert 006
878 event_return = false;
880 } else if (event.which == 118 && event.shiftKey) { // shift + F7, insert 007
882 event_return = false;
884 } else if (event.which == 119 && event.shiftKey) { // shift + F8, insert/replace 008
886 event_return = false;
888 } else if (event.which == 13 && event.ctrlKey) { // ctrl+enter, insert datafield
889 addDatafield(event, event.shiftKey); // shift key inserts before
890 event_return = false;
892 } else if (event.which == 46 && event.ctrlKey) { // ctrl+del, remove field
893 deleteDatafield(event);
894 event_return = false;
896 } else if (event.which == 46 && event.shiftKey && $(event.target).hasClass('marcsf')) { // shift+del, remove subfield
898 var sf = event.data.scope.subfield[2] - 1;
899 if (sf == -1) sf = 0;
901 event.data.scope.field.deleteExactSubfields(
902 event.data.scope.subfield
905 if (!event.data.scope.field.subfields[sf]) {
906 $scope.current_event_target = 'r' + $scope.recordId +
907 'f' + event.data.scope.field.position +
910 $scope.current_event_target = 'r' + $scope.recordId +
911 'f' + event.data.scope.field.position +
915 $scope.current_event_target_cursor_pos = 0;
916 $scope.current_event_target_cursor_pos_end = 0;
917 $scope.force_render = true;
919 $timeout(function(){$scope.$digest()}).then(setCaret);
921 event_return = false;
923 } else if (event.keyCode == 38) {
924 if (event.ctrlKey) { // copy the field up
925 var index_field = event.data.scope.field.position;
928 if (event.data.scope.field.isControlfield()) {
929 field_obj = new MARC21.Field({
930 tag : event.data.scope.field.tag,
931 data : event.data.scope.field.data
935 for (var i in event.data.scope.field.subfields) {
936 sf_clone.push(event.data.scope.field.subfields[i].slice());
938 field_obj = new MARC21.Field({
939 tag : event.data.scope.field.tag,
940 ind1 : event.data.scope.field.ind1,
941 ind2 : event.data.scope.field.ind2,
947 event.data.scope.field.record.insertFieldsBefore(
948 event.data.scope.field,
952 $scope.current_event_target = 'r' + $scope.recordId +
953 'f' + index_field + 'tag';
955 $scope.current_event_target_cursor_pos = 0;
956 $scope.current_event_target_cursor_pos_end = 3;
957 $scope.force_render = true;
959 $timeout(function(){$scope.$digest()}).then(setCaret);
961 } else { // jump to prev field
962 if (event.data.scope.field.position > 0) {
964 $scope.current_event_target_cursor_pos = 0;
965 $scope.current_event_target_cursor_pos_end = 0;
966 $scope.current_event_target = 'r' + $scope.recordId +
967 'f' + (event.data.scope.field.position - 1) +
973 event_return = false;
975 } else if (event.keyCode == 40) { // down arrow...
976 if (event.ctrlKey) { // copy the field down
978 var index_field = event.data.scope.field.position;
979 var new_field = index_field + 1;
982 if (event.data.scope.field.isControlfield()) {
983 field_obj = new MARC21.Field({
984 tag : event.data.scope.field.tag,
985 data : event.data.scope.field.data
989 for (var i in event.data.scope.field.subfields) {
990 sf_clone.push(event.data.scope.field.subfields[i].slice());
992 field_obj = new MARC21.Field({
993 tag : event.data.scope.field.tag,
994 ind1 : event.data.scope.field.ind1,
995 ind2 : event.data.scope.field.ind2,
1000 event.data.scope.field.record.insertFieldsAfter(
1001 event.data.scope.field,
1005 $scope.current_event_target = 'r' + $scope.recordId +
1006 'f' + new_field + 'tag';
1008 $scope.current_event_target_cursor_pos = 0;
1009 $scope.current_event_target_cursor_pos_end = 3;
1010 $scope.force_render = true;
1012 $timeout(function(){$scope.$digest()}).then(setCaret);
1014 } else { // jump to next field
1015 if (event.data.scope.field.record.fields[event.data.scope.field.position + 1]) {
1016 $timeout(function(){
1017 $scope.current_event_target_cursor_pos = 0;
1018 $scope.current_event_target_cursor_pos_end = 0;
1019 $scope.current_event_target = 'r' + $scope.recordId +
1020 'f' + (event.data.scope.field.position + 1) +
1026 event_return = false;
1028 } else { // Assumes only marc editor elements have IDs that can trigger this event handler.
1029 $scope.current_event_target = $(event.target).attr('id');
1030 if ($scope.current_event_target) {
1031 $scope.current_event_target_cursor_pos =
1032 event.target.selectionDirection=='backward' ?
1033 event.target.selectionStart :
1034 event.target.selectionEnd;
1038 return event_return;
1041 function setCaret() {
1042 if ($scope.current_event_target) {
1043 console.log("Putting caret in " + $scope.current_event_target);
1044 if (!$scope.current_event_target_cursor_pos_end)
1045 $scope.current_event_target_cursor_pos_end = $scope.current_event_target_cursor_pos
1047 var element = $('#'+$scope.current_event_target).get(0);
1050 if (element.setSelectionRange) {
1051 element.setSelectionRange(
1052 $scope.current_event_target_cursor_pos,
1053 $scope.current_event_target_cursor_pos_end
1056 $scope.current_event_cursor_pos_end = null;
1057 $scope.current_event_target = null;
1062 function loadRecord() {
1063 return (function() {
1064 var deferred = $q.defer();
1065 if ($scope.recordId) {
1066 egCore.pcrud.retrieve(
1067 $scope.record_type, $scope.recordId
1068 ).then(function(rec) {
1069 deferred.resolve(rec);
1072 if ($scope.recordType == 'bre') {
1073 var bre = new egCore.idl.bre();
1074 bre.marc($scope.marcXml);
1075 deferred.resolve(bre);
1076 } else if ($scope.recordType == 'are') {
1077 var are = new egCore.idl.are();
1078 are.marc($scope.marcXml);
1079 deferred.resolve(are);
1081 $scope.brandNewRecord = true;
1083 return deferred.promise;
1084 })().then(function(rec) {
1085 $scope.in_redo = true;
1086 $scope[$scope.record_type] = rec;
1087 $scope.record = new MARC21.Record({ marcxml : $scope.Record().marc() });
1088 $scope.calculated_record_type = $scope.record.recordType();
1089 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
1090 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
1091 $scope.save_stack_depth = $scope.record_undo_stack.length;
1092 $scope.dirtyFlag = false;
1093 $scope.flat_text_marc = $scope.record.toBreaker();
1095 if ($scope.record_type == 'bre') {
1096 $scope.bib_source = $scope.Record().source();
1100 return egTagTable.fetchFFPosTable($scope.calculated_record_type)
1102 return egTagTable.fetchFFValueTable($scope.calculated_record_type)
1106 $scope.$watch('record.toBreaker()', function (newVal, oldVal) {
1107 if (!$scope.in_undo && !$scope.in_redo && oldVal != newVal) {
1108 $scope.record_undo_stack.push({
1110 target: $scope.current_event_target,
1111 pos: $scope.current_event_target_cursor_pos
1114 if ($scope.force_render) {
1115 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
1116 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
1117 $scope.force_render = false;
1120 $scope.flat_text_marc = newVal;
1123 if ($scope.record_undo_stack.length != $scope.save_stack_depth) {
1124 $scope.dirtyFlag = true;
1126 $scope.dirtyFlag = false;
1129 if ($scope.record_undo_stack.length > $scope.max_undo)
1130 $scope.record_undo_stack.shift();
1132 console.log('undo stack is ' + $scope.record_undo_stack.length + ' deep');
1133 $scope.in_redo = false;
1134 $scope.in_undo = false;
1137 $scope.processUndo = function () {
1138 if ($scope.record_undo_stack.length) {
1139 $scope.in_undo = true;
1141 var undo_item = $scope.record_undo_stack.pop();
1142 $scope.record_redo_stack.push(undo_item);
1144 $scope.record = new MARC21.Record({ marcbreaker : undo_item.breaker });
1145 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
1146 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
1148 $scope.current_event_target = undo_item.target;
1149 $scope.current_event_target_cursor_pos = undo_item.pos;
1150 console.log('Undo targeting ' + $scope.current_event_target + ' position ' + $scope.current_event_target_cursor_pos);
1152 $timeout(function(){$scope.$digest()}).then(setCaret);
1159 $scope.processRedo = function () {
1160 if ($scope.record_redo_stack.length) {
1161 $scope.in_redo = true;
1163 var redo_item = $scope.record_redo_stack.pop();
1164 $scope.record_undo_stack.push(redo_item);
1166 $scope.record = new MARC21.Record({ marcbreaker : redo_item.breaker });
1167 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
1168 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
1170 $scope.current_event_target = redo_item.target;
1171 $scope.current_event_target_cursor_pos = redo_item.pos;
1172 console.log('Redo targeting ' + $scope.current_event_target + ' position ' + $scope.current_event_target_cursor_pos);
1174 $timeout(function(){$scope.$digest()}).then(setCaret);
1181 $scope.Record = function () {
1182 return $scope[$scope.record_type];
1185 $scope.deleteRecord = function () {
1186 egConfirmDialog.open(
1187 egCore.strings.CONFIRM_DELETE_RECORD,
1188 (($scope.record_type == 'bre') ?
1189 egCore.strings.CONFIRM_DELETE_BRE_MSG :
1190 egCore.strings.CONFIRM_DELETE_ARE_MSG),
1191 { id : $scope.recordId }
1192 ).result.then(function() {
1193 if ($scope.record_type == 'bre') {
1196 'open-ils.cat.biblio.record_entry.delete',
1197 egCore.auth.token(), $scope.recordId
1198 ).then(function(resp) {
1199 var evt = egCore.evt.parse(resp);
1201 return egAlertDialog.open(
1202 egCore.strings.ALERT_DELETE_FAILED,
1203 { id : $scope.recordId, desc : evt.desc }
1206 loadRecord().then(processOnSaveCallbacks);
1210 $scope.Record().deleted(true);
1211 return $scope.saveRecord();
1216 $scope.undeleteRecord = function () {
1217 $scope.Record().deleted(false);
1218 return $scope.saveRecord();
1221 $scope.validateHeadings = function () {
1222 if ($scope.record_type != 'bre') return;
1223 var chain = $q.when();
1224 angular.forEach($scope.record.fields, function(f) {
1225 if (!$scope.controlSet.bibFieldByTag(f.tag)) return;
1226 // if heading already has a $0, assume it's good
1227 if (f.subfield('0', true).length) {
1228 f.heading_checked = true;
1229 f.heading_valid = true;
1232 var auth_match = $scope.controlSet.bibToAuthorities(f);
1233 chain = chain.then(function() {
1234 var promise = egCore.net.request(
1236 'open-ils.search.authority.simple_heading.from_xml.batch.atomic',
1238 ).then(function (matches) {
1239 f.heading_valid = false;
1240 if (matches[0]) { // probably set
1241 for (var cset in matches[0]) {
1242 var arr = matches[0][cset];
1244 // protect against errant empty string values
1245 if (arr.length == 1 && arr[0] == '')
1247 f.heading_valid = true;
1252 f.heading_checked = true;
1259 processOnSaveCallbacks = function() {
1260 var deferred = $q.defer();
1261 if (typeof $scope.onSaveCallback !== 'undefined') {
1262 var promise = deferred.promise;
1264 angular.forEach($scope.onSaveCallback, function (f) {
1265 if (angular.isFunction(f)) promise = promise.then(f);
1269 return deferred.resolve($scope.recordId)
1272 $scope.saveRecord = function () {
1273 if ($scope.inPlaceMode) {
1274 $scope.marcXml = $scope.record.toXmlString();
1275 return processOnSaveCallbacks();
1277 $scope.mangle_005();
1278 $scope.Record().editor(egCore.auth.user().id());
1279 $scope.Record().edit_date('now');
1280 $scope.record.pruneEmptyFieldsAndSubfields();
1281 $scope.Record().marc($scope.record.toXmlString());
1282 if ($scope.recordId) {
1283 return egCore.pcrud.update(
1285 ).then(function() { // success
1286 $scope.save_stack_depth = $scope.record_undo_stack.length;
1287 $scope.dirtyFlag = false;
1288 if ($scope.enable_fast_add) {
1291 'open-ils.actor.anon_cache.set_value',
1292 null, 'edit-these-copies', {
1293 record_id: $scope.recordId,
1295 label : $scope.fast_item_callnumber,
1296 barcode : $scope.fast_item_barcode,
1302 ).then(function(key) {
1304 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1305 $timeout(function() { $window.open(url, '_blank') });
1307 alert('Could not create anonymous cache key!');
1311 }, function() { // failure
1312 alert('Could not save the record!');
1313 }).then(loadRecord).then(processOnSaveCallbacks);
1315 $scope.Record().creator(egCore.auth.user().id());
1316 $scope.Record().create_date('now');
1317 return egCore.pcrud.create(
1319 ).then(function(bre) {
1320 $scope.recordId = bre.id();
1321 if ($scope.enable_fast_add) {
1324 'open-ils.actor.anon_cache.set_value',
1325 null, 'edit-these-copies', {
1326 record_id: $scope.recordId,
1328 label : $scope.fast_item_callnumber,
1329 barcode : $scope.fast_item_barcode,
1334 ).then(function(key) {
1336 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1337 $timeout(function() { $window.open(url, '_blank') });
1339 alert('Could not create anonymous cache key!');
1343 }).then(loadRecord).then(processOnSaveCallbacks);
1349 $scope.seeBreaker = function () {
1350 alert($scope.record.toBreaker());
1353 $scope.$watch('recordId',
1354 function(newVal, oldVal) {
1355 if (newVal && newVal !== oldVal) {
1360 $scope.$watch('marcXml',
1361 function(newVal, oldVal) {
1362 if (newVal && newVal !== oldVal) {
1368 var unregister = $scope.$watch(function() {
1369 return egTagTable.initialized();
1373 if ($scope.recordId || $scope.marcXml) {
1379 $scope.mangle_005 = function () {
1380 var now = new Date();
1381 var y = now.getUTCFullYear();
1383 var m = now.getUTCMonth() + 1;
1384 if (m < 10) m = '0' + m;
1386 var d = now.getUTCDate();
1387 if (d < 10) d = '0' + d;
1389 var H = now.getUTCHours();
1390 if (H < 10) H = '0' + H;
1392 var M = now.getUTCMinutes();
1393 if (M < 10) M = '0' + M;
1395 var S = now.getUTCSeconds();
1396 if (S < 10) S = '0' + S;
1398 var stamp = '' + y + m + d + H + M + S + '.0';
1399 var f = $scope.record.field('005',true)[0];
1403 $scope.record.insertOrderedFields(
1418 .directive("egMarcEditBibsource", ['$timeout',function ($timeout) {
1422 template: '<span class="nullable">'+
1423 '<select class="form-control" ng-model="bib_source" ng-options="s.id() as s.source() for s in bib_sources">'+
1424 '<option value="">Select a Source</option>'+
1427 controller: ['$scope','egCore',
1428 function ($scope , egCore) {
1430 egCore.pcrud.retrieveAll('cbs', {}, {atomic : true})
1431 .then(function(list) { $scope.bib_sources = list; });
1433 $scope.$watch('bib_source',
1434 function(newVal, oldVal) {
1435 if (newVal !== oldVal) {
1436 $scope.bre.source(newVal);
1446 .directive("egMarcEditAuthorityLinker", function () {
1450 templateUrl: './cat/share/t_authority_linker',
1456 controller: ['$scope','$modal','egCore','egAuth',
1457 function ($scope , $modal, egCore, egAuth) {
1459 $scope.searchStr = '';
1460 var cni = egCore.env.aous['cat.marc_control_number_identifier'] ||
1461 'Set cat.marc_control_number_identifier in Library Settings';
1463 var axis_list = $scope.controlSet.bibFieldBrowseAxes($scope.bibField.tag);
1464 $scope.axis = axis_list[0];
1466 $scope._controlled_sf_list = {};
1467 $scope._controlled_auth_sf_list = {};
1469 angular.forEach($scope.controlSet.controlSetList(), function(acs_id) {
1470 if ($scope.controlSet.controlSet(acs_id).control_map[$scope.bibField.tag])
1471 found_acs.push(acs_id);
1473 if (found_acs.length) {
1474 angular.forEach($scope.controlSet.controlSet(found_acs[0]).control_map[$scope.bibField.tag],
1475 function(value, sf_label) {
1476 $scope._controlled_sf_list[ sf_label ] = 1;
1477 angular.forEach($scope.controlSet.controlSet(found_acs[0]).control_map[$scope.bibField.tag][sf_label],
1478 function(auth_sf, auth_tag) {
1479 if (!$scope._controlled_auth_sf_list[auth_tag]) {
1480 $scope._controlled_auth_sf_list[auth_tag] = { };
1482 $scope._controlled_auth_sf_list[auth_tag][auth_sf] = 1;
1489 $scope.bibField.subfields.forEach(function (sf) {
1490 if (sf[0] in $scope._controlled_sf_list) {
1492 sf.selectable = true;
1494 sf.selectable = false;
1497 $scope.summarizeField = function() {
1499 'tag': $scope.bibField.tag,
1500 'ind1': $scope.bibField.ind1,
1501 'ind2': $scope.bibField.ind2,
1504 $scope.bibField.subfields.forEach(function(sf) {
1506 source_f.subfields.push([ sf[0], sf[1] ]);
1511 $scope.getSearchString = function() {
1512 var source_f = $scope.summarizeField();
1514 angular.forEach(source_f.subfields, function(val) {
1515 values.push(val[1]);
1517 return values.join(' ');
1519 $scope.searchStr = $scope.getSearchString();
1520 $scope.$watch(function() {
1522 angular.forEach($scope.bibField.subfields, function(sf) {
1523 if (sf.selected) ct++
1527 function(newVal, oldVal) {
1528 $scope.searchStr = $scope.getSearchString();
1531 $scope.updateSubfieldZero = function(value) {
1532 $scope.changed = true;
1533 $scope.bibField.deleteSubfield({ code : ['0'] });
1534 $scope.bibField.subfields.push([
1535 '0', '(' + cni + ')' + value
1539 $scope.applyHeading = function(headingField) {
1540 // TODO: move the MARC21 rules for copying indicators
1542 if (headingField.tag == '130' && $scope.bibField.tag == '130') {
1543 $scope.bibField.ind1 = headingField.ind2;
1545 $scope.bibField.ind1 = headingField.ind1;
1547 // deal with 4xx and 5xx
1548 var authFallbackTag = '1' + headingField.tag.substr(1, 2);
1549 var _valid_auth_sfs = (headingField.tag in $scope._controlled_auth_sf_list) ?
1550 $scope._controlled_auth_sf_list[headingField.tag] :
1551 (authFallbackTag in $scope._controlled_auth_sf_list) ?
1552 $scope._controlled_auth_sf_list[authFallbackTag] :
1554 // save the $0 for later use
1556 if (headingField.subfield('0')) {
1557 sfZero = headingField.subfield('0')[1];
1559 // grab any bib subfields not under authority control
1560 // TODO do something about uncontrolled subdivisions
1561 var uncontrolledBibSf = [];
1562 angular.forEach($scope.bibField.subfields, function(sf) {
1563 if (!(sf[0] in $scope._controlled_sf_list) && (sf[0] != '0')) {
1564 uncontrolledBibSf.push([ sf[0], sf[1] ]);
1567 // grab the authority subfields
1568 var authoritySf = [];
1569 angular.forEach(headingField.subfields, function(sf) {
1570 if (sf[0] in _valid_auth_sfs) {
1571 authoritySf.push([ sf[0], sf[1] ]);
1574 $scope.bibField.subfields.length = 0;
1575 angular.forEach(authoritySf, function(sf) {
1576 $scope.bibField.addSubfields(sf[0], sf[1]);
1578 angular.forEach(uncontrolledBibSf, function(sf) {
1579 $scope.bibField.addSubfields(sf[0], sf[1]);
1582 $scope.bibField.addSubfields('0', sfZero);
1584 $scope.bibField.subfields.forEach(function (sf) {
1585 if (sf[0] in $scope._controlled_sf_list) {
1586 // intentionally not selecting any subfields
1587 // after we've applied an authority heading
1588 sf.selected = false;
1589 sf.selectable = true;
1591 sf.selectable = false;
1594 $scope.changed = true;
1597 $scope.createAuthorityFromBib = function(spawn_editor) {
1598 var source_f = $scope.summarizeField();
1600 var args = { authority_id : 0 };
1601 var method = (spawn_editor) ?
1602 'open-ils.cat.authority.record.create_from_bib.readonly' :
1603 'open-ils.cat.authority.record.create_from_bib';
1610 ).then(function(newAuthority) {
1613 templateUrl: './cat/share/t_edit_new_authority',
1616 ['$scope', '$modalInstance', function($scope, $modalInstance) {
1617 $scope.focusMe = true;
1619 $scope.dirty_flag = false;
1620 $scope.marc_xml = newAuthority,
1621 $scope.ok = function(args) { $modalInstance.close(args) }
1622 $scope.cancel = function () { $modalInstance.dismiss() }
1624 }).result.then(function (args) {
1625 if (!args || !args.authority_id) return;
1626 $scope.updateSubfieldZero(args.authority_id);
1629 $scope.updateSubfieldZero(newAuthority.id());
1639 .directive("egPhyscharWizard", ['$sce', function ($sce) {
1643 templateUrl: './cat/share/t_physchar_wizard',
1647 controller: ['$scope','$q','egTagTable',
1648 function ($scope , $q , egTagTable) {
1650 // $scope.step is the 1-based position in the list of
1651 // subfields for the currently selected type.
1652 // step==0 means we are currently selecting the type
1655 // position and offset of the "subfields" we're
1656 // currently editing; this is maintained as a convenience
1657 // for the highlighting of the currently active position
1661 if (!$scope.field.data)
1662 $scope.field.data = '';
1664 // currently selected subfield value selector option
1665 $scope.selected_option = null;
1667 function current_ptype() {
1668 return $scope.field.data.substr(0, 1);
1671 function current_subfield() {
1672 return egTagTable.getPhysCharSubfieldMap(current_ptype())
1673 .then(function(sf_list) {return sf_list[$scope.step-1]});
1676 $scope.values_for_step = [];
1677 function set_values_for_step() {
1680 if ($scope.step == 0) {
1683 promise = egTagTable.getPhysCharTypeMap();
1685 promise = current_subfield().then(
1686 function(subfield) {
1688 .getPhysCharValueMap(subfield.id());
1693 return promise.then(function(list) {
1694 $scope.values_for_step = list;
1695 set_selected_option_from_field();
1696 set_label_for_step();
1700 $scope.change_ptype = function(option) {
1701 $scope.selected_option = option;
1702 var new_val = option.ptype_key();
1703 if (current_ptype() != new_val) {
1704 $scope.field.data = new_val; // total reset
1708 $scope.change_option = function(option) {
1709 $scope.selected_option = option;
1710 var new_val = option.value();
1711 get_step_slot().then(function(slot) {
1712 var value = $scope.field.data;
1713 while (value.length < (slot[0] + slot[1]))
1715 var before = value.substr(0, slot[0]);
1716 var after = value.substr(slot[0] + slot[1]);
1718 before + new_val.substr(0, slot[1]) + after;
1719 $scope.offset = slot[0];
1720 $scope.len = slot[1];
1724 function get_step_slot() {
1725 if ($scope.step == 0) return $q.when([0, 1]);
1726 return current_subfield().then(function(sf) {
1727 return [sf.start_pos(), sf.length()]
1731 $scope.is_last_step = function() {
1732 // This one is called w/ every digest, so avoid async
1733 // calls. Wait until we have loaded the current ptype
1734 // subfields to determine if this is the last step.
1737 egTagTable.phys_char_sf_map[current_ptype()] &&
1738 egTagTable.phys_char_sf_map[current_ptype()].length
1743 $scope.label_for_step = '';
1744 function set_label_for_step() {
1745 if ($scope.step > 0) {
1746 current_subfield().then(function(sf) {
1747 $scope.label_for_step = sf.label();
1752 $scope.next_step = function() {
1754 set_values_for_step();
1757 $scope.prev_step = function() {
1759 set_values_for_step();
1762 function set_selected_option_from_field() {
1763 if ($scope.step == 0) {
1764 $scope.selected_option = $scope.values_for_step
1765 .filter(function(opt) {
1766 return (opt.ptype_key() == current_ptype())})[0];
1768 get_step_slot().then(function(slot) {
1769 $scope.offset = slot[0];
1770 $scope.len = slot[1];
1771 var val = String.prototype.substr.apply(
1772 $scope.field.data, slot);
1774 $scope.selected_option = $scope.values_for_step
1775 .filter(function(opt) {
1776 return (opt.value() == val)})[0];
1778 $scope.selected_option = null;
1784 $scope.highlightedFieldData = function() {
1786 $scope.len && $scope.field.data &&
1787 $scope.field.data.length > 0 &&
1788 $scope.field.data.length >= $scope.offset
1790 return $sce.trustAsHtml(
1791 $scope.field.data.substring(0, $scope.offset) +
1792 '<span class="active-physchar">' +
1793 $scope.field.data.substr($scope.offset, $scope.len) +
1795 $scope.field.data.substr($scope.offset + $scope.len)
1798 return $scope.field.data;
1802 set_values_for_step();
1809 .directive("egMarcEditAuthorityBrowser", function () {
1813 templateUrl: './cat/share/t_authority_browser',
1820 controller: ['$scope','$http',
1821 function ($scope , $http) {
1825 $scope.main_headings = [];
1827 function getHeadingString(headingField) {
1829 angular.forEach(headingField.subfields, function (sf) {
1830 if (['x', 'y', 'z'].indexOf(sf[0]) > -1) {
1841 $scope.doBrowse = function() {
1842 $scope.main_headings.length = 0;
1843 if ($scope.searchString.length == 0) return;
1844 var type = 'authority.'
1845 var url = '/opac/extras/browse/marcxml/'
1846 + 'authority.' + $scope.axis + '.refs'
1847 + '/1' // OU - currently unscoped
1848 + '/' + $scope.searchString
1850 + '/' + $scope.limit;
1854 transformResponse : function(data) {
1855 // use a bit of jQuery to deal with the XML
1856 var $xml = $( $.parseXML(data) );
1858 $xml.find('record').each(function() {
1859 var rec = new MARC21.Record();
1860 rec.fromXmlDocument($(this)[0].outerHTML);
1865 }).then(function(response) {
1866 angular.forEach(response.data, function(rec) {
1867 var authId = rec.subfield('901', 'c')[1];
1869 if (rec.field('003')) {
1870 auth_org = rec.field('003').data;
1872 var headingField = rec.field('1..');
1873 var seeFroms = rec.field('4..', true);
1874 var seeAlsos = rec.field('5..', true);
1876 var main_heading = {
1877 authority_id : authId,
1878 heading : getHeadingString(headingField),
1879 seealso_headings : [ ],
1880 seefrom_headings : [ ],
1885 sfZero = '(' + auth_org + ')';
1888 headingField.addSubfields('0', sfZero);
1890 main_heading['headingField'] = headingField;
1891 angular.forEach(seeAlsos, function(headingField) {
1892 main_heading.seealso_headings.push({
1893 heading : getHeadingString(headingField),
1894 headingField : headingField
1897 angular.forEach(seeFroms, function(headingField) {
1898 main_heading.seefrom_headings.push({
1899 heading : getHeadingString(headingField),
1900 headingField : headingField
1903 $scope.main_headings.push(main_heading);
1908 $scope.$watch('searchString',
1909 function(newVal, oldVal) {
1910 if (newVal !== oldVal) {
1915 $scope.$watch('page',
1916 function(newVal, oldVal) {
1917 if (newVal !== oldVal) {