From 66adc860cc410a3ab2aa57f80edacbb24faae981 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 17 Mar 2014 16:28:10 -0400 Subject: [PATCH] CRM-13966 - Simplify reassign case form with ajax framework and select2 --- CRM/Case/Form/CaseView.php | 21 --------- CRM/Case/Form/EditClient.php | 56 ++++++++++++---------- templates/CRM/Case/Form/CaseView.tpl | 25 +--------- templates/CRM/Case/Form/EditClient.tpl | 65 +++++--------------------- 4 files changed, 46 insertions(+), 121 deletions(-) diff --git a/CRM/Case/Form/CaseView.php b/CRM/Case/Form/CaseView.php index 7302e9a3fd..903fa6abb3 100644 --- a/CRM/Case/Form/CaseView.php +++ b/CRM/Case/Form/CaseView.php @@ -315,17 +315,6 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form { } } - $this->add('text', 'change_client_id', ts('Assign to another Client')); - $this->add('hidden', 'contact_id', '', array('id' => 'contact_id')); - $this->addElement('submit', - $this->getButtonName('next', 'edit_client'), - ts('Reassign Case'), - array( - 'class' => 'form-submit-inline', - 'onclick' => "return checkSelection( this );", - ) - ); - $activityStatus = CRM_Core_PseudoConstant::activityStatus(); $this->add('select', 'status_id', ts('Status'), array("" => ts(' - any status - ')) + $activityStatus); @@ -522,16 +511,6 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form { $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); } - elseif ($buttonName == '_qf_CaseView_next_edit_client') { - $mainCaseId = CRM_Case_BAO_Case::mergeCases($params['contact_id'], $this->_caseID, $this->_contactID, NULL, TRUE); - - // user context - $url = CRM_Utils_System::url('civicrm/contact/view/case', - "reset=1&action=view&cid={$params['contact_id']}&id={$mainCaseId[0]}&show=1" - ); - $session = CRM_Core_Session::singleton(); - $session->pushUserContext($url); - } } } diff --git a/CRM/Case/Form/EditClient.php b/CRM/Case/Form/EditClient.php index 06844eeabf..a314700f6a 100644 --- a/CRM/Case/Form/EditClient.php +++ b/CRM/Case/Form/EditClient.php @@ -46,15 +46,15 @@ class CRM_Case_Form_EditClient extends CRM_Core_Form { * @access public */ public function preProcess() { - $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); - $this->_caseId = CRM_Utils_Request::retrieve('id', 'Positive', $this); - $context = CRM_Utils_Request::retrieve('context', 'String', $this); + $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); + CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); + $context = CRM_Utils_Request::retrieve('context', 'String', $this); //get current client name. - $this->assign('currentClientName', CRM_Contact_BAO_Contact::displayName($this->_contactId)); + $this->assign('currentClientName', CRM_Contact_BAO_Contact::displayName($cid)); //set the context. - $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactId}&selectedChild=case"); + $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$cid}&selectedChild=case"); if ($context == 'search') { $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); //validate the qfKey @@ -82,24 +82,33 @@ class CRM_Case_Form_EditClient extends CRM_Core_Form { * @access public */ public function buildQuickForm() { - $this->add('text', 'change_client_id', ts('Select Contact')); - $this->add('hidden', 'contact_id', '', array('id' => 'contact_id')); - $this->addElement('submit', - $this->getButtonName('next', 'edit_client'), - ts('Reassign Case'), + $this->addEntityRef('reassign_contact_id', ts('Select Contact'), array('create' => TRUE), TRUE); + $this->addButtons(array( array( - 'class' => 'form-submit-inline', - 'onclick' => "return checkSelection( this );", - ) - ); + 'type' => 'cancel', + 'name' => ts('Cancel'), + ), + array( + 'type' => 'done', + 'name' => ts('Reassign Case'), + ), + )); + + // This form may change the url structure so should not submit via ajax + $this->preventAjaxSubmit(); + } - $this->addElement('submit', - $this->getButtonName('cancel', 'edit_client'), - ts('Cancel'), - array('class' => 'form-submit-inline') - ); - $this->assign('contactId', $this->_contactId); + function addRules() { + $this->addFormRule(array(get_class($this), 'formRule'), $this); + } + + static function formRule($vals, $rule, $form) { + $errors = array(); + if (empty($vals['reassign_contact_id']) || $vals['reassign_contact_id'] == $form->get('cid')) { + $errors['reassign_contact_id'] = ts("Please select a different contact."); + } + return $errors; } /** @@ -112,14 +121,13 @@ class CRM_Case_Form_EditClient extends CRM_Core_Form { $params = $this->controller->exportValues($this->_name); //assign case to another client. - $mainCaseId = CRM_Case_BAO_Case::mergeCases($params['contact_id'], $this->_caseId, $this->_contactId, NULL, TRUE); + $mainCaseId = CRM_Case_BAO_Case::mergeCases($params['reassign_contact_id'], $this->get('id'), $this->get('cid'), NULL, TRUE); // user context $url = CRM_Utils_System::url('civicrm/contact/view/case', - "reset=1&action=view&cid={$params['contact_id']}&id={$mainCaseId[0]}&show=1" + "reset=1&action=view&cid={$params['reassign_contact_id']}&id={$mainCaseId[0]}&show=1" ); - $session = CRM_Core_Session::singleton(); - $session->pushUserContext($url); + CRM_Core_Session::singleton()->pushUserContext($url); } } diff --git a/templates/CRM/Case/Form/CaseView.tpl b/templates/CRM/Case/Form/CaseView.tpl index dceb9e4311..4f0402b89e 100644 --- a/templates/CRM/Case/Form/CaseView.tpl +++ b/templates/CRM/Case/Form/CaseView.tpl @@ -130,10 +130,8 @@ {if call_user_func(array('CRM_Core_Permission','giveMeAllACLs'))} - {ts}Assign to Another Contact{/ts} - - {$form.change_client_id.html|crmAddClass:twenty} {$form._qf_CaseView_next_edit_client.html} - + + {ts}Assign to Another Contact{/ts} {/if} @@ -282,12 +280,6 @@ {literal} -{/literal} -- 2.25.1