2 angular.module('egCoreMod')
3 // toss tihs onto egCoreMod since the page app may vary
5 .factory('patronRegSvc', ['$q', 'egCore', function($q, egCore) {
8 field_doc : {}, // config.idl_field_doc
9 profiles : [], // permission groups
11 user_settings : {}, // applied user settings
12 user_setting_types : {}, // config.usr_setting_type
13 opt_in_setting_types : {}, // config.usr_setting_type for event-def opt-in
14 survey_questions : {},
16 survey_responses : {}, // survey.responses for loaded patron in progress
17 stat_cat_entry_maps : {}, // cat.id to selected entry object map
18 virt_id : -1 // virtual ID for new objects
21 // launch a series of parallel data retrieval calls
22 service.init = function(scope) {
24 service.get_field_doc(),
25 service.get_perm_groups(),
26 service.get_ident_types(),
27 service.get_user_settings(),
28 service.get_org_settings(),
29 service.get_stat_cats(),
30 service.get_surveys(),
31 service.get_net_access_levels()
35 service.get_surveys = function() {
36 var org_ids = egCore.org.fullPath(egCore.auth.user().ws_ou(), true);
38 return egCore.pcrud.search('asv', {
40 start_date : {'<=' : 'now'},
41 end_date : {'>=' : 'now'}
50 ).then(function(surveys) {
51 surveys = surveys.sort(function(a,b) {
52 return a.name() < b.name() ? -1 : 1 });
53 service.surveys = surveys;
54 angular.forEach(surveys, function(survey) {
55 angular.forEach(survey.questions(), function(question) {
56 service.survey_questions[question.id()] = question;
57 angular.forEach(question.answers(), function(answer) {
58 service.survey_answers[answer.id()] = answer;
65 service.get_stat_cats = function() {
66 return egCore.net.request(
68 'open-ils.circ.stat_cat.actor.retrieve.all',
69 egCore.auth.token(), egCore.auth.user().ws_ou()
70 ).then(function(cats) {
71 cats = cats.sort(function(a, b) {
72 return a.name() < b.name() ? -1 : 1});
73 angular.forEach(cats, function(cat) {
75 cat.entries().sort(function(a,b) {
76 return a.value() < b.value() ? -1 : 1
80 service.stat_cats = cats;
84 service.get_org_settings = function() {
85 return egCore.org.settings([
86 'global.password_regex',
87 'global.juvenile_age_threshold',
88 'patron.password.use_phone',
89 'ui.patron.default_inet_access_level',
90 'ui.patron.default_ident_type',
91 'ui.patron.default_country',
92 'ui.patron.registration.require_address',
93 'circ.holds.behind_desk_pickup_supported',
94 'circ.patron_edit.clone.copy_address',
95 'ui.patron.edit.au.prefix.require',
96 'ui.patron.edit.au.prefix.show',
97 'ui.patron.edit.au.prefix.suggest',
98 'ui.patron.edit.ac.barcode.regex',
99 'ui.patron.edit.au.second_given_name.show',
100 'ui.patron.edit.au.second_given_name.suggest',
101 'ui.patron.edit.au.suffix.show',
102 'ui.patron.edit.au.suffix.suggest',
103 'ui.patron.edit.au.alias.show',
104 'ui.patron.edit.au.alias.suggest',
105 'ui.patron.edit.au.dob.require',
106 'ui.patron.edit.au.dob.show',
107 'ui.patron.edit.au.dob.suggest',
108 'ui.patron.edit.au.dob.calendar',
109 'ui.patron.edit.au.juvenile.show',
110 'ui.patron.edit.au.juvenile.suggest',
111 'ui.patron.edit.au.ident_value.show',
112 'ui.patron.edit.au.ident_value.suggest',
113 'ui.patron.edit.au.ident_value2.show',
114 'ui.patron.edit.au.ident_value2.suggest',
115 'ui.patron.edit.au.email.require',
116 'ui.patron.edit.au.email.show',
117 'ui.patron.edit.au.email.suggest',
118 'ui.patron.edit.au.email.regex',
119 'ui.patron.edit.au.email.example',
120 'ui.patron.edit.au.day_phone.require',
121 'ui.patron.edit.au.day_phone.show',
122 'ui.patron.edit.au.day_phone.suggest',
123 'ui.patron.edit.au.day_phone.regex',
124 'ui.patron.edit.au.day_phone.example',
125 'ui.patron.edit.au.evening_phone.require',
126 'ui.patron.edit.au.evening_phone.show',
127 'ui.patron.edit.au.evening_phone.suggest',
128 'ui.patron.edit.au.evening_phone.regex',
129 'ui.patron.edit.au.evening_phone.example',
130 'ui.patron.edit.au.other_phone.require',
131 'ui.patron.edit.au.other_phone.show',
132 'ui.patron.edit.au.other_phone.suggest',
133 'ui.patron.edit.au.other_phone.regex',
134 'ui.patron.edit.au.other_phone.example',
135 'ui.patron.edit.phone.regex',
136 'ui.patron.edit.phone.example',
137 'ui.patron.edit.au.active.show',
138 'ui.patron.edit.au.active.suggest',
139 'ui.patron.edit.au.barred.show',
140 'ui.patron.edit.au.barred.suggest',
141 'ui.patron.edit.au.master_account.show',
142 'ui.patron.edit.au.master_account.suggest',
143 'ui.patron.edit.au.claims_returned_count.show',
144 'ui.patron.edit.au.claims_returned_count.suggest',
145 'ui.patron.edit.au.claims_never_checked_out_count.show',
146 'ui.patron.edit.au.claims_never_checked_out_count.suggest',
147 'ui.patron.edit.au.alert_message.show',
148 'ui.patron.edit.au.alert_message.suggest',
149 'ui.patron.edit.aua.post_code.regex',
150 'ui.patron.edit.aua.post_code.example',
151 'ui.patron.edit.aua.county.require',
153 'ui.patron.edit.default_suggested',
154 'opac.barcode_regex',
155 'opac.username_regex',
157 'ui.patron.edit.aua.state.require',
158 'ui.patron.edit.aua.state.suggest',
159 'ui.patron.edit.aua.state.show'
160 ]).then(function(settings) {
161 service.org_settings = settings;
162 return service.process_org_settings(settings);
166 // some org settings require the retrieval of additional data
167 service.process_org_settings = function(settings) {
171 if (settings['sms.enable']) {
172 // fetch SMS carriers
174 egCore.pcrud.search('csc',
177 {'class':'csc', 'field':'name'},
178 {'class':'csc', 'field':'region'}
180 ).then(function(carriers) {
181 service.sms_carriers = carriers;
185 // if other promises are added below, this is not necessary.
186 promises.push($q.when());
189 // other post-org-settings processing goes here,
190 // adding to promises as needed.
192 return $q.all(promises);
195 service.get_ident_types = function() {
196 if (egCore.env.cit) {
197 service.ident_types = egCore.env.cit.list;
200 return egCore.pcrud.retrieveAll('cit', {}, {atomic : true})
201 .then(function(types) {
202 egCore.env.absorbList(types, 'cit')
203 service.ident_types = types
208 service.get_net_access_levels = function() {
209 if (egCore.env.cnal) {
210 service.net_access_levels = egCore.env.cnal.list;
213 return egCore.pcrud.retrieveAll('cnal', {}, {atomic : true})
214 .then(function(levels) {
215 egCore.env.absorbList(levels, 'cnal')
216 service.net_access_levels = levels
221 service.get_perm_groups = function() {
222 if (egCore.env.pgt) {
223 service.profiles = egCore.env.pgt.list;
226 return egCore.pcrud.search('pgt', {parent : null},
227 {flesh : -1, flesh_fields : {pgt : ['children']}}
230 egCore.env.absorbTree(tree, 'pgt')
231 service.profiles = egCore.env.pgt.list;
237 service.get_field_doc = function() {
239 return egCore.pcrud.search('fdoc', {
240 fm_class: ['au', 'ac', 'aua', 'actsc', 'asv', 'asvq', 'asva']})
241 .then(null, null, function(doc) {
242 if (!service.field_doc[doc.fm_class()]) {
243 service.field_doc[doc.fm_class()] = {};
245 service.field_doc[doc.fm_class()][doc.field()] = doc;
249 service.get_user_settings = function() {
250 var org_ids = egCore.org.ancestors(egCore.auth.user().ws_ou(), true);
253 'circ.holds_behind_desk',
254 'circ.collections.exempt',
256 'opac.default_phone',
257 'opac.default_pickup_location',
258 'opac.default_sms_carrier',
259 'opac.default_sms_notify'];
261 return egCore.pcrud.search('cust', {
263 {name : static_types}, // common user settings
264 {name : { // opt-in notification user settings
266 select : {atevdef : ['opt_in_setting']},
268 // we only care about opt-in settings for
269 // event_defs our users encounter
270 where : {'+atevdef' : {owner : org_ids}}
274 }, {}, {atomic : true}).then(function(setting_types) {
276 angular.forEach(setting_types, function(stype) {
277 service.user_setting_types[stype.name()] = stype;
278 if (static_types.indexOf(stype.name()) == -1) {
279 service.opt_in_setting_types[stype.name()] = stype;
283 if (service.patron_id) {
284 // retrieve applied values for the current user
285 // for the setting types we care about.
288 setting_types.map(function(obj) { return obj.name() });
290 return egCore.net.request(
292 'open-ils.actor.patron.settings.retrieve.authoritative',
296 ).then(function(settings) {
297 service.user_settings = settings;
301 // apply default user setting values
302 angular.forEach(setting_types, function(stype, index) {
303 if (stype.reg_default() != undefined) {
304 service.user_settings[setting.name()] =
305 setting.reg_default();
312 service.init_patron = function(current) {
315 return service.init_new_patron();
317 service.patron = current;
318 return service.init_existing_patron(current)
321 service.ingest_address = function(patron, addr) {
322 addr.valid = addr.valid == 't';
323 addr.within_city_limits = addr.within_city_limits == 't';
324 addr._is_mailing = (patron.mailing_address &&
325 addr.id == patron.mailing_address.id);
326 addr._is_billing = (patron.billing_address &&
327 addr.id == patron.billing_address.id);
331 * Existing patron objects reqire some data munging before insertion
334 * 1. Turn everything into a hash
335 * 2. ... Except certain fields (selectors) whose widgets require objects
336 * 3. Bools must be Boolean, not t/f.
338 service.init_existing_patron = function(current) {
340 var patron = egCore.idl.toHash(current);
342 patron.home_ou = egCore.org.get(patron.home_ou.id);
343 patron.expire_date = new Date(Date.parse(patron.expire_date));
344 patron.dob = new Date(Date.parse(patron.dob));
345 patron.profile = current.profile(); // pre-hash version
346 patron.net_access_level = current.net_access_level();
347 patron.ident_type = current.ident_type();
350 ['juvenile', 'barred', 'active', 'master_account'],
351 function(field) { patron[field] = patron[field] == 't'; }
354 angular.forEach(patron.cards, function(card) {
355 card.active = card.active == 't';
356 if (card.id == patron.card.id) {
358 card._primary = 'on';
362 angular.forEach(patron.addresses,
363 function(addr) { service.ingest_address(patron, addr) });
365 // toss entries for existing stat cat maps into our living
366 // stat cat entry map, which is modified within the template.
367 angular.forEach(patron.stat_cat_entries, function(map) {
369 angular.forEach(service.stat_cats, function(cat) {
370 angular.forEach(cat.entries(), function(ent) {
371 if (ent.id() == map.stat_cat_entry)
375 service.stat_cat_entry_maps[map.stat_cat.id] = entry;
381 service.init_new_patron = function() {
383 id : service.virt_id--,
386 address_type : egCore.strings.REG_ADDR_TYPE,
389 within_city_limits : false,
390 stat_cat_entries : []
394 id : service.virt_id--,
405 home_ou : egCore.org.get(egCore.auth.user().ws_ou()),
407 // TODO default profile group?
412 // translate the patron back into IDL form
413 service.save_user = function(phash) {
415 var patron = egCore.idl.fromHash('au', phash);
417 patron.home_ou(patron.home_ou().id());
419 patron.expire_date().toISOString().replace(/T.*/,''));
420 patron.profile(patron.profile().id());
422 patron.dob(patron.dob().toISOString().replace(/T.*/,''));
423 if (patron.ident_type())
424 patron.ident_type(patron.ident_type().id());
425 if (patron.net_access_level())
426 patron.net_access_level(patron.net_access_level().id());
429 ['juvenile', 'barred', 'active', 'master_account'],
430 function(field) { patron[field](phash[field] ? 't' : 'f'); }
433 var card_hashes = patron.cards();
435 angular.forEach(card_hashes, function(chash) {
436 var card = egCore.idl.fromHash('ac', chash)
437 card.usr(patron.id());
438 card.active(chash.active ? 't' : 'f');
439 patron.cards().push(card);
440 if (chash._primary) {
445 var addr_hashes = patron.addresses();
446 patron.addresses([]);
447 angular.forEach(addr_hashes, function(addr_hash) {
448 if (!addr_hash.isnew && !addr_hash.isdeleted)
449 addr_hash.ischanged = true;
450 var addr = egCore.idl.fromHash('aua', addr_hash);
451 patron.addresses().push(addr);
452 addr.valid(addr.valid() ? 't' : 'f');
453 addr.within_city_limits(addr.within_city_limits() ? 't' : 'f');
454 if (addr_hash._is_mailing) patron.mailing_address(addr);
455 if (addr_hash._is_billing) patron.billing_address(addr);
458 patron.survey_responses([]);
459 angular.forEach(service.survey_responses, function(answer) {
460 var question = service.survey_questions[answer.question()];
461 var resp = new egCore.idl.asvr();
463 resp.survey(question.survey());
464 resp.question(question.id());
465 resp.answer(answer.id());
466 resp.usr(patron.id());
467 resp.answer_date('now');
468 patron.survey_responses().push(resp);
471 // re-object-ify the patron stat cat entry maps
473 angular.forEach(patron.stat_cat_entries(), function(entry) {
474 var e = egCore.idl.fromHash('actscecm', entry);
475 e.stat_cat(e.stat_cat().id);
478 patron.stat_cat_entries(maps);
480 // service.stat_cat_entry_maps maps stats to entries
481 // patron.stat_cat_entries is an array of stat_cat_entry_usr_map's
482 angular.forEach(service.stat_cat_entry_maps, function(entry) {
484 // see if we already have a mapping for this entry
485 var existing = patron.stat_cat_entries().filter(function(e) {
486 return e.stat_cat() == entry.stat_cat();
489 if (existing) { // we have a mapping
490 // if the existing mapping matches the new one,
491 // there' nothing left to do
492 if (existing.stat_cat_entry() == entry.id()) return;
494 // mappings differ. delete the old one and create
496 existing.isdeleted(true);
499 var newmap = new egCore.idl.actscecm();
500 newmap.target_usr(patron.id());
502 newmap.stat_cat(entry.stat_cat());
503 newmap.stat_cat_entry(entry.id());
504 patron.stat_cat_entries().push(newmap);
507 angular.forEach(patron.stat_cat_entries(), function(entry) {
508 console.log(egCore.idl.toString(entry));
511 if (!patron.isnew()) patron.ischanged(true);
513 return egCore.net.request(
515 'open-ils.actor.patron.update',
516 egCore.auth.token(), patron);
519 service.save_user_settings = function(new_user, user_settings) {
520 // user_settings contains the values from the scope/form.
521 // service.user_settings contain the values from page load time.
524 if (service.patron_id) {
525 // only update modified settings for existing patrons
526 angular.forEach(user_settings, function(val, key) {
527 if (val !== service.user_settings[key])
532 // all non-null setting values are updated for new patrons
533 angular.forEach(user_settings, function(val, key) {
534 if (val !== null) settings[key] = val;
538 if (Object.keys(settings).length == 0) return $q.when();
540 return egCore.net.request(
542 'open-ils.actor.patron.settings.update',
543 egCore.auth.token(), new_user.id(), settings
544 ).then(function(resp) {
545 console.log('settings returned ' + resp);
554 function PatronRegCtrl($scope, $routeParams,
555 $q, $modal, $window, egCore, patronSvc, patronRegSvc) {
557 $scope.page_data_loaded = false;
558 $scope.clone_id = $routeParams.clone_id;
559 $scope.stage_username = $routeParams.stage_username;
561 patronRegSvc.patron_id = $routeParams.edit_id || $routeParams.id;
563 // for existing patrons, disable barcode input by default
564 $scope.disable_bc = $scope.focus_usrname = Boolean($scope.patron_id);
565 $scope.focus_bc = !Boolean($scope.patron_id);
567 if (!$scope.edit_passthru) {
568 // in edit more, scope.edit_passthru is delivered to us by
569 // the enclosing controller. In register mode, there is
570 // no enclosing controller, so we create our own.
571 $scope.edit_passthru = {};
574 // 0=all, 1=suggested, 2=all
575 $scope.edit_passthru.vis_level = 0;
576 // TODO: add save/clone handlers here
578 // Apply default values for new patrons during initial registration
579 // prs is shorthand for patronSvc
580 function set_new_patron_defaults(prs) {
581 $scope.generate_password();
582 $scope.hold_notify_phone = true;
583 $scope.hold_notify_email = true;
585 if (prs.org_settings['ui.patron.default_ident_type']) {
586 // $scope.patron needs this field to be an object
587 var id = prs.org_settings['ui.patron.default_ident_type'];
588 var ident_type = $scope.ident_types.filter(
589 function(type) { return type.id() == id })[0];
590 $scope.patron.ident_type = ident_type;
592 if (prs.org_settings['ui.patron.default_inet_access_level']) {
593 // $scope.patron needs this field to be an object
594 var id = prs.org_settings['ui.patron.default_inet_access_level'];
595 var level = $scope.net_access_levels.filter(
596 function(lvl) { return lvl.id() == id })[0];
597 $scope.patron.net_access_level = level;
599 if (prs.org_settings['ui.patron.default_country']) {
600 $scope.patron.addresses[0].country =
601 prs.org_settings['ui.patron.default_country'];
607 $scope.initTab ? // initTab comes from patron app
608 $scope.initTab('edit', $routeParams.id) : $q.when(),
613 // called after initTab and patronRegSvc.init have completed
615 var prs = patronRegSvc; // brevity
616 // in standalone mode, we have no patronSvc
617 $scope.patron = prs.init_patron(patronSvc ? patronSvc.current : null);
618 $scope.field_doc = prs.field_doc;
619 $scope.profiles = prs.profiles;
620 $scope.ident_types = prs.ident_types;
621 $scope.net_access_levels = prs.net_access_levels;
622 $scope.user_setting_types = prs.user_setting_types;
623 $scope.opt_in_setting_types = prs.opt_in_setting_types;
624 $scope.org_settings = prs.org_settings;
625 $scope.sms_carriers = prs.sms_carriers;
626 $scope.stat_cats = prs.stat_cats;
627 $scope.surveys = prs.surveys;
628 $scope.survey_responses = prs.survey_responses;
629 $scope.stat_cat_entry_maps = prs.stat_cat_entry_maps;
631 $scope.user_settings = prs.user_settings;
632 // clone the user settings back into the patronRegSvc so
633 // we have a copy of the original state of the settings.
634 prs.user_settings = {};
635 angular.forEach($scope.user_settings, function(val, key) {
636 prs.user_settings[key] = val;
639 extract_hold_notify();
641 if ($scope.org_settings['ui.patron.edit.default_suggested'])
642 $scope.edit_passthru.vis_level = 1;
644 if ($scope.patron.isnew)
645 set_new_patron_defaults(prs);
647 $scope.page_data_loaded = true;
648 console.log('here with ' + $scope.page_data_loaded);
651 // update the currently displayed field documentation
652 $scope.set_selected_field_doc = function(cls, field) {
653 $scope.selected_field_doc = $scope.field_doc[cls][field];
656 // returns the tree depth of the selected profile group tree node.
657 $scope.pgt_depth = function(grp) {
659 while (grp = egCore.env.pgt.map[grp.parent()]) d++;
663 // IDL fields used for labels in the UI.
664 $scope.idl_fields = {
665 au : egCore.idl.classes.au.field_map,
666 ac : egCore.idl.classes.ac.field_map,
667 aua : egCore.idl.classes.aua.field_map
670 // field visibility cache. Some fields are universally required.
671 var field_visibility = {
676 'au.first_given_name' : 2,
677 'au.family_name' : 2,
681 'au.expire_date' : 2,
682 'au.net_access_level' : 2,
683 'aua.address_type' : 2,
692 'aua.within_city_limits' : 2,
697 // returns true if the selected field should be visible
698 // given the current required/suggested/all setting.
699 $scope.show_field = function(field_key) {
701 if (field_visibility[field_key] == undefined) {
702 // compile and cache the visibility for the selected field
704 // org settings have not been received yet.
705 if (!$scope.org_settings) return false;
707 var req_set = 'ui.patron.edit.' + field_key + '.require';
708 var sho_set = 'ui.patron.edit.' + field_key + '.show';
709 var sug_set = 'ui.patron.edit.' + field_key + '.suggest';
711 if ($scope.org_settings[req_set]) {
712 field_visibility[field_key] = 2;
713 } else if ($scope.org_settings[sho_set]) {
714 field_visibility[field_key] = 2;
715 } else if ($scope.org_settings[sug_set]) {
716 field_visibility[field_key] = 1;
718 field_visibility[field_key] = 0;
722 return field_visibility[field_key] >= $scope.edit_passthru.vis_level;
725 // generates a random 4-digit password
726 $scope.generate_password = function() {
727 $scope.patron.passwd = Math.floor(Math.random()*9000) + 1000;
730 $scope.set_expire_date = function() {
731 if (!$scope.patron.profile) return;
732 var seconds = egCore.date.intervalToSeconds(
733 $scope.patron.profile.perm_interval());
734 var now_epoch = new Date().getTime();
735 $scope.patron.expire_date = new Date(
736 now_epoch + (seconds * 1000 /* milliseconds */))
739 // grp is the pgt object
740 $scope.set_profile = function(grp) {
741 $scope.patron.profile = grp;
742 $scope.set_expire_date();
745 $scope.new_address = function() {
746 var addr = egCore.idl.toHash(new egCore.idl.aua());
747 patronRegSvc.ingest_address($scope.patron, addr);
748 addr.id = patronRegSvc.virt_id--;
751 addr.within_city_limits = true;
752 $scope.patron.addresses.push(addr);
755 // keep deleted addresses out of the patron object so
756 // they won't appear in the UI. They'll be re-inserted
757 // when the patron is updated.
758 deleted_addresses = [];
759 $scope.delete_address = function(id) {
761 angular.forEach($scope.patron.addresses, function(addr) {
764 addr.isdeleted = true;
765 deleted_addresses.push(addr);
768 addresses.push(addr);
771 $scope.patron.addresses = addresses;
774 $scope.post_code_changed = function(addr) {
776 'open-ils.search', 'open-ils.search.zip', addr.post_code)
777 .then(function(resp) {
779 if (resp.city) addr.city = resp.city;
780 if (resp.state) addr.state = resp.state;
781 if (resp.county) addr.county = resp.county;
782 if (resp.alert) alert(resp.alert);
786 $scope.replace_card = function() {
787 $scope.patron.card.active = false;
788 $scope.patron.card.ischanged = true;
789 $scope.disable_bc = false;
791 var new_card = egCore.idl.toHash(new egCore.idl.ac());
792 new_card.id = patronRegSvc.virt_id--;
793 new_card.isnew = true;
794 new_card.active = true;
795 new_card._primary = 'on';
796 $scope.patron.card = new_card;
797 $scope.patron.cards.push(new_card);
800 $scope.day_phone_changed = function(phone) {
801 if (phone && $scope.org_settings['patron.password.use_phone']) {
802 $scope.patron.passwd = phone.substr(-4);
806 $scope.barcode_changed = function(bc) {
810 'open-ils.actor.barcode.exists',
811 egCore.auth.token(), bc
812 ).then(function(resp) {
814 console.log('duplicate barcode detected: ' + bc);
817 if (!$scope.patron.usrname)
818 $scope.patron.usrname = bc;
824 $scope.cards_dialog = function() {
826 templateUrl: './circ/patron/t_patron_cards_dialog',
828 ['$scope','$modalInstance','cards',
829 function($scope , $modalInstance , cards) {
830 // scope here is the modal-level scope
831 $scope.args = {cards : cards};
832 $scope.ok = function() { $modalInstance.close($scope.args) }
833 $scope.cancel = function () { $modalInstance.dismiss() }
837 // scope here is the controller-level scope
838 return $scope.patron.cards;
843 angular.forEach(args.cards, function(card) {
844 card.ischanged = true; // assume cards need updating, OK?
845 if (card._primary == 'on' &&
846 card.id != $scope.patron.card.id) {
847 $scope.patron.card = card;
854 $scope.set_addr_type = function(addr, type) {
855 var addrs = $scope.patron.addresses;
856 if (addr['_is_'+type]) {
857 angular.forEach(addrs, function(a) {
858 if (a.id != addr.id) a['_is_'+type] = false;
861 // unchecking mailing/billing means we have to randomly
862 // select another address to fill that role. Select the
863 // first address in the list (that does not match the
865 for (var i = 0; i < addrs.length; i++) {
866 if (addrs[i].id != addr.id) {
867 addrs[i]['_is_' + type] = true;
875 // Translate hold notify preferences from the form/scope back into a
876 // single user setting value for opac.hold_notify.
877 function compress_hold_notify() {
878 var hold_notify = '';
880 if ($scope.hold_notify_phone) {
881 hold_notify = 'phone';
884 if ($scope.hold_notify_email) {
885 hold_notify = splitter + 'email';
888 if ($scope.hold_notify_sms) {
889 hold_notify = splitter + 'sms';
892 $scope.user_settings['opac.hold_notify'] = hold_notify;
895 function extract_hold_notify() {
896 notify = $scope.user_settings['opac.hold_notify'];
898 $scope.hold_notify_phone = Boolean(notify.match(/phone/));
899 $scope.hold_notify_email = Boolean(notify.match(/email/));
900 $scope.hold_notify_sms = Boolean(notify.match(/sms/));
903 $scope.edit_passthru.save = function() {
905 // toss the deleted addresses back into the patron's list of
906 // addresses so it's included in the update
907 $scope.patron.addresses =
908 $scope.patron.addresses.concat(deleted_addresses);
910 compress_hold_notify();
912 patronRegSvc.save_user($scope.patron)
913 .then(function(new_user) {
914 if (new_user && new_user.classname) {
915 return patronRegSvc.save_user_settings(
916 new_user, $scope.user_settings);
918 alert('Patron update failed. \n\n' + js2JSON(new_user));
919 return true; // ensure page reloads to reset
921 }).then(function(keep_going) {
922 // reloading the page means potentially losing some information
923 // (e.g. last patron search), but is the only way to ensure all
924 // components are properly updated to reflect the modified patron.
925 $window.location.href = location.href;
930 // This controller may be loaded from different modules (patron edit vs.
931 // register new patron), so we have to inject the controller params manually.
932 PatronRegCtrl.$inject = ['$scope', '$routeParams', '$q', '$modal',
933 '$window', 'egCore', 'patronSvc', 'patronRegSvc'];