2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2014 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
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>
31 <script type="text/javascript">
32 cj('form#{$form.formName}').data('tokens', {$tokens|@json_encode});
33 var text_message = null;
34 var html_message = null;
36 var isMailing = false;
39 {if $form.formName eq 'MessageTemplates'}
41 text_message = "msg_text";
42 html_message = "msg_html";
44 {elseif $form.formName eq 'Address'}
46 text_message = "mailing_format";
51 text_message = "text_message";
52 html_message = (cj("#edit-html-message-value").length > 0) ? "edit-html-message-value" : "html_message";
57 {if $form.formName eq 'PDF'}
63 {if $templateSelected}
65 if ( document.getElementsByName("saveTemplate")[0].checked ) {
66 document.getElementById('template').selectedIndex = {/literal}{$templateSelected}{literal};
72 var editor = {/literal}"{$editor}"{literal};
73 function showSaveUpdateChkBox() {
74 if (document.getElementById('template') == null) {
75 if (document.getElementsByName("saveTemplate")[0].checked){
76 document.getElementById("saveDetails").style.display = "block";
77 document.getElementById("editMessageDetails").style.display = "block";
80 document.getElementById("saveDetails").style.display = "none";
81 document.getElementById("editMessageDetails").style.display = "none";
86 if (document.getElementsByName("saveTemplate")[0].checked &&
87 document.getElementsByName("updateTemplate")[0].checked == false) {
88 document.getElementById("updateDetails").style.display = "none";
90 else if ( document.getElementsByName("saveTemplate")[0].checked &&
91 document.getElementsByName("updateTemplate")[0].checked ){
92 document.getElementById("editMessageDetails").style.display = "block";
93 document.getElementById("saveDetails").style.display = "block";
95 else if ( document.getElementsByName("saveTemplate")[0].checked == false &&
96 document.getElementsByName("updateTemplate")[0].checked ) {
97 document.getElementById("saveDetails").style.display = "none";
98 document.getElementById("editMessageDetails").style.display = "block";
101 document.getElementById("saveDetails").style.display = "none";
102 document.getElementById("editMessageDetails").style.display = "none";
106 function selectValue( val ) {
107 document.getElementsByName("saveTemplate")[0].checked = false;
108 document.getElementsByName("updateTemplate")[0].checked = false;
109 showSaveUpdateChkBox();
111 document.getElementById("subject").value ="";
113 document.getElementById(text_message).value ="";
115 if ( editor == "ckeditor" ) {
116 oEditor = CKEDITOR.instances[html_message];
119 else if ( editor == "tinymce" ) {
120 tinyMCE.getInstanceById(html_message).setContent( html_body );
122 else if ( editor == "joomlaeditor" ) {
123 document.getElementById(html_message).value = '' ;
124 tinyMCE.execCommand('mceSetContent',false, '');
126 else if ( editor =="drupalwysiwyg" ) {
127 if (Drupal.wysiwyg.instances[html_message].setContent) {
128 Drupal.wysiwyg.instances[html_message].setContent(html_body);
130 // @TODO: Remove this when http://drupal.org/node/614146 drops
131 else if (Drupal.wysiwyg.instances[html_message].insert) {
132 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.");
133 Drupal.wysiwyg.instances[html_message].insert(html_body);
136 alert("Sorry, your editor doesn't support this function yet.");
140 document.getElementById(html_message).value = '' ;
143 showBindFormatChkBox();
148 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/template' h=0 }"{literal};
150 cj.post( dataUrl, {tid: val}, function( data ) {
151 cj("#subject").val( data.subject );
153 if ( data.msg_text ) {
154 cj("#"+text_message).val( data.msg_text );
155 cj("div.text").show();
156 cj(".head").find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-s');
157 cj("#helptext").show();
160 cj("#"+text_message).val("");
164 if ( data.msg_html ) {
165 html_body = data.msg_html;
168 if (editor == "ckeditor") {
169 oEditor = CKEDITOR.instances[html_message];
170 oEditor.setData( html_body );
172 else if (editor == "tinymce") {
173 tinyMCE.execInstanceCommand('html_message',"mceInsertContent",false, html_body );
175 else if (editor == "joomlaeditor") {
176 cj("#"+ html_message).val( html_body );
177 tinyMCE.execCommand('mceSetContent',false, html_body);
179 else if ( editor =="drupalwysiwyg") {
180 if (Drupal.wysiwyg.instances[html_message].setContent) {
181 Drupal.wysiwyg.instances[html_message].setContent(html_body);
183 // @TODO: Remove this when http://drupal.org/node/614146 drops
184 else if (Drupal.wysiwyg.instances[html_message].insert) {
185 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.");
186 Drupal.wysiwyg.instances[html_message].insert(html_body);
189 alert("Sorry, your editor doesn't support this function yet.");
193 cj("#"+ html_message).val( html_body );
196 var bind = data.pdf_format_id ? true : false ;
197 selectFormat( data.pdf_format_id, bind );
199 document.getElementById("bindFormat").style.display = "none";
206 document.getElementById("editMessageDetails").style.display = "block";
208 function verify(select) {
209 if (document.getElementsByName("saveTemplate")[0].checked == false) {
210 document.getElementById("saveDetails").style.display = "none";
212 document.getElementById("editMessageDetails").style.display = "block";
214 var templateExists = true;
215 if (document.getElementById('template') == null) {
216 templateExists = false;
219 if (templateExists && document.getElementById('template').value) {
220 document.getElementById("updateDetails").style.display = '';
223 document.getElementById("updateDetails").style.display = 'none';
226 document.getElementById("saveTemplateName").disabled = false;
229 function showSaveDetails(chkbox) {
230 if (chkbox.checked) {
231 document.getElementById("saveDetails").style.display = "block";
232 document.getElementById("saveTemplateName").disabled = false;
235 document.getElementById("saveDetails").style.display = "none";
236 document.getElementById("saveTemplateName").disabled = true;
240 showSaveUpdateChkBox();
243 {if $editor eq "ckeditor"}
246 oEditor = CKEDITOR.instances['html_message'];
247 oEditor.BaseHref = '' ;
248 oEditor.UserFilesPath = '' ;
249 oEditor.on( 'focus', verify );
252 {elseif $editor eq "tinymce"}
256 cj('div.html').hover(
258 if ( tinyMCE.get(html_message) ) {
259 tinyMCE.get(html_message).onKeyUp.add(function() {
265 if ( tinyMCE.get(html_message) ) {
266 if ( tinyMCE.get(html_message).getContent() ) {
275 {elseif $editor eq "drupalwysiwyg"}
279 cj('div.html').hover(
291 function insertToken() {
293 token = $(this).val(),
294 field = $(this).data('field');
295 if (field === 'html_message') {
296 tokenReplHtml(token);
298 field = textMsgID($(this));
299 $('#' + field).replaceSelection(token);
301 $(this).select2('val', '');
307 function textMsgID(obj) {
308 if (obj.parents().is("#sms")) {
309 field = 'sms #' + obj.data('field');
311 else if(obj.parents().is("#email")) {
312 field = 'email #' + obj.data('field');
315 field = obj.data('field');
321 function tokenReplHtml(token) {
322 var editor = {/literal}"{$editor}"{literal};
323 if ( editor == "tinymce" ) {
324 tinyMCE.execInstanceCommand('html_message',"mceInsertContent",false, token );
326 else if ( editor == "joomlaeditor" ) {
327 tinyMCE.execCommand('mceInsertContent',false, token);
328 var msg = document.getElementById(html_message).value;
329 var cursorlen = document.getElementById(html_message).selectionStart;
330 var textlen = msg.length;
331 document.getElementById(html_message).value = msg.substring(0, cursorlen) + token + msg.substring(cursorlen, textlen);
332 var cursorPos = (cursorlen + token.length);
333 document.getElementById(html_message).selectionStart = cursorPos;
334 document.getElementById(html_message).selectionEnd = cursorPos;
335 document.getElementById(html_message).focus();
337 else if ( editor == "ckeditor" ) {
338 oEditor = CKEDITOR.instances[html_message];
339 oEditor.insertHtml(token.toString() );
341 else if ( editor == "drupalwysiwyg" ) {
342 if (Drupal.wysiwyg.instances[html_message].insert) {
343 Drupal.wysiwyg.instances[html_message].insert(token.toString() );
346 alert("Sorry, your editor doesn't support this function yet.");
350 cj( "#"+ html_message ).replaceSelection( token );
354 // Initialize token selector widgets
355 var form = $('#{/literal}{$form.formName}{literal}');
356 $('input.crm-token-selector', form)
357 .addClass('crm-action-menu')
360 data: form.data('tokens'),
361 placeholder: '{/literal}{ts escape='js'}Insert Token{/ts}{literal}'
364 cj('.accordion .head').addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ");
365 cj('.resizable-textarea textarea').css( 'width', '99%' );
366 cj('.grippie').css( 'margin-right', '3px');
367 cj('.accordion .head').hover( function() { cj(this).addClass( "ui-state-hover");
368 }, function() { cj(this).removeClass( "ui-state-hover");
369 }).bind('click', function() {
370 var checkClass = cj(this).find('span').attr( 'class' );
371 var len = checkClass.length;
372 if ( checkClass.substring( len - 1, len ) == 's' ) {
373 cj(this).find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-e');
374 cj("span#help"+cj(this).find('span').attr('id')).hide();
377 cj(this).find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-s');
378 cj("span#help"+cj(this).find('span').attr('id')).show();
380 cj(this).next().toggle(); return false;
382 cj('span#html').removeClass().addClass('ui-icon ui-icon-triangle-1-s');
383 cj("div.html").show();
386 cj("div.text").show();
389 function setSignature() {
390 var emailID = $("#fromEmailAddress").val( );
391 if ( !isNaN( emailID ) ) {
392 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/signature' h=0 }"{literal};
393 $.post( dataUrl, {emailID: emailID}, function( data ) {
394 var editor = {/literal}"{$editor}"{literal};
396 if (data.signature_text) {
397 // get existing text & html and append signatue
398 var textMessage = $("#"+ text_message).val( ) + '\n\n--\n' + data.signature_text;
401 $("#"+ text_message).val( textMessage );
404 if ( data.signature_html ) {
405 var htmlMessage = $("#"+ html_message).val( ) + '<br/><br/>--<br/>' + data.signature_html;
408 if ( editor == "ckeditor" ) {
409 oEditor = CKEDITOR.instances[html_message];
410 var htmlMessage = oEditor.getData( ) + '<br/><br/>--' + data.signature_html;
411 oEditor.setData( htmlMessage );
413 else if ( editor == "tinymce" ) {
414 tinyMCE.execInstanceCommand('html_message',"mceInsertContent",false, htmlMessage);
416 else if ( editor == "drupalwysiwyg" ) {
417 if (Drupal.wysiwyg.instances[html_message].setContent) {
418 Drupal.wysiwyg.instances[html_message].setContent(htmlMessage);
420 // @TODO: Remove this when http://drupal.org/node/614146 drops
421 else if (Drupal.wysiwyg.instances[html_message].insert) {
422 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.");
423 Drupal.wysiwyg.instances[html_message].insert(htmlMessage);
426 alert("Sorry, your editor doesn't support this function yet.");
430 $("#"+ html_message).val(htmlMessage);
436 if (!cj().find('div.crm-error').text()) {
437 cj(window).load(function () {
441 cj("#fromEmailAddress").change( function( ) {