From 559865a0775aaf5c438aae5530923fd08d2996a2 Mon Sep 17 00:00:00 2001 From: Kurund Jalmi <kurund@civicrm.org> Date: Mon, 20 May 2013 20:45:02 -0400 Subject: [PATCH] CRM-12466, added smart group pane --- CRM/Contact/Page/View/ContactSmartGroup.php | 17 ++++-- CRM/Contact/Page/View/GroupContact.php | 32 ++--------- CRM/Core/xml/Menu/Contact.xml | 6 ++ .../Contact/Page/View/ContactSmartGroup.tpl | 8 ++- .../CRM/Contact/Page/View/GroupContact.tpl | 55 ++++++++++++++++++- 5 files changed, 80 insertions(+), 38 deletions(-) diff --git a/CRM/Contact/Page/View/ContactSmartGroup.php b/CRM/Contact/Page/View/ContactSmartGroup.php index 483045a8ef..0a32eaa1e2 100644 --- a/CRM/Contact/Page/View/ContactSmartGroup.php +++ b/CRM/Contact/Page/View/ContactSmartGroup.php @@ -34,6 +34,11 @@ */ 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); } /** diff --git a/CRM/Contact/Page/View/GroupContact.php b/CRM/Contact/Page/View/GroupContact.php index ab0b2accc8..152d3d261f 100644 --- a/CRM/Contact/Page/View/GroupContact.php +++ b/CRM/Contact/Page/View/GroupContact.php @@ -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); } /** diff --git a/CRM/Core/xml/Menu/Contact.xml b/CRM/Core/xml/Menu/Contact.xml index 391b2b7833..628a9a764f 100644 --- a/CRM/Core/xml/Menu/Contact.xml +++ b/CRM/Core/xml/Menu/Contact.xml @@ -184,6 +184,12 @@ <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> diff --git a/templates/CRM/Contact/Page/View/ContactSmartGroup.tpl b/templates/CRM/Contact/Page/View/ContactSmartGroup.tpl index 830acee373..4208723f6a 100644 --- a/templates/CRM/Contact/Page/View/ContactSmartGroup.tpl +++ b/templates/CRM/Contact/Page/View/ContactSmartGroup.tpl @@ -24,9 +24,15 @@ +--------------------------------------------------------------------+ *} <div class="view-content"> + {if !$groupSmart AND !$groupParent} + <div class="messages status no-popup"> + <div class="icon inform-icon"></div> + {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> diff --git a/templates/CRM/Contact/Page/View/GroupContact.tpl b/templates/CRM/Contact/Page/View/GroupContact.tpl index ba6cd34470..e8183b0d9c 100644 --- a/templates/CRM/Contact/Page/View/GroupContact.tpl +++ b/templates/CRM/Contact/Page/View/GroupContact.tpl @@ -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> {ts}This contact does not currently belong to any groups.{/ts} @@ -81,7 +81,21 @@ {/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> @@ -166,4 +180,39 @@ </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}" /> {/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 -- GitLab