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); element && element.remove(false);
}); });
Ox.Focus.remove(that.id); Ox.Focus.remove(that.id);
Ox.Keyboard.unbind(that.id);
delete self.$eventHandler; delete self.$eventHandler;
delete Ox.UI.elements[that.id]; delete Ox.UI.elements[that.id];
that.$tooltip && that.$tooltip.remove(); that.$tooltip && that.$tooltip.remove();

View file

@ -60,6 +60,7 @@ Ox.Request = function(options) {
} }
}, },
// fixme: remove
_leakCache: function() { _leakCache: function() {
return cache; return cache;
}, },
@ -174,7 +175,7 @@ Ox.Request = function(options) {
} }
function complete(request) { function complete(request) {
var data; var $dialog, data, error;
try { try {
data = JSON.parse(request.responseText); data = JSON.parse(request.responseText);
} catch (err) { } catch (err) {
@ -204,7 +205,7 @@ Ox.Request = function(options) {
callback(data); callback(data);
} else if (data.status.code == 401 || data.status.code == 403) { } else if (data.status.code == 401 || data.status.code == 403) {
// unauthorized or forbidden // unauthorized or forbidden
var $dialog = Ox.Dialog({ $dialog = Ox.Dialog({
buttons: [ buttons: [
Ox.Button({ Ox.Button({
id: 'close', id: 'close',
@ -227,6 +228,7 @@ Ox.Request = function(options) {
.css({position: 'absolute', left: '96px', top: '16px', width: '256px'}) .css({position: 'absolute', left: '96px', top: '16px', width: '256px'})
.html('Sorry, you have made an unauthorized request.') .html('Sorry, you have made an unauthorized request.')
), ),
fixedSize: true,
height: 192, height: 192,
keys: {enter: 'close', escape: 'close'}, keys: {enter: 'close', escape: 'close'},
title: Ox.toTitleCase(data.status.text), title: Ox.toTitleCase(data.status.text),
@ -235,7 +237,11 @@ Ox.Request = function(options) {
.open(); .open();
} else { } else {
// 0 (timeout) or 500 (error) // 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: [ buttons: [
Ox.Button({ Ox.Button({
id: 'details', id: 'details',
@ -267,15 +273,20 @@ Ox.Request = function(options) {
.append( .append(
Ox.Element() Ox.Element()
.css({position: 'absolute', left: '96px', top: '16px', width: '256px'}) .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, height: 192,
keys: {enter: 'close', escape: 'close'}, keys: {enter: 'close', escape: 'close'},
title: 'Application Error', title: 'Server ' + Ox.toTitleCase(error),
width: 368 width: 368
}) })
.open(); .open();
// fixme: change this to Send / Don't Send // fixme: change this to Send / Don't Send
}, error == 'timeout' ? 250 : 0);
} }
pending[options.id] = false; 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 itemMargin: self.options.type == 'text' ? 0 : 8, // 2 x 4 px margin ... fixme: the 2x should be computed later
keyboardEvents: { keyboardEvents: {
key_control_c: copyItems, key_control_c: copyItems,
key_control_e: editItems,
key_control_n: function() { key_control_n: function() {
addItem(''); 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() { function emptyFirstPage() {
if (self.$pages[0]) { if (self.$pages[0]) {
if (self.options.type == 'text') { if (self.options.type == 'text') {