From ac0a3db5bb884559ac5d56176fb4c12d04be73da Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 21 Feb 2014 20:21:43 -0500 Subject: [PATCH] CRM-14258 - Use select2 for inserting tokens --- CRM/Admin/Form/MessageTemplates.php | 31 +-- CRM/Admin/Form/Preferences/Address.php | 12 +- CRM/Core/Form.php | 1 + CRM/Mailing/BAO/Mailing.php | 46 +--- CRM/Utils/Token.php | 35 +++ css/civicrm.css | 13 + templates/CRM/Admin/Form/MessageTemplates.tpl | 38 +-- .../CRM/Admin/Form/Preferences/Address.tpl | 12 +- templates/CRM/Admin/Page/MessageTemplates.tpl | 3 + templates/CRM/Contact/Form/Task/Email.tpl | 12 +- .../CRM/Contact/Form/Task/EmailCommon.tpl | 29 +-- .../CRM/Contact/Form/Task/PDFLetterCommon.tpl | 50 +--- templates/CRM/Contact/Form/Task/SMSCommon.tpl | 14 +- templates/CRM/Mailing/Form/InsertTokens.tpl | 227 ++++++++---------- templates/CRM/Mailing/Form/Upload.tpl | 12 +- templates/CRM/common/Filter.tpl | 138 ----------- 16 files changed, 190 insertions(+), 483 deletions(-) delete mode 100644 templates/CRM/common/Filter.tpl diff --git a/CRM/Admin/Form/MessageTemplates.php b/CRM/Admin/Form/MessageTemplates.php index fbb5b3098c..38b09b2d55 100644 --- a/CRM/Admin/Form/MessageTemplates.php +++ b/CRM/Admin/Form/MessageTemplates.php @@ -158,36 +158,7 @@ class CRM_Admin_Form_MessageTemplates extends CRM_Admin_Form { //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" diff --git a/CRM/Admin/Form/Preferences/Address.php b/CRM/Admin/Form/Preferences/Address.php index 01862a2b48..34c9be613a 100644 --- a/CRM/Admin/Form/Preferences/Address.php +++ b/CRM/Admin/Form/Preferences/Address.php @@ -151,17 +151,7 @@ class CRM_Admin_Form_Preferences_Address extends CRM_Admin_Form_Preferences { //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(); } diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 0899588c65..23ab78413e 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1271,6 +1271,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { 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')); diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 7dcdaa5809..34ab8f3bc4 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -2389,16 +2389,6 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id = m.id //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); @@ -2413,27 +2403,7 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id = m.id } //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)) { @@ -2498,19 +2468,7 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id = m.id $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)) { diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php index e6ad765924..813c5dfc70 100644 --- a/CRM/Utils/Token.php +++ b/CRM/Utils/Token.php @@ -1531,4 +1531,39 @@ class CRM_Utils_Token { ); } + /** + * 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; + } + } diff --git a/css/civicrm.css b/css/civicrm.css index 803481e9f5..286b678f00 100644 --- a/css/civicrm.css +++ b/css/civicrm.css @@ -3893,6 +3893,19 @@ div.m ul#civicrm-menu, 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, diff --git a/templates/CRM/Admin/Form/MessageTemplates.tpl b/templates/CRM/Admin/Form/MessageTemplates.tpl index 092d9bb6b6..0ee7810de7 100644 --- a/templates/CRM/Admin/Form/MessageTemplates.tpl +++ b/templates/CRM/Admin/Form/MessageTemplates.tpl @@ -52,14 +52,9 @@ {$form.msg_subject.label} - {$form.msg_subject.html|crmAddClass:huge} - {$form.token3.label} - {help id="id-token-text" file="CRM/Contact/Form/Task/Email.hlp"} - + {$form.msg_subject.html|crmAddClass:huge} + + {help id="id-token-subject" tplFile=$tplFile isAdmin=$isAdmin file="CRM/Contact/Form/Task/Email.hlp"}
{ts}Subject for email message.{/ts} {ts 1=$tokenDocsRepeated}Tokens may be included (%1).{/ts} @@ -71,16 +66,10 @@ {ts}Plain-Text Format{/ts}
- - {$form.token1.label} - {help id="id-token-text" file="CRM/Contact/Form/Task/Email.hlp"} - - -
+
+ + {help id="id-token-text" tplFile=$tplFile file="CRM/Contact/Form/Task/Email.hlp"} +
{$form.msg_text.html|crmAddClass:huge}
{ts}Text formatted message.{/ts} {ts 1=$tokenDocsRepeated}Tokens may be included (%1).{/ts}
@@ -94,15 +83,10 @@ {help id="id-message-text" file="CRM/Contact/Form/Task/Email.hlp"}
- - {$form.token2.label} - {help id="id-token-html" file="CRM/Contact/Form/Task/Email.hlp"} - - +
+ + {help id="id-token-html" tplFile=$tplFile isAdmin=$isAdmin editor=$editor file="CRM/Contact/Form/Task/Email.hlp"} +
{$form.msg_html.html} diff --git a/templates/CRM/Admin/Form/Preferences/Address.tpl b/templates/CRM/Admin/Form/Preferences/Address.tpl index 1a5ca2d806..14bc443118 100644 --- a/templates/CRM/Admin/Form/Preferences/Address.tpl +++ b/templates/CRM/Admin/Form/Preferences/Address.tpl @@ -30,14 +30,10 @@ {$form.mailing_format.label}
{help id='label-tokens'} - - {ts}Insert Tokens{/ts} - -
+
+ + {help id="id-token-text" tplFile=$tplFile file="CRM/Contact/Form/Task/Email.hlp"} +
{$form.mailing_format.html|crmAddClass:huge12}
{ts}Content and format for mailing labels.{/ts} diff --git a/templates/CRM/Admin/Page/MessageTemplates.tpl b/templates/CRM/Admin/Page/MessageTemplates.tpl index b0f2637130..68b0505220 100644 --- a/templates/CRM/Admin/Page/MessageTemplates.tpl +++ b/templates/CRM/Admin/Page/MessageTemplates.tpl @@ -87,6 +87,9 @@ {if $rows and $action ne 2 and $action ne 4} + {* include wysiwyg related files*} + {include file="CRM/common/wysiwyg.tpl" includeWysiwygEditor=true} +
  • {ts}User-driven Messages{/ts}
  • diff --git a/templates/CRM/Contact/Form/Task/Email.tpl b/templates/CRM/Contact/Form/Task/Email.tpl index ab3e1d02c3..e74cbd0266 100644 --- a/templates/CRM/Contact/Form/Task/Email.tpl +++ b/templates/CRM/Contact/Form/Task/Email.tpl @@ -57,14 +57,10 @@ {/if} {$form.subject.label} - {$form.subject.html|crmAddClass:huge}  - {$form.token3.label} - {help id="id-token-subject" file="CRM/Contact/Form/Task/Email.hlp"} - + + {$form.subject.html|crmAddClass:huge}  + + {help id="id-token-subject" tplFile=$tplFile isAdmin=$isAdmin file="CRM/Contact/Form/Task/Email.hlp"} diff --git a/templates/CRM/Contact/Form/Task/EmailCommon.tpl b/templates/CRM/Contact/Form/Task/EmailCommon.tpl index 9ff138512c..379bd41734 100644 --- a/templates/CRM/Contact/Form/Task/EmailCommon.tpl +++ b/templates/CRM/Contact/Form/Task/EmailCommon.tpl @@ -31,16 +31,11 @@ {help id="id-message-text" file="CRM/Contact/Form/Task/Email.hlp"}
- - {$form.token2.label} - {help id="id-token-html" tplFile=$tplFile isAdmin=$isAdmin editor=$editor file="CRM/Contact/Form/Task/Email.hlp"} -