2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.6 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
26 <script type="text/javascript">
27 cj('form.{$form.formClass}').data('tokens', {$tokens|@json_encode});
28 var text_message = null;
29 var html_message = null;
32 var isMailing = false;
34 {if $form.formName eq 'MessageTemplates'}
36 text_message = "msg_text";
37 html_message = "msg_html";
39 {elseif $form.formName eq 'Address'}
41 text_message = "mailing_format";
44 {elseif $form.formClass eq 'CRM_SMS_Form_Upload' || $form.formClass eq 'CRM_Contact_Form_Task_SMS'}
47 text_message = "sms_text_message";
52 text_message = "text_message";
53 html_message = (cj("#edit-html-message-value").length > 0) ? "edit-html-message-value" : "html_message";
58 {if $form.formName eq 'PDF'}
64 {if $templateSelected}
66 if ( document.getElementsByName(prefix + "saveTemplate")[0].checked ) {
67 document.getElementById(prefix + "template").selectedIndex = {/literal}{$templateSelected}{literal};
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";
81 document.getElementById(prefix + "saveDetails").style.display = "none";
82 document.getElementById(prefix + "updateDetails").style.display = "none";
87 if (document.getElementsByName(prefix + "saveTemplate")[0].checked &&
88 document.getElementsByName(prefix + "updateTemplate")[0].checked == false) {
89 document.getElementById(prefix + "updateDetails").style.display = "none";
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";
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";
102 document.getElementById(prefix + "saveDetails").style.display = "none";
103 document.getElementById(prefix + "updateDetails").style.display = "none";
107 function selectValue( val, prefix) {
108 document.getElementsByName(prefix + "saveTemplate")[0].checked = false;
109 document.getElementsByName(prefix + "updateTemplate")[0].checked = false;
110 showSaveUpdateChkBox(prefix);
112 if (document.getElementById("subject").length) {
113 document.getElementById("subject").value ="";
116 if (prefix == 'SMS') {
117 document.getElementById("sms_text_message").value ="";
121 document.getElementById("text_message").value ="";
124 CRM.wysiwyg.setVal('#' + html_message, '');
126 showBindFormatChkBox();
131 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/template' h=0 }"{literal};
133 cj.post( dataUrl, {tid: val}, function( data ) {
135 if (prefix == "SMS") {
136 text_message = "sms_text_message";
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();
145 cj("#"+text_message).val("");
149 if (prefix == "SMS") {
153 cj("#subject").val( data.subject );
156 CRM.wysiwyg.setVal('#' + html_message, data.msg_html || '');
159 var bind = data.pdf_format_id ? true : false ;
160 selectFormat( data.pdf_format_id, bind );
162 document.getElementById("bindFormat").style.display = "none";
169 document.getElementById(prefix + "editMessageDetails").style.display = "block";
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";
176 document.getElementById(prefix + "editMessageDetails").style.display = "block";
178 var templateExists = true;
179 if (document.getElementById(prefix + "template") == null) {
180 templateExists = false;
183 if (templateExists && document.getElementById(prefix + "template").value) {
184 document.getElementById(prefix + "updateDetails").style.display = '';
187 document.getElementById(prefix + "updateDetails").style.display = 'none';
190 document.getElementById(prefix + "saveTemplateName").disabled = false;
193 function showSaveDetails(chkbox, prefix) {
194 prefix = prefix || '';
195 if (chkbox.checked) {
196 document.getElementById(prefix + "saveDetails").style.display = "block";
197 document.getElementById(prefix + "saveTemplateName").disabled = false;
200 document.getElementById(prefix + "saveDetails").style.display = "none";
201 document.getElementById(prefix + "saveTemplateName").disabled = true;
205 if (cj("#sms_text_message").length) {
206 showSaveUpdateChkBox('SMS');
208 if (cj("#text_message").length) {
209 showSaveUpdateChkBox();
212 cj('#' + html_message).on('focus change', verify);
216 function insertToken() {
218 token = $(this).val(),
219 field = $(this).data('field');
220 if (field !== 'html_message') {
221 field = textMsgID($(this));
223 CRM.wysiwyg.insert('#' + field, token);
224 $(this).select2('val', '');
230 function textMsgID(obj) {
231 if (obj.parents().is("#sms")) {
232 field = 'sms #' + obj.data('field');
234 else if(obj.parents().is("#email")) {
235 field = 'email #' + obj.data('field');
238 field = obj.data('field');
244 // Initialize token selector widgets
245 var form = $('form.{/literal}{$form.formClass}{literal}');
246 $('input.crm-token-selector', form)
247 .addClass('crm-action-menu action-icon-token')
250 data: form.data('tokens'),
251 placeholder: '{/literal}{ts escape='js'}Tokens{/ts}{literal}'
254 $('.accordion .head').addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ")
255 .hover( function() { $(this).addClass( "ui-state-hover");
256 }, function() { $(this).removeClass( "ui-state-hover");
257 }).bind('click', function() {
258 var checkClass = $(this).find('span').attr( 'class' );
259 var len = checkClass.length;
260 if ( checkClass.substring( len - 1, len ) == 's' ) {
261 $(this).find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-e');
262 $("span#help"+$(this).find('span').attr('id')).hide();
265 $(this).find('span').removeClass().addClass('ui-icon ui-icon-triangle-1-s');
266 $("span#help"+$(this).find('span').attr('id')).show();
268 $(this).next().toggle(); return false;
270 $('span#html').removeClass().addClass('ui-icon ui-icon-triangle-1-s');
271 $("div.html").show();
274 $("div.text").show();
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 ) {
283 if (data.signature_text) {
284 var textMessage = $("#"+ text_message).val( ) + '\n\n--\n' + data.signature_text;
285 $("#"+ text_message).val( textMessage );
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);
295 $("#fromEmailAddress", form).change(setSignature);