X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fcrm.ajax.js;h=3ea776c4f834190e1cd261bae28f1c509a8a3f9b;hb=e4a6290df32ba56cbbd81501e4258a2ca056347d;hp=cf8f2eb293a2adf2917d4d73c487dad21abcd523;hpb=6e1a96bec4660bb24e8f6f8202a04ef5139fda8b;p=civicrm-core.git diff --git a/js/crm.ajax.js b/js/crm.ajax.js index cf8f2eb293..3ea776c4f8 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -225,14 +225,16 @@ this.element.dialog('close'); } }, - _formatUrl: function(url) { + _formatUrl: function(url, snippetType) { // Strip hash url = url.split('#')[0]; // Add snippet argument to url - if (url.search(/[&?]snippet=/) < 0) { - url += (url.indexOf('?') < 0 ? '?' : '&') + 'snippet=json'; - } else { - url = url.replace(/snippet=[^&]*/, 'snippet=json'); + if (snippetType) { + if (url.search(/[&?]snippet=/) < 0) { + url += (url.indexOf('?') < 0 ? '?' : '&') + 'snippet=' + snippetType; + } else { + url = url.replace(/snippet=[^&]*/, 'snippet=' + snippetType); + } } return url; }, @@ -241,7 +243,7 @@ var that = this; $('a.crm-weight-arrow', that.element).click(function(e) { if (that.options.block) that.element.block(); - $.getJSON(that._formatUrl(this.href)).done(function() { + $.getJSON(that._formatUrl(this.href, 'json')).done(function() { that.refresh(); }); e.stopImmediatePropagation(); @@ -250,7 +252,7 @@ }, refresh: function() { var that = this; - var url = this._formatUrl(this.options.url); + var url = this._formatUrl(this.options.url, 'json'); if (this.options.crmForm) $('form', this.element).ajaxFormUnbind(); if (this.options.block) this.element.block(); $.getJSON(url, function(data) { @@ -270,6 +272,14 @@ that._handleOrderLinks(); that.element.trigger('crmLoad', data); if (that.options.crmForm) that.element.trigger('crmFormLoad', data); + // This is only needed by forms that load via ajax but submit without ajax, e.g. configure contribution page tabs + // TODO: remove this when those forms have been converted to use ajax submit + if (data.status === 'form_error' && $.isPlainObject(data.errors)) { + that.element.trigger('crmFormError', data); + $.each(data.errors, function(formElement, msg) { + $('[name="'+formElement+'"]', that.element).crmError(msg); + }); + } }).fail(function(data, msg, status) { that._onFailure(data, status); }); @@ -313,8 +323,13 @@ // Create new dialog if (settings.dialog) { settings.dialog = CRM.utils.adjustDialogDefaults(settings.dialog); - $('
').dialog(settings.dialog); + $('
') + .dialog(settings.dialog) + .parent().find('.ui-dialog-titlebar') + .append($('') + .button({icons: {primary: 'ui-icon-print'}, text: false})); } + // Add handlers to new or existing dialog if ($(settings.target).data('uiDialog')) { $(settings.target) .on('dialogclose', function() { @@ -327,6 +342,8 @@ if (e.target === $(settings.target)[0] && data && !settings.dialog.title && data.title) { $(this).dialog('option', 'title', data.title); } + // Update print url + $(this).parent().find('a.crm-dialog-titlebar-print').attr('href', $(this).data('civiCrmSnippet')._formatUrl($(this).crmSnippet('option', 'url'), '2')); }); } $(settings.target).crmSnippet(settings).crmSnippet('refresh'); @@ -441,17 +458,20 @@ }, settings.ajaxForm)); if (settings.openInline) { settings.autoClose = $el.crmSnippet('isOriginalUrl'); - $(settings.openInline, this).not(exclude + ', .crm-popup').click(function(event) { + $(this).on('click', settings.openInline, function(e) { + if ($(this).is(exclude + ', .crm-popup')) { + return; + } if ($(this).hasClass('open-inline-noreturn')) { // Force reset of original url $el.data('civiCrmSnippet')._originalUrl = $(this).attr('href'); } $el.crmSnippet('option', 'url', $(this).attr('href')).crmSnippet('refresh'); - return false; + e.preventDefault(); }); } - // Show form buttons as part of the dialog if ($el.data('uiDialog')) { + // Show form buttons as part of the dialog var buttonContainers = '.crm-submit-buttons, .action-link', buttons = [], added = []; @@ -477,6 +497,15 @@ $el.parents(buttonContainers).css({height: 0, padding: 0, margin: 0, overflow: 'hidden'}).find('.crm-button-icon').hide(); }); $el.dialog('option', 'buttons', buttons); + + // Show done button for non-ajax dialogs (e.g. file downloads) + $(this).on('submit', "form[data-no-ajax-submit=true]", function() { + $el.dialog('option', 'buttons', [{ + text: ts('Done'), + icons: {primary: 'ui-icon-close'}, + click: function() {$(this).dialog('close');} + }]); + }); } // Allow a button to prevent ajax submit $('input[data-no-ajax-submit=true]').click(function() {