oxjs/source/Ox.UI/js/List/Ox.ListItem.js

59 lines
1.6 KiB
JavaScript
Raw Normal View History

2011-07-29 18:48:43 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
2011-05-16 10:49:48 +00:00
/*@
Ox.ListItem <f:Ox.Element> ListItem Object
() -> <f> ListItem Object
(options) -> <f> ListItem Object
(options, self) -> <f> ListItem Object
options <o> Options object
construct <f> construct function
data <o|{}> item data
draggable <b|false> can be dragged
position <n|0> item position
unique <s|''> unique key
self <o> shared private variable
cancel <!> triggered if cancel button is pressed
save <!> triggered if save button is pressed
@*/
2011-04-22 22:03:10 +00:00
Ox.ListItem = function(options, self) {
self = self || {};
var that = Ox.Element({}, self)
2011-04-22 22:03:10 +00:00
.defaults({
2011-08-07 02:33:26 +00:00
construct: null,
2011-04-22 22:03:10 +00:00
data: {},
draggable: false,
position: 0,
unique: ''
})
.options(options || {});
constructItem();
function constructItem(update) {
var $element = self.options.construct(self.options.data)
.addClass('OxItem LISTITEM')
2011-04-22 22:03:10 +00:00
.data({
id: self.options.data[self.options.unique],
position: self.options.position
});
if (update) {
that.$element.hasClass('OxSelected') && $element.addClass('OxSelected');
// that.$element.replaceWith($element);
2011-04-22 22:03:10 +00:00
}
// that.$element = $element;
that.setElement($element);
Ox.print('LISTITEM', that.$element.data('id'))
2011-04-22 22:03:10 +00:00
}
2011-04-29 12:40:51 +00:00
self.setOption = function(key, value) {
2011-04-22 22:03:10 +00:00
if (key == 'data') {
constructItem(true);
}
};
2011-04-22 22:03:10 +00:00
return that;
};