Patron address copy on clone
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 3 Sep 2010 19:13:08 +0000 (19:13 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 3 Sep 2010 19:13:08 +0000 (19:13 +0000)
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
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/0386.data.org-setting-patron-clone-copy-addr.sql [new file with mode: 0644]
Open-ILS/web/js/ui/default/actor/user/register.js

index c30c7d3..670c720 100644 (file)
@@ -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,
index a583377..c1c1ff6 100644 (file)
@@ -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 (file)
index 0000000..39580f7
--- /dev/null
@@ -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;
index 94f6e45..44bb3f1 100644 (file)
@@ -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);
+        }
     }
 }