From c8b79f80c7e74cd6fb0fc0de27aa38a50b5e006e Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 11 Dec 2009 15:41:16 +0000 Subject: [PATCH] added support for staff control of event-def opt-in user settings. iow, staff can turn on the X-day overdue notice for patrons if it is an opt-in notice git-svn-id: svn://svn.open-ils.org/ILS/trunk@15142 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/ui/default/actor/user/register.js | 65 +++++++++++++++------- .../web/templates/default/actor/user/register.tt2 | 6 +- 2 files changed, 48 insertions(+), 23 deletions(-) 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 2fdd320e26..4017f03fa6 100644 --- a/Open-ILS/web/js/ui/default/actor/user/register.js +++ b/Open-ILS/web/js/ui/default/actor/user/register.js @@ -34,12 +34,14 @@ var uEditAddrVirtId = -1; var orgSettings = {}; var userSettings = {}; var userSettingsToUpdate = {}; +var userSettingTypes; var tbody; var addrTemplateRows; var cgi; var cloneUser; var cloneUserObj; var stageUser; +var optInSettings; if(!window.xulG) var xulG = null; @@ -224,9 +226,32 @@ function uEditCopyCloneData(patron) { function uEditFetchUserSettings(userId) { + + var baseNode = fieldmapper.aou.findOrgUnit(staff.ws_ou()); + var orgs = fieldmapper.aou.orgNodeTrail(baseNode); + orgs = orgs.map(function(node) { return node.id(); }); + + /* fetch any user setting types we need + any that offer opt-in */ + userSettingTypes = pcrud.search('cust', { + '-or' : [ + {name:['circ.holds_behind_desk']}, + {name : { + 'in': { + select : {atevdef : ['opt_in_setting']}, + from : 'atevdef', + // we only care about opt-in settings for event_defs our users encounter + where : {'+atevdef' : {owner : orgs}} + } + }} + ] + }); + + var names = userSettingTypes.map(function(obj) { return obj.name() }); + + /* fetch any values set for this user */ userSettings = fieldmapper.standardRequest( ['open-ils.actor', 'open-ils.actor.patron.settings.retrieve'], - {params : [openils.User.authtoken, userId, ['circ.holds_behind_desk']]}); + {params : [openils.User.authtoken, userId, names]}); } @@ -247,29 +272,29 @@ function loadStaticFields() { if(fmcls) { fleshFMRow(row, fmcls); } else { - if(row.getAttribute('user_setting')) - fleshUserSettingRow(row, row.getAttribute('user_setting')) + + if(row.id == 'uedit-settings-divider') { + + var template = tbody.removeChild(dojo.byId('uedit-user-setting-template')); + dojo.forEach(userSettingTypes, function(type) { uEditDrawSettingRow(tbody, row, template, type); } ); + + if(userSettingTypes.length > 1 || orgSettings['circ.holds.behind_desk_pickup_supported']) { + openils.Util.show('uedit-settings-divider', 'table-row'); + } + } } } } -function fleshUserSettingRow(row, userSetting) { - switch(userSetting) { - case 'circ.holds_behind_desk': - if(orgSettings['circ.holds.behind_desk_pickup_supported']) { - openils.Util.show('uedit-settings-divider', 'table-row'); - openils.Util.show(row, 'table-row'); - if(userSettings[userSetting]) - holdsBehindShelfBox.attr('checked', true); - - // if the setting changes, add it to the list of settings that need updating - dojo.connect( - holdsBehindShelfBox, - 'onChange', - function(newVal) { userSettingsToUpdate['circ.holds_behind_desk'] = newVal; } - ); - } - } +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({}, 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'); } function uEditUpdateUserSettings(userId) { diff --git a/Open-ILS/web/templates/default/actor/user/register.tt2 b/Open-ILS/web/templates/default/actor/user/register.tt2 index ff24c5eca6..355ef70e0f 100644 --- a/Open-ILS/web/templates/default/actor/user/register.tt2 +++ b/Open-ILS/web/templates/default/actor/user/register.tt2 @@ -117,10 +117,10 @@ User Settings - + - Holds Behind Shelf -
+ +
-- 2.11.0