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).removeClass('fixed-field-box');
201 $($element).children().css({ display : 'none' });
203 $scope.content = null; // this is where context menus dump their values
204 $scope.item_container = [];
205 $scope.in_handler = false;
206 $scope.ready = false;
207 $element.find('input').bind('focus', function (e) { e.target.select() });
208 $element.find('input').bind('mouseup', function(e) {
213 $scope.$watch('content', function (newVal, oldVal) {
214 var input = $($element).find('input');
216 input.trigger('keyup'); // cascade the update
219 $scope.$watch('record.ready', function (newVal, oldVal) { // wait for the record to be loaded
220 if (newVal && !$scope.ready) {
221 $scope.rtype = $scope.record.recordType();
223 egTagTable.fetchFFPosTable( $scope.rtype ).then(function (ff_list) {
224 angular.forEach(ff_list, function (ff) {
226 if (ff.fixed_field == $scope.fixedField && ff.rec_type == $scope.rtype) {
229 $($element).addClass('fixed-field-box');
230 $($element).children().css({ display : 'inline' });
232 var input = $($element).find('input');
233 input.attr('maxlength', $scope.me.length);
234 input.val($scope.record.extractFixedField($scope.me.fixed_field));
235 input.on('keyup', function(e) {
236 $scope.in_handler = true;
237 $scope.record.setFixedField($scope.me.fixed_field, input.val());
238 try { $scope.$parent.$digest(); } catch(e) {};
244 }).then(function (me) {
248 return $scope.record.extractFixedField($scope.fixedField);
250 function (newVal, oldVal) {
251 if ($scope.in_handler) {
252 $scope.in_handler = false;
253 } else if (oldVal != newVal) {
254 $($element).find('input').val(newVal);
259 }).then(function () {
260 return egTagTable.fetchFFValueTable( $scope.rtype );
261 }).then(function (vlist) {
262 if (vlist[$scope.fixedField]) {
263 vlist[$scope.fixedField].forEach(function (v) {
264 if (v[0].length <= v[2]) {
265 $scope.item_container.push({ value : v[0], label : v[0] + ': ' + v[1] });
269 }).then(function () {
270 if ($scope.item_container && $scope.item_container.length)
271 $($element).bind('contextmenu', $scope.showContext);
277 $scope.showContext = function (event) {
278 if ($scope.context_menu_element) {
279 console.log('Reshowing context menu...');
280 $('body').trigger('click');
281 $($scope.context_menu_element).css({ display: 'block', top: event.pageY, left: event.pageX });
282 $('body').on('click.context_menu',function() {
283 $($scope.context_menu_element).css('display','none');
284 $('body').off('click.context_menu');
289 if (angular.isArray($scope.item_container)) { // we have a list of values or transforms
290 console.log('Showing context menu...');
291 $('body').trigger('click');
294 '<ul class="dropdown-menu scrollable-menu" role="menu" style="z-index: 2000;">'+
295 '<eg-context-menu-item ng-repeat="item in item_container" item="item" content="content"/>'+
298 var tnode = angular.element(tmpl);
299 $document.find('body').append(tnode);
307 $scope.context_menu_element = tnode;
309 $timeout(function() {
310 var e = $compile(tnode)($scope);
314 $('body').on('click.context_menu',function() {
315 $(tnode).css('display','none');
316 $('body').off('click.context_menu');
330 .directive("egMarcEditSubfield", function () {
335 '<span><label class="marcedit marcsfcodedelimiter"'+
336 'for="r{{field.record.subfield(\'901\',\'c\')[1] || 0}}f{{field.position}}s{{subfield[2]}}code" '+
337 '>‡</label><eg-marc-edit-editable '+
339 'select-on-focus="true" '+
340 'advance-focus-after-input="true" '+
341 'class="marcedit marcsf marcsfcode" '+
343 'subfield="subfield" '+
344 'content="subfield[0]" '+
346 'on-keydown="onKeydown" '+
347 'context-item-generator="sf_code_options" '+
348 'id="r{{field.record.subfield(\'901\',\'c\')[1] || 0}}f{{field.position}}s{{subfield[2]}}code" '+
350 '<span><eg-marc-edit-editable '+
352 'class="marcedit marcsf marcsfvalue" '+
354 'subfield="subfield" '+
355 'content="subfield[1]" '+
356 'on-keydown="onKeydown" '+
357 'context-item-generator="sf_val_options" '+
358 'id="r{{field.record.subfield(\'901\',\'c\')[1] || 0}}f{{field.position}}s{{subfield[2]}}value" '+
361 scope: { field: "=", subfield: "=", onKeydown: '=' },
363 controller : ['$scope', 'egTagTable',
364 function ( $scope , egTagTable) {
366 $scope.sf_code_options = function () {
367 return egTagTable.getSubfieldCodes($scope.field.tag);
369 $scope.sf_val_options = function () {
370 return egTagTable.getSubfieldValues($scope.field.tag, $scope.subfield[0]);
377 .directive("egMarcEditInd", function () {
381 template: '<span><eg-marc-edit-editable '+
383 'class="marcedit marcind" '+
384 'select-on-focus="true" '+
385 'advance-focus-after-input="true" '+
389 'on-keydown="onKeydown" '+
390 'context-item-generator="ind_val_options" '+
391 'id="r{{field.record.subfield(\'901\',\'c\')[1] || 0}}f{{field.position}}i{{indNumber}}"'+
393 scope: { ind : '=', field: '=', onKeydown: '=', indNumber: '@' },
395 controller : ['$scope', 'egTagTable',
396 function ( $scope , egTagTable) {
398 $scope.ind_val_options = function () {
399 return egTagTable.getIndicatorValues($scope.field.tag, $scope.indNumber);
406 .directive("egMarcEditTag", function () {
410 template: '<span><eg-marc-edit-editable '+
412 'class="marcedit marctag" '+
413 'select-on-focus="true" '+
414 'advance-focus-after-input="true" '+
418 'on-keydown="onKeydown" '+
419 'context-item-generator="tag_options" '+
420 'id="r{{field.record.subfield(\'901\',\'c\')[1] || 0}}f{{field.position}}tag"'+
422 scope: { tag : '=', field: '=', onKeydown: '=', contextFunctions: '=' },
424 controller : ['$scope', 'egTagTable', 'egCore',
425 function ( $scope , egTagTable, egCore) {
427 $scope.tag_options = [
430 { label : egCore.strings.ADD_006, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.add006(e) } },
431 { label : egCore.strings.ADD_007, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.add007(e) } },
432 { label : egCore.strings.ADD_REPLACE_008, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.reify008(e) } },
435 if (!$scope.field.isControlfield()) {
436 options = options.concat([
437 { label : egCore.strings.INSERT_FIELD_AFTER, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.addDatafield(e) } },
438 { label : egCore.strings.INSERT_FIELD_BEFORE, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.addDatafield(e,true) } },
442 options.push({ label : egCore.strings.DELETE_FIELD, action : function(j1,j2,j3,j4,e) { $scope.contextFunctions.deleteDatafield(e) } });
445 function () { return egTagTable.getFieldTags() }
453 .directive("egMarcEditDatafield", function () {
458 '<span><eg-marc-edit-tag context-functions="contextFunctions" field="field" tag="field.tag" on-keydown="onKeydown"/></span>'+
459 '<span><eg-marc-edit-ind field="field" ind="field.ind1" on-keydown="onKeydown" ind-number="1"/></span>'+
460 '<span><eg-marc-edit-ind field="field" ind="field.ind2" on-keydown="onKeydown" ind-number="2"/></span>'+
461 '<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>'+
462 // FIXME: template should probably be moved to file to improve
464 '<span ng-class="{ \'marcedit_stacked_subfield\' : stackSubfields.enabled }">' +
465 '<button class="btn btn-info btn-xs" '+
466 'aria-label="Manage authority record links" '+
467 'ng-show="isAuthorityControlled(field)"'+
468 'ng-click="spawnAuthorityLinker()"'+
470 '<span class="glyphicon glyphicon-link"></span>'+
472 '<span ng-show="field.heading_checked && field.heading_valid" class="glyphicon glyphicon-ok-sign"></span>'+
473 '<span ng-show="field.heading_checked && !field.heading_valid" class="glyphicon glyphicon-question-sign"></span>'+
476 scope: { field: "=", onKeydown: '=', contextFunctions: '=' },
478 controller : ['$scope','$uibModal',
479 function ( $scope, $uibModal ) {
480 $scope.stackSubfields = $scope.$parent.$parent.stackSubfields;
481 $scope.isAuthorityControlled = function () {
482 return ($scope.$parent.$parent.record_type == 'bre') &&
483 $scope.$parent.$parent.controlSet.bibFieldByTag($scope.field.tag);
485 $scope.spawnAuthorityLinker = function() {
486 // intentionally making a clone in case
487 // user decides to abandon the linking
488 var fieldCopy = new MARC21.Field({
489 tag : $scope.field.tag,
490 ind1 : $scope.field.ind1,
491 ind2 : $scope.field.ind2
493 angular.forEach($scope.field.subfields, function(sf) {
494 fieldCopy.subfields.push(sf.slice(0));
496 var cs = $scope.$parent.$parent.controlSet;
497 var args = { changed : false };
499 templateUrl: './cat/share/t_authority_link_dialog',
502 controller: ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
503 $scope.controlSet = cs;
504 $scope.bibField = fieldCopy;
505 $scope.focusMe = true;
507 $scope.ok = function(args) { $uibModalInstance.close(args) };
508 $scope.cancel = function () { $uibModalInstance.dismiss() };
510 }).result.then(function (args) {
512 $scope.field.subfields.length = 0;
513 angular.forEach(fieldCopy.subfields, function(sf) {
514 $scope.field.addSubfields(sf[0], sf[1]);
524 .directive("egMarcEditControlfield", function () {
529 '<span><eg-marc-edit-tag context-functions="contextFunctions" field="field" tag="field.tag" on-keydown="onKeydown"/></span>'+
530 '<span><eg-marc-edit-editable '+
533 'class="marcedit marcdata" '+
534 'content="field.data" '+
535 'on-keydown="onKeydown" '+
536 'id="r{{field.record.subfield(\'901\',\'c\')[1] || 0}}f{{field.position}}data"'+
538 // TODO: move to TT2 template
539 '<button class="btn btn-info btn-xs" '+
540 'aria-label="Physical Characteristics Wizard" '+
541 'ng-show="showPhysCharLink()"'+
542 'ng-click="spawnPhysCharWizard()"'+
544 '<span class="glyphicon glyphicon-link"></span>'+
547 scope: { field: "=", onKeydown: '=', contextFunctions: '=' },
548 controller : ['$scope','$uibModal',
549 function ( $scope, $uibModal) {
550 $scope.showPhysCharLink = function () {
551 return ($scope.$parent.$parent.record_type == 'bre')
552 && $scope.field.tag == '007';
554 $scope.spawnPhysCharWizard = function() {
557 field : $scope.field,
558 orig_value : $scope.field.data
561 templateUrl: './cat/share/t_physchar_dialog',
562 controller: ['$scope','$uibModalInstance',
563 function( $scope , $uibModalInstance) {
564 $scope.focusMe = true;
566 $scope.ok = function(args) { $uibModalInstance.close(args) };
567 $scope.cancel = function () {
568 $uibModalInstance.dismiss();
569 args.field.data = args.orig_value;
572 }).result.then(function (args) {
573 // $scope.field.data is changed within the
574 // wizard. Nothing left to do on submit.
583 .directive("egMarcEditLeader", function () {
588 '<span><eg-marc-edit-editable '+
589 'class="marcedit marctag" '+
591 'on-keydown="onKeydown" '+
593 'disabled="disabled"'+
595 '<span><eg-marc-edit-editable '+
596 'class="marcedit marcdata" '+
598 'max="{{record.leader.length}}" '+
599 'content="record.leader" '+
600 'id="r{{record.subfield(\'901\',\'c\')[1] || 0}}leaderdata" '+
601 'on-keydown="onKeydown"'+
604 controller : ['$scope',
605 function ( $scope ) {
609 scope: { record: "=", onKeydown: '=' }
613 /// TODO: fixed field editor and such
614 .directive("egMarcEditRecord", function () {
616 templateUrl : './cat/share/t_marcedit',
624 // in-place mode means that the editor is being
625 // used just to munge some MARCXML client-side, rather
626 // than to (immediately) update the database
635 link: function (scope, element, attrs) {
637 element.bind('mouseup', function(e) {;
638 scope.current_event_target = $(e.target).attr('id');
639 if (scope.current_event_target && $(e.target).hasClass('noSelection')) {
645 element.bind('click', function(e) {;
646 scope.current_event_target = $(e.target).attr('id');
647 if (scope.current_event_target) {
648 console.log('Recording click event on ' + scope.current_event_target);
649 scope.current_event_target_cursor_pos =
650 e.target.selectionDirection=='backward' ?
651 e.target.selectionStart :
652 e.target.selectionEnd;
657 controller : ['$timeout','$scope','$q','$window','egCore', 'egTagTable','egConfirmDialog','egAlertDialog',
658 function ( $timeout , $scope , $q, $window , egCore , egTagTable , egConfirmDialog , egAlertDialog ) {
661 $scope.onSaveCallback = $scope.onSave;
662 if (typeof $scope.onSaveCallback !== 'undefined' && !angular.isArray($scope.onSaveCallback))
663 $scope.onSaveCallback = [ $scope.onSaveCallback ];
665 MARC21.Record.delimiter = '$';
667 $scope.enable_fast_add = false;
668 $scope.fast_item_callnumber = '';
669 $scope.fast_item_barcode = '';
671 $scope.flatEditor = { isEnabled : $scope.flatOnly ? true : false };
673 egCore.hatch.getItem('cat.marcedit.flateditor').then(function(val) {
674 $scope.flatEditor.isEnabled = val;
677 $scope.$watch('flatEditor.isEnabled', function (newVal, oldVal) {
678 if (newVal != oldVal) egCore.hatch.setItem('cat.marcedit.flateditor', newVal);
681 $scope.brandNewRecord = false;
682 $scope.bib_source = null;
683 $scope.record_type = $scope.recordType || 'bre';
684 $scope.max_undo = $scope.maxUndo || 100;
685 $scope.record_undo_stack = [];
686 $scope.record_redo_stack = [];
687 $scope.in_undo = false;
688 $scope.in_redo = false;
689 $scope.record = new MARC21.Record();
690 $scope.save_stack_depth = 0;
691 $scope.controlfields = [];
692 $scope.datafields = [];
693 $scope.controlSet = egTagTable.getAuthorityControlSet();
694 $scope.showHelp = false;
695 $scope.stackSubfields = { enabled : false };
696 egCore.hatch.getItem('cat.marcedit.stack_subfields').then(function(val) {
697 $scope.stackSubfields.enabled = val;
699 $scope.$watch('stackSubfields.enabled', function (newVal, oldVal) {
700 if (newVal != oldVal) egCore.hatch.setItem('cat.marcedit.stack_subfields', newVal);
702 $scope.caretRecId = $scope.recordId;
704 egTagTable.loadTagTable({ marcRecordType : $scope.record_type });
706 $scope.saveFlatTextMARC = function () {
707 $scope.record = new MARC21.Record({ marcbreaker : $scope.flat_text_marc });
710 $scope.refreshVisual = function () {
711 if (!$scope.flatEditor.isEnabled) {
712 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
713 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
717 var addDatafield = function (e,before) {
718 var element = $(e.target);
720 var index_field = e.data.scope.field.position;
721 var new_field_index = index_field;
723 var new_field = new MARC21.Field({
725 subfields : [[' ','',0]]
728 if (Boolean(before)) {
729 e.data.scope.field.record.insertFieldsBefore(
734 e.data.scope.field.record.insertFieldsAfter(
741 $scope.current_event_target = 'r' + $scope.caretRecId +
742 'f' + new_field_index + 'tag';
744 $scope.current_event_target_cursor_pos = 0;
745 $scope.current_event_target_cursor_pos_end = 3;
746 $scope.force_render = true;
748 $timeout(function(){$scope.$digest()}).then(setCaret);
751 var deleteDatafield = function (e) {
752 var del_field = e.data.scope.field.position;
754 var sf901c = e.data.scope.field.record.subfield('901','c');
755 var recId = (sf901c === null) ? '' : sf901c[1];
756 var domnode = $('#r' + recId + 'f' + del_field);
758 e.data.scope.field.record.deleteFields(
762 domnode.scope().$destroy();
765 $scope.current_event_target = 'r' + $scope.caretRecId +
766 'f' + del_field + 'tag';
768 $scope.current_event_target_cursor_pos = 0;
769 $scope.current_event_target_cursor_pos_end = 0
770 $scope.force_render = true;
772 $timeout(function(){$scope.$digest()}).then(setCaret);
775 var add006 = function (e) {
776 e.data.scope.field.record.insertOrderedFields(
783 $scope.force_render = true;
784 $timeout(function(){$scope.$digest()}).then(setCaret);
787 var add007 = function (e) {
788 e.data.scope.field.record.insertOrderedFields(
795 $scope.force_render = true;
796 $timeout(function(){$scope.$digest()}).then(setCaret);
799 var reify008 = function (e) {
800 var new_008_data = e.data.scope.field.record.generate008();
803 var old_008s = e.data.scope.field.record.field('008',true);
804 old_008s.forEach(function(o) {
805 var domnode = $('#r'+o.record.subfield('901','c')[1] + 'f' + o.position);
806 domnode.scope().$destroy();
808 e.data.scope.field.record.deleteFields(o);
811 e.data.scope.field.record.insertOrderedFields(
818 $scope.force_render = true;
819 $timeout(function(){$scope.$digest()}).then(setCaret);
822 $scope.context_functions = {
823 addDatafield : addDatafield,
824 deleteDatafield : deleteDatafield,
830 $scope.onKeydown = function (event) {
831 var event_return = true;
834 'keydown: which='+event.which+
835 ', ctrlKey='+event.ctrlKey+
836 ', shiftKey='+event.shiftKey+
837 ', altKey='+event.altKey+
838 ', metaKey='+event.altKey
841 if (event.which == 89 && event.ctrlKey) { // ctrl+y, redo
842 event_return = $scope.processRedo();
843 } else if (event.which == 90 && event.ctrlKey) { // ctrl+z, undo
844 event_return = $scope.processUndo();
845 } else if ((event.which == 68 || event.which == 73) && event.ctrlKey) { // ctrl+d or ctrl+i, insert subfield
847 var element = $(event.target);
848 var new_sf, index_sf, move_data;
850 if (element.hasClass('marcsfvalue')) {
851 index_sf = event.data.scope.subfield[2];
852 new_sf = index_sf + 1;
854 var start = event.target.selectionStart;
855 var end = event.target.selectionEnd - event.target.selectionStart ?
856 event.target.selectionEnd :
857 event.target.value.length;
859 move_data = event.target.value.substring(start,end);
861 } else if (element.hasClass('marcsfcode')) {
862 index_sf = event.data.scope.subfield[2];
863 new_sf = index_sf + 1;
864 } else if (element.hasClass('marctag') || element.hasClass('marcind')) {
869 $scope.current_event_target = 'r' + $scope.caretRecId +
870 'f' + event.data.scope.field.position +
871 's' + new_sf + 'code';
873 event.data.scope.field.subfields.forEach(function(sf) {
874 if (sf[2] >= new_sf) sf[2]++;
875 if (sf[2] == index_sf) sf[1] = event.target.value.substring(0,start) + event.target.value.substring(end);
877 event.data.scope.field.subfields.splice(
880 [' ', move_data, new_sf ]
883 $scope.current_event_target_cursor_pos = 0;
884 $scope.current_event_target_cursor_pos_end = 1;
886 $timeout(function(){$scope.$digest()}).then(setCaret);
888 event_return = false;
890 } else if (event.which == 117 && event.shiftKey) { // shift + F6, insert 006
892 event_return = false;
894 } else if (event.which == 118 && event.shiftKey) { // shift + F7, insert 007
896 event_return = false;
898 } else if (event.which == 119 && event.shiftKey) { // shift + F8, insert/replace 008
900 event_return = false;
902 } else if (event.which == 13 && event.ctrlKey) { // ctrl+enter, insert datafield
903 addDatafield(event, event.shiftKey); // shift key inserts before
904 event_return = false;
906 } else if (event.which == 46 && event.ctrlKey) { // ctrl+del, remove field
907 deleteDatafield(event);
908 event_return = false;
910 } else if (event.which == 46 && event.shiftKey && $(event.target).hasClass('marcsf')) { // shift+del, remove subfield
912 var sf = event.data.scope.subfield[2] - 1;
913 if (sf == -1) sf = 0;
915 event.data.scope.field.deleteExactSubfields(
916 event.data.scope.subfield
919 if (!event.data.scope.field.subfields[sf]) {
920 $scope.current_event_target = 'r' + $scope.caretRecId +
921 'f' + event.data.scope.field.position +
924 $scope.current_event_target = 'r' + $scope.caretRecId +
925 'f' + event.data.scope.field.position +
929 $scope.current_event_target_cursor_pos = 0;
930 $scope.current_event_target_cursor_pos_end = 0;
931 $scope.force_render = true;
933 $timeout(function(){$scope.$digest()}).then(setCaret);
935 event_return = false;
937 } else if (event.keyCode == 38) {
938 if (event.ctrlKey) { // copy the field up
939 var index_field = event.data.scope.field.position;
942 if (event.data.scope.field.isControlfield()) {
943 field_obj = new MARC21.Field({
944 tag : event.data.scope.field.tag,
945 data : event.data.scope.field.data
949 for (var i in event.data.scope.field.subfields) {
950 sf_clone.push(event.data.scope.field.subfields[i].slice());
952 field_obj = new MARC21.Field({
953 tag : event.data.scope.field.tag,
954 ind1 : event.data.scope.field.ind1,
955 ind2 : event.data.scope.field.ind2,
961 event.data.scope.field.record.insertFieldsBefore(
962 event.data.scope.field,
966 $scope.current_event_target = 'r' + $scope.caretRecId +
967 'f' + index_field + 'tag';
969 $scope.current_event_target_cursor_pos = 0;
970 $scope.current_event_target_cursor_pos_end = 3;
971 $scope.force_render = true;
973 $timeout(function(){$scope.$digest()}).then(setCaret);
975 } else { // jump to prev field
976 if (event.data.scope.field.position > 0) {
978 $scope.current_event_target_cursor_pos = 0;
979 $scope.current_event_target_cursor_pos_end = 0;
980 $scope.current_event_target = 'r' + $scope.caretRecId +
981 'f' + (event.data.scope.field.position - 1) +
987 event_return = false;
989 } else if (event.keyCode == 40) { // down arrow...
990 if (event.ctrlKey) { // copy the field down
992 var index_field = event.data.scope.field.position;
993 var new_field = index_field + 1;
996 if (event.data.scope.field.isControlfield()) {
997 field_obj = new MARC21.Field({
998 tag : event.data.scope.field.tag,
999 data : event.data.scope.field.data
1003 for (var i in event.data.scope.field.subfields) {
1004 sf_clone.push(event.data.scope.field.subfields[i].slice());
1006 field_obj = new MARC21.Field({
1007 tag : event.data.scope.field.tag,
1008 ind1 : event.data.scope.field.ind1,
1009 ind2 : event.data.scope.field.ind2,
1010 subfields : sf_clone
1014 event.data.scope.field.record.insertFieldsAfter(
1015 event.data.scope.field,
1019 $scope.current_event_target = 'r' + $scope.caretRecId +
1020 'f' + new_field + 'tag';
1022 $scope.current_event_target_cursor_pos = 0;
1023 $scope.current_event_target_cursor_pos_end = 3;
1024 $scope.force_render = true;
1026 $timeout(function(){$scope.$digest()}).then(setCaret);
1028 } else { // jump to next field
1029 if (event.data.scope.field.record.fields[event.data.scope.field.position + 1]) {
1030 $timeout(function(){
1031 $scope.current_event_target_cursor_pos = 0;
1032 $scope.current_event_target_cursor_pos_end = 0;
1033 $scope.current_event_target = 'r' + $scope.caretRecId +
1034 'f' + (event.data.scope.field.position + 1) +
1040 event_return = false;
1042 } else { // Assumes only marc editor elements have IDs that can trigger this event handler.
1043 $scope.current_event_target = $(event.target).attr('id');
1044 if ($scope.current_event_target) {
1045 $scope.current_event_target_cursor_pos =
1046 event.target.selectionDirection=='backward' ?
1047 event.target.selectionStart :
1048 event.target.selectionEnd;
1052 return event_return;
1055 function setCaret() {
1056 if ($scope.current_event_target) {
1057 console.log("Putting caret in " + $scope.current_event_target);
1058 if (!$scope.current_event_target_cursor_pos_end)
1059 $scope.current_event_target_cursor_pos_end = $scope.current_event_target_cursor_pos
1061 var element = $('#'+$scope.current_event_target).get(0);
1064 if (element.setSelectionRange) {
1065 element.setSelectionRange(
1066 $scope.current_event_target_cursor_pos,
1067 $scope.current_event_target_cursor_pos_end
1070 $scope.current_event_cursor_pos_end = null;
1071 $scope.current_event_target = null;
1076 function loadRecord() {
1077 return (function() {
1078 var deferred = $q.defer();
1079 if ($scope.recordId) {
1080 egCore.pcrud.retrieve(
1081 $scope.record_type, $scope.recordId
1082 ).then(function(rec) {
1083 deferred.resolve(rec);
1086 if ($scope.recordType == 'bre') {
1087 var bre = new egCore.idl.bre();
1088 bre.marc($scope.marcXml);
1089 deferred.resolve(bre);
1090 } else if ($scope.recordType == 'are') {
1091 var are = new egCore.idl.are();
1092 are.marc($scope.marcXml);
1093 deferred.resolve(are);
1094 } else if ($scope.recordType == 'sre') {
1095 var sre = new egCore.idl.sre();
1096 sre.marc($scope.marcXml);
1097 deferred.resolve(sre);
1099 $scope.brandNewRecord = true;
1101 return deferred.promise;
1102 })().then(function(rec) {
1103 $scope.in_redo = true;
1104 $scope[$scope.record_type] = rec;
1105 $scope.record = new MARC21.Record({ marcxml : $scope.Record().marc() });
1106 if (!$scope.recordId) {
1107 var sf901c = $scope.record.subfield('901', 'c');
1108 if (sf901c !== null) {
1109 $scope.caretRecId = sf901c[1];
1112 $scope.calculated_record_type = $scope.record.recordType();
1113 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
1114 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
1115 $scope.save_stack_depth = $scope.record_undo_stack.length;
1116 $scope.dirtyFlag = false;
1117 $scope.flat_text_marc = $scope.record.toBreaker();
1119 if ($scope.record_type == 'bre') {
1120 $scope.bib_source = $scope.Record().source();
1124 return egTagTable.fetchFFPosTable($scope.calculated_record_type)
1126 return egTagTable.fetchFFValueTable($scope.calculated_record_type)
1130 $scope.$watch('record.toBreaker()', function (newVal, oldVal) {
1131 if (!$scope.in_undo && !$scope.in_redo && oldVal != newVal) {
1132 $scope.record_undo_stack.push({
1134 target: $scope.current_event_target,
1135 pos: $scope.current_event_target_cursor_pos
1138 if ($scope.force_render) {
1139 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
1140 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
1141 $scope.force_render = false;
1144 $scope.flat_text_marc = newVal;
1147 if ($scope.record_undo_stack.length != $scope.save_stack_depth) {
1148 $scope.dirtyFlag = true;
1150 $scope.dirtyFlag = false;
1153 if ($scope.record_undo_stack.length > $scope.max_undo)
1154 $scope.record_undo_stack.shift();
1156 console.log('undo stack is ' + $scope.record_undo_stack.length + ' deep');
1157 $scope.in_redo = false;
1158 $scope.in_undo = false;
1161 $scope.processUndo = function () {
1162 if ($scope.record_undo_stack.length) {
1163 $scope.in_undo = true;
1165 var undo_item = $scope.record_undo_stack.pop();
1166 $scope.record_redo_stack.push(undo_item);
1168 $scope.record = new MARC21.Record({ marcbreaker : undo_item.breaker });
1169 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
1170 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
1172 $scope.current_event_target = undo_item.target;
1173 $scope.current_event_target_cursor_pos = undo_item.pos;
1174 console.log('Undo targeting ' + $scope.current_event_target + ' position ' + $scope.current_event_target_cursor_pos);
1176 $timeout(function(){$scope.$digest()}).then(setCaret);
1183 $scope.processRedo = function () {
1184 if ($scope.record_redo_stack.length) {
1185 $scope.in_redo = true;
1187 var redo_item = $scope.record_redo_stack.pop();
1188 $scope.record_undo_stack.push(redo_item);
1190 $scope.record = new MARC21.Record({ marcbreaker : redo_item.breaker });
1191 $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
1192 $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
1194 $scope.current_event_target = redo_item.target;
1195 $scope.current_event_target_cursor_pos = redo_item.pos;
1196 console.log('Redo targeting ' + $scope.current_event_target + ' position ' + $scope.current_event_target_cursor_pos);
1198 $timeout(function(){$scope.$digest()}).then(setCaret);
1205 $scope.Record = function () {
1206 return $scope[$scope.record_type];
1209 $scope.deleteRecord = function () {
1210 egConfirmDialog.open(
1211 egCore.strings.CONFIRM_DELETE_RECORD,
1212 (($scope.record_type == 'bre') ?
1213 egCore.strings.CONFIRM_DELETE_BRE_MSG :
1214 egCore.strings.CONFIRM_DELETE_ARE_MSG),
1215 { id : $scope.recordId }
1216 ).result.then(function() {
1217 if ($scope.record_type == 'bre') {
1220 'open-ils.cat.biblio.record_entry.delete',
1221 egCore.auth.token(), $scope.recordId
1222 ).then(function(resp) {
1223 var evt = egCore.evt.parse(resp);
1225 return egAlertDialog.open(
1226 egCore.strings.ALERT_DELETE_FAILED,
1227 { id : $scope.recordId, desc : evt.desc }
1230 loadRecord().then(processOnSaveCallbacks);
1234 $scope.Record().deleted(true);
1235 return $scope.saveRecord();
1240 $scope.undeleteRecord = function () {
1241 $scope.Record().deleted(false);
1242 return $scope.saveRecord();
1245 $scope.validateHeadings = function () {
1246 if ($scope.record_type != 'bre') return;
1247 var chain = $q.when();
1248 angular.forEach($scope.record.fields, function(f) {
1249 if (!$scope.controlSet.bibFieldByTag(f.tag)) return;
1250 // if heading already has a $0, assume it's good
1251 if (f.subfield('0', true).length) {
1252 f.heading_checked = true;
1253 f.heading_valid = true;
1256 var auth_match = $scope.controlSet.bibToAuthorities(f);
1257 chain = chain.then(function() {
1258 var promise = egCore.net.request(
1260 'open-ils.search.authority.simple_heading.from_xml.batch.atomic',
1262 ).then(function (matches) {
1263 f.heading_valid = false;
1264 if (matches[0]) { // probably set
1265 for (var cset in matches[0]) {
1266 var arr = matches[0][cset];
1268 // protect against errant empty string values
1269 if (arr.length == 1 && arr[0] == '')
1271 f.heading_valid = true;
1276 f.heading_checked = true;
1283 processOnSaveCallbacks = function() {
1284 var deferred = $q.defer();
1285 if (typeof $scope.onSaveCallback !== 'undefined') {
1286 var promise = deferred.promise;
1288 angular.forEach($scope.onSaveCallback, function (f) {
1289 if (angular.isFunction(f)) promise = promise.then(f);
1293 return deferred.resolve($scope.recordId)
1296 $scope.saveRecord = function () {
1297 if ($scope.inPlaceMode) {
1298 $scope.marcXml = $scope.record.toXmlString();
1299 return processOnSaveCallbacks();
1301 $scope.mangle_005();
1302 $scope.Record().editor(egCore.auth.user().id());
1303 $scope.Record().edit_date('now');
1304 $scope.record.pruneEmptyFieldsAndSubfields();
1305 $scope.Record().marc($scope.record.toXmlString());
1306 if ($scope.recordId) {
1307 return egCore.pcrud.update(
1309 ).then(function() { // success
1310 $scope.save_stack_depth = $scope.record_undo_stack.length;
1311 $scope.dirtyFlag = false;
1312 if ($scope.enable_fast_add) {
1315 'open-ils.actor.anon_cache.set_value',
1316 null, 'edit-these-copies', {
1317 record_id: $scope.recordId,
1319 label : $scope.fast_item_callnumber,
1320 barcode : $scope.fast_item_barcode,
1326 ).then(function(key) {
1328 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1329 $timeout(function() { $window.open(url, '_blank') });
1331 alert('Could not create anonymous cache key!');
1335 }, function() { // failure
1336 alert('Could not save the record!');
1337 }).then(loadRecord).then(processOnSaveCallbacks);
1339 $scope.Record().creator(egCore.auth.user().id());
1340 $scope.Record().create_date('now');
1341 return egCore.pcrud.create(
1343 ).then(function(bre) {
1344 $scope.recordId = bre.id();
1345 $scope.caretRecId = $scope.recordId;
1346 if ($scope.enable_fast_add) {
1349 'open-ils.actor.anon_cache.set_value',
1350 null, 'edit-these-copies', {
1351 record_id: $scope.recordId,
1353 label : $scope.fast_item_callnumber,
1354 barcode : $scope.fast_item_barcode,
1359 ).then(function(key) {
1361 var url = egCore.env.basePath + 'cat/volcopy/' + key;
1362 $timeout(function() { $window.open(url, '_blank') });
1364 alert('Could not create anonymous cache key!');
1368 }).then(loadRecord).then(processOnSaveCallbacks);
1374 $scope.seeBreaker = function () {
1375 alert($scope.record.toBreaker());
1378 $scope.$watch('recordId',
1379 function(newVal, oldVal) {
1380 if (newVal && newVal !== oldVal) {
1385 $scope.$watch('marcXml',
1386 function(newVal, oldVal) {
1387 if (newVal && newVal !== oldVal) {
1393 var unregister = $scope.$watch(function() {
1394 return egTagTable.initialized();
1398 if ($scope.recordId || $scope.marcXml) {
1404 $scope.mangle_005 = function () {
1405 var now = new Date();
1406 var y = now.getUTCFullYear();
1408 var m = now.getUTCMonth() + 1;
1409 if (m < 10) m = '0' + m;
1411 var d = now.getUTCDate();
1412 if (d < 10) d = '0' + d;
1414 var H = now.getUTCHours();
1415 if (H < 10) H = '0' + H;
1417 var M = now.getUTCMinutes();
1418 if (M < 10) M = '0' + M;
1420 var S = now.getUTCSeconds();
1421 if (S < 10) S = '0' + S;
1423 var stamp = '' + y + m + d + H + M + S + '.0';
1424 var f = $scope.record.field('005',true)[0];
1428 $scope.record.insertOrderedFields(
1443 .directive("egMarcEditBibsource", ['$timeout',function ($timeout) {
1447 template: '<span class="nullable">'+
1448 '<select class="form-control" ng-model="bib_source" ng-options="s.id() as s.source() for s in bib_sources">'+
1449 '<option value="">Select a Source</option>'+
1452 controller: ['$scope','egCore',
1453 function ($scope , egCore) {
1455 egCore.pcrud.retrieveAll('cbs', {}, {atomic : true})
1456 .then(function(list) { $scope.bib_sources = list; });
1458 $scope.$watch('bib_source',
1459 function(newVal, oldVal) {
1460 if (newVal !== oldVal) {
1461 $scope.bre.source(newVal);
1471 .directive("egMarcEditAuthorityLinker", function () {
1475 templateUrl: './cat/share/t_authority_linker',
1481 controller: ['$scope','$uibModal','egCore','egAuth',
1482 function ($scope , $uibModal, egCore, egAuth) {
1484 $scope.searchStr = '';
1485 var cni = egCore.env.aous['cat.marc_control_number_identifier'] ||
1486 'Set cat.marc_control_number_identifier in Library Settings';
1488 var axis_list = $scope.controlSet.bibFieldBrowseAxes($scope.bibField.tag);
1489 $scope.axis = axis_list[0];
1491 $scope._controlled_sf_list = {};
1492 $scope._controlled_auth_sf_list = {};
1494 angular.forEach($scope.controlSet.controlSetList(), function(acs_id) {
1495 if ($scope.controlSet.controlSet(acs_id).control_map[$scope.bibField.tag])
1496 found_acs.push(acs_id);
1498 if (found_acs.length) {
1499 angular.forEach($scope.controlSet.controlSet(found_acs[0]).control_map[$scope.bibField.tag],
1500 function(value, sf_label) {
1501 $scope._controlled_sf_list[ sf_label ] = 1;
1502 angular.forEach($scope.controlSet.controlSet(found_acs[0]).control_map[$scope.bibField.tag][sf_label],
1503 function(auth_sf, auth_tag) {
1504 if (!$scope._controlled_auth_sf_list[auth_tag]) {
1505 $scope._controlled_auth_sf_list[auth_tag] = { };
1507 $scope._controlled_auth_sf_list[auth_tag][auth_sf] = 1;
1514 $scope.bibField.subfields.forEach(function (sf) {
1515 if (sf[0] in $scope._controlled_sf_list) {
1517 sf.selectable = true;
1519 sf.selectable = false;
1522 $scope.summarizeField = function() {
1524 'tag': $scope.bibField.tag,
1525 'ind1': $scope.bibField.ind1,
1526 'ind2': $scope.bibField.ind2,
1529 $scope.bibField.subfields.forEach(function(sf) {
1531 source_f.subfields.push([ sf[0], sf[1] ]);
1536 $scope.getSearchString = function() {
1537 var source_f = $scope.summarizeField();
1539 angular.forEach(source_f.subfields, function(val) {
1540 values.push(val[1]);
1542 return values.join(' ');
1544 $scope.searchStr = $scope.getSearchString();
1545 $scope.$watch(function() {
1547 angular.forEach($scope.bibField.subfields, function(sf) {
1548 if (sf.selected) ct++
1552 function(newVal, oldVal) {
1553 $scope.searchStr = $scope.getSearchString();
1556 $scope.updateSubfieldZero = function(value) {
1557 $scope.changed = true;
1558 $scope.bibField.deleteSubfield({ code : ['0'] });
1559 $scope.bibField.subfields.push([
1560 '0', '(' + cni + ')' + value
1564 $scope.applyHeading = function(headingField) {
1565 // TODO: move the MARC21 rules for copying indicators
1567 if (headingField.tag == '130' && $scope.bibField.tag == '130') {
1568 $scope.bibField.ind1 = headingField.ind2;
1570 $scope.bibField.ind1 = headingField.ind1;
1572 // deal with 4xx and 5xx
1573 var authFallbackTag = '1' + headingField.tag.substr(1, 2);
1574 var _valid_auth_sfs = (headingField.tag in $scope._controlled_auth_sf_list) ?
1575 $scope._controlled_auth_sf_list[headingField.tag] :
1576 (authFallbackTag in $scope._controlled_auth_sf_list) ?
1577 $scope._controlled_auth_sf_list[authFallbackTag] :
1579 // save the $0 for later use
1581 if (headingField.subfield('0')) {
1582 sfZero = headingField.subfield('0')[1];
1584 // grab any bib subfields not under authority control
1585 // TODO do something about uncontrolled subdivisions
1586 var uncontrolledBibSf = [];
1587 angular.forEach($scope.bibField.subfields, function(sf) {
1588 if (!(sf[0] in $scope._controlled_sf_list) && (sf[0] != '0')) {
1589 uncontrolledBibSf.push([ sf[0], sf[1] ]);
1592 // grab the authority subfields
1593 var authoritySf = [];
1594 angular.forEach(headingField.subfields, function(sf) {
1595 if (sf[0] in _valid_auth_sfs) {
1596 authoritySf.push([ sf[0], sf[1] ]);
1599 $scope.bibField.subfields.length = 0;
1600 angular.forEach(authoritySf, function(sf) {
1601 $scope.bibField.addSubfields(sf[0], sf[1]);
1603 angular.forEach(uncontrolledBibSf, function(sf) {
1604 $scope.bibField.addSubfields(sf[0], sf[1]);
1607 $scope.bibField.addSubfields('0', sfZero);
1609 $scope.bibField.subfields.forEach(function (sf) {
1610 if (sf[0] in $scope._controlled_sf_list) {
1611 // intentionally not selecting any subfields
1612 // after we've applied an authority heading
1613 sf.selected = false;
1614 sf.selectable = true;
1616 sf.selectable = false;
1619 $scope.changed = true;
1622 $scope.createAuthorityFromBib = function(spawn_editor) {
1623 var source_f = $scope.summarizeField();
1625 var args = { authority_id : 0 };
1626 var method = (spawn_editor) ?
1627 'open-ils.cat.authority.record.create_from_bib.readonly' :
1628 'open-ils.cat.authority.record.create_from_bib';
1635 ).then(function(newAuthority) {
1638 templateUrl: './cat/share/t_edit_new_authority',
1641 ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
1642 $scope.focusMe = true;
1644 $scope.dirty_flag = false;
1645 $scope.marc_xml = newAuthority,
1646 $scope.ok = function(args) { $uibModalInstance.close(args) }
1647 $scope.cancel = function () { $uibModalInstance.dismiss() }
1649 }).result.then(function (args) {
1650 if (!args || !args.authority_id) return;
1651 $scope.updateSubfieldZero(args.authority_id);
1654 $scope.updateSubfieldZero(newAuthority.id());
1664 .directive("egPhyscharWizard", ['$sce', function ($sce) {
1668 templateUrl: './cat/share/t_physchar_wizard',
1672 controller: ['$scope','$q','egTagTable',
1673 function ($scope , $q , egTagTable) {
1675 // $scope.step is the 1-based position in the list of
1676 // subfields for the currently selected type.
1677 // step==0 means we are currently selecting the type
1680 // position and offset of the "subfields" we're
1681 // currently editing; this is maintained as a convenience
1682 // for the highlighting of the currently active position
1686 if (!$scope.field.data)
1687 $scope.field.data = '';
1689 // currently selected subfield value selector option
1690 $scope.selected_option = null;
1692 function current_ptype() {
1693 return $scope.field.data.substr(0, 1);
1696 function current_subfield() {
1697 return egTagTable.getPhysCharSubfieldMap(current_ptype())
1698 .then(function(sf_list) {return sf_list[$scope.step-1]});
1701 $scope.values_for_step = [];
1702 function set_values_for_step() {
1705 if ($scope.step == 0) {
1708 promise = egTagTable.getPhysCharTypeMap();
1710 promise = current_subfield().then(
1711 function(subfield) {
1713 .getPhysCharValueMap(subfield.id());
1718 return promise.then(function(list) {
1719 $scope.values_for_step = list;
1720 set_selected_option_from_field();
1721 set_label_for_step();
1725 $scope.change_ptype = function(option) {
1726 $scope.selected_option = option;
1727 var new_val = option.ptype_key();
1728 if (current_ptype() != new_val) {
1729 $scope.field.data = new_val; // total reset
1733 $scope.change_option = function(option) {
1734 $scope.selected_option = option;
1735 var new_val = option.value();
1736 get_step_slot().then(function(slot) {
1737 var value = $scope.field.data;
1738 while (value.length < (slot[0] + slot[1]))
1740 var before = value.substr(0, slot[0]);
1741 var after = value.substr(slot[0] + slot[1]);
1743 before + new_val.substr(0, slot[1]) + after;
1744 $scope.offset = slot[0];
1745 $scope.len = slot[1];
1749 function get_step_slot() {
1750 if ($scope.step == 0) return $q.when([0, 1]);
1751 return current_subfield().then(function(sf) {
1752 return [sf.start_pos(), sf.length()]
1756 $scope.is_last_step = function() {
1757 // This one is called w/ every digest, so avoid async
1758 // calls. Wait until we have loaded the current ptype
1759 // subfields to determine if this is the last step.
1762 egTagTable.phys_char_sf_map[current_ptype()] &&
1763 egTagTable.phys_char_sf_map[current_ptype()].length
1768 $scope.label_for_step = '';
1769 function set_label_for_step() {
1770 if ($scope.step > 0) {
1771 current_subfield().then(function(sf) {
1772 $scope.label_for_step = sf.label();
1777 $scope.next_step = function() {
1779 set_values_for_step();
1782 $scope.prev_step = function() {
1784 set_values_for_step();
1787 function set_selected_option_from_field() {
1788 if ($scope.step == 0) {
1789 $scope.selected_option = $scope.values_for_step
1790 .filter(function(opt) {
1791 return (opt.ptype_key() == current_ptype())})[0];
1793 get_step_slot().then(function(slot) {
1794 $scope.offset = slot[0];
1795 $scope.len = slot[1];
1796 var val = String.prototype.substr.apply(
1797 $scope.field.data, slot);
1799 $scope.selected_option = $scope.values_for_step
1800 .filter(function(opt) {
1801 return (opt.value() == val)})[0];
1803 $scope.selected_option = null;
1809 $scope.highlightedFieldData = function() {
1811 $scope.len && $scope.field.data &&
1812 $scope.field.data.length > 0 &&
1813 $scope.field.data.length >= $scope.offset
1815 return $sce.trustAsHtml(
1816 $scope.field.data.substring(0, $scope.offset) +
1817 '<span class="active-physchar">' +
1818 $scope.field.data.substr($scope.offset, $scope.len) +
1820 $scope.field.data.substr($scope.offset + $scope.len)
1823 return $scope.field.data;
1827 set_values_for_step();
1834 .directive("egMarcEditAuthorityBrowser", function () {
1838 templateUrl: './cat/share/t_authority_browser',
1845 controller: ['$scope','$http',
1846 function ($scope , $http) {
1850 $scope.main_headings = [];
1852 function getHeadingString(headingField) {
1854 angular.forEach(headingField.subfields, function (sf) {
1855 if (['x', 'y', 'z'].indexOf(sf[0]) > -1) {
1866 $scope.doBrowse = function() {
1867 $scope.main_headings.length = 0;
1868 if ($scope.searchString.length == 0) return;
1869 var type = 'authority.'
1870 var url = '/opac/extras/browse/marcxml/'
1871 + 'authority.' + $scope.axis + '.refs'
1872 + '/1' // OU - currently unscoped
1873 + '/' + $scope.searchString
1875 + '/' + $scope.limit;
1879 transformResponse : function(data) {
1880 // use a bit of jQuery to deal with the XML
1881 var $xml = $( $.parseXML(data) );
1883 $xml.find('record').each(function() {
1884 var rec = new MARC21.Record();
1885 rec.fromXmlDocument($(this)[0].outerHTML);
1890 }).then(function(response) {
1891 angular.forEach(response.data, function(rec) {
1892 var authId = rec.subfield('901', 'c')[1];
1894 if (rec.field('003')) {
1895 auth_org = rec.field('003').data;
1897 var headingField = rec.field('1..');
1898 var seeFroms = rec.field('4..', true);
1899 var seeAlsos = rec.field('5..', true);
1901 var main_heading = {
1902 authority_id : authId,
1903 heading : getHeadingString(headingField),
1904 seealso_headings : [ ],
1905 seefrom_headings : [ ],
1910 sfZero = '(' + auth_org + ')';
1913 headingField.addSubfields('0', sfZero);
1915 main_heading['headingField'] = headingField;
1916 angular.forEach(seeAlsos, function(headingField) {
1917 main_heading.seealso_headings.push({
1918 heading : getHeadingString(headingField),
1919 headingField : headingField
1922 angular.forEach(seeFroms, function(headingField) {
1923 main_heading.seefrom_headings.push({
1924 heading : getHeadingString(headingField),
1925 headingField : headingField
1928 $scope.main_headings.push(main_heading);
1933 $scope.$watch('searchString',
1934 function(newVal, oldVal) {
1935 if (newVal !== oldVal) {
1940 $scope.$watch('page',
1941 function(newVal, oldVal) {
1942 if (newVal !== oldVal) {