2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-05-16 10:49:48 +00:00
|
|
|
/*@
|
2012-05-31 10:32:54 +00:00
|
|
|
Ox.ListItem <f> ListItem Object
|
2011-05-16 10:49:48 +00:00
|
|
|
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
|
2012-07-04 11:29:18 +00:00
|
|
|
self <o> Shared private variable
|
|
|
|
([options[, self]]) -> <o:Ox.Element> ListItem Object
|
|
|
|
cancel <!> triggered if cancel button is pressed
|
|
|
|
save <!> triggered if save button is pressed
|
2011-05-16 10:49:48 +00:00
|
|
|
@*/
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
Ox.ListItem = function(options, self) {
|
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
2012-01-17 17:34:33 +00:00
|
|
|
.defaults({
|
|
|
|
construct: null,
|
|
|
|
data: {},
|
|
|
|
draggable: false,
|
|
|
|
position: 0,
|
|
|
|
unique: ''
|
|
|
|
})
|
2012-05-28 19:35:41 +00:00
|
|
|
.options(options || {})
|
|
|
|
.update({
|
|
|
|
data: function() {
|
|
|
|
constructItem(true);
|
2013-07-14 13:39:39 +00:00
|
|
|
},
|
|
|
|
position: function() {
|
2014-09-22 11:28:14 +00:00
|
|
|
that.data({position: self.options.position});
|
2012-05-28 19:35:41 +00:00
|
|
|
}
|
|
|
|
});
|
2011-04-22 22:03:10 +00: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-22 22:03:10 +00:00
|
|
|
.data({
|
|
|
|
id: self.options.data[self.options.unique],
|
|
|
|
position: self.options.position
|
|
|
|
});
|
|
|
|
if (update) {
|
2014-09-22 11:28:14 +00:00
|
|
|
that.hasClass('OxSelected') && $element.addClass('OxSelected');
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2011-11-04 22:14:30 +00:00
|
|
|
that.setElement($element);
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|