mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 14:17:57 +01:00
Fix jQuery resturn status.
This commit is contained in:
parent
3b23fead8e
commit
6d1a00291e
@ -98,6 +98,53 @@ jQuery.fn.dialogForm = function (options) {
|
|||||||
$('#' + containerId + ' input').each(function (index, elem) {
|
$('#' + containerId + ' input').each(function (index, elem) {
|
||||||
formData[elem.name] = elem.value;
|
formData[elem.name] = elem.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Success actions ...
|
||||||
|
var onSuccess = function (jqXHR, textStatus,data) {
|
||||||
|
if (options.redirect) {
|
||||||
|
var resourceId = jqXHR.getResponseHeader("ResourceId");
|
||||||
|
var redirectUrl = options.redirect;
|
||||||
|
redirectUrl = redirectUrl.replace("{header.resourceId}", resourceId);
|
||||||
|
|
||||||
|
// Hack: IE ignore the base href tag ...
|
||||||
|
var baseUrl = window.location.href.substring(0, window.location.href.lastIndexOf("c/maps/"));
|
||||||
|
window.open(baseUrl + redirectUrl, '_self');
|
||||||
|
|
||||||
|
} else if (options.postUpdate) {
|
||||||
|
options.postUpdate(formData);
|
||||||
|
}
|
||||||
|
dialogElem.modal('hide');
|
||||||
|
};
|
||||||
|
|
||||||
|
// On error message
|
||||||
|
var onFailure = function(jqXHR,textStatus, data){
|
||||||
|
var errors = JSON.parse(jqXHR.responseText);
|
||||||
|
// Mark fields with errors ...
|
||||||
|
var fieldErrors = errors.fieldErrors;
|
||||||
|
if (fieldErrors) {
|
||||||
|
for (var fieldName in fieldErrors) {
|
||||||
|
// Mark the field with errors ...
|
||||||
|
var message = fieldErrors[fieldName];
|
||||||
|
var inputField = $("#" + containerId + " input[name='" + fieldName + "']");
|
||||||
|
|
||||||
|
$("#" + containerId).find(".errorMessage").text(message).addClass("alert alert-error");
|
||||||
|
inputField.parent().addClass('error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var acceptBtn = $('#' + containerId + ' .btn-accept');
|
||||||
|
acceptBtn.button('reset');
|
||||||
|
};
|
||||||
|
|
||||||
|
var onError = function (jqXHR, textStatus, errorThrown) {
|
||||||
|
console.log(errorThrown);
|
||||||
|
console.log(jqXHR);
|
||||||
|
dialogElem.modal('hide');
|
||||||
|
$('#messagesPanel div div').text(errorThrown);
|
||||||
|
$('#messagesPanel').show()
|
||||||
|
var acceptBtn = $('#' + containerId + ' .btn-accept');
|
||||||
|
acceptBtn.button('reset');
|
||||||
|
};
|
||||||
|
|
||||||
$(acceptBtn).button('loading');
|
$(acceptBtn).button('loading');
|
||||||
var dialogElem = this;
|
var dialogElem = this;
|
||||||
jQuery.ajax(url, {
|
jQuery.ajax(url, {
|
||||||
@ -106,47 +153,14 @@ jQuery.fn.dialogForm = function (options) {
|
|||||||
data:JSON.stringify(formData),
|
data:JSON.stringify(formData),
|
||||||
type:options.type ? options.type : 'POST',
|
type:options.type ? options.type : 'POST',
|
||||||
contentType:"application/json; charset=utf-8",
|
contentType:"application/json; charset=utf-8",
|
||||||
success:function (data, textStatus, jqXHR) {
|
statusCode:{
|
||||||
if (options.redirect) {
|
200: onSuccess,
|
||||||
var resourceId = jqXHR.getResponseHeader("ResourceId");
|
201: onSuccess,
|
||||||
var redirectUrl = options.redirect;
|
204: onSuccess,
|
||||||
redirectUrl = redirectUrl.replace("{header.resourceId}", resourceId);
|
400: onFailure,
|
||||||
|
444: onError,
|
||||||
// Hack: IE ignore the base href tag ...
|
500: onError,
|
||||||
var baseUrl = window.location.href.substring(0, window.location.href.lastIndexOf("c/maps/"));
|
501: onError
|
||||||
window.open(baseUrl + redirectUrl, '_self');
|
|
||||||
|
|
||||||
} else if (options.postUpdate) {
|
|
||||||
options.postUpdate(formData);
|
|
||||||
}
|
|
||||||
dialogElem.modal('hide');
|
|
||||||
},
|
|
||||||
error:function (jqXHR, textStatus, errorThrown) {
|
|
||||||
if (jqXHR.status == 400) {
|
|
||||||
var errors = JSON.parse(jqXHR.responseText);
|
|
||||||
// Mark fields with errors ...
|
|
||||||
var fieldErrors = errors.fieldErrors;
|
|
||||||
if (fieldErrors) {
|
|
||||||
for (var fieldName in fieldErrors) {
|
|
||||||
// Mark the field with errors ...
|
|
||||||
var message = fieldErrors[fieldName];
|
|
||||||
var inputField = $("#" + containerId + " input[name='" + fieldName + "']");
|
|
||||||
|
|
||||||
$("#" + containerId).find(".errorMessage").text(message).addClass("alert alert-error");
|
|
||||||
inputField.parent().addClass('error');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
console.log(errorThrown);
|
|
||||||
console.log(jqXHR);
|
|
||||||
dialogElem.modal('hide');
|
|
||||||
$('#messagesPanel div div').text(errorThrown);
|
|
||||||
$('#messagesPanel').show()
|
|
||||||
}
|
|
||||||
var acceptBtn = $('#' + containerId + ' .btn-accept');
|
|
||||||
acceptBtn.button('reset');
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
Loading…
Reference in New Issue
Block a user