CRM-14789 - crmCaseType - Allow enable/disable/delete
[civicrm-core.git] / js / crm.ajax.js
index 8d785e82c03d35eecbf1e2420f40e71788805961..a3e9932e6e0ebd4c98f2ee77022cba9e40117f52 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 && 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();