1
0
Fork 0
forked from 0x2620/oxjs

some dialog

This commit is contained in:
Rolux 2010-01-31 13:33:22 +05:30
commit 8603ea938b
5 changed files with 153 additions and 44 deletions

View file

@ -105,15 +105,15 @@ requires
return Ox.getset(self.options, Array.slice.call(arguments), self.change, that);
};
that.request = function(fn, data, callback) {
if(Ox.isFunction(data)) {
that.request = function(action, data, callback) {
if (arguments.length == 2) {
callback = data;
data = {};
}
return Ox.Request.send({
url: self.options.requestURL,
data: {
"function": fn,
action: action,
data: JSON.stringify(data)
},
callback: callback
@ -126,14 +126,6 @@ requires
}();
/*
----------------------------------------------------------------------------
Ox.Cache
----------------------------------------------------------------------------
*/
// currently part of Ox.Request
/*
----------------------------------------------------------------------------
Ox.Event
@ -457,13 +449,19 @@ requires
}
function error(request, status, error) {
var result;
try {
var result = JSON.parse(request.responseText);
result = JSON.parse(request.responseText);
} catch(e) {
var result = {status: {code:request.status, text:request.statusText}};
result = {
status: {
code: request.status,
text: request.statusText
}
};
}
options.callback(result);
if(result.status.code >= 500) {
if (result.status.code >= 500) {
var $dialog = new Ox.Dialog({
title: "Error: Remote request failed.",
buttons: [
@ -999,7 +997,7 @@ requires
/*
============================================================================
Dialog
Ox.Dialog
============================================================================
*/
@ -1008,7 +1006,7 @@ requires
options = $.extend({
title: "",
buttons: [],
width: 256,
width: 384,
height: 128
}, options),
that = new Ox.Element()
@ -1017,11 +1015,13 @@ requires
left: (($(document).width() - options.width) / 2) + "px",
top: (($(document).height() - options.height - 48) / 2) + "px",
width: options.width + "px",
height: (options.height + 48) + "px"
height: (options.height + 60) + "px"
});
that.$titlebar = new Ox.Element()
that.$titlebar = new Ox.Bar({
size: "medium"
})
.addClass("OxTitleBar")
.html(options.title)
//.html(options.title)
.mousedown(function(e) {
var offset = that.offset(),
//maxLeft = $(document).width() - that.width(),
@ -1031,8 +1031,11 @@ requires
documentWidth = $(document).width();
documentHeight = $(document).height();
$(window).mousemove(function(e) {
var left = Ox.constrain(offset.left - x + e.clientX, 24 - options.width, documentWidth - 24),
top = Ox.constrain(offset.top - y + e.clientY, -24 - options.height, documentHeight - 24);
$("*").css({
WebkitUserSelect: "none"
});
var left = Ox.limit(offset.left - x + e.clientX, 24 - options.width, documentWidth - 24),
top = Ox.limit(offset.top - y + e.clientY, 24, documentHeight - 24);
that.css({
left: left + "px",
top: top + "px"
@ -1040,9 +1043,13 @@ requires
});
$(window).one("mouseup", function() {
$(window).unbind("mousemove");
$("*").css({
WebkitUserSelect: "auto"
});
});
})
.appendTo(that);
that.$title = new Ox.Element().addClass("OxTitle").html(options.title).appendTo(that.$titlebar);
that.$content = new Ox.Container()
.addClass("OxContent")
.css({
@ -1058,6 +1065,12 @@ requires
});
options.buttons[0].focus();
that.$layer = $(".OxLayer"); // fixme: lazy loading of layer is fine, but save in var, dont look up
that.$buttons = options.buttons; // fixme: publicy accessible buttons, or dialog methods for manipulation?
self.onChange = function(key, value) {
if (key == "title") {
that.$title.html(value);
}
}
that.append = function($element) {
that.$content.append($element);
return that;
@ -1184,6 +1197,11 @@ requires
}
}
}
that.toggleDisabled = function() {
that.options({
enabled: !self.options.disabled
});
}
that.toggleSelected = function() {
that.options({
selected: !self.options.selected