dev/core-1711 Show segment count for SMS construction
authorJohn Twyman <john.twyman@greens.org.au>
Wed, 5 May 2021 01:11:56 +0000 (11:11 +1000)
committerJohn Twyman <john.twyman@greens.org.au>
Mon, 28 Jun 2021 00:30:33 +0000 (10:30 +1000)
Use Standard methods for downloading third party js package

Update composer.lock

composer.json
composer.lock
templates/CRM/Contact/Form/Task/SMS.hlp
templates/CRM/Contact/Form/Task/SMSCommon.tpl

index 5765df6b981c54291c46aa2789b3cecb1a6b62a7..5015cc35eb01c175ca06edef0ea9d55d35794659 100644 (file)
       "smartmenus": {
         "url": "https://github.com/vadikom/smartmenus/archive/1.1.0.zip",
         "ignore": [".gitignore", "Gruntfile.js"]
+      },
+      "sms-counter": {
+        "url": "https://github.com/danxexe/sms-counter/archive/master.zip",
+        "ignore": ["examples"]
       }
     },
     "patches": {
index 6938b626a7226d09a859913c2a7fbe984d0aad0f..8dfc659d5ffefa1843cdb3db7a411dbfe2870e14 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "806655f49ee4984e61d0c1bf7bcc0c88",
+    "content-hash": "3d4576d680aea8094656e1d832571507",
     "packages": [
         {
             "name": "adrienrn/php-mimetyper",
index af5b509608a39269fc820e66aefbf4eae78297d2..e52a37f905eafec1e5a2c06c1d68003961de565d 100644 (file)
 
 {/htxt} 
 
+{htxt id="id-count-text"}
+<p>{ts}A single SMS message is typically 160 characters in length. If you want to send a message that is longer than 160 characters, it is split into multiple segments.{/ts}</p>
+<p>{ts}The cost of sending SMS message is typically <em>per segment</em>.{/ts}</p>
+<p>{ts}Certain characters like emoji or curly quotes can shorten the segment size to 96 characters, increasing the cost per message.{/ts}</p>
+{/htxt}
+
 {htxt id="id-message-text-title"}
 {ts}Rich Text{/ts}
 {/htxt}
index 671da643439fba1cd63f1143efb703278c03509a..16c1924a28f027c7a422728595ad809645719f1e 100644 (file)
@@ -9,12 +9,14 @@
 *}
 {*common template for compose sms*}
 
+{crmScript file=bower_components/sms-counter/sms_counter.min.js region=html-header}
+
 <div class="crm-accordion-wrapper crm-plaint_text_sms-accordion ">
 <div class="crm-accordion-header">
   {$form.sms_text_message.label}
   </div><!-- /.crm-accordion-header -->
  <div class="crm-accordion-body">
- <div id='char-count-message'></div>
+ <div><span id="char-count-message"></span> <span id="char-count-help">{help id="id-count-text" tplFile=$tplFile file="CRM/Contact/Form/Task/SMS.hlp"}</span></div>
    <div class="helpIcon" id="helptext">
      <input class="crm-token-selector big" data-field="sms_text_message" />
      {help id="id-token-text" tplFile=$tplFile file="CRM/Contact/Form/Task/SMS.hlp"}
    <div class="content">{$form.SMSsaveTemplateName.html|crmAddClass:huge}</div>
 </div>
 
+{capture assign="char_count_message"}
+{ts}You can insert up to %1 characters. You have entered %2 characters, requiring %3 segments.{/ts}
+{/capture}
+
 {literal}
 <script type="text/javascript">
-
 {/literal}{if $max_sms_length}{literal}
 maxCharInfoDisplay();
 
-cj('#sms_text_message').bind({
+CRM.$('#sms_text_message').bind({
   change: function() {
    maxLengthMessage();
   },
@@ -55,10 +60,10 @@ cj('#sms_text_message').bind({
 
 function maxLengthMessage()
 {
-   var len = cj('#sms_text_message').val().length;
+   var len = CRM.$('#sms_text_message').val().length;
    var maxLength = {/literal}{$max_sms_length}{literal};
    if (len > maxLength) {
-      cj('#sms_text_message').crmError({/literal}'{ts escape="js"}SMS body exceeding limit of 160 characters{/ts}'{literal});
+      CRM.$('#sms_text_message').crmError({/literal}'{ts escape="js"}SMS body exceeding limit of {$max_sms_length} characters{/ts}'{literal});
       return false;
    }
 return true;
@@ -66,14 +71,16 @@ return true;
 
 function maxCharInfoDisplay(){
    var maxLength = {/literal}{$max_sms_length}{literal};
-   var enteredCharLength = cj('#sms_text_message').val().length;
-   var count = enteredCharLength;
+   var enteredText = SmsCounter.count(CRM.$('#sms_text_message').val());
+   var count = enteredText.length;
+   var segments = enteredText.messages;
 
    if( count < 0 ) {
-      cj('#sms_text_message').val(cj('#sms_text_message').val().substring(0, maxLength));
+      CRM.$('#sms_text_message').val(CRM.$('#sms_text_message').val().substring(0, maxLength));
       count = 0;
    }
-   cj('#char-count-message').text( "You can insert up to " + maxLength + " characters. You have entered " + count + " characters." );
+   var message = "{/literal}{$char_count_message}{literal}"
+   CRM.$('#char-count-message').text(message.replace('%1', maxLength).replace('%2', count).replace('%3', segments));
 }
 {/literal}{/if}{literal}