Towards generalising comfirm box, postprocess delete function
authorunknown <priyanka.karan26@gmail.com>
Wed, 8 Oct 2014 20:41:15 +0000 (21:41 +0100)
committerunknown <priyanka.karan26@gmail.com>
Wed, 8 Oct 2014 20:41:15 +0000 (21:41 +0100)
CRM/Activity/Form/Activity.php
CRM/Core/BAO/RecurringEntity.php
CRM/Core/Form/RecurringEntity.php
templates/CRM/Activity/Form/Activity.tpl
templates/CRM/Event/Form/ManageEvent/ConfirmRepeatMode.tpl
templates/CRM/Event/Form/ManageEvent/Tab.tpl

index 2de952d77fa72b7356e25565f3bfaf7362740ad3..cedcdaf8207f8b8918dab9db12cd0a2f6f169340 100644 (file)
@@ -505,6 +505,8 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
     }
     
     if ($this->_action & CRM_Core_Action::UPDATE) {
+      $mapper = array('CRM_Activity_Form_Activity' => '');
+      $this->assign('mapper', json_encode($mapper));
       CRM_Core_Form_RecurringEntity::preProcess('activity');
     }
   }
index cf5e88d945f5dd7b25a88b85ba31d0f0f8b91895..be7fff6abb214caa8b46444ebea8305f66f56587 100644 (file)
@@ -51,6 +51,20 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
   public $isRecurringEntityRecord = TRUE;
 
   protected $recursion = NULL;
+  
+  static $_recurringEntityHelper = 
+    array(
+      'civicrm_event' => array(
+      'helper_class' => 'CRM_Event_BAO_Event',
+      'delete_func' => 'del',
+      'count_func' => ''
+      ),
+      'civicrm_activity' => array(
+      'helper_class' => 'CRM_Activity_BAO_Activity',
+      'delete_func' => 'del',
+      'count_func' => ''
+      ) 
+    ); 
 
   static $_tableDAOMapper = 
     array(
index ea1578b671d262344ae95f96f08ce1711a933c86..340ff8426110579b9f143c809d8cbc6a7bdc2c79 100644 (file)
@@ -360,6 +360,7 @@ class CRM_Core_Form_RecurringEntity {
       //Delete relations if any from recurring entity tables before inserting new relations for this entity id
       if ($params['entity_id']) {
         $getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], 'civicrm_'.$type, TRUE);
+        
         if ($type == 'event') {
           $participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getRelatedEntities);
           //Check if participants exists for events
index 613b811a9120c5df4693da07ac931bad5291f0a2..bfcb5eb37df222dc86bc1715544a537696600a41 100644 (file)
   {/if}
   </div>{* end of form block*}
 {/if} {* end of snippet if*}
+{literal}
+<script type="text/javascript">
+  CRM.$(function($) {
+    var mapper = {'CRM_Activity_Form_Activity': ''};
+    var form = '';
+    $('#_qf_Activity_upload-top, #_qf_Activity_upload-bottom').click( function () {      
+        form = $(this).parents('form:first').attr('class');
+        if (form != "" && mapper.hasOwnProperty(form)) {
+          $("#recurring-dialog").dialog({
+            title: ts('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;
+        }
+    }); 
+  });
+</script>
+{/literal}
+{foreach from=$mapper key=k item=item}
+  {$k} {$item}
+{/foreach}
+{include file="CRM/Event/Form/ManageEvent/ConfirmRepeatMode.tpl" entityType="activity" entityID=$activityId entityTable="civicrm_activity" mapper=$mapper}
\ No newline at end of file
index b38d3ff429f64ace85d3e3097152e14624526671..7a9955b7858b861c4cbf0ccea27b6d4a8ec41bc0 100644 (file)
 *}
 
 <div id="recurring-dialog" class="hide-block">
-    {ts}How would you like this change to affect other events in the repetition set?{/ts}<br/><br/>
+    {ts}How would you like this change to affect other {$entityType}s in the repetition set?{/ts}<br/><br/>
     <div class="show-block">
         <div class="recurring-dialog-inner-wrapper">
             <div class="recurring-dialog-inner-left">
-                <button class="recurring-dialog-button only-this-event">{ts}Only this Event{/ts}</button>
+                <button class="recurring-dialog-button only-this-event">{ts}Only this {$entityType}{/ts}</button>
             </div>
-          <div class="recurring-dialog-inner-right">{ts}All other events in the series will remain same.{/ts}</div>
+          <div class="recurring-dialog-inner-right">{ts}All other {$entityType}s in the series will remain same.{/ts}</div>
         </div>
         <div class="recurring-dialog-inner-wrapper">
             <div class="recurring-dialog-inner-left">
-                <button class="recurring-dialog-button this-and-all-following-event">{ts}This and Following Events{/ts}</button>
+                <button class="recurring-dialog-button this-and-all-following-event">{ts}This and Following {$entityType}s{/ts}</button>
             </div>
-            <div class="recurring-dialog-inner-right">{ts}Change applies to this and all the following events.{/ts}</div>
+            <div class="recurring-dialog-inner-right">{ts}Change applies to this and all the following {$entityType}s.{/ts}</div>
         </div>
         <div class="recurring-dialog-inner-wrapper">
             <div class="recurring-dialog-inner-left">
-                <button class="recurring-dialog-button all-events">{ts}All the Events{/ts}</button>
+                <button class="recurring-dialog-button all-events">{ts}All the {$entityType}s{/ts}</button>
             </div>
-            <div class="recurring-dialog-inner-right">{ts}Change applies to all the events in the series.{/ts}</div>
+            <div class="recurring-dialog-inner-right">{ts}Change applies to all the {$entityType}s in the series.{/ts}</div>
         </div>
     </div>
 </div>
 <input type="hidden" value="" name="isRepeatingEvent" id="is-repeating-event"/>
-{if $isRepeat eq 'repeat'}
 {literal}
-<script>
-  CRM.$(function($) {
-    //Tab and table mapper
-    var mapper = {'CRM_Event_Form_ManageEvent_EventInfo': '',
-                'CRM_Event_Form_ManageEvent_Location': '',
-                'CRM_Event_Form_ManageEvent_Fee': '',
-                'CRM_Event_Form_ManageEvent_Registration': '',
-                'CRM_Friend_Form_Event': 'civicrm_tell_friend',
-                'CRM_PCP_Form_Event': 'civicrm_pcp_block'
-                };
-    
-    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() {
-        form = $(this).parents('form:first').attr('class');
-        if (form != "" && mapper.hasOwnProperty(form)) {
-          $("#recurring-dialog").dialog({
-            title: ts('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;
-        }
-    }); 
+  <script type="text/javascript">
+    CRM.$(function($) {  
+      var form = '';
+      form = $(this).parents('form:first').attr('class');
+      
+      $(".only-this-event").click(function() {
+        updateMode(1);
+      });
 
-    $(".only-this-event").click(function() {
-      updateMode(1);
-    });
-  
-    cj(".this-and-all-following-event").click(function() {
-      updateMode(2);
-    });
-  
-    cj(".all-events").click(function() {
-      updateMode(3);
-    });
-    
-    function updateMode(mode) {
-      var eventID = {/literal}{$id}{literal};
-      if (eventID != "" && mode && form != "") {
-        var ajaxurl = CRM.url("civicrm/ajax/recurringentity/update-mode");
-        var data    = {mode: mode, entityId: eventID, entityTable:'civicrm_event', linkedEntityTable:mapper[form]};
-        $.ajax({
-          dataType: "json",
-          data: data,
-          url:  ajaxurl,
-          success: function (result) {
-            if (result.status != "" && result.status == 'Done') {
-              $("#recurring-dialog").dialog('close');
-              $('#mainTabContainer div:visible Form').submit();
-            } else if (result.status != "" && result.status == 'Error') {
-              var errorBox = confirm(ts("Mode could not be updated, save only this event?"));
-              if (errorBox == true) {
+      $(".this-and-all-following-event").click(function() {
+        updateMode(2);
+      });
+
+      $(".all-events").click(function() {
+        updateMode(3);
+      });
+      
+      function updateMode(mode) {
+        var entityID = parseInt('{/literal}{$entityID}{literal}');
+        var entityTable = '{/literal}{$entityTable}{literal}';
+        var testmapper = '{/literal}$mapper['{literal}+form+{/literal}']{literal}';
+        alert(testmapper);
+        if (entityID != "" && mode && form != "" && entityTable !="") {
+          var ajaxurl = CRM.url("civicrm/ajax/recurringentity/update-mode");
+          var data    = {mode: mode, entityId: entityID, entityTable: entityTable, linkedEntityTable:'{/literal}$mapper['{literal}+form+{/literal}']{literal}'};
+          $.ajax({
+            dataType: "json",
+            data: data,
+            url:  ajaxurl,
+            success: function (result) {
+              if (result.status != "" && result.status == 'Done') {
                 $("#recurring-dialog").dialog('close');
                 $('#mainTabContainer div:visible Form').submit();
-              } else {
-                $("#recurring-dialog").dialog('close');
-                return false;
+              } else if (result.status != "" && result.status == 'Error') {
+                var errorBox = confirm(ts("Mode could not be updated, save only this event?"));
+                if (errorBox == true) {
+                  $("#recurring-dialog").dialog('close');
+                  $('#mainTabContainer div:visible Form').submit();
+                } else {
+                  $("#recurring-dialog").dialog('close');
+                  return false;
+                }
               }
             }
-          }
-        });
-      }
-    }
-  });
-</script>
-{/literal}
-{/if}
+          });
+        }
+      }  
+    });
+  </script>
+  {/literal}
\ No newline at end of file
index eca262bef7a3a867c3b97a7951e2f4e8180a54a4..36b790fbe73e9afa23f20d5fac6b1745e4652d84 100644 (file)
@@ -107,4 +107,4 @@ CRM.$(function($) {
 </script>
 {/literal}
 
-{include file="CRM/Event/Form/ManageEvent/ConfirmRepeatMode.tpl"}
+{include file="CRM/Event/Form/ManageEvent/ConfirmRepeatMode.tpl" entityType="event"}