CRM-13929 Refactor shared address form
authorColeman Watts <coleman@civicrm.org>
Sun, 16 Feb 2014 00:53:23 +0000 (16:53 -0800)
committerColeman Watts <coleman@civicrm.org>
Sun, 16 Feb 2014 00:53:23 +0000 (16:53 -0800)
CRM/Contact/Form/Edit/Address.php
CRM/Core/BAO/UFGroup.php
templates/CRM/Contact/Form/ShareAddress.tpl

index 0b45786e9499ea6b81cfb7ac17c976df86fc0ea2..ee0a52eb2217f9731401323e803821819bd1a8b3 100644 (file)
@@ -288,14 +288,9 @@ class CRM_Contact_Form_Edit_Address {
       // shared address
       $form->addElement('checkbox', "address[$blockId][use_shared_address]", NULL, ts('Use another contact\'s address'));
 
-      // get the reserved for address
-      $profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'shared_address', 'id', 'name');
-
-      if (!$profileId) {
-        CRM_Core_Error::fatal(ts('Your install is missing required "Shared Address" profile.'));
-      }
-
-      CRM_Contact_Form_NewContact::buildQuickForm($form, $blockId, array($profileId));
+      // Override the default profile links to add address form
+      $profileLinks = CRM_Core_BAO_UFGroup::getCreateLinks(array('new_individual', 'new_organization', 'new_household'), 'shared_address');
+      $form->addEntityRef("address[$blockId][master_contact_id]", ts('Share With'), array('create' => $profileLinks));
     }
   }
 
index 635979e3e631dcc6d1f3123a604b19a553deb86b..b2077302a3328767f16cc133a86859690a62ebdc 100644 (file)
@@ -3257,7 +3257,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    */
   static function getCreateLinks($profiles, $appendProfiles = array()) {
     $profiles = (array) $profiles;
-    $toGet = array_merge($profiles, $appendProfiles);
+    $toGet = array_merge($profiles, (array) $appendProfiles);
     $retrieved = civicrm_api3('uf_group', 'get', array(
       'name' => array('IN' => $toGet),
       'is_active' => 1,
index 8bc63b20eb7e88b800d656f7b25376725bc8a275..6566a3f6aa8316b89663a0e994fb1252c59bc38a 100644 (file)
       </span>
     {/if}
 
-    <table id="shared-address-{$blockId}" class="form-layout-compressed hiddenElement">
-      {include file="CRM/Contact/Form/NewContact.tpl" blockNo="$blockId"}
-    </table>
+    <div id="shared-address-{$blockId}" class="form-layout-compressed hiddenElement">
+      {$form.address.$blockId.master_contact_id.label}
+      {$form.address.$blockId.master_contact_id.html}
+    </div>
   </td>
 </tr>
 
@@ -83,10 +84,7 @@ cj( function( ) {
     });
 
     // start of code to add onchange event for hidden element
-    var contactHiddenElement = 'input[name="contact_select_id[' + blockNo +']"]';
-
-    // store initial value
-    var _default  = cj( contactHiddenElement ).val();
+    var contactHiddenElement = 'input[name="address[' + blockNo +'][master_contact_id]"]';
 
     // observe changes
     cj( contactHiddenElement ).change(function( ) {
@@ -98,11 +96,10 @@ cj( function( ) {
       var addressHTML = '';
       var postUrl = {/literal}"{crmURL p='civicrm/ajax/inline' h=0}"{literal};
 
-      $('div.crm-address_' + blockNo).block();
-
       cj.post( postUrl, {
         'contact_id': sharedContactId,
         'type': 'method',
+        'async': false,
         'class_name': 'CRM_Contact_Page_AJAX',
         'fn_name': 'getAddressDisplay'
         },
@@ -137,25 +134,9 @@ cj( function( ) {
               cj( '#shared-address-' + blockNo + ' .shared-address-list' ).remove( );
               cj( '#shared-address-' + blockNo ).append( '<tr class="shared-address-list"><td></td><td>' + helpText + '</td></tr>');
             }
-
-            cj('div.crm-address_' + blockNo).unblock();
           }
         },'json');
     });
-
-
-    // continuous check for changed value
-    setInterval(function( ) {
-        if ( cj( contactHiddenElement ).val( ) != _default ) {
-        // trigger native
-        cj( contactHiddenElement ).change( );
-
-        // update stored value
-        _default = cj( contactHiddenElement ).val( );
-        }
-
-    }, 500);
-    // end of code to add onchange event for hidden element
 });
 </script>
 {/literal}