CRM-12466, added smart group pane
authorKurund Jalmi <kurund@civicrm.org>
Tue, 21 May 2013 00:45:02 +0000 (20:45 -0400)
committerKurund Jalmi <kurund@civicrm.org>
Tue, 21 May 2013 00:52:22 +0000 (20:52 -0400)
CRM/Contact/Page/View/ContactSmartGroup.php
CRM/Contact/Page/View/GroupContact.php
CRM/Core/xml/Menu/Contact.xml
templates/CRM/Contact/Page/View/ContactSmartGroup.tpl
templates/CRM/Contact/Page/View/GroupContact.tpl

index 483045a8ef0dd589b22753b6a2e38506b788c193..0a32eaa1e23de9e21a395b0088caaedbe8ae899c 100644 (file)
  */
 class CRM_Contact_Page_View_ContactSmartGroup extends CRM_Core_Page {
 
+  /**
+   * @var int contact id
+   */
+  public $_contactId;
+
   /**
    * This function is called when action is browse
    *
@@ -41,7 +46,7 @@ class CRM_Contact_Page_View_ContactSmartGroup extends CRM_Core_Page {
    * @access public
    */
   function browse() {
-    $in      = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added');
+    $in = CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added');
 
     // keep track of all 'added' contact groups so we can remove them from the smart group
     // section
@@ -53,8 +58,8 @@ class CRM_Contact_Page_View_ContactSmartGroup extends CRM_Core_Page {
     }
 
     $allGroup = CRM_Contact_BAO_GroupContactCache::contactGroup($this->_contactId);
-    $this->assign('groupSmart'  , null);
-    $this->assign('groupParent', null);
+    $this->assign('groupSmart'  , NULL);
+    $this->assign('groupParent', NULL);
 
     if (!empty($allGroup)) {
       $smart = $parent = array( );
@@ -84,11 +89,11 @@ class CRM_Contact_Page_View_ContactSmartGroup extends CRM_Core_Page {
     $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
     $this->assign('contactId', $this->_contactId);
 
+    $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
+    $this->assign('displayName', $displayName);
+
     // check logged in url permission
     CRM_Contact_Page_View::checkUserPermission($this);
-
-    $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
-    $this->assign('action', $this->_action);
   }
 
   /**
index ab0b2accc8d93fc90c72c57d72f5ee8346b7af53..152d3d261f696add8758fef2f409c45ac6161051 100644 (file)
@@ -62,34 +62,10 @@ class CRM_Contact_Page_View_GroupContact extends CRM_Core_Page {
     $this->assign_by_ref('groupPending', $pending);
     $this->assign_by_ref('groupOut', $out);
 
-    /*
-    $allGroup = CRM_Contact_BAO_GroupContactCache::contactGroup($this->_contactId);
-    $this->assign('groupSmart'  , null);
-    $this->assign('groupParent', null);
-
-    if (!empty($allGroup)) {
-      $smart = $parent = array( );
-      foreach ($allGroup['group'] as $group) {
-        // delete all smart groups which are also in static groups
-        if (isset($staticGroups[$group['id']])) {
-          continue;
-        }
-        if (empty($group['children'])) {
-          $smart[] = $group;
-        }
-        else {
-          $parent[] = $group;
-        }
-      }
-
-      if (!empty($smart)) {
-        $this->assign_by_ref('groupSmart', $smart);
-      }
-      if (!empty($parent)) {
-        $this->assign_by_ref('groupParent', $parent);
-      }
-    }
-    */
+    // get the info on contact smart groups
+    $contactSmartGroupSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
+      'contact_smart_group_display');
+    $this->assign('contactSmartGroupSettings', $contactSmartGroupSettings);
   }
 
   /**
index 391b2b7833ad0ac3ae0423a521f69bab1616beba..628a9a764f00822d1c2854a2107d1dc064d76d11 100644 (file)
      <title>Groups</title>
      <page_callback>CRM_Contact_Page_View_GroupContact</page_callback>
   </item>
+  <item>
+    <path>civicrm/contact/view/smartgroup</path>
+    <path_arguments>cid=%%cid%%</path_arguments>
+    <title>Smart Groups</title>
+    <page_callback>CRM_Contact_Page_View_ContactSmartGroup</page_callback>
+  </item>
   <item>
      <path>civicrm/contact/view/sunlight</path>
      <title>Sunlight</title>
index 830acee373db7d7442c6a32ae9a9edc22c9a3595..4208723f6aa47ed3cc7f61a9cb84d398873d031b 100644 (file)
  +--------------------------------------------------------------------+
 *}
 <div class="view-content">
+  {if !$groupSmart AND !$groupParent}
+    <div class="messages status no-popup">
+      <div class="icon inform-icon"></div>
+      &nbsp;{ts}This contact does not currently belong to any smart groups.{/ts}
+    </div>
+  {/if}
+
   {if $groupSmart}
     <div class="ht-one"></div>
-    <h3>{ts}Smart Groups{/ts}</h3>
     <div class="description">
       {ts 1=$displayName}%1 is currently included in these Smart group(s) (e.g. saved searches).{/ts}
     </div>
index ba6cd344706555caf095fab8c5486c518847811f..e8183b0d9ca676df14f9ce54812ff02e4e7205cb 100644 (file)
@@ -24,7 +24,7 @@
  +--------------------------------------------------------------------+
 *}
 <div class="view-content">
-  {if $groupCount eq 0 AND ! $groupSmart AND ! $groupParent}
+  {if $groupCount eq 0}
     <div class="messages status no-popup">
       <div class="icon inform-icon"></div>
       &nbsp;{ts}This contact does not currently belong to any groups.{/ts}
     {/strip}
   {/if}
 
-
+  {if $contactSmartGroupSettings neq 3}
+  <div class="accordion ui-accordion ui-widget ui-helper-reset">
+    <div class="crm-accordion-wrapper crm-ajax-accordion crm-smartgroup-accordion {if $contactSmartGroupSettings eq 1}collapsed{/if}">
+      <div class="crm-accordion-header" id="crm-contact_smartgroup" contact_id="{$contactId}">
+        {ts}Smart Groups{/ts}
+      </div>
+      <!-- /.crm-accordion-header -->
+      <div class="crm-accordion-body">
+        <div class="crm-contact_smartgroup"></div>
+      </div>
+      <!-- /.crm-accordion-body -->
+    </div>
+    <!-- /.crm-accordion-wrapper -->
+  </div>
+  {/if}
 
   {if $groupPending}
     <div class="ht-one"></div>
       </table>
     {/strip}
   {/if}
-</div>
\ No newline at end of file
+</div>
+
+
+{literal}
+<script type="text/javascript">
+  // bind first click of accordion header to load crm-accordion-body with snippet
+  // everything else taken care of by cj().crm-accordions()
+  cj(function () {
+    cj('.crm-ajax-accordion .crm-accordion-header').one('click', function () {
+      loadPanes(cj(this));
+    });
+    cj('.crm-ajax-accordion:not(.collapsed) .crm-accordion-header').each(function (index) {
+      loadPanes(cj(this));
+    });
+  });
+
+  // load panes function calls for snippet based on id of crm-accordion-header
+  function loadPanes(paneObj) {
+    var id = paneObj.attr('id');
+    var contactId = paneObj.attr('contact_id');
+
+    var dataUrl = CRM.url('civicrm/contact/view/smartgroup', 'snippet=4&cid=' + contactId);
+
+    if (!cj('div.' + id).html()) {
+      var loading = '<img src="{/literal}{$config->resourceBase}i/loading.gif{literal}" alt="{/literal}{ts escape='js'}loading{/ts}{literal}" />&nbsp;{/literal}{ts escape='js'}Loading{/ts}{literal}...';
+      cj('div.' + id).html(loading);
+      cj.ajax({
+        url: dataUrl,
+        success: function (data) {
+          cj('div.' + id).html(data);
+        }
+      });
+    }
+  }
+</script>
+{/literal}
\ No newline at end of file