From 56a7bb7ce72345e37c4eb422216cc5facdb359f2 Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Wed, 20 Jan 2016 16:19:08 +0530 Subject: [PATCH] use rowCallback --- CRM/Custom/Page/AJAX.php | 3 +- .../CRM/Contact/Page/View/CustomData.tpl | 13 ++++++-- .../Page/MultipleRecordFieldsListing.tpl | 32 +++++-------------- 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/CRM/Custom/Page/AJAX.php b/CRM/Custom/Page/AJAX.php index ece28c55f3..bfa703cd46 100644 --- a/CRM/Custom/Page/AJAX.php +++ b/CRM/Custom/Page/AJAX.php @@ -145,7 +145,7 @@ class CRM_Custom_Page_AJAX { $field = array(); foreach ($value as $fieldId => &$fieldName) { if (!empty($attributes[$fieldId][$id]['class'])) { - $fieldName = array('data' => $fieldName, 'cssClass' => $attributes[$fieldId][$id]['class']); + $fieldName = array('data' => $fieldName, 'cellClass' => $attributes[$fieldId][$id]['class']); } if (is_numeric($fieldId)) { $fName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $fieldId, 'label'); @@ -156,7 +156,6 @@ class CRM_Custom_Page_AJAX { array_push($fieldList, $field); } $totalRecords = !empty($obj->_total) ? $obj->_total : 0; - $fieldList = array_map('array_merge', $fieldList); $multiRecordFields = array(); $multiRecordFields['data'] = $fieldList; diff --git a/templates/CRM/Contact/Page/View/CustomData.tpl b/templates/CRM/Contact/Page/View/CustomData.tpl index 865cad24f5..68359ee16d 100644 --- a/templates/CRM/Contact/Page/View/CustomData.tpl +++ b/templates/CRM/Contact/Page/View/CustomData.tpl @@ -49,7 +49,15 @@ CRM.$(function($) { var $table = $("#{/literal}custom-{$customGroupId}-table-wrapper{literal}"); $('a.delete-custom-row', $table).on('click', function(e) { - var $el = $(this); + deleteRow($(this)); + e.preventDefault(); + }); + $(".crm-multifield-selector").on('click', '.delete-custom-row', function (e) { + deleteRow($(this)); + e.preventDefault(); + }); + + function deleteRow($el) { CRM.confirm({ message: '{/literal}{ts escape='js'}Are you sure you want to delete this record?{/ts}{literal}' }).on('crmConfirm:yes', function() { @@ -60,8 +68,7 @@ CRM.refreshParent($el); }); }) - e.preventDefault(); - }); + } }); {/literal} diff --git a/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl b/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl index f38e65cf97..31c560c43b 100644 --- a/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl +++ b/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl @@ -60,37 +60,21 @@ "emptyTable": ZeroRecordText, }, //Add class attributes to cells - "fnRowCallback": function(nRow, aData) { - $('thead th').each( function( index ) { + "rowCallback": function(row, data) { + $('thead th').each( function(index) { var fName = $(this).attr('data-data'); - var cell = $('td:eq(' + index + ')', nRow); - if (typeof aData[fName]=='object') { - if (typeof aData[fName].data != 'undefined') { - $(cell).html(aData[fName].data); + var cell = $('td:eq(' + index + ')', row); + if (typeof data[fName] == 'object') { + if (typeof data[fName].data != 'undefined') { + $(cell).html(data[fName].data); } - if (typeof aData[fName].cssClass != 'undefined') { - $(cell).attr('class', aData[fName].cssClass); + if (typeof data[fName].cellClass != 'undefined') { + $(cell).attr('class', data[fName].cellClass); } } }); - return nRow; }, }) - - $(".crm-multifield-selector").on('click','.delete-custom-row', function (e) { - var $el = $(this); - CRM.confirm({ - message: '{/literal}{ts escape='js'}Are you sure you want to delete this record?{/ts}{literal}' - }).on('crmConfirm:yes', function() { - var postUrl = {/literal}"{crmURL p='civicrm/ajax/customvalue' h=0 }"{literal}; - var request = $.post(postUrl, $el.data('delete_params')); - CRM.status({/literal}"{ts escape='js'}Record Deleted{/ts}"{literal}, request); - request.done(function() { - CRM.refreshParent($el); - }); - }) - e.preventDefault(); - }); })(CRM.$); {/literal} -- 2.25.1