Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
fee14197 | 3 | | CiviCRM version 5 | |
6a488035 | 4 | +--------------------------------------------------------------------+ |
8c9251b3 | 5 | | Copyright CiviCRM LLC (c) 2004-2018 | |
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 | *} | |
6a488035 | 26 | <script type="text/javascript"> |
b50fdacc | 27 | cj('form.{$form.formClass}').data('tokens', {$tokens|@json_encode}); |
6a488035 TO |
28 | var text_message = null; |
29 | var html_message = null; | |
1e035d58 | 30 | var prefix = ''; |
6a488035 TO |
31 | var isPDF = false; |
32 | var isMailing = false; | |
33 | ||
6a488035 TO |
34 | {if $form.formName eq 'MessageTemplates'} |
35 | {literal} | |
36 | text_message = "msg_text"; | |
37 | html_message = "msg_html"; | |
38 | {/literal} | |
39 | {elseif $form.formName eq 'Address'} | |
40 | {literal} | |
41 | text_message = "mailing_format"; | |
42 | isMailing = false; | |
43 | {/literal} | |
1b7a39f5 | 44 | {elseif $form.formClass eq 'CRM_SMS_Form_Upload' || $form.formClass eq 'CRM_Contact_Form_Task_SMS'} |
1e035d58 | 45 | {literal} |
46 | prefix = "SMS"; | |
47 | text_message = "sms_text_message"; | |
48 | isMailing = true; | |
49 | {/literal} | |
6a488035 TO |
50 | {else} |
51 | {literal} | |
52 | text_message = "text_message"; | |
53 | html_message = (cj("#edit-html-message-value").length > 0) ? "edit-html-message-value" : "html_message"; | |
54 | isMailing = true; | |
55 | {/literal} | |
56 | {/if} | |
57 | ||
58 | {if $form.formName eq 'PDF'} | |
59 | {literal} | |
60 | isPDF = true; | |
61 | {/literal} | |
62 | {/if} | |
63 | ||
64 | {if $templateSelected} | |
65 | {literal} | |
1e035d58 | 66 | if ( document.getElementsByName(prefix + "saveTemplate")[0].checked ) { |
67 | document.getElementById(prefix + "template").selectedIndex = {/literal}{$templateSelected}{literal}; | |
6a488035 TO |
68 | } |
69 | {/literal} | |
70 | {/if} | |
71 | {literal} | |
72 | ||
1e035d58 | 73 | function showSaveUpdateChkBox(prefix) { |
74 | prefix = prefix || ''; | |
75 | if (document.getElementById(prefix + "template") == null) { | |
76 | if (document.getElementsByName(prefix + "saveTemplate")[0].checked){ | |
77 | document.getElementById(prefix + "saveDetails").style.display = "block"; | |
78 | document.getElementById(prefix + "editMessageDetails").style.display = "block"; | |
6a488035 TO |
79 | } |
80 | else { | |
1e035d58 | 81 | document.getElementById(prefix + "saveDetails").style.display = "none"; |
82 | document.getElementById(prefix + "updateDetails").style.display = "none"; | |
6a488035 TO |
83 | } |
84 | return; | |
85 | } | |
86 | ||
1e035d58 | 87 | if (document.getElementsByName(prefix + "saveTemplate")[0].checked && |
88 | document.getElementsByName(prefix + "updateTemplate")[0].checked == false) { | |
89 | document.getElementById(prefix + "updateDetails").style.display = "none"; | |
6a488035 | 90 | } |
1e035d58 | 91 | else if ( document.getElementsByName(prefix + "saveTemplate")[0].checked && |
92 | document.getElementsByName(prefix + "updateTemplate")[0].checked ){ | |
93 | document.getElementById(prefix + "editMessageDetails").style.display = "block"; | |
94 | document.getElementById(pefix + "saveDetails").style.display = "block"; | |
6a488035 | 95 | } |
1e035d58 | 96 | else if ( document.getElementsByName(prefix + "saveTemplate")[0].checked == false && |
97 | document.getElementsByName(prefix + "updateTemplate")[0].checked ) { | |
98 | document.getElementById(prefix + "saveDetails").style.display = "none"; | |
99 | document.getElementById(prefix + "editMessageDetails").style.display = "block"; | |
6a488035 TO |
100 | } |
101 | else { | |
1e035d58 | 102 | document.getElementById(prefix + "saveDetails").style.display = "none"; |
103 | document.getElementById(prefix + "updateDetails").style.display = "none"; | |
6a488035 TO |
104 | } |
105 | } | |
106 | ||
1e035d58 | 107 | function selectValue( val, prefix) { |
108 | document.getElementsByName(prefix + "saveTemplate")[0].checked = false; | |
109 | document.getElementsByName(prefix + "updateTemplate")[0].checked = false; | |
110 | showSaveUpdateChkBox(prefix); | |
6a488035 | 111 | if ( !val ) { |
04a76231 | 112 | if (document.getElementById("subject").length) { |
113 | document.getElementById("subject").value =""; | |
114 | } | |
1e035d58 | 115 | if (document.getElementById("subject").length) { |
116 | document.getElementById("subject").value =""; | |
117 | } | |
6a488035 | 118 | if ( !isPDF ) { |
1e035d58 | 119 | if (prefix == 'SMS') { |
120 | document.getElementById("sms_text_message").value =""; | |
121 | return; | |
122 | } | |
123 | else { | |
124 | document.getElementById("text_message").value =""; | |
125 | } | |
6a488035 | 126 | } |
04a76231 | 127 | else { |
128 | cj('.crm-html_email-accordion').show(); | |
129 | cj('.crm-document-accordion').hide(); | |
2c8a6e63 | 130 | cj('#document_type').closest('tr').show(); |
04a76231 | 131 | } |
132 | ||
13d9bc82 | 133 | CRM.wysiwyg.setVal('#' + html_message, ''); |
6a488035 TO |
134 | if ( isPDF ) { |
135 | showBindFormatChkBox(); | |
136 | } | |
137 | return; | |
138 | } | |
139 | ||
140 | var dataUrl = {/literal}"{crmURL p='civicrm/ajax/template' h=0 }"{literal}; | |
141 | ||
142 | cj.post( dataUrl, {tid: val}, function( data ) { | |
9cbcd63f | 143 | var hide = (data.document_body && isPDF) ? false : true; |
4c9dc59f | 144 | cj('.crm-html_email-accordion, .crm-pdf-format-accordion').toggle(hide); |
04a76231 | 145 | cj('.crm-document-accordion').toggle(!hide); |
4c9dc59f | 146 | |
2c8a6e63 | 147 | cj('#document_type').closest('tr').toggle(hide); |
04a76231 | 148 | |
8d63890e | 149 | // Unset any uploaded document when any template is chosen |
150 | if (cj('#document.file').length) { | |
151 | cj('#document_file').val(''); | |
152 | } | |
153 | ||
04a76231 | 154 | if (!hide) { |
04a76231 | 155 | cj("#subject").val( data.subject ); |
9cbcd63f | 156 | cj("#document-preview").html(data.document_body).parent().css({'background': 'white'}); |
04a76231 | 157 | return; |
90a73810 | 158 | } |
159 | ||
6a488035 | 160 | if ( !isPDF ) { |
1e035d58 | 161 | if (prefix == "SMS") { |
162 | text_message = "sms_text_message"; | |
163 | } | |
6a488035 TO |
164 | if ( data.msg_text ) { |
165 | cj("#"+text_message).val( data.msg_text ); | |
166 | cj("div.text").show(); | |
167 | cj(".head").find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-s'); | |
168 | cj("#helptext").show(); | |
169 | } | |
170 | else { | |
171 | cj("#"+text_message).val(""); | |
172 | } | |
173 | } | |
1e035d58 | 174 | |
175 | if (prefix == "SMS") { | |
176 | return; | |
177 | } | |
9ed86096 | 178 | else { |
179 | cj("#subject").val( data.subject ); | |
180 | } | |
6a488035 | 181 | |
13d9bc82 CW |
182 | CRM.wysiwyg.setVal('#' + html_message, data.msg_html || ''); |
183 | ||
6a488035 TO |
184 | if (isPDF) { |
185 | var bind = data.pdf_format_id ? true : false ; | |
186 | selectFormat( data.pdf_format_id, bind ); | |
187 | if (!bind) { | |
188 | document.getElementById("bindFormat").style.display = "none"; | |
189 | } | |
190 | } | |
191 | }, 'json'); | |
192 | } | |
193 | ||
194 | if ( isMailing ) { | |
1e035d58 | 195 | document.getElementById(prefix + "editMessageDetails").style.display = "block"; |
6a488035 | 196 | |
1e035d58 | 197 | function verify(select, prefix) { |
198 | prefix = prefix || ''; | |
199 | if (document.getElementsByName(prefix + "saveTemplate")[0].checked == false) { | |
200 | document.getElementById(prefix + "saveDetails").style.display = "none"; | |
6a488035 | 201 | } |
1e035d58 | 202 | document.getElementById(prefix + "editMessageDetails").style.display = "block"; |
6a488035 TO |
203 | |
204 | var templateExists = true; | |
1e035d58 | 205 | if (document.getElementById(prefix + "template") == null) { |
6a488035 TO |
206 | templateExists = false; |
207 | } | |
208 | ||
1e035d58 | 209 | if (templateExists && document.getElementById(prefix + "template").value) { |
210 | document.getElementById(prefix + "updateDetails").style.display = ''; | |
6a488035 TO |
211 | } |
212 | else { | |
1e035d58 | 213 | document.getElementById(prefix + "updateDetails").style.display = 'none'; |
6a488035 TO |
214 | } |
215 | ||
1e035d58 | 216 | document.getElementById(prefix + "saveTemplateName").disabled = false; |
6a488035 TO |
217 | } |
218 | ||
1e035d58 | 219 | function showSaveDetails(chkbox, prefix) { |
220 | prefix = prefix || ''; | |
6a488035 | 221 | if (chkbox.checked) { |
1e035d58 | 222 | document.getElementById(prefix + "saveDetails").style.display = "block"; |
223 | document.getElementById(prefix + "saveTemplateName").disabled = false; | |
6a488035 TO |
224 | } |
225 | else { | |
1e035d58 | 226 | document.getElementById(prefix + "saveDetails").style.display = "none"; |
227 | document.getElementById(prefix + "saveTemplateName").disabled = true; | |
6a488035 TO |
228 | } |
229 | } | |
230 | ||
1e035d58 | 231 | if (cj("#sms_text_message").length) { |
232 | showSaveUpdateChkBox('SMS'); | |
233 | } | |
234 | if (cj("#text_message").length) { | |
235 | showSaveUpdateChkBox(); | |
236 | } | |
6a488035 | 237 | |
13d9bc82 | 238 | cj('#' + html_message).on('focus change', verify); |
6a488035 TO |
239 | } |
240 | ||
3cc60a06 | 241 | CRM.$(function($) { |
ac0a3db5 CW |
242 | function insertToken() { |
243 | var | |
244 | token = $(this).val(), | |
245 | field = $(this).data('field'); | |
0980703c | 246 | if (field.indexOf('html') < 0) { |
95136c4e | 247 | field = textMsgID($(this)); |
ac0a3db5 | 248 | } |
13d9bc82 | 249 | CRM.wysiwyg.insert('#' + field, token); |
ac0a3db5 CW |
250 | $(this).select2('val', ''); |
251 | if (isMailing) { | |
252 | verify(); | |
253 | } | |
6a488035 | 254 | } |
6a488035 | 255 | |
95136c4e | 256 | function textMsgID(obj) { |
257 | if (obj.parents().is("#sms")) { | |
258 | field = 'sms #' + obj.data('field'); | |
259 | } | |
260 | else if(obj.parents().is("#email")) { | |
261 | field = 'email #' + obj.data('field'); | |
262 | } | |
263 | else { | |
264 | field = obj.data('field'); | |
265 | } | |
266 | ||
267 | return field; | |
268 | } | |
269 | ||
ac0a3db5 | 270 | // Initialize token selector widgets |
b50fdacc | 271 | var form = $('form.{/literal}{$form.formClass}{literal}'); |
ac0a3db5 | 272 | $('input.crm-token-selector', form) |
9597c394 | 273 | .addClass('crm-action-menu fa-code') |
ac0a3db5 | 274 | .change(insertToken) |
a243158e | 275 | .crmSelect2({ |
ac0a3db5 | 276 | data: form.data('tokens'), |
5ad67eee | 277 | placeholder: '{/literal}{ts escape='js'}Tokens{/ts}{literal}' |
ac0a3db5 | 278 | }); |
6a488035 | 279 | |
77447093 CW |
280 | $('.accordion .head').addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ") |
281 | .hover( function() { $(this).addClass( "ui-state-hover"); | |
ae8f569f | 282 | }, function() { $(this).removeClass( "ui-state-hover"); |
6a488035 | 283 | }).bind('click', function() { |
ae8f569f | 284 | var checkClass = $(this).find('span').attr( 'class' ); |
6a488035 TO |
285 | var len = checkClass.length; |
286 | if ( checkClass.substring( len - 1, len ) == 's' ) { | |
ae8f569f CW |
287 | $(this).find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-e'); |
288 | $("span#help"+$(this).find('span').attr('id')).hide(); | |
6a488035 TO |
289 | } |
290 | else { | |
ae8f569f CW |
291 | $(this).find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-s'); |
292 | $("span#help"+$(this).find('span').attr('id')).show(); | |
6a488035 | 293 | } |
ae8f569f | 294 | $(this).next().toggle(); return false; |
6a488035 | 295 | }).next().hide(); |
ae8f569f CW |
296 | $('span#html').removeClass().addClass('ui-icon ui-icon-triangle-1-s'); |
297 | $("div.html").show(); | |
6a488035 TO |
298 | |
299 | if ( !isMailing ) { | |
ae8f569f | 300 | $("div.text").show(); |
6a488035 | 301 | } |
6a488035 | 302 | |
ac0a3db5 CW |
303 | function setSignature() { |
304 | var emailID = $("#fromEmailAddress").val( ); | |
305 | if ( !isNaN( emailID ) ) { | |
306 | var dataUrl = {/literal}"{crmURL p='civicrm/ajax/signature' h=0 }"{literal}; | |
307 | $.post( dataUrl, {emailID: emailID}, function( data ) { | |
ac0a3db5 CW |
308 | |
309 | if (data.signature_text) { | |
ac0a3db5 | 310 | var textMessage = $("#"+ text_message).val( ) + '\n\n--\n' + data.signature_text; |
ac0a3db5 | 311 | $("#"+ text_message).val( textMessage ); |
6a488035 | 312 | } |
ac0a3db5 | 313 | |
13d9bc82 CW |
314 | if (data.signature_html) { |
315 | var htmlMessage = CRM.wysiwyg.getVal("#" + html_message) + '<br/><br/>--<br/>' + data.signature_html; | |
316 | CRM.wysiwyg.setVal("#" + html_message, htmlMessage); | |
6a488035 | 317 | } |
ac0a3db5 | 318 | }, 'json'); |
6a488035 | 319 | } |
ac0a3db5 | 320 | } |
20b22300 | 321 | $("#fromEmailAddress", form).change(setSignature); |
6a488035 TO |
322 | }); |
323 | ||
6a488035 TO |
324 | </script> |
325 | {/literal} |