2012-12-10 00:01:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/*@
|
|
|
|
Ox.CustomList <f> Custom List Widget
|
|
|
|
experimental
|
|
|
|
@*/
|
|
|
|
|
|
|
|
Ox.CustomList = function(options, self) {
|
|
|
|
|
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
|
|
|
.defaults({
|
|
|
|
draggable: false,
|
|
|
|
item: null,
|
|
|
|
itemHeight: 32,
|
|
|
|
items: null,
|
|
|
|
itemWidth: 256,
|
|
|
|
keys: [],
|
|
|
|
max: -1,
|
|
|
|
min: 0,
|
|
|
|
pageLength: 100,
|
|
|
|
query: {conditions: [], operator: '&'},
|
2012-12-18 10:47:40 +00:00
|
|
|
resize: null,
|
2012-12-10 00:01:29 +00:00
|
|
|
scrollbarVisible: false,
|
|
|
|
selected: [],
|
|
|
|
sort: [],
|
|
|
|
sortable: false,
|
|
|
|
sums: [],
|
|
|
|
unique: ''
|
|
|
|
})
|
|
|
|
.options(options || {})
|
|
|
|
.update({
|
2012-12-10 16:46:48 +00:00
|
|
|
items: function() {
|
|
|
|
self.$list.options({items: self.options.items});
|
|
|
|
},
|
2012-12-18 10:47:40 +00:00
|
|
|
itemWidth: function() {
|
2014-09-25 16:35:17 +00:00
|
|
|
var width = self.options.itemWidth - Ox.SCROLLBAR_SIZE;
|
2012-12-18 10:47:40 +00:00
|
|
|
if (self.options.resize) {
|
2014-09-24 18:17:33 +00:00
|
|
|
that.find('.OxItem').each(function(element) {
|
2012-12-18 10:47:40 +00:00
|
|
|
self.options.resize($(this), width);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2012-12-18 14:04:59 +00:00
|
|
|
query: function() {
|
|
|
|
self.$list.options({query: self.options.query});
|
|
|
|
},
|
2012-12-10 16:46:48 +00:00
|
|
|
selected: function() {
|
|
|
|
self.$list.options({selected: self.options.selected});
|
|
|
|
// FIXME: TableList doesn't trigger event here
|
|
|
|
that.triggerEvent('select', {ids: self.options.selected});
|
2012-12-18 21:48:27 +00:00
|
|
|
},
|
|
|
|
sort: function() {
|
|
|
|
self.$list.options({sort: self.options.sort});
|
2012-12-10 16:46:48 +00:00
|
|
|
}
|
2012-12-10 00:01:29 +00:00
|
|
|
})
|
|
|
|
.addClass('OxCustomList');
|
|
|
|
|
|
|
|
self.$list = Ox.List({
|
|
|
|
construct: function(data) {
|
2012-12-18 10:47:40 +00:00
|
|
|
return self.options.item(
|
2014-09-25 16:35:17 +00:00
|
|
|
data, self.options.itemWidth - Ox.SCROLLBAR_SIZE
|
2012-12-18 10:47:40 +00:00
|
|
|
).addClass('OxTarget');
|
2012-12-10 00:01:29 +00:00
|
|
|
},
|
|
|
|
draggable: self.options.draggable,
|
|
|
|
itemHeight: self.options.itemHeight,
|
|
|
|
itemWidth: self.options.itemWidth
|
2014-09-25 16:35:17 +00:00
|
|
|
- self.options.scrollbarVisible * Ox.SCROLLBAR_SIZE,
|
2012-12-10 00:01:29 +00:00
|
|
|
items: self.options.items,
|
|
|
|
keys: self.options.keys.concat(self.options.unique),
|
|
|
|
max: self.options.max,
|
|
|
|
min: self.options.min,
|
|
|
|
orientation: 'vertical',
|
|
|
|
pageLength: self.options.pageLength,
|
2012-12-18 21:48:27 +00:00
|
|
|
query: Ox.clone(self.options.query, true),
|
2012-12-10 00:01:29 +00:00
|
|
|
selected: self.options.selected,
|
2012-12-18 21:48:27 +00:00
|
|
|
sort: Ox.clone(self.options.sort, true),
|
2012-12-10 00:01:29 +00:00
|
|
|
sortable: self.options.sortable,
|
|
|
|
sums: self.options.sums,
|
|
|
|
type: 'text',
|
|
|
|
unique: self.options.unique
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
top: 0,
|
|
|
|
overflowY: (self.options.scrollbarVisible ? 'scroll' : 'hidden')
|
|
|
|
})
|
|
|
|
.bindEvent(function(data, event) {
|
2012-12-10 16:46:48 +00:00
|
|
|
if (event == 'select') {
|
|
|
|
self.options.selected = data.ids;
|
|
|
|
}
|
2012-12-10 00:01:29 +00:00
|
|
|
that.triggerEvent(event, data);
|
|
|
|
})
|
|
|
|
.appendTo(that);
|
|
|
|
|
2012-12-11 15:36:38 +00:00
|
|
|
that.api = self.$list.options('items');
|
|
|
|
|
2012-12-10 16:46:48 +00:00
|
|
|
/*@
|
|
|
|
gainFocus <f> gain Focus
|
|
|
|
@*/
|
|
|
|
that.gainFocus = function() {
|
|
|
|
self.$list.gainFocus();
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2014-02-12 13:56:54 +00:00
|
|
|
that.getPasteIndex = function() {
|
|
|
|
return self.$list.getPasteIndex();
|
|
|
|
};
|
|
|
|
|
2012-12-10 16:46:48 +00:00
|
|
|
/*@
|
|
|
|
hasFocus <f> has Focus
|
|
|
|
@*/
|
|
|
|
that.hasFocus = function() {
|
|
|
|
return self.$list.hasFocus();
|
|
|
|
};
|
|
|
|
|
2013-08-02 12:23:43 +00:00
|
|
|
that.invertSelection = function() {
|
|
|
|
self.$list.invertSelection();
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-12-10 16:46:48 +00:00
|
|
|
/*@
|
|
|
|
loseFocus <f> lose Focus
|
|
|
|
@*/
|
|
|
|
that.loseFocus = function() {
|
|
|
|
self.$list.loseFocus();
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2013-08-02 12:23:43 +00:00
|
|
|
that.selectAll = function() {
|
|
|
|
self.$list.selectAll();
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-12-18 10:47:40 +00:00
|
|
|
/*@
|
|
|
|
selectPosition <f> select position
|
|
|
|
@*/
|
|
|
|
that.selectPosition = function(pos) {
|
|
|
|
self.$list.selectPosition(pos);
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2014-02-02 12:34:12 +00:00
|
|
|
that.selectSelected = function(offset) {
|
|
|
|
that.$list.selectSelected(offset);
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-12-18 10:47:40 +00:00
|
|
|
/*@
|
|
|
|
size <f> size
|
|
|
|
@*/
|
|
|
|
that.size = function() {
|
|
|
|
self.$list.size();
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-12-10 00:01:29 +00:00
|
|
|
return that;
|
|
|
|
|
2014-09-24 18:17:33 +00:00
|
|
|
};
|