2 * UI tools and directives.
4 angular.module('egUiMod', ['egCoreMod', 'ui.bootstrap'])
8 * <input focus-me="iAmOpen"/>
9 * $scope.iAmOpen = true;
13 function($timeout , $parse) {
15 link: function(scope, element, attrs) {
16 var model = $parse(attrs.focusMe);
17 scope.$watch(model, function(value) {
19 $timeout(function() {element[0].focus()});
21 element.bind('blur', function() {
23 scope.$apply(model.assign(scope, false));
31 * <input blur-me="pleaseBlurMe"/>
32 * $scope.pleaseBlurMe = true
33 * Useful for de-focusing when no other obvious focus target exists
37 function($timeout , $parse) {
39 link: function(scope, element, attrs) {
40 var model = $parse(attrs.blurMe);
41 scope.$watch(model, function(value) {
43 $timeout(function() {element[0].blur()});
45 element.bind('focus', function() {
47 scope.$apply(model.assign(scope, false));
55 // <input select-me="iWantToBeSelected"/>
56 // $scope.iWantToBeSelected = true;
57 .directive('selectMe',
59 function($timeout , $parse) {
61 link: function(scope, element, attrs) {
62 var model = $parse(attrs.selectMe);
63 scope.$watch(model, function(value) {
65 $timeout(function() {element[0].select()});
67 element.bind('blur', function() {
69 scope.$apply(model.assign(scope, false));
78 // <div ng-repeat="item in items | reverse">{{item.name}}</div>
79 // http://stackoverflow.com/questions/15266671/angular-ng-repeat-in-reverse
80 // TODO: perhaps this should live elsewhere
81 .filter('reverse', function() {
82 return function(items) {
83 return items.slice().reverse();
88 // Overriding the core angular date filter with a moment-js based one for
89 // better timezone and formatting support.
90 .filter('date',function() {
107 var formatReplace = [
121 return function (date, format, tz) {
122 if (!date) return '';
125 date = new Date().toISOString();
128 var fmt = formatMap[format] || format;
129 angular.forEach(formatReplace, function (r) {
130 fmt = fmt.replace(r[0],r[1]);
134 var d = moment(date);
135 if (tz && tz !== '-') d.tz(tz);
137 return d.isValid() ? d.format(fmt) : '';
142 // 'egOrgDate' filter
143 // Uses moment.js and moment-timezone.js to put dates into the most appropriate
144 // timezone for a given (optional) org unit based on its lib.timezone setting
145 .filter('egOrgDate',['$filter','egCore',
146 function($filter , egCore) {
150 function eg_date_filter (date, fmt, ouID) {
152 if (angular.isObject(ouID)) {
153 if (angular.isFunction(ouID.id)) {
160 if (!tzcache[ouID]) {
162 egCore.org.settings('lib.timezone', ouID)
164 tzcache[ouID] = s['lib.timezone'] || OpenSRF.tz;
169 return $filter('date')(date, fmt, tzcache[ouID]);
172 eg_date_filter.$stateful = true;
174 return eg_date_filter;
177 // 'egOrgDateInContext' filter
178 // Uses the egOrgDate filter to make time and date location aware, and further
179 // modifies the format if one of [short, medium, long, full] to show only the
180 // date if the optional interval parameter is day-granular. This is
181 // particularly useful for due dates on circulations.
182 .filter('egOrgDateInContext',['$filter','egCore',
183 function($filter , egCore) {
185 function eg_context_date_filter (date, format, orgID, interval) {
187 if (!fmt) fmt = 'shortDate';
189 // if this is a simple, one-word format, and it doesn't say "Date" in it...
190 if (['short','medium','long','full'].filter(function(x){return fmt == x}).length > 0 && interval) {
191 var secs = egCore.date.intervalToSeconds(interval);
192 if (secs !== null && secs % 86400 == 0) fmt += 'Date';
195 return $filter('egOrgDate')(date, fmt, orgID);
198 eg_context_date_filter.$stateful = true;
200 return eg_context_date_filter;
203 // 'egDueDate' filter
204 // Uses the egOrgDateInContext filter to make time and date location aware, but
205 // only if the supplied interval is day-granular. This is as wrapper for
206 // egOrgDateInContext to be used for circulation due date /only/.
207 .filter('egDueDate',['$filter','egCore',
208 function($filter , egCore) {
210 function eg_context_due_date_filter (date, format, orgID, interval) {
212 var secs = egCore.date.intervalToSeconds(interval);
213 if (secs === null || secs % 86400 != 0) {
218 return $filter('egOrgDateInContext')(date, format, orgID, interval);
221 eg_context_due_date_filter.$stateful = true;
223 return eg_context_due_date_filter;
227 // TODO: perhaps this should live elsewhere
228 .filter('join', function() {
229 return function(arr,sep) {
230 if (typeof arr == 'object' && arr.constructor == Array) {
231 return arr.join(sep || ',');
241 * egProgressDialog.open();
242 * egProgressDialog.open({value : 0});
243 * egProgressDialog.open({value : 0, max : 123});
244 * egProgressDialog.increment();
245 * egProgressDialog.increment();
246 * egProgressDialog.close();
248 * Each dialog has 2 numbers, 'max' and 'value'.
249 * The content of these values determines how the dialog displays.
251 * There are 3 flavors:
253 * -- value is set, max is set
254 * determinate: shows a progression with a percent complete.
256 * -- value is set, max is unset
257 * semi-determinate, with a value report. Shows a value-less
258 * <progress/>, but shows the value as a number in the dialog.
260 * This is useful in cases where the total number of items to retrieve
261 * from the server is unknown, but we know how many items we've
262 * retrieved thus far. It helps to reinforce that something specific
263 * is happening, but we don't know when it will end.
266 * indeterminate: shows a generic value-less <progress/> with no
267 * clear indication of progress.
269 * Only 1 egProgressDialog instance will be activate at a time.
270 * Each invocation of .open() destroys any existing instance.
273 /* Simple storage class for egProgressDialog data maintenance.
274 * This data lives outside of egProgressDialog so it can be
275 * directly imported into egProgressDialog's $uibModalInstance.
277 .factory('egProgressData', [
279 var service = {}; // max/value initially unset
281 service.reset = function() {
283 delete service.value;
286 service.hasvalue = function() {
287 return Number.isInteger(service.value);
290 service.hasmax = function() {
291 return Number.isInteger(service.max);
294 service.percent = function() {
295 if (service.hasvalue() &&
298 service.value <= service.max)
299 return Math.floor((service.value / service.max) * 100);
307 .factory('egProgressDialog', [
308 'egProgressData','$uibModal',
309 function(egProgressData , $uibModal) {
312 service.open = function(args) {
313 service.close(); // force-kill existing instances.
315 // Reset to an indeterminate progress bar,
316 // overlay with caller values.
317 egProgressData.reset();
318 service.update(angular.extend({}, args));
320 return $uibModal.open({
321 templateUrl: './share/t_progress_dialog',
322 controller: ['$scope','$uibModalInstance','egProgressData',
323 function( $scope , $uibModalInstance , egProgressData) {
324 service.currentInstance = $uibModalInstance;
325 $scope.data = egProgressData; // tiny service
331 service.close = function() {
332 if (service.currentInstance) {
333 service.currentInstance.close();
334 delete service.currentInstance;
338 // Set the current state of the progress bar.
339 service.update = function(args) {
340 if (args.max != undefined)
341 egProgressData.max = args.max;
342 if (args.value != undefined)
343 egProgressData.value = args.value;
346 // Increment the current value. If no amount is specified,
347 // it increments by 1. Calling increment() on an indetermite
348 // progress bar will force it to be a (semi-)determinate bar.
349 service.increment = function(amt) {
350 if (!Number.isInteger(amt)) amt = 1;
352 if (!egProgressData.hasvalue())
353 egProgressData.value = 0;
355 egProgressData.value += amt;
362 * egAlertDialog.open({message : 'hello {{name}}'}).result.then(
363 * function() { console.log('alert closed') });
365 .factory('egAlertDialog',
367 ['$uibModal','$interpolate',
368 function($uibModal , $interpolate) {
371 service.open = function(message, msg_scope) {
372 return $uibModal.open({
373 templateUrl: './share/t_alert_dialog',
374 controller: ['$scope', '$uibModalInstance',
375 function($scope, $uibModalInstance) {
376 $scope.message = $interpolate(message)(msg_scope);
377 $scope.ok = function() {
378 if (msg_scope && msg_scope.ok) msg_scope.ok();
379 $uibModalInstance.close()
390 * egConfirmDialog.open("some message goes {{here}}", {
391 * here : 'foo', ok : function() {}, cancel : function() {}},
394 .factory('egConfirmDialog',
396 ['$uibModal','$interpolate',
397 function($uibModal, $interpolate) {
400 service.open = function(title, message, msg_scope, ok_button_label, cancel_button_label) {
401 return $uibModal.open({
402 templateUrl: './share/t_confirm_dialog',
403 controller: ['$scope', '$uibModalInstance',
404 function($scope, $uibModalInstance) {
405 $scope.title = $interpolate(title)(msg_scope);
406 $scope.message = $interpolate(message)(msg_scope);
407 $scope.ok_button_label = $interpolate(ok_button_label || '')(msg_scope);
408 $scope.cancel_button_label = $interpolate(cancel_button_label || '')(msg_scope);
409 $scope.ok = function() {
410 if (msg_scope.ok) msg_scope.ok();
411 $uibModalInstance.close()
413 $scope.cancel = function() {
414 if (msg_scope.cancel) msg_scope.cancel();
415 $uibModalInstance.dismiss();
426 * egPromptDialog.open(
427 * "prompt message goes {{here}}",
428 * promptValue, // optional
431 * ok : function(value) {console.log(value)},
432 * cancel : function() {console.log('prompt denied')}
436 .factory('egPromptDialog',
438 ['$uibModal','$interpolate',
439 function($uibModal, $interpolate) {
442 service.open = function(message, promptValue, msg_scope) {
443 return $uibModal.open({
444 templateUrl: './share/t_prompt_dialog',
445 controller: ['$scope', '$uibModalInstance',
446 function($scope, $uibModalInstance) {
447 $scope.message = $interpolate(message)(msg_scope);
448 $scope.args = {value : promptValue || ''};
450 $scope.ok = function() {
451 if (msg_scope.ok) msg_scope.ok($scope.args.value);
452 $uibModalInstance.close()
454 $scope.cancel = function() {
455 if (msg_scope.cancel) msg_scope.cancel();
456 $uibModalInstance.dismiss();
467 * egSelectDialog.open(
468 * "message goes {{here}}",
469 * list, // ['values','for','dropdown'],
470 * selectedValue, // optional
473 * ok : function(value) {console.log(value)},
474 * cancel : function() {console.log('prompt denied')}
478 .factory('egSelectDialog',
480 ['$uibModal','$interpolate',
481 function($uibModal, $interpolate) {
484 service.open = function(message, inputList, selectedValue, msg_scope) {
485 return $uibModal.open({
486 templateUrl: './share/t_select_dialog',
487 controller: ['$scope', '$uibModalInstance',
488 function($scope, $uibModalInstance) {
489 $scope.message = $interpolate(message)(msg_scope);
492 value : selectedValue
495 $scope.ok = function() {
496 if (msg_scope.ok) msg_scope.ok($scope.args.value);
497 $uibModalInstance.close()
499 $scope.cancel = function() {
500 if (msg_scope.cancel) msg_scope.cancel();
501 $uibModalInstance.dismiss();
512 * Warn on page unload and give the user a chance to avoid navigating
513 * away from the current page.
514 * Only one handler is supported per page.
515 * NOTE: we can't use an egUnloadDialog as the dialog builder, because
516 * it renders asynchronously, which allows the page to redirect before
517 * the dialog appears.
519 .factory('egUnloadPrompt', [
520 '$window','egStrings',
521 function($window , egStrings) {
522 var service = {attached : false};
524 // attach a page/scope unload prompt
525 service.attach = function($scope, msg) {
526 if (service.attached) return;
527 service.attached = true;
529 // handle page change
530 $($window).on('beforeunload', function() {
532 return msg || egStrings.EG_UNLOAD_PAGE_PROMPT_MSG;
537 // If a scope was provided, attach a scope-change handler,
538 // similar to the page-page prompt.
539 service.locChangeCancel =
540 $scope.$on('$locationChangeStart', function(evt, next, current) {
541 if (confirm(msg || egStrings.EG_UNLOAD_CTRL_PROMPT_MSG)) {
542 // user allowed the page to change.
543 // Clear the unload handler.
546 evt.preventDefault();
551 // remove the page unload prompt
552 service.clear = function() {
553 $($window).off('beforeunload');
554 if (service.locChangeCancel)
555 service.locChangeCancel();
556 service.attached = false;
562 .directive('aDisabled', function() {
565 compile: function(tElement, tAttrs, transclude) {
567 tAttrs["ngClick"] = ("ng-click", "!("+tAttrs["aDisabled"]+") && ("+tAttrs["ngClick"]+")");
569 //Toggle "disabled" to class when aDisabled becomes true
570 return function (scope, iElement, iAttrs) {
571 scope.$watch(iAttrs["aDisabled"], function(newValue) {
572 if (newValue !== undefined) {
573 iElement.toggleClass("disabled", newValue);
577 //Disable href on click
578 iElement.on("click", function(e) {
579 if (scope.$eval(iAttrs["aDisabled"])) {
588 .directive('egBasicComboBox', function() {
593 list: "=", // list of strings
599 '<div class="input-group">'+
600 '<input type="text" ng-disabled="egDisabled" class="form-control" ng-model="selected" ng-change="makeOpen()">'+
601 '<div class="input-group-btn" dropdown ng-class="{open:isopen}">'+
602 '<button type="button" ng-click="showAll()" class="btn btn-default dropdown-toggle"><span class="caret"></span></button>'+
603 '<ul class="dropdown-menu dropdown-menu-right">'+
604 '<li ng-repeat="item in list|filter:selected"><a href ng-click="changeValue(item)">{{item}}</a></li>'+
605 '<li ng-if="complete_list" class="divider"><span></span></li>'+
606 '<li ng-if="complete_list" ng-repeat="item in list"><a href ng-click="changeValue(item)">{{item}}</a></li>'+
610 controller: ['$scope','$filter',
611 function( $scope , $filter) {
613 $scope.complete_list = false;
614 $scope.isopen = false;
615 $scope.clickedopen = false;
616 $scope.clickedclosed = null;
618 $scope.showAll = function () {
620 $scope.clickedopen = !$scope.clickedopen;
622 if ($scope.clickedclosed === null) {
623 if (!$scope.clickedopen) {
624 $scope.clickedclosed = true;
627 $scope.clickedclosed = !$scope.clickedopen;
630 if ($scope.selected.length > 0) $scope.complete_list = true;
631 if ($scope.selected.length == 0) $scope.complete_list = false;
635 $scope.makeOpen = function () {
636 $scope.isopen = $scope.clickedopen || ($filter('filter')(
639 ).length > 0 && $scope.selected.length > 0);
640 if ($scope.clickedclosed) $scope.isopen = false;
643 $scope.changeValue = function (newVal) {
644 $scope.selected = newVal;
645 $scope.isopen = false;
646 $scope.clickedclosed = null;
647 $scope.clickedopen = false;
648 if ($scope.selected.length == 0) $scope.complete_list = false;
657 * Nested org unit selector modeled as a Bootstrap dropdown button.
659 .directive('egOrgSelector', function() {
663 replace : true, // makes styling easier
665 selected : '=', // defaults to workstation or root org,
666 // unless the nodefault attibute exists
668 // Each org unit is passed into this function and, for
669 // any org units where the response value is true, the
670 // org unit will not be added to the selector.
673 // Each org unit is passed into this function and, for
674 // any org units where the response value is true, the
675 // org unit will not be available for selection.
678 // if set to true, disable the UI element altogether
681 // Caller can either $watch(selected, ..) or register an
685 // optional primary drop-down button label
688 // optional name of settings key for persisting
689 // the last selected org unit
693 // any reason to move this into a TT2 template?
695 '<div class="btn-group eg-org-selector" uib-dropdown>'
696 + '<button type="button" class="btn btn-default" uib-dropdown-toggle ng-disabled="disable_button">'
697 + '<span style="padding-right: 5px;">{{getSelectedName()}}</span>'
698 + '<span class="caret"></span>'
700 + '<ul uib-dropdown-menu class="scrollable-menu">'
701 + '<li ng-repeat="org in orgList" ng-hide="hiddenTest(org.id)">'
702 + '<a href ng-click="orgChanged(org)" a-disabled="disableTest(org.id)" '
703 + 'style="padding-left: {{org.depth * 10 + 5}}px">'
704 + '{{org.shortname}}'
710 controller : ['$scope','$timeout','egCore','egStartup','egLovefield','$q',
711 function($scope , $timeout , egCore , egStartup , egLovefield , $q) {
713 if ($scope.alldisabled) {
714 $scope.disable_button = $scope.alldisabled == 'true' ? true : false;
716 $scope.disable_button = false;
719 // avoid linking the full fleshed tree to the scope by
720 // tossing in a flattened list.
722 // Run-time code referencing post-start data should be run
723 // from within a startup block, otherwise accessing this
724 // module before startup completes will lead to failure.
726 // controller() runs before link().
727 // This post-startup code runs after link().
731 return egCore.env.classLoaders.aou();
736 $scope.orgList = egCore.org.list().map(function(org) {
739 shortname : org.shortname(),
740 depth : org.ou_type().depth()
745 // Apply default values
747 if ($scope.stickySetting) {
748 var orgId = egCore.hatch.getLocalItem($scope.stickySetting);
750 $scope.selected = egCore.org.get(orgId);
754 if (!$scope.selected && !$scope.nodefault && egCore.auth.user()) {
756 egCore.org.get(egCore.auth.user().ws_ou());
759 fire_orgsel_onchange(); // no-op if nothing is selected
764 * Fire onchange handler after a timeout, so the
765 * $scope.selected value has a chance to propagate to
766 * the page controllers before the onchange fires. This
767 * way, the caller does not have to manually capture the
768 * $scope.selected value during onchange.
770 function fire_orgsel_onchange() {
771 if (!$scope.selected || !$scope.onchange) return;
772 $timeout(function() {
774 'egOrgSelector onchange('+$scope.selected.id()+')');
775 $scope.onchange($scope.selected)
779 $scope.getSelectedName = function() {
780 if ($scope.selected && $scope.selected.shortname)
781 return $scope.selected.shortname();
785 $scope.orgChanged = function(org) {
786 $scope.selected = egCore.org.get(org.id);
787 if ($scope.stickySetting) {
788 egCore.hatch.setLocalItem($scope.stickySetting, org.id);
790 fire_orgsel_onchange();
794 link : function(scope, element, attrs, egGridCtrl) {
796 // boolean fields are presented as value-less attributes
800 if (angular.isDefined(attrs[field]))
803 scope[field] = false;
810 .directive('nextOnEnter', function () {
811 return function (scope, element, attrs) {
812 element.bind("keydown keypress", function (event) {
813 if(event.which === 13) {
814 $('#'+attrs.nextOnEnter).focus();
815 event.preventDefault();
821 /* http://eric.sau.pe/angularjs-detect-enter-key-ngenter/ */
822 .directive('egEnter', function () {
823 return function (scope, element, attrs) {
824 element.bind("keydown keypress", function (event) {
825 if(event.which === 13) {
826 scope.$apply(function (){
827 scope.$eval(attrs.egEnter);
830 event.preventDefault();
837 * Handy wrapper directive for uib-datapicker-popup
840 'egDateInput', ['egStrings', 'egCore',
841 function(egStrings, egCore) {
853 hideDatePicker : '=',
858 templateUrl: './share/t_datetime',
860 controller : ['$scope', function($scope) {
862 minDate : $scope.minDate,
863 maxDate : $scope.maxDate
866 var maxDateObj = $scope.maxDate ? new Date($scope.maxDate) : null;
867 var minDateObj = $scope.minDate ? new Date($scope.minDate) : null;
869 if ($scope.outOfRange !== undefined && (maxDateObj || minDateObj)) {
870 $scope.$watch('ngModel', function (n,o) {
873 var newdate = new Date(n);
874 if (maxDateObj && newdate.getTime() > maxDateObj.getTime()) bad = true;
875 if (minDateObj && newdate.getTime() < minDateObj.getTime()) bad = true;
876 $scope.outOfRange = bad;
881 link : function(scope, elm, attrs) {
882 if (!scope.closeText)
883 scope.closeText = egStrings.EG_DATE_INPUT_CLOSE_TEXT;
885 if ('showTimePicker' in attrs)
886 scope.showTimePicker = true;
888 var default_format = 'mediumDate';
889 egCore.org.settings(['format.date']).then(function(set) {
890 default_format = set['format.date'];
891 scope.date_format = (scope.dateFormat) ?
901 * egFmValueSelector - widget for selecting a value from list specified
904 .directive('egFmValueSelector', function() {
912 // optional filter for refining the set of rows that
913 // get returned. Example:
915 // filter="{'column':{'=':null}}"
918 // optional name of settings key for persisting
919 // the last selected value
922 // optional OU setting for fetching default value;
923 // used only if sticky setting not set
927 templateUrl : './share/t_fm_value_selector',
928 controller : ['$scope','egCore', function($scope , egCore) {
930 $scope.org = egCore.org; // for use in the link function
931 $scope.auth = egCore.auth; // for use in the link function
932 $scope.hatch = egCore.hatch // for use in the link function
934 function flatten_linked_values(cls, list) {
936 var fields = egCore.idl.classes[cls].fields;
939 angular.forEach(fields, function(fld) {
940 if (fld.datatype == 'id') {
942 selector = fld.selector ? fld.selector : id_field;
946 angular.forEach(list, function(item) {
947 var rec = egCore.idl.toHash(item);
957 search[egCore.idl.classes[$scope.idlClass].pkey] = {'!=' : null};
959 angular.extend(search, $scope.filter);
962 $scope.idlClass, search, {}, {atomic : true}
963 ).then(function(list) {
964 $scope.linked_values = flatten_linked_values($scope.idlClass, list);
967 $scope.handleChange = function(value) {
968 if ($scope.stickySetting) {
969 egCore.hatch.setLocalItem($scope.stickySetting, value);
974 link : function(scope, element, attrs) {
975 if (scope.stickySetting && (angular.isUndefined(scope.ngModel) || (scope.ngModel === null))) {
976 var value = scope.hatch.getLocalItem(scope.stickySetting);
977 scope.ngModel = value;
979 if (scope.ouSetting && (angular.isUndefined(scope.ngModel) || (scope.ngModel === null))) {
980 scope.org.settings([scope.ouSetting], scope.auth.user().ws_ou())
981 .then(function(set) {
982 var value = parseInt(set[scope.ouSetting]);
984 scope.ngModel = value;
992 * egShareDepthSelector - widget for selecting a share depth
994 .directive('egShareDepthSelector', function() {
1002 templateUrl : './share/t_share_depth_selector',
1003 controller : ['$scope','egCore', function($scope , egCore) {
1005 egCore.pcrud.search('aout',
1006 { id : {'!=' : null} },
1007 { order_by : {aout : ['depth', 'name']} },
1009 ).then(function(list) {
1011 angular.forEach(list, function(aout) {
1012 var depth = parseInt(aout.depth());
1013 if (depth in scratch) {
1014 scratch[depth].push(aout.name());
1016 scratch[depth] = [ aout.name() ]
1019 scratch.forEach(function(val, idx) {
1020 $scope.values.push({ id : idx, name : scratch[idx].join(' / ') });
1027 .factory('egWorkLog', ['egCore', function(egCore) {
1030 service.retrieve_all = function() {
1031 var workLog = egCore.hatch.getLocalItem('eg.work_log') || [];
1032 var patronLog = egCore.hatch.getLocalItem('eg.patron_log') || [];
1034 return { 'work_log' : workLog, 'patron_log' : patronLog };
1037 service.record = function(message,data) {
1040 if (typeof egCore != 'undefined') {
1041 if (typeof egCore.env != 'undefined') {
1042 if (typeof egCore.env.aous != 'undefined') {
1043 max_entries = egCore.env.aous['ui.admin.work_log.max_entries'];
1044 max_patrons = egCore.env.aous['ui.admin.patron_log.max_entries'];
1046 console.log('worklog: missing egCore.env.aous');
1049 console.log('worklog: missing egCore.env');
1052 console.log('worklog: missing egCore');
1055 if (typeof egCore.org != 'undefined') {
1056 if (typeof egCore.org.cachedSettings != 'undefined') {
1057 max_entries = egCore.org.cachedSettings['ui.admin.work_log.max_entries'];
1059 console.log('worklog: missing egCore.org.cachedSettings');
1062 console.log('worklog: missing egCore.org');
1066 if (typeof egCore.org != 'undefined') {
1067 if (typeof egCore.org.cachedSettings != 'undefined') {
1068 max_patrons = egCore.org.cachedSettings['ui.admin.patron_log.max_entries'];
1070 console.log('worklog: missing egCore.org.cachedSettings');
1073 console.log('worklog: missing egCore.org');
1078 console.log('worklog: defaulting to max_entries = ' + max_entries);
1082 console.log('worklog: defaulting to max_patrons = ' + max_patrons);
1085 var workLog = egCore.hatch.getLocalItem('eg.work_log') || [];
1086 var patronLog = egCore.hatch.getLocalItem('eg.patron_log') || [];
1088 'when' : new Date(),
1090 'action' : data.action,
1091 'actor' : egCore.auth.user().usrname()
1093 if (data.action == 'checkin') {
1094 entry['item'] = data.response.params.copy_barcode;
1095 entry['item_id'] = data.response.data.acp.id();
1096 if (data.response.data.au) {
1097 entry['user'] = data.response.data.au.family_name();
1098 entry['patron_id'] = data.response.data.au.id();
1101 if (data.action == 'checkout') {
1102 entry['item'] = data.response.params.copy_barcode;
1103 entry['user'] = data.response.data.au.family_name();
1104 entry['item_id'] = data.response.data.acp.id();
1105 entry['patron_id'] = data.response.data.au.id();
1107 if (data.action == 'noncat_checkout') {
1108 entry['user'] = data.response.data.au.family_name();
1109 entry['patron_id'] = data.response.data.au.id();
1111 if (data.action == 'renew') {
1112 entry['item'] = data.response.params.copy_barcode;
1113 entry['user'] = data.response.data.au.family_name();
1114 entry['item_id'] = data.response.data.acp.id();
1115 entry['patron_id'] = data.response.data.au.id();
1117 if (data.action == 'requested_hold'
1118 || data.action == 'edited_patron'
1119 || data.action == 'registered_patron'
1120 || data.action == 'paid_bill') {
1121 entry['patron_id'] = data.patron_id;
1123 if (data.action == 'requested_hold') {
1124 entry['hold_id'] = data.hold_id;
1126 if (data.action == 'paid_bill') {
1127 entry['amount'] = data.total_amount;
1130 workLog.push( entry );
1131 if (workLog.length > max_entries) workLog.shift();
1132 egCore.hatch.setLocalItem('eg.work_log',workLog); // hatch JSONifies the data, so should be okay re: memory leaks?
1134 if (entry['patron_id']) {
1136 for (var i = 0; i < patronLog.length; i++) { // filter out any matching patron
1137 if (patronLog[i]['patron_id'] != entry['patron_id']) temp.push(patronLog[i]);
1140 if (temp.length > max_patrons) temp.shift();
1142 egCore.hatch.setLocalItem('eg.patron_log',patronLog);
1145 console.log('worklog',entry);