/**
* @see https://wiki.civicrm.org/confluence/display/CRMDOC/Notification+Reference
*/
- CRM.confirm = function (buttons, options, cancelLabel) {
- var dialog, callbacks = {};
- cancelLabel = cancelLabel || ts('Cancel');
- var settings = {
+ CRM.confirm = function (options) {
+ var dialog, settings = {
title: ts('Confirm Action'),
message: ts('Are you sure you want to continue?'),
- resizable: false,
- modal: true,
width: 'auto',
+ modal: true,
+ dialogClass: 'crm-container crm-confirm',
close: function () {
- $(dialog).dialog('destroy').remove();
+ $(this).dialog('destroy').remove();
},
- buttons: {}
- };
-
- settings.buttons[cancelLabel] = function () {
- dialog.trigger('crmConfirmNo').dialog('close');
+ options: {
+ no: ts('Cancel'),
+ yes: ts('Continue')
+ }
};
- options = options || {};
- $.extend(settings, options);
- if ($.isFunction(buttons)) {
- callbacks[ts('Continue')] = buttons;
- }
- else if (_.isString(buttons) || !buttons) {
- callbacks[buttons || ts('Continue')] = function() {};
+ $.extend(settings, ($.isFunction(options) ? arguments[1] : options) || {});
+ if (!settings.buttons && $.isPlainObject(settings.options)) {
+ settings.buttons = [];
+ $.each(settings.options, function(key, label) {
+ settings.buttons.push({
+ text: label,
+ click: function() {
+ var event = $.Event('crmConfirm:' + key);
+ $(this).trigger(event);
+ if (!event.isDefaultPrevented()) {
+ dialog.dialog('close');
+ }
+ }
+ });
+ });
}
- else {
- callbacks = buttons;
+ dialog = $('<div class="crm-confirm-dialog"></div>').html(settings.message);
+ delete settings.options;
+ delete settings.message;
+ if ($.isFunction(options)) {
+ dialog.on('crmConfirm:yes', options);
}
- $.each(callbacks, function (label, callback) {
- settings.buttons[label] = function () {
- dialog.trigger('crmConfirmYes');
- if (callback.call(dialog) !== false) {
- dialog.dialog('close');
- }
- };
- });
- dialog = $('<div class="crm-confirm-dialog"></div>')
- .html(options.message)
- .dialog(settings)
- .trigger('crmLoad');
- return dialog;
+ return dialog.dialog(settings).trigger('crmLoad');
};
/**
});
// Handle qf form errors
$('form :input.error', this).one('blur', function() {
- // ignore autocomplete fields
- if ($(this).is('.ac_input')) {
- return;
- }
-
$('.ui-notify-message.error a.ui-notify-close').click();
$(this).removeClass('error');
$(this).next('span.crm-error').remove();
messagesFromMarkup.call($('#crm-container'));
}
- // bind the event for image popup
$('body')
- .on('click', 'a.crm-image-popup', function() {
- var o = $('<div class="crm-custom-image-popup"><img src=' + $(this).attr('href') + '></div>');
-
- CRM.confirm('',
- {
- title: ts('Preview'),
- message: o
- },
- ts('Done')
- );
- return false;
+ // bind the event for image popup
+ .on('click', 'a.crm-image-popup', function(e) {
+ CRM.confirm({
+ title: ts('Preview'),
+ message: '<div class="crm-custom-image-popup"><img src=' + $(this).attr('href') + '></div>',
+ options: null
+ });
+ e.preventDefault();
})
.on('click', function (event) {
<script type="text/javascript">
cj(function($) {
var tag;
- $('.merge_tag').click(function() {
+ $('.merge_tag').click(function(e) {
tag = $(this).crmEditableEntity();
mergeTagDialog();
- return false;
+ e.preventDefault();
});
function mergeTagDialog() {
var tagUrl = {/literal}"{crmURL p='civicrm/ajax/mergeTagList' h=0}"{literal};
var title = {/literal}'{ts escape="js" 1="%1"}Merge tag %1 into:{/ts}'{literal};
- CRM.confirm(doMergeTag, {
+ CRM.confirm({
title: ts(title, {1: tag.name}),
message: '<input name="select_merge_tag" class="big" />',
open: function() {
$(dialog).append('<div class="messages status">{/literal}{ts escape='js'}Note: the selected tag is used by additional entities.{/ts}{literal}</div>');
}
});
- },
- close: function() {
- $('input[name=select_merge_tag]', this).select2('destroy');
- $(this).dialog('destroy').remove();
}
- });
- }
-
- function doMergeTag() {
- var toId = $("input[name=select_merge_tag]").val();
- if (!toId) {
- return false;
- }
- /* send synchronous request so that disabling any actions for slow servers*/
- var postUrl = {/literal}"{crmURL p='civicrm/ajax/mergeTags' h=0 }"{literal};
- var data = {fromId: tag.id, toId: toId, key:{/literal}"{crmKey name='civicrm/ajax/mergeTags'}"{literal}};
- cj.ajax({
- type: "POST",
- url: postUrl,
- data: data,
- dataType: "json",
- success: function(values) {
- if ( values.status == true ) {
- $('#tag-' + toId).children('td.crm-tag-used_for').text(values.tagB_used_for);
- $('#tag-' + tag.id).html('<td colspan="8"><div class="status message"><div class="icon inform-icon"></div>' + values.message + '</div></td>');
+ })
+ .on('dialogclose', function() {
+ $('input[name=select_merge_tag]', this).select2('destroy');
+ })
+ .on('crmConfirm:yes', function() {
+ var toId = $("input[name=select_merge_tag]", this).val();
+ if (!toId) {
+ $("input[name=select_merge_tag]", this).crmError(ts('Select a tag'));
+ return false;
}
- }
- });
+ /* send synchronous request so that disabling any actions for slow servers*/
+ var postUrl = {/literal}"{crmURL p='civicrm/ajax/mergeTags' h=0 }"{literal};
+ var data = {fromId: tag.id, toId: toId, key:{/literal}"{crmKey name='civicrm/ajax/mergeTags'}"{literal}};
+ cj.ajax({
+ type: "POST",
+ url: postUrl,
+ data: data,
+ dataType: "json",
+ success: function(values) {
+ if ( values.status == true ) {
+ $('#tag-' + toId).children('td.crm-tag-used_for').text(values.tagB_used_for);
+ $('#tag-' + tag.id).html('<td colspan="8"><div class="status message"><div class="icon inform-icon"></div>' + values.message + '</div></td>');
+ }
+ }
+ });
+ });
}
});
</script>
cj("#activity_change_status").val(current_status_id);
});
- CRM.confirm(function() {
+ CRM.confirm({
+ title: {/literal}'{ts escape='js'}Change Activity Status{/ts}'{literal},
+ message: $el
+ })
+ .on('crmConfirm:yes', function() {
// update the status
var status_id = $("#activity_change_status").val();
if (status_id === current_status_id) {
}
});
CRM.status({}, request);
- }
- ,{
- title: {/literal}'{ts escape='js'}Change Activity Status{/ts}'{literal},
- message: $el
- }
- );
+ });
return false;
});
});
})
.on('change', 'select[name=timeline_id]', function() {
if ($(this).val()) {
- CRM.confirm(ts('Add'), {
+ CRM.confirm({
title: $('option:first', this).text(),
message: ts('Add the %1 set of scheduled activities to this case?', {1: '<em>' + $('option:selected', this).text() + '</em>'})
})
- .on('crmConfirmYes', function() {
+ .on('crmConfirm:yes', function() {
$('[name=_qf_CaseView_next]').click();
})
- .on('crmConfirmNo', function() {
+ .on('crmConfirm:no', function() {
$('select[name=timeline_id]').select2('val', '');
});
}
$(this).select2('val', '');
}
})
- .on('click', 'a.case-miniform', function() {
+ .on('click', 'a.case-miniform', function(e) {
var dialog,
$el = $(this),
target = $el.attr('href');
}
return submission;
}
- dialog = CRM.confirm(submit, {
+ dialog = CRM.confirm({
title: $(this).attr('title') || $(this).text(),
message: detached[target],
- close: function() {
- detached[target] = $(target, dialog).detach();
- $(dialog).dialog('destroy').remove();
- },
open: miniForms[target].pre
- });
- return false;
+ })
+ .on('dialogclose', function() {
+ detached[target] = $(target, dialog).detach();
+ })
+ .on('crmConfirm:yes', submit);
+ e.preventDefault();
});
$().crmAccordions();
var $el = $(this),
$row = $el.closest('.crm-attachment-wrapper'),
msg = '{/literal}{ts escape="js" 1="%1"}This will immediately delete the file %1. This action cannot be undone.{/ts}{literal}';
- CRM.confirm(null, {
+ CRM.confirm({
title: $el.attr('title'),
message: ts(msg, {1: '<em>' + $el.data('filename') + '</em>'})
- }).on('crmConfirmYes', function() {
+ }).on('crmConfirm:yes', function() {
var postUrl = {/literal}"{crmURL p='civicrm/file/delete' h=0 }"{literal};
var request = $.post(postUrl, $el.data('args'));
CRM.status({success: '{/literal}{ts escape="js"}Removed{/ts}{literal}'}, request);
o.unblock();
});
- CRM.confirm( ''
- ,{
- title: ts('Email Message'),
- message: o,
- width : "680px", // don't remove px
- height: "560"
- },
- ts('Done')
- );
+ CRM.confirm({
+ title: ts('Email Message'),
+ message: o,
+ width : 680,
+ height: 560
+ });
return false;
});
}
fieldLabel = info.label || info.title || info.name || {/literal}'{ts escape="js"}Record{/ts}'{literal};
enabled = !$row.hasClass('disabled');
if (enabled) {
- CRM.confirm({}, {{/literal}
+ CRM.confirm({{/literal}
message: '<div class="crm-loading-element">{ts escape="js"}Loading{/ts}...</div>',
{* client-side variable substitutions in smarty are AWKWARD! *}
title: ts('{ts escape="js" 1='%1'}Disable %1{/ts}{literal}', {1: fieldLabel}),
width: 300,
+ options: null,
open: confirmation
});
} else {