2011-07-29 20:48:43 +02:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
2011-05-16 12:49:48 +02:00
|
|
|
|
2011-11-05 17:46:53 +01:00
|
|
|
'use strict';
|
|
|
|
|
2011-05-16 12:49:48 +02: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-23 00:03:10 +02:00
|
|
|
Ox.ListItem = function(options, self) {
|
|
|
|
|
2011-06-19 19:48:32 +02:00
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
2012-01-17 23:04:33 +05:30
|
|
|
.defaults({
|
|
|
|
construct: null,
|
|
|
|
data: {},
|
|
|
|
draggable: false,
|
|
|
|
position: 0,
|
|
|
|
unique: ''
|
|
|
|
})
|
|
|
|
.options(options || {});
|
2011-04-23 00:03:10 +02:00
|
|
|
|
|
|
|
constructItem();
|
|
|
|
|
|
|
|
function constructItem(update) {
|
|
|
|
var $element = self.options.construct(self.options.data)
|
2011-11-11 15:48:54 +00:00
|
|
|
.addClass('OxItem')
|
2011-04-23 00:03:10 +02:00
|
|
|
.data({
|
|
|
|
id: self.options.data[self.options.unique],
|
|
|
|
position: self.options.position
|
|
|
|
});
|
|
|
|
if (update) {
|
|
|
|
that.$element.hasClass('OxSelected') && $element.addClass('OxSelected');
|
|
|
|
}
|
2011-11-04 22:14:30 +00:00
|
|
|
that.setElement($element);
|
2011-04-23 00:03:10 +02:00
|
|
|
}
|
|
|
|
|
2011-04-29 14:40:51 +02:00
|
|
|
self.setOption = function(key, value) {
|
2011-04-23 00:03:10 +02:00
|
|
|
if (key == 'data') {
|
|
|
|
constructItem(true);
|
|
|
|
}
|
2011-06-19 19:48:32 +02:00
|
|
|
};
|
2011-04-23 00:03:10 +02:00
|
|
|
|
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|