requests, errors, dialogs

This commit is contained in:
Rolux 2010-01-31 15:36:52 +05:30
parent 06852ed89c
commit c9f854061c
2 changed files with 18 additions and 13 deletions

View file

@ -97,6 +97,8 @@ Dialog
top: 24px;
height: 100%;
padding: 16px;
font-size: 12px;
line-height: 16px;
}
.OxDialog > .OxButtonsBar {

View file

@ -443,9 +443,9 @@ requires
data: options.data
});
function callback(data, callback) {
function callback(data) {
delete requests[options.id];
callback(data);
options.callback(data);
}
function debug(request) {
@ -476,20 +476,21 @@ requires
}
function error(request, status, error) {
var result;
console.log("error", request, status, error);
var data;
Ox.print("error", request, status, error);
try {
result = JSON.parse(request.responseText);
} catch(e) {
result = {
data = JSON.parse(request.responseText);
} catch (error) {
data = {
status: {
code: request.status,
text: request.statusText
}
};
}
options.callback(result);
if (result.status.code >= 500) {
if (data.status.code < 500) {
callback(data);
} else {
var $dialog = new Ox.Dialog({
title: "Application Error",
buttons: [
@ -504,14 +505,16 @@ requires
{
value: "Close",
click: function() {
$dialog.close();
$dialog.close(function() {
callback(data);
});
}
}
],
width: 400,
height: 100
})
.append(request.status + " " + request.statusText)
.append("Sorry, we have encountered an application error while handling your request. To help us find out what went wrong, you may want to report this error to an administrator. Otherwise, please try again later.")
.open();
Ox.print({
request: request,
@ -540,7 +543,7 @@ requires
data: data,
time: Ox.getTime()
};
callback(data, options.callback);
callback(data);
}
if (pending[options.id]) {
@ -554,7 +557,7 @@ requires
};
if (cache[req] && (options.age == -1 || options.age > Ox.getTime() - cache[req].time)) {
setTimeout(function() {
callback(cache[req].data, callback);
callback(cache[req].data);
}, 0);
} else {
pending[options.id] = true;