1f5a9da24bff5d63da4788ef34cfa471f64e1e5a
[civicrm-core.git] / templates / CRM / Case / Form / ActivityToCase.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2014 |
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 $('input[name=file_on_case_unclosed_case_id]', '#fileOnCaseDialog').crmSelect2({
50 placeholder: {/literal}'{ts escape="js"}- select case -{/ts}'{literal},
51 minimumInputLength: 1,
52 formatResult: CRM.utils.formatSelect2Result,
53 formatSelection: function(row) {
54 return row.label;
55 },
56 ajax: {
57 url: {/literal}"{crmURL p='civicrm/case/ajax/unclosed' h=0}"{literal},
58 data: function(term) {
59 return {term: term, excludeCaseIds: "{/literal}{$currentCaseId}{literal}"};
60 },
61 results: function(response) {
62 return {results: response};
63 }
64 }
65 }).change(function() {
66 if ($(this).val()) {
67 selectedCaseId = $(this).val();
68 contactId = $(this).select2('data').extra.contact_id;
69 }
70 });
71 });
72
73 cj( "#fileOnCaseDialog" ).hide( );
74
75 </script>
76 {/literal}
77 {* main form end *}
78
79 {else}
80 {* Markup and js to go on the main page for loading the above form in a popup *}
81 <div id="fileOnCaseDialog"></div>
82 {literal}
83 <script type="text/javascript">
84 function fileOnCase( action, activityID, currentCaseId ) {
85 if ( action == "move" ) {
86 var dialogTitle = "{/literal}{ts escape='js'}Move to Case{/ts}{literal}";
87 } else if ( action == "copy" ) {
88 var dialogTitle = "{/literal}{ts escape='js'}Copy to Case{/ts}{literal}";
89 } else if ( action == "file" ) {
90 var dialogTitle = "{/literal}{ts escape='js'}File On Case{/ts}{literal}";
91 }
92
93 var dataUrl = {/literal}"{crmURL p='civicrm/case/addToCase' q='reset=1&snippet=4' h=0}"{literal};
94 dataUrl += '&activityId=' + activityID + '&caseId=' + currentCaseId + '&cid=' + {/literal}"{$contactID}"{literal};
95
96 cj.ajax({
97 url : dataUrl,
98 success : function ( content ) {
99 cj("#fileOnCaseDialog").show( ).html( content).trigger('crmLoad').dialog({
100 title: dialogTitle,
101 modal: true,
102 width: 600,
103 height: 'auto',
104 close: function( event, ui ) {
105 cj('input[name=file_on_case_unclosed_case_id]', '#fileOnCaseDialog').select2('destroy');
106 cj(this).hide().dialog("destroy");
107 },
108 buttons: {
109 "{/literal}{ts escape='js'}Save{/ts}{literal}": function() {
110 var subject = cj("#file_on_case_activity_subject").val( );
111 var targetContactId = cj("#file_on_case_target_contact_id").val( );
112
113 if ( !cj("#file_on_case_unclosed_case_id").val( ) ) {
114 cj("#file_on_case_unclosed_case_id").crmError('{/literal}{ts escape="js"}Please select a case from the list{/ts}{literal}.');
115 return false;
116 }
117
118 cj(this).dialog("close");
119
120 var postUrl = {/literal}"{crmURL p='civicrm/ajax/activity/convert' h=0 }"{literal};
121 cj.post( postUrl, { activityID: activityID, caseID: selectedCaseId, contactID: contactId, newSubject: subject, targetContactIds: targetContactId, mode: action, key: {/literal}"{crmKey name='civicrm/ajax/activity/convert'}"{literal} },
122 function( values ) {
123 if ( values.error_msg ) {
124 cj().crmError(values.error_msg, "{/literal}{ts escape='js'}Unable to file on case{/ts}{literal}.");
125 return false;
126 } else {
127 var destUrl = {/literal}"{crmURL p='civicrm/contact/view/case' q='reset=1&action=view&id=' h=0 }"{literal};
128 var context = '';
129 {/literal}{if !empty($fulltext)}{literal}
130 context = '&context={/literal}{$fulltext}{literal}';
131 {/literal}{/if}{literal}
132 var caseUrl = destUrl + selectedCaseId + '&cid=' + contactId + context;
133 var redirectToCase = false;
134 var reloadWindow = false;
135 if ( action == 'move' ) redirectToCase = true;
136 if ( action == 'file' ) {
137 var curPath = document.location.href;
138 if ( curPath.indexOf( 'civicrm/contact/view' ) != -1 ) {
139 //hide current activity row.
140 cj( "#crm-activity_" + activityID ).hide( );
141 var visibleRowCount = 0;
142 cj('[id^="'+ 'crm-activity' +'"]:visible').each(function() {
143 visibleRowCount++;
144 } );
145 if ( visibleRowCount < 1 ) {
146 reloadWindow = true;
147 }
148 }
149 if ( ( curPath.indexOf( 'civicrm/contact/view/activity' ) != -1 ) ||
150 ( curPath.indexOf( 'civicrm/activity' ) != -1 ) ) {
151 redirectToCase = true;
152 }
153 }
154
155 if ( redirectToCase ) {
156 window.location.href = caseUrl;
157 } else if ( reloadWindow ) {
158 window.location.reload( );
159 } else {
160 var activitySubject = cj("#file_on_case_activity_subject").val( );
161 var statusMsg = activitySubject + '" has been filed to selected case: <a href="' + caseUrl + '">' + cj("#unclosed_cases").val( ) + '</a>.';
162 CRM.alert(statusMsg, '{/literal}{ts escape="js"}Activity Filed{/ts}{literal}', 'success');
163
164 }
165 }
166 }
167 );
168 },
169 "{/literal}{ts escape='js'}Cancel{/ts}{literal}": function() {
170 cj(this).dialog("close");
171 }
172 }
173
174 });
175 }
176 });
177 }
178 </script>
179 {/literal}
180 {/if}