Case view improvements
[civicrm-core.git] / templates / CRM / Case / Form / ActivityToCase.tpl
CommitLineData
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">
050fc124
CW
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>
cf111af5 33 </tr>
050fc124
CW
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>
cf111af5 37 </tr>
050fc124
CW
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 />
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 47 <script type="text/javascript">
3cc60a06 48 CRM.$(function($) {
050fc124 49 $('input[name=file_on_case_unclosed_case_id]', '#fileOnCaseDialog').crmSelect2({
f72119d9
CW
50 placeholder: {/literal}'{ts escape="js"}- select case -{/ts}'{literal},
51 minimumInputLength: 1,
3c0b6a40
CW
52 formatResult: CRM.utils.formatSelect2Result,
53 formatSelection: function(row) {
54 return row.label;
55 },
bd343dcc
CW
56 initSelection: function($el, callback) {
57 callback($el.data('value'));
58 },
f72119d9
CW
59 ajax: {
60 url: {/literal}"{crmURL p='civicrm/case/ajax/unclosed' h=0}"{literal},
61 data: function(term) {
62 return {term: term, excludeCaseIds: "{/literal}{$currentCaseId}{literal}"};
63 },
64 results: function(response) {
65 return {results: response};
66 }
67 }
f72119d9 68 });
cf111af5 69 });
6a488035 70
cf111af5 71 cj( "#fileOnCaseDialog" ).hide( );
6a488035 72
cf111af5 73 </script>
6a488035 74{/literal}
cf111af5 75{* main form end *}
6a488035 76
cf111af5
CW
77{else}
78{* Markup and js to go on the main page for loading the above form in a popup *}
79<div id="fileOnCaseDialog"></div>
6a488035
TO
80{literal}
81<script type="text/javascript">
cf111af5 82 function fileOnCase( action, activityID, currentCaseId ) {
6a488035 83 if ( action == "move" ) {
cf111af5 84 var dialogTitle = "{/literal}{ts escape='js'}Move to Case{/ts}{literal}";
6a488035 85 } else if ( action == "copy" ) {
cf111af5 86 var dialogTitle = "{/literal}{ts escape='js'}Copy to Case{/ts}{literal}";
6a488035 87 } else if ( action == "file" ) {
cf111af5 88 var dialogTitle = "{/literal}{ts escape='js'}File On Case{/ts}{literal}";
6a488035
TO
89 }
90
91 var dataUrl = {/literal}"{crmURL p='civicrm/case/addToCase' q='reset=1&snippet=4' h=0}"{literal};
cf111af5 92 dataUrl += '&activityId=' + activityID + '&caseId=' + currentCaseId + '&cid=' + {/literal}"{$contactID}"{literal};
6a488035
TO
93
94 cj.ajax({
cf111af5
CW
95 url : dataUrl,
96 success : function ( content ) {
050fc124 97 cj("#fileOnCaseDialog").show( ).html( content).trigger('crmLoad').dialog({
cf111af5
CW
98 title: dialogTitle,
99 modal: true,
100 width: 600,
a243158e 101 height: 'auto',
cf111af5 102 close: function( event, ui ) {
050fc124 103 cj('input[name=file_on_case_unclosed_case_id]', '#fileOnCaseDialog').select2('destroy');
cf111af5
CW
104 cj(this).hide().dialog("destroy");
105 },
cf111af5 106 buttons: {
a243158e 107 "{/literal}{ts escape='js'}Save{/ts}{literal}": function() {
7359cdbc
CW
108 var selectedCaseId = cj('input[name=file_on_case_unclosed_case_id]', '#fileOnCaseDialog').val();
109 var contactId = cj('input[name=file_on_case_unclosed_case_id]', '#fileOnCaseDialog').select2('data').extra.contact_id;
050fc124
CW
110 var subject = cj("#file_on_case_activity_subject").val( );
111 var targetContactId = cj("#file_on_case_target_contact_id").val( );
cf111af5 112
050fc124
CW
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}.');
cf111af5
CW
115 return false;
116 }
117
a243158e 118 cj(this).dialog("close");
cf111af5
CW
119
120 var postUrl = {/literal}"{crmURL p='civicrm/ajax/activity/convert' h=0 }"{literal};
6a488035 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} },
cf111af5
CW
122 function( values ) {
123 if ( values.error_msg ) {
6a488035 124 cj().crmError(values.error_msg, "{/literal}{ts escape='js'}Unable to file on case{/ts}{literal}.");
cf111af5
CW
125 return false;
126 } else {
6a488035 127 var destUrl = {/literal}"{crmURL p='civicrm/contact/view/case' q='reset=1&action=view&id=' h=0 }"{literal};
cf111af5
CW
128 var context = '';
129 {/literal}{if !empty($fulltext)}{literal}
6a488035 130 context = '&context={/literal}{$fulltext}{literal}';
cf111af5
CW
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;
6a488035 138 if ( curPath.indexOf( 'civicrm/contact/view' ) != -1 ) {
cf111af5
CW
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 }
6a488035 148 }
cf111af5
CW
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 ) {
6a488035 158 window.location.reload( );
cf111af5 159 } else {
050fc124 160 var activitySubject = cj("#file_on_case_activity_subject").val( );
6a488035
TO
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
6a488035 164 }
cf111af5
CW
165 }
166 }
6a488035 167 );
cf111af5
CW
168 },
169 "{/literal}{ts escape='js'}Cancel{/ts}{literal}": function() {
170 cj(this).dialog("close");
cf111af5
CW
171 }
172 }
173
174 });
6a488035 175 }
cf111af5
CW
176 });
177 }
6a488035
TO
178</script>
179{/literal}
cf111af5 180{/if}