CRM-16354 - Remove old wysiwyg code
[civicrm-core.git] / templates / CRM / Mailing / Form / InsertTokens.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.6 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2015 |
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">
32 cj('form.{$form.formClass}').data('tokens', {$tokens|@json_encode});
33 var text_message = null;
34 var html_message = null;
35 var prefix = '';
36 var isPDF = false;
37 var isMailing = false;
38
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}
49 {elseif $form.formClass eq 'CRM_SMS_Form_Upload' || $form.formClass eq 'CRM_Contact_Form_Task_SMS'}
50 {literal}
51 prefix = "SMS";
52 text_message = "sms_text_message";
53 isMailing = true;
54 {/literal}
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}
71 if ( document.getElementsByName(prefix + "saveTemplate")[0].checked ) {
72 document.getElementById(prefix + "template").selectedIndex = {/literal}{$templateSelected}{literal};
73 }
74 {/literal}
75 {/if}
76 {literal}
77
78 function showSaveUpdateChkBox(prefix) {
79 prefix = prefix || '';
80 if (document.getElementById(prefix + "template") == null) {
81 if (document.getElementsByName(prefix + "saveTemplate")[0].checked){
82 document.getElementById(prefix + "saveDetails").style.display = "block";
83 document.getElementById(prefix + "editMessageDetails").style.display = "block";
84 }
85 else {
86 document.getElementById(prefix + "saveDetails").style.display = "none";
87 document.getElementById(prefix + "updateDetails").style.display = "none";
88 }
89 return;
90 }
91
92 if (document.getElementsByName(prefix + "saveTemplate")[0].checked &&
93 document.getElementsByName(prefix + "updateTemplate")[0].checked == false) {
94 document.getElementById(prefix + "updateDetails").style.display = "none";
95 }
96 else if ( document.getElementsByName(prefix + "saveTemplate")[0].checked &&
97 document.getElementsByName(prefix + "updateTemplate")[0].checked ){
98 document.getElementById(prefix + "editMessageDetails").style.display = "block";
99 document.getElementById(pefix + "saveDetails").style.display = "block";
100 }
101 else if ( document.getElementsByName(prefix + "saveTemplate")[0].checked == false &&
102 document.getElementsByName(prefix + "updateTemplate")[0].checked ) {
103 document.getElementById(prefix + "saveDetails").style.display = "none";
104 document.getElementById(prefix + "editMessageDetails").style.display = "block";
105 }
106 else {
107 document.getElementById(prefix + "saveDetails").style.display = "none";
108 document.getElementById(prefix + "updateDetails").style.display = "none";
109 }
110 }
111
112 function selectValue( val, prefix) {
113 document.getElementsByName(prefix + "saveTemplate")[0].checked = false;
114 document.getElementsByName(prefix + "updateTemplate")[0].checked = false;
115 showSaveUpdateChkBox(prefix);
116 if ( !val ) {
117 if (document.getElementById("subject").length) {
118 document.getElementById("subject").value ="";
119 }
120 if ( !isPDF ) {
121 if (prefix == 'SMS') {
122 document.getElementById("sms_text_message").value ="";
123 return;
124 }
125 else {
126 document.getElementById("text_message").value ="";
127 }
128 }
129 CRM.wysiwyg.setVal('#' + html_message, '');
130 if ( isPDF ) {
131 showBindFormatChkBox();
132 }
133 return;
134 }
135
136 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/template' h=0 }"{literal};
137
138 cj.post( dataUrl, {tid: val}, function( data ) {
139 if ( !isPDF ) {
140 if (prefix == "SMS") {
141 text_message = "sms_text_message";
142 }
143 if ( data.msg_text ) {
144 cj("#"+text_message).val( data.msg_text );
145 cj("div.text").show();
146 cj(".head").find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-s');
147 cj("#helptext").show();
148 }
149 else {
150 cj("#"+text_message).val("");
151 }
152 }
153
154 if (prefix == "SMS") {
155 return;
156 }
157 else {
158 cj("#subject").val( data.subject );
159 }
160
161 CRM.wysiwyg.setVal('#' + html_message, data.msg_html || '');
162
163 if (isPDF) {
164 var bind = data.pdf_format_id ? true : false ;
165 selectFormat( data.pdf_format_id, bind );
166 if (!bind) {
167 document.getElementById("bindFormat").style.display = "none";
168 }
169 }
170 }, 'json');
171 }
172
173 if ( isMailing ) {
174 document.getElementById(prefix + "editMessageDetails").style.display = "block";
175
176 function verify(select, prefix) {
177 prefix = prefix || '';
178 if (document.getElementsByName(prefix + "saveTemplate")[0].checked == false) {
179 document.getElementById(prefix + "saveDetails").style.display = "none";
180 }
181 document.getElementById(prefix + "editMessageDetails").style.display = "block";
182
183 var templateExists = true;
184 if (document.getElementById(prefix + "template") == null) {
185 templateExists = false;
186 }
187
188 if (templateExists && document.getElementById(prefix + "template").value) {
189 document.getElementById(prefix + "updateDetails").style.display = '';
190 }
191 else {
192 document.getElementById(prefix + "updateDetails").style.display = 'none';
193 }
194
195 document.getElementById(prefix + "saveTemplateName").disabled = false;
196 }
197
198 function showSaveDetails(chkbox, prefix) {
199 prefix = prefix || '';
200 if (chkbox.checked) {
201 document.getElementById(prefix + "saveDetails").style.display = "block";
202 document.getElementById(prefix + "saveTemplateName").disabled = false;
203 }
204 else {
205 document.getElementById(prefix + "saveDetails").style.display = "none";
206 document.getElementById(prefix + "saveTemplateName").disabled = true;
207 }
208 }
209
210 if (cj("#sms_text_message").length) {
211 showSaveUpdateChkBox('SMS');
212 }
213 if (cj("#text_message").length) {
214 showSaveUpdateChkBox();
215 }
216
217 cj('#' + html_message).on('focus change', verify);
218 }
219
220 CRM.$(function($) {
221 function insertToken() {
222 var
223 token = $(this).val(),
224 field = $(this).data('field');
225 if (field !== 'html_message') {
226 field = textMsgID($(this));
227 }
228 CRM.wysiwyg.insert('#' + field, token);
229 $(this).select2('val', '');
230 if (isMailing) {
231 verify();
232 }
233 }
234
235 function textMsgID(obj) {
236 if (obj.parents().is("#sms")) {
237 field = 'sms #' + obj.data('field');
238 }
239 else if(obj.parents().is("#email")) {
240 field = 'email #' + obj.data('field');
241 }
242 else {
243 field = obj.data('field');
244 }
245
246 return field;
247 }
248
249 // Initialize token selector widgets
250 var form = $('form.{/literal}{$form.formClass}{literal}');
251 $('input.crm-token-selector', form)
252 .addClass('crm-action-menu action-icon-token')
253 .change(insertToken)
254 .crmSelect2({
255 data: form.data('tokens'),
256 placeholder: '{/literal}{ts escape='js'}Tokens{/ts}{literal}'
257 });
258
259 $('.accordion .head').addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ");
260 $('.resizable-textarea textarea').css( 'width', '99%' );
261 $('.grippie').css( 'margin-right', '3px');
262 $('.accordion .head').hover( function() { $(this).addClass( "ui-state-hover");
263 }, function() { $(this).removeClass( "ui-state-hover");
264 }).bind('click', function() {
265 var checkClass = $(this).find('span').attr( 'class' );
266 var len = checkClass.length;
267 if ( checkClass.substring( len - 1, len ) == 's' ) {
268 $(this).find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-e');
269 $("span#help"+$(this).find('span').attr('id')).hide();
270 }
271 else {
272 $(this).find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-s');
273 $("span#help"+$(this).find('span').attr('id')).show();
274 }
275 $(this).next().toggle(); return false;
276 }).next().hide();
277 $('span#html').removeClass().addClass('ui-icon ui-icon-triangle-1-s');
278 $("div.html").show();
279
280 if ( !isMailing ) {
281 $("div.text").show();
282 }
283
284 function setSignature() {
285 var emailID = $("#fromEmailAddress").val( );
286 if ( !isNaN( emailID ) ) {
287 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/signature' h=0 }"{literal};
288 $.post( dataUrl, {emailID: emailID}, function( data ) {
289
290 if (data.signature_text) {
291 var textMessage = $("#"+ text_message).val( ) + '\n\n--\n' + data.signature_text;
292 $("#"+ text_message).val( textMessage );
293 }
294
295 if (data.signature_html) {
296 var htmlMessage = CRM.wysiwyg.getVal("#" + html_message) + '<br/><br/>--<br/>' + data.signature_html;
297 CRM.wysiwyg.setVal("#" + html_message, htmlMessage);
298 }
299 }, 'json');
300 }
301 }
302 $("#fromEmailAddress", form).change(setSignature);
303 });
304
305 </script>
306 {/literal}