Case ui enhancements & code cleanup
[civicrm-core.git] / templates / CRM / Case / Form / CaseView.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.4 |
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 - view case screen*}
27
28 <div class="crm-block crm-form-block crm-case-caseview-form-block">
29
30 {* here we are showing related cases w/ jquery dialog *}
31 {if $showRelatedCases}
32 {include file="CRM/Case/Form/ViewRelatedCases.tpl"}
33
34 {* Main case view *}
35 {else}
36
37 <h3>{ts}Summary{/ts}</h3>
38 <table class="report crm-entity case-summary" data-entity="case" data-id="{$caseID}" data-cid="{$contactID}">
39 {if $multiClient}
40 <tr class="crm-case-caseview-client">
41 <td colspan="5" class="label">
42 {ts}Clients:{/ts}
43 {foreach from=$caseRoles.client item=client name=clients}
44 <a href="{crmURL p='civicrm/contact/view' q="action=view&reset=1&cid=`$client.contact_id`"}" title="{ts}view contact record{/ts}">{$client.display_name}</a>{if not $smarty.foreach.clients.last}, &nbsp; {/if}
45 {/foreach}
46 <a href="#" class="crm-hover-button" title="{ts}add new client to the case{/ts}" onclick="addClient( );return false;">
47 <span class="icon edit-icon"></span>
48 </a>
49 {if $hasRelatedCases}
50 <div class="crm-block relatedCases-link"><a class="crm-hover-button crm-popup medium-popup" href="{$relatedCaseUrl}">{$relatedCaseLabel}</a></div>
51 {/if}
52 </td>
53 </tr>
54 {/if}
55 <tr>
56 {if not $multiClient}
57 <td>
58 <table class="form-layout-compressed">
59 {foreach from=$caseRoles.client item=client}
60 <tr class="crm-case-caseview-display_name">
61 <td class="label-left bold" style="padding: 0px; border: none;">{$client.display_name}</td>
62 </tr>
63 {if $client.phone}
64 <tr class="crm-case-caseview-phone">
65 <td class="label-left description" style="padding: 1px">{$client.phone}</td>
66 </tr>
67 {/if}
68 {if $client.birth_date}
69 <tr class="crm-case-caseview-birth_date">
70 <td class="label-left description" style="padding: 1px">{ts}DOB{/ts}: {$client.birth_date|crmDate}</td>
71 </tr>
72 {/if}
73 {/foreach}
74 </table>
75 {if $hasRelatedCases}
76 <div class="crm-block relatedCases-link"><a class="crm-hover-button crm-popup medium-popup" href="{$relatedCaseUrl}">{$relatedCaseLabel}</a></div>
77 {/if}
78 </td>
79 {/if}
80 <td class="crm-case-caseview-case_subject label">
81 <span class="crm-case-summary-label">{ts}Subject{/ts}:</span>&nbsp;{$caseDetails.case_subject}
82 </td>
83 <td class="crm-case-caseview-case_type label">
84 <span class="crm-case-summary-label">{ts}Type{/ts}:</span>&nbsp;{$caseDetails.case_type}&nbsp;<a class="crm-hover-button crm-popup" href="{crmURL p='civicrm/case/activity' q="action=add&reset=1&cid=`$contactId`&caseid=`$caseId`&selectedChild=activity&atype=`$changeCaseTypeId`"}" title="{ts}Change case type (creates activity record){/ts}"><span class="icon edit-icon"></span></a>
85 </td>
86 <td class="crm-case-caseview-case_status label">
87 <span class="crm-case-summary-label">{ts}Status{/ts}:</span>&nbsp;{$caseDetails.case_status}&nbsp;<a class="crm-hover-button crm-popup" href="{crmURL p='civicrm/case/activity' q="action=add&reset=1&cid=`$contactId`&caseid=`$caseId`&selectedChild=activity&atype=`$changeCaseStatusId`"}" title="{ts}Change case status (creates activity record){/ts}"><span class="icon edit-icon"></span></a>
88 </td>
89 <td class="crm-case-caseview-case_start_date label">
90 <span class="crm-case-summary-label">{ts}Open Date{/ts}:</span>&nbsp;{$caseDetails.case_start_date|crmDate}&nbsp;<a class="crm-hover-button crm-popup" href="{crmURL p='civicrm/case/activity' q="action=add&reset=1&cid=`$contactId`&caseid=`$caseId`&selectedChild=activity&atype=`$changeCaseStartDateId`"}" title="{ts}Change case start date (creates activity record){/ts}"><span class="icon edit-icon"></span></a>
91 </td>
92 <td class="crm-case-caseview-{$caseID} label">
93 <span class="crm-case-summary-label">{ts}ID{/ts}:</span>&nbsp;{$caseID}
94 </td>
95 </tr>
96 </table>
97 {if $hookCaseSummary}
98 <div id="caseSummary">
99 {foreach from=$hookCaseSummary item=val key=div_id}
100 <div id="{$div_id}"><label>{$val.label}</label><div class="value">{$val.value}</div></div>
101 {/foreach}
102 </div>
103 {/if}
104
105 <div class="case-control-panel">
106 <div>
107 <p>
108 {$form.add_activity_type_id.html}
109 {if $hasAccessToAllCases} &nbsp;
110 {$form.timeline_id.html}{$form._qf_CaseView_next.html} &nbsp;
111 {$form.report_id.html}
112 {/if}
113 </p>
114 </div>
115 <div>
116 <p>
117 {if $hasAccessToAllCases}
118 <a class="crm-hover-button action-item no-popup" href="{crmURL p='civicrm/case/report/print' q="all=1&redact=0&cid=$contactID&caseID=$caseId&asn=standard_timeline"}"><span class="icon print-icon"></span> {ts}Print Report{/ts}</a>
119 {/if}
120
121 {if $mergeCases}
122 <a href="#merge_cases" class="action-item no-popup crm-hover-button case-miniform"><span class="icon ui-icon-copy"></span>{ts}Merge Case{/ts}</a>
123 {$form._qf_CaseView_next_merge_case.html}
124 <span id='merge_cases' class="hiddenElement">
125 {$form.merge_case_id.html}
126 </span>
127 {/if}
128
129 {if call_user_func(array('CRM_Core_Permission','giveMeAllACLs'))}
130 <a class="action-item crm-hover-button medium-popup" href="{crmURL p='civicrm/contact/view/case/editClient' h=1 q="reset=1&action=update&id=$caseID&cid=$contactID"}"><span class="icon ui-icon-person"></span> {ts}Assign to Another Client{/ts}</a>
131 {/if}
132 </p>
133 </div>
134 </div>
135
136 <div class="clear"></div>
137 {include file="CRM/Case/Page/CustomDataView.tpl"}
138
139 <div class="crm-accordion-wrapper collapsed crm-case-roles-block">
140 <div class="crm-accordion-header">
141 {ts}Roles{/ts}
142 </div><!-- /.crm-accordion-header -->
143 <div class="crm-accordion-body">
144
145 {if $hasAccessToAllCases}
146 <div class="crm-submit-buttons">
147 <a class="button" href="#" onclick="addRole();return false;"><span><div class="icon add-icon"></div>{ts}Add new role{/ts}</span></a>
148 </div>
149 {/if}
150
151 <table id="caseRoles-selector" class="report-layout">
152 <thead><tr>
153 <th>{ts}Case Role{/ts}</th>
154 <th>{ts}Name{/ts}</th>
155 <th>{ts}Phone{/ts}</th>
156 <th>{ts}Email{/ts}</th>
157 {if $relId neq 'client' and $hasAccessToAllCases}
158 <th id="nosort">{ts}Actions{/ts}</th>
159 {/if}
160 </tr></thead>
161 </table>
162
163 <div id="deleteCaseRole" class="case-miniform hiddenElement">
164 {ts}Are you sure you want to delete this case role?{/ts}
165 </div>
166
167 {literal}
168 <script type="text/javascript">
169 var oTable;
170
171 cj(function() {
172 buildCaseRoles(false);
173 });
174
175 function buildCaseRoles(filterSearch) {
176 if(filterSearch) {
177 oTable.fnDestroy();
178 }
179 var count = 0;
180 var columns = '';
181 var sourceUrl = {/literal}"{crmURL p='civicrm/ajax/caseroles' h=0 q='snippet=4&caseID='}{$caseID}"{literal};
182 sourceUrl = sourceUrl + '&cid={/literal}{$contactID}{literal}';
183 sourceUrl = sourceUrl + '&userID={/literal}{$userID}{literal}';
184
185 cj('#caseRoles-selector th').each( function( ) {
186 if ( cj(this).attr('id') != 'nosort' ) {
187 columns += '{"sClass": "' + cj(this).attr('class') +'"},';
188 }
189 else {
190 columns += '{ "bSortable": false },';
191 }
192 count++;
193 });
194
195 columns = columns.substring(0, columns.length - 1 );
196 eval('columns =[' + columns + ']');
197
198 oTable = cj('#caseRoles-selector').dataTable({
199 "bFilter" : false,
200 "bAutoWidth" : false,
201 "aaSorting" : [],
202 "aoColumns" : columns,
203 "bProcessing": true,
204 "bJQueryUI": true,
205 "asStripClasses" : [ "odd-row", "even-row" ],
206 "sPaginationType": "full_numbers",
207 "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
208 "bServerSide": true,
209 "sAjaxSource": sourceUrl,
210 "iDisplayLength": 10,
211 "fnDrawCallback": function() { setCaseRolesSelectorClass(); },
212 "fnServerData": function ( sSource, aoData, fnCallback ) {
213 cj.ajax({
214 "dataType": 'json',
215 "type": "POST",
216 "url": sSource,
217 "data": aoData,
218 "success": fnCallback
219 });
220 }
221 });
222 }
223
224 function setCaseRolesSelectorClass( ) {
225 cj("#caseRoles-selector td:last-child").each( function( ) {
226 cj(this).parent().addClass(cj(this).text() );
227 });
228 }
229
230 </script>
231 {/literal}
232 </div><!-- /.crm-accordion-body -->
233 </div><!-- /.crm-accordion-wrapper -->
234 <div id="dialog">
235 {ts}Begin typing last name of contact.{/ts}<br/>
236 <input type="text" id="rel_contact"/>
237 <input type="hidden" id="rel_contact_id" value="">
238 </div>
239
240 {literal}
241 <script type="text/javascript">
242
243 cj("#dialog").hide( );
244
245 function addClient( ) {
246 cj("#dialog").show( );
247
248 cj("#dialog").dialog({
249 title: "{/literal}{ts escape="js"}Add Client to the Case{/ts}{literal}",
250 modal: true,
251 close : function(event, ui) {
252 cj("#rel_contact").unautocomplete( );
253 cj("#dialog").hide( );
254 },
255 overlay: { opacity: 0.5, background: "black" },
256
257 open:function() {
258 var contactUrl = {/literal}"{crmURL p='civicrm/ajax/rest' q='className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=caseview' h=0 }"{literal};
259 cj("#rel_contact").autocomplete( contactUrl, {
260 width: 260,
261 selectFirst: false,
262 matchContains: true
263 });
264
265 cj("#rel_contact").focus();
266 cj("#rel_contact").result(function(event, data, formatted) {
267 cj("input[id=rel_contact_id]").val(data[1]);
268 });
269 },
270
271 buttons: {
272 "{/literal}{ts escape='js'}Done{/ts}{literal}": function() {
273 var postUrl = {/literal}"{crmURL p='civicrm/case/ajax/addclient' h=0 }"{literal};
274 var caseID = {/literal}"{$caseID}"{literal};
275 var contactID = cj("#rel_contact_id").val( );
276
277 if ( !cj("#rel_contact").val( ) || !contactID ) {
278 cj("#rel_contact").crmError('{/literal}{ts escape="js"}Select valid contact from the list.{/ts}{literal}');
279 return false;
280 }
281 cj.post( postUrl, {contactID: contactID,caseID: caseID,
282 key: {/literal}"{crmKey name='civicrm/case/ajax/addclient'}"{literal} },
283 function( data ) {
284 //due to caching issues we use redirection rather than reload
285 document.location = {/literal}'{crmURL q="action=view&reset=1&id=$caseID&cid=$contactID&context=$context" h=0 }'{literal};
286 },
287 'json'
288 );
289 },
290
291 "{/literal}{ts escape='js'}Cancel{/ts}{literal}": function() {
292 cj(this).dialog("close");
293 cj(this).dialog("destroy");
294 }
295 }
296 });
297 }
298
299 function createRelationship( relType, contactID, relID, rowNumber, relTypeName ) {
300 cj("#dialog").show( );
301
302 cj("#dialog").dialog({
303 title: "Assign Case Role",
304 modal: true,
305 close: function(event, ui) { cj("#rel_contact").unautocomplete( ); },
306 open:function() {
307 /* set defaults if editing */
308 cj("#rel_contact").val("");
309 cj("#rel_contact_id").val(null);
310 if (contactID) {
311 cj("#rel_contact_id").val(contactID);
312 var contactName = cj('#caseRoles-selector').find('tr :eq('+ rowNumber +')').children(':eq(1)').text();
313 cj("#rel_contact").val(contactName);
314 }
315
316 var contactUrl = {/literal}"{crmURL p='civicrm/ajax/rest' q='className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=caseview' h=0 }"{literal};
317
318 cj("#rel_contact").autocomplete( contactUrl, {
319 width: 260,
320 selectFirst: false,
321 matchContains: true
322 });
323
324 cj("#rel_contact").focus();
325 cj("#rel_contact").result(function(event, data, formatted) {
326 cj("input[id=rel_contact_id]").val(data[1]);
327 });
328 },
329
330 buttons: {
331 "{/literal}{ts escape='js'}Ok{/ts}{literal}": function() {
332
333 var sourceContact = {/literal}"{$contactID}"{literal};
334 var caseID = {/literal}"{$caseID}"{literal};
335
336 var v1 = cj("#rel_contact_id").val( );
337
338 if ( !cj("#rel_contact").val( ) || !v1 ) {
339 cj("#rel_contact").crmError('{/literal}{ts escape="js"}Select valid contact from the list{/ts}{literal}.');
340 return false;
341 }
342
343 var postUrl = {/literal}"{crmURL p='civicrm/ajax/relation' h=0 }"{literal};
344 cj.post( postUrl, { rel_contact: v1, rel_type: relType, contact_id: sourceContact,
345 rel_id: relID, case_id: caseID, key: {/literal}"{crmKey name='civicrm/ajax/relation'}"{literal} },
346 function( data ) {
347 if ( data.status == 'process-relationship-success' ) {
348 // reloading datatable
349 var oTable = cj('#caseRoles-selector').dataTable();
350 oTable.fnDraw();
351 }
352 else {
353 // This is an awkward mix of smarty and javascript: the relTypeName variable is
354 // not available in smarty, could not find an i18n-correct way of doing this.
355 {/literal}
356 {capture assign=relTypeAdminLink}{crmURL p='civicrm/admin/reltype' q='reset=1' h=0 }{/capture}
357 {literal}
358 var errorMsg = relTypeName + ': ' + '{/literal}{ts escape="js" 1="$relTypeAdminLink"}The relationship type definition for the case role is not valid for the client and / or staff contact types. You can review and edit relationship types at <a href="%1">Administer >> Option Lists >> Relationship Types</a>.{/ts}{literal}';
359
360 //display error message.
361 cj().crmError(errorMsg);
362 }
363 }, 'json'
364 );
365
366 cj(this).dialog("close");
367 cj(this).dialog("destroy");
368 },
369
370 "{/literal}{ts escape='js'}Cancel{/ts}{literal}": function() {
371 cj(this).dialog("close");
372 cj(this).dialog("destroy");
373 }
374 }
375 });
376 }
377
378 </script>
379 {/literal}
380
381 {if $hasAccessToAllCases}
382 <div class="crm-accordion-wrapper collapsed crm-case-other-relationships-block">
383 <div class="crm-accordion-header">
384 {ts}Other Relationships{/ts}
385 </div><!-- /.crm-accordion-header -->
386 <div class="crm-accordion-body">
387 {capture assign=relUrl}{crmURL p='civicrm/contact/view/rel' q="action=add&reset=1&cid=`$contactId`&caseID=`$caseID`"}{/capture}
388 {if $clientRelationships}
389 <div class="crm-submit-buttons">
390 <a class="button" href="{$relUrl}">
391 <div class="icon add-icon"></div>{ts}Add client relationship{/ts}</a>
392 </div>
393 <table id="clientRelationships-selector" class="report-layout">
394 <thead><tr>
395 <th>{ts}Client Relationship{/ts}</th>
396 <th>{ts}Name{/ts}</th>
397 <th>{ts}Phone{/ts}</th>
398 <th>{ts}Email{/ts}</th>
399 </tr></thead>
400 </table>
401 {else}
402 <div class="messages status no-popup">
403 <div class="icon inform-icon"></div>
404 {capture assign=link}class="action-item" href="{$relUrl}"{/capture}
405 {ts 1=$link}There are no Relationships entered for this client. You can <a %1>add one</a>.{/ts}
406 </div>
407 {/if}
408 {literal}
409 <script type="text/javascript">
410 cj(function( ) {
411 buildCaseClientRelationships(false);
412 });
413
414 function buildCaseClientRelationships(filterSearch) {
415 if (filterSearch) {
416 oTable.fnDestroy();
417 }
418 var count = 0;
419 var columns = '';
420 var sourceUrl = {/literal}"{crmURL p='civicrm/ajax/clientrelationships' h=0 q='snippet=4&caseID='}{$caseID}"{literal};
421 sourceUrl = sourceUrl + '&cid={/literal}{$contactID}{literal}';
422 sourceUrl = sourceUrl + '&userID={/literal}{$userID}{literal}';
423
424 cj('#clientRelationships-selector th').each( function( ) {
425 if ( cj(this).attr('id') != 'nosort' ) {
426 columns += '{"sClass": "' + cj(this).attr('class') +'"},';
427 }
428 else {
429 columns += '{ "bSortable": false },';
430 }
431 count++;
432 });
433
434 columns = columns.substring(0, columns.length - 1 );
435 eval('columns =[' + columns + ']');
436
437 oTable = cj('#clientRelationships-selector').dataTable({
438 "bFilter" : false,
439 "bAutoWidth" : false,
440 "aaSorting" : [],
441 "aoColumns" : columns,
442 "bProcessing": true,
443 "bJQueryUI": true,
444 "asStripClasses" : [ "odd-row", "even-row" ],
445 "sPaginationType": "full_numbers",
446 "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
447 "bServerSide": true,
448 "sAjaxSource": sourceUrl,
449 "iDisplayLength": 10,
450 "fnDrawCallback": function() { setClientRelationshipsSelectorClass(); },
451 "fnServerData": function (sSource, aoData, fnCallback) {
452 cj.ajax( {
453 "dataType": 'json',
454 "type": "POST",
455 "url": sSource,
456 "data": aoData,
457 "success": fnCallback
458 } );
459 }
460 });
461 }
462
463 function setClientRelationshipsSelectorClass( ) {
464 cj("#clientRelationships-selector td:last-child").each(function() {
465 cj(this).parent().addClass(cj(this).text());
466 });
467 }
468 </script>
469 {/literal}
470 <br />
471
472 {if $globalRelationships}
473 <div class="crm-submit-buttons">
474 <a class="button" href="#" onClick="window.location='{crmURL p='civicrm/group/search' q="reset=1&context=amtg&amtgID=`$globalGroupInfo.id`"}'; return false;">
475 <span><div class="icon add-icon"></div>{ts 1=$globalGroupInfo.title}Add members to %1{/ts}</a></span>
476 </div>
477 <table id="globalRelationships-selector" class="report-layout">
478 <thead><tr>
479 <th>{$globalGroupInfo.title}</th>
480 <th>{ts}Phone{/ts}</th>
481 <th>{ts}Email{/ts}</th>
482 </tr></thead>
483 </table>
484 {elseif $globalGroupInfo.id}
485 <div class="messages status no-popup">
486 <div class="icon inform-icon"></div>&nbsp;
487 {capture assign=crmURL}{crmURL p='civicrm/group/search' q="reset=1&context=amtg&amtgID=`$globalGroupInfo.id`"}{/capture}
488 {ts 1=$crmURL 2=$globalGroupInfo.title}The group %2 has no members. You can <a href='%1'>add one</a>.{/ts}
489 </div>
490 {/if}
491
492 {literal}
493 <script type="text/javascript">
494
495 cj(function() {
496 buildCaseGlobalRelationships(false);
497 });
498
499 function buildCaseGlobalRelationships(filterSearch) {
500 if (filterSearch) {
501 oTable.fnDestroy();
502 }
503 var count = 0;
504 var columns = '';
505 var sourceUrl = {/literal}"{crmURL p='civicrm/ajax/globalrelationships' h=0 q='snippet=4&caseID='}{$caseID}"{literal};
506 sourceUrl = sourceUrl + '&cid={/literal}{$contactID}{literal}';
507 sourceUrl = sourceUrl + '&userID={/literal}{$userID}{literal}';
508
509 cj('#globalRelationships-selector th').each( function( ) {
510 if (cj(this).attr('id') != 'nosort') {
511 columns += '{"sClass": "' + cj(this).attr('class') +'"},';
512 }
513 else {
514 columns += '{ "bSortable": false },';
515 }
516 count++;
517 });
518
519 columns = columns.substring(0, columns.length - 1 );
520 eval('columns =[' + columns + ']');
521
522 oTable = cj('#globalRelationships-selector').dataTable({
523 "bFilter" : false,
524 "bAutoWidth" : false,
525 "aaSorting" : [],
526 "aoColumns" : columns,
527 "bProcessing": true,
528 "bJQueryUI": true,
529 "asStripClasses" : [ "odd-row", "even-row" ],
530 "sPaginationType": "full_numbers",
531 "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
532 "bServerSide": true,
533 "sAjaxSource": sourceUrl,
534 "iDisplayLength": 10,
535 "fnDrawCallback": function() { setGlobalRelationshipsSelectorClass(); },
536 "fnServerData": function ( sSource, aoData, fnCallback ) {
537 cj.ajax( {
538 "dataType": 'json',
539 "type": "POST",
540 "url": sSource,
541 "data": aoData,
542 "success": fnCallback
543 } );
544 }
545 });
546 }
547
548 function setGlobalRelationshipsSelectorClass( ) {
549 cj("#globalRelationships-selector td:last-child").each( function( ) {
550 cj(this).parent().addClass(cj(this).text() );
551 });
552 }
553 </script>
554 {/literal}
555 </div><!-- /.crm-accordion-body -->
556 </div><!-- /.crm-accordion-wrapper -->
557
558 {/if} {* other relationship section ends *}
559
560 <div id="addRoleDialog">
561 {$form.role_type.label}<br />
562 {$form.role_type.html}
563 <br /><br />
564 {ts}Begin typing last name of contact.{/ts}<br/>
565 <input type="text" id="role_contact"/>
566 <input type="hidden" id="role_contact_id" value="">
567 </div>
568
569 {literal}
570 <script type="text/javascript">
571
572 cj("#addRoleDialog").hide( );
573 function addRole() {
574 cj("#addRoleDialog").show( );
575
576 cj("#addRoleDialog").dialog({
577 title: "Add Role",
578 modal: true,
579 close: function(event, ui) { cj("#role_contact").unautocomplete( ); },
580 open:function() {
581 /* set defaults if editing */
582 cj("#role_contact").val( "" );
583 cj("#role_contact_id").val( null );
584
585 var contactUrl = {/literal}"{crmURL p='civicrm/ajax/rest' q='className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=caseview' h=0 }"{literal};
586
587 cj("#role_contact").autocomplete( contactUrl, {
588 width: 260,
589 selectFirst: false,
590 matchContains: true
591 });
592
593 cj("#role_contact").focus();
594 cj("#role_contact").result(function(event, data, formatted) {
595 cj("input[id=role_contact_id]").val(data[1]);
596 });
597 },
598
599 buttons: {
600 "{/literal}{ts escape='js'}Ok{/ts}{literal}": function() {
601 var sourceContact = {/literal}"{$contactID}"{literal};
602 var caseID = {/literal}"{$caseID}"{literal};
603 var relID = null;
604
605 var v2 = cj("#role_type").val();
606 if (!v2) {
607 cj("#role_type").crmError('{/literal}{ts escape="js"}Select valid type from the list{/ts}{literal}.');
608 return false;
609 }
610
611 var v1 = cj("#role_contact_id").val( );
612 if (!cj("#role_contact").val( ) || !v1) {
613 cj("#role_contact").crmError('{/literal}{ts escape="js"}Select valid contact from the list{/ts}{literal}.');
614 return false;
615 }
616
617 /* send synchronous request so that disabling any actions for slow servers*/
618 var postUrl = {/literal}"{crmURL p='civicrm/ajax/relation' h=0 }"{literal};
619 var data = 'rel_contact='+ v1 + '&rel_type='+ v2 + '&contact_id='+sourceContact + '&rel_id='+ relID
620 + '&case_id=' + caseID + "&key={/literal}{crmKey name='civicrm/ajax/relation'}{literal}";
621 cj.ajax({
622 type : "POST",
623 url : postUrl,
624 data : data,
625 async : false,
626 dataType : "json",
627 success : function(values) {
628 if (values.status == 'process-relationship-success') {
629 // reloading datatable
630 var oTable = cj('#caseRoles-selector').dataTable();
631 oTable.fnDraw();
632 }
633 else {
634 var relTypeName = cj("#role_type :selected").text();
635 var relTypeAdminLink = {/literal}"{crmURL p='civicrm/admin/reltype' q='reset=1' h=0 }"{literal};
636 var errorMsg = '{/literal}{ts escape="js" 1="' + relTypeName + '" 2="' + relTypeAdminLink + '"}The relationship type definition for the %1 case role is not valid for the client and / or staff contact types. You can review and edit relationship types at <a href="%2">Administer >> Option Lists >> Relationship Types</a>{/ts}{literal}.';
637
638 //display error message.
639 cj().crmError(errorMsg);
640 }
641 }
642 });
643
644 cj(this).dialog("close");
645 cj(this).dialog("destroy");
646 },
647
648 "{/literal}{ts escape='js'}Cancel{/ts}{literal}": function() {
649 cj(this).dialog("close");
650 cj(this).dialog("destroy");
651 }
652 }
653 });
654 }
655
656 </script>
657 {/literal}
658 {include file="CRM/Case/Form/ActivityToCase.tpl"}
659
660 {* pane to display / edit regular tags or tagsets for cases *}
661 {if $showTags OR $showTagsets}
662
663 <div id="casetags" class="crm-accordion-wrapper crm-case-tags-block">
664 <div class="crm-accordion-header">
665 {ts}Case Tags{/ts}
666 </div><!-- /.crm-accordion-header -->
667 <div class="crm-accordion-body">
668 {assign var="tagExits" value=0}
669 {if $tags}
670 <div class="crm-block crm-content-block crm-case-caseview-display-tags">&nbsp;&nbsp;{$tags}</div>
671 {assign var="tagExits" value=1}
672 {/if}
673
674 {foreach from=$tagsetInfo_case item=displayTagset}
675 {if $displayTagset.entityTagsArray}
676 <div class="crm-block crm-content-block crm-case-caseview-display-tagset">
677 &nbsp;&nbsp;{$displayTagset.parentName}:
678 {foreach from=$displayTagset.entityTagsArray item=val name="tagsetList"}
679 &nbsp;{$val.name}{if !$smarty.foreach.tagsetList.last},{/if}
680 {/foreach}
681 </div>
682 {assign var="tagExits" value=1}
683 {/if}
684 {/foreach}
685
686 {if !$tagExits }
687 <div class="status">
688 {ts}There are no tags currently assigned to this case.{/ts}
689 </div>
690 {/if}
691
692 <div class="crm-submit-buttons">
693 <a class="button case-miniform" href="#manageTags" data-key="{crmKey name='civicrm/case/ajax/processtags'}">{if $tagExits}{ts}Edit Tags{/ts}{else}{ts}Add Tags{/ts}{/if}</a>
694 </div>
695
696 </div><!-- /.crm-accordion-body -->
697 </div><!-- /.crm-accordion-wrapper -->
698
699 <div id="manageTags" class="hiddenElement">
700 <div class="label">{$form.case_tag.label}</div>
701 <div class="view-value"><div class="crm-select-container">{$form.case_tag.html}</div>
702 <br/>
703 <div style="text-align:left;">{include file="CRM/common/Tag.tpl" tagsetType='case'}</div>
704 <br/>
705 <div class="clear"></div>
706 </div>
707 </div>
708
709 {/if} {* end of tag block*}
710
711 <div class="crm-accordion-wrapper crm-case_activities-accordion crm-case-activities-block">
712 <div class="crm-accordion-header">
713 {ts}Activities{/ts}
714 </div>
715 <div id="activities" class="crm-accordion-body">
716 <div class="crm-accordion-wrapper crm-accordion-inner crm-search_filters-accordion collapsed">
717 <div class="crm-accordion-header">
718 {ts}Search Filters{/ts}</a>
719 </div><!-- /.crm-accordion-header -->
720 <div class="crm-accordion-body">
721 <table class="no-border form-layout-compressed" id="searchOptions">
722 <tr>
723 <td class="crm-case-caseview-form-block-repoter_id"colspan="2"><label for="reporter_id">{ts}Reporter/Role{/ts}</label><br />
724 {$form.reporter_id.html|crmAddClass:twenty}
725 </td>
726 <td class="crm-case-caseview-form-block-status_id"><label for="status_id">{$form.status_id.label}</label><br />
727 {$form.status_id.html}
728 </td>
729 <td style="vertical-align: bottom;">
730 <span class="crm-button"><input class="form-submit default" name="_qf_Basic_refresh" value="Search" type="button" onclick="buildCaseActivities( true )"; /></span>
731 </td>
732 </tr>
733 <tr>
734 <td class="crm-case-caseview-form-block-activity_date_low">
735 {$form.activity_date_low.label}<br />
736 {include file="CRM/common/jcalendar.tpl" elementName=activity_date_low}
737 </td>
738 <td class="crm-case-caseview-form-block-activity_date_high">
739 {$form.activity_date_high.label}<br />
740 {include file="CRM/common/jcalendar.tpl" elementName=activity_date_high}
741 </td>
742 <td class="crm-case-caseview-form-block-activity_type_filter_id">
743 {$form.activity_type_filter_id.label}<br />
744 {$form.activity_type_filter_id.html}
745 </td>
746 </tr>
747 {if $form.activity_deleted}
748 <tr class="crm-case-caseview-form-block-activity_deleted">
749 <td>
750 {$form.activity_deleted.html}{$form.activity_deleted.label}
751 </td>
752 </tr>
753 {/if}
754 </table>
755 </div><!-- /.crm-accordion-body -->
756 </div><!-- /.crm-accordion-wrapper -->
757
758 <table id="activities-selector" class="nestedActivitySelector">
759 <thead><tr>
760 <th class='crm-case-activities-date'>{ts}Date{/ts}</th>
761 <th class='crm-case-activities-subject'>{ts}Subject{/ts}</th>
762 <th class='crm-case-activities-type'>{ts}Type{/ts}</th>
763 <th class='crm-case-activities-with'>{ts}With{/ts}</th>
764 <th class='crm-case-activities-assignee'>{ts}Reporter / Assignee{/ts}</th>
765 <th class='crm-case-activities-status'>{ts}Status{/ts}</th>
766 <th class='crm-case-activities-status' id="nosort">&nbsp;</th>
767 <th class='hiddenElement'>&nbsp;</th>
768 </tr></thead>
769 </table>
770
771 </div><!-- /.crm-accordion-body -->
772 </div><!-- /.crm-accordion-wrapper -->
773
774 {literal}
775 <script type="text/javascript">
776 var oTable;
777
778 cj(function( ) {
779 buildCaseActivities(false);
780 });
781
782 function buildCaseActivities(filterSearch) {
783 if (filterSearch) {
784 oTable.fnDestroy();
785 }
786 var count = 0;
787 var columns = '';
788 var sourceUrl = {/literal}"{crmURL p='civicrm/ajax/activity' h=0 q='snippet=4&caseID='}{$caseID}"{literal};
789 sourceUrl = sourceUrl + '&cid={/literal}{$contactID}{literal}';
790 sourceUrl = sourceUrl + '&userID={/literal}{$userID}{literal}';
791
792 cj('#activities-selector th').each(function( ) {
793 if (cj(this).attr('id') != 'nosort') {
794 columns += '{"sClass": "' + cj(this).attr('class') +'"},';
795 }
796 else {
797 columns += '{ "bSortable": false },';
798 }
799 count++;
800 });
801
802 columns = columns.substring(0, columns.length - 1 );
803 eval('columns =[' + columns + ']');
804
805 oTable = cj('#activities-selector').dataTable({
806 "bFilter" : false,
807 "bAutoWidth" : false,
808 "aaSorting" : [],
809 "aoColumns" : columns,
810 "bProcessing": true,
811 "bJQueryUI": true,
812 "asStripClasses" : [ "odd-row", "even-row" ],
813 "sPaginationType": "full_numbers",
814 "sDom" : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
815 "bServerSide": true,
816 "sAjaxSource": sourceUrl,
817 "iDisplayLength": 10,
818 "fnDrawCallback": function() { setSelectorClass(); },
819 "fnServerData": function ( sSource, aoData, fnCallback ) {
820
821 if ( filterSearch ) {
822 var activity_deleted = 0;
823 if ( cj("#activity_deleted:checked").val() == 1 ) {
824 activity_deleted = 1;
825 }
826 aoData.push(
827 {name:'status_id', value: cj("select#status_id").val()},
828 {name:'activity_type_id', value: cj("select#activity_type_filter_id").val()},
829 {name:'activity_date_low', value: cj("#activity_date_low").val()},
830 {name:'activity_date_high', value: cj("#activity_date_high").val() },
831 {name:'activity_deleted', value: activity_deleted }
832 );
833 }
834 cj.ajax( {
835 "dataType": 'json',
836 "type": "POST",
837 "url": sSource,
838 "data": aoData,
839 "success": fnCallback
840 } );
841 }
842 });
843 }
844
845 function setSelectorClass( ) {
846 cj("#activities-selector td:last-child").each( function( ) {
847 cj(this).parent().addClass(cj(this).text() );
848 });
849 }
850
851 </script>
852 {/literal}
853
854 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
855
856 {include file="CRM/Case/Form/ActivityChangeStatusJs.tpl"}
857 {/if} {* view related cases if end *}
858 </div>
859