2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2014 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
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-unclosed_case_id">
31 <td class="label">{$form.unclosed_case_id.label}</td>
32 <td>{$form.unclosed_case_id.html}</td>
34 <tr class="crm-case-activitytocase-form-block-target_contact_id">
35 <td class="label">{$form.target_contact_id.label}</td>
36 <td>{$form.target_contact_id.html}</td>
38 <tr class="crm-case-activitytocase-form-block-case_activity_subject">
39 <td class="label">{$form.case_activity_subject.label}</td>
40 <td>{$form.case_activity_subject.html}<br />
41 <span class="description">{ts}You can modify the activity subject before filing.{/ts}</span>
47 <script type="text/javascript">
48 var target_contact = '';
49 var target_contact_id = '';
50 var selectedCaseId = '';
53 $('input[name=unclosed_case_id]', '#fileOnCaseDialog').select2({
54 placeholder: {/literal}'{ts escape="js"}- select case -{/ts}'{literal},
55 minimumInputLength: 1,
57 url: {/literal}"{crmURL p='civicrm/case/ajax/unclosed' h=0}"{literal},
58 data: function(term) {
59 return {term: term, excludeCaseIds: "{/literal}{$currentCaseId}{literal}"};
61 results: function(response) {
62 return {results: response};
65 }).change(function() {
67 selectedCaseId = $(this).val();
68 contactId = $(this).select2('data').extra.contact_id;
73 {if $targetContactValues}
74 {foreach from=$targetContactValues key=id item=name}
76 target_contact += '{"name":"'+{/literal}"{$name}"{literal}+'","id":"'+{/literal}"{$id}"{literal}+'"},';
80 eval( 'target_contact = [' + target_contact + ']');
84 {if $form.target_contact_id.value}
86 var toDataUrl = "{/literal}{crmURL p='civicrm/ajax/checkemail' q='id=1&noemail=1' h=0 }{literal}";
87 var target_contact_id = cj.ajax({ url: toDataUrl + "&cid={/literal}{$form.$currentElement.value}{literal}", async: false }).responseText;
92 if ( target_contact_id ) {
93 eval( 'target_contact = ' + target_contact_id );
96 var tokenDataUrl = "{/literal}{$tokenUrl}{literal}";
97 var hintText = "{/literal}{ts escape='js'}Type in a partial or complete name or email address of an existing contact.{/ts}{literal}";
98 cj( "#target_contact_id" ).tokenInput(tokenDataUrl,{prePopulate: target_contact, theme: 'facebook', hintText: hintText });
99 cj( 'ul.token-input-list-facebook, div.token-input-dropdown-facebook' ).css( 'width', '450px' );
101 cj( "#fileOnCaseDialog" ).hide( );
108 {* Markup and js to go on the main page for loading the above form in a popup *}
109 <div id="fileOnCaseDialog"></div>
111 <script type="text/javascript">
112 function fileOnCase( action, activityID, currentCaseId ) {
113 if ( action == "move" ) {
114 var dialogTitle = "{/literal}{ts escape='js'}Move to Case{/ts}{literal}";
115 } else if ( action == "copy" ) {
116 var dialogTitle = "{/literal}{ts escape='js'}Copy to Case{/ts}{literal}";
117 } else if ( action == "file" ) {
118 var dialogTitle = "{/literal}{ts escape='js'}File On Case{/ts}{literal}";
121 var dataUrl = {/literal}"{crmURL p='civicrm/case/addToCase' q='reset=1&snippet=4' h=0}"{literal};
122 dataUrl += '&activityId=' + activityID + '&caseId=' + currentCaseId + '&cid=' + {/literal}"{$contactID}"{literal};
126 success : function ( content ) {
127 cj("#fileOnCaseDialog").show( ).html( content ).dialog({
132 close: function( event, ui ) {
133 cj('input[name=unclosed_case_id]', '#fileOnCaseDialog').select2('destroy');
134 cj(this).hide().dialog("destroy");
141 "{/literal}{ts escape='js'}Ok{/ts}{literal}": function() {
142 var subject = cj("#case_activity_subject").val( );
143 var targetContactId = cj("#target_contact_id").val( );
145 if ( !cj("#unclosed_cases").val( ) ) {
146 cj("#unclosed_cases").crmError('{/literal}{ts escape="js"}Please select a case from the list{/ts}{literal}.');
150 cj(this).dialog("destroy");
152 var postUrl = {/literal}"{crmURL p='civicrm/ajax/activity/convert' h=0 }"{literal};
153 cj.post( postUrl, { activityID: activityID, caseID: selectedCaseId, contactID: contactId, newSubject: subject, targetContactIds: targetContactId, mode: action, key: {/literal}"{crmKey name='civicrm/ajax/activity/convert'}"{literal} },
155 if ( values.error_msg ) {
156 cj().crmError(values.error_msg, "{/literal}{ts escape='js'}Unable to file on case{/ts}{literal}.");
159 var destUrl = {/literal}"{crmURL p='civicrm/contact/view/case' q='reset=1&action=view&id=' h=0 }"{literal};
161 {/literal}{if !empty($fulltext)}{literal}
162 context = '&context={/literal}{$fulltext}{literal}';
163 {/literal}{/if}{literal}
164 var caseUrl = destUrl + selectedCaseId + '&cid=' + contactId + context;
165 var redirectToCase = false;
166 var reloadWindow = false;
167 if ( action == 'move' ) redirectToCase = true;
168 if ( action == 'file' ) {
169 var curPath = document.location.href;
170 if ( curPath.indexOf( 'civicrm/contact/view' ) != -1 ) {
171 //hide current activity row.
172 cj( "#crm-activity_" + activityID ).hide( );
173 var visibleRowCount = 0;
174 cj('[id^="'+ 'crm-activity' +'"]:visible').each(function() {
177 if ( visibleRowCount < 1 ) {
181 if ( ( curPath.indexOf( 'civicrm/contact/view/activity' ) != -1 ) ||
182 ( curPath.indexOf( 'civicrm/activity' ) != -1 ) ) {
183 redirectToCase = true;
187 if ( redirectToCase ) {
188 window.location.href = caseUrl;
189 } else if ( reloadWindow ) {
190 window.location.reload( );
192 var activitySubject = cj("#case_activity_subject").val( );
193 var statusMsg = activitySubject + '" has been filed to selected case: <a href="' + caseUrl + '">' + cj("#unclosed_cases").val( ) + '</a>.';
194 CRM.alert(statusMsg, '{/literal}{ts escape="js"}Activity Filed{/ts}{literal}', 'success');
201 "{/literal}{ts escape='js'}Cancel{/ts}{literal}": function() {
202 cj(this).dialog("close");
203 cj(this).dialog("destroy");