CRM-13863 - Ajax event tabs improvements - update 'disabled' tab class, etc.
authorColeman Watts <coleman@civicrm.org>
Mon, 6 Jan 2014 04:55:41 +0000 (20:55 -0800)
committerColeman Watts <coleman@civicrm.org>
Mon, 6 Jan 2014 19:14:26 +0000 (11:14 -0800)
15 files changed:
CRM/Core/QuickForm/Action/Display.php
CRM/Event/Form/ManageEvent/EventInfo.php
CRM/Event/Form/ManageEvent/Fee.php
CRM/Event/Form/ManageEvent/Location.php
CRM/Event/Form/ManageEvent/Registration.php
CRM/Event/Form/ManageEvent/ScheduleReminders.php
CRM/Event/Form/ManageEvent/TabHeader.php
CRM/Event/Page/ManageEvent.php
CRM/Friend/Form/Event.php
CRM/PCP/Form/Event.php
js/Common.js
templates/CRM/Campaign/Form/addCampaignToComponent.tpl
templates/CRM/Event/Form/ManageEvent/EventInfo.tpl
templates/CRM/Event/Form/ManageEvent/Tab.tpl
templates/CRM/common/TabHeader.js

index 832b617d7977db4d1e8dc4c3de290d0b092571d5..e7e51456dfc99bd18018d5120ca0466dbd07343d 100644 (file)
@@ -157,9 +157,10 @@ class CRM_Core_QuickForm_Action_Display extends CRM_Core_QuickForm_Action {
     }
 
     if ($controller->_QFResponseType == 'json') {
-      $response = array(
-        'content' => $html,
-      );
+      $response = array('content' => $html);
+      if (!empty($page->ajaxResponse)) {
+        $response += $page->ajaxResponse;
+      }
       if (!empty($form['errors'])) {
         $response['status'] = 'form_error';
         $response['errors'] = $form['errors'];
index ec5ecdf6b5c18602c3217d5dca6edd543623843e..2539671f40f2d56663e0efa4d2f92d0d3e044cdc 100644 (file)
@@ -181,10 +181,7 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent {
         CRM_Core_Session::setStatus(ts('If you find that you are creating multiple events with similar settings, you may want to use the <a href="%1">Event Templates</a> feature to streamline your workflow.', array(1 => $url)), ts('Tip'), 'info');
       }
       if (!CRM_Utils_System::isNull($eventTemplates)) {
-        $this->add('select', 'template_id', ts('From Template'), array(
-          '' => ts('- select -')) + $eventTemplates,
-          FALSE, array('onchange' => "reloadWindow(this.value);")
-        );
+        $this->add('select', 'template_id', ts('From Template'), array('' => ts('- select -')) + $eventTemplates);
       }
     }
 
index 21ce91016e04746fb55422472d7511c61945cc6a..136339739835a1b965aa809da815c5599d80727d 100644 (file)
@@ -796,6 +796,8 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent {
     
     CRM_Event_BAO_Event::add($params);
 
+    // Update tab "disabled" css class
+    $this->ajaxResponse['tabValid'] = !empty($params['is_monetary']);
     parent::endPostProcess();
   }
 
index eddddf145fdf5fae396836c151ddb3af3c50d550..c671ce0459ee192d69cbb2f33aa3e12233894221 100644 (file)
@@ -108,7 +108,7 @@ class CRM_Event_Form_ManageEvent_Location extends CRM_Event_Form_ManageEvent {
   function setDefaultValues() {
     $defaults = $this->_values;
 
-    if (CRM_Utils_Array::value('loc_block_id', $defaults)) {
+    if (!empty($defaults['loc_block_id'])) {
       $defaults['loc_event_id'] = $defaults['loc_block_id'];
       $countLocUsed = CRM_Event_BAO_Event::countEventsUsingLocBlockId($defaults['loc_block_id']);
       if ($countLocUsed > 1) {
@@ -302,6 +302,8 @@ class CRM_Event_Form_ManageEvent_Location extends CRM_Event_Form_ManageEvent {
     $params['id'] = $this->_id;
     CRM_Event_BAO_Event::add($params);
 
+    // Update tab "disabled" css class
+    $this->ajaxResponse['tabValid'] = TRUE;
     parent::endPostProcess();
   }
   //end of function
index 715544b09c0d53fec4fac33c64b24c9d08985203..d1f0189b4fdff2ffe5788551d08adf71a48e81fd 100644 (file)
@@ -696,7 +696,6 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent
    * @return void
    */
   public function postProcess() {
-    $params = array();
     $params = $this->exportValues();
 
     $params['id'] = $this->_id;
@@ -825,6 +824,9 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent
       }
     }
 
+    // Update tab "disabled" css class
+    $this->ajaxResponse['tabValid'] = !empty($params['is_online_registration']);
+
     parent::endPostProcess();
   }
   //end of function
index 58c400b9e89ee90dae9b29293c6848a0ef995c32..acbc2dcefa53589828bc80d0928b026c92fa0aed 100755 (executable)
@@ -87,6 +87,9 @@ class CRM_Event_Form_ManageEvent_ScheduleReminders extends CRM_Event_Form_Manage
         $reminderList = TRUE;
       }
       $this->assign('rows', $reminderList);
+
+      // Update tab "disabled" css class
+      $this->ajaxResponse['tabValid'] = !empty($reminderList) && is_array($reminderList);
     }
   }
 
index d591fc35a9830c64d86ef5a9f3cffb4ac114af6e..2de811aecaa95c0adba4b4b3db6308d805259175 100644 (file)
@@ -67,7 +67,7 @@ class CRM_Event_Form_ManageEvent_TabHeader {
     );
 
     $tabs = array(
-      'settings' => array('title' => ts('Info and Settings')) + $default,
+      'settings' => array('title' => ts('Info and Settings'), 'class' => 'ajaxForm livePage') + $default,
       'location' => array('title' => ts('Event Location')) + $default,
       'fee' => array('title' => ts('Fees')) + $default,
       'registration' => array('title' => ts('Online Registration')) + $default,
@@ -89,7 +89,7 @@ class CRM_Event_Form_ManageEvent_TabHeader {
     if ($eventID) {
       // disable tabs based on their configuration status 
       $sql = "
-SELECT     e.loc_block_id as is_location, e.is_online_registration, e.is_monetary, taf.is_active, pcp.id as is_pcp, sch.id as is_reminder
+SELECT     e.loc_block_id as is_location, e.is_online_registration, e.is_monetary, taf.is_active, pcp.is_active as is_pcp, sch.id as is_reminder
 FROM       civicrm_event e
 LEFT JOIN  civicrm_tell_friend taf ON ( taf.entity_table = 'civicrm_event' AND taf.entity_id = e.id )
 LEFT JOIN  civicrm_pcp_block pcp   ON ( pcp.entity_table = 'civicrm_event' AND pcp.entity_id = e.id )
index a52317e577c50b3cb46cd5b0578bfd4aaf8ecb4c..c2b815497cee7c40422237d80db3c445c5839c1b 100644 (file)
@@ -228,7 +228,6 @@ class CRM_Event_Page_ManageEvent extends CRM_Core_Page {
    * @return void
    */
   function browse() {
-    CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
     $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter',
       'String',
       $this
index dec3b68e6f0057fb5abd7364a0f3dc3ba53d132f..4a1c03296d5d66dbe9abfbae1bdd2f6a92aa1acf 100644 (file)
@@ -126,6 +126,9 @@ class CRM_Friend_Form_Event extends CRM_Event_Form_ManageEvent {
 
     CRM_Friend_BAO_Friend::addTellAFriend($formValues);
 
+    // Update tab "disabled" css class
+    $this->ajaxResponse['tabValid'] = !empty($formValues['tf_is_active']);
+
     parent::endPostProcess();
   }
 
index e3c88454b53b4def94730b4f15437ce44c398488..23ffdde5d87175ec3a30d4b030313df51b484c96 100644 (file)
@@ -204,6 +204,9 @@ class CRM_PCP_Form_Event extends CRM_Event_Form_ManageEvent {
 
     $dao = CRM_PCP_BAO_PCP::add($params);
 
+    // Update tab "disabled" css class
+    $this->ajaxResponse['tabValid'] = !empty($params['is_active']);
+
     parent::endPostProcess();
   }
 
index 52f9c92faf3de4881e841e0ca5828790a16acfd1..9493cdcebb7edd31b1397ced6303f0c242dcd8aa 100644 (file)
@@ -848,7 +848,8 @@ CRM.validate = CRM.validate || {
         this.element.addClass('crm-container');
       }
       this._handleOrderLinks();
-      this.options.url ? this.refresh() : this.options.url = document.location.href;
+      // Set default if not supplied
+      this.options.url = this.options.url || document.location.href;
       this._originalUrl = this.options.url;
     },
     _onFailure: function(data) {
@@ -889,7 +890,7 @@ CRM.validate = CRM.validate || {
           return;
         }
         data.url = url;
-        that.element.html(data.content);
+        that.element.trigger('crmBeforeLoad', data).html(data.content);
         that._handleOrderLinks();
         that.element.trigger('crmLoad', data);
         that.options.crmForm && that.element.trigger('crmFormLoad', data);
@@ -930,7 +931,8 @@ CRM.validate = CRM.validate || {
         data.title && $(this).dialog('option', 'title', data.title);
       });
     }
-    return $(settings.target).crmSnippet(settings);
+    $(settings.target).crmSnippet(settings).crmSnippet('refresh');
+    return $(settings.target);
   };
 
   CRM.loadForm = function(url, options) {
@@ -945,7 +947,7 @@ CRM.validate = CRM.validate || {
         onCancel: function(event) {},
         onError: function(data) {
           var $el = $(this);
-          $el.html(data.content).trigger('crmLoad', data).trigger('crmFormLoad', data);
+          $el.html(data.content).trigger('crmLoad', data).trigger('crmFormLoad', data).trigger('crmFormError', data);
           if (typeof(data.errors) == 'object') {
             $.each(data.errors, function(formElement, msg) {
               $('[name="'+formElement+'"]', $el).crmError(msg);
index aaf99214a7af6283f427135e211176a4d155d9b9..79713ff537ed0c7c53d2c78a5736edffacb58a1f 100644 (file)
@@ -59,7 +59,8 @@
             <div class="status">
             {ts}There are currently no active Campaigns.{/ts}
             {if $campaignInfo.addCampaignURL}
-                {ts 1=$campaignInfo.addCampaignURL}If you want to associate this record with a campaign, you can <a href="%1">create a campaign here</a>.{/ts}
+              {capture assign="link"}href="{$campaignInfo.addCampaignURL}" class="action-item action-item-first"{/capture}
+              {ts 1=$link}If you want to associate this record with a campaign, you can <a %1>create a campaign here</a>.{/ts}
             {/if} {help id="id-campaign_id" file="CRM/Campaign/Form/addCampaignToComponent.hlp"}
             </div>
           {/if}
index 1e40f861d26a8da7d963bdfa22d346cfb65719d8..a94b6c9280be29998befca90310be8658ed3168b 100644 (file)
 </div>
 {literal}
 <script type="text/javascript">
-
-function reloadWindow(tempId) {
-
-   //ignore form navigation, CRM-6815
-   global_formNavigate = true;
-
-   //freeze the event type element
-   //when template form is loading.
-   cj( "#event_type_id" ).prop('disabled', true );
-
-   window.location += '&template_id=' + tempId;
-}
-
+  cj(function($) {
+    $('#template_id', '#EventInfo').change(function() {
+      $('#crm-main-content-wrapper')
+        .crmSnippet({url: CRM.url('civicrm/event/add', {action: 'add', reset: 1, template_id: $(this).val()})})
+        .crmSnippet('refresh');
+    })
+  });
 </script>
 {/literal}
 
index 4d659c01857e7590ff3b7c91e607bd907a256209..095cbcda0528febe4a66a8a12b4cdd6d440be0e8 100644 (file)
 
 {literal}
 <script>
-
-cj('body').click(function() {
-  cj('#crm-event-links-list').hide();
-  cj('#crm-participant-list').hide();
+cj(function($) {
+  $('body').click(function() {
+    $('#crm-event-links-list, #crm-participant-list').hide();
   });
 
-cj('#crm-event-links-link').click(function(event) {
-  cj('#crm-event-links-list').toggle();
-  cj('#crm-participant-list').hide();
-  event.stopPropagation();
-  return false;
-});
+  $('#crm-event-links-link').click(function(event) {
+    $('#crm-event-links-list').toggle();
+    $('#crm-participant-list').hide();
+    event.stopPropagation();
+    return false;
+  });
+  
+  $('#crm-participant-link').click(function(event) {
+    $('#crm-participant-list').toggle();
+    $('#crm-event-links-list').hide();
+    event.stopPropagation();
+    return false;
+  });
 
-cj('#crm-participant-link').click(function(event) {
-  cj('#crm-participant-list').toggle();
-  cj('#crm-event-links-list').hide();
-  event.stopPropagation();
-  return false;
+  // Update title dynamically
+  $('h1').each(function() {
+    var title = {/literal}{$title|json_encode}{literal};
+    $(this).html($(this).html().replace(title, '<span id="crm-event-name-page-title">' + title + '</span>'));
+  });
+  $('#crm-main-content-wrapper').on('keyup change', 'input#title', function() {
+    $('#crm-event-name-page-title').text($(this).val());
+  });
+  
+  $().crmAccordions();
 });
-
-cj().crmAccordions();
-
 </script>
 {/literal}
index 0209f4e2f33bdc6c1ad000acac02be0ff8ca799e..37fb70f2f5c8329dfa4ad4de51a197517fdae6ae 100644 (file)
@@ -47,11 +47,15 @@ cj(function($) {
             });
         }
         ui.panel
-          .off('crmLoad.tabCount')
-          .on('crmLoad.tabCount', function(e, data) {
+          .off('.tabInfo')
+          .on('crmLoad.tabInfo crmFormSuccess.tabInfo', function(e, data) {
             if (typeof(data.tabCount) !== 'undefined') {
               CRM.tabHeader.updateCount(ui.tab, data.tabCount);
             }
+            if (typeof(data.tabValid) !== 'undefined') {
+              var method = data.tabValid ? 'removeClass' : 'addClass';
+              ui.tab[method]('disabled');
+            }
           });
         CRM[method]($('a', ui.tab).attr('href'), params);
       }