2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
2012-05-31 10:32:54 +00:00
|
|
|
Ox.InfoList <f> Info List
|
2012-05-21 10:38:18 +00:00
|
|
|
options <o> Options
|
|
|
|
self <o> Shared private variable
|
2012-07-04 11:29:18 +00:00
|
|
|
([options[, self]]) -> <o:Ox.List> Info List
|
2012-05-21 10:38:18 +00:00
|
|
|
@*/
|
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,
|
2012-06-19 12:15:20 +00:00
|
|
|
query: {conditions: [], operator: '&'},
|
2012-06-29 12:19:34 +00:00
|
|
|
selectAsYouType: '',
|
2011-08-19 06:41:48 +00:00
|
|
|
selected: [],
|
|
|
|
size: 192,
|
|
|
|
sort: [],
|
2012-10-26 14:46:14 +00:00
|
|
|
sums: [],
|
2011-08-19 06:41:48 +00:00
|
|
|
unique: ''
|
|
|
|
})
|
|
|
|
.options(options || {})
|
2012-05-28 19:35:41 +00:00
|
|
|
.update({
|
|
|
|
items: function() {
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.options({items: self.options.items});
|
2012-06-19 12:15:20 +00:00
|
|
|
},
|
|
|
|
query: function() {
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.options({query: self.options.query});
|
2012-05-28 19:35:41 +00:00
|
|
|
},
|
|
|
|
selected: function() {
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.options({selected: self.options.selected});
|
2012-05-28 19:35:41 +00:00
|
|
|
},
|
|
|
|
sort: function() {
|
|
|
|
updateKeys();
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.options({sort: self.options.sort});
|
2012-05-28 19:35:41 +00:00
|
|
|
},
|
|
|
|
width: function() {
|
2014-09-24 08:26:51 +00:00
|
|
|
// FIXME: don't use classname for this lookup
|
2012-05-28 19:35:41 +00:00
|
|
|
var width = getItemWidth();
|
|
|
|
$('.OxInfoElement').each(function() {
|
|
|
|
var $parent = $(this).parent(),
|
2012-06-13 08:37:07 +00:00
|
|
|
id = parseInt(/OxId(.*?)$/.exec(this.className)[1], 10);
|
2012-05-28 19:35:41 +00:00
|
|
|
$parent.css({width: width - 144});
|
|
|
|
$parent.parent().css({width: width - 144});
|
|
|
|
$parent.parent().parent().css({width: width - 8});
|
2014-09-25 17:40:29 +00:00
|
|
|
Ox.$elements[id].options({width: width - 152});
|
2012-05-28 19:35:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2011-08-19 06:41:48 +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(
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list = 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,
|
2012-06-19 12:15:20 +00:00
|
|
|
query: self.options.query,
|
2012-06-29 12:19:34 +00:00
|
|
|
selectAsYouType: self.options.selectAsYouType,
|
2011-08-19 06:41:48 +00:00
|
|
|
selected: self.options.selected,
|
|
|
|
sort: self.options.sort,
|
2012-10-26 14:46:14 +00:00
|
|
|
sums: self.options.sums,
|
2011-08-19 06:41:48 +00:00
|
|
|
type: 'info',
|
|
|
|
unique: self.options.unique
|
2012-06-30 09:20:37 +00:00
|
|
|
})
|
2011-10-16 12:32:02 +00:00
|
|
|
.addClass('OxInfoList')
|
2012-06-30 09:20:37 +00:00
|
|
|
.bindEvent(function(data, event) {
|
2012-06-30 16:12:05 +00:00
|
|
|
if (event == 'select') {
|
|
|
|
self.options.selected = data.ids;
|
|
|
|
}
|
2012-06-30 09:20:37 +00:00
|
|
|
that.triggerEvent(event, data);
|
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',
|
2013-08-05 22:02:16 +00:00
|
|
|
margin: '2px'
|
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',
|
2012-05-26 15:48:19 +00:00
|
|
|
height: 196 + 'px'
|
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',
|
2012-05-26 15:48:19 +00:00
|
|
|
margin: '4px'
|
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);
|
2012-06-13 08:37:07 +00:00
|
|
|
$element.addClass('OxId' + $element.oxid); // fixme: needed?
|
2011-08-19 06:41:48 +00:00
|
|
|
$infobox.append($element);
|
|
|
|
}
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getItemWidth(cached) {
|
|
|
|
if (!cached) {
|
2014-09-25 19:56:44 +00:00
|
|
|
self.cachedWidth = that.width() - Ox.SCROLLBAR_SIZE;
|
2011-08-19 06:41:48 +00:00
|
|
|
} else if (!self.cachedWidth || self.cachedWidthTime < +new Date() - 5000) {
|
2014-09-25 19:56:44 +00:00
|
|
|
self.cachedWidth = that.width() - Ox.SCROLLBAR_SIZE;
|
2011-08-19 06:41:48 +00:00
|
|
|
self.cachedWidthTime = +new Date();
|
|
|
|
}
|
|
|
|
return self.cachedWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateKeys() {
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.options({
|
2012-05-24 07:45:33 +00:00
|
|
|
keys: Ox.unique(
|
|
|
|
[self.options.sort[0].key].concat(self.options.keys)
|
2012-05-24 07:46:42 +00:00
|
|
|
)
|
2011-08-19 06:41:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
2012-05-28 19:35:41 +00:00
|
|
|
closePreview <f> closePreview
|
2012-05-21 10:38:18 +00:00
|
|
|
@*/
|
2011-08-19 06:41:48 +00:00
|
|
|
that.closePreview = function() {
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.closePreview();
|
2011-08-19 06:41:48 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
gainFocus <f> gainFocus
|
|
|
|
@*/
|
2012-04-24 08:21:00 +00:00
|
|
|
that.gainFocus = function() {
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.gainFocus();
|
2012-04-24 08:21:00 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2014-02-12 13:56:54 +00:00
|
|
|
that.getPasteIndex = function() {
|
2014-09-24 18:17:57 +00:00
|
|
|
return self.$list.getPasteIndex();
|
2014-02-12 13:56:54 +00:00
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
hasFocus <f> hasFocus
|
|
|
|
@*/
|
2012-04-24 08:21:00 +00:00
|
|
|
that.hasFocus = function() {
|
2014-09-24 18:17:57 +00:00
|
|
|
return self.$list.hasFocus();
|
2012-04-24 08:21:00 +00:00
|
|
|
};
|
|
|
|
|
2013-08-02 12:23:43 +00:00
|
|
|
that.invertSelection = function() {
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.invertSelection();
|
2013-08-02 12:23:43 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
loseFocus <f> loseFocus
|
|
|
|
@*/
|
2012-04-24 08:21:00 +00:00
|
|
|
that.loseFocus = function() {
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.loseFocus();
|
2012-04-24 08:21:00 +00:00
|
|
|
return that;
|
|
|
|
};
|
2011-10-19 10:49:19 +00:00
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
reloadList <f> reloadList
|
|
|
|
@*/
|
2011-10-20 16:49:42 +00:00
|
|
|
that.reloadList = function(stayAtPosition) {
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.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() {
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.scrollToSelection();
|
2011-10-16 12:32:02 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2013-08-02 12:23:43 +00:00
|
|
|
that.selectAll = function() {
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.selectAll();
|
2013-08-02 12:23:43 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2014-02-02 12:34:12 +00:00
|
|
|
that.selectPosition = function(pos) {
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.selectPosition(pos);
|
2014-02-02 12:34:12 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
|
|
|
that.selectSelected = function(offset) {
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.selectSelected(offset);
|
2014-02-02 12:34:12 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
size <f> size
|
|
|
|
@*/
|
2011-10-16 12:32:02 +00:00
|
|
|
that.size = function() {
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.size();
|
2012-08-30 22:16:26 +00:00
|
|
|
return that;
|
2011-10-16 12:32:02 +00:00
|
|
|
};
|
|
|
|
|
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();
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.sortList(key, operator);
|
2011-10-16 12:32:02 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
value <f> value
|
|
|
|
(id) -> values
|
|
|
|
(id, key) -> value
|
|
|
|
(id, key, value) -> <o>
|
2013-12-01 13:55:57 +00:00
|
|
|
(id, {key: value}) -> <o>
|
2012-05-21 10:38:18 +00:00
|
|
|
@*/
|
2013-12-01 13:55:57 +00:00
|
|
|
that.value = function() {
|
|
|
|
var args = Ox.slice(arguments),
|
|
|
|
id = args.shift();
|
2011-10-16 12:32:02 +00:00
|
|
|
if (arguments.length == 1) {
|
2014-09-24 18:17:57 +00:00
|
|
|
return self.$list.value(id);
|
2013-12-01 13:55:57 +00:00
|
|
|
} else if (arguments.length == 2 && Ox.isString(arguments[1])) {
|
2014-09-24 18:17:57 +00:00
|
|
|
return self.$list.value(id, arguments[1]);
|
2011-10-16 12:32:02 +00:00
|
|
|
} else {
|
2013-12-01 13:55:57 +00:00
|
|
|
Ox.forEach(Ox.makeObject(args), function(value, key) {
|
2014-09-24 18:17:57 +00:00
|
|
|
self.$list.value(id, key, value);
|
2013-12-01 13:55:57 +00:00
|
|
|
});
|
2011-10-16 12:32:02 +00:00
|
|
|
return that;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-08-19 06:41:48 +00:00
|
|
|
return that;
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
};
|