//get the tokens.
$tokens = CRM_Core_SelectValues::contactTokens();
- //sorted in ascending order tokens by ignoring word case
- natcasesort($tokens);
- $this->assign('tokens', json_encode($tokens));
-
- $this->add('select', 'token1', ts('Insert Tokens'),
- $tokens, FALSE,
- array(
- 'size' => "5",
- 'multiple' => TRUE,
- 'onchange' => "return tokenReplText(this);",
- )
- );
-
- $this->add('select', 'token2', ts('Insert Tokens'),
- $tokens, FALSE,
- array(
- 'size' => "5",
- 'multiple' => TRUE,
- 'onchange' => "return tokenReplHtml(this);",
- )
- );
-
- $this->add('select', 'token3', ts('Insert Tokens'),
- $tokens, FALSE,
- array(
- 'size' => "5",
- 'multiple' => TRUE,
- 'onchange' => "return tokenReplText(this);",
- )
- );
+ $this->assign('tokens', CRM_Utils_Token::formatTokensForDisplay($tokens));
$this->add('textarea', 'msg_text', ts('Text Message'),
"cols=50 rows=6"
//get the tokens for Mailing Label field
$tokens = CRM_Core_SelectValues::contactTokens();
- natcasesort($tokens);
- $this->assign('tokens', json_encode($tokens));
-
- $this->add('select', 'token1', ts('Insert Token'),
- $tokens, FALSE,
- array(
- 'size' => "5",
- 'multiple' => TRUE,
- 'onclick' => "return tokenReplText(this);",
- )
- );
+ $this->assign('tokens', CRM_Utils_Token::formatTokensForDisplay($tokens));
parent::buildQuickForm();
}
if ($props['entity'] == 'contact' && isset($props['create']) && !(CRM_Core_Permission::check('edit all contacts') || CRM_Core_Permission::check('add contacts'))) {
unset($props['create']);
}
+ // Convenient shortcut to passing in array create links
if ($props['entity'] == 'contact' && isset($props['create']) && $props['create'] === TRUE) {
if (empty($props['api']['params']['contact_type'])) {
$props['create'] = CRM_Core_BAO_UFGroup::getCreateLinks(array('new_individual', 'new_organization', 'new_household'));
//get the tokens.
$tokens = CRM_Core_SelectValues::contactTokens();
- //token selector for subject
- //CRM-5058
- $form->add('select', 'token3', ts('Insert Token'),
- $tokens, FALSE,
- array(
- 'size' => "5",
- 'multiple' => TRUE,
- 'onclick' => "return tokenReplText(this);",
- )
- );
$className = CRM_Utils_System::getClassName($form);
if ($className == 'CRM_Mailing_Form_Upload') {
$tokens = array_merge(CRM_Core_SelectValues::mailingTokens(), $tokens);
}
//sorted in ascending order tokens by ignoring word case
- natcasesort($tokens);
- $form->assign('tokens', json_encode($tokens));
-
- $form->add('select', 'token1', ts('Insert Tokens'),
- $tokens, FALSE,
- array(
- 'size' => "5",
- 'multiple' => TRUE,
- 'onclick' => "return tokenReplText(this);",
- )
- );
-
- $form->add('select', 'token2', ts('Insert Tokens'),
- $tokens, FALSE,
- array(
- 'size' => "5",
- 'multiple' => TRUE,
- 'onclick' => "return tokenReplHtml(this);",
- )
- );
-
+ $form->assign('tokens', CRM_Utils_Token::formatTokensForDisplay($tokens));
$form->_templates = CRM_Core_BAO_MessageTemplate::getMessageTemplates(FALSE);
if (!empty($form->_templates)) {
$tokens = array_merge($form->listTokens(), $tokens);
}
- //sorted in ascending order tokens by ignoring word case
- natcasesort($tokens);
-
- $form->assign('tokens', json_encode($tokens));
-
- $form->add('select', 'token1', ts('Insert Tokens'),
- $tokens, FALSE,
- array(
- 'size' => "5",
- 'multiple' => TRUE,
- 'onchange' => "return tokenReplHtml(this);",
- )
- );
+ $form->assign('tokens', CRM_Utils_Token::formatTokensForDisplay($tokens));
$form->_templates = CRM_Core_BAO_MessageTemplate::getMessageTemplates(FALSE);
if (!empty($form->_templates)) {
);
}
+ /**
+ * Formats a token list for the select2 widget
+ * @param $tokens
+ * @return array
+ */
+ static function formatTokensForDisplay($tokens) {
+ $sorted = $output = array();
+
+ // Sort in ascending order by ignoring word case
+ natcasesort($tokens);
+
+ // Attempt to place tokens into optgroups
+ // TODO: These groupings could be better and less hackish. Getting them pre-grouped from upstream would be nice.
+ foreach ($tokens as $k => $v) {
+ // Check to see if this token is already in a group e.g. for custom fields
+ $split = explode(' :: ', $v);
+ if (!empty($split[1])) {
+ $sorted[$split[1]][] = array('id' => $k, 'text' => $split[0]);
+ }
+ // Group by entity
+ else {
+ $split = explode('.', trim($k, '{}'));
+ $entity = isset($split[1]) ? ucfirst($split[0]) : 'Contact';
+ $sorted[ts($entity)][] = array('id' => $k, 'text' => $v);
+ }
+ }
+
+ ksort($sorted);
+ foreach ($sorted as $k => $v) {
+ $output[] = array('text' => $k, 'children' => $v);
+ }
+
+ return $output;
+ }
+
}
margin: 0;
padding: 0;
}
+.crm-container .crm-action-menu .select2-default span.select2-chosen {
+ color: #2786C2;
+}
+.crm-container .crm-action-menu .select2-default span.select2-chosen:before {
+ background: url("../i/icons/jquery-ui-2786C2.png") no-repeat scroll -64px -112px;
+ content: "";
+ display: inline-block;
+ height: 16px;
+ width: 16px;
+ margin-right: 3px;
+ position: relative;
+ top: 3px;
+}
/* Special styling for specific form buttons */
#crm-container span.crm-button_qf_Main_upload input,
<tr>
<td class="label-left">{$form.msg_subject.label}</td>
<td>
- {$form.msg_subject.html|crmAddClass:huge}
- <a href="#" onClick="return showToken('Subject', 3);">{$form.token3.label}</a>
- {help id="id-token-text" file="CRM/Contact/Form/Task/Email.hlp"}
- <div id='tokenSubject' style="display:none">
- <input style="border:1px solid #999999;" type="text" id="filter3" size="20" name="filter3" onkeyup="filter(this, 3)"/><br />
- <span class="description">{ts}Begin typing to filter list of tokens{/ts}</span><br/>
- {$form.token3.html}
- </div>
+ {$form.msg_subject.html|crmAddClass:huge}
+ <input class="crm-token-selector big" data-field="msg_subject" />
+ {help id="id-token-subject" tplFile=$tplFile isAdmin=$isAdmin file="CRM/Contact/Form/Task/Email.hlp"}
<br /><span class="description">{ts}Subject for email message.{/ts} {ts 1=$tokenDocsRepeated}Tokens may be included (%1).{/ts}</span>
</td>
</tr>
{ts}Plain-Text Format{/ts}
</div><!-- /.crm-accordion-header -->
<div class="crm-accordion-body">
- <span class="helpIcon" id="helptext">
- <a href="#" onClick="return showToken('Text', 1);">{$form.token1.label}</a>
- {help id="id-token-text" file="CRM/Contact/Form/Task/Email.hlp"}
- <div id='tokenText' style="display:none">
- <input style="border:1px solid #999999;" type="text" id="filter1" size="20" name="filter1" onkeyup="filter(this, 1)"/><br />
- <span class="description">{ts}Begin typing to filter list of tokens{/ts}</span><br/>
- {$form.token1.html}
- </div>
- </span>
- <div class="clear"></div>
+ <div class="helpIcon" id="helptext">
+ <input class="crm-token-selector big" data-field="msg_text" />
+ {help id="id-token-text" tplFile=$tplFile file="CRM/Contact/Form/Task/Email.hlp"}
+ </div>
<div class='text'>
{$form.msg_text.html|crmAddClass:huge}
<div class="description">{ts}Text formatted message.{/ts} {ts 1=$tokenDocsRepeated}Tokens may be included (%1).{/ts}</div>
{help id="id-message-text" file="CRM/Contact/Form/Task/Email.hlp"}
</div><!-- /.crm-accordion-header -->
<div class="crm-accordion-body">
- <span class="helpIcon" id="helphtml">
- <a href="#" onClick="return showToken('Html', 2);">{$form.token2.label}</a>
- {help id="id-token-html" file="CRM/Contact/Form/Task/Email.hlp"}
- <div id='tokenHtml' style="display:none">
- <input style="border:1px solid #999999;" type="text" id="filter2" size="20" name="filter2" onkeyup="filter(this, 2)"/><br />
- <span class="description">{ts}Begin typing to filter list of tokens{/ts}</span><br/>
- {$form.token2.html}
- </div>
- </span>
+ <div class="helpIcon" id="helphtml">
+ <input class="crm-token-selector big" data-field="html_message" />
+ {help id="id-token-html" tplFile=$tplFile isAdmin=$isAdmin editor=$editor file="CRM/Contact/Form/Task/Email.hlp"}
+ </div>
<div class="clear"></div>
<div class='html'>
{$form.msg_html.html}
<tr class="crm-preferences-address-form-block-mailing_format">
<td class="label">{$form.mailing_format.label}<br />{help id='label-tokens'}</td>
<td>
- <span>
- <a href="#" onClick="return showToken('Text', 1);">{ts}Insert Tokens{/ts}</a>
- <div id='tokenText' style="display:none">
- <input style="border:1px solid #999999;" type="text" id="filter1" size="20" name="filter1" onkeyup="filter(this, 1)"/><br />
- <span class="description">{ts}Begin typing to filter list of tokens{/ts}</span><br/>
- {$form.token1.html}
- </div>
- </span><br />
+ <div class="helpIcon" id="helphtml">
+ <input class="crm-token-selector big" data-field="mailing_format" />
+ {help id="id-token-text" tplFile=$tplFile file="CRM/Contact/Form/Task/Email.hlp"}
+ </div>
{$form.mailing_format.html|crmAddClass:huge12}<br />
<span class="description">{ts}Content and format for mailing labels.{/ts}</span>
</td>
{if $rows and $action ne 2 and $action ne 4}
+ {* include wysiwyg related files*}
+ {include file="CRM/common/wysiwyg.tpl" includeWysiwygEditor=true}
+
<div id='mainTabContainer'>
<ul>
<li id='tab_user'> <a href='#user' title='{ts}User-driven Messages{/ts}'> {ts}User-driven Messages{/ts} </a></li>
{/if}
<tr class="crm-contactEmail-form-block-subject">
<td class="label">{$form.subject.label}</td>
- <td>{$form.subject.html|crmAddClass:huge}
- <a href="#" onClick="return showToken('Subject', 3);">{$form.token3.label}</a>
- {help id="id-token-subject" file="CRM/Contact/Form/Task/Email.hlp"}
- <div id='tokenSubject' style="display:none">
- <input style="border:1px solid #999999;" type="text" id="filter3" size="20" name="filter3" onkeyup="filter(this, 3)"/><br />
- <span class="description">{ts}Begin typing to filter list of tokens{/ts}</span><br/>
- {$form.token3.html}
- </div>
+ <td>
+ {$form.subject.html|crmAddClass:huge}
+ <input class="crm-token-selector big" data-field="subject" />
+ {help id="id-token-subject" tplFile=$tplFile isAdmin=$isAdmin file="CRM/Contact/Form/Task/Email.hlp"}
</td>
</tr>
</table>
{help id="id-message-text" file="CRM/Contact/Form/Task/Email.hlp"}
</div><!-- /.crm-accordion-header -->
<div class="crm-accordion-body">
- <span class="helpIcon" id="helphtml">
- <a href="#" onClick="return showToken('Html', 2);">{$form.token2.label}</a>
- {help id="id-token-html" tplFile=$tplFile isAdmin=$isAdmin editor=$editor file="CRM/Contact/Form/Task/Email.hlp"}
- <div id="tokenHtml" style="display:none;">
- <input style="border:1px solid #999999;" type="text" id="filter2" size="20" name="filter2" onkeyup="filter(this, 2)"/><br />
- <span class="description">{ts}Begin typing to filter list of tokens{/ts}</span><br/>
- {$form.token2.html}
+ <div class="helpIcon" id="helphtml">
+ <input class="crm-token-selector big" data-field="html_message" />
+ {help id="id-token-html" tplFile=$tplFile isAdmin=$isAdmin editor=$editor file="CRM/Contact/Form/Task/Email.hlp"}
</div>
- </span>
- <div class="clear"></div>
+ <div class="clear"></div>
<div class='html'>
{if $editor EQ 'textarea'}
<div class="help description">{ts}NOTE: If you are composing HTML-formatted messages, you may want to enable a Rich Text (WYSIWYG) editor (Administer » Customize Data & Screens » Display Preferences).{/ts}</div>
{ts}Plain-Text Format{/ts}
</div><!-- /.crm-accordion-header -->
<div class="crm-accordion-body">
-
- <span class="helpIcon" id="helptext">
- <a href="#" onClick="return showToken('Text', 1);">{$form.token1.label}</a>
- {help id="id-token-text" tplFile=$tplFile file="CRM/Contact/Form/Task/Email.hlp"}
- <div id='tokenText' style="display:none">
- <input style="border:1px solid #999999;" type="text" id="filter1" size="20" name="filter1" onkeyup="filter(this, 1)"/><br />
- <span class="description">{ts}Begin typing to filter list of tokens{/ts}</span><br/>
- {$form.token1.html}
- </div>
- </span>
- <div class="clear"></div>
-
+ <div class="helpIcon" id="helptext">
+ <input class="crm-token-selector big" data-field="text_message" />
+ {help id="id-token-text" tplFile=$tplFile file="CRM/Contact/Form/Task/Email.hlp"}
+ </div>
<div class='text'>
{$form.text_message.html}<br />
</div>
{$form.html_message.label}
</div><!-- /.crm-accordion-header -->
<div class="crm-accordion-body">
- {if $action neq 4}
- <span class="helpIcon" id="helphtml">
- <a href="#" onClick="return showToken('Html', 1);">{$form.token1.label}</a>
- {help id="id-token-html" file="CRM/Contact/Form/Task/Email.hlp" tplFile=$tplFile isAdmin=$isAdmin editor=$editor}
- <div id="tokenHtml" style="display:none;">
- <input style="border:1px solid #999999;" type="text" id="filter1" size="20" name="filter1" onkeyup="filter(this, 1)"/><br />
- <span class="description">{ts}Begin typing to filter list of tokens{/ts}</span><br/>
- {$form.token1.html}
- </div>
- </span>
- {/if}
+ <div class="helpIcon" id="helphtml">
+ <input class="crm-token-selector big" data-field="html_message" />
+ {help id="id-token-html" tplFile=$tplFile isAdmin=$isAdmin editor=$editor file="CRM/Contact/Form/Task/Email.hlp"}
+ </div>
<div class="clear"></div>
<div class='html'>
{if $editor EQ 'textarea'}
showBindFormatChkBox();
selectPaper( document.getElementById('paper_size').value );
-function tokenReplHtml ( )
-{
- var token1 = cj("#token1").val( )[0];
- var editor = {/literal}"{$editor}"{literal};
- if ( editor == "tinymce" ) {
- var content= tinyMCE.get('html_message').getContent() +token1;
- tinyMCE.get('html_message').setContent(content);
- } else if ( editor == "joomlaeditor" ) {
- tinyMCE.execCommand('mceInsertContent',false, token1);
- var msg = document.getElementById(html_message).value;
- var cursorlen = document.getElementById(html_message).selectionStart;
- var textlen = msg.length;
- document.getElementById(html_message).value = msg.substring(0, cursorlen) + token1 + msg.substring(cursorlen, textlen);
- var cursorPos = (cursorlen + token1.length);
- document.getElementById(html_message).selectionStart = cursorPos;
- document.getElementById(html_message).selectionEnd = cursorPos;
- document.getElementById(html_message).focus();
- } else if ( editor == "ckeditor" ) {
- oEditor = CKEDITOR.instances[html_message];
- oEditor.insertHtml(token1.toString() );
- } else if ( editor == "drupalwysiwyg" ) {
- Drupal.wysiwyg.instances[html_message].insert(token1.toString());
- } else {
- var msg = document.getElementById(html_message).value;
- var cursorlen = document.getElementById(html_message).selectionStart;
- var textlen = msg.length;
- document.getElementById(html_message).value = msg.substring(0, cursorlen) + token1 + msg.substring(cursorlen, textlen);
- var cursorPos = (cursorlen + token1.length);
- document.getElementById(html_message).selectionStart = cursorPos;
- document.getElementById(html_message).selectionEnd = cursorPos;
- document.getElementById(html_message).focus();
- }
- verify();
-}
-
function showBindFormatChkBox()
{
var templateExists = true;
</div><!-- /.crm-accordion-header -->
<div class="crm-accordion-body">
<div id='char-count-message'></div>
- <span class="helpIcon" id="helptext">
- <a href="#" onClick="return showToken('Text', 1);">{$form.token1.label}</a>
- {help id="id-token-text" file="CRM/Contact/Form/Task/SMS.hlp"}
- <div id='tokenText' style="display:none">
- <input style="border:1px solid #999999;" type="text" id="filter1" size="20" name="filter1" onkeyup="filter(this, 1)"/><br />
- <span class="description">{ts}Begin typing to filter list of tokens{/ts}</span><br/>
- {$form.token1.html}
- </div>
- </span>
- <div class="clear"></div>
+ <div class="helpIcon" id="helptext">
+ <input class="crm-token-selector big" data-field="text_message" />
+ {help id="id-token-text" tplFile=$tplFile file="CRM/Contact/Form/Task/SMS.hlp"}
+ </div>
<div class='text'>
{$form.text_message.html}<br />
</div>
<script type="text/javascript" src="{$config->resourceBase}packages/jquery/plugins/jquery-fieldselection.js"></script>
<script type="text/javascript">
+cj('form#{$form.formName}').data('tokens', {$tokens|@json_encode});
var text_message = null;
var html_message = null;
var isPDF = false;
{literal}
}
-function tokenReplText(element) {
- var token = cj("#"+element.id).val( )[0];
- if ( element.id == 'token3' ) {
- ( isMailing ) ? text_message = "subject" : text_message = "msg_subject";
- }
- else if ( element.id == 'token1' ) {
- ( isMailing ) ? text_message = "text_message" : text_message = "msg_text";
- }
-
- cj( "#"+ text_message ).replaceSelection( token );
-
- if ( isMailing ) {
- verify();
+cj(function($) {
+ function insertToken() {
+ var
+ token = $(this).val(),
+ field = $(this).data('field');
+ if (field === 'html_message') {
+ tokenReplHtml(token);
+ } else {
+ $('#' + field).replaceSelection(token);
+ }
+ $(this).select2('val', '');
+ if (isMailing) {
+ verify();
+ }
}
-}
-function tokenReplHtml() {
- var token2 = cj("#token2").val( )[0];
- var editor = {/literal}"{$editor}"{literal};
- if ( editor == "tinymce" ) {
- tinyMCE.execInstanceCommand('html_message',"mceInsertContent",false, token2 );
- }
- else if ( editor == "joomlaeditor" ) {
- tinyMCE.execCommand('mceInsertContent',false, token2);
- var msg = document.getElementById(html_message).value;
- var cursorlen = document.getElementById(html_message).selectionStart;
- var textlen = msg.length;
- document.getElementById(html_message).value = msg.substring(0, cursorlen) + token2 + msg.substring(cursorlen, textlen);
- var cursorPos = (cursorlen + token2.length);
- document.getElementById(html_message).selectionStart = cursorPos;
- document.getElementById(html_message).selectionEnd = cursorPos;
- document.getElementById(html_message).focus();
- }
- else if ( editor == "ckeditor" ) {
- oEditor = CKEDITOR.instances[html_message];
- oEditor.insertHtml(token2.toString() );
- }
- else if ( editor == "drupalwysiwyg" ) {
- if (Drupal.wysiwyg.instances[html_message].insert) {
- Drupal.wysiwyg.instances[html_message].insert(token2.toString() );
+ function tokenReplHtml(token) {
+ var editor = {/literal}"{$editor}"{literal};
+ if ( editor == "tinymce" ) {
+ tinyMCE.execInstanceCommand('html_message',"mceInsertContent",false, token );
+ }
+ else if ( editor == "joomlaeditor" ) {
+ tinyMCE.execCommand('mceInsertContent',false, token);
+ var msg = document.getElementById(html_message).value;
+ var cursorlen = document.getElementById(html_message).selectionStart;
+ var textlen = msg.length;
+ document.getElementById(html_message).value = msg.substring(0, cursorlen) + token + msg.substring(cursorlen, textlen);
+ var cursorPos = (cursorlen + token.length);
+ document.getElementById(html_message).selectionStart = cursorPos;
+ document.getElementById(html_message).selectionEnd = cursorPos;
+ document.getElementById(html_message).focus();
+ }
+ else if ( editor == "ckeditor" ) {
+ oEditor = CKEDITOR.instances[html_message];
+ oEditor.insertHtml(token.toString() );
+ }
+ else if ( editor == "drupalwysiwyg" ) {
+ if (Drupal.wysiwyg.instances[html_message].insert) {
+ Drupal.wysiwyg.instances[html_message].insert(token.toString() );
+ }
+ else {
+ alert("Sorry, your editor doesn't support this function yet.");
+ }
}
else {
- alert("Sorry, your editor doesn't support this function yet.");
+ cj( "#"+ html_message ).replaceSelection( token );
}
}
- else {
- cj( "#"+ html_message ).replaceSelection( token2 );
- }
- if ( isMailing ) {
- verify();
- }
-}
+ // Initialize token selector widgets
+ var form = $('#{/literal}{$form.formName}{literal}');
+ $('input.crm-token-selector', form)
+ .addClass('crm-action-menu')
+ .change(insertToken)
+ .select2({
+ data: form.data('tokens'),
+ placeholder: '{/literal}{ts escape='js'}Insert Token{/ts}{literal}'
+ });
-cj(function() {
cj('.accordion .head').addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ");
cj('.resizable-textarea textarea').css( 'width', '99%' );
cj('.grippie').css( 'margin-right', '3px');
if ( !isMailing ) {
cj("div.text").show();
}
-});
-{/literal}{include file="CRM/common/Filter.tpl"}{literal}
-function showToken(element, id ) {
- initFilter(id);
- cj("#token"+id).css({"width":"290px", "size":"8"});
- var tokenTitle = {/literal}'{ts escape="js"}Select Token{/ts}'{literal};
- cj("#token"+element ).show( ).dialog({
- title : tokenTitle,
- modal : true,
- width : '310px',
- resizable : false,
- bgiframe : false,
- overlay : { opacity: 0.5, background: "black" },
- beforeclose : function(event, ui) { cj(this).dialog("destroy"); },
- buttons : {
- "Done": function() {
- cj(this).dialog("close");
- //focus on editor/textarea after token selection
- if (element == 'Text') {
- cj('#' + text_message).focus();
+ function setSignature() {
+ var emailID = $("#fromEmailAddress").val( );
+ if ( !isNaN( emailID ) ) {
+ var dataUrl = {/literal}"{crmURL p='civicrm/ajax/signature' h=0 }"{literal};
+ $.post( dataUrl, {emailID: emailID}, function( data ) {
+ var editor = {/literal}"{$editor}"{literal};
+
+ if (data.signature_text) {
+ // get existing text & html and append signatue
+ var textMessage = $("#"+ text_message).val( ) + '\n\n--\n' + data.signature_text;
+
+ // append signature
+ $("#"+ text_message).val( textMessage );
}
- else if (element == 'Html' ) {
- switch ({/literal}"{$editor}"{literal}) {
- case 'ckeditor': { oEditor = CKEDITOR.instances[html_message]; oEditor.focus(); break;}
- case 'tinymce' : { tinyMCE.get(html_message).focus(); break; }
- case 'joomlaeditor' : { tinyMCE.get(html_message).focus(); break; }
- default : { cj("#"+ html_message).focus(); break; }
+
+ if ( data.signature_html ) {
+ var htmlMessage = $("#"+ html_message).val( ) + '<br/><br/>--<br/>' + data.signature_html;
+
+ // set wysiwg editor
+ if ( editor == "ckeditor" ) {
+ oEditor = CKEDITOR.instances[html_message];
+ var htmlMessage = oEditor.getData( ) + '<br/><br/>--' + data.signature_html;
+ oEditor.setData( htmlMessage );
+ }
+ else if ( editor == "tinymce" ) {
+ tinyMCE.execInstanceCommand('html_message',"mceInsertContent",false, htmlMessage);
+ }
+ else if ( editor == "drupalwysiwyg" ) {
+ if (Drupal.wysiwyg.instances[html_message].setContent) {
+ Drupal.wysiwyg.instances[html_message].setContent(htmlMessage);
+ }
+ // @TODO: Remove this when http://drupal.org/node/614146 drops
+ else if (Drupal.wysiwyg.instances[html_message].insert) {
+ 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.");
+ Drupal.wysiwyg.instances[html_message].insert(htmlMessage);
+ }
+ else {
+ alert("Sorry, your editor doesn't support this function yet.");
+ }
+ }
+ else {
+ $("#"+ html_message).val(htmlMessage);
}
}
- else if (element == 'Subject') {
- var subject = null;
- ( isMailing ) ? subject = "subject" : subject = "msg_subject";
- cj('#'+subject).focus();
- }
- }
+ }, 'json');
}
- });
- return false;
-}
-
-cj(function() {
+ }
if (!cj().find('div.crm-error').text()) {
cj(window).load(function () {
setSignature();
});
}
-
cj("#fromEmailAddress").change( function( ) {
setSignature( );
});
});
-function setSignature( ) {
- var emailID = cj("#fromEmailAddress").val( );
- if ( !isNaN( emailID ) ) {
- var dataUrl = {/literal}"{crmURL p='civicrm/ajax/signature' h=0 }"{literal};
- cj.post( dataUrl, {emailID: emailID}, function( data ) {
- var editor = {/literal}"{$editor}"{literal};
-
- if (data.signature_text) {
- // get existing text & html and append signatue
- var textMessage = cj("#"+ text_message).val( ) + '\n\n--\n' + data.signature_text;
-
- // append signature
- cj("#"+ text_message).val( textMessage );
- }
-
- if ( data.signature_html ) {
- var htmlMessage = cj("#"+ html_message).val( ) + '<br/><br/>--<br/>' + data.signature_html;
-
- // set wysiwg editor
- if ( editor == "ckeditor" ) {
- oEditor = CKEDITOR.instances[html_message];
- var htmlMessage = oEditor.getData( ) + '<br/><br/>--' + data.signature_html;
- oEditor.setData( htmlMessage );
- }
- else if ( editor == "tinymce" ) {
- tinyMCE.execInstanceCommand('html_message',"mceInsertContent",false, htmlMessage);
- }
- else if ( editor == "drupalwysiwyg" ) {
- if (Drupal.wysiwyg.instances[html_message].setContent) {
- Drupal.wysiwyg.instances[html_message].setContent(htmlMessage);
- }
- // @TODO: Remove this when http://drupal.org/node/614146 drops
- else if (Drupal.wysiwyg.instances[html_message].insert) {
- 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.");
- Drupal.wysiwyg.instances[html_message].insert(htmlMessage);
- }
- else {
- alert("Sorry, your editor doesn't support this function yet.");
- }
- }
- else {
- cj("#"+ html_message).val(htmlMessage);
- }
- }
- }, 'json');
- }
-}
</script>
{/literal}
<td>{$form.template.html}</td>
</tr>
<tr class="crm-mailing-upload-form-block-subject"><td class="label">{$form.subject.label}</td>
- <td colspan="2">{$form.subject.html|crmAddClass:huge}
- <a href="#" onClick="return showToken('Subject', 3);">{$form.token3.label}</a>
- {help id="id-token-subject" file="CRM/Contact/Form/Task/Email.hlp"}
- <div id='tokenSubject' style="display:none">
- <input style="border:1px solid #999999;" type="text" id="filter3" size="20" name="filter3" onkeyup="filter(this, 3)"/><br />
- <span class="description">{ts}Begin typing to filter list of tokens{/ts}</span><br/>
- {$form.token3.html}
- </div>
+ <td colspan="2">
+ {$form.subject.html|crmAddClass:huge}
+ <input class="crm-token-selector big" data-field="subject" />
+ {help id="id-token-subject" tplFile=$tplFile isAdmin=$isAdmin file="CRM/Contact/Form/Task/Email.hlp"}
</td>
</tr>
<tr class="crm-mailing-upload-form-block-upload_type"><td></td><td colspan="2">{$form.upload_type.label} {$form.upload_type.html} {help id="upload-compose"}</td></tr>
+++ /dev/null
-{*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.4 |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM. |
- | |
- | CiviCRM is free software; you can copy, modify, and distribute it |
- | under the terms of the GNU Affero General Public License |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
- | |
- | CiviCRM is distributed in the hope that it will be useful, but |
- | WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
- | See the GNU Affero General Public License for more details. |
- | |
- | You should have received a copy of the GNU Affero General Public |
- | License and the CiviCRM Licensing Exception along |
- | with this program; if not, contact CiviCRM LLC |
- | at info[AT]civicrm[DOT]org. If you have questions about the |
- | GNU Affero General Public License or the licensing of CiviCRM, |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing |
- +--------------------------------------------------------------------+
-*}
-{literal}
-var stregexp = new RegExp;
-
-function initFilter( id ) {
- //build the array
- filterArray = new Array();
- filterArray = {/literal}{$tokens}{literal};
-
- tempArray = new Array();
- remvdArray = new Array();
-
- //get select object
- selObj = document.getElementById("token"+ id);
-
- //rebuild the list
- buildOptions(filterArray);
-
- //clear the input box
- document.getElementById("filter"+id).value = "";
-
- //clear the last typed value
- lastVal = "";
-}
-
-function filter( ob, id ) {
- str = ob.value;
- //if the length of str is 0, keep original array as option
- if ( str.length == 0 ) {
- buildOptions(filterArray);
- remvdArray.length = 0;
- } else {
- //clear tempArray
- tempArray.length = 0;
-
- //set up temporary array
- for ( i = 0; i < selObj.options.length; i++ ) {
- tempArray[selObj.options[i].value] = selObj.options[i].text;
- }
- //escape the special character
- str = str.replace(/([\\"'()\]\[])/g, "\\$1");
-
- //case-insensitive regexp
- stregexp = new RegExp( str, "i" );
-
- //remove appropriate item(s)
- if ( lastVal.length < str.length ) {
- for ( j = selObj.options.length-1; j > -1; j-- ) {
- if ( selObj.options[j].text.match( stregexp ) == null ) {
- //delete unwanted option
- delete tempArray[selObj.options[j].value];
- }
- }
- } else {
- //add appropriate item(s)
- //if a removed item matches the new pattern, add it to the list of names
- for ( key in remvdArray) {
- tempName = remvdArray[key].toString();
- if ( tempName.match(stregexp) != null ) {
- tempArray[key] = tempName;
- }
- }
-
- //sort the names array
- tempArray.sort();
- }
-
- //build the new select list
- buildOptions(tempArray);
- }
-
- //remember the last value on which we narrowed
- lastVal = str;
-}
-
-function buildOptions( arrayName ) {
- //clear the select list
- selObj.options.length = 0;
- //to select only valid tokens in tokens list
- var tokenRegx = new RegExp (/{(\w+\.\w+)}/);
- var i = 0;
- for ( script in arrayName ) {
- if ( script.match(tokenRegx) != null ) {
- var option = new Option( arrayName[script], script );
- selObj.options[i] = option;
- i++;
- }
- }
- buildRemvd();
-}
-
-function buildRemvd( ) {
- //clear the removed items array
- remvdArray.length = 0;
- var remToken = null;
- //build the removed items array
- for ( key in filterArray ) {
- //for filtering tokens
- remToken = filterArray[key].toString();
- if ( remToken.match(stregexp) == null ) {
- //remember which item was removed
- remvdArray[key] = filterArray[key];
- }
- }
-}
-
-function getMatches(id) {
- if ( selObj.options.length == 1 ) {
- document.getElementById("match"+id).innerHTML = "{/literal}{ts escape='js'}1 match{/ts}{literal}";
- } else {
- document.getElementById("match"+id).innerHTML = selObj.options.length +" {/literal}{ts escape='js'}matches{/ts}{literal}";
- }
-}
-{/literal}