CRM-13817 - Migrate simple success messages to mini-notifications
[civicrm-core.git] / templates / CRM / Contact / Page / View / GroupContact.tpl
index cee0b16ce9ea6158fac3d5297583d9f61b8598fe..f17dea5e80421b33c9be56d28d2d6858b9c7f695 100644 (file)
@@ -1,6 +1,6 @@
 {*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
 *}
-<div class="view-content">
-{if $groupCount eq 0 AND ! $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 groups.{/ts}
-  </div>
- {/if}
-
-{include file="CRM/common/jsortable.tpl"}
+<div class="view-content view-contact-groups">
+  {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}
+    </div>
+  {else}
+    {include file="CRM/common/jsortable.tpl"}
+  {/if}
 
-{* Include 'add to new group' form if session has edit contact permissions *}
-{if $permission EQ 'edit'}
-  {include file="CRM/Contact/Form/GroupContact.tpl"}
-{/if}
+  {* Include 'add to new group' form if session has edit contact permissions *}
+  {if $permission EQ 'edit'}
+    {include file="CRM/Contact/Form/GroupContact.tpl"}
+  {/if}
 
-{if $groupIn }
-  <div class="ht-one"></div>
-  <h3>{ts}Regular Groups{/ts}</h3>
-  <div class="description">{ts 1=$displayName}%1 has joined or been added to these group(s).{/ts}</div>
-  {strip}
-    <table id="current_group" class="display">
-    <thead>
+  {if $groupIn }
+    <div class="ht-one"></div>
+    <h3>{ts}Regular Groups{/ts}</h3>
+    <div class="description">{ts 1=$displayName}%1 has joined or been added to these group(s).{/ts}</div>
+    {strip}
+      <table id="current_group" class="display">
+        <thead>
         <tr>
-    <th>{ts}Group{/ts}</th>
-    <th>{ts}Status{/ts}</th>
-    <th>{ts}Date Added{/ts}</th>
-    <th></th>
-  </tr>
-    </thead>
-         {foreach from=$groupIn item=row}
-        <tr id="grp_{$row.id}" class="{cycle values="odd-row,even-row"}">
-          <td class="bold"><a href="{crmURL p='civicrm/group/search' q="reset=1&force=1&context=smog&gid=`$row.group_id`"}">{$row.title}</a></td>
-        <td>{ts 1=$row.in_method}Added (by %1){/ts}</td>
-            <td>{$row.in_date|crmDate}</td>
-          <td>{if $permission EQ 'edit'}<a href="{crmURL p='civicrm/contact/view/group' q="gcid=`$row.id`&action=delete&st=o"}" onclick ="return confirm('{ts 1=$displayName 2=$row.title}Are you sure you want to remove %1 from %2?{/ts}');" title="{ts}Remove contact from this group (status in this group will be changed to 'Removed').{/ts}">[ {ts}Remove{/ts} ]</a>{/if}
-              {if $permission EQ 'edit'}<a href="{crmURL p='civicrm/contact/view/group' q="gcid=`$row.id`&action=delete&st=d"}" onclick ="return confirm('{ts 1=$displayName 2=$row.title}Are you sure you want to delete %1 from %2?{/ts}');" title="{ts}Remove contact from this group AND delete their group status record.{/ts}">[ {ts}Delete{/ts} ]</a>{/if}
-          </td>
+          <th>{ts}Group{/ts}</th>
+          <th>{ts}Status{/ts}</th>
+          <th>{ts}Date Added{/ts}</th>
+          <th></th>
         </tr>
-       {/foreach}
-        </table>
-  {/strip}
-{/if}
+        </thead>
+        {foreach from=$groupIn item=row}
+          <tr id="group_contact-{$row.id}" class="crm-entity {cycle values="odd-row,even-row"}">
+            <td class="bold">
+              <a href="{crmURL p='civicrm/group/search' q="reset=1&force=1&context=smog&gid=`$row.group_id`"}">
+                {$row.title}
+              </a>
+            </td>
+            <td>{ts 1=$row.in_method}Added (by %1){/ts}</td>
+            <td>{$row.in_date|crmDate}</td>
+            <td>
+              {if $permission EQ 'edit'}
+                <a class="action-item action-item-first" href="#Removed" title="{ts 1=$displayName 2=$row.title}Remove %1 from %2? (status in this group will be changed to 'Removed').{/ts}">
+                  {ts}Remove{/ts}</a>
+                <a class="action-item" href="#Deleted" title="{ts 1=$displayName 2=$row.title}Delete %1 from %2? (remove contact AND delete their record of having been in this group).{/ts}">
+                  {ts}Delete{/ts}</a>
+              {/if}
+            </td>
+          </tr>
+        {/foreach}
+      </table>
+    {/strip}
+  {/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>
-  {strip}
-    <table id="smart_group" class="display">
-    <thead>
-    <tr>
-    <th>{ts}Group{/ts}</th>
-    <th>{ts}Description{/ts}</th>
-    </tr>
-    </thead>
-   {foreach from=$groupSmart item=row}
-        <tr id="grp_{$row.id}" class="{cycle values="odd-row,even-row"}">
-          <td class="bold"><a href="{crmURL p='civicrm/group/search' q="reset=1&force=1&context=smog&gid=`$row.id`"}">{$row.title}</a></td>
-          <td>{$row.description}</td>
-        </tr>
-       {/foreach}
-    </table>
-  {/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 $groupParent}
-  <div class="ht-one"></div>
-  <h3>{ts}Parent Groups{/ts}</h3>
-  <div class="description">{ts 1=$displayName}%1 is included in these Parent group(s) based on belonging to group(s) which are their children.{/ts}</div>
-  {strip}
-    <table id="parent_group" class="display">
-    <thead>
-    <tr>
-    <th>{ts}Group{/ts}</th>
-    </tr>
-    </thead>
-   {foreach from=$groupParent item=row}
-        <tr id="grp_{$row.id}" class="{cycle values="odd-row,even-row"}">
-          <td class="bold"><a href="{crmURL p='civicrm/group/search' q="reset=1&force=1&context=smog&gid=`$row.id`"}">{$row.title}</a></td>
+  {if $groupPending}
+    <div class="ht-one"></div>
+    <h3 class="status-pending">{ts}Pending{/ts}</h3>
+    <div class="description">{ts}Joining these group(s) is pending confirmation by this contact.{/ts}</div>
+    {strip}
+      <table id="pending_group" class="display">
+        <thead>
+        <tr>
+          <th>{ts}Group{/ts}</th>
+          <th>{ts}Status{/ts}</th>
+          <th>{ts}Date Pending{/ts}</th>
+          <th></th>
         </tr>
-       {/foreach}
-    </table>
-  {/strip}
-{/if}
-
-{if $groupPending }
-  <div class="ht-one"></div>
-  <h3 class="status-pending">{ts}Pending{/ts}</h3>
-  <div class="description">{ts}Joining these group(s) is pending confirmation by this contact.{/ts}</div>
-  {strip}
-    <table id="pending_group" class="display">
-    <thead>
-  <tr>
-    <th>{ts}Group{/ts}</th>
-    <th>{ts}Status{/ts}</th>
-    <th>{ts}Date Pending{/ts}</th>
-    <th></th>
-  </tr>
-    </thead>
-     {foreach from=$groupPending item=row}
-        <tr class="{cycle values="odd-row,even-row"}">
-            <td class="bold"><a href="{crmURL p='civicrm/group/search' q="reset=1&force=1&context=smog&gid=`$row.group_id`"}">{$row.title}</a></td>
+        </thead>
+        {foreach from=$groupPending item=row}
+          <tr id="group_contact-{$row.id}" class="crm-entity {cycle values="odd-row,even-row"}">
+            <td class="bold">
+              <a href="{crmURL p='civicrm/group/search' q="reset=1&force=1&context=smog&gid=`$row.group_id`"}">
+                {$row.title}
+              </a>
+            </td>
             <td>{ts 1=$row.pending_method}Pending (by %1){/ts}</td>
             <td>{$row.pending_date|crmDate}</td>
-            <td>{if $permission EQ 'edit'}<a href="{crmURL p='civicrm/contact/view/group' q="gcid=`$row.id`&action=delete&st=o"}" onclick ="return confirm('{ts 1=$displayName 2=$row.title}Are you sure you want to remove %1 from %2?{/ts}');"  title="{ts}Remove contact from this group (status in this group will be changed to 'Removed').{/ts}">[ {ts}Remove{/ts} ]</a>{/if}
-                {if $permission EQ 'edit'}<a href="{crmURL p='civicrm/contact/view/group' q="gcid=`$row.id`&action=delete&st=d"}" onclick ="return confirm('{ts 1=$displayName 2=$row.title}Are you sure you want to delete %1 from %2?{/ts}');"  title="{ts}Delete the group status record (this group will no longer be listed under Pending Groups).{/ts}">[ {ts}Delete{/ts} ]</a>{/if}
+            <td>
+              {if $permission EQ 'edit'}
+                <a class="action-item action-item-first" href="#Removed" title="{ts 1=$displayName 2=$row.title}Remove %1 from %2? (status in this group will be changed to 'Removed').{/ts}">
+                  {ts}Remove{/ts}</a>
+                <a class="action-item" href="#Deleted" title="{ts 1=$displayName 2=$row.title}Delete %1 from %2? (this group will no longer be listed under Pending Groups){/ts}">
+                  {ts}Delete{/ts}</a>
+              {/if}
             </td>
-      </tr>
-       {/foreach}
-  </table>
-  {/strip}
-{/if}
+          </tr>
+        {/foreach}
+      </table>
+    {/strip}
+  {/if}
 
-{if $groupOut }
-  <div class="ht-one"></div>
-  <h3 class="status-removed">{ts}Past Groups{/ts}</h3>
+  {if $groupOut}
+    <div class="ht-one"></div>
+    <h3 class="status-removed">{ts}Past Groups{/ts}</h3>
     <div class="description">{ts 1=$displayName}%1 is no longer part of these group(s).{/ts}</div>
     {strip}
-    <table id="past_group" class="display">
-    <thead>
-  <tr>
-    <th>{ts}Group{/ts}</th>
-    <th>{ts}Status{/ts}</th>
-        <th>{ts}Date Added{/ts}</th>
-    <th>{ts}Date Removed{/ts}</th>
-    <th></th>
-  </tr>
-    </thead>
-    {foreach from=$groupOut item=row}
-        <tr class="{cycle values="odd-row,even-row"}">
-            <td class="bold"><a href="{crmURL p='civicrm/group/search' q="reset=1&force=1&context=smog&gid=`$row.group_id`"}">{$row.title}</a></td>
-        <td class="status-removed">{ts 1=$row.out_method}Removed (by %1){/ts}</td>
+      <table id="past_group" class="display">
+        <thead>
+        <tr>
+          <th>{ts}Group{/ts}</th>
+          <th>{ts}Status{/ts}</th>
+          <th>{ts}Date Added{/ts}</th>
+          <th>{ts}Date Removed{/ts}</th>
+          <th></th>
+        </tr>
+        </thead>
+        {foreach from=$groupOut item=row}
+          <tr id="group_contact-{$row.id}" class="crm-entity {cycle values="odd-row,even-row"}">
+            <td class="bold">
+              <a href="{crmURL p='civicrm/group/search' q="reset=1&force=1&context=smog&gid=`$row.group_id`"}">
+                {$row.title}
+              </a>
+            </td>
+            <td class="status-removed">{ts 1=$row.out_method}Removed (by %1){/ts}</td>
             <td>{$row.date_added|crmDate}</td>
             <td>{$row.out_date|crmDate}</td>
-          <td>{if $permission EQ 'edit'}<a href="{crmURL p='civicrm/contact/view/group' q="gcid=`$row.id`&action=delete&st=i"}" onclick ="return confirm('{ts 1=$displayName 2=$row.title}Are you sure you want to add %1 back into %2?{/ts}');">[ {ts}Rejoin Group{/ts} ]</a>{/if}
-              {if $permission EQ 'edit'}<a href="{crmURL p='civicrm/contact/view/group' q="gcid=`$row.id`&action=delete&st=d"}" onclick ="return confirm('{ts 1=$displayName 2=$row.title}Are you sure you want to delete %1 from %2?{/ts}');" title="{ts}Delete the group status record (this group will no longer be listed under Past Groups).{/ts}">[ {ts}Delete{/ts} ]</a>{/if}
-          </td>
-      </tr>
-    {/foreach}
-     </table>
-  {/strip}
+            <td>{if $permission EQ 'edit'}
+                <a class="action-item action-item-first" href="#Added" title="{ts 1=$displayName 2=$row.title}Add %1 back into %2?{/ts}">
+                  {ts}Rejoin Group{/ts}</a>
+              <a class="action-item" href="#Deleted" title="{ts 1=$displayName 2=$row.title}Delete %1 from %2? (this group will no longer be listed under Past Groups).{/ts}">
+                {ts}Delete{/ts}</a>{/if}
+            </td>
+          </tr>
+        {/foreach}
+      </table>
+    {/strip}
   {/if}
 </div>
-</div>
\ No newline at end of file
+
+
+{literal}
+<script type="text/javascript">
+  cj(function($) {
+    // load panes function calls for snippet based on id of crm-accordion-header
+    function loadPanes() {
+      var id = $(this).attr('id');
+      var contactId = $(this).attr('contact_id');
+      if (!$('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}...';
+        $('div.' + id).html(loading).load(CRM.url('civicrm/contact/view/smartgroup', {snippet: 4, cid: contactId}));
+      }
+    }
+    // bind first click of accordion header to load crm-accordion-body with snippet
+    $('.view-contact-groups .crm-ajax-accordion.collapsed .crm-accordion-header').one('click', loadPanes);
+    $('.view-contact-groups .crm-ajax-accordion:not(.collapsed) .crm-accordion-header').each(loadPanes);
+    // Handle enable/delete links
+    var that;
+    function refresh() {
+      $(that).closest('.crm-ajax-container, #crm-main-content-wrapper').crmSnippet().crmSnippet('refresh');
+    }
+    function enableDisableGroup() {
+      var params = {
+        id: $(that).closest('.crm-entity').attr('id').split('-')[1],
+        method: 'Admin'
+      };
+      var status = that.href.split('#')[1];
+      if (status === 'Deleted') {
+        params.skip_undelete = true;
+      } else {
+        params.status = status;
+      }
+      // This api is weird - 'delete' actually works for updating as well as deleting
+      // Normally you wouldn't put a variable within ts() but this works due to smarty hack below
+      CRM.api3('group_contact', 'delete', params, {success: ts(status)}).done(refresh);
+    }
+    $('.view-contact-groups a.action-item').click(function() {
+      that = this;
+      CRM.confirm(enableDisableGroup, {message: this.title});
+      return false;
+    });
+  });
+  {/literal}
+  // Hack to ensure status msg is properly translated
+  CRM.strings.Added = "{ts escape='js'}Added{/ts}";
+  CRM.strings.Removed = "{ts escape='js'}Removed{/ts}";
+  CRM.strings.Deleted = "{ts escape='js'}Deleted{/ts}";
+</script>