From bc37053c7517065c68ca8f4cefdca39aadd73a83 Mon Sep 17 00:00:00 2001 From: Andrew Hunt Date: Fri, 8 May 2020 15:40:46 -0400 Subject: [PATCH] Send `is_default` data as boolean, not rendered icon; add js icon helper --- CRM/Campaign/Page/DashBoard.php | 7 +++-- CRM/Core/BAO/CustomOption.php | 5 ++-- CRM/Price/Page/Option.php | 1 - js/Common.js | 28 +++++++++++++++++++ .../CRM/Campaign/Form/Search/Petition.tpl | 1 + templates/CRM/Campaign/Form/Search/Survey.tpl | 1 + templates/CRM/Custom/Page/Option.tpl | 4 +-- 7 files changed, 39 insertions(+), 8 deletions(-) diff --git a/CRM/Campaign/Page/DashBoard.php b/CRM/Campaign/Page/DashBoard.php index 563f85654b..dfd6f3126c 100644 --- a/CRM/Campaign/Page/DashBoard.php +++ b/CRM/Campaign/Page/DashBoard.php @@ -312,7 +312,8 @@ class CRM_Campaign_Page_DashBoard extends CRM_Core_Page { } $surveysData[$sid]['isActive'] = $isActive; - $surveysData[$sid]['is_default'] = self::crmIcon('fa-check', ts('Default'), $surveysData[$sid]['is_default']); + // For some reason, 'is_default' is coming as a string. + $surveysData[$sid]['is_default'] = boolval($surveysData[$sid]['is_default']); if ($surveysData[$sid]['result_id']) { $resultSet = '' . ts('Result Set') . ''; @@ -411,7 +412,9 @@ class CRM_Campaign_Page_DashBoard extends CRM_Core_Page { $isActive = ts('Yes'); } $petitionsData[$pid]['isActive'] = $isActive; - $petitionsData[$pid]['is_default'] = self::crmIcon('fa-check', ts('Default'), $petitionsData[$pid]['is_default']); + + // For some reason, 'is_default' is coming as a string. + $petitionsData[$pid]['is_default'] = boolval($petitionsData[$pid]['is_default']); $petitionsData[$pid]['action'] = CRM_Core_Action::formLink(self::petitionActionLinks(), $action, diff --git a/CRM/Core/BAO/CustomOption.php b/CRM/Core/BAO/CustomOption.php index 7ada066788..9009cce0ac 100644 --- a/CRM/Core/BAO/CustomOption.php +++ b/CRM/Core/BAO/CustomOption.php @@ -138,12 +138,11 @@ class CRM_Core_BAO_CustomOption { } if (in_array($field->html_type, ['CheckBox', 'Multi-Select'])) { - $isDefault = (isset($defVal) && in_array($dao->value, $defVal)); + $options[$dao->id]['is_default'] = (isset($defVal) && in_array($dao->value, $defVal)); } else { - $isDefault = ($field->default_value == $dao->value); + $options[$dao->id]['is_default'] = ($field->default_value == $dao->value); } - $options[$dao->id]['is_default'] = CRM_Core_Page::crmIcon('fa-check', ts('Default'), $isDefault); $options[$dao->id]['description'] = $dao->description; $options[$dao->id]['class'] = $dao->id . ',' . $class; $options[$dao->id]['is_active'] = empty($dao->is_active) ? ts('No') : ts('Yes'); diff --git a/CRM/Price/Page/Option.php b/CRM/Price/Page/Option.php index 14dfa3f65f..a8ea081f50 100644 --- a/CRM/Price/Page/Option.php +++ b/CRM/Price/Page/Option.php @@ -160,7 +160,6 @@ class CRM_Price_Page_Option extends CRM_Core_Page { $action -= CRM_Core_Action::DISABLE; } } - $customOption[$id]['is_default'] = CRM_Core_Page::crmIcon('fa-check', ts('Default'), !empty($customOption[$id]['is_default'])); $customOption[$id]['order'] = $customOption[$id]['weight']; $customOption[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, [ diff --git a/js/Common.js b/js/Common.js index f4c2a60a6f..af35e7df80 100644 --- a/js/Common.js +++ b/js/Common.js @@ -395,6 +395,34 @@ if (!CRM.vars) CRM.vars = {}; return ret + _.escape(row.text) + (description ? '

' + _.escape(description) + '

' : ''); } + /** + * Helper to generate an icon with alt text. + * + * See also smarty `{icon}` and CRM_Core_Page::crmIcon() functions + * + * @param string icon + * The Font Awesome icon class to use. + * @param string text + * Alt text to display. + * @param mixed condition + * This will only display if this is truthy. + * + * @return string + * The formatted icon markup. + */ + CRM.utils.formatConditionalIcon = function (icon, text, condition) { + if (!condition) { + return ''; + } + var title = ''; + var sr = ''; + if (text) { + title = ' title="' + text + '"'; + sr = '' + text + ''; + } + return '' + sr; + }; + /** * Wrapper for select2 initialization function; supplies defaults * @param options object diff --git a/templates/CRM/Campaign/Form/Search/Petition.tpl b/templates/CRM/Campaign/Form/Search/Petition.tpl index e14be7e538..9db79c205d 100644 --- a/templates/CRM/Campaign/Form/Search/Petition.tpl +++ b/templates/CRM/Campaign/Form/Search/Petition.tpl @@ -198,6 +198,7 @@ function loadPetitionList( ) //add id for yes/no column. CRM.$(nRow).children().eq(8).attr( 'id', rowId + '_status' ); + CRM.$(nRow).children().eq(6).html(CRM.utils.formatConditionalIcon('fa-check', ts('Default'), nRow.cells[6].innerText)); return nRow; }, diff --git a/templates/CRM/Campaign/Form/Search/Survey.tpl b/templates/CRM/Campaign/Form/Search/Survey.tpl index 1177d3a5ce..ec82b95ed5 100644 --- a/templates/CRM/Campaign/Form/Search/Survey.tpl +++ b/templates/CRM/Campaign/Form/Search/Survey.tpl @@ -210,6 +210,7 @@ function loadSurveyList( ) //add id for yes/no column. CRM.$(nRow).children().eq(11).attr( 'id', rowId + '_status' ); + CRM.$(nRow).children().eq(9).html(CRM.utils.formatConditionalIcon('fa-check', ts('Default'), nRow.cells[9].innerText)); return nRow; }, diff --git a/templates/CRM/Custom/Page/Option.tpl b/templates/CRM/Custom/Page/Option.tpl index f47cafc27e..b61de6b99e 100644 --- a/templates/CRM/Custom/Page/Option.tpl +++ b/templates/CRM/Custom/Page/Option.tpl @@ -54,8 +54,8 @@ "aoColumns" : [ {sClass:'crm-custom_option-label'}, {sClass:'crm-custom_option-value'}, + {sClass:'crm-custom_option-description'}, {sClass:'crm-custom_option-default_value'}, - {sClass:'crm-custom_option-default_description'}, {sClass:'crm-custom_option-is_active'}, {sClass:'crm-custom_option-links'}, {sClass:'hiddenElement'} @@ -87,7 +87,7 @@ $(nRow).addClass(cl).attr({id: 'OptionValue-' + id}); $('td:eq(0)', nRow).wrapInner(''); $('td:eq(0)', nRow).prepend(''); - $('td:eq(2)', nRow).addClass('crmf-default_value'); + $('td:eq(3)', nRow).addClass('crmf-default_value').html(CRM.utils.formatConditionalIcon('fa-check', ts('Default'), nRow.cells[3].innerText)); return nRow; }, "fnDrawCallback": function() { -- 2.25.1