From e737155e05649e17904caa6f4b8abc9240f6a9e5 Mon Sep 17 00:00:00 2001 From: JKingsnorth Date: Wed, 24 Oct 2018 09:03:53 -0700 Subject: [PATCH] dev/core#456 Improve UX of scheduling mass SMS --- CRM/SMS/Form/Schedule.php | 45 ++++++++++++++--------------- templates/CRM/SMS/Form/Schedule.tpl | 45 ++++++++++++++--------------- 2 files changed, 42 insertions(+), 48 deletions(-) diff --git a/CRM/SMS/Form/Schedule.php b/CRM/SMS/Form/Schedule.php index 64bf752d6f..50058c1f99 100644 --- a/CRM/SMS/Form/Schedule.php +++ b/CRM/SMS/Form/Schedule.php @@ -53,7 +53,7 @@ class CRM_SMS_Form_Schedule extends CRM_Core_Form { $count = $this->get('count'); $this->assign('count', $count); - $defaults['now'] = 1; + $defaults['send_option'] = 'send_immediate'; return $defaults; } @@ -61,9 +61,18 @@ class CRM_SMS_Form_Schedule extends CRM_Core_Form { * Build the form object for the last step of the sms wizard. */ public function buildQuickform() { - $this->addDateTime('start_date', ts('Schedule SMS'), FALSE, array('formatType' => 'mailing')); - $this->addElement('checkbox', 'now', ts('Send Immediately')); + // Fix Firefox issue where the non-default field is displayed as checked + // on page refresh. + $this->setAttribute('autocomplete', 'off'); + + $sendOptions = [ + $this->createElement('radio', NULL, NULL, 'Send immediately', 'send_immediate', ['id' => 'send_immediate', 'style' => 'margin-bottom: 10px;']), + $this->createElement('radio', NULL, NULL, 'Send at:', 'send_later', ['id' => 'send_later']), + ]; + $this->addGroup($sendOptions, 'send_option', '', '
'); + + $this->add('datepicker', 'start_date', '', NULL, FALSE, ['minDate' => time()]); $this->addFormRule(array('CRM_SMS_Form_Schedule', 'formRule'), $this); @@ -111,29 +120,28 @@ class CRM_SMS_Form_Schedule extends CRM_Core_Form { * set. */ public static function formRule($params, $files, $self) { - if (!empty($params['_qf_Schedule_submit'])) { + if (!empty($params['_qf_Schedule_submit'])) { CRM_Core_Session::setStatus(ts("Your Mass SMS has been saved. Click the 'Continue' action to resume working on it."), ts('Saved'), 'success'); $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1&sms=1'); CRM_Utils_System::redirect($url); } - if (isset($params['now']) || CRM_Utils_Array::value('_qf_Schedule_back', $params) == ts('Previous')) { + + if ((isset($params['send_option']) && $params['send_option'] == 'send_immediate') || CRM_Utils_Array::value('_qf_Schedule_back', $params) == ts('Previous')) { return TRUE; } - if (CRM_Utils_Date::format(CRM_Utils_Date::processDate($params['start_date'], - $params['start_date_time'] - )) < CRM_Utils_Date::format(date('YmdHi00')) - ) { + if (strtotime($params['start_date']) < time()) { return array( 'start_date' => ts('Start date cannot be earlier than the current time.'), ); } + return TRUE; } /** - * Process the posted form values. Create and schedule a Mass SMS. + * Process the posted form values. Create and schedule a Mass SMS. */ public function postProcess() { $params = array(); @@ -144,21 +152,17 @@ class CRM_SMS_Form_Schedule extends CRM_Core_Form { CRM_Core_Error::fatal(ts('Could not find a mailing id')); } - foreach (array('now', 'start_date', 'start_date_time') as $parameter) { - $params[$parameter] = $this->controller->exportValue($this->_name, $parameter); - } - - if ($params['now']) { + $send_option = $this->controller->exportValue($this->_name, 'send_option'); + if (isset($params['send_option']) && $params['send_option'] == 'send_immediate') { $params['scheduled_date'] = date('YmdHis'); } else { - $params['scheduled_date'] = CRM_Utils_Date::processDate($params['start_date'] . ' ' . $params['start_date_time']); + $params['scheduled_date'] = $this->controller->exportValue($this->_name, 'start_date'); } $session = CRM_Core_Session::singleton(); // set the scheduled_id $params['scheduled_id'] = $session->get('userID'); - $params['scheduled_date'] = date('YmdHis'); // set approval details if workflow is not enabled if (!CRM_Mailing_Info::workflowEnabled()) { @@ -167,13 +171,6 @@ class CRM_SMS_Form_Schedule extends CRM_Core_Form { $params['approval_status_id'] = 1; } - if ($params['now']) { - $params['scheduled_date'] = date('YmdHis'); - } - else { - $params['scheduled_date'] = CRM_Utils_Date::processDate($params['start_date'] . ' ' . $params['start_date_time']); - } - // Build the mailing object. CRM_Mailing_BAO_Mailing::create($params, $ids); diff --git a/templates/CRM/SMS/Form/Schedule.tpl b/templates/CRM/SMS/Form/Schedule.tpl index 1eb30371b5..0923c1b961 100644 --- a/templates/CRM/SMS/Form/Schedule.tpl +++ b/templates/CRM/SMS/Form/Schedule.tpl @@ -30,24 +30,16 @@ {include file="CRM/Mailing/Form/Count.tpl"} - - - - - - - - - - - - - - - -
{$form.now.label}{$form.now.html}
{ts}OR{/ts} 
{$form.start_date.label}{include file="CRM/common/jcalendar.tpl" elementName=start_date} -
{ts}Set a date and time when you want CiviSMS to start sending this Mass SMS.{/ts}
-
+
+
+
+ {$form.send_option.html} + {$form.start_date.html} +
+ +
+
{ts}Set a date and time when you want CiviSMS to start sending this Mass SMS.{/ts}
+
{include file="CRM/common/formButtons.tpl"}
{if $preview} @@ -71,16 +63,21 @@ -- 2.25.1