X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fcrm.ajax.js;h=fc7610cceff39938f2eea044bf0a0b1513c34ed4;hb=6bcb856fe634ec10a29ec224e7c2134e8506584b;hp=8aff1bbdb7eb8570ec8e8c69257cb06746fd08b8;hpb=8d7d55a99b2d31e96b4e2c2858f42c058a056d01;p=civicrm-core.git diff --git a/js/crm.ajax.js b/js/crm.ajax.js index 8aff1bbdb7..fc7610ccef 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -12,7 +12,8 @@ var tplURL; CRM.url = function (path, query, mode) { if (typeof path === 'object') { - return tplURL = path; + tplURL = path; + return path; } if (!tplURL) { CRM.console('error', 'Error: CRM.url called before initialization'); @@ -204,10 +205,19 @@ this.options.url = this.options.url || document.location.href; this._originalUrl = this.options.url; }, - _onFailure: function(data) { - this.options.block && this.element.unblock(); + _onFailure: function(data, status) { + var msg, title = ts('Network Error'); + if (this.options.block) this.element.unblock(); this.element.trigger('crmAjaxFail', data); - CRM.alert(ts('Unable to reach the server. Please refresh this page in your browser and try again.'), ts('Network Error'), 'error'); + switch (status) { + case 'Forbidden': + title = ts('Access Denied'); + msg = ts('Ensure you are still logged in and have permission to access this feature.'); + break; + default: + msg = ts('Unable to reach the server. Please refresh this page in your browser and try again.'); + } + CRM.alert(msg, title, 'error'); }, _onError: function(data) { this.element.attr('data-unsaved-changes', 'false').trigger('crmAjaxError', data); @@ -230,7 +240,7 @@ _handleOrderLinks: function() { var that = this; $('a.crm-weight-arrow', that.element).click(function(e) { - that.options.block && that.element.block(); + if (that.options.block) that.element.block(); $.getJSON(that._formatUrl(this.href)).done(function() { that.refresh(); }); @@ -241,13 +251,13 @@ refresh: function() { var that = this; var url = this._formatUrl(this.options.url); - this.options.crmForm && $('form', this.element).ajaxFormUnbind(); + if (this.options.crmForm) $('form', this.element).ajaxFormUnbind(); if (this._originalContent === null) { this._originalContent = this.element.contents().detach(); } - this.options.block && this.element.block(); + if (this.options.block) this.element.block(); $.getJSON(url, function(data) { - that.options.block && that.element.unblock(); + if (that.options.block) that.element.unblock(); if (!$.isPlainObject(data)) { that._onFailure(data); return; @@ -257,14 +267,14 @@ return; } data.url = url; - that.element.trigger('crmBeforeLoad', data); + that.element.trigger('crmUnload').trigger('crmBeforeLoad', data); that._beforeRemovingContent(); that.element.html(data.content); that._handleOrderLinks(); that.element.trigger('crmLoad', data); - that.options.crmForm && that.element.trigger('crmFormLoad', data); - }).fail(function() { - that._onFailure(); + if (that.options.crmForm) that.element.trigger('crmFormLoad', data); + }).fail(function(data, msg, status) { + that._onFailure(data, status); }); }, // Perform any cleanup needed before removing/replacing content @@ -277,7 +287,7 @@ } }); } - this.options.crmForm && $('form', this.element).ajaxFormUnbind(); + if (this.options.crmForm) $('form', this.element).ajaxFormUnbind(); }, _destroy: function() { this.element.removeClass('crm-ajax-container').trigger('crmUnload'); @@ -303,7 +313,7 @@ height: '75%' }; } - options && $.extend(true, settings, options); + if (options) $.extend(true, settings, options); settings.url = url; // Create new dialog if (settings.dialog) { @@ -368,7 +378,7 @@ } }; // Move options that belong to crmForm. Others will be passed through to crmSnippet - options && $.each(options, function(key, value) { + if (options) $.each(options, function(key, value) { if (typeof(settings.crmForm[key]) !== 'undefined') { settings.crmForm[key] = value; } @@ -394,7 +404,7 @@ } } - widget.data('uiDialog') && widget.on('dialogbeforeclose', function(e) { + if (widget.data('uiDialog')) widget.on('dialogbeforeclose', function(e) { // CRM-14353 - Warn unsaved changes if user clicks close button or presses "esc" if (e.originalEvent) { cancelAction(); @@ -404,7 +414,7 @@ widget.on('crmFormLoad.crmForm', function(event, data) { var $el = $(this).attr('data-unsaved-changes', 'false'), settings = $el.crmSnippet('option', 'crmForm'); - settings.cancelButton && $(settings.cancelButton, this).click(function(e) { + if (settings.cancelButton) $(settings.cancelButton, this).click(function(e) { e.preventDefault(); var returnVal = settings.onCancel.call($el, e); if (returnVal !== false) { @@ -442,7 +452,7 @@ } } else { - $el.crmSnippet('option', 'block') && $el.unblock(); + if ($el.crmSnippet('option', 'block')) $el.unblock(); response.url = data.url; $el.html(response.content).trigger('crmLoad', response).trigger('crmFormLoad', response); if (response.status === 'form_error') { @@ -457,7 +467,7 @@ beforeSerialize: function(form, options) { if (window.CKEDITOR && window.CKEDITOR.instances) { $.each(CKEDITOR.instances, function() { - this.updateElement && this.updateElement(); + if (this.updateElement) this.updateElement(); }); } if (window.tinyMCE && tinyMCE.editors) { @@ -468,9 +478,9 @@ }, beforeSubmit: function(submission) { $.each(formErrors, function() { - this && this.close && this.close(); + if (this && this.close) this.close(); }); - $el.crmSnippet('option', 'block') && $el.block(); + if ($el.crmSnippet('option', 'block')) $el.block(); $el.trigger('crmFormSubmit', submission); } }, settings.ajaxForm)); @@ -493,7 +503,7 @@ if (!identifier || identifier === '#' || $.inArray(identifier, added) < 0) { var $icon = $el.find('.icon'), button = {'data-identifier': identifier, text: label, click: function() { - $el.click(); + $el[0].click(); }}; if ($icon.length) { button.icons = {primary: $icon.attr('class')}; @@ -566,7 +576,7 @@ if ($table.length && $.fn.DataTable.fnIsDataTable($table[0]) && $table.dataTable().fnSettings().sAjaxSource) { // Refresh ALL datatables - needed for contact relationship tab $.each($.fn.dataTable.fnTables(), function() { - $(this).dataTable().fnSettings().sAjaxSource && $(this).unblock().dataTable().fnDraw(); + if ($(this).dataTable().fnSettings().sAjaxSource) $(this).unblock().dataTable().fnDraw(); }); } // Otherwise refresh the nearest crmSnippet