From 59fa7f72b211ee65b0452c296be5c8d3467efca6 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 15 Oct 2014 17:54:25 +0100 Subject: [PATCH] Generalised cascade changes and preview dialog code --- templates/CRM/Core/Form/RecurringEntity.tpl | 212 ++++++++++-------- .../Form/ManageEvent/ConfirmRepeatMode.tpl | 38 ++-- 2 files changed, 132 insertions(+), 118 deletions(-) diff --git a/templates/CRM/Core/Form/RecurringEntity.tpl b/templates/CRM/Core/Form/RecurringEntity.tpl index 985f2b39e3..aac1e39472 100644 --- a/templates/CRM/Core/Form/RecurringEntity.tpl +++ b/templates/CRM/Core/Form/RecurringEntity.tpl @@ -222,120 +222,138 @@ unsavedChanges = true; }); - //If there are changes in repeat configuration enable save button + //If there are changes in repeat configuration, enable save button //Dialog for preview repeat Configuration dates cj('#preview-dialog').dialog({ autoOpen: false }); - cj('#_qf_Repeat_submit-top, #_qf_Repeat_submit-bottom, #_qf_Activity_upload-top, #_qf_Activity_upload-bottom').click( function (e) { - if (unsavedChanges) { - e.preventDefault(); - cj('#exclude_date_list option').attr('selected',true); - //Copy exclude dates - var dateTxt=[]; - cj('#exclude_date_list option:selected').each(function() { - dateTxt.push(cj(this).text()); - }); - var completeDateText = dateTxt.join(','); - cj('#copyExcludeDates').val(completeDateText); + function previewDialog () { + cj('#exclude_date_list option').attr('selected',true); + //Copy exclude dates + var dateTxt=[]; + cj('#exclude_date_list option:selected').each(function() { + dateTxt.push(cj(this).text()); + }); + var completeDateText = dateTxt.join(','); + cj('#copyExcludeDates').val(completeDateText); - cj('#generated_dates').html('').html('
{/literal}{ts escape='js'}Just a moment, generating dates{/ts}{literal}...
'); - cj('#preview-dialog').dialog('open'); - cj('#preview-dialog').dialog({ - title: 'Confirm event dates', - width: '650', - position: 'center', - //draggable: false, - buttons: { - Ok: function() { - cj(this).dialog( "close" ); - cj('form#Repeat, form#Activity').submit(); - }, - Cancel: function() { //cancel - cj(this).dialog( "close" ); + cj('#generated_dates').html('').html('
{/literal}{ts escape='js'}Just a moment, generating dates{/ts}{literal}...
'); + cj('#preview-dialog').dialog('open'); + cj('#preview-dialog').dialog({ + title: 'Confirm event dates', + width: '650', + position: 'center', + //draggable: false, + buttons: { + Ok: function() { + cj(this).dialog( "close" ); + cj('form#Repeat, form#Activity').submit(); + }, + Cancel: function() { //cancel + cj(this).dialog( "close" ); + } } + }); + var ajaxurl = CRM.url("civicrm/ajax/recurringentity/generate-preview"); + var entityID = parseInt('{/literal}{$currentEntityId}{literal}'); + var entityTable = '{/literal}{$entityTable}{literal}'; + if (entityID != "" && entityTable != "") { + ajaxurl += "?entity_id="+entityID+"&entity_table="+entityTable; } - }); - var ajaxurl = CRM.url("civicrm/ajax/recurringentity/generate-preview"); - var entityID = {/literal}{$currentEntityId}{literal}; - var entityTable = '{/literal}{$entityTable}{literal}'; - if (entityID != "" && entityTable != "") { - ajaxurl += "?entity_id="+entityID+"&entity_table="+entityTable; - } - var formData = cj('form').serializeArray(); - cj.ajax({ - dataType: "json", - type: "POST", - data: formData, - url: ajaxurl, - success: function (result) { - if (Object.keys(result).length > 0) { - var errors = []; - var participantData = []; - var html = 'Based on your repeat configuration here is the list of event dates, Do you wish to proceed creating events for these dates?
'; - var count = 1; - for(var i in result) { - if (i != 'errors') { - if (i == 'participantData') { - participantData = result.participantData; - break; - } - var start_date = result[i].start_date; - var end_date = result[i].end_date; + var formData = cj('form').serializeArray(); + cj.ajax({ + dataType: "json", + type: "POST", + data: formData, + url: ajaxurl, + success: function (result) { + if (Object.keys(result).length > 0) { + var errors = []; + var participantData = []; + var html = 'Based on your repeat configuration here is the list of event dates, Do you wish to proceed creating events for these dates?
Sr NoStart dateEnd date
'; + var count = 1; + for(var i in result) { + if (i != 'errors') { + if (i == 'participantData') { + participantData = result.participantData; + break; + } + var start_date = result[i].start_date; + var end_date = result[i].end_date; - var end_date_text = ''; - if (end_date !== undefined) { - end_date_text = ''; + var end_date_text = ''; + if (end_date !== undefined) { + end_date_text = ''; + } + html += ''+end_date_text+''; + count = count + 1; + } else { + errors = result.errors; } - html += ''+end_date_text+''; - count = count + 1; - } else { - errors = result.errors; } - } - html += '
Sr NoStart dateEnd date
'+end_date+''+end_date+'
'+count+''+start_date+'
'+count+''+start_date+'
'; - var warningHtml = ''; - if (Object.keys(participantData).length > 0) { - warningHtml += '
 There are registrations for the repeating events already present in the set, continuing with the process would unlink them and repeating events without registration would be trashed.
'; - for (var id in participantData) { - for(var data in participantData[id]) { - warningHtml += ''; + html += '
Event IDEventParticipant Count
'+id+' '+data+''+participantData[id][data]+'
'; + var warningHtml = ''; + if (Object.keys(participantData).length > 0) { + warningHtml += '
 There are registrations for the repeating events already present in the set, continuing with the process would unlink them and repeating events without registration would be trashed.
'; + for (var id in participantData) { + for(var data in participantData[id]) { + warningHtml += ''; + } } + warningHtml += '
Event IDEventParticipant Count
'+id+' '+data+''+participantData[id][data]+'

'; } - warningHtml += '
'; - } - if (errors.length > 0) { - html = ''; - for (var j = 0; j < errors.length; j++) { - html += '* ' + errors[j] + '
'; + if (errors.length > 0) { + html = ''; + for (var j = 0; j < errors.length; j++) { + html += '* ' + errors[j] + '
'; + } + } + if (warningHtml != "") { + cj('#generated_dates').append(warningHtml).append(html); + } else { + cj('#generated_dates').html(html); + } + if (end_date_text == "") { + cj('#th-end-date').hide(); + } + if (cj("#preview-dialog").height() >= 300) { + cj('#preview-dialog').css('height', '300'); + cj('#preview-dialog').css('overflow-y', 'auto'); } - } - if (warningHtml != "") { - cj('#generated_dates').append(warningHtml).append(html); } else { - cj('#generated_dates').html(html); + cj('div.ui-dialog-buttonset button span:contains(Ok)').hide(); + cj('#generated_dates').append("Sorry, no dates could be generated for the given criteria!"); } - if (end_date_text == "") { - cj('#th-end-date').hide(); - } - if (cj("#preview-dialog").height() >= 300) { - cj('#preview-dialog').css('height', '300'); - cj('#preview-dialog').css('overflow-y', 'auto'); - } - } else { - cj('div.ui-dialog-buttonset button span:contains(Ok)').hide(); - cj('#generated_dates').append("Sorry, no dates could be generated for the given criteria!"); + }, + complete: function() { + cj('div.crm-loading-element').hide(); } - }, - complete: function() { - cj('div.crm-loading-element').hide(); + }); + return false; + } + + cj('#_qf_Repeat_submit-top, #_qf_Repeat_submit-bottom').click( function () { + return previewDialog(); + }); + + cj('#_qf_Activity_upload-top, #_qf_Activity_upload-bottom').click( function () { + //Process this only when repeat is configured. We need to do this test here as there is a common save for activity. + var isRepeatConfigured = '{/literal}{$scheduleReminderId}{literal}'; + if (isRepeatConfigured) { + if (unsavedChanges) { + //Set this variable to decide which dialog box to show + cj.data( document.body, "preview-dialog", true ); + return previewDialog(); } - }); - return false; - } + else { + cj.data( document.body, "preview-dialog", false ); + return false; + } + } else { - alert("No changes to save"); - return false; + if (unsavedChanges) { + return previewDialog(); + } } - }); + }); //Build Summary var finalSummary = ''; diff --git a/templates/CRM/Event/Form/ManageEvent/ConfirmRepeatMode.tpl b/templates/CRM/Event/Form/ManageEvent/ConfirmRepeatMode.tpl index d4bce549cf..dd5aadc1f0 100644 --- a/templates/CRM/Event/Form/ManageEvent/ConfirmRepeatMode.tpl +++ b/templates/CRM/Event/Form/ManageEvent/ConfirmRepeatMode.tpl @@ -60,38 +60,34 @@ 'CRM_PCP_Form_Event': 'civicrm_pcp_block', 'CRM_Activity_Form_Activity': '' }; + function cascadeChangesDialog() { + $("#recurring-dialog").dialog({ + title: 'How does this change affect other repeating entities in the set?', + modal: true, + width: '650', + buttons: { + Cancel: function() { //cancel + $( this ).dialog( "close" ); + } + } + }).dialog('open'); + } 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: 'How does this change affect other repeating entities in the set?', - modal: true, - width: '650', - buttons: { - Cancel: function() { //cancel - $( this ).dialog( "close" ); - } - } - }).dialog('open'); + cascadeChangesDialog(); return false; } }); - $("#_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: 'How does this change affect other repeating entities in the set?', - modal: true, - width: '650', - buttons: { - Cancel: function() { //cancel - $( this ).dialog( "close" ); - } - } - }).dialog('open'); + var showPreviewDialog = $.data( document.body, "preview-dialog"); + if (showPreviewDialog == false) { + cascadeChangesDialog(); + } return false; } }); -- 2.25.1