forked from 0x2620/pandora
bind to request error events and show one dialog
This commit is contained in:
parent
81548bba04
commit
b7ca10808e
3 changed files with 94 additions and 2 deletions
|
@ -172,7 +172,7 @@ appPanel
|
||||||
function loadPandoraFiles(callback) {
|
function loadPandoraFiles(callback) {
|
||||||
var prefix = '/static/';
|
var prefix = '/static/';
|
||||||
if (localStorage && localStorage['pandora.debug']) {
|
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 = [];
|
var promises = [];
|
||||||
files.forEach(function(file) {
|
files.forEach(function(file) {
|
||||||
var dfd = new $.Deferred();
|
var dfd = new $.Deferred();
|
||||||
|
@ -287,7 +287,9 @@ appPanel
|
||||||
Ox.Request.requests() && pandora.$ui.loadingIcon.start();
|
Ox.Request.requests() && pandora.$ui.loadingIcon.start();
|
||||||
pandora.$ui.body.ajaxStart(pandora.$ui.loadingIcon.start);
|
pandora.$ui.body.ajaxStart(pandora.$ui.loadingIcon.start);
|
||||||
pandora.$ui.body.ajaxStop(pandora.$ui.loadingIcon.stop);
|
pandora.$ui.body.ajaxStop(pandora.$ui.loadingIcon.stop);
|
||||||
|
Ox.Request.bindEvent({
|
||||||
|
error: pandora.ui.errorDialog
|
||||||
|
});
|
||||||
pandora.site.sectionButtonsWidth = pandora.$ui.sectionButtons.width() + 8;
|
pandora.site.sectionButtonsWidth = pandora.$ui.sectionButtons.width() + 8;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
88
static/js/pandora/errorDialog.js
Normal file
88
static/js/pandora/errorDialog.js
Normal file
|
@ -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(
|
||||||
|
$('<img>')
|
||||||
|
.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(
|
||||||
|
$('<img>')
|
||||||
|
.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');
|
||||||
|
};
|
|
@ -1034,6 +1034,8 @@ pandora.selectList = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
pandora.unloadWindow = 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
|
// fixme: ajax request has to have async set to false for this to work
|
||||||
pandora.user.ui.section == 'items'
|
pandora.user.ui.section == 'items'
|
||||||
|
|
Loading…
Reference in a new issue