when removing an element, unbind global keyboard handler; delay request timeout dialog until after window unload

This commit is contained in:
rlx 2011-11-08 10:27:49 +00:00
parent 314788dd24
commit 243614cee2
3 changed files with 54 additions and 33 deletions

View file

@ -405,6 +405,7 @@ Ox.Element = function(options, self) {
element && element.remove(false);
});
Ox.Focus.remove(that.id);
Ox.Keyboard.unbind(that.id);
delete self.$eventHandler;
delete Ox.UI.elements[that.id];
that.$tooltip && that.$tooltip.remove();

View file

@ -60,6 +60,7 @@ Ox.Request = function(options) {
}
},
// fixme: remove
_leakCache: function() {
return cache;
},
@ -174,7 +175,7 @@ Ox.Request = function(options) {
}
function complete(request) {
var data;
var $dialog, data, error;
try {
data = JSON.parse(request.responseText);
} catch (err) {
@ -204,38 +205,43 @@ Ox.Request = function(options) {
callback(data);
} else if (data.status.code == 401 || data.status.code == 403) {
// unauthorized or forbidden
var $dialog = Ox.Dialog({
buttons: [
Ox.Button({
id: 'close',
title: 'Close'
})
.bindEvent({
click: function() {
$dialog.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.')
),
height: 192,
keys: {enter: 'close', escape: 'close'},
title: Ox.toTitleCase(data.status.text),
width: 368
})
.open();
$dialog = Ox.Dialog({
buttons: [
Ox.Button({
id: 'close',
title: 'Close'
})
.bindEvent({
click: function() {
$dialog.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'},
title: Ox.toTitleCase(data.status.text),
width: 368
})
.open();
} else {
// 0 (timeout) or 500 (error)
var $dialog = Ox.Dialog({
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
setTimeout(function() {
$dialog = Ox.Dialog({
buttons: [
Ox.Button({
id: 'details',
@ -267,15 +273,20 @@ Ox.Request = function(options) {
.append(
Ox.Element()
.css({position: 'absolute', left: '96px', top: '16px', width: '256px'})
.html('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.')
.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'},
title: 'Application Error',
title: 'Server ' + Ox.toTitleCase(error),
width: 368
})
.open();
// fixme: change this to Send / Don't Send
}, error == 'timeout' ? 250 : 0);
}
pending[options.id] = false;
}

View file

@ -107,6 +107,7 @@ Ox.List = function(options, self) {
itemMargin: self.options.type == 'text' ? 0 : 8, // 2 x 4 px margin ... fixme: the 2x should be computed later
keyboardEvents: {
key_control_c: copyItems,
key_control_e: editItems,
key_control_n: function() {
addItem('');
},
@ -413,6 +414,14 @@ Ox.List = function(options, self) {
}
}
function editItems() {
/*
self.options.selected.length && that.triggerEvent('edit', {
ids: self.options.selected
});
*/
}
function emptyFirstPage() {
if (self.$pages[0]) {
if (self.options.type == 'text') {