CRM-14931 - Nicer aja handling of statusBounce errors
authorColeman Watts <coleman@civicrm.org>
Thu, 3 Jul 2014 19:30:30 +0000 (20:30 +0100)
committerColeman Watts <coleman@civicrm.org>
Thu, 3 Jul 2014 19:30:30 +0000 (20:30 +0100)
js/crm.ajax.js

index 8d785e82c03d35eecbf1e2420f40e71788805961..5ca6a8907fbe89f9f3c2d628a68a51602722eb9b 100644 (file)
       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');
     },
+    _onError: function(data) {
+      this.element.attr('data-unsaved-changes', 'false').trigger('crmAjaxError', data);
+      if (this.options.crmForm.autoClose && this.element.data('uiDialog')) {
+        this.element.dialog('close');
+      }
+    },
     _formatUrl: function(url) {
       // Strip hash
       url = url.split('#')[0];
       }
       this.options.block && $('.blockOverlay', this.element).length < 1 && this.element.block();
       $.getJSON(url, function(data) {
-        if (typeof(data) != 'object' || typeof(data.content) != 'string') {
+        if (!$.isPlainObject(data)) {
           that._onFailure(data);
           return;
         }
+        if (data.status === 'error') {
+          that._onError(data);
+          return;
+        }
         data.url = url;
         that.element.trigger('crmBeforeLoad', data).html(data.content);
         that._handleOrderLinks();