From 9f486f9f3687faf1c0f73f2a8e66684fd5b36ff6 Mon Sep 17 00:00:00 2001 From: Joseph Lacey Date: Mon, 28 Dec 2015 13:26:30 -0500 Subject: [PATCH] CRM-16353 - Moving all js functions within CRM.$. Minor bug fix to editable child group rows. ---------------------------------------- * CRM-16353: Upgrade datatables integration to use v2 api https://issues.civicrm.org/jira/browse/CRM-16353 --- templates/CRM/Group/Form/Search.tpl | 156 ++++++++++++++-------------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/templates/CRM/Group/Form/Search.tpl b/templates/CRM/Group/Form/Search.tpl index 9b67bb5496..7ab8bb1c4a 100644 --- a/templates/CRM/Group/Form/Search.tpl +++ b/templates/CRM/Group/Form/Search.tpl @@ -95,7 +95,7 @@ // also to handle search filtering for initial load of same page. var parentsOnly = 1 var ZeroRecordText = {/literal}'{ts escape="js"}
No Groups have been created for this site.{/ts}
'{literal}; - CRM.$('table.crm-group-selector').data({ + $('table.crm-group-selector').data({ "ajax": { "url": {/literal}'{crmURL p="civicrm/ajax/grouplist" h=0 q="snippet=4"}'{literal}, "data": function (d) { @@ -155,84 +155,84 @@ $('table.crm-group-selector').DataTable().draw(); }); }); - })(CRM.$); - CRM.$('#crm-container') - .on('click', 'a.button, a.action-item[href*="action=update"], a.action-item[href*="action=delete"]', CRM.popup) - .on('crmPopupFormSuccess', 'a.button, a.action-item[href*="action=update"], a.action-item[href*="action=delete"]', function() { - // Refresh datatable when form completes - CRM.$('table.crm-group-selector').DataTable().draw(); - }); - // show hide children - var context = CRM.$('#crm-main-content-wrapper'); - CRM.$('table.crm-group-selector', context).on( 'click', 'span.show-children', function(){ - var showOrgInfo = {/literal}"{$showOrgInfo}"{literal}; - var rowID = CRM.$(this).parents('tr').prop('id'); - var parentRow = rowID.split('_'); - var parent_id = parentRow[1]; - var group_id = ''; - if ( parentRow[2]) { - group_id = parentRow[2]; - } - var levelClass = 'level_2'; - // check enclosing td if already at level 2 - if ( CRM.$(this).parent().hasClass('level_2') ) { - levelClass = 'level_3'; - } - if ( CRM.$(this).hasClass('collapsed') ) { - CRM.$(this).removeClass("collapsed").addClass("expanded").attr("title",{/literal}"{ts escape='js'}hide child groups{/ts}"{literal}); - showChildren( parent_id, showOrgInfo, group_id, levelClass ); - } - else { - CRM.$(this).removeClass("expanded").addClass("collapsed").attr("title",{/literal}"{ts escape='js'}show child groups{/ts}"{literal}); - CRM.$('.parent_is_' + parent_id).find('.show-children').removeClass("expanded").addClass("collapsed").attr("title",{/literal}"{ts escape='js'}show child groups{/ts}"{literal}); - CRM.$('.parent_is_' + parent_id).hide(); - CRM.$('.parent_is_' + parent_id).each(function(i, obj) { - // also hide children of children - var gID = $(this).find('td:nth-child(2)').text(); - CRM.$('.parent_is_' + gID).hide(); - }); - } - }); - function showChildren( parent_id, showOrgInfo, group_id, levelClass) { - var rowID = '#row_' + parent_id; - if ( group_id ) { - rowID = '#row_' + parent_id + '_' + group_id; - } - if ( CRM.$(rowID).next().hasClass('parent_is_' + parent_id ) ) { - // child rows for this parent have already been retrieved so just show them - CRM.$('.parent_is_' + parent_id ).show(); - } else { - //FIXME Is it possible to replace all this with a datatables call? - CRM.$.ajax( { - "dataType": 'json', - "url": {/literal}'{crmURL p="civicrm/ajax/grouplist" h=0 q="snippet=4"}'{literal}, - "data": {'parent_id': parent_id, 'showOrgInfo': showOrgInfo}, - "success": function(response){ - var appendHTML = ''; - CRM.$.each( response.data, function( i, val ) { - appendHTML += ''; - if ( val.is_parent ) { - appendHTML += '' + '{/literal}{literal}' + val.group_name + ''; - } - else { - appendHTML += '' + val.title + ''; - } - appendHTML += '' + val.count + ""; - appendHTML += "" + val.created_by + ""; - appendHTML += '' + (val.description || '') + ""; - appendHTML += "" + val.group_type + ""; - appendHTML += '' + val.visibility + ""; - if (showOrgInfo) { - appendHTML += "" + val.org_info + ""; - } - appendHTML += "" + val.links + ""; - appendHTML += ""; - }); - CRM.$( rowID ).after( appendHTML ); - CRM.$( rowID ).next().trigger('crmLoad'); - } + $('#crm-container') + .on('click', 'a.button, a.action-item[href*="action=update"], a.action-item[href*="action=delete"]', CRM.popup) + .on('crmPopupFormSuccess', 'a.button, a.action-item[href*="action=update"], a.action-item[href*="action=delete"]', function() { + // Refresh datatable when form completes + $('table.crm-group-selector').DataTable().draw(); }); + // show hide children + var context = $('#crm-main-content-wrapper'); + $('table.crm-group-selector', context).on( 'click', 'span.show-children', function(){ + var showOrgInfo = {/literal}"{$showOrgInfo}"{literal}; + var rowID = $(this).parents('tr').prop('id'); + var parentRow = rowID.split('_'); + var parent_id = parentRow[1]; + var group_id = ''; + if ( parentRow[2]) { + group_id = parentRow[2]; + } + var levelClass = 'level_2'; + // check enclosing td if already at level 2 + if ( $(this).parent().hasClass('level_2') ) { + levelClass = 'level_3'; + } + if ( $(this).hasClass('collapsed') ) { + $(this).removeClass("collapsed").addClass("expanded").attr("title",{/literal}"{ts escape='js'}hide child groups{/ts}"{literal}); + showChildren( parent_id, showOrgInfo, group_id, levelClass ); + } + else { + $(this).removeClass("expanded").addClass("collapsed").attr("title",{/literal}"{ts escape='js'}show child groups{/ts}"{literal}); + $('.parent_is_' + parent_id).find('.show-children').removeClass("expanded").addClass("collapsed").attr("title",{/literal}"{ts escape='js'}show child groups{/ts}"{literal}); + $('.parent_is_' + parent_id).hide(); + $('.parent_is_' + parent_id).each(function(i, obj) { + // also hide children of children + var gID = $(this).find('td:nth-child(2)').text(); + $('.parent_is_' + gID).hide(); + }); + } + }); + function showChildren( parent_id, showOrgInfo, group_id, levelClass) { + var rowID = '#row_' + parent_id; + if ( group_id ) { + rowID = '#row_' + parent_id + '_' + group_id; + } + if ( $(rowID).next().hasClass('parent_is_' + parent_id ) ) { + // child rows for this parent have already been retrieved so just show them + $('.parent_is_' + parent_id ).show(); + } else { + //FIXME Is it possible to replace all this with a datatables call? + $.ajax( { + "dataType": 'json', + "url": {/literal}'{crmURL p="civicrm/ajax/grouplist" h=0 q="snippet=4"}'{literal}, + "data": {'parent_id': parent_id, 'showOrgInfo': showOrgInfo}, + "success": function(response){ + var appendHTML = ''; + $.each( response.data, function( i, val ) { + appendHTML += ''; + if ( val.is_parent ) { + appendHTML += '' + '{/literal}{literal}' + val.group_name + ''; + } + else { + appendHTML += '' + val.title + ''; + } + appendHTML += '' + val.count + ""; + appendHTML += "" + val.created_by + ""; + appendHTML += '' + (val.description || '') + ""; + appendHTML += "" + val.group_type + ""; + appendHTML += '' + val.visibility + ""; + if (showOrgInfo) { + appendHTML += "" + val.org_info + ""; + } + appendHTML += "" + val.links + ""; + appendHTML += ""; + }); + $( rowID ).after( appendHTML ); + $( rowID ).next().trigger('crmLoad'); + } + }); + } } - } + })(CRM.$); {/literal} -- 2.25.1