From 445431845dc630a6c738f9a3df4a35068bde1dee Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 22 Jun 2016 19:59:16 +1200 Subject: [PATCH] CRM-17154 refactor task actions to accept per-option confirm message & data and add Delete-confirm modal --- CRM/Core/Form.php | 13 +++++++++-- CRM/Core/Form/Search.php | 13 +++++++++++ CRM/Report/BAO/ReportInstance.php | 22 +++++++++++++++++ CRM/Report/Form.php | 39 ++++++------------------------- js/crm.searchForm.js | 22 ++++++++++++++--- 5 files changed, 72 insertions(+), 37 deletions(-) diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 6482b48795..6df1313ddf 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -2177,8 +2177,17 @@ class CRM_Core_Form extends HTML_QuickForm_Page { */ public function addTaskMenu($tasks) { if (is_array($tasks) && !empty($tasks)) { - $tasks = array('' => ts('Actions')) + $tasks; - $this->add('select', 'task', NULL, $tasks, FALSE, array('class' => 'crm-select2 crm-action-menu fa-check-circle-o huge crm-search-result-actions')); + $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']; + } + $select->addOption($task['title'], $key, $attributes); + } if (empty($this->_actionButtonName)) { $this->_actionButtonName = $this->getButtonName('next', 'action'); } diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index 863e204ed2..6977411413 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -139,6 +139,19 @@ class CRM_Core_Form_Search extends CRM_Core_Form { } } + /** + * Add actions menu to search results form. + * + * @param array $tasks + */ + public function addTaskMenu($tasks) { + $taskMetaData = array(); + foreach ($tasks as $key => $task) { + $taskMetaData[$key] = array('title' => $task); + } + parent::addTaskMenu($taskMetaData); + } + /** * Add the sort-name field to the form. * diff --git a/CRM/Report/BAO/ReportInstance.php b/CRM/Report/BAO/ReportInstance.php index 0df77a97eb..999f80a266 100644 --- a/CRM/Report/BAO/ReportInstance.php +++ b/CRM/Report/BAO/ReportInstance.php @@ -346,4 +346,26 @@ class CRM_Report_BAO_ReportInstance extends CRM_Report_DAO_ReportInstance { } } + /** + * Get the metadata of actions available for this entity. + */ + 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.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.'), + ); + } + return $actions; + } + } diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 06e2369ca7..9bd6402e55 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -1515,40 +1515,15 @@ class CRM_Report_Form extends CRM_Core_Form { * @return array */ protected function getActions($instanceId) { - $actions = array( - 'html' => $this->getResultsLabel(), - 'save' => ts('Update'), - 'copy' => ts('Save a Copy'), - 'print' => ts('Print Report'), - 'pdf' => ts('Print to PDF'), - ); + $actions = CRM_Report_BAO_ReportInstance::getActionMetadata(); if (empty($instanceId)) { - $actions['save'] = ts('Create Report'); + $actions['report_instance.save']['title'] = ts('Create Report'); } - if ($this->_outputMode || $this->_id) { - $actions['html'] = ts('Refresh Results'); - } + $actions['report_instance.html']['title'] = $this->getResultsLabel(); - if ($this->_csvSupported) { - $actions['csv'] = ts('Export as CSV'); - } - - if (!empty($this->_charts)) { - $this->assign('charts', $this->_charts); - if ($this->_format != '') { - $actions['tabular'] = ts('View as tabular data'); - } - if ($this->_format != 'pieChart') { - $actions['pieChart'] = ts('View as pie chart'); - } - if ($this->_format != 'barChart') { - $actions['barChart'] = ts('View as bar graph'); - } - } - - if (CRM_Core_Permission::check('administer Reports')) { - $actions['delete'] = ts('Delete report'); + if (!$this->_csvSupported) { + unset($actions['report_instance.csv']); } return $actions; @@ -4599,13 +4574,13 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a */ protected function setOutputMode() { $buttonName = $this->controller->getButtonName(); - $this->_outputMode = CRM_Utils_Request::retrieve( + $this->_outputMode = str_replace('report_instance.', '' , CRM_Utils_Request::retrieve( 'output', 'String', CRM_Core_DAO::$_nullObject, FALSE, CRM_Utils_Array::value('task', $this->_params) - ); + )); if ($buttonName) { if ($buttonName == $this->_instanceButtonName) { diff --git a/js/crm.searchForm.js b/js/crm.searchForm.js index c110521330..4063874262 100644 --- a/js/crm.searchForm.js +++ b/js/crm.searchForm.js @@ -134,12 +134,28 @@ // When selecting a task .on('change', 'select#task', function() { var $form = $(this).closest('form'), - $go = $('input.crm-search-go-button', $form); - if (1) { + $go = $('input.crm-search-go-button', $form); + var $selectedOption = $(this).find(':selected'); + if ($selectedOption.data('confirm_message')) { + var confirmed = false; + CRM.confirm({ + title: $selectedOption.data('confirm_title') ? $selectedOption.data('confirm_title') : ts('Confirm action'), + message: '' + $(title).html() + '' + $selectedOption.data('confirm_message') + '
', + }) + .on('crmConfirm:yes', function() { + confirmed = true; + $go.click(); + }) + .on('crmConfirm:no', function() { + $('#task').val('').change(); + return; + }); + } + else if (!$(this).find(':selected').data('supports_modal')) { $go.click(); } // The following code can load the task in a popup, however not all tasks function correctly with this - // So it's disabled pending a per-task opt-in mechanism + // So it's a per-task opt-in mechanism. else { var data = $form.serialize() + '&' + $go.attr('name') + '=' + $go.attr('value'); var url = $form.attr('action'); -- 2.25.1