From bd470b6984ba49d0e30fa3a60d3c028bc9abc12b Mon Sep 17 00:00:00 2001
From: Pratik Joshi <pratik.joshi@webaccess.co.in>
Date: Fri, 28 Mar 2014 11:51:42 +0530
Subject: [PATCH] CRM-14327 : code cleanup and following implementation for
 livePage ajax

---
 CRM/Contact/Form/CustomData.php               |  4 ---
 CRM/Contact/Page/View/CustomData.php          |  2 ++
 CRM/Contact/Page/View/Summary.php             |  1 +
 .../Page/MultipleRecordFieldsListing.php      | 12 ++++----
 templates/CRM/Contact/Form/CustomData.tpl     | 28 -------------------
 .../Page/MultipleRecordFieldsListing.tpl      | 18 ++----------
 6 files changed, 11 insertions(+), 54 deletions(-)

diff --git a/CRM/Contact/Form/CustomData.php b/CRM/Contact/Form/CustomData.php
index 76f87fc1d3..c67ee30b6c 100644
--- a/CRM/Contact/Form/CustomData.php
+++ b/CRM/Contact/Form/CustomData.php
@@ -133,10 +133,6 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form {
         $this->_tableID = $this->_entityId;
         $this->_copyValueId = CRM_Utils_Request::retrieve('copyValueId', 'Positive', $this);
 
-        $backUrl = 'civicrm/contact/view';
-        $backUrl = CRM_Utils_System::url($backUrl, 'action=browse&selectedChild=custom_' . $this->_groupID, TRUE, NULL, FALSE);
-        $this->assign('backUrl', $backUrl);
-
         if (!empty($_POST['hidden_custom'])) {
           $this->assign('postedInfo', TRUE);
         }
diff --git a/CRM/Contact/Page/View/CustomData.php b/CRM/Contact/Page/View/CustomData.php
index df525102ad..ae774e9e1f 100644
--- a/CRM/Contact/Page/View/CustomData.php
+++ b/CRM/Contact/Page/View/CustomData.php
@@ -130,6 +130,8 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page {
       );
 
       if ($displayStyle === 'Tab with table' && $this->_multiRecordDisplay != 'single') {
+        $id = "custom_{$this->_groupId}";
+        $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $groupTree[$this->_groupId]['table_name']);
         $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
           $this->_contactId,
           'contact_type'
diff --git a/CRM/Contact/Page/View/Summary.php b/CRM/Contact/Page/View/Summary.php
index cd2ced25ef..a8df6e947d 100644
--- a/CRM/Contact/Page/View/Summary.php
+++ b/CRM/Contact/Page/View/Summary.php
@@ -394,6 +394,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
         'title' => $group['title'],
         'weight' => $weight,
         'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name']),
+        'class' => 'livePage'
       );
       $weight += 10;
     }
diff --git a/CRM/Profile/Page/MultipleRecordFieldsListing.php b/CRM/Profile/Page/MultipleRecordFieldsListing.php
index dbacefa403..e38cc2d19c 100644
--- a/CRM/Profile/Page/MultipleRecordFieldsListing.php
+++ b/CRM/Profile/Page/MultipleRecordFieldsListing.php
@@ -95,23 +95,23 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
       // urls and queryStrings
       if ($this->_pageViewType == 'profileDataView') {
         $links[CRM_Core_Action::VIEW]['url'] = 'civicrm/profile/view';
-        $links[CRM_Core_Action::VIEW]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$view}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%";
+        $links[CRM_Core_Action::VIEW]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$view}&context=multiProfileDialog&onPopupClose=%%onPopupClose%%";
 
         $links[CRM_Core_Action::UPDATE]['url'] = 'civicrm/profile/edit';
-        $links[CRM_Core_Action::UPDATE]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$update}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%";
+        $links[CRM_Core_Action::UPDATE]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$update}&context=multiProfileDialog&onPopupClose=%%onPopupClose%%";
 
         $links[CRM_Core_Action::DELETE]['url'] = 'civicrm/profile/edit';
-        $links[CRM_Core_Action::DELETE]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$delete}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%";
+        $links[CRM_Core_Action::DELETE]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$delete}&context=multiProfileDialog&onPopupClose=%%onPopupClose%%";
 
       }
       elseif ($this->_pageViewType == 'customDataView') {
         // custom data specific view links
         $links[CRM_Core_Action::VIEW]['url'] = 'civicrm/contact/view/cd';
-        $links[CRM_Core_Action::VIEW]['qs'] = 'reset=1&snippet=1&gid=%%gid%%&cid=%%cid%%&recId=%%recId%%&multiRecordDisplay=single';
+        $links[CRM_Core_Action::VIEW]['qs'] = 'reset=1&gid=%%gid%%&cid=%%cid%%&recId=%%recId%%&multiRecordDisplay=single';
 
         // custom data specific update links
         $links[CRM_Core_Action::UPDATE]['url'] = 'civicrm/contact/view/cd/edit';
-        $links[CRM_Core_Action::UPDATE]['qs'] = 'reset=1&snippet=1&type=%%type%%&groupID=%%groupID%%&entityID=%%entityID%%&cgcount=%%cgcount%%&multiRecordDisplay=single';
+        $links[CRM_Core_Action::UPDATE]['qs'] = 'reset=1&type=%%type%%&groupID=%%groupID%%&entityID=%%entityID%%&cgcount=%%cgcount%%&multiRecordDisplay=single';
         // NOTE : links for DELETE action for customDataView is handled in browse
 
         // copy action
@@ -119,7 +119,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
           'name' => ts('Copy'),
           'title' => ts('Copy %1', array( 1 => $this->_customGroupTitle . ' record')),
           'url' => 'civicrm/contact/view/cd/edit',
-          'qs' => 'reset=1&snippet=1&type=%%type%%&groupID=%%groupID%%&entityID=%%entityID%%&cgcount=%%newCgCount%%&multiRecordDisplay=single&copyValueId=%%cgcount%%'
+          'qs' => 'reset=1&type=%%type%%&groupID=%%groupID%%&entityID=%%entityID%%&cgcount=%%newCgCount%%&multiRecordDisplay=single&copyValueId=%%cgcount%%'
         );
       }
 
diff --git a/templates/CRM/Contact/Form/CustomData.tpl b/templates/CRM/Contact/Form/CustomData.tpl
index 1d9210312a..aa2edffc76 100644
--- a/templates/CRM/Contact/Form/CustomData.tpl
+++ b/templates/CRM/Contact/Form/CustomData.tpl
@@ -28,34 +28,6 @@
    {include file="CRM/Custom/Form/CustomData.tpl"}
    {if $multiRecordDisplay eq 'single'}
      <div class="html-adjust">{$form.buttons.html}</div>
-     {* for form rule handling *}
-     {include file="CRM/Form/validate.tpl"}
-     {literal}
-     <script type='text/javascript'>
-       cj(function($) {
-         $('#custom-record-dialog .crm-container-snippet #CustomData').validate(CRM.validate.params);
-         var formOptions = {
-           success:       checkResponse  // post-submit callback
-         };
-
-         //binding the callback to snippet profile form
-         $('.crm-container-snippet #CustomData').ajaxForm(formOptions);
-       });
-
-     // post-submit callback
-     function checkResponse(responseText, statusText, xhr, $form) {
-       //if there is any form error show the dialog
-       //else redirect to post url
-       if (!cj(responseText).find('.crm-error').html()) {
-         window.location.href = '{/literal}{$backUrl}{literal}';
-       }
-       else {
-         var errorInfo = cj(responseText).find('div.crm-error').html();
-         cj('.crm-container-snippet #CustomData').prepend(errorInfo);
-       }
-     }
-     </script>
-     {/literal}
    {/if}
 {else}
     <div id="customData"></div>
diff --git a/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl b/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl
index eee710e377..13a9018f0d 100644
--- a/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl
+++ b/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl
@@ -80,10 +80,10 @@
 
   {if !$reachedMax}
     {if $pageViewType eq 'customDataView'}
-      <br/><a accesskey="N" title="{ts 1=$customGroupTitle}Add %1 Record{/ts}" href="{crmURL p='civicrm/contact/view/cd/edit' q="reset=1&snippet=1&type=$ctype&groupID=$customGroupId&entityID=$contactId&cgcount=$cgcount&multiRecordDisplay=single"}" 
+      <br/><a accesskey="N" title="{ts 1=$customGroupTitle}Add %1 Record{/ts}" href="{crmURL p='civicrm/contact/view/cd/edit' q="reset=1&type=$ctype&groupID=$customGroupId&entityID=$contactId&cgcount=$cgcount&multiRecordDisplay=single"}" 
        class="button action-item"><span><div class="icon add-icon"></div>{ts 1=$customGroupTitle}Add %1 Record{/ts}</span></a>
     {else}
-      <a accesskey="N" href="{crmURL p='civicrm/profile/edit' q="reset=1&id=`$contactId`&multiRecord=add&gid=`$gid`&snippet=1&context=multiProfileDialog&onPopupClose=`$onPopupClose`"}"
+      <a accesskey="N" href="{crmURL p='civicrm/profile/edit' q="reset=1&id=`$contactId`&multiRecord=add&gid=`$gid`&context=multiProfileDialog&onPopupClose=`$onPopupClose`"}"
        class="button action-item"><span><div class="icon add-icon"></div>{ts}Add New Record{/ts}</span></a>
     {/if}
   {/if}
@@ -133,12 +133,6 @@
       }
 
       var profileName = {/literal}"{$ufGroupName}"{literal};
-      cj('.action-item').each(function () {
-        if (!cj(this).attr('jshref') && !cj(this).hasClass('ignore-jshref')) {
-          cj(this).attr('jshref', cj(this).attr('href'));
-          cj(this).attr('href', '#browseValues');
-        }
-      });
 
       if (pageViewType == 'customDataView') {
         var actionItemHeirarchy = '.action-item';
@@ -147,14 +141,6 @@
       else {
         var actionItemHeirarchy = '.crm-profile-name-' + profileName + ' .action-item';
       }
-
-      cj(actionItemHeirarchy).click(function () {
-        dataURL = cj(this).attr('jshref');
-        dialogTitle = cj(this).attr('title');
-        if (!cj(this).hasClass('ignore-jshref')) {
-          formDialog(profileName, dataURL, dialogTitle);
-        }
-      });
     });
     </script>
   {/literal}
-- 
GitLab