From 1a7356e72a72195abfc06832049f778f1ffe46e4 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 23 Jun 2016 10:50:58 +1200 Subject: [PATCH] CRM-17154 fix search actions to support refreshing fields in confirm (like save a copy) Always refresh 'task' to '' as it is not a true field, enotice fix minor simplification Remove obsoleted code Show navigation menu on save-as screen --- CRM/Core/Form.php | 9 +++- CRM/Report/BAO/ReportInstance.php | 33 ++++++++++++-- CRM/Report/Form.php | 6 +-- CRM/Report/Form/Instance.php | 6 +-- js/crm.searchForm.js | 25 +++++++++-- templates/CRM/Report/Form/Tabs/Instance.tpl | 50 --------------------- 6 files changed, 64 insertions(+), 65 deletions(-) diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 6df1313ddf..029083d11b 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -2177,14 +2177,19 @@ class CRM_Core_Form extends HTML_QuickForm_Page { */ public function addTaskMenu($tasks) { if (is_array($tasks) && !empty($tasks)) { + // Set constants means this will always load with an empty value, not reloading any submitted value. + // This is appropriate as it is a pseudofield. + $this->setConstants(array('task' => '')); $this->assign('taskMetaData', $tasks); $select = $this->add('select', 'task', NULL, array('' => ts('Actions')), FALSE, array( 'class' => 'crm-select2 crm-action-menu fa-check-circle-o huge crm-search-result-actions') ); foreach ($tasks as $key => $task) { $attributes = array(); - if (isset($task['confirm_message'])) { - $attributes['data-confirm_message'] = $task['confirm_message']; + if (isset($task['data'])) { + foreach ($task['data'] as $dataKey => $dataValue) { + $attributes['data-' . $dataKey] = $dataValue; + } } $select->addOption($task['title'], $key, $attributes); } diff --git a/CRM/Report/BAO/ReportInstance.php b/CRM/Report/BAO/ReportInstance.php index 999f80a266..df6b842076 100644 --- a/CRM/Report/BAO/ReportInstance.php +++ b/CRM/Report/BAO/ReportInstance.php @@ -348,21 +348,46 @@ class CRM_Report_BAO_ReportInstance extends CRM_Report_DAO_ReportInstance { /** * Get the metadata of actions available for this entity. + * + * The thinking here is to describe the various actions on the BAO and then functions + * can add a mix of actions from different BAO as appropriate. The crm.SearchForm.js code + * transforms the 'confirm_mesage' into a message that needs to be confirmed. + * confirm_refresh_fields need to be reviewed & potentially updated at the confirm stage. + * + * Ideas not yet implemented: + * - supports_modal task can be loaded in a popup, theoretically worked, not attempted. + * - class and or icon - per option icons or classes (I added these in addTaskMenu::addTaskMenu + * but I didn't have the right classes). ie adding 'class' => 'crm-i fa-print' to print / class looked + * wrong, but at the php level it worked https://github.com/civicrm/civicrm-core/pull/8529#issuecomment-227639091 + * - general script-add. */ public static function getActionMetadata() { $actions = array( 'report_instance.html' => array('title' => ts('View results')), 'report_instance.save' => array('title' => ts('Update')), - 'report_instance.copy' => array('title' => ts('Save a Copy')), - 'report_instance.print' => array('title' => ts('Print Report'), 'icon' => 'fa-print'), + 'report_instance.copy' => array( + 'title' => ts('Save a Copy'), + 'data' => array( + 'is_confirm' => TRUE, + 'confirm_title' => ts('Save a copy...'), + 'confirm_refresh_fields' => json_encode(array( + 'title' => array('selector' => '.crm-report-instanceForm-form-block-title', 'prepend' => ts('(Copy) ')), + 'description' => array('selector' => '.crm-report-instanceForm-form-block-description', 'prepend' => ''), + 'parent_id' => array('selector' => '.crm-report-instanceForm-form-block-parent_id', 'prepend' => ''), + )), + ), + ), + 'report_instance.print' => array('title' => ts('Print Report')), 'report_instance.pdf' => array('title' => ts('Print to PDF')), 'report_instance.csv' => array('title' => ts('Export as CSV')), ); if (CRM_Core_Permission::check('administer Reports')) { $actions['report_instance.delete'] = array( 'title' => ts('Delete report'), - 'icon' => 'fa-trash', - 'confirm_message' => ts('Are you sure you want delete this report? This action cannot be undone.'), + 'data' => array( + 'is_confirm' => TRUE, + 'confirm_message' => ts('Are you sure you want delete this report? This action cannot be undone.'), + ), ); } return $actions; diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index fc5552cae0..698edb7b9e 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -3231,9 +3231,9 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND */ public function compileContent() { $templateFile = $this->getHookedTemplateFileName(); - return $this->_formValues['report_header'] . + return CRM_Utils_Array::value('report_header', $this->_formValues) . CRM_Core_Form::$_template->fetch($templateFile) . - $this->_formValues['report_footer']; + CRM_Utils_Array::value('report_footer', $this->_formValues); } @@ -4573,7 +4573,7 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a * is that we might print a bar chart as a pdf. */ protected function setOutputMode() { - $this->_outputMode = str_replace('report_instance.', '' , CRM_Utils_Request::retrieve( + $this->_outputMode = str_replace('report_instance.', '', CRM_Utils_Request::retrieve( 'output', 'String', CRM_Core_DAO::$_nullObject, diff --git a/CRM/Report/Form/Instance.php b/CRM/Report/Form/Instance.php index 2d748a3f81..b57391871b 100644 --- a/CRM/Report/Form/Instance.php +++ b/CRM/Report/Form/Instance.php @@ -228,7 +228,7 @@ class CRM_Report_Form_Instance { $defaults['permission'] = $permissions['CiviReport: access CiviReport']; } - $config = CRM_Core_Config::singleton(); + $userFrameworkResourceURL = CRM_Core_Config::singleton()->userFrameworkResourceURL; // Add a special region for the default HTML header of printed reports. It // won't affect reports with customized headers, just ones with the default. @@ -239,12 +239,12 @@ class CRM_Report_Form_Instance { CiviCRM Report - + {$htmlHeader}
"; - $defaults['report_footer'] = $report_footer = "

userFrameworkResourceURL}i/powered_by.png\" />

+ $defaults['report_footer'] = $report_footer = "

"; diff --git a/js/crm.searchForm.js b/js/crm.searchForm.js index 4063874262..2e2a6cd492 100644 --- a/js/crm.searchForm.js +++ b/js/crm.searchForm.js @@ -132,18 +132,37 @@ } }) // When selecting a task - .on('change', 'select#task', function() { + .on('change', 'select#task', function(e) { var $form = $(this).closest('form'), $go = $('input.crm-search-go-button', $form); var $selectedOption = $(this).find(':selected'); - if ($selectedOption.data('confirm_message')) { + if (!$selectedOption.val()) { + // do not blank refresh the empty option. + return; + } + if ($selectedOption.data('is_confirm')) { var confirmed = false; + var refresh_fields = $selectedOption.data('confirm_refresh_fields'); + var $message = '' + (($selectedOption.data('confirm_message') !== undefined) ? $selectedOption.data('confirm_message') : '') + ''; + if (refresh_fields === undefined) { + refresh_fields = {}; + } + $.each(refresh_fields, function (refreshIndex, refreshValue) { + var $refresh_field = $(refreshValue.selector); + var prependText = (refreshValue.prepend !== undefined) ? refreshValue.prepend : ''; + var existingInput = $refresh_field.find('input').val(); + $message = $message + '' + $refresh_field.html().replace(existingInput, prependText + existingInput) + ''; + }); + CRM.confirm({ title: $selectedOption.data('confirm_title') ? $selectedOption.data('confirm_title') : ts('Confirm action'), - message: '' + $(title).html() + '' + $selectedOption.data('confirm_message') + '
', + message: '' + $message + '
' }) .on('crmConfirm:yes', function() { confirmed = true; + $.each(refresh_fields, function (refreshIndex, refreshValue) { + $('#' + refreshIndex).val($('.crm-confirm #' + refreshIndex).val()); + }); $go.click(); }) .on('crmConfirm:no', function() { diff --git a/templates/CRM/Report/Form/Tabs/Instance.tpl b/templates/CRM/Report/Form/Tabs/Instance.tpl index 17e5eec343..ca7db8c37e 100644 --- a/templates/CRM/Report/Form/Tabs/Instance.tpl +++ b/templates/CRM/Report/Form/Tabs/Instance.tpl @@ -136,53 +136,3 @@ showHideByValue('is_navigation','','navigation_menu','table-row','radio',false); {/if} - -{literal} - -{/literal} -- 2.25.1