CRM-15058 - Cleanup and js bug fixes in ScheduleReminder forms
authorColeman Watts <coleman@civicrm.org>
Fri, 29 Aug 2014 15:38:03 +0000 (16:38 +0100)
committerColeman Watts <coleman@civicrm.org>
Fri, 29 Aug 2014 16:53:23 +0000 (17:53 +0100)
CRM/Admin/Form/ScheduleReminders.php
CRM/Admin/Page/AJAX.php
CRM/Admin/Page/ScheduleReminders.php
CRM/Event/Form/ManageEvent/ScheduleReminders.php
js/Common.js
templates/CRM/Admin/Form/ScheduleReminders.tpl
templates/CRM/Admin/Page/ScheduleReminders.tpl
templates/CRM/Event/Form/ManageEvent/ScheduleReminders.tpl

index 0d764aaa30347ebb3a43bcb0a5b1d97784c61f8c..9f81d2e847e9c2e41cd60f9a6f795af899e766fd 100644 (file)
@@ -176,7 +176,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
     $this->addElement('checkbox', 'record_activity', $recordActivity);
 
     $this->addElement('checkbox', 'is_repeat', ts('Repeat'),
-      NULL, array('onclick' => "return showHideByValue('is_repeat',true,'repeatFields','table-row','radio',false);")
+      NULL, array('onchange' => "return showHideByValue('is_repeat',true,'repeatFields','table-row','radio',false);")
     );
 
     $this->add('select', 'repetition_frequency_unit', ts('every'), $freqUnitsDisplay);
@@ -203,7 +203,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
     $this->add('select', 'limit_to', ts('Limit Options'), $limitOptions);
 
     $this->add('select', 'recipient', ts('Recipients'), $sel5[$recipient],
-      FALSE, array('onClick' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);")
+      FALSE, array('onchange' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);")
     );
 
     if (!empty($_POST['is_recipient_listing'])) {
@@ -212,18 +212,14 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
     elseif (!empty($this->_values['recipient_listing'])) {
       $recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($this->_values['mapping_id'], $this->_values['recipient']);
     }
-    $recipientListing = $this->add('select', 'recipient_listing', ts('Recipient Listing'), $recipientListingOptions);
-    $recipientListing->setMultiple(TRUE);
-    $this->add('hidden', 'is_recipient_listing', empty($recipientListingOptions) ? FALSE : TRUE, array('id' => 'is_recipient_listing'));
+    $this->add('select', 'recipient_listing', ts('Recipient Roles'), $recipientListingOptions, FALSE,
+      array('multiple' => TRUE, 'class' => 'crm-select2 huge', 'placeholder' => TRUE));
+    $this->add('hidden', 'is_recipient_listing', (int) !empty($recipientListingOptions));
 
     $this->addEntityRef('recipient_manual_id', ts('Manual Recipients'), array('multiple' => TRUE, 'create' => TRUE));
 
-    $this->addElement(
-      'select',
-      'group_id',
-      ts('Group'),
-      // CRM-13577
-      CRM_Core_PseudoConstant::group()
+    $this->add('select', 'group_id', ts('Group'),
+      CRM_Core_PseudoConstant::nestedGroup(), FALSE, array('class' => 'crm-select2 huge')
     );
 
     CRM_Mailing_BAO_Mailing::commonCompose($this);
@@ -235,6 +231,8 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
     $this->add('checkbox', 'is_active', $isActive);
 
     $this->addFormRule(array('CRM_Admin_Form_ScheduleReminders', 'formRule'));
+
+    $this->setPageTitle(ts('Scheduled Reminder'));
   }
   /**
    * global form rule
index 7df95e15ff44423dacb5cf0e5c5e25edf09862ff..f05acc485c2a297aabed09612e0ed507259e3e11 100644 (file)
@@ -296,52 +296,27 @@ LIMIT $limit";
   }
 
   function mappingList() {
-    $params = array('mappingID');
-    foreach ($params as $param) {
-      $$param = CRM_Utils_Array::value($param, $_POST);
+    if (empty($_GET['mappingID'])) {
+      CRM_Utils_JSON::output(array('status' => 'error', 'error_msg' => 'required params missing.'));
     }
 
-    if (!$mappingID) {
-      CRM_Utils_JSON::output(array('error_msg' => 'required params missing.'));
-    }
-
-    $selectionOptions = CRM_Core_BAO_ActionSchedule::getSelection1($mappingID);
-    extract($selectionOptions);
-
-    $elements = array();
-    foreach ($sel4 as $id => $name) {
-      $elements[] = array(
-        'name' => $name,
-        'value' => $id,
-      );
-    }
-
-    CRM_Utils_JSON::output($elements);
-  }
-
-  function mappingList1() {
-    $params = array('mappingID');
-    foreach ($params as $param) {
-      $$param = CRM_Utils_Array::value($param, $_POST);
-    }
-
-    if (!$mappingID) {
-      CRM_Utils_JSON::output(array('error_msg' => 'required params missing.'));
-    }
+    $selectionOptions = CRM_Core_BAO_ActionSchedule::getSelection1($_GET['mappingID']);
 
-    $selectionOptions = CRM_Core_BAO_ActionSchedule::getSelection1($mappingID);
-    extract($selectionOptions);
-
-    $elements = array();
-    foreach ($sel5 as $id => $name) {
-      $elements['sel5'][] = array(
-        'name' => $name,
-        'value' => $id,
-      );
+    $output = array(
+      'sel4' => array(),
+      'sel5' => array(),
+      'recipientMapping' => $selectionOptions['recipientMapping'],
+    );
+    foreach (array(4, 5) as $sel) {
+      foreach ($selectionOptions["sel$sel"] as $id => $name) {
+        $output["sel$sel"][] = array(
+          'value' => $name,
+          'key' => $id,
+        );
+      }
     }
-    $elements['recipientMapping'] = $recipientMapping;
 
-    CRM_Utils_JSON::output($elements);
+    CRM_Utils_JSON::output($output);
   }
 
   static function mergeTags() {
@@ -366,16 +341,11 @@ LIMIT $limit";
   }
 
   function recipient() {
-    $params = array('recipient');
-    foreach ($params as $param) {
-      $$param = CRM_Utils_Array::value($param, $_POST);
-    }
-
-    if (!$recipient) {
-      CRM_Utils_JSON::output(array('error_msg' => 'required params missing.'));
+    if (empty($_GET['recipient'])) {
+      CRM_Utils_JSON::output(array('status' => 'error', 'error_msg' => 'required params missing.'));
     }
 
-    switch ($recipient) {
+    switch ($_GET['recipient']) {
       case 'Participant Status':
         $values = CRM_Event_PseudoConstant::participantStatus();
         break;
@@ -391,8 +361,8 @@ LIMIT $limit";
     $elements = array();
     foreach ($values as $id => $name) {
       $elements[] = array(
-        'name' => $name,
-        'value' => $id,
+        'value' => $name,
+        'key' => $id,
       );
     }
 
index d93f58954e5bcc889b18fc2a82c5b5f83f869139..4f375464d284d8aa59b7f79792cf28ed34a251c3 100644 (file)
@@ -72,7 +72,6 @@ class CRM_Admin_Page_ScheduleReminders extends CRM_Core_Page_Basic {
           'url' => 'civicrm/admin/scheduleReminders',
           'qs' => 'action=update&id=%%id%%&reset=1',
           'title' => ts('Edit Schedule Reminders'),
-          'class' => 'no-popup',
         ),
         CRM_Core_Action::ENABLE => array(
           'name' => ts('Enable'),
index f0c468883436db48a5d69280f25a8d02584e4672..2fc095c3fdb8e5893d66c155220ccf5cf3200913 100755 (executable)
@@ -92,6 +92,7 @@ class CRM_Event_Form_ManageEvent_ScheduleReminders extends CRM_Event_Form_Manage
       // Update tab "disabled" css class
       $this->ajaxResponse['tabValid'] = !empty($reminderList) && is_array($reminderList);
     }
+    $this->setPageTitle(ts('Scheduled Reminder'));
   }
 
   /**
@@ -192,16 +193,14 @@ class CRM_Event_Form_ManageEvent_ScheduleReminders extends CRM_Event_Form_Manage
     $this->add('select', 'recipient', ts('Recipients'), $sel5[$recipient],
       FALSE, array('onchange' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);")
     );
-    $recipientListing = $this->add('select', 'recipient_listing', ts('Recipient Listing'),
-      $sel3[$this->_mappingID][0], FALSE, array('class' => 'crm-select2 huge')
+    $recipientListing = $this->add('select', 'recipient_listing', ts('Recipient Roles'),
+      $sel3[$this->_mappingID][0], FALSE, array('multiple' => TRUE, 'class' => 'crm-select2 huge', 'placeholder' => TRUE)
     );
-    $recipientListing->setMultiple(TRUE);
 
     $this->addEntityRef('recipient_manual_id', ts('Manual Recipients'), array('multiple' => true));
 
-    $groups = CRM_Contact_BAO_Group::getGroupsHierarchy(CRM_Core_PseudoConstant::staticGroup(), NULL, '&nbsp;&nbsp;', TRUE);
     $this->add('select', 'group_id', ts('Group'),
-      $groups, FALSE, array('class' => 'crm-select2 huge')
+      CRM_Core_PseudoConstant::nestedGroup(), FALSE, array('class' => 'crm-select2 huge')
     );
 
     CRM_Mailing_BAO_Mailing::commonCompose($this);
index 1a614e3e411ad128c6f7dd27f4c2fbff1433f952..c7856defcc8820e85bcfe07819427362c4d67325 100644 (file)
@@ -213,16 +213,15 @@ CRM.strings = CRM.strings || {};
 
   /**
    * Populate a select list, overwriting the existing options except for the placeholder.
-   * @param $el jquery collection - 1 or more select elements
+   * @param select jquery selector - 1 or more select elements
    * @param options array in format returned by api.getoptions
    * @param placeholder string
    */
-  CRM.utils.setOptions = function($el, options, placeholder) {
-    $el.each(function() {
+  CRM.utils.setOptions = function(select, options, placeholder) {
+    $(select).each(function() {
       var
         $elect = $(this),
         val = $elect.val() || [],
-        multiple = $el.is('[multiple]'),
         opts = placeholder || placeholder === '' ? '' : '[value!=""]',
         newOptions = '',
         theme = function(options) {
@@ -243,8 +242,8 @@ CRM.strings = CRM.strings || {};
       $elect.find('option' + opts).remove();
       theme(options);
       if (typeof placeholder === 'string') {
-        if (multiple) {
-          $el.attr('placeholder', placeholder);
+        if ($elect.is('[multiple]')) {
+          select.attr('placeholder', placeholder);
         } else {
           newOptions = '<option value="">' + placeholder + '</option>' + newOptions;
         }
index fb8cbae96f560d6983663612204a9d7def300f8f..7dee089b7e05aaa6cba67469a10a4c4bf1124b39 100644 (file)
 
 {literal}
 <script type='text/javascript'>
-    var entityMapping = eval({/literal}{$entityMapping}{literal});
-    var recipientMapping = eval({/literal}{$recipientMapping}{literal});
-
-
     CRM.$(function($) {
-      $('#absolute_date_display').change(function() {
-        if($('#absolute_date_display').val()) {
-          $('#relativeDate').hide();
-          $('#relativeDateRepeat').hide();
-          $('#repeatFields').hide();
+      var $form = $('form.{/literal}{$form.formClass}{literal}'),
+        recipientMapping = eval({/literal}{$recipientMapping}{literal});
+
+      $('#absolute_date_display', $form).change(function() {
+        if($(this).val()) {
+          $('#relativeDate, #relativeDateRepeat, #repeatFields', $form).hide();
         } else {
-          $('#relativeDate').show();
-          $('#relativeDateRepeat').show();
+          $('#relativeDate, #relativeDateRepeat', $form).show();
         }
       });
       
-      if ($('#absolute_date_display').val()) {
-        $('#relativeDate, #relativeDateRepeat, #repeatFields').hide();
+      if ($('#absolute_date_display', $form).val()) {
+        $('#relativeDate, #relativeDateRepeat, #repeatFields', $form).hide();
       }
 
-      $('#entity_0').change( function( ) {
-        buildSelect("start_action_date");
-        buildSelect("end_date");
-        buildSelect1("recipient");
-        showHideLimitTo();
-      });
+      $('#entity_0', $form).change(buildSelects);
 
       loadMsgBox();
-      $('#mode').change(loadMsgBox);
+      $('#mode', $form).change(loadMsgBox);
 
       showHideLimitTo();
 
-      if ($('#is_recipient_listing').val()) {
-        $('#recipientList').show();
+      $('#recipient', $form).change(populateRecipient);
+
+      var entity = $('#entity_0', $form).val();
+      if (!(entity === '2' || entity === '3') || $('#recipient', $form).val() !== '1') {
+        $('#recipientList', $form).hide();
+      }
+
+      function buildSelects() {
+        var mappingID = $('#entity_0', $form).val();
+
+        $('#is_recipient_listing').val('');
+        $.getJSON(CRM.url('civicrm/ajax/mapping'), {mappingID: mappingID},
+          function (result) {
+            CRM.utils.setOptions($('#start_action_date', $form), result.sel4);
+            CRM.utils.setOptions($('#end_date', $form), result.sel4);
+            CRM.utils.setOptions($('#recipient', $form), result.sel5);
+            recipientMapping = result.recipientMapping;
+            populateRecipient();
+          }
+        );
       }
-      else {
-        $('#recipientList').hide();
+      function populateRecipient() {
+        var recipient = $("#recipient", $form).val();
+
+        if (recipientMapping[recipient] == 'Participant Status' || recipientMapping[recipient] == 'participant_role') {
+          $.getJSON(CRM.url('civicrm/ajax/populateRecipient'), {recipient: recipientMapping[recipient]},
+            function (result) {
+              CRM.utils.setOptions($('#recipient_listing', $form), result);
+            }
+          );
+          $("#recipientList", $form).show();
+          $('#is_recipient_listing', $form).val(1);
+        } else {
+          $("#recipientList", $form).hide();
+          $('#is_recipient_listing', $form).val('');
+        }
       }
-      $('#recipient').change(populateRecipient);
     });
 
   function loadMsgBox() {
     }
   }
 
-  function populateRecipient( ) {
-    var recipient = cj("#recipient option:selected").val();
-    var entity = cj("#entity_0 option:selected").val();
-    var postUrl = "{/literal}{crmURL p='civicrm/ajax/populateRecipient' h=0}{literal}";
-
-    if (recipientMapping[recipient] == 'Participant Status' || recipientMapping[recipient] == 'participant_role') {
-      var elementID = '#recipient_listing';
-      cj( elementID ).html('');
-      cj.post(postUrl, {recipient: recipientMapping[recipient]},
-      function ( response ) {
-        response = eval( response );
-        for (i = 0; i < response.length; i++) {
-          cj( elementID ).get(0).add(new Option(response[i].name, response[i].value), document.all ? i : null);
-        }
-      });
-      cj("#recipientList").show();
-      cj('#is_recipient_listing').val(1);
-    } else {
-      cj("#recipientList").hide();
-      cj('#is_recipient_listing').val('');
-    }
-  }
-  
-  function buildSelect( selectID ) {
-    var elementID = '#' +  selectID;
-    cj( elementID ).html('');
-    var mappingID = cj('#entity_0').val();
-    var postUrl = "{/literal}{crmURL p='civicrm/ajax/mapping' h=0}{literal}";
-    cj.post( postUrl, { mappingID: mappingID},
-    function ( response ) {
-      response = eval( response );
-      for (i = 0; i < response.length; i++) {
-        cj( elementID ).get(0).add(new Option(response[i].name, response[i].value), document.all ? i : null);
-      }
-    }
-    );
-  }
-
-  function buildSelect1( selectID ) {
-    var elementID = '#' +  selectID;
-    cj( elementID ).html('');
-    var mappingID = cj('#entity_0').val();
-    var postUrl1 = "{/literal}{crmURL p='civicrm/ajax/mapping1' h=0}{literal}";
-
-    cj('#is_recipient_listing').val('');
-    cj.post( postUrl1, { mappingID: mappingID},
-    function ( result ) {
-      var responseResult = cj.parseJSON(result);
-      var response       = eval(responseResult.sel5);
-      recipientMapping   = eval(responseResult.recipientMapping);
-      for (i = 0; i < response.length; i++) {
-        cj( elementID ).get(0).add(new Option(response[i].name, response[i].value), document.all ? i : null);
-      }
-      populateRecipient();
-    }
-    );
-  }
-
  </script>
  {/literal}
 
index 234011941d823a64d62ebc8e326f6e81cd5d78b9..40ecbf322c0f95a22fbf20e30ebd5f7feb3554be 100644 (file)
 {if $action eq 1 or $action eq 2 or $action eq 8 or $action eq 16384}
    {include file="CRM/Admin/Form/ScheduleReminders.tpl"}
 {else}
-{* include wysiwyg related files*}
-{include file="CRM/common/wysiwyg.tpl" includeWysiwygEditor=true}
-{capture assign=schedRemindersDocLink}{docURL page="user/current/email/scheduled-reminders/"}{/capture}
-<div class="help">
-  {ts}Scheduled reminders allow you to automatically send messages to contacts regarding their memberships, participation in events, or other activities.{/ts} {$schedRemindersDocLink}
-</div>
-{if $rows}
+  {* include wysiwyg related files*}
+  {include file="CRM/common/wysiwyg.tpl" includeWysiwygEditor=true}
+  {capture assign=schedRemindersDocLink}{docURL page="user/current/email/scheduled-reminders/"}{/capture}
+  <div class="help">
+    {ts}Scheduled reminders allow you to automatically send messages to contacts regarding their memberships, participation in events, or other activities.{/ts} {$schedRemindersDocLink}
+  </div>
+  {if $rows}
     <div id="reminder">
       {include file="CRM/Admin/Page/Reminders.tpl"}
-      <div class="action-link">
-        <a href="{crmURL q="action=add&reset=1"}" id="newScheduleReminder" class="button no-popup"><span><div class="icon add-icon"></div>{ts}Add Reminder{/ts}</span></a>
-      </div>
-
     </div>
-
-{else}
+  {else}
     <div class="messages status no-popup">
       <div class="icon inform-icon"></div>
-        {capture assign=crmURL}class="no-popup" href="{crmURL p='civicrm/admin/scheduleReminders' q="action=add&reset=1"}" class="action-item"{/capture}
-        {ts 1=$crmURL}There are no Scheduled Reminders configured. You can <a %1>add one</a>.{/ts}
+      {ts}None found.{/ts}
     </div>
-{/if}
+  {/if}
+  <div class="action-link">
+    <a href="{crmURL q="action=add&reset=1"}" id="newScheduleReminder" class="button"><span><div class="icon add-icon"></div>{ts}Add Reminder{/ts}</span></a>
+  </div>
 {/if}
index 9b9ba3462358f9bcba3597d779389a2fc0dcf5e8..ada0d04c2b498cdd4b7da8ec56ec0c025cb8b855 100755 (executable)
   {literal}
     <script type='text/javascript'>
       CRM.$(function($) {
+        var $form = $('form.{/literal}{$form.formClass}{literal}'),
+          recipientMapping = eval({/literal}{$recipientMapping}{literal});
+
         populateRecipient();
-        $('#recipient').click( function( ) {
-          populateRecipient();
-        });
-      });
+        $('#recipient', $form).change(populateRecipient);
 
-      function populateRecipient( ) {
-        var recipientMapping = eval({/literal}{$recipientMapping}{literal});
-        var recipient = cj("#recipient option:selected").val();
-        var postUrl = "{/literal}{crmURL p='civicrm/ajax/populateRecipient' h=0}{literal}";
-        if(recipientMapping[recipient] == 'Participant Status' || recipientMapping[recipient] == 'participant_role'){
-          var elementID = '#recipient_listing';
-          cj( elementID ).html('');
-          cj.post(postUrl, {recipient: recipientMapping[recipient]},
-            function ( response ) {
-              response = eval( response );
-              for (iota = 0; iota < response.length; iota++) {
-                cj( elementID ).get(0).add(new Option(response[iota].name, response[iota].value), document.all ? iota : null);
+        function populateRecipient() {
+          var recipient = $("#recipient", $form).val();
+
+          if (recipientMapping[recipient] == 'Participant Status' || recipientMapping[recipient] == 'participant_role') {
+            $.getJSON(CRM.url('civicrm/ajax/populateRecipient'), {recipient: recipientMapping[recipient]},
+              function (result) {
+                CRM.utils.setOptions($('#recipient_listing', $form), result);
               }
-            }
-          );
-          cj("#recipientList").show();
-        } else {
-          cj("#recipientList").hide();
+            );
+            $("#recipientList", $form).show();
+            $('#is_recipient_listing', $form).val(1);
+          } else {
+            $("#recipientList", $form).hide();
+            $('#is_recipient_listing', $form).val('');
+          }
         }
-      }
-
-      cj('#absolute_date_display').click( function( ) {
-        if(cj('#absolute_date_display').val()) {
-          cj('#relativeDate').hide();
-          cj('#relativeDateRepeat').hide();
-          cj('#repeatFields').hide();
-        } else {
-          cj('#relativeDate').show();
-          cj('#relativeDateRepeat').show();
+
+        $('#absolute_date_display', $form).change(function() {
+          if($(this).val()) {
+            $('#relativeDate, #relativeDateRepeat, #repeatFields', $form).hide();
+          } else {
+            $('#relativeDate, #relativeDateRepeat', $form).show();
+          }
+        });
+
+        if ($('#absolute_date_display', $form).val()) {
+          $('#relativeDate, #relativeDateRepeat, #repeatFields', $form).hide();
         }
+
       });
 
     </script>
   {/literal}
   {/if}
   <div class="crm-submit-buttons">
-    {include file="CRM/common/formButtons.tpl" location="bottom"}</div>
+    {include file="CRM/common/formButtons.tpl" location="bottom"}
+  </div>
 </div>
 {/if}