From b7ca10808effe4ce6f47b9f6be78d353bb2b97f7 Mon Sep 17 00:00:00 2001
From: j <0x006A@0x2620.org>
Date: Sat, 14 Jan 2012 16:19:15 +0530
Subject: [PATCH] bind to request error events and show one dialog
---
static/js/pandora.js | 6 ++-
static/js/pandora/errorDialog.js | 88 ++++++++++++++++++++++++++++++++
static/js/pandora/utils.js | 2 +
3 files changed, 94 insertions(+), 2 deletions(-)
create mode 100644 static/js/pandora/errorDialog.js
diff --git a/static/js/pandora.js b/static/js/pandora.js
index 4d7c6d952..6cf415773 100644
--- a/static/js/pandora.js
+++ b/static/js/pandora.js
@@ -172,7 +172,7 @@ appPanel
function loadPandoraFiles(callback) {
var prefix = '/static/';
if (localStorage && localStorage['pandora.debug']) {
- Ox.getJSON(prefix + 'json/pandora.json', function(files) {
+ Ox.getJSON(prefix + 'json/pandora.json?' + Ox.random(1000), function(files) {
var promises = [];
files.forEach(function(file) {
var dfd = new $.Deferred();
@@ -287,7 +287,9 @@ appPanel
Ox.Request.requests() && pandora.$ui.loadingIcon.start();
pandora.$ui.body.ajaxStart(pandora.$ui.loadingIcon.start);
pandora.$ui.body.ajaxStop(pandora.$ui.loadingIcon.stop);
-
+ Ox.Request.bindEvent({
+ error: pandora.ui.errorDialog
+ });
pandora.site.sectionButtonsWidth = pandora.$ui.sectionButtons.width() + 8;
});
diff --git a/static/js/pandora/errorDialog.js b/static/js/pandora/errorDialog.js
new file mode 100644
index 000000000..7bb035276
--- /dev/null
+++ b/static/js/pandora/errorDialog.js
@@ -0,0 +1,88 @@
+// vim: et:ts=4:sw=4:sts=4:ft=javascript
+'use strict';
+
+pandora.ui.errorDialog = function(data) {
+ var that, error;
+
+ //dont open dialog on unload or if antoher error is open
+ //fixme: error dialog should updated instead
+ if ($('.OxErrorDialog').length || pandora.isUnloading) {
+ return;
+ }
+
+ if (data.status.code == 401 || data.status.code == 403) {
+ that = Ox.Dialog({
+ buttons: [
+ Ox.Button({
+ id: 'close',
+ title: 'Close'
+ })
+ .bindEvent({
+ click: function() {
+ that.close();
+ }
+ })
+ ],
+ content: Ox.Element()
+ .append(
+ $('')
+ .attr({src: Ox.UI.PATH + 'png/icon128.png'})
+ .css({position: 'absolute', left: '16px', top: '16px', width: '64px', height: '64px'})
+ )
+ .append(
+ Ox.Element()
+ .css({position: 'absolute', left: '96px', top: '16px', width: '256px'})
+ .html('Sorry, you have made an unauthorized request.')
+ ),
+ fixedSize: true,
+ height: 192,
+ keys: {enter: 'close', escape: 'close'},
+ removeOnClose: true,
+ title: Ox.toTitleCase(data.status.text),
+ width: 368
+ })
+ .open();
+ } else {
+ // 0 (timeout) or 500 (error)
+ var error = data.status.code == 0 ? 'timeout' : 'error';
+
+ // on window unload, pending request will time out, so
+ // in order to keep the dialog from appearing, delay it
+
+ that = Ox.Dialog({
+ buttons: [
+ Ox.Button({
+ id: 'close',
+ title: 'Close'
+ })
+ .bindEvent({
+ click: function() {
+ that.close();
+ }
+ })
+ ],
+ content: Ox.Element()
+ .append(
+ $('')
+ .attr({src: Ox.UI.PATH + 'png/icon128.png'})
+ .css({position: 'absolute', left: '16px', top: '16px', width: '64px', height: '64px'})
+ )
+ .append(
+ Ox.Element()
+ .css({position: 'absolute', left: '96px', top: '16px', width: '256px'})
+ .html(
+ 'Sorry, a server ' + error
+ + ' occured 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.'
+ )
+ ),
+ fixedSize: true,
+ height: 192,
+ keys: {enter: 'close', escape: 'close'},
+ removeOnClose: true,
+ title: 'Server ' + Ox.toTitleCase(error),
+ width: 368
+ })
+ .open();
+ }
+ that.addClass('OxErrorDialog');
+};
diff --git a/static/js/pandora/utils.js b/static/js/pandora/utils.js
index 8d2a07d45..2881f786e 100644
--- a/static/js/pandora/utils.js
+++ b/static/js/pandora/utils.js
@@ -1034,6 +1034,8 @@ pandora.selectList = function() {
};
pandora.unloadWindow = function() {
+ //prevent errors on unload
+ pandora.isUnloading = true;
/*
// fixme: ajax request has to have async set to false for this to work
pandora.user.ui.section == 'items'