1
0
Fork 0
forked from 0x2620/oxjs

add icon to application error dialog

This commit is contained in:
rlx 2011-08-17 11:39:33 +00:00
commit 31149d7ecc
5 changed files with 82 additions and 29 deletions

View file

@ -31,6 +31,7 @@ Ox.Dialog = function(options, self) {
fixedRatio: false,
focus: true,
height: 200,
keys: {},
maxHeight: Infinity,
maximizeButton: false,
maxWidth: Infinity,
@ -41,6 +42,14 @@ Ox.Dialog = function(options, self) {
})
.options(options || {})
.addClass('OxDialog')
.bindEvent({
key_enter: function() {
keypress('enter');
},
key_escape: function() {
keypress('escape');
}
})
.hide()
.appendTo(Ox.UI.$body);
@ -128,24 +137,7 @@ Ox.Dialog = function(options, self) {
self.$buttonsRight = $('<div>')
.addClass('OxButtonsRight')
.appendTo(self.$buttonsbar.$element);
var buttonsLeft,
buttonsRight,
index = Ox.map(self.options.buttons, function(v, i) {
return Ox.isEmpty(v) ? i : null;
})[0];
if (index) {
buttonsLeft = Ox.sub(self.options.buttons, 0, index);
buttonsRight = Ox.sub(self.options.buttons, index + 1);
} else {
buttonsLeft = [];
buttonsRight = self.options.buttons;
}
buttonsLeft.forEach(function($button) {
$button.addClass('OxLeft').appendTo(self.$buttonsLeft);
});
buttonsRight.forEach(function($button) {
$button.addClass('OxRight').appendTo(self.$buttonsRight);
});
setButtons();
}
if (!self.options.fixedCenter) {
@ -263,6 +255,22 @@ Ox.Dialog = function(options, self) {
that.unwrap();
}
function getButtonById(id) {
var ret = null;
Ox.forEach(self.options.buttons, function(button) {
if (button.options && button.options('id') == id) {
ret = button;
return false;
}
});
return ret;
}
function keypress(key) {
var id = self.options.keys[key];
id && getButtonById(id).$element.trigger('click');
}
function maximize() {
var offset = that.offset();
decenter();
@ -501,13 +509,36 @@ Ox.Dialog = function(options, self) {
that.unwrap();
}
function setButtons() {
var buttonsLeft,
buttonsRight,
index = Ox.map(self.options.buttons, function(v, i) {
return Ox.isEmpty(v) ? i : null;
})[0];
if (index) {
buttonsLeft = Ox.sub(self.options.buttons, 0, index);
buttonsRight = Ox.sub(self.options.buttons, index + 1);
} else {
buttonsLeft = [];
buttonsRight = self.options.buttons;
}
self.$buttonsLeft.empty();
buttonsLeft.forEach(function($button) {
$button.addClass('OxLeft').appendTo(self.$buttonsLeft);
});
self.$buttonsRight.empty();
buttonsRight.forEach(function($button) {
$button.addClass('OxRight').appendTo(self.$buttonsRight);
});
}
function setContent() {
var animate = !!self.$content
isImage = !self.options.content.ox && self.options.content.is('img');
if (animate) {
self.$content.animate({
opacity: 0
}, 100, function() {
}, 250, function() {
$(this).remove() // fixme: removeElement?
});
self.options.content.css({
@ -532,7 +563,7 @@ Ox.Dialog = function(options, self) {
);
animate && self.options.content.animate({
opacity: 1
}, 100);
}, 250);
}
function setCSS(css, animate) {
@ -591,7 +622,9 @@ Ox.Dialog = function(options, self) {
}
self.setOption = function(key, value) {
if (key == 'content') {
if (key == 'buttons') {
setButtons();
} else if (key == 'content') {
setContent();
} else if (key == 'height') {
setMinAndMax();
@ -631,6 +664,16 @@ Ox.Dialog = function(options, self) {
return that;
};
that.disableButton = function(id) {
getButtonById(id).options({disabled: true});
return that;
};
that.enableButton = function(id) {
getButtonById(id).options({disabled: false});
return that;
};
that.open = function() {
self.initialHeight = self.options.height;
self.initialWidth = self.options.width;