CRM-13863 - Ajaxify event tabs
authorColeman Watts <coleman@civicrm.org>
Mon, 30 Dec 2013 01:09:47 +0000 (17:09 -0800)
committerColeman Watts <coleman@civicrm.org>
Mon, 6 Jan 2014 19:11:39 +0000 (11:11 -0800)
13 files changed:
CRM/Admin/Page/ScheduleReminders.php
CRM/Event/Form/ManageEvent.php
CRM/Event/Form/ManageEvent/ScheduleReminders.php
CRM/Event/Form/ManageEvent/TabHeader.php
js/Common.js
js/crm.livePage.js
templates/CRM/Admin/Form/ScheduleReminders.tpl
templates/CRM/Admin/Page/Reminders.tpl
templates/CRM/Admin/Page/ScheduleReminders.tpl
templates/CRM/Contact/Page/View/Summary.js
templates/CRM/Contact/Page/View/Summary.tpl
templates/CRM/Event/Form/ManageEvent/ScheduleReminders.tpl
templates/CRM/common/TabHeader.js

index 8d117b33d654be6d5990c3c2d69a3c265adf565e..b42ee6090122b8f26b4e872b99a5e56a86e8dcb2 100644 (file)
@@ -128,6 +128,7 @@ class CRM_Admin_Page_ScheduleReminders extends CRM_Core_Page_Basic {
    * @static
    */
   function browse($action = NULL) {
+    CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
     // Get list of configured reminders
     $reminderList = CRM_Core_BAO_ActionSchedule::getList();
 
index 32c0651b5d39dca3753621e7074db455de52478f..1b873b1748ef72974b7d5df84cf59a207ba09238 100644 (file)
@@ -338,7 +338,7 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form {
       }
 
       CRM_Core_Session::setStatus(ts("'%1' information has been saved.",
-          array(1 => ($subPage == 'friend') ? 'Friend' : $className)
+          array(1 => CRM_Utils_Array::value('title', CRM_Utils_Array::value($subPage, $this->get('tabHeader')), $className))
         ), ts('Saved'), 'success');
 
       $config = CRM_Core_Config::singleton();
@@ -353,18 +353,14 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form {
       $this->postProcessHook();
       if ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_done") {
         if ($this->_isTemplate) {
-          CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/eventTemplate',
-              'reset=1'
-            ));
+          CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1'));
         }
         else {
-          CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/manage',
-              'reset=1'
-            ));
+          CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/event/manage', 'reset=1'));
         }
       }
       else {
-        CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/event/manage/{$subPage}",
+        CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url("civicrm/event/manage/{$subPage}",
             "action=update&reset=1&id={$this->_id}"
           ));
       }
index de285bf3bce493a66887b67ccb3d287d0c2af25f..58c400b9e89ee90dae9b29293c6848a0ef995c32 100755 (executable)
@@ -58,7 +58,7 @@ class CRM_Event_Form_ManageEvent_ScheduleReminders extends CRM_Event_Form_Manage
         $field = 'event_template';
       }
       $reminderList = CRM_Core_BAO_ActionSchedule::getList(FALSE, $field, $this->_id );
-      if (is_array($reminderList)) {
+      if ($reminderList && is_array($reminderList)) {
         // Add action links to each of the reminders
         foreach ($reminderList as & $format) {
           $action = CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE;
@@ -82,8 +82,11 @@ class CRM_Event_Form_ManageEvent_ScheduleReminders extends CRM_Event_Form_Manage
             $this->_id
           );
         }
-        $this->assign('rows', $reminderList);
       }
+      else {
+        $reminderList = TRUE;
+      }
+      $this->assign('rows', $reminderList);
     }
   }
 
index 92756352fe0fb12638d13293c97f8484df4c4709..d591fc35a9830c64d86ef5a9f3cffb4ac114af6e 100644 (file)
@@ -58,55 +58,23 @@ class CRM_Event_Form_ManageEvent_TabHeader {
       return NULL;
     }
 
+    $default = array(
+      'link' => NULL,
+      'valid' => TRUE,
+      'active' => TRUE,
+      'current' => FALSE,
+      'class' => 'ajaxForm',
+    );
+
     $tabs = array(
-      'settings' => array('title' => ts('Info and Settings'),
-        'link' => NULL,
-        'valid' => TRUE,
-        'active' => TRUE,
-        'current' => FALSE,
-      ),
-      'location' => array('title' => ts('Event Location'),
-        'link' => NULL,
-        'valid' => TRUE,
-        'active' => TRUE,
-        'current' => FALSE,
-      ),
-      'fee' => array('title' => ts('Fees'),
-        'link' => NULL,
-        'valid' => TRUE,
-        'active' => TRUE,
-        'current' => FALSE,
-      ),
-      'registration' => array('title' => ts('Online Registration'),
-        'link' => NULL,
-        'valid' => TRUE,
-        'active' => TRUE,
-        'current' => FALSE,
-      ),
-      'reminder' => array('title' => ts('Schedule Reminders'),
-        'link' => NULL,
-        'valid' => TRUE,
-        'active' => TRUE,
-        'current' => FALSE,
-      ),
-      'conference' => array('title' => ts('Conference Slots'),
-        'link' => NULL,
-        'valid' => TRUE,
-        'active' => TRUE,
-        'current' => FALSE,
-      ),
-      'friend' => array('title' => ts('Tell a Friend'),
-        'link' => NULL,
-        'valid' => TRUE,
-        'active' => TRUE,
-        'current' => FALSE,
-      ),
-      'pcp' => array('title' => ts('Personal Campaigns'),
-        'link' => NULL,
-        'valid' => TRUE,
-        'active' => TRUE,
-        'current' => FALSE,
-      )
+      'settings' => array('title' => ts('Info and Settings')) + $default,
+      'location' => array('title' => ts('Event Location')) + $default,
+      'fee' => array('title' => ts('Fees')) + $default,
+      'registration' => array('title' => ts('Online Registration')) + $default,
+      'reminder' => array('title' => ts('Schedule Reminders'), 'class' => 'livePage') + $default,
+      'conference' => array('title' => ts('Conference Slots')) + $default,
+      'friend' => array('title' => ts('Tell a Friend')) + $default,
+      'pcp' => array('title' => ts('Personal Campaigns')) + $default,
     );
 
     // check if we're in shopping cart mode for events
index a8674d6600bf84ee394f9bc5c8e836d3e0da1c7d..f9ba78ac9bffcd3f2d9c649bce73bffbe473b298 100644 (file)
@@ -896,6 +896,9 @@ CRM.validate = CRM.validate || {
       }).fail(function() {
           that._onFailure();
         });
+    },
+    _destroy: function() {
+      this.element.removeClass('crm-ajax-container');
     }
   });
 
index b7f8f15f4de64b10164b7aa791aaed9fcac0ebd1..2d01bef689fa262a2b1b7e47c0258592039376f5 100644 (file)
@@ -5,7 +5,8 @@ cj(function($) {
     // Widgetize the content area
     .crmSnippet()
     // Open action links in a popup
-    .on('click', 'a.button, a.action-item', function() {
+    .off('click.crmLivePage')
+    .on('click.crmLivePage', 'a.button, a.action-item', function() {
       // only follow real links not javascript buttons
       if ($(this).attr('href') === '#' || $(this).attr('onclick')) {
         return;
index a19fb449b08263c1b1a60c69a788f18a479da3db..1bd573ad75298bac689b45fb32c0f72172d6c6a1 100644 (file)
         {include file="CRM/Contact/Form/Task/EmailCommon.tpl" upload=1 noAttach=1}
   </fieldset>
 
-{/if}
-
-<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
-</div>
-
 {include file="CRM/common/showHideByFieldValue.tpl"
     trigger_field_id    = "is_repeat"
     trigger_value       = "true"
 
  </script>
  {/literal}
+
+{/if}
+
+ <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
+</div>
index 7f97a331e1a8e67fe68e842fc95705c730dc05c1..379393a57eb680ee6ff2c18b869fda6e84442de0 100755 (executable)
 *}
 {* this template is for configuring Scheduled Reminders Table*}
 {strip}
-  {include file="CRM/common/enableDisableApi.tpl"}
-  {include file="CRM/common/crmeditable.tpl"}
-  {include file="CRM/common/jsortable.tpl"}
+  {if $rows and is_array($rows)}
+    {include file="CRM/common/enableDisableApi.tpl"}
+    {include file="CRM/common/crmeditable.tpl"}
+    {include file="CRM/common/jsortable.tpl"}
+  {/if}
   <table id="scheduleReminders" class="display">
     <thead>
     <tr id="options" class="columnheader">
       <th ></th>
     </tr>
     </thead>
-    {foreach from=$rows item=row}
-      <tr id="action_schedule-{$row.id}" class="crm-entity {cycle values="odd-row,even-row"} {$row.class}{if NOT $row.is_active} disabled{/if}">
-        <td class="crm-scheduleReminders-title crm-editable" data-field="title">{$row.title}</td>
-        <td class="crm-scheduleReminders-value">{$row.entity} - {$row.value}</td>
-        <td class="crm-scheduleReminders-description">{if $row.absolute_date}{$row.absolute_date|crmDate}{else}{$row.start_action_offset}&nbsp;{$row.start_action_unit}{if $row.start_action_offset > 1}{ts}(s){/ts}{/if}&nbsp;{$row.start_action_condition}&nbsp;{$row.entityDate}{/if}</td>
-        <td class="crm-scheduleReminders-title">{$row.status}</td>
-        <td class="crm-scheduleReminders-is_repeat">{if $row.is_repeat eq 1}{ts}Yes{/ts}{else}{ts}No{/ts}{/if}&nbsp;</td>
-        <td id="row_{$row.id}_status" class="crm-scheduleReminders-is_active">{if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
-        <td>{$row.action|replace:'xx':$row.id}</td>
-        <td class="hiddenElement"></td>
-      </tr>
-    {/foreach}
+    {if $rows and is_array($rows)}
+      {foreach from=$rows item=row}
+        <tr id="action_schedule-{$row.id}" class="crm-entity {cycle values="odd-row,even-row"} {$row.class}{if NOT $row.is_active} disabled{/if}">
+          <td class="crm-scheduleReminders-title crm-editable" data-field="title">{$row.title}</td>
+          <td class="crm-scheduleReminders-value">{$row.entity} - {$row.value}</td>
+          <td class="crm-scheduleReminders-description">{if $row.absolute_date}{$row.absolute_date|crmDate}{else}{$row.start_action_offset}&nbsp;{$row.start_action_unit}{if $row.start_action_offset > 1}{ts}(s){/ts}{/if}&nbsp;{$row.start_action_condition}&nbsp;{$row.entityDate}{/if}</td>
+          <td class="crm-scheduleReminders-title">{$row.status}</td>
+          <td class="crm-scheduleReminders-is_repeat">{if $row.is_repeat eq 1}{ts}Yes{/ts}{else}{ts}No{/ts}{/if}&nbsp;</td>
+          <td id="row_{$row.id}_status" class="crm-scheduleReminders-is_active">{if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
+          <td>{$row.action|replace:'xx':$row.id}</td>
+          <td class="hiddenElement"></td>
+        </tr>
+      {/foreach}
+    {else}
+      <tr><td colspan="8">{ts}No Scheduled Reminders have been created.{/ts}</td></tr>
+    {/if}
   </table>
 {/strip}
 
index dfb08bee8ae95504996cf33276b947bbcaee7a67..a8f519bb9db534f701e89f25acaf6b28a8f42642 100644 (file)
@@ -29,6 +29,8 @@
 {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}
@@ -45,8 +47,8 @@
 {else}
     <div class="messages status no-popup">
       <div class="icon inform-icon"></div>
-        {capture assign=crmURL}{crmURL p='civicrm/admin/scheduleReminders' q="action=add&reset=1"}{/capture}
-        {ts 1=$crmURL}There are no Scheduled Reminders configured. You can <a href='%1'>add one</a>.{/ts}
+        {capture assign=crmURL}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}
     </div>
 {/if}
 {/if}
index edf04537ae577d2a9eb7b9e7d2b61fd97cac706a..0259a9068071ebd2b30850451d1e40a418c37599 100644 (file)
@@ -98,8 +98,8 @@
         CRM.reloadChangeLogTab();
       }
       // Refresh tab contents - Simple logging
-      else if ($('#Change_Log div').length) {
-        $('#Change_Log').load($("#tab_log a").attr('href'));
+      else if ($('#changeLog').closest('.ui-tabs-panel').data('civicrmCrmSnippet')) {
+        $('#changeLog').closest('.ui-tabs-panel').crmSnippet('destroy');
       }
     }
     else {
index 6146484d31113670ae823eb61f8fff3232da333b..27eef2bc6dff3f605d4cc80deff86882b7b06404 100644 (file)
           </a>
         </li>
         {foreach from=$allTabs key=tabName item=tabValue}
-          <li id="tab_{$tabValue.id}" class="crm-tab-button crm-count-{$tabValue.count}{if isset($tabValue.class)} {$tabValue.class}{/if}">
+          <li id="tab_{$tabValue.id}" class="crm-tab-button ui-corner-all crm-count-{$tabValue.count}{if isset($tabValue.class)} {$tabValue.class}{/if}">
             <a href="{$tabValue.url}" title="{$tabValue.title}">
               <span> </span> {$tabValue.title}
               <em>{$tabValue.count}</em>
index 96c1076d249cbfab9e333abc97153880c370fa40..422471151837d2f0c32e1fb9e75d0e492759b084 100755 (executable)
       </table>
       {include file="CRM/Contact/Form/Task/EmailCommon.tpl" upload=1 noAttach=1}
     </fieldset>
-  {/if}
 
-  <div class="crm-submit-buttons">
-    {include file="CRM/common/formButtons.tpl" location="bottom"}</div>
-</div>
-{/if}
-{include file="CRM/common/showHideByFieldValue.tpl"
-trigger_field_id    = "is_repeat"
-trigger_value       = "true"
-target_element_id   = "repeatFields"
-target_element_type = "table-row"
-field_type          = "radio"
-invert              = "false"
-}
-
-{include file="CRM/common/showHideByFieldValue.tpl"
-trigger_field_id    ="recipient"
-trigger_value       = 'manual'
-target_element_id   ="recipientManual"
-target_element_type ="table-row"
-field_type          ="select"
-invert              = 0
-}
-
-{include file="CRM/common/showHideByFieldValue.tpl"
-trigger_field_id    ="recipient"
-trigger_value       = 'group'
-target_element_id   ="recipientGroup"
-target_element_type ="table-row"
-field_type          ="select"
-invert              = 0
-}
-
-{literal}
-<script type='text/javascript'>
-  cj(function() {
-    populateRecipient();
-    cj('#recipient').click( function( ) {
-      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);
-          }
-        }
-      );
-      cj("#recipientList").show();
-    } else {
-      cj("#recipientList").hide();
+    {include file="CRM/common/showHideByFieldValue.tpl"
+    trigger_field_id    = "is_repeat"
+    trigger_value       = "true"
+    target_element_id   = "repeatFields"
+    target_element_type = "table-row"
+    field_type          = "radio"
+    invert              = "false"
+    }
+
+    {include file="CRM/common/showHideByFieldValue.tpl"
+    trigger_field_id    ="recipient"
+    trigger_value       = 'manual'
+    target_element_id   ="recipientManual"
+    target_element_type ="table-row"
+    field_type          ="select"
+    invert              = 0
     }
-  }
 
-  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();
+    {include file="CRM/common/showHideByFieldValue.tpl"
+    trigger_field_id    ="recipient"
+    trigger_value       = 'group'
+    target_element_id   ="recipientGroup"
+    target_element_type ="table-row"
+    field_type          ="select"
+    invert              = 0
     }
-  });
 
-</script>
-{/literal}
+  {literal}
+    <script type='text/javascript'>
+      cj(function() {
+        populateRecipient();
+        cj('#recipient').click( function( ) {
+          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);
+              }
+            }
+          );
+          cj("#recipientList").show();
+        } else {
+          cj("#recipientList").hide();
+        }
+      }
+
+      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();
+        }
+      });
 
+    </script>
+  {/literal}
+  {/if}
+  <div class="crm-submit-buttons">
+    {include file="CRM/common/formButtons.tpl" location="bottom"}</div>
+</div>
+{/if}
index 56cdcab228788e1ad2c3abafec3eec5cb301cb1f..7e2543a3ca70319c024860127bb6282f685b8c38 100644 (file)
@@ -1,4 +1,9 @@
 // https://civicrm.org/licensing
+/**
+ * By default this simply loads tabs via ajax CRM.loadPage method
+ * Tabs with class 'ajaxForm' will use CRM.loadForm instead, suitable for most forms
+ * Tabs with class 'livePage' will get popup action links, suitable for crud tables
+ */
 cj(function($) {
   var tabSettings = CRM.tabSettings || {};
   tabSettings.active = tabSettings.active ? $('#tab_' + tabSettings.active).prevAll().length : 0;
@@ -24,6 +29,23 @@ cj(function($) {
             })
           });
         }
+        if (ui.tab.hasClass('livePage')) {
+          ui.panel
+            .off('click.crmLivePage')
+            .on('click.crmLivePage', 'a.button, a.action-item', function() {
+              // only follow real links not javascript buttons
+              if ($(this).attr('href') === '#' || $(this).attr('onclick')) {
+                return;
+              }
+              CRM.loadForm($(this).attr('href'), {
+                openInline: 'a:not([href="#"])'
+              }).on('crmFormSuccess', function(e, data) {
+                  // Refresh when form completes
+                  ui.panel.crmSnippet('refresh');
+                });
+              return false;
+            });
+        }
         CRM[method]($('a', ui.tab).attr('href'), params);
       }
       e.preventDefault();