*
* @return void
* @access public
- */ function preProcess() {
- /*
- * initialize the task and row fields
- */
-
+ */
+ function preProcess() {
parent::preProcess();
$session = CRM_Core_Session::singleton();
$this->_userContext = $session->readUserContext();
CRM_Utils_System::setTitle(ts('File on Case'));
-
- $validationFailed = FALSE;
-
- // insert validations here
-
- // then redirect
- if ($validationFailed) {
- CRM_Utils_System::redirect($this->_userContext);
- }
}
/**
* @return void
*/
function buildQuickForm() {
- $this->addElement('text', 'unclosed_cases', ts('Select Case'));
- $this->add('hidden', 'unclosed_case_id', '', array('id' => 'unclosed_case_id'));
+ $this->add('text', 'unclosed_case_id', ts('Select Case'), array('class' => 'huge'), TRUE);
$this->addDefaultButtons(ts('Continue >>'));
}
*
* @return void
*/
- function addRules() {
- $this->addFormRule(array('CRM_Activity_Form_Task_FileOnCase', 'formRule'));
- }
-
- /**
- * global validation rules for the form
- *
- * @param array $fields posted values of the form
- *
- * @return array list of errors to be posted back to the form
- * @static
- * @access public
- */
- static
- function formRule($fields) {
- $errors = array();
- if (empty($fields['unclosed_case_id'])) {
- $errors['unclosed_case_id'] = ts('Case is a required field.');
- }
- return $errors;
- }
+ function addRules() {}
/**
* process the form after the input has been submitted and validated
}
static function buildQuickForm(&$form) {
- $form->add('text', 'link_to_case', ts('Link To Case'));
- $form->add('hidden', 'link_to_case_id', '', array('id' => 'link_to_case_id'));
+ $form->add('text', 'link_to_case_id', ts('Link To Case'), array('class' => 'huge'), TRUE);
}
/**
$errors = array();
$linkCaseId = CRM_Utils_Array::value('link_to_case_id', $values);
- if (!$linkCaseId) {
- $errors['link_to_case'] = ts('Please select a case to link.');
- }
- elseif ($linkCaseId == $form->_caseId) {
+ if ($linkCaseId == $form->_caseId) {
$errors['link_to_case'] = ts('Please select some other case to link.');
}
// do check for existing related cases.
$relatedCases = $form->get('relatedCases');
if (is_array($relatedCases) && array_key_exists($linkCaseId, $relatedCases)) {
- $errors['link_to_case'] = ts('It looks like selected case is already linked.');
+ $errors['link_to_case'] = ts('Selected case is already linked.');
}
return empty($errors) ? TRUE : $errors;
*
* @access public
*
- * @return void
+ * @return array
*/
function setDefaultValues() {
$targetContactValues = $defaults = array();
$tokenUrl = CRM_Utils_System::url("civicrm/ajax/checkemail", "noemail=1", FALSE, NULL, FALSE);
$this->assign('tokenUrl', $tokenUrl);
- $this->add('text', 'unclosed_cases', ts('Select Case'));
- $this->add('hidden', 'unclosed_case_id', '', array('id' => 'open_case_id'));
+ $this->add('text', 'unclosed_case_id', ts('Select Case'), array('class' => 'huge'), TRUE);
$this->add('text', 'target_contact_id', ts('With Contact(s)'));
$this->add('text', 'case_activity_subject', ts('Subject'), array('size' => 50));
}
* Retrieve unclosed cases.
*/
static function unclosedCases() {
- $criteria = explode('-', CRM_Utils_Type::escape(CRM_Utils_Array::value('s', $_GET), 'String'));
-
- $limit = CRM_Utils_Array::value('limit', $_GET);
- if ($limit) {
- $limit = CRM_Utils_Type::escape($limit, 'Integer');
- }
-
$params = array(
- 'limit' => $limit,
- 'case_type' => trim(CRM_Utils_Array::value(1, $criteria)),
- 'sort_name' => trim(CRM_Utils_Array::value(0, $criteria)),
+ 'limit' => CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'search_autocomplete_count', NULL, 10),
+ 'sort_name' => CRM_Utils_Type::escape(CRM_Utils_Array::value('term', $_GET, ''), 'String'),
);
$excludeCaseIds = array();
- if ($caseIdStr = CRM_Utils_Array::value('excludeCaseIds', $_GET)) {
- $excludeIdStr = CRM_Utils_Type::escape($caseIdStr, 'String');
- $excludeCaseIds = explode(',', $excludeIdStr);
+ if (!empty($_GET['excludeCaseIds'])) {
+ $excludeCaseIds = explode(',', CRM_Utils_Type::escape($_GET['excludeCaseIds'], 'String'));
}
$unclosedCases = CRM_Case_BAO_Case::getUnclosedCases($params, $excludeCaseIds);
$results = array();
foreach ($unclosedCases as $caseId => $details) {
- $results["$caseId|" . $details['contact_id'] . '|' . $details['case_type'] . '|' . $details['sort_name']] = $details['sort_name'] . ' (' . $details['case_type'] . ': ' . $details['case_subject'] . ')';
+ $results[] = array(
+ 'id' => $caseId,
+ 'text' => $details['sort_name'] . ' (' . $details['case_type'] . ': ' . $details['case_subject'] . ')',
+ 'extra' => $details,
+ );
}
- CRM_Core_Page_AJAX::autocompleteResults($results);
+ print json_encode($results);
+ CRM_Utils_System::civiExit();
}
function processCaseTags() {
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
<table class="form-layout-compressed">
<tr class="crm-file-on-case-form-block-unclosed_cases">
- <td class="label">{$form.unclosed_cases.label}
- <span class="crm-marker" title="{ts}This field is required.{/ts}">*</span></td>
- <td>{$form.unclosed_cases.html}<br />
- <span class="description">{ts}Begin typing client name for a list of open cases.{/ts}</span>
+ <td class="label">
+ {$form.unclosed_case_id.label}
+ </td>
+ <td>
+ {$form.unclosed_case_id.html}<br />
</td>
</tr>
<tr>
</div>
{literal}
<script type="text/javascript">
-
-var unclosedCaseUrl = {/literal}"{crmURL p='civicrm/case/ajax/unclosed' h=0}"{literal};
-cj( "#unclosed_cases" ).autocomplete( unclosedCaseUrl, { width : 250, selectFirst : false, matchContains:true
- }).result( function(event, data, formatted) {
- cj( "#unclosed_case_id" ).val( data[1] );
- }).bind( 'click', function( ) {
- cj( "#unclosed_case_id" ).val('');
- });
+cj(function($) {
+ var $form = $("#{/literal}{$form.formName}{literal}");
+ $('input[name=unclosed_case_id]', $form).select2({
+ placeholder: {/literal}'{ts escape="js"}- select case -{/ts}'{literal},
+ minimumInputLength: 1,
+ ajax: {
+ url: {/literal}"{crmURL p='civicrm/case/ajax/unclosed' h=0}"{literal},
+ data: function(term) {
+ return {term: term};
+ },
+ results: function(response) {
+ return {results: response};
+ }
+ }
+ });
+});
{/literal}
</script>
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
-{* Template for to create a link between two cases. *}
+{* Template for to create a link between two cases. *}{debug}
<div class="crm-block crm-form-block crm-case-linkcases-form-block">
- <tr class="crm-case-linkcases-form-block-link_to_case">
- <td class="label">{$form.link_to_case.label}</td>
- <td>{$form.link_to_case.html}</td>
+ <tr class="crm-case-linkcases-form-block-link_to_case_id">
+ <td class="label">{$form.link_to_case_id.label}</td>
+ <td>{$form.link_to_case_id.html}</td>
</tr>
{literal}
<script type="text/javascript">
-var unclosedCaseUrl = {/literal}"{crmURL p='civicrm/case/ajax/unclosed' h=0 q='excludeCaseIds='}{$excludeCaseIds}{literal}";
-cj( "#link_to_case").autocomplete( unclosedCaseUrl, { width : 250, selectFirst : false, matchContains:true
- }).result( function(event, data, formatted) {
- cj( "#link_to_case_id" ).val( data[1] );
- var subject = {/literal}"Create link between {$client_name} - {$caseTypeLabel} (CaseID: {$caseId})"{literal} + ' AND ' + data[4] + ' - ' + data[3] + ' (CaseID: ' + data[1] + ')';
- cj( "#subject" ).val( subject );
- }).bind( 'click', function( ) {
- cj( "#link_to_case_id" ).val('');
- cj( "#subject" ).val( '' );
- });
+ cj(function($) {
+ var $form = $("#{/literal}{$form.formName}{literal}");
+ $('input[name=link_to_case_id]', $form).select2({
+ placeholder: {/literal}'{ts escape="js"}- select case -{/ts}'{literal},
+ minimumInputLength: 1,
+ ajax: {
+ url: {/literal}"{crmURL p='civicrm/case/ajax/unclosed' h=0}"{literal},
+ data: function(term) {
+ return {term: term, excludeCaseIds: "{/literal}{$excludeCaseIds}{literal}"};
+ },
+ results: function(response) {
+ return {results: response};
+ }
+ }
+ }).change(function() {
+ if ($(this).val()) {
+ var info = $(this).select2('data').extra;
+ {/literal}{* Mix in variables and placeholders for clientside substitution *}
+ var subject = "{ts escape=js 1="%1" 2="%2" 3="%3" 4=$client.sort_name 5=$caseTypeLabel 6=$caseId}Create link between %1 - %2 (CaseID: %3) and %4 - %5 (CaseID: %6){/ts}";
+ {literal}
+ $('#subject', $form).val(ts(subject, {1: info.sort_name, 2: info.case_type, 3: $(this).val()}));
+ }
+ });
+ });
</script>
{/literal}
</div>
{if !empty($buildCaseActivityForm)}
<div class="crm-block crm-form-block crm-case-activitytocase-form-block">
<table class="form-layout">
- <tr class="crm-case-activitytocase-form-block-unclosed_cases">
- <td class="label">{$form.unclosed_cases.label}</td>
- <td>{$form.unclosed_cases.html}<br />
- <span class="description">{ts}Begin typing client name for a list of open cases.{/ts}</span>
- </td>
+ <tr class="crm-case-activitytocase-form-block-unclosed_case_id">
+ <td class="label">{$form.unclosed_case_id.label}</td>
+ <td>{$form.unclosed_case_id.html}</td>
</tr>
<tr class="crm-case-activitytocase-form-block-target_contact_id">
<td class="label">{$form.target_contact_id.label}</td>
var target_contact_id = '';
var selectedCaseId = '';
var contactId = '';
-
- var unclosedCaseUrl = {/literal}"{crmURL p='civicrm/case/ajax/unclosed' h=0 q='excludeCaseIds='}{$currentCaseId}"{literal};
- cj( "#unclosed_cases" ).autocomplete( unclosedCaseUrl, { width : 250, selectFirst : false, matchContains:true
- }).result( function(event, data, formatted) {
- cj( "#unclosed_case_id" ).val( data[1] );
- contactId = data[2];
- selectedCaseId = data[1];
- }).bind( 'click', function( ) {
- cj( "#unclosed_case_id" ).val('');
- contactId = selectedCaseId = '';
+ cj(function($) {
+ $('input[name=unclosed_case_id]', '#fileOnCaseDialog').select2({
+ placeholder: {/literal}'{ts escape="js"}- select case -{/ts}'{literal},
+ minimumInputLength: 1,
+ ajax: {
+ url: {/literal}"{crmURL p='civicrm/case/ajax/unclosed' h=0}"{literal},
+ data: function(term) {
+ return {term: term, excludeCaseIds: "{/literal}{$currentCaseId}{literal}"};
+ },
+ results: function(response) {
+ return {results: response};
+ }
+ }
+ }).change(function() {
+ if ($(this).val()) {
+ selectedCaseId = $(this).val();
+ contactId = $(this).select2('data').extra.contact_id;
+ }
+ });
});
{/literal}
{if $targetContactValues}