From 243614cee20223578695a65759967465fb1b3d27 Mon Sep 17 00:00:00 2001
From: rlx <0x0073@0x2620.org>
Date: Tue, 8 Nov 2011 10:27:49 +0000
Subject: [PATCH] when removing an element, unbind global keyboard handler;
delay request timeout dialog until after window unload
---
source/Ox.UI/js/Core/Ox.Element.js | 1 +
source/Ox.UI/js/Core/Ox.Request.js | 77 +++++++++++++++++-------------
source/Ox.UI/js/List/Ox.List.js | 9 ++++
3 files changed, 54 insertions(+), 33 deletions(-)
diff --git a/source/Ox.UI/js/Core/Ox.Element.js b/source/Ox.UI/js/Core/Ox.Element.js
index cf160f56..7d616f11 100644
--- a/source/Ox.UI/js/Core/Ox.Element.js
+++ b/source/Ox.UI/js/Core/Ox.Element.js
@@ -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();
diff --git a/source/Ox.UI/js/Core/Ox.Request.js b/source/Ox.UI/js/Core/Ox.Request.js
index ebe666c3..65002689 100644
--- a/source/Ox.UI/js/Core/Ox.Request.js
+++ b/source/Ox.UI/js/Core/Ox.Request.js
@@ -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(
- $('')
- .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(
+ $('')
+ .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;
}
diff --git a/source/Ox.UI/js/List/Ox.List.js b/source/Ox.UI/js/List/Ox.List.js
index 48b2de86..a38cdb1d 100644
--- a/source/Ox.UI/js/List/Ox.List.js
+++ b/source/Ox.UI/js/List/Ox.List.js
@@ -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') {