Merge pull request #1105 from colemanw/prevNext
[civicrm-core.git] / templates / CRM / Case / Form / ActivityToCase.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.3 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
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 - build activity to a case*}
27<div id="fileOnCaseDialog"></div>
28
29{if !empty($buildCaseActivityForm)}
30<div class="crm-block crm-form-block crm-case-activitytocase-form-block">
31<table class="form-layout">
32 <tr class="crm-case-activitytocase-form-block-unclosed_cases">
33 <td class="label">{$form.unclosed_cases.label}</td>
34 <td>{$form.unclosed_cases.html}<br />
35 <span class="description">{ts}Begin typing client name for a list of open cases.{/ts}</span>
36 </td>
37 </tr>
38 <tr class="crm-case-activitytocase-form-block-target_contact_id">
39 <td class="label">{$form.target_contact_id.label}</td>
40 <td>{$form.target_contact_id.html}</td>
41 </tr>
42 <tr class="crm-case-activitytocase-form-block-case_activity_subject">
43 <td class="label">{$form.case_activity_subject.label}</td>
44 <td>{$form.case_activity_subject.html}<br />
45 <span class="description">{ts}You can modify the activity subject before filing.{/ts}</span>
46 </td>
47 </tr>
48</table>
49</div>
50{literal}
51<script type="text/javascript">
52var target_contact = '';
53var target_contact_id = '';
54var selectedCaseId = '';
55var contactId = '';
56
57var unclosedCaseUrl = {/literal}"{crmURL p='civicrm/case/ajax/unclosed' h=0 q='excludeCaseIds='}{$currentCaseId}"{literal};
58cj( "#unclosed_cases" ).autocomplete( unclosedCaseUrl, { width : 250, selectFirst : false, matchContains:true
59 }).result( function(event, data, formatted) {
60 cj( "#unclosed_case_id" ).val( data[1] );
61 contactId = data[2];
62 selectedCaseId = data[1];
63 }).bind( 'click', function( ) {
64 cj( "#unclosed_case_id" ).val('');
65 contactId = selectedCaseId = '';
66 });
67{/literal}
68{if $targetContactValues}
69{foreach from=$targetContactValues key=id item=name}
70 {literal}
71 target_contact += '{"name":"'+{/literal}"{$name}"{literal}+'","id":"'+{/literal}"{$id}"{literal}+'"},';{/literal}
72{/foreach}
73 {literal}
74 eval( 'target_contact = [' + target_contact + ']');
75 {/literal}
76{/if}
77
78{if $form.target_contact_id.value}
79 {literal}
80 var toDataUrl = "{/literal}{crmURL p='civicrm/ajax/checkemail' q='id=1&noemail=1' h=0 }{literal}";
81 var target_contact_id = cj.ajax({ url: toDataUrl + "&cid={/literal}{$form.$currentElement.value}{literal}", async: false }).responseText;
82 {/literal}
83{/if}
84
85{literal}
86if ( target_contact_id ) {
87 eval( 'target_contact = ' + target_contact_id );
88}
89
90var tokenDataUrl = "{/literal}{$tokenUrl}{literal}";
91var hintText = "{/literal}{ts escape='js'}Type in a partial or complete name or email address of an existing contact.{/ts}{literal}";
92cj( "#target_contact_id" ).tokenInput(tokenDataUrl,{prePopulate: target_contact, theme: 'facebook', hintText: hintText });
93cj( 'ul.token-input-list-facebook, div.token-input-dropdown-facebook' ).css( 'width', '450px' );
94
95cj( "#fileOnCaseDialog" ).hide( );
96
97</script>
98{/literal}
99
100{/if} {* main form if end *}
101
102{literal}
103<script type="text/javascript">
104function fileOnCase( action, activityID, currentCaseId ) {
105 if ( action == "move" ) {
106 dialogTitle = "Move to Case";
107 } else if ( action == "copy" ) {
108 dialogTitle = "Copy to Case";
109 } else if ( action == "file" ) {
110 dialogTitle = "File On Case";
111 }
112
113 var dataUrl = {/literal}"{crmURL p='civicrm/case/addToCase' q='reset=1&snippet=4' h=0}"{literal};
114 dataUrl = dataUrl + '&activityId=' + activityID + '&caseId=' + currentCaseId + '&cid=' + {/literal}"{$contactID}"{literal};
115
116 cj.ajax({
117 url : dataUrl,
118 success : function ( content ) {
119 cj("#fileOnCaseDialog").show( ).html( content ).dialog({
120 title : dialogTitle,
121 modal : true,
122 bgiframe : true,
123 width : 600,
124 height : 270,
125 close : function( event, ui ) { cj( "#unclosed_cases" ).unautocomplete( ); },
126 overlay : { opacity: 0.5, background: "black" },
127 beforeclose : function( event, ui ) {
128 cj(this).dialog("destroy");
129 },
130 open : function() { },
131
132 buttons : {
133 "Ok": function() {
134 var subject = cj("#case_activity_subject").val( );
135 var targetContactId = cj("#target_contact_id").val( );
136
137 if ( !cj("#unclosed_cases").val( ) ) {
138 cj("#unclosed_cases").crmError('{/literal}{ts escape="js"}Please select a case from the list{/ts}{literal}.');
139 return false;
140 }
141
142 cj(this).dialog("destroy");
143
144 var postUrl = {/literal}"{crmURL p='civicrm/ajax/activity/convert' h=0 }"{literal};
145 cj.post( postUrl, { activityID: activityID, caseID: selectedCaseId, contactID: contactId, newSubject: subject, targetContactIds: targetContactId, mode: action, key: {/literal}"{crmKey name='civicrm/ajax/activity/convert'}"{literal} },
146 function( values ) {
147 if ( values.error_msg ) {
148 cj().crmError(values.error_msg, "{/literal}{ts escape='js'}Unable to file on case{/ts}{literal}.");
149 return false;
150 } else {
151 var destUrl = {/literal}"{crmURL p='civicrm/contact/view/case' q='reset=1&action=view&id=' h=0 }"{literal};
152 var context = '';
153 {/literal}{if !empty($fulltext)}{literal}
154 context = '&context={/literal}{$fulltext}{literal}';
155 {/literal}{/if}{literal}
156 var caseUrl = destUrl + selectedCaseId + '&cid=' + contactId + context;
157 var redirectToCase = false;
158 var reloadWindow = false;
159 if ( action == 'move' ) redirectToCase = true;
160 if ( action == 'file' ) {
161 var curPath = document.location.href;
162 if ( curPath.indexOf( 'civicrm/contact/view' ) != -1 ) {
163 //hide current activity row.
164 cj( "#crm-activity_" + activityID ).hide( );
165 var visibleRowCount = 0;
166 cj('[id^="'+ 'crm-activity' +'"]::visible').each(function() {
167 visibleRowCount++;
168 } );
169 if ( visibleRowCount < 1 ) {
170 reloadWindow = true;
171 }
172 }
173 if ( ( curPath.indexOf( 'civicrm/contact/view/activity' ) != -1 ) ||
174 ( curPath.indexOf( 'civicrm/activity' ) != -1 ) ) {
175 redirectToCase = true;
176 }
177 }
178
179 if ( redirectToCase ) {
180 window.location.href = caseUrl;
181 } else if ( reloadWindow ) {
182 window.location.reload( );
183 } else {
184 var activitySubject = cj("#case_activity_subject").val( );
185 var statusMsg = activitySubject + '" has been filed to selected case: <a href="' + caseUrl + '">' + cj("#unclosed_cases").val( ) + '</a>.';
186 CRM.alert(statusMsg, '{/literal}{ts escape="js"}Activity Filed{/ts}{literal}', 'success');
187
188 }
189 }
190 }
191 );
192 },
193
194 "Cancel": function() {
195 cj(this).dialog("close");
196 cj(this).dialog("destroy");
197 }
198 }
199
200 });
201 }
202 });
203}
204</script>
205{/literal}