Confirm pop up called only for the core tabs of the manage event and cascade changes...
authorunknown <priyanka.karan26@gmail.com>
Tue, 16 Sep 2014 15:50:24 +0000 (16:50 +0100)
committerdeepak-srivastava <deepak.srivastava.0303@gmail.com>
Fri, 3 Oct 2014 09:08:26 +0000 (10:08 +0100)
CRM/Core/Page/AJAX/RecurringEntity.php
CRM/Event/BAO/Event.php
templates/CRM/Event/Form/ManageEvent/ConfirmRepeatMode.tpl

index eb81cad5a650d06a73e51ace7c91de1c6fcc3b11..a5e78c91cb9296fa5b7616288517881d84a4848b 100644 (file)
 class CRM_Core_Page_AJAX_RecurringEntity {
   
   public static function updateMode() {
-    if(CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST)){
+    if(CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST) && CRM_Utils_Array::value('entityTable', $_REQUEST)){
+      
       $finalResult = array();
       $mode = CRM_Utils_Type::escape($_REQUEST['mode'], 'Integer');
       $entityId = CRM_Utils_Type::escape($_REQUEST['entityId'], 'Integer');
+      $entityTable = CRM_Utils_Type::escape($_REQUEST['entityTable'], 'String');
 
-      $sql = "UPDATE
-        civicrm_recurring_entity
-        SET mode = %1
-        WHERE entity_id = %2 AND entity_table = 'civicrm_event'";
-      $params = array(
-        1 => array($mode, 'Integer'),          
-        2 => array($entityId, 'Integer')
-      );
-      CRM_Core_DAO::executeQuery($sql, $params);
+      if(CRM_Utils_Array::value('linkedEntityTable', $_REQUEST)){
+        $result = array();
+        $result = CRM_Event_BAO_Event::updateModeRecurringEntityForEvent($entityId, $_REQUEST['linkedEntityTable']);
+      }
+
+      $dao = new CRM_Core_DAO_RecurringEntity();
+      if(!empty($result)){
+        $dao->entity_id = $result['entityId'];
+        $dao->entityTable = $result['entityTable'];
+      }else{
+        $dao->entity_id = $entityId;
+        $dao->entityTable = $entityTable;
+      }
+      $dao->find(TRUE);
+      $dao->mode = $mode;
+      $dao->save();
       $finalResult['status'] = 'Done';
     }
     echo json_encode($finalResult);
index e56c286297ece9f56da2d8ed85d1f058646f5ba1..8b31dc0d1bb20582eb8753f3b7ceab213da4bf2e 100644 (file)
@@ -2200,5 +2200,49 @@ LEFT  JOIN  civicrm_price_field_value value ON ( value.id = lineItem.price_field
     }
     return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
   }
+  
+  /**
+   * Update mode column in civicrm_recurring_entity table for event related tabs
+   * 
+   * @params int $entityId event id
+   * @params string $linkedEntityTable Linked entity table name for this event
+   * @return array
+   */
+  public static function updateModeRecurringEntityForEvent($entityId, $linkedEntityTable){
+    $result = array();
+    if( $entityId && $linkedEntityTable ){
+      switch ($linkedEntityTable) {
+          case 'civicrm_tell_friend':
+            $params = array(
+                        'entity_id' => $entityId,
+                        'entity_table' => 'civicrm_event'
+                      );
+            $defaults = array();
+            CRM_Core_DAO::commonRetrieve('CRM_Friend_DAO_Friend', $params, $defaults);
+            if(CRM_Utils_Array::value('id', $defaults)){
+              $result['entityId'] = $defaults['id'];
+              $result['entityTable'] = 'civicrm_tell_friend';
+            }
+            break;
+
+          case 'civicrm_pcp_block':
+            $params = array(
+                        'entity_id' => $entityId,
+                        'entity_table' => 'civicrm_event'
+                      );
+            $defaults = array();
+            CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $defaults);
+            if(CRM_Utils_Array::value('id', $defaults)){
+              $result['entityId'] = $defaults['id'];
+              $result['entityTable'] = 'civicrm_pcp_block';
+            }
+            break;
+
+          default:
+            break;
+        }
+      } 
+      return $result;
+    }
 }
 
index dd2fe864fd39ab6841f059da696b312291072eba..d10c44e262755c184ce10da5a51a88388110ee0d 100644 (file)
 {literal}
 <script>
   CRM.$(function($) {
+    //Tab and table mapper
+    var mapper = {'CRM_Event_Form_ManageEvent_EventInfo': 'civicrm_event',
+                'CRM_Event_Form_ManageEvent_Location': 'civicrm_location',
+                'CRM_Event_Form_ManageEvent_Fee': 'civicrm_fee',
+                'CRM_Event_Form_ManageEvent_Registration': 'civicrm_registration',
+                'CRM_Friend_Form_Event': 'civicrm_tell_friend',
+                'CRM_PCP_Form_Event': 'civicrm_pcp_block'
+                };
+    //var findTellAFriend = false;
+    var form = '';
     $('#crm-main-content-wrapper').on('click', 'div.crm-submit-buttons span.crm-button input[value="Save"], div.crm-submit-buttons span.crm-button input[value="Save and Done"]', function() {
-      $("#repeat-mode-dailog").dialog({
-        title: 'How does this change affect other repeating events in the set?',
-        modal: true,
-        width: '650',
-        buttons: {
-          Cancel: function() { //cancel
-            $( this ).dialog( "close" );
-          }
+        form = $(this).parents('form:first').attr('class');
+        if( form != "" && mapper.hasOwnProperty(form)){
+/*            var re = new RegExp("^CRM_Friend_", "i");
+            var match = re.test(form);
+            if (match == true){
+                findTellAFriend = true;
+            }else{
+                findTellAFriend = false;
+            }
+*/
+          $("#repeat-mode-dailog").dialog({
+            title: 'How does this change affect other repeating events in the set?',
+            modal: true,
+            width: '650',
+            buttons: {
+              Cancel: function() { //cancel
+                $( this ).dialog( "close" );
+              }
+            }
+          }).dialog('open');
+          return false;
         }
-      }).dialog('open');
-      return false;
     }); 
 
     $(".only-this-event").click(function(){
     cj(".all-events").click(function(){
       updateMode(3);
     });
-  
+    
     function updateMode(mode) {
       var eventID = {/literal}{$id}{literal};
-      if (eventID != "" && mode) {
+      if (eventID != "" && mode && form != "") {
         var ajaxurl = CRM.url("civicrm/ajax/recurringentity/update-mode");
-        var data    = {mode: mode, entityId: eventID};
+        var data    = {mode: mode, entityId: eventID, entityTable:'civicrm_event', linkedEntityTable:mapper[form]};
         $.ajax({
           dataType: "json",
           data: data,