forked from 0x2620/oxjs
updates for html parsing, request handling, and editable elements
This commit is contained in:
parent
a949ad2cf4
commit
62f8a907ea
6 changed files with 153 additions and 69 deletions
|
|
@ -125,10 +125,9 @@ Ox.Request = function(options) {
|
|||
} else {
|
||||
pending[options.id] = true;
|
||||
$.ajax({
|
||||
complete: complete,
|
||||
data: options.data,
|
||||
dataType: 'json',
|
||||
error: error,
|
||||
success: success,
|
||||
//dataType: 'json',
|
||||
timeout: options.timeout,
|
||||
type: options.type,
|
||||
url: options.url
|
||||
|
|
@ -172,37 +171,66 @@ Ox.Request = function(options) {
|
|||
iframe.close();
|
||||
}
|
||||
|
||||
function error(request, status, error) {
|
||||
function complete(request) {
|
||||
var data;
|
||||
if (arguments.length == 1) {
|
||||
data = arguments[0]
|
||||
} else {
|
||||
try {
|
||||
data = JSON.parse(request.responseText);
|
||||
} catch (err) {
|
||||
try {
|
||||
data = JSON.parse(request.responseText);
|
||||
data = {
|
||||
status: {
|
||||
code: request.status,
|
||||
text: request.statusText
|
||||
}
|
||||
};
|
||||
} catch (err) {
|
||||
try {
|
||||
data = {
|
||||
status: {
|
||||
code: request.status,
|
||||
text: request.statusText
|
||||
}
|
||||
};
|
||||
} catch (err) {
|
||||
data = {
|
||||
status: {
|
||||
code: '500',
|
||||
text: 'Unknown Error'
|
||||
}
|
||||
};
|
||||
}
|
||||
data = {
|
||||
status: {
|
||||
code: '500',
|
||||
text: 'Unknown Error'
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
if (data.status.code && data.status.code < 500) {
|
||||
// 0 is timeout
|
||||
if (data.status.code == 200) {
|
||||
cache[req] = {
|
||||
data: data,
|
||||
time: Ox.getTime()
|
||||
};
|
||||
callback(data);
|
||||
} else {
|
||||
} else if (data.status.code >= 400 && data.status.code < 500) {
|
||||
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();
|
||||
} else {
|
||||
// 0 (timeout) or 500 (error)
|
||||
var $dialog = Ox.Dialog({
|
||||
title: 'Application Error',
|
||||
buttons: [
|
||||
Ox.Button({
|
||||
id: 'details',
|
||||
|
|
@ -238,28 +266,15 @@ Ox.Request = function(options) {
|
|||
),
|
||||
height: 192,
|
||||
keys: {enter: 'close', escape: 'close'},
|
||||
title: 'Application Error',
|
||||
width: 368
|
||||
})
|
||||
.open();
|
||||
// fixme: change this to Send / Don't Send
|
||||
/*Ox.print({
|
||||
request: request,
|
||||
status: status,
|
||||
error: error
|
||||
});*/
|
||||
}
|
||||
pending[options.id] = false;
|
||||
}
|
||||
|
||||
function success(data) {
|
||||
pending[options.id] = false;
|
||||
cache[req] = {
|
||||
data: data,
|
||||
time: Ox.getTime()
|
||||
};
|
||||
callback(data);
|
||||
}
|
||||
|
||||
// return dfd.promise();
|
||||
|
||||
return options.id;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue