From 15039eb6c71e8edbcc84662eefed18be6d7afde1 Mon Sep 17 00:00:00 2001 From: Thomas Berezansky Date: Wed, 25 Jan 2012 21:22:56 -0500 Subject: [PATCH] TPac: Add Default Hold Pickup Location And add it (plus other user settings) to the patron editor. And fix a bug where notice prefs were saving without POST. Signed-off-by: Thomas Berezansky Signed-off-by: Ben Shum --- .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 13 +++ Open-ILS/src/sql/Pg/950.data.seed-values.sql | 3 + .../sql/Pg/upgrade/XXXX.hold_default_pickup.sql | 2 + .../src/templates/opac/myopac/prefs_settings.tt2 | 12 +++ Open-ILS/web/js/dojo/openils/actor/nls/register.js | 5 +- Open-ILS/web/js/ui/default/actor/user/register.js | 108 +++++++++++++++++++-- 6 files changed, 133 insertions(+), 10 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.hold_default_pickup.sql diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm index 72f460195d..261aefe3f5 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -176,12 +176,19 @@ sub load_myopac_prefs_notify { my $self = shift; my $e = $self->editor; + + my $stat = $self->_load_user_with_prefs; + return $stat if $stat; + my $user_prefs = $self->fetch_optin_prefs; $user_prefs = $self->update_optin_prefs($user_prefs) if $self->cgi->request_method eq 'POST'; $self->ctx->{opt_in_settings} = $user_prefs; + return Apache2::Const::OK + unless $self->cgi->request_method eq 'POST'; + my %settings; my $set_map = $self->ctx->{user_setting_map}; @@ -343,6 +350,7 @@ sub load_myopac_prefs_settings { my @user_prefs = qw/ opac.hits_per_page opac.default_search_location + opac.default_pickup_location /; my $stat = $self->_load_user_with_prefs; @@ -646,6 +654,11 @@ sub load_place_hold { $ctx->{default_sms_notify} = ''; } + # If we have a default pickup location, grab it + if ($$user_setting_map{'opac.default_pickup_location'}) { + $ctx->{default_pickup_lib} = $$user_setting_map{'opac.default_pickup_location'}; + } + my $request_lib = $e->requestor->ws_ou; my @hold_data; $ctx->{hold_data} = \@hold_data; diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index bd9fc24c7a..ccacf9f77c 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -2437,6 +2437,9 @@ INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatyp INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype) VALUES ('circ.holds_behind_desk', FALSE, 'Hold is behind Circ Desk', 'Hold is behind Circ Desk', 'bool'); +INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype) + VALUES ('opac.default_pickup_location', TRUE, 'Default Hold Pickup Location', 'Default location for holds pickup', 'integer'); + -- Add groups for org_unitu settings INSERT INTO config.settings_group (name, label) VALUES ('sys', oils_i18n_gettext('config.settings_group.system', 'System', 'coust', 'label')), diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.hold_default_pickup.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.hold_default_pickup.sql new file mode 100644 index 0000000000..67200e8bc0 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.hold_default_pickup.sql @@ -0,0 +1,2 @@ +INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype) + VALUES ('opac.default_pickup_location', TRUE, 'Default Hold Pickup Location', 'Default location for holds pickup', 'integer'); diff --git a/Open-ILS/src/templates/opac/myopac/prefs_settings.tt2 b/Open-ILS/src/templates/opac/myopac/prefs_settings.tt2 index 8e301d581c..4ee61903cf 100644 --- a/Open-ILS/src/templates/opac/myopac/prefs_settings.tt2 +++ b/Open-ILS/src/templates/opac/myopac/prefs_settings.tt2 @@ -50,6 +50,18 @@ + [% l("Preferred pickup location") %] + + [%- setting = 'opac.default_pickup_location'; + thang = ctx.user.home_ou.id; + IF ctx.user_setting_map.$setting; + thang = ctx.user_setting_map.$setting; + END; + INCLUDE build_org_selector name=setting value=thang can_have_vols_only=1; + %] + + + [% l('Keep history of checked out items?') %] [% setting = 'history.circ.retention_start' %] diff --git a/Open-ILS/web/js/dojo/openils/actor/nls/register.js b/Open-ILS/web/js/dojo/openils/actor/nls/register.js index f6d6587f23..ae635376cb 100644 --- a/Open-ILS/web/js/dojo/openils/actor/nls/register.js +++ b/Open-ILS/web/js/dojo/openils/actor/nls/register.js @@ -36,5 +36,8 @@ "ALL_CARDS_PRIMARY" : "Primary", "ALL_CARDS_CLOSE" : "Close", "ALL_CARDS_APPLY" : "Apply Changes", - "INVALIDATE": "Invalidate" + "INVALIDATE": "Invalidate", + "HOLD_NOTIFY_PHONE": "Phone: ", + "HOLD_NOTIFY_EMAIL": "Email: ", + "HOLD_NOTIFY_SMS": "SMS: " } diff --git a/Open-ILS/web/js/ui/default/actor/user/register.js b/Open-ILS/web/js/ui/default/actor/user/register.js index d56622c00b..1ed56a437c 100644 --- a/Open-ILS/web/js/ui/default/actor/user/register.js +++ b/Open-ILS/web/js/ui/default/actor/user/register.js @@ -5,6 +5,7 @@ dojo.require('dijit.form.FilteringSelect'); dojo.require('dijit.form.ComboBox'); dojo.require('dijit.form.NumberSpinner'); dojo.require('fieldmapper.IDL'); +dojo.require('fieldmapper.OrgUtils'); dojo.require('openils.PermaCrud'); dojo.require('openils.widget.AutoGrid'); dojo.require('openils.widget.AutoFieldWidget'); @@ -47,6 +48,7 @@ var optInSettings; var allCardsTemplate; var uEditCloneCopyAddr; // if true, copy addrs on clone instead of link var homeOuTypes = {}; +var holdPickupTypes = {}; var cardPerms = {}; var editCard; var prevBillingAddress; @@ -186,7 +188,8 @@ function load() { 'format.date', 'ui.patron.edit.default_suggested', 'opac.barcode_regex', - 'opac.username_regex' + 'opac.username_regex', + 'sms.enable' ]); for(k in orgSettings) @@ -223,6 +226,11 @@ function load() { var type = list[i]; homeOuTypes[type.id()] = true; } + list = pcrud.search('aout', {can_have_vols: 'true'}); + for(var i in list) { + var type = list[i]; + holdPickupTypes[type.id()] = true; + } tbody = dojo.byId('uedit-tbody'); @@ -630,7 +638,7 @@ function uEditFetchUserSettings(userId) { /* fetch any user setting types we need + any that offer opt-in */ userSettingTypes = pcrud.search('cust', { '-or' : [ - {name:['circ.holds_behind_desk', 'circ.collections.exempt']}, + {name:['circ.holds_behind_desk', 'circ.collections.exempt', 'opac.hold_notify', 'opac.default_phone', 'opac.default_pickup_location', 'opac.default_sms_carrier', 'opac.default_sms_notify']}, {name : { 'in': { select : {atevdef : ['opt_in_setting']}, @@ -688,15 +696,97 @@ function uEditDrawSettingRow(tbody, dividerRow, template, stype) { var row = template.cloneNode(true); row.setAttribute('user_setting', stype.name()); getByName(row, 'label').innerHTML = stype.label(); - var cb = new dijit.form.CheckBox({scrollOnFocus:false}, getByName(row, 'widget')); - cb.attr('value', userSettings[stype.name()]); - dojo.connect(cb, 'onChange', function(newVal) { userSettingsToUpdate[stype.name()] = newVal; }); - tbody.insertBefore(row, dividerRow.nextSibling); - openils.Util.show(row, 'table-row'); + switch(stype.name()) { + case 'opac.hold_notify': + var template = localeStrings.HOLD_NOTIFY_PHONE + ' ' + + localeStrings.HOLD_NOTIFY_EMAIL + ''; + if(orgSettings['sms.enable']) { + template += ' ' + localeStrings.HOLD_NOTIFY_SMS + ''; + } + getByName(row, 'widget').innerHTML = template; + var setting = userSettings['opac.hold_notify']; + if(setting == null) setting = 'phone:email'; + var cb_phone = new dijit.form.CheckBox({scrollOnFocus:false}, getByName(row, 'hold_phone')); + cb_phone.attr('value', setting.indexOf('phone') != -1); + var cb_email = new dijit.form.CheckBox({scrollOnFocus:false}, getByName(row, 'hold_email')); + cb_email.attr('value', setting.indexOf('email') != -1); + var cb_sms = null; + if(orgSettings['sms.enable']) { + cb_sms = new dijit.form.CheckBox({scrollOnFocus:false}, getByName(row, 'hold_sms')); + cb_sms.attr('value', setting.indexOf('sms') != -1); + } + var func = function() { + var newVal = ''; + var splitter = ''; + if(cb_phone.checked) { + newVal+= splitter + 'phone'; + splitter = ':'; + } + if(cb_email.checked) { + newVal+= splitter + 'email'; + splitter = ':'; + } + if(orgSettings['sms.enable'] && cb_sms.checked) { + newVal+= splitter + 'sms'; + splitter = ':'; + } + userSettingsToUpdate['opac.hold_notify'] = newVal; + }; + dojo.connect(cb_phone, 'onChange', func); + dojo.connect(cb_email, 'onChange', func); + if(cb_sms) dojo.connect(cb_sms, 'onChange', func); + break; + case 'opac.default_pickup_location': + var sb = new openils.widget.FilteringTreeSelect({ + scrollOnFocus: false, + labelAttr: 'name', + searchAttr: 'name', + parentField: 'parent_ou', + }, getByName(row, 'widget')); + sb.tree = fieldmapper.aou.globalOrgTree; + sb.startup(); + sb.attr('value', userSettings[stype.name()]); + + sb.isValid = function() { + if(this.item) { + if(holdPickupTypes[this.store.getValue(this.item, 'ou_type')]) { + return true; + } + return false; + } + return true; + }; - if(stype.name() == 'circ.collections.exempt') { - checkCollectionsExemptPerm(cb); + dojo.connect(sb, 'onChange', function(newVal) { userSettingsToUpdate[stype.name()] = newVal; }); + break; + case 'opac.default_sms_carrier': + if(!orgSettings['sms.enable']) return; // Skip when SMS is disabled + var carriers = pcrud.search('csc', {active: 'true'}, {'order_by':[{'class':'csc', 'field':'name'},{'class':'csc', 'field':'region'}]}); + var storedata = fieldmapper.csc.toStoreData(carriers); + for(var i in storedata.items) storedata.items[i].label = storedata.items[i].name + ' (' + storedata.items[i].region + ')'; + var store = new dojo.data.ItemFileReadStore({data:storedata}); + var select = new dijit.form.FilteringSelect({store:store,scrollOnFocus:false,labelAttr:'label',searchAttr:'label'}, getByName(row, 'widget')); + select.attr('value', userSettings[stype.name()]); + select.isValid = function() { return true; }; + dojo.connect(select, 'onChange', function(newVal) { userSettingsToUpdate[stype.name()] = newVal; }); + break; + case 'opac.default_sms_notify': + if(!orgSettings['sms.enable']) return; // Skip when SMS is disabled + case 'opac.default_phone': + var tb = new dijit.form.TextBox({scrollOnFocus:false}, getByName(row, 'widget')); + tb.attr('value', userSettings[stype.name()]); + dojo.connect(tb, 'onChange', function(newVal) { userSettingsToUpdate[stype.name()] = newVal; }); + break; + default: + var cb = new dijit.form.CheckBox({scrollOnFocus:false}, getByName(row, 'widget')); + cb.attr('value', userSettings[stype.name()]); + dojo.connect(cb, 'onChange', function(newVal) { userSettingsToUpdate[stype.name()] = newVal; }); + if(stype.name() == 'circ.collections.exempt') { + checkCollectionsExemptPerm(cb); + } } + tbody.insertBefore(row, dividerRow.nextSibling); + openils.Util.show(row, 'table-row'); } function uEditUpdateUserSettings(userId) { -- 2.11.0