From dedac0a29f3cccfe9e9ad38fb4bac07d1d20000e Mon Sep 17 00:00:00 2001 From: Rolux Date: Sun, 31 Jan 2010 15:36:52 +0530 Subject: [PATCH] requests, errors, dialogs --- build/css/ox.ui.css | 2 ++ build/js/ox.ui.js | 29 ++++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/build/css/ox.ui.css b/build/css/ox.ui.css index 876a829..7181464 100644 --- a/build/css/ox.ui.css +++ b/build/css/ox.ui.css @@ -97,6 +97,8 @@ Dialog top: 24px; height: 100%; padding: 16px; + font-size: 12px; + line-height: 16px; } .OxDialog > .OxButtonsBar { diff --git a/build/js/ox.ui.js b/build/js/ox.ui.js index 746f05e..d03099d 100644 --- a/build/js/ox.ui.js +++ b/build/js/ox.ui.js @@ -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;