Commit cd96b0a9 authored by unknown's avatar unknown

Towards generalising comfirm box, postprocess delete function

parent a7ea18bf
......@@ -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');
}
}
......
......@@ -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(
......
......@@ -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
......
......@@ -330,3 +330,31 @@
{/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
......@@ -25,100 +25,77 @@
*}
<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
......@@ -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"}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment