2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
Ox.InfoList <function> Info List
|
|
|
|
(options[, self]) -> <o> Info List
|
|
|
|
options <o> Options
|
|
|
|
self <o> Shared private variable
|
|
|
|
@*/
|
2011-08-19 06:41:48 +00:00
|
|
|
Ox.InfoList = function(options, self) {
|
2011-11-03 15:42:41 +00:00
|
|
|
|
2011-08-19 06:41:48 +00:00
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
|
|
|
.defaults({
|
|
|
|
borderRadius: 0,
|
|
|
|
defaultRatio: 1,
|
|
|
|
draggable: false,
|
|
|
|
id: '',
|
|
|
|
item: null,
|
|
|
|
items: null,
|
|
|
|
keys: [],
|
|
|
|
max: -1,
|
|
|
|
min: 0,
|
|
|
|
selected: [],
|
|
|
|
size: 192,
|
|
|
|
sort: [],
|
|
|
|
unique: ''
|
|
|
|
})
|
|
|
|
.options(options || {})
|
|
|
|
|
2012-04-22 11:50:57 +00:00
|
|
|
//Ox.print('INFO LIST FIND', self.options.find);
|
2012-02-01 11:57:21 +00:00
|
|
|
|
2011-10-17 10:23:16 +00:00
|
|
|
self.iconSize = Math.round(self.options.size * 2/3);
|
2011-08-19 06:41:48 +00:00
|
|
|
self.itemHeight = self.options.size;
|
|
|
|
|
2012-04-22 11:50:57 +00:00
|
|
|
that.setElement(
|
|
|
|
Ox.List({
|
2011-08-19 06:41:48 +00:00
|
|
|
construct: constructItem,
|
|
|
|
draggable: self.options.draggable,
|
|
|
|
id: self.options.id,
|
|
|
|
itemHeight: self.itemHeight,
|
|
|
|
items: self.options.items,
|
|
|
|
itemWidth: getItemWidth(),
|
|
|
|
keys: self.options.keys,
|
|
|
|
max: self.options.max,
|
|
|
|
min: self.options.min,
|
|
|
|
orientation: 'vertical',
|
|
|
|
pageLength: 10,
|
|
|
|
selected: self.options.selected,
|
|
|
|
sort: self.options.sort,
|
|
|
|
type: 'info',
|
|
|
|
unique: self.options.unique
|
2011-10-16 12:32:02 +00:00
|
|
|
}, Ox.clone(self))
|
|
|
|
.addClass('OxInfoList')
|
|
|
|
.bindEvent({
|
|
|
|
select: function() {
|
|
|
|
self.options.selected = that.$element.options('selected');
|
|
|
|
}
|
2012-04-22 11:50:57 +00:00
|
|
|
})
|
|
|
|
);
|
2011-08-19 06:41:48 +00:00
|
|
|
|
|
|
|
updateKeys();
|
|
|
|
|
|
|
|
function constructItem(data) {
|
|
|
|
var isEmpty = Ox.isEmpty(data),
|
|
|
|
data = !isEmpty
|
|
|
|
? self.options.item(data, self.options.sort, self.options.size)
|
|
|
|
: {
|
|
|
|
icon: {
|
2011-10-17 10:23:16 +00:00
|
|
|
width: Math.round(self.iconSize * (
|
2011-08-19 06:41:48 +00:00
|
|
|
self.options.defaultRatio >= 1 ? 1 : self.options.defaultRatio
|
|
|
|
)),
|
2011-10-17 10:23:16 +00:00
|
|
|
height: Math.round(self.iconSize / (
|
2011-08-19 06:41:48 +00:00
|
|
|
self.options.defaultRatio <= 1 ? 1 : self.options.defaultRatio
|
|
|
|
))
|
|
|
|
},
|
|
|
|
info: {}
|
2012-02-01 11:57:21 +00:00
|
|
|
},
|
|
|
|
$icon = Ox.Element()
|
2011-08-19 06:41:48 +00:00
|
|
|
.css({
|
|
|
|
float: 'left',
|
2011-10-16 12:32:02 +00:00
|
|
|
width: '132px',
|
2011-10-16 12:46:27 +00:00
|
|
|
height: '192px',
|
|
|
|
margin: '4px 2px 4px 2px',
|
2011-10-16 12:32:02 +00:00
|
|
|
//background: 'blue'
|
2011-08-19 06:41:48 +00:00
|
|
|
})
|
|
|
|
.append(
|
|
|
|
Ox.IconItem(Ox.extend(data.icon, {
|
|
|
|
borderRadius: self.options.borderRadius,
|
2011-10-17 10:23:16 +00:00
|
|
|
iconHeight: self.iconSize,
|
|
|
|
iconWidth: self.iconSize,
|
|
|
|
imageHeight: data.icon.height,
|
|
|
|
imageWidth: data.icon.width,
|
2011-08-19 06:41:48 +00:00
|
|
|
itemHeight: self.itemHeight,
|
2011-10-17 10:23:16 +00:00
|
|
|
itemWidth: 128
|
2011-08-19 06:41:48 +00:00
|
|
|
}))
|
2011-10-16 12:32:02 +00:00
|
|
|
.addClass('OxInfoIcon')
|
2011-08-19 06:41:48 +00:00
|
|
|
.css({
|
|
|
|
position: 'absolute'
|
|
|
|
})
|
|
|
|
),
|
|
|
|
$info = Ox.Element()
|
|
|
|
.css({
|
|
|
|
float: 'left',
|
2011-10-17 10:23:16 +00:00
|
|
|
width: getItemWidth() - 144 + 'px',
|
|
|
|
height: 196 + 'px',
|
2011-10-16 12:32:02 +00:00
|
|
|
//background: 'green'
|
2011-08-19 06:41:48 +00:00
|
|
|
}),
|
|
|
|
$infobox = Ox.Element()
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
2011-10-17 10:23:16 +00:00
|
|
|
width: getItemWidth() - 144 + 'px',
|
|
|
|
height: 196 + 'px',
|
2011-10-17 15:13:12 +00:00
|
|
|
marginTop: '-2px',
|
2011-08-19 06:41:48 +00:00
|
|
|
overflow: 'hidden'
|
|
|
|
})
|
2011-11-05 17:27:11 +00:00
|
|
|
.appendTo($info),
|
2011-08-19 06:41:48 +00:00
|
|
|
$item = Ox.Element()
|
|
|
|
.css({
|
|
|
|
width: getItemWidth() - 8 + 'px',
|
2011-10-16 12:46:27 +00:00
|
|
|
height: 196 + 'px',
|
2011-10-16 12:32:02 +00:00
|
|
|
margin: '4px',
|
|
|
|
//background: 'red'
|
2011-08-19 06:41:48 +00:00
|
|
|
})
|
|
|
|
.append($icon)
|
|
|
|
.append($info);
|
|
|
|
if (!isEmpty) {
|
|
|
|
var $element = data.info.element(Ox.extend(data.info.options, {
|
|
|
|
width: getItemWidth() - 152
|
|
|
|
}))
|
2011-10-17 10:23:16 +00:00
|
|
|
.addClass('OxInfoElement');
|
|
|
|
data.info.css && $element.css(data.info.css);
|
|
|
|
data.info.events && $element.bindEvent(data.info.events);
|
|
|
|
$element.addClass('OxId' + $element.id); // fixme: needed?
|
2011-08-19 06:41:48 +00:00
|
|
|
$infobox.append($element);
|
|
|
|
}
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getItemWidth(cached) {
|
|
|
|
if (!cached) {
|
|
|
|
self.cachedWidth = that.$element.width() - Ox.UI.SCROLLBAR_SIZE;
|
|
|
|
} else if (!self.cachedWidth || self.cachedWidthTime < +new Date() - 5000) {
|
|
|
|
self.cachedWidth = that.$element.width() - Ox.UI.SCROLLBAR_SIZE;
|
|
|
|
self.cachedWidthTime = +new Date();
|
|
|
|
}
|
|
|
|
return self.cachedWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateKeys() {
|
|
|
|
that.$element.options({
|
2012-04-22 11:50:57 +00:00
|
|
|
keys: Ox.unique(Ox.merge(
|
|
|
|
self.options.sort[0].key,
|
|
|
|
self.options.keys
|
|
|
|
))
|
2011-08-19 06:41:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
self.setOption = function(key, value) {
|
|
|
|
if (key == 'items') {
|
|
|
|
that.$element.options(key, value);
|
|
|
|
} else if (key == 'selected') {
|
|
|
|
that.$element.options(key, value);
|
|
|
|
} else if (key == 'sort') {
|
2012-04-22 11:50:57 +00:00
|
|
|
updateKeys();
|
2011-08-19 06:41:48 +00:00
|
|
|
that.$element.options(key, value);
|
|
|
|
} else if (key == 'width') {
|
|
|
|
var width = getItemWidth();
|
|
|
|
$('.OxInfoElement').each(function() {
|
|
|
|
var $parent = $(this).parent(),
|
|
|
|
id = parseInt(/OxId(.*?)$/.exec(this.className)[1]);
|
2011-10-17 10:23:16 +00:00
|
|
|
$parent.css({width: width - 144});
|
|
|
|
$parent.parent().css({width: width - 144});
|
2011-08-19 06:41:48 +00:00
|
|
|
$parent.parent().parent().css({width: width - 8});
|
2011-11-04 15:54:28 +00:00
|
|
|
Ox.Log('List', '@@@', this.className, id)
|
2011-08-19 06:41:48 +00:00
|
|
|
Ox.UI.elements[id].options({width: width - 152});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
closePreivew <f> closePreview
|
|
|
|
@*/
|
2011-08-19 06:41:48 +00:00
|
|
|
that.closePreview = function() {
|
|
|
|
that.$element.closePreview();
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
gainFocus <f> gainFocus
|
|
|
|
@*/
|
2012-04-24 08:21:00 +00:00
|
|
|
that.gainFocus = function() {
|
|
|
|
that.$element.gainFocus();
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
hasFocus <f> hasFocus
|
|
|
|
@*/
|
2012-04-24 08:21:00 +00:00
|
|
|
that.hasFocus = function() {
|
|
|
|
return that.$element.hasFocus();
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
loseFocus <f> loseFocus
|
|
|
|
@*/
|
2012-04-24 08:21:00 +00:00
|
|
|
that.loseFocus = function() {
|
|
|
|
that.$element.loseFocus();
|
|
|
|
return that;
|
|
|
|
};
|
2011-10-19 10:49:19 +00:00
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
paste <f> paste
|
|
|
|
@*/
|
2011-10-16 12:32:02 +00:00
|
|
|
that.paste = function(data) {
|
|
|
|
that.$element.paste(data);
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
reloadList <f> reloadList
|
|
|
|
@*/
|
2011-10-20 16:49:42 +00:00
|
|
|
that.reloadList = function(stayAtPosition) {
|
|
|
|
that.$element.reloadList(stayAtPosition);
|
2011-10-16 12:32:02 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
scrollToSelection <f> scrollToSelection
|
|
|
|
@*/
|
2011-10-16 12:32:02 +00:00
|
|
|
that.scrollToSelection = function() {
|
|
|
|
that.$element.scrollToSelection();
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
size <f> size
|
|
|
|
@*/
|
2011-10-16 12:32:02 +00:00
|
|
|
that.size = function() {
|
|
|
|
that.$element.size();
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
sortList <f> sortList
|
|
|
|
(key, operator) -> <o>
|
|
|
|
@*/
|
2011-10-16 12:32:02 +00:00
|
|
|
that.sortList = function(key, operator) {
|
|
|
|
self.options.sort = [{
|
|
|
|
key: key,
|
|
|
|
operator: operator
|
|
|
|
}];
|
|
|
|
updateKeys();
|
|
|
|
that.$element.sortList(key, operator);
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
value <f> value
|
|
|
|
(id) -> values
|
|
|
|
(id, key) -> value
|
|
|
|
(id, key, value) -> <o>
|
|
|
|
@*/
|
2011-10-16 12:32:02 +00:00
|
|
|
that.value = function(id, key, value) {
|
|
|
|
// fixme: make this accept id, {k: v, ...}
|
|
|
|
if (arguments.length == 1) {
|
|
|
|
return that.$element.value(id);
|
|
|
|
} else if (arguments.length == 2) {
|
|
|
|
return that.$element.value(id, key);
|
|
|
|
} else {
|
|
|
|
that.$element.value(id, key, value);
|
|
|
|
return that;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-08-19 06:41:48 +00:00
|
|
|
return that;
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
};
|