From 87ecd5b7b227153e200d21a63a6493ef965885db Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 18 Sep 2015 15:36:40 +1200 Subject: [PATCH] CRM-17154 report actions improvement Also add delete to action buttons --- CRM/Core/Form.php | 25 +++++++ CRM/Report/Form.php | 94 ++++++++++++++++++++------- CRM/Report/Form/Contribute/Detail.php | 1 - CRM/Report/Form/Instance.php | 1 + templates/CRM/Report/Form.tpl | 2 - templates/CRM/Report/Form/Actions.tpl | 7 +- templates/CRM/common/tasks.tpl | 4 ++ 7 files changed, 100 insertions(+), 34 deletions(-) create mode 100644 templates/CRM/common/tasks.tpl diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 266f82ba53..b8bad65c5a 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -2170,6 +2170,31 @@ class CRM_Core_Form extends HTML_QuickForm_Page { return $this->add('select', $elementName, $settings['label'], NULL, $settings['required'], $props); } + /** + * Add actions menu to results form. + * + * @param $tasks + */ + 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 huge crm-search-result-actions')); + if (empty($this->_actionButtonName)) { + $this->_actionButtonName = $this->getButtonName('next', 'action'); + } + $this->assign('actionButtonName', $this->_actionButtonName); + $this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'hiddenElement crm-search-go-button')); + + // Radio to choose "All items" or "Selected items only" + $selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked')); + $allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all'); + $this->assign('ts_sel_id', $selectedRowsRadio->_attributes['id']); + $this->assign('ts_all_id', $allRowsRadio->_attributes['id']); + + CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js', 1, 'html-header'); + } + } + /** * Set options and attributes for chain select fields based on the controlling field's value */ diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index a018885051..cb5c6fb4fe 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -636,9 +636,6 @@ class CRM_Report_Form extends CRM_Core_Form { $this->_instanceButtonName = $this->getButtonName('submit', 'save'); $this->_createNewButtonName = $this->getButtonName('submit', 'next'); - $this->_printButtonName = $this->getButtonName('submit', 'print'); - $this->_pdfButtonName = $this->getButtonName('submit', 'pdf'); - $this->_csvButtonName = $this->getButtonName('submit', 'csv'); $this->_groupButtonName = $this->getButtonName('submit', 'group'); $this->_chartButtonName = $this->getButtonName('submit', 'chart'); } @@ -1468,30 +1465,17 @@ class CRM_Report_Form extends CRM_Core_Form { */ public function buildInstanceAndButtons() { CRM_Report_Form_Instance::buildForm($this); - - $label = $this->_id ? ts('Update Report') : ts('Create Report'); - - $this->addElement('submit', $this->_instanceButtonName, $label); - $this->addElement('submit', $this->_printButtonName, ts('Print Report')); - $this->addElement('submit', $this->_pdfButtonName, ts('PDF')); + $this->_actionButtonName = $this->getButtonName('submit'); + $this->addTaskMenu($this->getActions($this->_id)); if ($this->_id) { $this->addElement('submit', $this->_createNewButtonName, ts('Save a Copy') . '...'); } - $this->assign('instanceForm', $this->_instanceForm); - - $label = $this->_id ? ts('Print Report') : ts('Print Preview'); - $this->addElement('submit', $this->_printButtonName, $label); - - $label = $this->_id ? ts('PDF') : ts('Preview PDF'); - $this->addElement('submit', $this->_pdfButtonName, $label); - - $label = $this->_id ? ts('Export to CSV') : ts('Preview CSV'); + $this->addElement('submit', $this->_instanceButtonName, + ts('Update Report')); - if ($this->_csvSupported) { - $this->addElement('submit', $this->_csvButtonName, $label); - } + $this->assign('instanceForm', $this->_instanceForm); // CRM-16274 Determine if user has 'edit all contacts' or equivalent $permission = CRM_Core_Permission::getPermission(); @@ -1509,16 +1493,74 @@ class CRM_Report_Form extends CRM_Core_Form { $this->addElement('submit', $this->_groupButtonName, '', array('style' => 'display: none;')); $this->addChartOptions(); + $showResultsLabel = $this->getResultsLabel(); $this->addButtons(array( array( 'type' => 'submit', - 'name' => ts('Preview Report'), + 'name' => $showResultsLabel, 'isDefault' => TRUE, ), ) ); } + /** + * Has this form been submitted already? + * + * @return bool + */ + public function resultsDisplayed() { + $buttonName = $this->controller->getButtonName(); + return ($buttonName || $this->_outputMode); + } + + /** + * Get the actions for this report instance. + * + * @param int $instanceId + * + * @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'), + ); + if (empty($instanceId)) { + $actions['save'] = ts('Create Report'); + } + + if ($this->_outputMode || $this->_id) { + $actions['html'] = ts('Refresh Results'); + } + + 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'); + } + + return $actions; + } + /** * Main build form function. */ @@ -2509,6 +2551,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND public function processReportMode() { $this->setOutputMode(); + $buttonName = $this->controller->getButtonName(); $this->_sendmail = CRM_Utils_Request::retrieve( 'sendmail', @@ -2551,6 +2594,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND elseif ($this->_outputMode == 'copy' && $this->_criteriaForm) { $this->_createNew = TRUE; } + $this->assign('outputMode', $this->_outputMode); $this->assign('outputMode', $this->_outputMode); $this->assign('printOnly', $printOnly); @@ -2598,9 +2642,6 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND if ($this->_outputMode == 'save' || $this->_outputMode == 'copy') { $this->_createNew = ($this->_outputMode == 'copy'); - // Do not pass go. Do not collect another chance to re-run the same query. - // This will be called from the button - there is an earlier response to the url - // perhaps they can still be consolidated more. CRM_Report_Form_Instance::postProcess($this); } $this->beginPostProcessCommon(); @@ -4664,6 +4705,9 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id) AND {$this->_aliases['civicrm_address']}.is_primary = 1\n"; + if ($buttonName == $this->_createNewButtonName) { + $this->_outputMode = 'copy'; + } } } diff --git a/CRM/Report/Form/Contribute/Detail.php b/CRM/Report/Form/Contribute/Detail.php index 60000bfab0..721c5b242a 100644 --- a/CRM/Report/Form/Contribute/Detail.php +++ b/CRM/Report/Form/Contribute/Detail.php @@ -681,7 +681,6 @@ UNION ALL // assign variables to templates $this->doTemplateAssignment($rows); - // do print / pdf / instance stuff if needed $this->endPostProcess($rows); } diff --git a/CRM/Report/Form/Instance.php b/CRM/Report/Form/Instance.php index f0c0846a2f..2d748a3f81 100644 --- a/CRM/Report/Form/Instance.php +++ b/CRM/Report/Form/Instance.php @@ -358,6 +358,7 @@ class CRM_Report_Form_Instance { 'report_header', 'report_footer', 'grouprole', + 'task', ); foreach ($unsetFields as $field) { unset($formValues[$field]); diff --git a/templates/CRM/Report/Form.tpl b/templates/CRM/Report/Form.tpl index c5613b08f0..c580c3c108 100644 --- a/templates/CRM/Report/Form.tpl +++ b/templates/CRM/Report/Form.tpl @@ -23,8 +23,6 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ *} -{if $outputMode neq 'print'} -{/if} {* this div is being used to apply special css *} {if $section eq 1}
diff --git a/templates/CRM/Report/Form/Actions.tpl b/templates/CRM/Report/Form/Actions.tpl index 1c9213045f..add64c9789 100644 --- a/templates/CRM/Report/Form/Actions.tpl +++ b/templates/CRM/Report/Form/Actions.tpl @@ -27,9 +27,6 @@ {* build the print pdf buttons *}
- {assign var=print value="_qf_"|cat:$form.formName|cat:"_submit_print"} - {assign var=pdf value="_qf_"|cat:$form.formName|cat:"_submit_pdf"} - {assign var=csv value="_qf_"|cat:$form.formName|cat:"_submit_csv"} {assign var=group value="_qf_"|cat:$form.formName|cat:"_submit_group"} {assign var=chart value="_qf_"|cat:$form.formName|cat:"_submit_chart"} @@ -37,9 +34,7 @@
- - - + {include file="CRM/common/tasks.tpl" location="botton"} {if $instanceUrl} {/if} diff --git a/templates/CRM/common/tasks.tpl b/templates/CRM/common/tasks.tpl new file mode 100644 index 0000000000..9ccabe102a --- /dev/null +++ b/templates/CRM/common/tasks.tpl @@ -0,0 +1,4 @@ + + {$form.task.html} + {$form.$actionButtonName.html}     + -- 2.25.1
{$form.$print.html}  {$form.$pdf.html}  {$form.$csv.html}    » {ts}Existing report(s) from this template{/ts}