| 1 | {* |
| 2 | +--------------------------------------------------------------------+ |
| 3 | | CiviCRM version 4.7 | |
| 4 | +--------------------------------------------------------------------+ |
| 5 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 6 | +--------------------------------------------------------------------+ |
| 7 | | This file is a part of CiviCRM. | |
| 8 | | | |
| 9 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 10 | | under the terms of the GNU Affero General Public License | |
| 11 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 12 | | | |
| 13 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 14 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 16 | | See the GNU Affero General Public License for more details. | |
| 17 | | | |
| 18 | | You should have received a copy of the GNU Affero General Public | |
| 19 | | License and the CiviCRM Licensing Exception along | |
| 20 | | with this program; if not, contact CiviCRM LLC | |
| 21 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 22 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 24 | +--------------------------------------------------------------------+ |
| 25 | *} |
| 26 | {* CiviCase - assign activity to case form *} |
| 27 | {if !empty($buildCaseActivityForm)} |
| 28 | <div class="crm-block crm-form-block crm-case-activitytocase-form-block"> |
| 29 | <table class="form-layout"> |
| 30 | <tr class="crm-case-activitytocase-form-block-file_on_case_unclosed_case_id"> |
| 31 | <td class="label">{$form.file_on_case_unclosed_case_id.label}</td> |
| 32 | <td>{$form.file_on_case_unclosed_case_id.html}</td> |
| 33 | </tr> |
| 34 | <tr class="crm-case-activitytocase-form-block-file_on_case_target_contact_id"> |
| 35 | <td class="label">{$form.file_on_case_target_contact_id.label}</td> |
| 36 | <td>{$form.file_on_case_target_contact_id.html}</td> |
| 37 | </tr> |
| 38 | <tr class="crm-case-activitytocase-form-block-file_on_case_activity_subject"> |
| 39 | <td class="label">{$form.file_on_case_activity_subject.label}</td> |
| 40 | <td>{$form.file_on_case_activity_subject.html}<br /> |
| 41 | <span class="description">{ts}You can modify the activity subject before filing.{/ts}</span> |
| 42 | </td> |
| 43 | </tr> |
| 44 | </table> |
| 45 | </div> |
| 46 | {literal} |
| 47 | <script type="text/javascript"> |
| 48 | CRM.$(function($) { |
| 49 | var $form = $('form.{/literal}{$form.formClass}{literal}'); |
| 50 | $('input[name=file_on_case_unclosed_case_id]', $form).crmSelect2({ |
| 51 | placeholder: {/literal}'{ts escape="js"}- select case -{/ts}'{literal}, |
| 52 | minimumInputLength: 1, |
| 53 | formatResult: CRM.utils.formatSelect2Result, |
| 54 | formatSelection: function(row) { |
| 55 | return row.label; |
| 56 | }, |
| 57 | initSelection: function($el, callback) { |
| 58 | callback($el.data('value')); |
| 59 | }, |
| 60 | ajax: { |
| 61 | url: {/literal}"{crmURL p='civicrm/case/ajax/unclosed' h=0}"{literal}, |
| 62 | data: function(term) { |
| 63 | return {term: term, excludeCaseIds: "{/literal}{$currentCaseId}{literal}"}; |
| 64 | }, |
| 65 | results: function(response) { |
| 66 | return {results: response}; |
| 67 | } |
| 68 | } |
| 69 | }); |
| 70 | }); |
| 71 | </script> |
| 72 | {/literal} |
| 73 | {* main form end *} |
| 74 | |
| 75 | {else} |
| 76 | {* Markup and js to go on the main page for loading the above form in a popup *} |
| 77 | {literal} |
| 78 | <script type="text/javascript"> |
| 79 | (function($) { |
| 80 | window.fileOnCase = function(action, activityID, currentCaseId, a) { |
| 81 | if ( action == "move" ) { |
| 82 | var dialogTitle = "{/literal}{ts escape='js'}Move to Case{/ts}{literal}"; |
| 83 | } else if ( action == "copy" ) { |
| 84 | var dialogTitle = "{/literal}{ts escape='js'}Copy to Case{/ts}{literal}"; |
| 85 | } else if ( action == "file" ) { |
| 86 | var dialogTitle = "{/literal}{ts escape='js'}File on Case{/ts}{literal}"; |
| 87 | } |
| 88 | |
| 89 | var dataUrl = {/literal}"{crmURL p='civicrm/case/addToCase' q='reset=1' h=0}"{literal}; |
| 90 | dataUrl += '&activityId=' + activityID + '&caseId=' + currentCaseId + '&cid=' + {/literal}"{$contactID}"{literal}; |
| 91 | |
| 92 | function save() { |
| 93 | var $context = $('div.crm-confirm-dialog'), |
| 94 | selectedCaseId = $('input[name=file_on_case_unclosed_case_id]', $context).val(), |
| 95 | caseTitle = $('input[name=file_on_case_unclosed_case_id]', $context).select2('data').label, |
| 96 | contactId = $('input[name=file_on_case_unclosed_case_id]', $context).select2('data').extra.contact_id, |
| 97 | subject = $("#file_on_case_activity_subject").val(), |
| 98 | targetContactId = $("#file_on_case_target_contact_id").val(); |
| 99 | |
| 100 | if (!$("#file_on_case_unclosed_case_id").val()) { |
| 101 | $("#file_on_case_unclosed_case_id").crmError('{/literal}{ts escape="js"}Please select a case from the list{/ts}{literal}.'); |
| 102 | return false; |
| 103 | } |
| 104 | |
| 105 | var postUrl = {/literal}"{crmURL p='civicrm/ajax/activity/convert' h=0 }"{literal}; |
| 106 | $.post( postUrl, { activityID: activityID, caseID: selectedCaseId, contactID: contactId, newSubject: subject, targetContactIds: targetContactId, mode: action, key: {/literal}"{crmKey name='civicrm/ajax/activity/convert'}"{literal} }, |
| 107 | function( values ) { |
| 108 | if ( values.error_msg ) { |
| 109 | $().crmError(values.error_msg, "{/literal}{ts escape='js'}Unable to file on case.{/ts}{literal}"); |
| 110 | } else { |
| 111 | var destUrl = {/literal}"{crmURL p='civicrm/contact/view/case' q='reset=1&action=view&id=' h=0 }"{literal}; |
| 112 | var context = ''; |
| 113 | {/literal}{if !empty($fulltext)}{literal} |
| 114 | context = '&context={/literal}{$fulltext}{literal}'; |
| 115 | {/literal}{/if}{literal} |
| 116 | var caseUrl = destUrl + selectedCaseId + '&cid=' + contactId + context; |
| 117 | |
| 118 | var statusMsg = {/literal}'{ts escape='js' 1='%1'}Activity has been filed to %1 case.{/ts}'{literal}; |
| 119 | CRM.alert(ts(statusMsg, {1: '<a href="' + caseUrl + '">' + caseTitle + '</a>'}), '{/literal}{ts escape="js"}Saved{/ts}{literal}', 'success'); |
| 120 | CRM.refreshParent(a); |
| 121 | } |
| 122 | } |
| 123 | ); |
| 124 | } |
| 125 | |
| 126 | CRM.confirm({ |
| 127 | title: dialogTitle, |
| 128 | width: '600', |
| 129 | resizable: true, |
| 130 | options: {yes: "{/literal}{ts escape='js'}Save{/ts}{literal}", no: "{/literal}{ts escape='js'}Cancel{/ts}{literal}"}, |
| 131 | url: dataUrl |
| 132 | }).on('crmConfirm:yes', save); |
| 133 | |
| 134 | } |
| 135 | })(CRM.$); |
| 136 | </script> |
| 137 | {/literal} |
| 138 | {/if} |