4 * Search, checkout, items out, holds, bills, edit, etc.
7 angular.module('egPatronApp', ['ngRoute', 'ui.bootstrap', 'egUserBucketMod',
8 'egCoreMod', 'egUiMod', 'egGridMod', 'egUserMod', 'ngToast',
11 .config(['ngToastProvider', function(ngToastProvider) {
12 ngToastProvider.configure({
13 verticalPosition: 'bottom',
18 .config(function($routeProvider, $locationProvider, $compileProvider) {
19 $locationProvider.html5Mode(true);
20 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
22 // data loaded at startup which only requires an authtoken goes
23 // here. this allows the requests to be run in parallel instead of
24 // waiting until startup has completed.
25 var resolver = {delay : ['egCore','egUser', function(egCore , egUser) {
27 // fetch the org settings we care about during egStartup
28 // and toss them into egCore.env as egCore.env.aous[name] = value.
29 // note: only load settings here needed by all tabs; load tab-
30 // specific settings from within their respective controllers
31 egCore.env.classLoaders.aous = function() {
32 return egCore.org.settings([
33 'ui.staff.require_initials.patron_info_notes',
34 'circ.do_not_tally_claims_returned',
37 'ui.circ.show_billing_tab_on_bills',
38 'circ.patron_expires_soon_warning',
39 'ui.circ.items_out.lost',
40 'ui.circ.items_out.longoverdue',
41 'ui.circ.items_out.claimsreturned'
42 ]).then(function(settings) {
43 // local settings are cached within egOrg. Caching them
44 // again in egEnv just simplifies the syntax for access.
45 egCore.env.aous = settings;
49 egCore.env.loadClasses.push('aous');
51 // app-globally modify the default flesh fields for
52 // fleshed user retrieval.
53 if (egUser.defaultFleshFields.indexOf('profile') == -1) {
54 egUser.defaultFleshFields = egUser.defaultFleshFields.concat([
64 return egCore.startup.go().then(function() {
66 // This call requires orgs to be loaded, because it
67 // calls egCore.org.ancestors(), so call it after startup
68 return egCore.pcrud.search('actsc',
69 {owner : egCore.org.ancestors(
70 egCore.auth.user().ws_ou(), true)},
72 ).then(function(cats) {
73 egCore.env.absorbList(cats, 'actsc');
78 $routeProvider.when('/circ/patron/search', {
79 templateUrl: './circ/patron/t_search',
80 controller: 'PatronSearchCtrl',
84 $routeProvider.when('/circ/patron/bcsearch', {
85 templateUrl: './circ/patron/t_bcsearch',
86 controller: 'PatronBarcodeSearchCtrl',
90 $routeProvider.when('/circ/patron/credentials', {
91 templateUrl: './circ/patron/t_credentials',
92 controller: 'PatronVerifyCredentialsCtrl',
96 $routeProvider.when('/circ/patron/last', {
97 templateUrl: './circ/patron/t_last_patron',
98 controller: 'PatronFetchLastCtrl',
102 // the following require a patron ID
104 $routeProvider.when('/circ/patron/:id/alerts', {
105 templateUrl: './circ/patron/t_alerts',
106 controller: 'PatronAlertsCtrl',
110 $routeProvider.when('/circ/patron/:id/checkout', {
111 templateUrl: './circ/patron/t_checkout',
112 controller: 'PatronCheckoutCtrl',
116 $routeProvider.when('/circ/patron/:id/items_out', {
117 templateUrl: './circ/patron/t_items_out',
118 controller: 'PatronItemsOutCtrl',
122 $routeProvider.when('/circ/patron/:id/holds', {
123 templateUrl: './circ/patron/t_holds',
124 controller: 'PatronHoldsCtrl',
128 $routeProvider.when('/circ/patron/:id/holds/create', {
129 templateUrl: './circ/patron/t_holds_create',
130 controller: 'PatronHoldsCreateCtrl',
134 $routeProvider.when('/circ/patron/:id/holds/:hold_id', {
135 templateUrl: './circ/patron/t_holds',
136 controller: 'PatronHoldsCtrl',
140 $routeProvider.when('/circ/patron/:id/hold/:hold_id', {
141 templateUrl: './circ/patron/t_hold_details',
142 controller: 'PatronHoldDetailsCtrl',
146 $routeProvider.when('/circ/patron/:id/bills', {
147 templateUrl: './circ/patron/t_bills',
148 controller: 'PatronBillsCtrl',
152 $routeProvider.when('/circ/patron/:id/bill/:xact_id', {
153 templateUrl: './circ/patron/t_xact_details',
154 controller: 'XactDetailsCtrl',
158 $routeProvider.when('/circ/patron/:id/bill_history/:history_tab', {
159 templateUrl: './circ/patron/t_bill_history',
160 controller: 'BillHistoryCtrl',
164 $routeProvider.when('/circ/patron/:id/messages', {
165 templateUrl: './circ/patron/t_messages',
166 controller: 'PatronMessagesCtrl',
170 $routeProvider.when('/circ/patron/:id/edit', {
171 templateUrl: './circ/patron/t_edit',
172 controller: 'PatronRegCtrl',
176 $routeProvider.when('/circ/patron/:id/credentials', {
177 templateUrl: './circ/patron/t_credentials',
178 controller: 'PatronVerifyCredentialsCtrl',
182 $routeProvider.when('/circ/patron/:id/notes', {
183 templateUrl: './circ/patron/t_notes',
184 controller: 'PatronNotesCtrl',
188 $routeProvider.when('/circ/patron/:id/triggered_events', {
189 templateUrl: './circ/patron/t_triggered_events',
190 controller: 'PatronTriggeredEventsCtrl',
194 $routeProvider.when('/circ/patron/:id/message_center', {
195 templateUrl: './circ/patron/t_message_center',
196 controller: 'PatronMessageCenterCtrl',
200 $routeProvider.when('/circ/patron/:id/edit_perms', {
201 templateUrl: './circ/patron/t_edit_perms',
202 controller: 'PatronPermsCtrl',
206 $routeProvider.when('/circ/patron/:id/group', {
207 templateUrl: './circ/patron/t_group',
208 controller: 'PatronGroupCtrl',
212 $routeProvider.when('/circ/patron/:id/stat_cats', {
213 templateUrl: './circ/patron/t_stat_cats',
214 controller: 'PatronStatCatsCtrl',
218 $routeProvider.when('/circ/patron/:id/surveys', {
219 templateUrl: './circ/patron/t_surveys',
220 controller: 'PatronSurveyCtrl',
224 $routeProvider.otherwise({redirectTo : '/circ/patron/search'});
228 * Manages tabbed patron view.
229 * This is the parent scope of all patron tab scopes.
232 .controller('PatronCtrl',
233 ['$scope','$q','$location','$filter','egCore','egNet','egUser','egAlertDialog','egConfirmDialog','egPromptDialog','patronSvc',
234 function($scope, $q , $location , $filter , egCore , egNet , egUser , egAlertDialog , egConfirmDialog , egPromptDialog , patronSvc) {
236 $scope.is_patron_edit = function() {
237 return Boolean($location.path().match(/patron\/\d+\/edit$/));
240 // To support the fixed position patron edit actions bar,
241 // its markup has to live outside the scope of the patron
242 // edit controller. Insert a scope blob here that can be
243 // modifed from within the patron edit controller.
244 $scope.edit_passthru = {};
246 // returns true if a redirect occurs
247 function redirectToAlertPanel() {
249 $scope.alert_penalties =
250 function() {return patronSvc.alert_penalties}
252 if (patronSvc.alertsShown()) return false;
254 // if the patron has any unshown alerts, show them now
255 if (patronSvc.hasAlerts &&
256 !$location.path().match(/alerts$/)) {
259 .path('/circ/patron/' + patronSvc.current.id() + '/alerts')
260 .search('card', null);
264 // no alert required. If the patron has fines and the show-bills
265 // OUS is applied, direct to the bills page.
266 if ($scope.patron_stats().fines.balance_owed > 0 // TODO: != 0 ?
267 && egCore.env.aous['ui.circ.show_billing_tab_on_bills']
268 && !$location.path().match(/bills$/)) {
270 $scope.tab = 'bills';
272 .path('/circ/patron/' + patronSvc.current.id() + '/bills')
273 .search('card', null);
281 // called after each route-specified controller is instantiated.
282 // this doubles as a way to inform the top-level controller that
283 // egStartup.go() has completed, which means we are clear to
284 // fetch the patron, etc.
285 $scope.initTab = function(tab, patron_id) {
286 console.log('init tab ' + tab);
288 $scope.aous = egCore.env.aous;
289 $scope.auth_user_id = egCore.auth.user().id();
292 $scope.patron_id = patron_id;
293 return patronSvc.setPrimary($scope.patron_id)
294 .then(function() {return patronSvc.checkAlerts()})
295 .then(redirectToAlertPanel);
300 $scope._show_dob = {};
301 $scope.show_dob = function (val) {
302 if ($scope.patron()) {
303 if (typeof val != 'undefined') $scope._show_dob[$scope.patron().id()] = val;
304 return $scope._show_dob[$scope.patron().id()];
306 return !egCore.env.aous['circ.obscure_dob'];
309 $scope.obscure_dob = function() {
310 return egCore.env.aous && egCore.env.aous['circ.obscure_dob'];
312 $scope.now_show_dob = function() {
313 return egCore.env.aous && egCore.env.aous['circ.obscure_dob'] ?
314 $scope.show_dob() : true;
317 $scope.patron = function() { return patronSvc.current }
318 $scope.patron_stats = function() { return patronSvc.patron_stats }
319 $scope.summary_stat_cats = function() { return patronSvc.summary_stat_cats }
320 $scope.hasAlerts = function() { return patronSvc.hasAlerts }
321 $scope.isPatronExpired = function() { return patronSvc.patronExpired }
323 $scope.print_address = function(addr) {
326 template : 'patron_address',
328 patron : egCore.idl.toHash(patronSvc.current),
329 address : egCore.idl.toHash(addr)
334 $scope.toggle_expand_summary = function() {
335 if ($scope.collapsePatronSummary) {
336 $scope.collapsePatronSummary = false;
337 egCore.hatch.removeItem('eg.circ.patron.summary.collapse');
339 $scope.collapsePatronSummary = true;
340 egCore.hatch.setItem('eg.circ.patron.summary.collapse', true);
344 // always expand the patron summary in the search UI, regardless
345 // of stored preference.
346 $scope.collapse_summary = function() {
347 return $scope.tab != 'search' && $scope.collapsePatronSummary;
350 function _purge_account(dest_usr,override) {
353 'open-ils.actor.user.delete' + (override ? '.override' : ''),
355 $scope.patron().id(),
357 ).then(function(resp){
358 if (evt = egCore.evt.parse(resp)) {
359 if (evt.code == '2004' /* ACTOR_USER_DELETE_OPEN_XACTS */) {
360 egConfirmDialog.open(
361 egCore.strings.PATRON_PURGE_CONFIRM_TITLE, egCore.strings.PATRON_PURGE_OVERRIDE_PROMPT,
363 _purge_account(dest_usr,true);
370 location.href = egCore.env.basePath + '/circ/patron/search';
375 function _purge_account_with_destination(dest_barcode) {
376 egCore.pcrud.search('ac', {barcode : dest_barcode})
377 .then(function(card) {
379 egAlertDialog.open(egCore.strings.PATRON_PURGE_STAFF_BAD_BARCODE);
381 _purge_account(card.usr());
386 $scope.purge_account = function() {
387 egConfirmDialog.open(
388 egCore.strings.PATRON_PURGE_CONFIRM_TITLE, egCore.strings.PATRON_PURGE_CONFIRM,
390 egConfirmDialog.open(
391 egCore.strings.PATRON_PURGE_CONFIRM_TITLE, egCore.strings.PATRON_PURGE_LAST_CHANCE,
395 'open-ils.actor.user.has_work_perm_at',
396 egCore.auth.token(), 'STAFF_LOGIN', $scope.patron().id()
397 ).then(function(resp) {
398 var is_staff = resp.length > 0;
401 egCore.strings.PATRON_PURGE_STAFF_PROMPT,
402 null, // TODO: this would be cool if it worked: egCore.auth.user().card().barcode(),
403 {ok : function(barcode) {_purge_account_with_destination(barcode)}}
415 egCore.hatch.getItem('eg.circ.patron.summary.collapse')
416 .then(function(val) {$scope.collapsePatronSummary = Boolean(val)});
419 .controller('PatronBarcodeSearchCtrl',
420 ['$scope','$location','egCore','egConfirmDialog','egUser','patronSvc',
421 function($scope , $location , egCore , egConfirmDialog , egUser , patronSvc) {
422 $scope.selectMe = true; // focus text input
423 patronSvc.clearPrimary(); // clear the default user
425 // jump to the patron checkout UI
426 function loadPatron(user_id) {
427 egCore.audio.play('success.patron.by_barcode');
429 .path('/circ/patron/' + user_id + '/checkout')
430 .search('card', $scope.args.barcode);
431 patronSvc.search_barcode = $scope.args.barcode;
434 // create an opt-in=yes response for the loaded user
435 function createOptIn(user_id) {
438 'open-ils.actor.user.org_unit_opt_in.create',
439 egCore.auth.token(), user_id).then(function(resp) {
440 if (evt = egCore.evt.parse(resp)) return alert(evt);
446 $scope.submitBarcode = function(args) {
447 $scope.bcNotFound = null;
448 $scope.optInRestricted = false;
449 if (!args.barcode) return;
450 args.barcode = args.barcode.replace(/\s/g,'');
451 // blur so next time it's set to true it will re-apply select()
452 $scope.selectMe = false;
459 'open-ils.actor.get_barcodes',
460 egCore.auth.token(), egCore.auth.user().ws_ou(),
461 'actor', args.barcode)
463 .then(function(resp) { // get_barcodes
465 if (evt = egCore.evt.parse(resp)) {
470 if (!resp || !resp[0]) {
471 $scope.bcNotFound = args.barcode;
472 $scope.selectMe = true;
473 egCore.audio.play('warning.patron.not_found');
477 // see if an opt-in request is needed
478 user_id = resp[0].id;
479 return egCore.net.request(
481 'open-ils.actor.user.org_unit_opt_in.check',
482 egCore.auth.token(), user_id);
484 }).then(function(optInResp) { // opt_in_check
486 if (evt = egCore.evt.parse(optInResp)) {
491 if (optInResp == 2) {
492 // opt-in disallowed at this location by patron's home library
493 $scope.optInRestricted = true;
494 $scope.selectMe = true;
495 egCore.audio.play('warning.patron.opt_in_restricted');
499 if (optInResp == 1) {
500 // opt-in handled or not needed
501 return loadPatron(user_id);
504 // opt-in needed, show the opt-in dialog
505 egUser.get(user_id, {useFields : []})
507 .then(function(user) { // retrieve user
508 var org = egCore.org.get(user.home_ou());
509 egConfirmDialog.open(
510 egCore.strings.OPT_IN_DIALOG_TITLE,
511 egCore.strings.OPT_IN_DIALOG,
512 { family_name : user.family_name(),
513 first_given_name : user.first_given_name(),
514 org_name : org.name(),
515 org_shortname : org.shortname(),
516 ok : function() { createOptIn(user.id()) },
517 cancel : function() {}
527 * Manages patron search
529 .controller('PatronSearchCtrl',
530 ['$scope','$q','$routeParams','$timeout','$window','$location','egCore','ngToast',
531 '$filter','egUser', 'patronSvc','egGridDataProvider','$document','bucketSvc',
532 'egPatronMerge','egProgressDialog','$controller','$interpolate','$uibModal',
533 function($scope, $q, $routeParams, $timeout, $window, $location, egCore , ngToast,
534 $filter, egUser, patronSvc , egGridDataProvider , $document , bucketSvc,
535 egPatronMerge , egProgressDialog , $controller , $interpolate , $uibModal) {
537 angular.extend(this, $controller('BasePatronSearchCtrl', {$scope : $scope}));
538 $scope.initTab('search');
540 $scope.gridControls = {
541 activateItem : function(item) {
542 $location.path('/circ/patron/' + item.id() + '/checkout');
544 selectedItems : function() { return [] }
547 $scope.bucketSvc = bucketSvc;
548 $scope.bucketSvc.fetchUserBuckets();
549 $scope.addToBucket = function(item, data, recs) {
550 if (recs.length == 0) return;
552 var failed_count = 0;
554 angular.forEach(recs,
556 var item = new egCore.idl.cubi();
557 item.bucket(data.id());
558 item.target_user(rec.id());
559 p.push(egCore.net.request(
561 'open-ils.actor.container.item.create',
562 egCore.auth.token(), 'user', item
564 function(){ added_count++ },
565 function(){ failed_count++ }
570 $q.all(p).then( function () {
571 if (added_count) ngToast.create($interpolate(egCore.strings.BUCKET_ADD_SUCCESS)({ count: ''+added_count, name: data.name()} ));
572 if (failed_count) ngToast.warning($interpolate(egCore.strings.BUCKET_ADD_FAIL)({ count: ''+failed_count, name: data.name() } ));
576 var temp_scope = $scope;
577 $scope.openCreateBucketDialog = function() {
579 templateUrl: './circ/patron/bucket/t_bucket_create',
582 ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
583 $scope.focusMe = true;
584 $scope.ok = function(args) { $uibModalInstance.close(args) }
585 $scope.cancel = function () { $uibModalInstance.dismiss() }
587 }).result.then(function (args) {
588 if (!args || !args.name) return;
589 bucketSvc.createBucket(args.name, args.desc).then(
592 $scope.bucketSvc.fetchBucket(id).then(function (b) {
596 $scope.gridControls.selectedItems()
598 $scope.bucketSvc.fetchUserBuckets(true);
607 function() {return $scope.gridControls.selectedItems()},
610 patronSvc.setPrimary(null, list[0]);
615 $scope.need_one_selected = function() {
616 var items = $scope.gridControls.selectedItems();
617 return (items.length > 0) ? false : true;
619 $scope.need_two_selected = function() {
620 var items = $scope.gridControls.selectedItems();
621 return (items.length == 2) ? false : true;
623 $scope.merge_patrons = function() {
624 var items = $scope.gridControls.selectedItems();
625 if (items.length != 2) return false;
628 angular.forEach(items, function(i) {
629 patron_ids.push(i.id());
631 egPatronMerge.do_merge(patron_ids).then(function() {
632 // ensure that we're not drawing from cached
633 // resuts, as a successful merge just deleted a
635 delete patronSvc.lastSearch;
636 $scope.gridControls.refresh();
645 .controller('PatronMessagesCtrl',
646 ['$scope','$q','$routeParams','egCore','$uibModal','patronSvc','egCirc',
647 function($scope , $q , $routeParams, egCore , $uibModal , patronSvc , egCirc) {
648 $scope.initTab('messages', $routeParams.id);
649 var usr_id = $routeParams.id;
651 // setup date filters
652 var start = new Date(); // now - 1 year
653 start.setFullYear(start.getFullYear() - 1),
656 end_date : new Date()
659 function date_range() {
660 var start = $scope.dates.start_date.toISOString().replace(/T.*/,'');
661 var end = $scope.dates.end_date.toISOString().replace(/T.*/,'');
662 var today = new Date().toISOString().replace(/T.*/,'');
663 if (end == today) end = 'now';
669 var activeGrid = $scope.activeGridControls = {
670 setSort : function() {
673 setQuery : function() {
678 {stop_date : {'>' : 'now'}}
684 var archiveGrid = $scope.archiveGridControls = {
685 setSort : function() {
688 setQuery : function() {
691 stop_date : {'<=' : 'now'},
692 set_date : {between : date_range()}
697 $scope.removePenalty = function(selected) {
698 // the grid stores flattened penalties. Fetch penalty objects first
700 var ids = selected.map(function(s){ return s.id });
701 egCore.pcrud.search('ausp',
703 {atomic : true, authoritative : true}
706 ).then(function(penalties) {
707 return egCore.pcrud.remove(penalties);
709 // then refresh the grid
711 activeGrid.refresh();
715 $scope.archivePenalty = function(selected) {
716 // the grid stores flattened penalties. Fetch penalty objects first
718 var ids = selected.map(function(s){ return s.id });
719 egCore.pcrud.search('ausp',
721 {atomic : true, authoritative : true}
724 ).then(function(penalties) {
725 angular.forEach(penalties, function(p){ p.stop_date('now') });
726 return egCore.pcrud.update(penalties);
728 // then refresh the grid
730 activeGrid.refresh();
731 archiveGrid.refresh();
735 // leverage egEnv for caching
736 function fetchPenaltyTypes() {
738 return $q.when(egCore.env.csp.list);
739 return egCore.pcrud.search(
740 // id <= 100 are reserved for system use
741 'csp', {id : {'>': 100}}, {}, {atomic : true})
742 .then(function(penalties) {
743 egCore.env.absorbList(penalties, 'csp');
748 $scope.createPenalty = function() {
749 egCirc.create_penalty(usr_id).then(function() {
750 activeGrid.refresh();
751 // force a refresh of the user, since they may now
752 // have blocking penalties, etc.
753 patronSvc.setPrimary(patronSvc.current.id(), null, true);
757 $scope.editPenalty = function(selected) {
758 if (selected.length == 0) return;
760 // grab the penalty from the user object
761 var penalty = patronSvc.current.standing_penalties().filter(
762 function(p) {return p.id() == selected[0].id})[0];
764 egCirc.edit_penalty(penalty).then(function() {
765 activeGrid.refresh();
766 // force a refresh of the user, since they may now
767 // have blocking penalties, etc.
768 patronSvc.setPrimary(patronSvc.current.id(), null, true);
777 .controller('PatronVerifyCredentialsCtrl',
778 ['$scope','$routeParams','$location','egCore',
779 function($scope, $routeParams , $location , egCore) {
780 $scope.verified = null;
781 $scope.focusMe = true;
783 // called with a patron, pre-populate the form args
784 $scope.initTab('other', $routeParams.id).then(
786 if ($routeParams.id && $scope.patron()) {
787 $scope.prepop = true;
788 $scope.username = $scope.patron().usrname();
789 $scope.barcode = $scope.patron().card().barcode();
791 $scope.username = '';
793 $scope.password = '';
798 // verify login credentials
799 $scope.verify = function() {
800 $scope.verified = null;
801 $scope.notFound = false;
805 'open-ils.actor.verify_user_password',
806 egCore.auth.token(), $scope.barcode,
807 $scope.username, hex_md5($scope.password || '')
809 ).then(function(resp) {
810 $scope.focusMe = true;
811 if (evt = egCore.evt.parse(resp)) {
813 } else if (resp == 1) {
814 $scope.verified = true;
816 $scope.verified = false;
821 // load the main patron UI for the provided username or barcode
822 $scope.load = function($event) {
823 $scope.notFound = false;
824 $scope.verified = null;
828 'open-ils.actor.user.retrieve_id_by_barcode_or_username',
829 egCore.auth.token(), $scope.barcode, $scope.username
831 ).then(function(resp) {
834 $location.path('/circ/patron/' + resp + '/checkout');
838 // something went wrong...
839 $scope.focusMe = true;
840 if (evt = egCore.evt.parse(resp)) {
841 if (evt.textcode == 'ACTOR_USR_NOT_FOUND') {
842 $scope.notFound = true;
851 // load() button sits within the verify form.
852 // avoid submitting the verify() form action on load()
853 $event.preventDefault();
857 .controller('PatronAlertsCtrl',
858 ['$scope','$routeParams','$location','egCore','patronSvc',
859 function($scope, $routeParams , $location , egCore , patronSvc) {
861 $scope.initTab('other', $routeParams.id)
863 $scope.patronExpired = patronSvc.patronExpired;
864 $scope.patronExpiresSoon = patronSvc.patronExpiresSoon;
865 $scope.retrievedWithInactive = patronSvc.fetchedWithInactiveCard();
866 $scope.invalidAddresses = patronSvc.invalidAddresses;
871 .controller('PatronNotesCtrl',
872 ['$scope','$filter','$routeParams','$location','egCore','patronSvc','$uibModal',
874 function($scope, $filter , $routeParams , $location , egCore , patronSvc , $uibModal,
876 $scope.initTab('other', $routeParams.id);
877 var usr_id = $routeParams.id;
880 function refreshPage() {
882 egCore.pcrud.search('aun',
884 {flesh : 1, flesh_fields : {aun : ['creator']}},
885 {authoritative : true})
886 .then(null, null, function(note) {
887 $scope.notes.push(note);
891 // open the new-note dialog and create the note
892 $scope.newNote = function() {
894 templateUrl: './circ/patron/t_new_note_dialog',
897 ['$scope', '$uibModalInstance',
898 function($scope, $uibModalInstance) {
899 $scope.focusNote = true;
901 $scope.require_initials = egCore.env.aous['ui.staff.require_initials.patron_info_notes'];
902 $scope.ok = function(count) { $uibModalInstance.close($scope.args) }
903 $scope.cancel = function () { $uibModalInstance.dismiss() }
907 if (!args.value) return;
908 var note = new egCore.idl.aun();
910 note.title(args.title);
911 note.value(args.value);
912 note.pub(args.pub ? 't' : 'f');
913 note.creator(egCore.auth.user().id());
915 note.value(note.value() + ' [' + args.initials + ']');
916 egCore.pcrud.create(note).then(function() {refreshPage()});
921 // delete the selected note
922 $scope.deleteNote = function(note) {
923 egConfirmDialog.open(
924 egCore.strings.PATRON_NOTE_DELETE_CONFIRM_TITLE, egCore.strings.PATRON_NOTE_DELETE_CONFIRM,
926 egCore.pcrud.remove(note).then(function() {refreshPage()});
928 note_title : note.title(),
929 create_date : note.create_date()
933 // print the selected note
934 $scope.printNote = function(note) {
935 var hash = egCore.idl.toHash(note);
936 hash.usr = egCore.idl.toHash($scope.patron());
939 template : 'patron_note',
940 scope : {note : hash}
944 // perform the initial note fetch
948 .controller('PatronGroupCtrl',
949 ['$scope','$routeParams','$q','$window','$timeout','$location','egCore',
950 'patronSvc','$uibModal','egPromptDialog','egConfirmDialog',
951 function($scope, $routeParams , $q , $window , $timeout, $location , egCore ,
952 patronSvc , $uibModal , egPromptDialog , egConfirmDialog) {
954 var usr_id = $routeParams.id;
956 $scope.totals = {owed : 0, total_out : 0, overdue : 0}
958 var grid = $scope.gridControls = {
959 activateItem : function(item) {
960 $location.path('/circ/patron/' + item.id + '/checkout');
962 itemRetrieved : function(item) {
964 if (item.id == patronSvc.current.id()) {
965 item.stats = patronSvc.patron_stats;
968 // flesh stats for other group members
969 patronSvc.getUserStats(item.id).then(function(stats) {
971 $scope.totals.total_out += stats.checkouts.total_out;
972 $scope.totals.overdue += stats.checkouts.overdue;
976 setSort : function() {
977 return ['create_date'];
981 $scope.initTab('other', $routeParams.id)
982 .then(function(redirect) {
983 // if we are redirecting to the alerts page, avoid updating the
985 if (redirect) return;
986 // let initTab() fetch the user first so we can know the usrgroup
989 usrgroup : patronSvc.current.usrgroup(),
992 $scope.totals.owed = patronSvc.patron_stats.fines.group_balance_owed;
995 $scope.removeFromGroup = function(selected) {
997 angular.forEach(selected, function(user) {
998 console.debug('removing user ' + user.id + ' from group');
1003 'open-ils.actor.usergroup.new',
1004 egCore.auth.token(), user.id, true
1009 $q.all(promises).then(function() {grid.refresh()});
1012 function addUserToGroup(user) {
1013 user.usrgroup(patronSvc.current.usrgroup());
1014 user.ischanged(true);
1017 'open-ils.actor.patron.update',
1018 egCore.auth.token(), user
1020 ).then(function() {grid.refresh()});
1023 // fetch each user ("selected" has flattened users)
1024 // update the usrgroup, then update the user object
1025 // After all updates are complete, refresh the grid.
1026 function moveUsersToGroup(target_user, selected) {
1029 angular.forEach(selected, function(user) {
1031 egCore.pcrud.retrieve('au', user.id)
1033 u.usrgroup(target_user.usrgroup());
1035 return egCore.net.request(
1037 'open-ils.actor.patron.update',
1038 egCore.auth.token(), u
1044 $q.all(promises).then(function() {grid.refresh()});
1047 function showMoveToGroupConfirm(barcode, selected, outbound) {
1050 egCore.pcrud.search('ac', {barcode : barcode})
1052 // fetch the fleshed user
1053 .then(function(card) {
1055 if (!card) return; // TODO: warn user
1057 egCore.pcrud.retrieve('au', card.usr())
1058 .then(function(user) {
1061 templateUrl: './circ/patron/t_move_to_group_dialog',
1064 '$scope','$uibModalInstance',
1065 function($scope , $uibModalInstance) {
1067 $scope.selected = selected;
1068 $scope.outbound = outbound;
1070 function(count) { $uibModalInstance.close() }
1072 function () { $uibModalInstance.dismiss() }
1075 }).result.then(function() {
1077 moveUsersToGroup(user, selected);
1079 addUserToGroup(user);
1086 // selected == move selected patrons to another patron's group
1087 // !selected == patron from a different group moves into our group
1088 function moveToGroup(selected, outbound) {
1089 egPromptDialog.open(
1090 egCore.strings.GROUP_ADD_USER, '',
1091 {ok : function(value) {
1093 showMoveToGroupConfirm(value, selected, outbound);
1098 $scope.moveToGroup = function() { moveToGroup([], false) };
1099 $scope.moveToAnotherGroup = function(selected) { moveToGroup(selected, true) };
1101 $scope.cloneUser = function(selected) {
1102 if (!selected.length) return;
1103 var url = $location.absUrl().replace(
1105 '/patron/register/clone/' + selected[0].id);
1106 $window.open(url, '_blank').focus();
1109 $scope.retrieveSelected = function(selected) {
1110 if (!selected.length) return;
1111 angular.forEach(selected, function(usr) {
1112 $timeout(function() {
1113 var url = $location.absUrl().replace(
1115 '/patron/' + usr.id + '/checkout');
1116 $window.open(url, '_blank')
1123 .controller('PatronStatCatsCtrl',
1124 ['$scope','$routeParams','$q','egCore','patronSvc',
1125 function($scope, $routeParams , $q , egCore , patronSvc) {
1126 $scope.initTab('other', $routeParams.id)
1127 .then(function(redirect) {
1128 // Entries for org-visible stat cats are fleshed. Any others
1129 // have to be fleshed within.
1132 angular.forEach(patronSvc.current.stat_cat_entries(),
1134 if (!angular.isObject(entry.stat_cat())) {
1135 to_flesh[entry.stat_cat()] = entry;
1140 if (!Object.keys(to_flesh).length) return;
1142 egCore.pcrud.search('actsc', {id : Object.keys(to_flesh)})
1143 .then(null, null, function(cat) { // stream
1144 cat.owner(egCore.org.get(cat.owner())); // owner flesh
1145 to_flesh[cat.id()].stat_cat(cat);
1150 .controller('PatronSurveyCtrl',
1151 ['$scope','$routeParams','$location','egCore','patronSvc',
1152 function($scope, $routeParams , $location , egCore , patronSvc) {
1153 $scope.initTab('other', $routeParams.id);
1154 var usr_id = $routeParams.id;
1155 var org_ids = egCore.org.fullPath(egCore.auth.user().ws_ou(), true);
1156 $scope.surveys = [];
1157 // fetch the surveys
1158 egCore.pcrud.search('asvr',
1160 {flesh : 4, flesh_fields : {
1161 asvr : ['question', 'survey', 'answer'],
1162 asv : ['responses', 'questions'],
1163 asvq : ['responses', 'question']
1165 {authoritative : true})
1166 .then(null, null, function(survey) {
1167 var sameSurveyId = false;
1168 if (survey.survey().id() && $scope.surveys.length > 0) {
1169 for (sid = 0; sid < $scope.surveys.length; sid++) {
1170 if (survey.survey().id() == $scope.surveys[sid].id()) sameSurveyId = true;
1173 if (!sameSurveyId) $scope.surveys.push(survey.survey());
1177 .controller('PatronFetchLastCtrl',
1178 ['$scope','$location','egCore',
1179 function($scope , $location , egCore) {
1181 var ids = egCore.hatch.getLoginSessionItem('eg.circ.recent_patrons') || [];
1183 return $location.path('/circ/patron/' + ids[0] + '/checkout');
1185 $scope.no_last = true;
1188 .controller('PatronTriggeredEventsCtrl',
1189 ['$scope','$routeParams','$location','egCore','patronSvc',
1190 function($scope, $routeParams, $location , egCore , patronSvc) {
1191 $scope.initTab('other', $routeParams.id);
1193 var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/event_log');
1194 url += '?patron_id=' + encodeURIComponent($routeParams.id);
1196 $scope.triggered_events_url = url;
1200 .controller('PatronMessageCenterCtrl',
1201 ['$scope','$routeParams','$location','egCore','patronSvc',
1202 function($scope, $routeParams, $location , egCore , patronSvc) {
1203 $scope.initTab('other', $routeParams.id);
1205 var url = $location.protocol() + '://' + $location.host()
1206 + egCore.env.basePath.replace(/\/staff.*/, '/actor/user/message');
1207 url += '/' + encodeURIComponent($routeParams.id);
1209 $scope.message_center_url = url;
1213 .controller('PatronPermsCtrl',
1214 ['$scope','$routeParams','$window','$location','egCore',
1215 function($scope , $routeParams , $window , $location , egCore) {
1216 $scope.initTab('other', $routeParams.id);
1218 var url = $location.absUrl().replace(
1219 /\/eg\/staff.*/, '/xul/server/patron/user_edit.xhtml');
1221 url += '?usr=' + encodeURIComponent($routeParams.id);
1223 // user_edit does not load the session via cookie. It uses URL
1224 // params or xulG instead. Pass via xulG.
1226 ses : egCore.auth.token(),
1227 on_patron_save : function() {
1228 $scope.funcs.reload();
1232 $scope.user_perms_url = url;