version fixes
[civicrm-core.git] / templates / CRM / Mailing / Form / InsertTokens.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
2c4c49ca 3 | CiviCRM version 4.7 |
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*}
6a488035 26<script type="text/javascript">
b50fdacc 27cj('form.{$form.formClass}').data('tokens', {$tokens|@json_encode});
6a488035
TO
28var text_message = null;
29var html_message = null;
1e035d58 30var prefix = '';
6a488035
TO
31var isPDF = false;
32var 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 73function 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 107function 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 ) {
1e035d58 112 if (document.getElementById("subject").length) {
113 document.getElementById("subject").value ="";
114 }
6a488035 115 if ( !isPDF ) {
1e035d58 116 if (prefix == 'SMS') {
117 document.getElementById("sms_text_message").value ="";
118 return;
119 }
120 else {
121 document.getElementById("text_message").value ="";
122 }
6a488035 123 }
13d9bc82 124 CRM.wysiwyg.setVal('#' + html_message, '');
6a488035
TO
125 if ( isPDF ) {
126 showBindFormatChkBox();
127 }
128 return;
129 }
130
131 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/template' h=0 }"{literal};
132
133 cj.post( dataUrl, {tid: val}, function( data ) {
134 if ( !isPDF ) {
1e035d58 135 if (prefix == "SMS") {
136 text_message = "sms_text_message";
137 }
6a488035
TO
138 if ( data.msg_text ) {
139 cj("#"+text_message).val( data.msg_text );
140 cj("div.text").show();
141 cj(".head").find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-s');
142 cj("#helptext").show();
143 }
144 else {
145 cj("#"+text_message).val("");
146 }
147 }
1e035d58 148
149 if (prefix == "SMS") {
150 return;
151 }
9ed86096 152 else {
153 cj("#subject").val( data.subject );
154 }
6a488035 155
13d9bc82
CW
156 CRM.wysiwyg.setVal('#' + html_message, data.msg_html || '');
157
6a488035
TO
158 if (isPDF) {
159 var bind = data.pdf_format_id ? true : false ;
160 selectFormat( data.pdf_format_id, bind );
161 if (!bind) {
162 document.getElementById("bindFormat").style.display = "none";
163 }
164 }
165 }, 'json');
166}
167
168if ( isMailing ) {
1e035d58 169 document.getElementById(prefix + "editMessageDetails").style.display = "block";
6a488035 170
1e035d58 171 function verify(select, prefix) {
172 prefix = prefix || '';
173 if (document.getElementsByName(prefix + "saveTemplate")[0].checked == false) {
174 document.getElementById(prefix + "saveDetails").style.display = "none";
6a488035 175 }
1e035d58 176 document.getElementById(prefix + "editMessageDetails").style.display = "block";
6a488035
TO
177
178 var templateExists = true;
1e035d58 179 if (document.getElementById(prefix + "template") == null) {
6a488035
TO
180 templateExists = false;
181 }
182
1e035d58 183 if (templateExists && document.getElementById(prefix + "template").value) {
184 document.getElementById(prefix + "updateDetails").style.display = '';
6a488035
TO
185 }
186 else {
1e035d58 187 document.getElementById(prefix + "updateDetails").style.display = 'none';
6a488035
TO
188 }
189
1e035d58 190 document.getElementById(prefix + "saveTemplateName").disabled = false;
6a488035
TO
191 }
192
1e035d58 193 function showSaveDetails(chkbox, prefix) {
194 prefix = prefix || '';
6a488035 195 if (chkbox.checked) {
1e035d58 196 document.getElementById(prefix + "saveDetails").style.display = "block";
197 document.getElementById(prefix + "saveTemplateName").disabled = false;
6a488035
TO
198 }
199 else {
1e035d58 200 document.getElementById(prefix + "saveDetails").style.display = "none";
201 document.getElementById(prefix + "saveTemplateName").disabled = true;
6a488035
TO
202 }
203 }
204
1e035d58 205 if (cj("#sms_text_message").length) {
206 showSaveUpdateChkBox('SMS');
207 }
208 if (cj("#text_message").length) {
209 showSaveUpdateChkBox();
210 }
6a488035 211
13d9bc82 212 cj('#' + html_message).on('focus change', verify);
6a488035
TO
213}
214
3cc60a06 215CRM.$(function($) {
ac0a3db5
CW
216 function insertToken() {
217 var
218 token = $(this).val(),
219 field = $(this).data('field');
13d9bc82 220 if (field !== 'html_message') {
95136c4e 221 field = textMsgID($(this));
ac0a3db5 222 }
13d9bc82 223 CRM.wysiwyg.insert('#' + field, token);
ac0a3db5
CW
224 $(this).select2('val', '');
225 if (isMailing) {
226 verify();
227 }
6a488035 228 }
6a488035 229
95136c4e 230 function textMsgID(obj) {
231 if (obj.parents().is("#sms")) {
232 field = 'sms #' + obj.data('field');
233 }
234 else if(obj.parents().is("#email")) {
235 field = 'email #' + obj.data('field');
236 }
237 else {
238 field = obj.data('field');
239 }
240
241 return field;
242 }
243
ac0a3db5 244 // Initialize token selector widgets
b50fdacc 245 var form = $('form.{/literal}{$form.formClass}{literal}');
ac0a3db5 246 $('input.crm-token-selector', form)
5ad67eee 247 .addClass('crm-action-menu action-icon-token')
ac0a3db5 248 .change(insertToken)
a243158e 249 .crmSelect2({
ac0a3db5 250 data: form.data('tokens'),
5ad67eee 251 placeholder: '{/literal}{ts escape='js'}Tokens{/ts}{literal}'
ac0a3db5 252 });
6a488035 253
77447093
CW
254 $('.accordion .head').addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ")
255 .hover( function() { $(this).addClass( "ui-state-hover");
ae8f569f 256 }, function() { $(this).removeClass( "ui-state-hover");
6a488035 257 }).bind('click', function() {
ae8f569f 258 var checkClass = $(this).find('span').attr( 'class' );
6a488035
TO
259 var len = checkClass.length;
260 if ( checkClass.substring( len - 1, len ) == 's' ) {
ae8f569f
CW
261 $(this).find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-e');
262 $("span#help"+$(this).find('span').attr('id')).hide();
6a488035
TO
263 }
264 else {
ae8f569f
CW
265 $(this).find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-s');
266 $("span#help"+$(this).find('span').attr('id')).show();
6a488035 267 }
ae8f569f 268 $(this).next().toggle(); return false;
6a488035 269 }).next().hide();
ae8f569f
CW
270 $('span#html').removeClass().addClass('ui-icon ui-icon-triangle-1-s');
271 $("div.html").show();
6a488035
TO
272
273 if ( !isMailing ) {
ae8f569f 274 $("div.text").show();
6a488035 275 }
6a488035 276
ac0a3db5
CW
277 function setSignature() {
278 var emailID = $("#fromEmailAddress").val( );
279 if ( !isNaN( emailID ) ) {
280 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/signature' h=0 }"{literal};
281 $.post( dataUrl, {emailID: emailID}, function( data ) {
ac0a3db5
CW
282
283 if (data.signature_text) {
ac0a3db5 284 var textMessage = $("#"+ text_message).val( ) + '\n\n--\n' + data.signature_text;
ac0a3db5 285 $("#"+ text_message).val( textMessage );
6a488035 286 }
ac0a3db5 287
13d9bc82
CW
288 if (data.signature_html) {
289 var htmlMessage = CRM.wysiwyg.getVal("#" + html_message) + '<br/><br/>--<br/>' + data.signature_html;
290 CRM.wysiwyg.setVal("#" + html_message, htmlMessage);
6a488035 291 }
ac0a3db5 292 }, 'json');
6a488035 293 }
ac0a3db5 294 }
20b22300 295 $("#fromEmailAddress", form).change(setSignature);
6a488035
TO
296});
297
6a488035
TO
298</script>
299{/literal}