+
+
+{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}" /> {/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
+ CRM.api('group_contact', 'delete', params, {success: function() {
+ refresh();
+ // Normally you wouldn't put a variable within ts() but this works due to smarty hack below
+ CRM.alert('', ts(status), 'success');
+ }});
+ }
+ $('.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>