{literal}
<script type="text/javascript">
CRM.$(function($) {
- var formName = {/literal}"{$form.formName}"{literal};
- $('#title').data('initial_value', $('#title').val());
- $('#_qf_' + formName + '_submit_save').click(function() {
+ var confirmed = false,
+ formName = {/literal}"{$form.formName}"{literal};
+ $('#_qf_' + formName + '_submit_next, #_qf_' + formName + '_submit_save').click(function() {
if ($('#is_navigation').prop('checked') && $('#parent_id').val() == '') {
var confirmMsg = {/literal}'{ts escape="js"}You have chosen to include this report in the Navigation Menu without selecting a Parent Menu item from the dropdown. This will add the report to the top level menu bar. Are you sure you want to continue?{/ts}'{literal}
return confirm(confirmMsg);
}
});
- $('#_qf_' + formName + '_submit_next').click(function() {
- if ($('#title').data('initial_value') == $('#title').val()) {
- var confirmMsg = {/literal}'{ts escape="js"}You are saving a copy of this report with the same report title. Are you sure you want to continue?{/ts}'{literal}
- return confirm(confirmMsg);
+ // Pop-up confirmation when clicking "Save a copy" (submit_next) or "Create Report" (submit_save)
+ var saveAction = $('#_qf_' + formName + '_submit_next').length ? 'next' : 'save';
+ $('#_qf_' + formName + '_submit_' + saveAction).click(function(e) {
+ if (!confirmed) {
+ var $button = $(this),
+ title = 'tr.crm-report-instanceForm-form-block-title',
+ description = 'tr.crm-report-instanceForm-form-block-description';
+ e.preventDefault();
+ e.stopImmediatePropagation();
+ CRM.confirm({
+ title: $(this).attr('value'),
+ message: '<table class="form-layout"><tr>' + $(title).html() + '</tr><tr>' + $(description).html() + '</tr></table>',
+ open: function() {
+ var $name = $('[name=title]', this);
+ if (saveAction == 'next') {
+ $name.val('' + $name.val() + ' ' + {/literal}'{ts escape='js'}(copy){/ts}'{literal})
+ }
+ }
+ })
+ .on('crmConfirm:yes', function() {
+ confirmed = true;
+ $('[name=title]', '#' + formName).val($('[name=title]', this).val());
+ $('[name=description]', '#' + formName).val($('[name=description]', this).val());
+ $button.click();
+ });
}
});
});