From efc140e9fd01b192a174061ff53dfec4f45146b1 Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 3 Sep 2010 19:13:08 +0000 Subject: [PATCH] Patron address copy on clone In patron reg, copy address instead of linking to original address on clone. Controlled by new org unit setting circ.patron_edit.clone.copy_address git-svn-id: svn://svn.open-ils.org/ILS/trunk@17480 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 20 ++++++ ...386.data.org-setting-patron-clone-copy-addr.sql | 22 +++++++ Open-ILS/web/js/ui/default/actor/user/register.js | 77 ++++++++++++++++------ 4 files changed, 101 insertions(+), 20 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0386.data.org-setting-patron-clone-copy-addr.sql diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index c30c7d3cc..670c72053 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -68,7 +68,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0385'); -- gmc +INSERT INTO config.upgrade_log (version) VALUES ('0386'); -- berick CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, 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 a58337737..c1c1ff64f 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -6847,3 +6847,23 @@ INSERT INTO action_trigger.environment ( (35, 'usr.card'), (35, 'pickup_lib') ; + +-- 0386.data.org-setting-patron-clone-copy-addr.sql + +INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES ( + 'circ.patron_edit.clone.copy_address', + oils_i18n_gettext( + 'circ.patron_edit.clone.copy_address', + 'Patron Registration: Cloned patrons get address copy', + 'coust', + 'label' + ), + oils_i18n_gettext( + 'circ.patron_edit.clone.copy_address', + 'In the Patron editor, copy addresses from the cloned user instead of linking directly to the address', + 'coust', + 'description' + ), + 'bool' +); + diff --git a/Open-ILS/src/sql/Pg/upgrade/0386.data.org-setting-patron-clone-copy-addr.sql b/Open-ILS/src/sql/Pg/upgrade/0386.data.org-setting-patron-clone-copy-addr.sql new file mode 100644 index 000000000..39580f71d --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0386.data.org-setting-patron-clone-copy-addr.sql @@ -0,0 +1,22 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0386'); + +INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES ( + 'circ.patron_edit.clone.copy_address', + oils_i18n_gettext( + 'circ.patron_edit.clone.copy_address', + 'Patron Registration: Cloned patrons get address copy', + 'coust', + 'label' + ), + oils_i18n_gettext( + 'circ.patron_edit.clone.copy_address', + 'In the Patron editor, copy addresses from the cloned user instead of linking directly to the address', + 'coust', + 'description' + ), + 'bool' +); + +COMMIT; 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 94f6e45f8..44bb3f118 100644 --- a/Open-ILS/web/js/ui/default/actor/user/register.js +++ b/Open-ILS/web/js/ui/default/actor/user/register.js @@ -44,6 +44,7 @@ var cloneUserObj; var stageUser; var optInSettings; var allCardsTemplate; +var uEditCloneCopyAddr; // if true, copy addrs on clone instead of link var dupeUsrname = false; var dupeBarcode = false; @@ -81,12 +82,15 @@ function load() { 'global.juvenile_age_threshold', 'patron.password.use_phone', 'ui.patron.default_inet_access_level', - 'circ.holds.behind_desk_pickup_supported' + 'circ.holds.behind_desk_pickup_supported', + 'circ.patron_edit.clone.copy_address' ]); + for(k in orgSettings) if(orgSettings[k]) orgSettings[k] = orgSettings[k].value; + uEditCloneCopyAddr = orgSettings['circ.patron_edit.clone.copy_address']; uEditUsePhonePw = orgSettings['patron.password.use_phone']; uEditFetchUserSettings(userId); @@ -285,34 +289,69 @@ function uEditLoadStageUser(stageUname) { function uEditCopyCloneData(patron) { cloneUserObj = uEditLoadUser(cloneUser); - dojo.forEach( [ + var cloneFields = [ 'home_ou', 'day_phone', 'evening_phone', 'other_phone', - 'billing_address', - 'usrgroup', - 'mailing_address' ], + 'usrgroup' + ]; + + if(!uEditCloneCopyAddr) + cloneFields = cloneFields.concat(['mailing_address', 'billing_address']); + + dojo.forEach( + cloneFields, function(field) { patron[field](cloneUserObj[field]()); } ); - // don't grab all addresses(). the only ones we can link to are billing/mailing - if(patron.billing_address()) { - var t = patron.addresses(); - if (!t) { t = []; } - t.push(patron.billing_address()); - patron.addresses(t); - } + if(uEditCloneCopyAddr) { + var billAddr, mailAddr; + + // copy the billing and mailing addresses into new addresses + function cloneAddr(addr) { + var newAddr = addr.clone(); + newAddr.isnew(true); + newAddr.id(uEditAddrVirtId--); + newAddr.usr(patron.id()); + patron.addresses().push(newAddr); + return newAddr; + } - if(patron.mailing_address() && ( - patron.addresses().length == 0 || - patron.mailing_address().id() != patron.billing_address().id()) ) { - var t = patron.addresses(); - if (!t) { t = []; } - t.push(patron.mailing_address()); - patron.addresses(t); + if(billAddr = cloneUserObj.billing_address()) + patron.billing_address(cloneAddr(billAddr)); + + if(mailAddr = cloneUserObj.mailing_address()) { + if (billAddr && billAddr.id() == mailAddr.id()) { + patron.mailing_address(patron.billing_address()); + } else { + patron.mailing_address(cloneAddr(mailAddr)); + } + } + + if(!billAddr) // if there was no billing addr, use the mailing addr + patron.billing_address(patron.mailing_address()); + + } else { + + // link the billing and mailing addresses + if(patron.billing_address()) { + var t = patron.addresses(); + if (!t) { t = []; } + t.push(patron.billing_address()); + patron.addresses(t); + } + + if(patron.mailing_address() && ( + patron.addresses().length == 0 || + patron.mailing_address().id() != patron.billing_address().id()) ) { + var t = patron.addresses(); + if (!t) { t = []; } + t.push(patron.mailing_address()); + patron.addresses(t); + } } } -- 2.11.0