Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
39de6fd5 | 3 | | CiviCRM version 4.6 | |
6a488035 | 4 | +--------------------------------------------------------------------+ |
e7112fa7 | 5 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | *} | |
26 | ||
27 | {* Include a modified version of jquery-fieldselection | |
28 | * FIXME: we use this plugin for so little it's hard to justify having it at all *} | |
29 | <script type="text/javascript" src="{$config->resourceBase}packages/jquery/plugins/jquery-fieldselection.js"></script> | |
30 | ||
31 | <script type="text/javascript"> | |
b50fdacc | 32 | cj('form.{$form.formClass}').data('tokens', {$tokens|@json_encode}); |
6a488035 TO |
33 | var text_message = null; |
34 | var html_message = null; | |
1e035d58 | 35 | var prefix = ''; |
6a488035 TO |
36 | var isPDF = false; |
37 | var isMailing = false; | |
38 | ||
6a488035 TO |
39 | {if $form.formName eq 'MessageTemplates'} |
40 | {literal} | |
41 | text_message = "msg_text"; | |
42 | html_message = "msg_html"; | |
43 | {/literal} | |
44 | {elseif $form.formName eq 'Address'} | |
45 | {literal} | |
46 | text_message = "mailing_format"; | |
47 | isMailing = false; | |
48 | {/literal} | |
1b7a39f5 | 49 | {elseif $form.formClass eq 'CRM_SMS_Form_Upload' || $form.formClass eq 'CRM_Contact_Form_Task_SMS'} |
1e035d58 | 50 | {literal} |
51 | prefix = "SMS"; | |
52 | text_message = "sms_text_message"; | |
53 | isMailing = true; | |
54 | {/literal} | |
6a488035 TO |
55 | {else} |
56 | {literal} | |
57 | text_message = "text_message"; | |
58 | html_message = (cj("#edit-html-message-value").length > 0) ? "edit-html-message-value" : "html_message"; | |
59 | isMailing = true; | |
60 | {/literal} | |
61 | {/if} | |
62 | ||
63 | {if $form.formName eq 'PDF'} | |
64 | {literal} | |
65 | isPDF = true; | |
66 | {/literal} | |
67 | {/if} | |
68 | ||
69 | {if $templateSelected} | |
70 | {literal} | |
1e035d58 | 71 | if ( document.getElementsByName(prefix + "saveTemplate")[0].checked ) { |
72 | document.getElementById(prefix + "template").selectedIndex = {/literal}{$templateSelected}{literal}; | |
6a488035 TO |
73 | } |
74 | {/literal} | |
75 | {/if} | |
76 | {literal} | |
77 | ||
78 | var editor = {/literal}"{$editor}"{literal}; | |
1e035d58 | 79 | function showSaveUpdateChkBox(prefix) { |
80 | prefix = prefix || ''; | |
81 | if (document.getElementById(prefix + "template") == null) { | |
82 | if (document.getElementsByName(prefix + "saveTemplate")[0].checked){ | |
83 | document.getElementById(prefix + "saveDetails").style.display = "block"; | |
84 | document.getElementById(prefix + "editMessageDetails").style.display = "block"; | |
6a488035 TO |
85 | } |
86 | else { | |
1e035d58 | 87 | document.getElementById(prefix + "saveDetails").style.display = "none"; |
88 | document.getElementById(prefix + "updateDetails").style.display = "none"; | |
6a488035 TO |
89 | } |
90 | return; | |
91 | } | |
92 | ||
1e035d58 | 93 | if (document.getElementsByName(prefix + "saveTemplate")[0].checked && |
94 | document.getElementsByName(prefix + "updateTemplate")[0].checked == false) { | |
95 | document.getElementById(prefix + "updateDetails").style.display = "none"; | |
6a488035 | 96 | } |
1e035d58 | 97 | else if ( document.getElementsByName(prefix + "saveTemplate")[0].checked && |
98 | document.getElementsByName(prefix + "updateTemplate")[0].checked ){ | |
99 | document.getElementById(prefix + "editMessageDetails").style.display = "block"; | |
100 | document.getElementById(pefix + "saveDetails").style.display = "block"; | |
6a488035 | 101 | } |
1e035d58 | 102 | else if ( document.getElementsByName(prefix + "saveTemplate")[0].checked == false && |
103 | document.getElementsByName(prefix + "updateTemplate")[0].checked ) { | |
104 | document.getElementById(prefix + "saveDetails").style.display = "none"; | |
105 | document.getElementById(prefix + "editMessageDetails").style.display = "block"; | |
6a488035 TO |
106 | } |
107 | else { | |
1e035d58 | 108 | document.getElementById(prefix + "saveDetails").style.display = "none"; |
109 | document.getElementById(prefix + "updateDetails").style.display = "none"; | |
6a488035 TO |
110 | } |
111 | } | |
112 | ||
1e035d58 | 113 | function selectValue( val, prefix) { |
114 | document.getElementsByName(prefix + "saveTemplate")[0].checked = false; | |
115 | document.getElementsByName(prefix + "updateTemplate")[0].checked = false; | |
116 | showSaveUpdateChkBox(prefix); | |
6a488035 | 117 | if ( !val ) { |
1e035d58 | 118 | if (document.getElementById("subject").length) { |
119 | document.getElementById("subject").value =""; | |
120 | } | |
6a488035 | 121 | if ( !isPDF ) { |
1e035d58 | 122 | if (prefix == 'SMS') { |
123 | document.getElementById("sms_text_message").value =""; | |
124 | return; | |
125 | } | |
126 | else { | |
127 | document.getElementById("text_message").value =""; | |
128 | } | |
6a488035 TO |
129 | } |
130 | if ( editor == "ckeditor" ) { | |
131 | oEditor = CKEDITOR.instances[html_message]; | |
132 | oEditor.setData(''); | |
133 | } | |
134 | else if ( editor == "tinymce" ) { | |
135 | tinyMCE.getInstanceById(html_message).setContent( html_body ); | |
136 | } | |
137 | else if ( editor == "joomlaeditor" ) { | |
138 | document.getElementById(html_message).value = '' ; | |
139 | tinyMCE.execCommand('mceSetContent',false, ''); | |
140 | } | |
141 | else if ( editor =="drupalwysiwyg" ) { | |
142 | if (Drupal.wysiwyg.instances[html_message].setContent) { | |
143 | Drupal.wysiwyg.instances[html_message].setContent(html_body); | |
144 | } | |
145 | // @TODO: Remove this when http://drupal.org/node/614146 drops | |
146 | else if (Drupal.wysiwyg.instances[html_message].insert) { | |
147 | alert("Please note your editor doesn't completely support this function. You may need to clear the contents of the editor prior to choosing a new template."); | |
148 | Drupal.wysiwyg.instances[html_message].insert(html_body); | |
149 | } | |
150 | else { | |
151 | alert("Sorry, your editor doesn't support this function yet."); | |
152 | } | |
153 | } | |
154 | else { | |
155 | document.getElementById(html_message).value = '' ; | |
156 | } | |
157 | if ( isPDF ) { | |
158 | showBindFormatChkBox(); | |
159 | } | |
160 | return; | |
161 | } | |
162 | ||
163 | var dataUrl = {/literal}"{crmURL p='civicrm/ajax/template' h=0 }"{literal}; | |
164 | ||
165 | cj.post( dataUrl, {tid: val}, function( data ) { | |
166 | if ( !isPDF ) { | |
1e035d58 | 167 | if (prefix == "SMS") { |
168 | text_message = "sms_text_message"; | |
169 | } | |
6a488035 TO |
170 | if ( data.msg_text ) { |
171 | cj("#"+text_message).val( data.msg_text ); | |
172 | cj("div.text").show(); | |
173 | cj(".head").find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-s'); | |
174 | cj("#helptext").show(); | |
175 | } | |
176 | else { | |
177 | cj("#"+text_message).val(""); | |
178 | } | |
179 | } | |
1e035d58 | 180 | |
181 | if (prefix == "SMS") { | |
182 | return; | |
183 | } | |
9ed86096 | 184 | else { |
185 | cj("#subject").val( data.subject ); | |
186 | } | |
6a488035 TO |
187 | var html_body = ""; |
188 | if ( data.msg_html ) { | |
189 | html_body = data.msg_html; | |
190 | } | |
191 | ||
192 | if (editor == "ckeditor") { | |
193 | oEditor = CKEDITOR.instances[html_message]; | |
194 | oEditor.setData( html_body ); | |
195 | } | |
196 | else if (editor == "tinymce") { | |
197 | tinyMCE.execInstanceCommand('html_message',"mceInsertContent",false, html_body ); | |
198 | } | |
199 | else if (editor == "joomlaeditor") { | |
200 | cj("#"+ html_message).val( html_body ); | |
201 | tinyMCE.execCommand('mceSetContent',false, html_body); | |
202 | } | |
203 | else if ( editor =="drupalwysiwyg") { | |
204 | if (Drupal.wysiwyg.instances[html_message].setContent) { | |
205 | Drupal.wysiwyg.instances[html_message].setContent(html_body); | |
206 | } | |
207 | // @TODO: Remove this when http://drupal.org/node/614146 drops | |
208 | else if (Drupal.wysiwyg.instances[html_message].insert) { | |
209 | alert("Please note your editor doesn't completely support this function. You may need to clear the contents of the editor prior to choosing a new template."); | |
210 | Drupal.wysiwyg.instances[html_message].insert(html_body); | |
211 | } | |
212 | else { | |
213 | alert("Sorry, your editor doesn't support this function yet."); | |
214 | } | |
215 | } | |
216 | else { | |
217 | cj("#"+ html_message).val( html_body ); | |
218 | } | |
219 | if (isPDF) { | |
220 | var bind = data.pdf_format_id ? true : false ; | |
221 | selectFormat( data.pdf_format_id, bind ); | |
222 | if (!bind) { | |
223 | document.getElementById("bindFormat").style.display = "none"; | |
224 | } | |
225 | } | |
226 | }, 'json'); | |
227 | } | |
228 | ||
229 | if ( isMailing ) { | |
1e035d58 | 230 | document.getElementById(prefix + "editMessageDetails").style.display = "block"; |
6a488035 | 231 | |
1e035d58 | 232 | function verify(select, prefix) { |
233 | prefix = prefix || ''; | |
234 | if (document.getElementsByName(prefix + "saveTemplate")[0].checked == false) { | |
235 | document.getElementById(prefix + "saveDetails").style.display = "none"; | |
6a488035 | 236 | } |
1e035d58 | 237 | document.getElementById(prefix + "editMessageDetails").style.display = "block"; |
6a488035 TO |
238 | |
239 | var templateExists = true; | |
1e035d58 | 240 | if (document.getElementById(prefix + "template") == null) { |
6a488035 TO |
241 | templateExists = false; |
242 | } | |
243 | ||
1e035d58 | 244 | if (templateExists && document.getElementById(prefix + "template").value) { |
245 | document.getElementById(prefix + "updateDetails").style.display = ''; | |
6a488035 TO |
246 | } |
247 | else { | |
1e035d58 | 248 | document.getElementById(prefix + "updateDetails").style.display = 'none'; |
6a488035 TO |
249 | } |
250 | ||
1e035d58 | 251 | document.getElementById(prefix + "saveTemplateName").disabled = false; |
6a488035 TO |
252 | } |
253 | ||
1e035d58 | 254 | function showSaveDetails(chkbox, prefix) { |
255 | prefix = prefix || ''; | |
6a488035 | 256 | if (chkbox.checked) { |
1e035d58 | 257 | document.getElementById(prefix + "saveDetails").style.display = "block"; |
258 | document.getElementById(prefix + "saveTemplateName").disabled = false; | |
6a488035 TO |
259 | } |
260 | else { | |
1e035d58 | 261 | document.getElementById(prefix + "saveDetails").style.display = "none"; |
262 | document.getElementById(prefix + "saveTemplateName").disabled = true; | |
6a488035 TO |
263 | } |
264 | } | |
265 | ||
1e035d58 | 266 | if (cj("#sms_text_message").length) { |
267 | showSaveUpdateChkBox('SMS'); | |
268 | } | |
269 | if (cj("#text_message").length) { | |
270 | showSaveUpdateChkBox(); | |
271 | } | |
6a488035 TO |
272 | |
273 | {/literal} | |
274 | {if $editor eq "ckeditor"} | |
275 | {literal} | |
3cc60a06 | 276 | CRM.$(function($) { |
6a488035 TO |
277 | oEditor = CKEDITOR.instances['html_message']; |
278 | oEditor.BaseHref = '' ; | |
279 | oEditor.UserFilesPath = '' ; | |
280 | oEditor.on( 'focus', verify ); | |
281 | }); | |
282 | {/literal} | |
283 | {elseif $editor eq "tinymce"} | |
284 | {literal} | |
3cc60a06 | 285 | CRM.$(function($) { |
6a488035 | 286 | if ( isMailing ) { |
ae8f569f | 287 | $('div.html').hover( |
6a488035 TO |
288 | function( ) { |
289 | if ( tinyMCE.get(html_message) ) { | |
290 | tinyMCE.get(html_message).onKeyUp.add(function() { | |
291 | verify( ); | |
292 | }); | |
293 | } | |
294 | }, | |
295 | function( ) { | |
296 | if ( tinyMCE.get(html_message) ) { | |
297 | if ( tinyMCE.get(html_message).getContent() ) { | |
298 | verify( ); | |
299 | } | |
300 | } | |
301 | } | |
302 | ); | |
303 | } | |
304 | }); | |
305 | {/literal} | |
306 | {elseif $editor eq "drupalwysiwyg"} | |
307 | {literal} | |
3cc60a06 | 308 | CRM.$(function($) { |
6a488035 | 309 | if ( isMailing ) { |
ae8f569f | 310 | $('div.html').hover( |
6a488035 TO |
311 | verify, |
312 | verify | |
313 | ); | |
314 | } | |
315 | }); | |
316 | {/literal} | |
317 | {/if} | |
318 | {literal} | |
319 | } | |
320 | ||
3cc60a06 | 321 | CRM.$(function($) { |
ac0a3db5 CW |
322 | function insertToken() { |
323 | var | |
324 | token = $(this).val(), | |
325 | field = $(this).data('field'); | |
326 | if (field === 'html_message') { | |
327 | tokenReplHtml(token); | |
328 | } else { | |
95136c4e | 329 | field = textMsgID($(this)); |
ac0a3db5 CW |
330 | $('#' + field).replaceSelection(token); |
331 | } | |
332 | $(this).select2('val', ''); | |
333 | if (isMailing) { | |
334 | verify(); | |
335 | } | |
6a488035 | 336 | } |
6a488035 | 337 | |
95136c4e | 338 | function textMsgID(obj) { |
339 | if (obj.parents().is("#sms")) { | |
340 | field = 'sms #' + obj.data('field'); | |
341 | } | |
342 | else if(obj.parents().is("#email")) { | |
343 | field = 'email #' + obj.data('field'); | |
344 | } | |
345 | else { | |
346 | field = obj.data('field'); | |
347 | } | |
348 | ||
349 | return field; | |
350 | } | |
351 | ||
ac0a3db5 CW |
352 | function tokenReplHtml(token) { |
353 | var editor = {/literal}"{$editor}"{literal}; | |
354 | if ( editor == "tinymce" ) { | |
355 | tinyMCE.execInstanceCommand('html_message',"mceInsertContent",false, token ); | |
356 | } | |
357 | else if ( editor == "joomlaeditor" ) { | |
358 | tinyMCE.execCommand('mceInsertContent',false, token); | |
359 | var msg = document.getElementById(html_message).value; | |
360 | var cursorlen = document.getElementById(html_message).selectionStart; | |
361 | var textlen = msg.length; | |
362 | document.getElementById(html_message).value = msg.substring(0, cursorlen) + token + msg.substring(cursorlen, textlen); | |
363 | var cursorPos = (cursorlen + token.length); | |
364 | document.getElementById(html_message).selectionStart = cursorPos; | |
365 | document.getElementById(html_message).selectionEnd = cursorPos; | |
366 | document.getElementById(html_message).focus(); | |
367 | } | |
368 | else if ( editor == "ckeditor" ) { | |
369 | oEditor = CKEDITOR.instances[html_message]; | |
370 | oEditor.insertHtml(token.toString() ); | |
371 | } | |
372 | else if ( editor == "drupalwysiwyg" ) { | |
373 | if (Drupal.wysiwyg.instances[html_message].insert) { | |
374 | Drupal.wysiwyg.instances[html_message].insert(token.toString() ); | |
375 | } | |
376 | else { | |
377 | alert("Sorry, your editor doesn't support this function yet."); | |
378 | } | |
6a488035 TO |
379 | } |
380 | else { | |
ae8f569f | 381 | $( "#"+ html_message ).replaceSelection( token ); |
6a488035 TO |
382 | } |
383 | } | |
6a488035 | 384 | |
ac0a3db5 | 385 | // Initialize token selector widgets |
b50fdacc | 386 | var form = $('form.{/literal}{$form.formClass}{literal}'); |
ac0a3db5 | 387 | $('input.crm-token-selector', form) |
5ad67eee | 388 | .addClass('crm-action-menu action-icon-token') |
ac0a3db5 | 389 | .change(insertToken) |
a243158e | 390 | .crmSelect2({ |
ac0a3db5 | 391 | data: form.data('tokens'), |
5ad67eee | 392 | placeholder: '{/literal}{ts escape='js'}Tokens{/ts}{literal}' |
ac0a3db5 | 393 | }); |
6a488035 | 394 | |
ae8f569f CW |
395 | $('.accordion .head').addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all "); |
396 | $('.resizable-textarea textarea').css( 'width', '99%' ); | |
397 | $('.grippie').css( 'margin-right', '3px'); | |
398 | $('.accordion .head').hover( function() { $(this).addClass( "ui-state-hover"); | |
399 | }, function() { $(this).removeClass( "ui-state-hover"); | |
6a488035 | 400 | }).bind('click', function() { |
ae8f569f | 401 | var checkClass = $(this).find('span').attr( 'class' ); |
6a488035 TO |
402 | var len = checkClass.length; |
403 | if ( checkClass.substring( len - 1, len ) == 's' ) { | |
ae8f569f CW |
404 | $(this).find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-e'); |
405 | $("span#help"+$(this).find('span').attr('id')).hide(); | |
6a488035 TO |
406 | } |
407 | else { | |
ae8f569f CW |
408 | $(this).find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-s'); |
409 | $("span#help"+$(this).find('span').attr('id')).show(); | |
6a488035 | 410 | } |
ae8f569f | 411 | $(this).next().toggle(); return false; |
6a488035 | 412 | }).next().hide(); |
ae8f569f CW |
413 | $('span#html').removeClass().addClass('ui-icon ui-icon-triangle-1-s'); |
414 | $("div.html").show(); | |
6a488035 TO |
415 | |
416 | if ( !isMailing ) { | |
ae8f569f | 417 | $("div.text").show(); |
6a488035 | 418 | } |
6a488035 | 419 | |
ac0a3db5 CW |
420 | function setSignature() { |
421 | var emailID = $("#fromEmailAddress").val( ); | |
422 | if ( !isNaN( emailID ) ) { | |
423 | var dataUrl = {/literal}"{crmURL p='civicrm/ajax/signature' h=0 }"{literal}; | |
424 | $.post( dataUrl, {emailID: emailID}, function( data ) { | |
425 | var editor = {/literal}"{$editor}"{literal}; | |
426 | ||
427 | if (data.signature_text) { | |
428 | // get existing text & html and append signatue | |
429 | var textMessage = $("#"+ text_message).val( ) + '\n\n--\n' + data.signature_text; | |
430 | ||
431 | // append signature | |
432 | $("#"+ text_message).val( textMessage ); | |
6a488035 | 433 | } |
ac0a3db5 CW |
434 | |
435 | if ( data.signature_html ) { | |
436 | var htmlMessage = $("#"+ html_message).val( ) + '<br/><br/>--<br/>' + data.signature_html; | |
437 | ||
438 | // set wysiwg editor | |
439 | if ( editor == "ckeditor" ) { | |
440 | oEditor = CKEDITOR.instances[html_message]; | |
441 | var htmlMessage = oEditor.getData( ) + '<br/><br/>--' + data.signature_html; | |
442 | oEditor.setData( htmlMessage ); | |
443 | } | |
444 | else if ( editor == "tinymce" ) { | |
445 | tinyMCE.execInstanceCommand('html_message',"mceInsertContent",false, htmlMessage); | |
446 | } | |
447 | else if ( editor == "drupalwysiwyg" ) { | |
448 | if (Drupal.wysiwyg.instances[html_message].setContent) { | |
449 | Drupal.wysiwyg.instances[html_message].setContent(htmlMessage); | |
450 | } | |
451 | // @TODO: Remove this when http://drupal.org/node/614146 drops | |
452 | else if (Drupal.wysiwyg.instances[html_message].insert) { | |
453 | alert("Please note your editor doesn't completely support this function. You may need to clear the contents of the editor prior to choosing a new template."); | |
454 | Drupal.wysiwyg.instances[html_message].insert(htmlMessage); | |
455 | } | |
456 | else { | |
457 | alert("Sorry, your editor doesn't support this function yet."); | |
458 | } | |
459 | } | |
460 | else { | |
461 | $("#"+ html_message).val(htmlMessage); | |
6a488035 TO |
462 | } |
463 | } | |
ac0a3db5 | 464 | }, 'json'); |
6a488035 | 465 | } |
ac0a3db5 | 466 | } |
20b22300 | 467 | $("#fromEmailAddress", form).change(setSignature); |
6a488035 TO |
468 | }); |
469 | ||
6a488035 TO |
470 | </script> |
471 | {/literal} |