<page_callback>CRM_Custom_Page_AJAX::fixOrdering</page_callback>
<access_arguments>access CiviCRM</access_arguments>
</item>
+ <item>
+ <path>civicrm/ajax/multirecordfieldlist</path>
+ <page_callback>CRM_Custom_Page_AJAX::getMultiRecordFieldList</page_callback>
+ <access_arguments>access CiviCRM</access_arguments>
+ </item>
</menu>
CRM_Utils_JSON::output(TRUE);
}
+ /**
+ * Get list of Multi Record Fields.
+ *
+ */
+ public static function getMultiRecordFieldList() {
+ $params = $_REQUEST;
+
+ $sEcho = CRM_Utils_Type::escape($_GET['sEcho'], 'Integer');
+ $offset = isset($params['iDisplayStart']) ? CRM_Utils_Type::escape($params['iDisplayStart'], 'Integer') : 0;
+ $rowCount = isset($params['iDisplayLength']) ? CRM_Utils_Type::escape($params['iDisplayLength'], 'Integer') : 25;
+
+ $params['page'] = ($offset / $rowCount) + 1;
+ $params['rp'] = $rowCount;
+ $contactType = CRM_Contact_BAO_Contact::getContactType($params['cid']);
+
+ $obj = new CRM_Profile_Page_MultipleRecordFieldsListing();
+ $obj->_pageViewType = 'customDataView';
+ $obj->_contactId = $params['cid'];
+ $obj->_customGroupId = $params['cgid'];
+ $obj->_contactType = $contactType;
+ $obj->_offset = ($params['page'] - 1) * $params['rp'];
+ $obj->_rowCount = $params['rp'];
+
+ list($headers, $multiRecordFields) = $obj->browse();
+
+ // sort the fields by the columns
+ $sortMapper = array_values($headers);
+ $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
+ $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
+ if ($sort && $sortOrder) {
+ $sortOrder = constant('SORT_' . strtoupper($sortOrder));
+ $sortCol = array();
+ $dataType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $sort, 'data_type');
+ foreach ($multiRecordFields as $key=> $row) {
+ $sortCol[$key] = $row[$sort];
+ if ($dataType == 'Date') {
+ $sortCol[$key] = CRM_Utils_Date::unixTime($row[$sort]);
+ }
+ }
+ array_multisort($sortCol, $sortOrder, $multiRecordFields);
+ }
+
+ $iFilteredTotal = $iTotal = $obj->_total;
+ $selectorElements = array_merge($headers, array('action', 'class'));
+
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
+ echo CRM_Utils_JSON::encodeDataTableSelector($multiRecordFields, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
+ CRM_Utils_System::civiExit();
+ }
+
}
protected $_profileId = NULL;
- protected $_contactId = NULL;
+ public $_contactId = NULL;
- protected $_customGroupTitle = NULL;
+ public $_customGroupTitle = NULL;
- protected $_pageViewType = NULL;
+ public $_pageViewType = NULL;
- protected $_contactType = NULL;
+ public $_contactType = NULL;
/**
* Get BAO Name.
unset($links[CRM_Core_Action::COPY]);
}
$newCgCount = (!$reached) ? count($result) + 1 : NULL;
+ if (isset($this->_offset) && isset($this->_rowCount)) {
+ $this->_total = count($result);
+ $result = array_slice($result, $this->_offset, $this->_rowCount, TRUE);
+ $cgcount = $this->_offset + 1;
+ }
foreach ($result as $recId => &$value) {
foreach ($value as $fieldId => &$val) {
if (is_numeric($fieldId)) {
$headers = array();
if (!empty($fieldIDs)) {
foreach ($fieldIDs as $fieldID) {
- $headers[$fieldID] = ($this->_pageViewType == 'profileDataView') ? $customGroupInfo[$fieldID]['fieldLabel'] : $fieldLabels[$fieldID]['label'];
+ $headers[$fieldID] = ($this->_pageViewType == 'profileDataView') ? $customGroupInfo[$fieldID]['fieldLabel'] : !isset($this->_offset) ? $fieldLabels[$fieldID]['label'] : $fieldID;
}
}
$this->assign('dateFields', $dateFields);
$this->assign('dateFieldsVals', $dateFieldsVals);
$this->assign('cgcount', $cgcount);
+ $this->assign('contactId', $this->_contactId);
+ $this->assign('contactType', $this->_contactType);
$this->assign('customGroupTitle', $this->_customGroupTitle);
$this->assign('headers', $headers);
$this->assign('records', $result);
- $this->assign('attributes', $attributes);
+ $this->assign('attributes', json_encode($attributes));
+
+ return array($headers, $result);
}
/**
<div id="custom-{$customGroupId}-table-wrapper" {if $pageViewType eq 'customDataView'}class="crm-entity" data-entity="contact" data-id="{$contactId}"{/if}>
<div>
{strip}
- <table id="records" class="display">
+ <table id="records" class={if $pageViewType eq 'customDataView'}"crm-multifield-selector"{else}'display'{/if}>
<thead>
<tr>
{foreach from=$headers key=recId item=head}
{/foreach}
</tr>
</thead>
- {foreach from=$records key=recId item=rows}
- <tr class="{cycle values="odd-row,even-row"}">
- {foreach from=$headers key=hrecId item=head}
- <td {crmAttributes a=$attributes.$hrecId.$recId}>{$rows.$hrecId}</td>
- {/foreach}
- <td>{$rows.action}</td>
- {foreach from=$dateFieldsVals key=fid item=rec}
- <td class='crm-field-{$fid}_date hiddenElement'>{$rec.$recId}</td>
- {/foreach}
- </tr>
- {/foreach}
+ {if $pageViewType eq 'customDataView'}
+ {literal}
+ <script type="text/javascript">
+ CRM.$(function($) {
+ var sourceUrl = {/literal}'{crmURL p="civicrm/ajax/multirecordfieldlist" h=0 q="snippet=4&cid=$contactId&cgid=$customGroupId"}'{literal};
+
+ $('table.crm-multifield-selector').dataTable({
+ "bProcessing": true,
+ "aaSorting": [],
+ "asStripClasses" : [ "odd-row", "even-row" ],
+ "sPaginationType": "full_numbers",
+ "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
+ "bServerSide": true,
+ "sAjaxSource": sourceUrl,
+ });
+
+ $(".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();
+ });
+ });
+ </script>
+ {/literal}
+ {else}
+ {foreach from=$records key=recId item=rows}
+ <tr class="{cycle values="odd-row,even-row"}">
+ {foreach from=$headers key=hrecId item=head}
+ <td {crmAttributes a=$attributes.$hrecId.$recId}>{$rows.$hrecId}</td>
+ {/foreach}
+ <td>{$rows.action}</td>
+ {foreach from=$dateFieldsVals key=fid item=rec}
+ <td class='crm-field-{$fid}_date hiddenElement'>{$rec.$recId}</td>
+ {/foreach}
+ </tr>
+ {/foreach}
+ {/if}
</table>
{/strip}
</div>