From 34197a5503432259180e78ec2c64fd02cc689dad Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 31 May 2014 18:44:37 +0100 Subject: [PATCH] CRM-12872 - Centralize search task menu code --- CRM/Activity/Form/Search.php | 11 +------ CRM/Case/Form/Search.php | 13 ++------- CRM/Contact/Form/Search.php | 11 ++----- CRM/Contribute/Form/Search.php | 11 ++----- CRM/Core/Form/Search.php | 15 ++++++++++ CRM/Event/Form/Search.php | 11 ++----- CRM/Grant/Form/Search.php | 14 +-------- CRM/Member/Form/Search.php | 10 +------ CRM/Pledge/Form/Search.php | 11 +------ js/crm.searchForm.js | 53 ---------------------------------- 10 files changed, 28 insertions(+), 132 deletions(-) diff --git a/CRM/Activity/Form/Search.php b/CRM/Activity/Form/Search.php index 9126675ad8..5899cfa2b2 100644 --- a/CRM/Activity/Form/Search.php +++ b/CRM/Activity/Form/Search.php @@ -249,16 +249,7 @@ class CRM_Activity_Form_Search extends CRM_Core_Form_Search { $permission = CRM_Core_Permission::getPermission(); - $tasks = array('' => ts('- actions -')) + CRM_Activity_Task::permissionedTaskTitles($permission); - - $this->add('select', 'task', ts('Actions:') . ' ', $tasks); - $this->add('submit', $this->_actionButtonName, ts('Go'), - array( - 'class' => 'form-submit', - 'id' => 'Go', - 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);", - ) - ); + $this->addTaskMenu(CRM_Activity_Task::permissionedTaskTitles($permission)); // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked')); diff --git a/CRM/Case/Form/Search.php b/CRM/Case/Form/Search.php index 73332948e5..67d9718101 100644 --- a/CRM/Case/Form/Search.php +++ b/CRM/Case/Form/Search.php @@ -262,7 +262,7 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search { $permission = CRM_Core_Permission::getPermission(); - $tasks = array('' => ts('- actions -')) + CRM_Case_Task::permissionedTaskTitles($permission); + $tasks = CRM_Case_Task::permissionedTaskTitles($permission); if (!empty($this->_formValues['case_deleted'])) { unset($tasks[1]); @@ -271,18 +271,11 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search { unset($tasks[4]); } - $this->add('select', 'task', ts('Actions:') . ' ', $tasks); - $this->add('submit', $this->_actionButtonName, ts('Go'), - array( - 'class' => 'form-submit', - 'id' => 'Go', - 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);", - ) - ); + $this->addTaskMenu($tasks); // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked')); - $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('class' => 'select-rows', 'onclick' => $this->getName() . ".toggleSelect.checked = false; toggleTaskAction( true );")); + $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('class' => 'select-rows')); } } diff --git a/CRM/Contact/Form/Search.php b/CRM/Contact/Form/Search.php index 2fb29196fc..64a90c9222 100644 --- a/CRM/Contact/Form/Search.php +++ b/CRM/Contact/Form/Search.php @@ -391,7 +391,7 @@ class CRM_Contact_Form_Search extends CRM_Core_Form_Search { ->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header'); $permission = CRM_Core_Permission::getPermission(); // some tasks.. what do we want to do with the selected contacts ? - $tasks = array('' => ts('- actions -')); + $tasks = array(); if ($this->_componentMode == 1 || $this->_componentMode == 7) { $tasks += CRM_Contact_Task::permissionedTaskTitles($permission, CRM_Utils_Array::value('deleted_contacts', $this->_formValues) @@ -504,14 +504,7 @@ class CRM_Contact_Form_Search extends CRM_Core_Form_Search { $this->add('hidden', 'task', CRM_Contact_Task::GROUP_CONTACTS); } else { - $this->add('select', 'task', ts('Actions:') . ' ', $tasks); - $this->add('submit', $this->_actionButtonName, ts('Go'), - array( - 'class' => 'form-submit', - 'id' => 'Go', - 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0, 1);", - ) - ); + $this->addTaskMenu($tasks); } // need to perform tasks on all or selected items ? using radio_ts(task selection) for it diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index 43ed084a79..f0f7621e91 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -290,15 +290,8 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { if (!empty($queryParams)) { $softCreditFiltering = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($queryParams); } - $tasks = array('' => ts('- actions -')) + CRM_Contribute_Task::permissionedTaskTitles($permission, $softCreditFiltering); - $this->add('select', 'task', ts('Actions:') . ' ', $tasks); - $this->add('submit', $this->_actionButtonName, ts('Go'), - array( - 'class' => 'form-submit', - 'id' => 'Go', - 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);", - ) - ); + $tasks = CRM_Contribute_Task::permissionedTaskTitles($permission, $softCreditFiltering); + $this->addTaskMenu($tasks); // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked')); diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index c584a0451f..1e9d14e966 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -29,6 +29,9 @@ */ class CRM_Core_Form_Search extends CRM_Core_Form { + /** + * Common buildform tasks required by all searches + */ function buildQuickform() { $resources = CRM_Core_Resources::singleton(); @@ -48,4 +51,16 @@ class CRM_Core_Form_Search extends CRM_Core_Form { ), )); } + + /** + * Add actions menu to search results form + * @param $tasks + */ + 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')); + $this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'hiddenElement crm-search-go-button')); + } + } } diff --git a/CRM/Event/Form/Search.php b/CRM/Event/Form/Search.php index 6c66f3673b..aeaaad7a29 100644 --- a/CRM/Event/Form/Search.php +++ b/CRM/Event/Form/Search.php @@ -289,7 +289,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { $permission = CRM_Core_Permission::getPermission(); - $tasks = array('' => ts('- actions -')) + CRM_Event_Task::permissionedTaskTitles($permission); + $tasks = CRM_Event_Task::permissionedTaskTitles($permission); if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { $tasks = $tasks + CRM_Event_Task::optionalTaskTitle(); @@ -303,14 +303,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { $this->assign('ssID', $this->_ssID); } - $this->add('select', 'task', ts('Actions:') . ' ', $tasks); - $this->add('submit', $this->_actionButtonName, ts('Go'), - array( - 'class' => 'form-submit', - 'id' => 'Go', - 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);", - ) - ); + $this->addTaskMenu($tasks); // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', diff --git a/CRM/Grant/Form/Search.php b/CRM/Grant/Form/Search.php index 9cd8cc2ecc..bda769908b 100644 --- a/CRM/Grant/Form/Search.php +++ b/CRM/Grant/Form/Search.php @@ -244,19 +244,7 @@ class CRM_Grant_Form_Search extends CRM_Core_Form_Search { $permission = CRM_Core_Permission::getPermission(); - $tasks = array('' => ts('- actions -')); - $permissionedTask = CRM_Grant_Task::permissionedTaskTitles($permission); - if (is_array($permissionedTask) && !CRM_Utils_System::isNull($permissionedTask)) { - $tasks += $permissionedTask; - } - - $this->add('select', 'task', ts('Actions:') . ' ', $tasks); - $this->add('submit', $this->_actionButtonName, ts('Go'), - array( - 'class' => 'form-submit', - 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);", - ) - ); + $this->addTaskMenu(CRM_Grant_Task::permissionedTaskTitles($permission)); // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked')); diff --git a/CRM/Member/Form/Search.php b/CRM/Member/Form/Search.php index 248ced281c..8ddb224036 100644 --- a/CRM/Member/Form/Search.php +++ b/CRM/Member/Form/Search.php @@ -239,15 +239,7 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search { $permission = CRM_Core_Permission::getPermission(); - $tasks = array('' => ts('- actions -')) + CRM_Member_Task::permissionedTaskTitles($permission); - $this->add('select', 'task', ts('Actions:') . ' ', $tasks); - $this->add('submit', $this->_actionButtonName, ts('Go'), - array( - 'class' => 'form-submit', - 'id' => 'Go', - 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);", - ) - ); + $this->addTaskMenu(CRM_Member_Task::permissionedTaskTitles($permission)); // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked')); diff --git a/CRM/Pledge/Form/Search.php b/CRM/Pledge/Form/Search.php index ac202912cf..4400064d47 100644 --- a/CRM/Pledge/Form/Search.php +++ b/CRM/Pledge/Form/Search.php @@ -238,16 +238,7 @@ class CRM_Pledge_Form_Search extends CRM_Core_Form_Search { $permission = CRM_Core_Permission::getPermission(); - $tasks = array('' => ts('- actions -')) + CRM_Pledge_Task::permissionedTaskTitles($permission); - - $this->add('select', 'task', ts('Actions:') . ' ', $tasks); - $this->add('submit', $this->_actionButtonName, ts('Go'), - array( - 'class' => 'form-submit', - 'id' => 'Go', - 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);", - ) - ); + $this->addTaskMenu(CRM_Pledge_Task::permissionedTaskTitles($permission)); // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked')); diff --git a/js/crm.searchForm.js b/js/crm.searchForm.js index 7e3a53b22b..7f8fc3c310 100644 --- a/js/crm.searchForm.js +++ b/js/crm.searchForm.js @@ -11,59 +11,6 @@ function countSelectedCheckboxes(fldPrefix, form) { return fieldCount; } -/** - * This function is used to check if any action is selected and also to check if any contacts are checked. - * - * @access public - * @param fldPrefix - common string which precedes unique checkbox ID and identifies field as - * belonging to the resultset's checkbox collection - * @param form - name of form that checkboxes are part of - * Sample usage: onClick="javascript:checkPerformAction('chk_', myForm );" - * - */ -function checkPerformAction(fldPrefix, form, taskButton, selection) { - var cnt; - var gotTask = 0; - - // taskButton TRUE means we don't need to check the 'task' field - it's a button-driven task - if (taskButton == 1) { - gotTask = 1; - } - else { - if (document.forms[form].task.selectedIndex) { - //force user to select all search contacts, CRM-3711 - if (document.forms[form].task.value == 13 || document.forms[form].task.value == 14) { - var toggleSelect = document.getElementsByName('toggleSelect'); - if (toggleSelect[0].checked || document.forms[form].radio_ts[0].checked) { - return true; - } - else { - alert("Please select all contacts for this action.\n\nTo use the entire set of search results, click the 'all records' radio button."); - return false; - } - } - gotTask = 1; - } - } - - if (gotTask == 1) { - // If user wants to perform action on ALL records and we have a task, return (no need to check further) - if (document.forms[form].radio_ts[0].checked) { - return true; - } - - cnt = (selection == 1) ? countSelections() : countSelectedCheckboxes(fldPrefix, document.forms[form]); - if (!cnt) { - alert("Please select one or more contacts for this action.\n\nTo use the entire set of search results, click the 'all records' radio button."); - return false; - } - } - else { - alert("Please select an action from the drop-down menu."); - return false; - } -} - /** * Function to enable task action select */ -- 2.25.1