CRM-17154 report actions improvement
authoreileen <emcnaughton@wikimedia.org>
Fri, 18 Sep 2015 03:36:40 +0000 (15:36 +1200)
committereileen <emcnaughton@wikimedia.org>
Thu, 23 Jun 2016 02:56:24 +0000 (14:56 +1200)
Also add delete to action buttons

CRM/Core/Form.php
CRM/Report/Form.php
CRM/Report/Form/Contribute/Detail.php
CRM/Report/Form/Instance.php
templates/CRM/Report/Form.tpl
templates/CRM/Report/Form/Actions.tpl
templates/CRM/common/tasks.tpl [new file with mode: 0644]

index 266f82ba5321d8a79e88af6cbdeb86da3133974d..b8bad65c5a2a4c683c67335b682357027b8122be 100644 (file)
@@ -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
    */
index a018885051b098c8643c08e3951641812183327f..cb5c6fb4fe3a9b6dc2c69b053eb671520ffac5d9 100644 (file)
@@ -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';
+      }
     }
   }
 
index 60000bfab057c43ffdc4cd2c97ef13fd00e0b8a8..721c5b242ac157b54862b3e192b0465b7b163414 100644 (file)
@@ -681,7 +681,6 @@ UNION ALL
 
     // assign variables to templates
     $this->doTemplateAssignment($rows);
-
     // do print / pdf / instance stuff if needed
     $this->endPostProcess($rows);
   }
index f0c0846a2f5f9c616120ebbd27b3df0a810500ec..2d748a3f81dc399365f78c1e2357debb4eea7fcb 100644 (file)
@@ -358,6 +358,7 @@ class CRM_Report_Form_Instance {
       'report_header',
       'report_footer',
       'grouprole',
+      'task',
     );
     foreach ($unsetFields as $field) {
       unset($formValues[$field]);
index c5613b08f06d963b765ffd063ca6d4df22271b68..c580c3c108c744f64bde9c77e67c3ed3af6f2bd8 100644 (file)
@@ -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}
   <div class="crm-block crm-content-block crm-report-layoutGraph-form-block">
index 1c9213045f13ba78d9914aeb30ca9ee5bdc5bae8..add64c97898e578b1b156b3c623e0ada642f9a0e 100644 (file)
@@ -27,9 +27,6 @@
 
   {* build the print pdf buttons *}
     <div class="crm-tasks">
-      {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"}
       <table style="border:0;">
@@ -37,9 +34,7 @@
           <td>
             <table class="form-layout-compressed">
               <tr>
-                <td>{$form.$print.html}&nbsp;&nbsp;</td>
-                <td>{$form.$pdf.html}&nbsp;&nbsp;</td>
-                <td>{$form.$csv.html}&nbsp;&nbsp;</td>
+                {include file="CRM/common/tasks.tpl" location="botton"}
                 {if $instanceUrl}
                   <td>&nbsp;&nbsp;&raquo;&nbsp;<a href="{$instanceUrl}">{ts}Existing report(s) from this template{/ts}</a></td>
                 {/if}
diff --git a/templates/CRM/common/tasks.tpl b/templates/CRM/common/tasks.tpl
new file mode 100644 (file)
index 0000000..9ccabe1
--- /dev/null
@@ -0,0 +1,4 @@
+<span id='task-section'>
+  {$form.task.html}
+  {$form.$actionButtonName.html} &nbsp; &nbsp;
+</span>