X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fcrm.ajax.js;h=3ee5394097030ed6f75b0043d9036826edd986bb;hb=da8f0cf5b79bdf01e67fb96e5aa9120594ac5fc0;hp=29b011530e10963382a8b369a5c14b270fe4304d;hpb=ebda93be0f6455153d39b373426d997021401927;p=civicrm-core.git diff --git a/js/crm.ajax.js b/js/crm.ajax.js index 29b011530e..3ee5394097 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -12,10 +12,11 @@ var tplURL; CRM.url = function (path, query, mode) { if (typeof path === 'object') { - return tplURL = path; + tplURL = path; + return path; } if (!tplURL) { - console && console.log && console.log('Warning: CRM.url called before initialization'); + CRM.console('error', 'Error: CRM.url called before initialization'); } if (!mode) { mode = CRM.config && CRM.config.isFrontend ? 'front' : 'back'; @@ -36,10 +37,10 @@ return url; }; - // Backwards compatible with jQuery fn + // @deprecated $.extend ({'crmURL': function (p, params) { - console && console.log && console.log('Calling crmURL from jQuery is deprecated. Please use CRM.url() instead.'); + CRM.console('warn', 'Calling crmURL from jQuery is deprecated. Please use CRM.url() instead.'); return CRM.url(p, params); } }); @@ -156,7 +157,7 @@ * @deprecated */ $.fn.crmAPI = function(entity, action, params, options) { - console && console.log && console.log('Calling crmAPI from jQuery is deprecated. Please use CRM.api() instead.'); + CRM.console('warn', 'Calling crmAPI from jQuery is deprecated. Please use CRM.api3() instead.'); return CRM.api.call(this, entity, action, params, options); }; @@ -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,10 +287,10 @@ } }); } - this.options.crmForm && $('form', this.element).ajaxFormUnbind(); + if (this.options.crmForm) $('form', this.element).ajaxFormUnbind(); }, _destroy: function() { - this.element.removeClass('crm-ajax-container'); + this.element.removeClass('crm-ajax-container').trigger('crmUnload'); this._beforeRemovingContent(); if (this._originalContent !== null) { this.element.empty().append(this._originalContent); @@ -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) { @@ -311,6 +321,18 @@ if (typeof settings.dialog.height === 'string' && settings.dialog.height.indexOf('%') > 0) { settings.dialog.height = parseInt($(window).height() * (parseFloat(settings.dialog.height)/100), 10); } + // Increase percent width on small screens + if (typeof settings.dialog.width === 'string' && settings.dialog.width.indexOf('%') > 0) { + var screenWidth = $(window).width(), + percentage = parseInt(settings.dialog.width.replace('%', ''), 10), + gap = 100-percentage; + if (screenWidth < 701) { + settings.dialog.width = '100%'; + } + else if (screenWidth < 1400) { + settings.dialog.width = '' + parseInt(percentage+gap-((screenWidth - 700)/7*(gap)/100), 10) + '%'; + } + } $('