$el.addClass('modal-dialog');
$('body').css({overflow: 'hidden'});
}
- $el.parent().find('.ui-dialog-titlebar-close').attr('title', ts('Close'));
// Add resize button
if ($el.parent().hasClass('crm-container') && $el.dialog('option', 'resizable')) {
$el.parent().find('.ui-dialog-titlebar').append($('<button class="crm-dialog-titlebar-resize ui-dialog-titlebar-close" title="'+ts('Toggle fullscreen')+'" style="right:2em;"/>').button({icons: {primary: 'ui-icon-newwin'}, text: false}));
e.preventDefault();
});
}
- // FIXME: D7 hack to get the toolbar out of the way (CRM-15341)
- if (CRM.config.userFramework === 'Drupal') $('#toolbar').css('z-index', '100');
})
.on('dialogclose', function(e) {
// Restore scrollbars when closing modal
if ($('.ui-dialog .modal-dialog:visible').not(e.target).length < 1) {
$('body').css({overflow: ''});
- // FIXME: D7 hack, restore toolbar (CRM-15341)
- if (CRM.config.userFramework === 'Drupal') $('#toolbar').css('z-index', '');
}
})
.on('submit', function(e) {
* @see https://wiki.civicrm.org/confluence/display/CRMDOC/Notification+Reference
*/
CRM.confirm = function (options) {
- var dialog, url, msg, settings = {
+ var dialog, url, msg, buttons = [], settings = {
title: ts('Confirm'),
message: ts('Are you sure you want to continue?'),
url: null,
};
$.extend(settings, ($.isFunction(options) ? arguments[1] : options) || {});
if (!settings.buttons && $.isPlainObject(settings.options)) {
- settings.buttons = [];
- $.each(settings.options, function(key, label) {
- settings.buttons.push({
+ $.each(settings.options, function(op, label) {
+ buttons.push({
text: label,
- icons: {primary: key === 'no' ? 'ui-icon-close' : 'ui-icon-check'},
+ 'data-op': op,
+ icons: {primary: op === 'no' ? 'ui-icon-close' : 'ui-icon-check'},
click: function() {
- var event = $.Event('crmConfirm:' + key);
+ var event = $.Event('crmConfirm:' + op);
$(this).trigger(event);
if (!event.isDefaultPrevented()) {
dialog.dialog('close');
}
});
});
+ // Order buttons so that "no" goes on the right-hand side
+ settings.buttons = _.sortBy(buttons, 'data-op').reverse();
}
url = settings.url;
- msg = settings.message;
+ msg = url ? '' : settings.message;
delete settings.options;
delete settings.message;
delete settings.url;
- dialog = $('<div class="crm-confirm-dialog"></div>').dialog(settings);
+ dialog = $('<div class="crm-confirm-dialog"></div>').html(msg || '').dialog(settings);
if ($.isFunction(options)) {
dialog.on('crmConfirm:yes', options);
}
if (url) {
CRM.loadPage(url, {target: dialog});
}
- else if (msg && msg.length) {
- dialog.html(msg).trigger('crmLoad');
+ else {
+ dialog.trigger('crmLoad');
}
return dialog;
};
});
}
+ /**
+ * Improve blockUI when used with jQuery dialog
+ */
var originalBlock = $.fn.block,
originalUnblock = $.fn.unblock;
return $(this);
}
return originalBlock.call(this, opts);
- }
-
+ };
$.fn.unblock = function(opts) {
if ($(this).is('.ui-dialog-content')) {
originalUnblock.call($(this).parents('.ui-dialog'), opts);
return $(this);
}
return originalUnblock.call(this, opts);
- }
+ };
- // Preprocess all cj ajax calls to display messages
+ // Preprocess all CRM ajax calls to display messages
$(document).ajaxSuccess(function(event, xhr, settings) {
try {
if ((!settings.dataType || settings.dataType == 'json') && xhr.responseText) {
if (response.backtrace) {
CRM.console('log', response.backtrace);
}
+ if (typeof response.deprecated === 'string') {
+ CRM.console('warn', response.deprecated);
+ }
}
}
- // Suppress errors
+ // Ignore errors thrown by parseJSON
catch (e) {}
});
CRM.confirm({
title: ts('Preview'),
resizable: true,
- message: '<div class="crm-custom-image-popup"><img src=' + $(this).attr('href') + '></div>',
+ message: '<div class="crm-custom-image-popup"><img style="max-width: 100%" src="' + $(this).attr('href') + '"></div>',
options: null
});
e.preventDefault();
/**
* Clientside currency formatting
- * @param value
- * @param format - currency representation of the number 1234.56
+ * @param number value
+ * @param [optional] string format - currency representation of the number 1234.56
* @return string
- * @see CRM_Core_Resources::addCoreResources
*/
var currencyTemplate;
CRM.formatMoney = function(value, format) {
return console[method](title, msg);
}
}
- }
+ };
})(jQuery, _);