Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
819d0d41 | 3 | | CiviCRM version 4.5 | |
6a488035 | 4 | +--------------------------------------------------------------------+ |
819d0d41 | 5 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | *} | |
cf111af5 | 26 | {* CiviCase - assign activity to case form *} |
6a488035 | 27 | {if !empty($buildCaseActivityForm)} |
cf111af5 CW |
28 | <div class="crm-block crm-form-block crm-case-activitytocase-form-block"> |
29 | <table class="form-layout"> | |
f72119d9 CW |
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> | |
cf111af5 CW |
33 | </tr> |
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> | |
37 | </tr> | |
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 /> | |
6a488035 | 41 | <span class="description">{ts}You can modify the activity subject before filing.{/ts}</span> |
cf111af5 CW |
42 | </td> |
43 | </tr> | |
44 | </table> | |
45 | </div> | |
6a488035 | 46 | {literal} |
cf111af5 CW |
47 | <script type="text/javascript"> |
48 | var target_contact = ''; | |
49 | var target_contact_id = ''; | |
50 | var selectedCaseId = ''; | |
51 | var contactId = ''; | |
3cc60a06 | 52 | CRM.$(function($) { |
a243158e | 53 | $('input[name=unclosed_case_id]', '#fileOnCaseDialog').crmSelect2({ |
f72119d9 CW |
54 | placeholder: {/literal}'{ts escape="js"}- select case -{/ts}'{literal}, |
55 | minimumInputLength: 1, | |
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 | }); | |
cf111af5 CW |
71 | }); |
72 | {/literal} | |
73 | {if $targetContactValues} | |
74 | {foreach from=$targetContactValues key=id item=name} | |
75 | {literal} | |
76 | target_contact += '{"name":"'+{/literal}"{$name}"{literal}+'","id":"'+{/literal}"{$id}"{literal}+'"},'; | |
77 | {/literal} | |
78 | {/foreach} | |
79 | {literal} | |
80 | eval( 'target_contact = [' + target_contact + ']'); | |
81 | {/literal} | |
82 | {/if} | |
83 | ||
84 | {if $form.target_contact_id.value} | |
85 | {literal} | |
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; | |
88 | {/literal} | |
89 | {/if} | |
90 | ||
91 | {literal} | |
92 | if ( target_contact_id ) { | |
93 | eval( 'target_contact = ' + target_contact_id ); | |
94 | } | |
6a488035 | 95 | |
cf111af5 CW |
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' ); | |
6a488035 | 100 | |
cf111af5 | 101 | cj( "#fileOnCaseDialog" ).hide( ); |
6a488035 | 102 | |
cf111af5 | 103 | </script> |
6a488035 | 104 | {/literal} |
cf111af5 | 105 | {* main form end *} |
6a488035 | 106 | |
cf111af5 CW |
107 | {else} |
108 | {* Markup and js to go on the main page for loading the above form in a popup *} | |
109 | <div id="fileOnCaseDialog"></div> | |
6a488035 TO |
110 | {literal} |
111 | <script type="text/javascript"> | |
cf111af5 | 112 | function fileOnCase( action, activityID, currentCaseId ) { |
6a488035 | 113 | if ( action == "move" ) { |
cf111af5 | 114 | var dialogTitle = "{/literal}{ts escape='js'}Move to Case{/ts}{literal}"; |
6a488035 | 115 | } else if ( action == "copy" ) { |
cf111af5 | 116 | var dialogTitle = "{/literal}{ts escape='js'}Copy to Case{/ts}{literal}"; |
6a488035 | 117 | } else if ( action == "file" ) { |
cf111af5 | 118 | var dialogTitle = "{/literal}{ts escape='js'}File On Case{/ts}{literal}"; |
6a488035 TO |
119 | } |
120 | ||
121 | var dataUrl = {/literal}"{crmURL p='civicrm/case/addToCase' q='reset=1&snippet=4' h=0}"{literal}; | |
cf111af5 | 122 | dataUrl += '&activityId=' + activityID + '&caseId=' + currentCaseId + '&cid=' + {/literal}"{$contactID}"{literal}; |
6a488035 TO |
123 | |
124 | cj.ajax({ | |
cf111af5 CW |
125 | url : dataUrl, |
126 | success : function ( content ) { | |
127 | cj("#fileOnCaseDialog").show( ).html( content ).dialog({ | |
128 | title: dialogTitle, | |
129 | modal: true, | |
130 | width: 600, | |
a243158e | 131 | height: 'auto', |
cf111af5 | 132 | close: function( event, ui ) { |
0d3f468f | 133 | cj('input[name=unclosed_case_id]', '#fileOnCaseDialog').select2('destroy'); |
cf111af5 CW |
134 | cj(this).hide().dialog("destroy"); |
135 | }, | |
136 | open: function() { | |
137 | ||
138 | }, | |
139 | ||
140 | buttons: { | |
a243158e | 141 | "{/literal}{ts escape='js'}Save{/ts}{literal}": function() { |
cf111af5 CW |
142 | var subject = cj("#case_activity_subject").val( ); |
143 | var targetContactId = cj("#target_contact_id").val( ); | |
144 | ||
145 | if ( !cj("#unclosed_cases").val( ) ) { | |
146 | cj("#unclosed_cases").crmError('{/literal}{ts escape="js"}Please select a case from the list{/ts}{literal}.'); | |
147 | return false; | |
148 | } | |
149 | ||
a243158e | 150 | cj(this).dialog("close"); |
cf111af5 CW |
151 | |
152 | var postUrl = {/literal}"{crmURL p='civicrm/ajax/activity/convert' h=0 }"{literal}; | |
6a488035 | 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} }, |
cf111af5 CW |
154 | function( values ) { |
155 | if ( values.error_msg ) { | |
6a488035 | 156 | cj().crmError(values.error_msg, "{/literal}{ts escape='js'}Unable to file on case{/ts}{literal}."); |
cf111af5 CW |
157 | return false; |
158 | } else { | |
6a488035 | 159 | var destUrl = {/literal}"{crmURL p='civicrm/contact/view/case' q='reset=1&action=view&id=' h=0 }"{literal}; |
cf111af5 CW |
160 | var context = ''; |
161 | {/literal}{if !empty($fulltext)}{literal} | |
6a488035 | 162 | context = '&context={/literal}{$fulltext}{literal}'; |
cf111af5 CW |
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; | |
6a488035 | 170 | if ( curPath.indexOf( 'civicrm/contact/view' ) != -1 ) { |
cf111af5 CW |
171 | //hide current activity row. |
172 | cj( "#crm-activity_" + activityID ).hide( ); | |
173 | var visibleRowCount = 0; | |
174 | cj('[id^="'+ 'crm-activity' +'"]:visible').each(function() { | |
175 | visibleRowCount++; | |
176 | } ); | |
177 | if ( visibleRowCount < 1 ) { | |
178 | reloadWindow = true; | |
179 | } | |
6a488035 | 180 | } |
cf111af5 CW |
181 | if ( ( curPath.indexOf( 'civicrm/contact/view/activity' ) != -1 ) || |
182 | ( curPath.indexOf( 'civicrm/activity' ) != -1 ) ) { | |
183 | redirectToCase = true; | |
184 | } | |
185 | } | |
186 | ||
187 | if ( redirectToCase ) { | |
188 | window.location.href = caseUrl; | |
189 | } else if ( reloadWindow ) { | |
6a488035 | 190 | window.location.reload( ); |
cf111af5 | 191 | } else { |
6a488035 TO |
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'); | |
195 | ||
6a488035 | 196 | } |
cf111af5 CW |
197 | } |
198 | } | |
6a488035 | 199 | ); |
cf111af5 CW |
200 | }, |
201 | "{/literal}{ts escape='js'}Cancel{/ts}{literal}": function() { | |
202 | cj(this).dialog("close"); | |
cf111af5 CW |
203 | } |
204 | } | |
205 | ||
206 | }); | |
6a488035 | 207 | } |
cf111af5 CW |
208 | }); |
209 | } | |
6a488035 TO |
210 | </script> |
211 | {/literal} | |
cf111af5 | 212 | {/if} |