2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-05-16 08:24:46 +00:00
|
|
|
/*@
|
2012-06-27 07:41:10 +00:00
|
|
|
Ox.TableList <f> TableList Widget
|
2011-05-16 08:24:46 +00:00
|
|
|
options <o> Options object
|
2012-08-31 14:57:03 +00:00
|
|
|
clearButton <b|false> If true and columns are visible, show clear button
|
|
|
|
clearButtonTooltip <s|''> Clear button tooltip
|
2011-10-03 09:52:30 +00:00
|
|
|
columns <[o]|[]> Columns
|
2011-09-04 12:19:36 +00:00
|
|
|
# Fixme: There's probably more...
|
2013-07-20 07:57:13 +00:00
|
|
|
addable <b|true> ...
|
2012-09-03 20:26:27 +00:00
|
|
|
align <s|'left'> ...
|
2011-10-03 09:52:30 +00:00
|
|
|
editable <b> ...
|
|
|
|
format <f> ...
|
|
|
|
id <s> ...
|
2011-05-22 13:14:42 +00:00
|
|
|
operator <s> default sort operator
|
2013-07-20 07:57:13 +00:00
|
|
|
removable <b|true> ...
|
2012-09-03 20:26:27 +00:00
|
|
|
resizable <b> ...
|
|
|
|
sort <f> function(value, object) that maps values to sort values
|
2011-10-03 09:52:30 +00:00
|
|
|
title <s> ...
|
2011-11-03 12:57:46 +00:00
|
|
|
titleImage <s> ...
|
2012-02-22 10:14:25 +00:00
|
|
|
unformat <f> Applied before editing
|
2012-06-27 16:19:24 +00:00
|
|
|
unique <b> If true, this column acts as unique id (deprecated)
|
2011-10-03 09:52:30 +00:00
|
|
|
visible <b> ...
|
|
|
|
width <n> ...
|
2011-09-04 12:19:36 +00:00
|
|
|
columnsMovable <b|false> If true, columns can be re-ordered
|
|
|
|
columnsRemovable <b|false> If true, columns are removable
|
|
|
|
columnsResizable <b|false> If true, columns are resizable
|
|
|
|
columnsVisible <b|false> If true, columns are visible
|
|
|
|
columnWidth <[n]|[40, 800]> Minimum and maximum column width
|
2012-09-01 09:46:01 +00:00
|
|
|
disableHorizontalScrolling <b|false> If true, disable scrolling
|
2011-09-01 09:16:41 +00:00
|
|
|
draggable <b|false> If true, items can be dragged
|
2013-08-02 09:21:37 +00:00
|
|
|
droppable <b> If true, items can be dropped
|
2012-05-29 22:28:52 +00:00
|
|
|
id <s|''> Id
|
2011-05-16 10:49:48 +00:00
|
|
|
items <f|null> function() {} {sort, range, keys, callback} or array
|
2011-09-04 16:43:52 +00:00
|
|
|
keys <[s]|[]> Additional keys (apart from keys of visible columns)
|
2011-09-03 23:04:18 +00:00
|
|
|
max <n|-1> Maximum number of items that can be selected (-1 for all)
|
|
|
|
min <n|0> Minimum number of items that must be selected
|
2011-09-04 12:19:36 +00:00
|
|
|
pageLength <n|100> Number of items per page
|
2012-06-19 12:15:20 +00:00
|
|
|
query <o> Query
|
2011-09-04 12:19:36 +00:00
|
|
|
scrollbarVisible <b|false> If true, the scrollbar is always visible
|
2012-06-29 12:19:34 +00:00
|
|
|
selectAsYouType <s|''> If set to a key, enables select-as-you-type
|
2012-05-29 22:28:52 +00:00
|
|
|
selected <[s]|[]> Array of selected ids
|
|
|
|
sort <[o]|[s]|[]> ['+foo', ...] or [{key: 'foo', operator: '+'}, ...]
|
2011-09-03 23:04:18 +00:00
|
|
|
sortable <b|false> If true, elements can be re-ordered
|
2012-05-29 22:28:52 +00:00
|
|
|
sums <[s]|[]> Sums to be included in totals
|
2012-06-27 16:19:24 +00:00
|
|
|
unique <s|''> Key of the unique id
|
|
|
|
This has precedence over a unique id specified via columns (which is
|
|
|
|
deprecated).
|
2012-06-17 22:38:26 +00:00
|
|
|
columnresize <!> columnresize
|
|
|
|
columnchange <!> columnchange
|
2012-07-04 11:29:18 +00:00
|
|
|
self <o> Shared private variable
|
|
|
|
([options[, self]]) -> <o:Ox.Element> TableList Object
|
2011-05-16 08:24:46 +00:00
|
|
|
@*/
|
|
|
|
|
2011-09-04 12:19:36 +00:00
|
|
|
// fixme: options.columnsMovable, but options.sortable ... pick one.
|
|
|
|
|
2012-06-27 07:41:10 +00:00
|
|
|
Ox.TableList = function(options, self) {
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-10-09 21:13:16 +00:00
|
|
|
// fixme: in columns, "operator" should be "sortOperator"
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
2011-04-22 22:03:10 +00:00
|
|
|
.defaults({
|
2012-08-31 14:57:03 +00:00
|
|
|
clearButton: false,
|
|
|
|
clearButtonTooltip: '',
|
2011-04-22 22:03:10 +00:00
|
|
|
columns: [],
|
|
|
|
columnsMovable: false,
|
|
|
|
columnsRemovable: false,
|
|
|
|
columnsResizable: false,
|
|
|
|
columnsVisible: false,
|
|
|
|
columnWidth: [40, 800],
|
2012-08-31 06:51:30 +00:00
|
|
|
disableHorizontalScrolling: false,
|
2011-09-01 09:16:41 +00:00
|
|
|
draggable: false,
|
2013-08-02 09:21:37 +00:00
|
|
|
droppable: false,
|
2011-04-22 22:03:10 +00:00
|
|
|
id: '',
|
2011-11-30 14:56:01 +00:00
|
|
|
items: null,
|
2011-09-04 16:43:52 +00:00
|
|
|
keys: [],
|
2011-04-22 22:03:10 +00:00
|
|
|
max: -1,
|
|
|
|
min: 0,
|
|
|
|
pageLength: 100,
|
2012-06-19 12:15:20 +00:00
|
|
|
query: {conditions: [], operator: '&'},
|
2011-04-22 22:03:10 +00:00
|
|
|
scrollbarVisible: false,
|
|
|
|
selected: [],
|
2011-09-03 23:04:18 +00:00
|
|
|
sort: [],
|
2012-04-04 07:06:55 +00:00
|
|
|
sortable: false,
|
2012-06-27 16:19:24 +00:00
|
|
|
sums: [],
|
|
|
|
unique: ''
|
2011-04-22 22:03:10 +00:00
|
|
|
})
|
|
|
|
.options(options || {})
|
2012-05-28 19:35:41 +00:00
|
|
|
.update({
|
2012-08-31 06:51:30 +00:00
|
|
|
disableHorizontalScrolling: function() {
|
|
|
|
self.options.disableHorizontalScrolling
|
|
|
|
? disableHorizontalScrolling()
|
|
|
|
: enableHorizontalScrolling();
|
2012-08-30 22:16:09 +00:00
|
|
|
},
|
2013-07-13 14:01:17 +00:00
|
|
|
draggable: function() {
|
|
|
|
that.$body.options({sortable: self.options.draggable});
|
|
|
|
},
|
2012-05-28 19:35:41 +00:00
|
|
|
items: function() {
|
2012-06-19 12:15:20 +00:00
|
|
|
that.$body.options({items: self.options.items});
|
2012-05-28 19:35:41 +00:00
|
|
|
},
|
|
|
|
paste: function() {
|
2012-06-19 12:15:20 +00:00
|
|
|
that.$body.options({paste: self.options.paste});
|
|
|
|
},
|
|
|
|
query: function() {
|
|
|
|
that.$body.options({query: self.options.query});
|
2012-05-28 19:35:41 +00:00
|
|
|
},
|
|
|
|
selected: function() {
|
2012-06-19 12:15:20 +00:00
|
|
|
that.$body.options({selected: self.options.selected});
|
2012-12-29 16:43:03 +00:00
|
|
|
// updateImages();
|
2012-08-31 14:57:03 +00:00
|
|
|
updateClearButton();
|
2012-05-28 19:35:41 +00:00
|
|
|
},
|
|
|
|
sort: function() {
|
|
|
|
updateColumn();
|
2012-06-19 12:15:20 +00:00
|
|
|
that.$body.options({sort: self.options.sort});
|
2013-07-13 14:01:17 +00:00
|
|
|
},
|
|
|
|
sortable: function() {
|
|
|
|
that.$body.options({sortable: self.options.sortable});
|
2012-05-28 19:35:41 +00:00
|
|
|
}
|
|
|
|
})
|
2012-08-30 22:16:09 +00:00
|
|
|
.addClass('OxTableList');
|
|
|
|
|
2011-09-09 10:41:13 +00:00
|
|
|
self.options.columns.forEach(function(column) { // fixme: can this go into a generic ox.js function?
|
2011-04-22 22:03:10 +00:00
|
|
|
// fixme: and can't these just remain undefined?
|
2011-09-09 10:41:13 +00:00
|
|
|
if (Ox.isUndefined(column.align)) {
|
|
|
|
column.align = 'left';
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2011-09-09 10:41:13 +00:00
|
|
|
if (Ox.isUndefined(column.clickable)) {
|
|
|
|
column.clickable = false;
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2011-09-09 10:41:13 +00:00
|
|
|
if (Ox.isUndefined(column.editable)) {
|
|
|
|
column.editable = false;
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2011-09-09 10:41:13 +00:00
|
|
|
if (Ox.isUndefined(column.unique)) {
|
|
|
|
column.unique = false;
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2011-09-09 10:41:13 +00:00
|
|
|
if (Ox.isUndefined(column.visible)) {
|
|
|
|
column.visible = false;
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2012-06-27 16:19:24 +00:00
|
|
|
if (column.unique && !self.options.unique) {
|
|
|
|
self.options.unique = column.id;
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-04-02 21:07:50 +00:00
|
|
|
if (Ox.isEmpty(self.options.sort)) {
|
|
|
|
self.options.sort = [{
|
2012-06-27 16:19:24 +00:00
|
|
|
key: self.options.unique,
|
|
|
|
operator: Ox.getObjectById(self.options.columns, self.options.unique).operator
|
2012-04-02 21:07:50 +00:00
|
|
|
}];
|
2012-06-27 18:28:59 +00:00
|
|
|
} else{
|
|
|
|
self.options.sort = self.options.sort.map(function(sort) {
|
|
|
|
return Ox.isString(sort) ? {
|
|
|
|
key: sort.replace(/^[\+\-]/, ''),
|
|
|
|
operator: sort[0] == '-' ? '-' : '+'
|
|
|
|
} : sort;
|
|
|
|
});
|
2012-04-02 21:07:50 +00:00
|
|
|
}
|
|
|
|
|
2011-09-09 10:41:13 +00:00
|
|
|
Ox.extend(self, {
|
2011-04-22 22:03:10 +00:00
|
|
|
columnPositions: [],
|
2011-09-09 10:41:13 +00:00
|
|
|
defaultColumnWidths: self.options.columns.map(function(column) {
|
|
|
|
return column.defaultWidth || column.width;
|
2011-04-22 22:03:10 +00:00
|
|
|
}),
|
2012-06-27 18:28:59 +00:00
|
|
|
hasItemsArray: Ox.isArray(self.options.items),
|
2011-04-22 22:03:10 +00:00
|
|
|
itemHeight: 16,
|
|
|
|
page: 0,
|
|
|
|
pageLength: 100,
|
|
|
|
scrollLeft: 0,
|
|
|
|
selectedColumn: getColumnIndexById(self.options.sort[0].key),
|
2011-09-09 10:41:13 +00:00
|
|
|
visibleColumns: self.options.columns.filter(function(column) {
|
|
|
|
return column.visible;
|
2011-04-22 22:03:10 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
// fixme: there might be a better way than passing both visible and position
|
2011-09-09 10:41:13 +00:00
|
|
|
self.options.columns.forEach(function(column) {
|
|
|
|
if (!Ox.isUndefined(column.position)) {
|
|
|
|
self.visibleColumns[column.position] = column;
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2011-06-19 17:48:32 +00:00
|
|
|
});
|
2011-09-09 10:41:13 +00:00
|
|
|
Ox.extend(self, {
|
|
|
|
columnWidths: self.visibleColumns.map(function(column) {
|
|
|
|
return column.width;
|
2011-04-22 22:03:10 +00:00
|
|
|
}),
|
|
|
|
pageHeight: self.options.pageLength * self.itemHeight
|
|
|
|
});
|
|
|
|
|
|
|
|
self.format = {};
|
2012-09-03 20:26:27 +00:00
|
|
|
self.map = {};
|
2011-09-09 10:41:13 +00:00
|
|
|
self.options.columns.forEach(function(column) {
|
|
|
|
if (column.format) {
|
|
|
|
self.format[column.id] = column.format;
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2012-09-03 20:26:27 +00:00
|
|
|
if (column.sort) {
|
|
|
|
self.map[column.id] = column.sort;
|
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Head
|
|
|
|
|
|
|
|
if (self.options.columnsVisible) {
|
2011-06-19 17:48:32 +00:00
|
|
|
that.$bar = Ox.Bar({
|
2011-04-22 22:03:10 +00:00
|
|
|
orientation: 'horizontal',
|
|
|
|
size: 16
|
|
|
|
}).appendTo(that);
|
2011-06-19 17:48:32 +00:00
|
|
|
that.$head = Ox.Container()
|
2011-04-22 22:03:10 +00:00
|
|
|
.addClass('OxHead')
|
|
|
|
.css({
|
2011-09-09 10:41:13 +00:00
|
|
|
right: self.options.scrollbarVisible
|
2014-09-25 16:35:17 +00:00
|
|
|
? Ox.SCROLLBAR_SIZE + 'px' : 0
|
2011-04-22 22:03:10 +00:00
|
|
|
})
|
|
|
|
.appendTo(that.$bar);
|
|
|
|
that.$head.$content.addClass('OxTitles');
|
|
|
|
constructHead();
|
|
|
|
if (self.options.columnsRemovable) {
|
2011-06-19 17:48:32 +00:00
|
|
|
that.$select = Ox.Select({
|
2011-04-22 22:03:10 +00:00
|
|
|
id: self.options.id + 'SelectColumns',
|
2013-07-20 07:57:13 +00:00
|
|
|
items: self.options.columns.filter(function(column){
|
|
|
|
return column.addable !== false;
|
|
|
|
}).map(function(column) {
|
2011-04-22 22:03:10 +00:00
|
|
|
return {
|
2011-09-09 10:41:13 +00:00
|
|
|
disabled: column.removable === false,
|
|
|
|
id: column.id,
|
|
|
|
title: column.title
|
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
}),
|
|
|
|
max: -1,
|
|
|
|
min: 1,
|
2011-12-23 09:54:20 +00:00
|
|
|
type: 'image',
|
2012-05-22 14:29:37 +00:00
|
|
|
value: Ox.filter(self.options.columns, function(column) {
|
|
|
|
return column.visible;
|
|
|
|
}).map(function(column) {
|
|
|
|
return column.id;
|
2011-12-23 09:54:20 +00:00
|
|
|
})
|
2011-04-22 22:03:10 +00:00
|
|
|
})
|
2014-09-25 16:35:17 +00:00
|
|
|
.css(Ox.SCROLLBAR_SIZE == 16 ? {
|
2012-12-10 16:44:52 +00:00
|
|
|
right: 0,
|
|
|
|
width: '14px'
|
|
|
|
} : {
|
|
|
|
right: '-1px',
|
|
|
|
width: '8px',
|
|
|
|
})
|
2011-04-22 22:03:10 +00:00
|
|
|
.bindEvent('change', changeColumns)
|
2012-08-31 14:57:03 +00:00
|
|
|
.appendTo(that.$bar);
|
2014-09-25 16:35:17 +00:00
|
|
|
Ox.SCROLLBAR_SIZE < 16 && $(that.$select.find('input')[0]).css({
|
2012-12-10 16:44:52 +00:00
|
|
|
marginRight: '-3px',
|
|
|
|
marginTop: '1px',
|
|
|
|
width: '8px',
|
|
|
|
height: '8px'
|
|
|
|
});
|
2012-08-31 14:57:03 +00:00
|
|
|
} else if (self.options.clearButton) {
|
|
|
|
self.$clearButton = Ox.Element({
|
|
|
|
element: '<img>',
|
|
|
|
tooltip: self.options.clearButtonTooltip
|
|
|
|
})
|
|
|
|
.addClass('OxClear')
|
2014-09-25 10:28:47 +00:00
|
|
|
.attr({src: Ox.getImageURL('symbolClose')})
|
2014-09-25 16:35:17 +00:00
|
|
|
.css(Ox.SCROLLBAR_SIZE == 16 ? {
|
2012-12-10 16:44:52 +00:00
|
|
|
paddingLeft: '4px',
|
|
|
|
paddingRight: '2px',
|
|
|
|
marginRight: 0
|
|
|
|
} : {
|
|
|
|
paddingRight: '1px',
|
|
|
|
marginRight: '-2px'
|
2012-08-31 14:57:03 +00:00
|
|
|
})
|
|
|
|
[self.options.selected.length ? 'show' : 'hide']()
|
|
|
|
.bindEvent({
|
|
|
|
anyclick: function() {
|
|
|
|
self.$clearButton.hide();
|
|
|
|
self.options.selected = [];
|
|
|
|
that.$body.options({selected: self.options.selected});
|
|
|
|
that.triggerEvent('select', {ids: []});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.appendTo(that.$bar);
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Body
|
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
that.$body = Ox.List({
|
2011-04-22 22:03:10 +00:00
|
|
|
construct: constructItem,
|
2012-09-01 09:46:01 +00:00
|
|
|
disableHorizontalScrolling: self.options.disableHorizontalScrolling,
|
2011-09-01 09:16:41 +00:00
|
|
|
draggable: self.options.draggable,
|
2011-04-22 22:03:10 +00:00
|
|
|
id: self.options.id,
|
|
|
|
itemHeight: 16,
|
|
|
|
items: self.options.items,
|
|
|
|
itemWidth: getItemWidth(),
|
2012-06-27 07:41:10 +00:00
|
|
|
format: self.format, // fixme: not needed, happens in TableList
|
2012-06-27 16:19:24 +00:00
|
|
|
keys: Ox.unique(
|
2012-06-27 18:28:59 +00:00
|
|
|
(
|
|
|
|
self.hasItemsArray
|
|
|
|
? self.options.columns
|
|
|
|
: self.visibleColumns
|
|
|
|
).map(function(column) {
|
2012-06-27 16:19:24 +00:00
|
|
|
return column.id;
|
|
|
|
})
|
|
|
|
.concat(self.options.unique)
|
|
|
|
.concat(self.options.keys)
|
|
|
|
),
|
2012-09-03 20:26:27 +00:00
|
|
|
map: self.map,
|
2011-04-22 22:03:10 +00:00
|
|
|
max: self.options.max,
|
|
|
|
min: self.options.min,
|
2012-06-19 12:15:20 +00:00
|
|
|
orientation: 'vertical',
|
2011-04-22 22:03:10 +00:00
|
|
|
pageLength: self.options.pageLength,
|
|
|
|
paste: self.options.paste,
|
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-04-22 22:03:10 +00:00
|
|
|
selected: self.options.selected,
|
|
|
|
sort: self.options.sort,
|
|
|
|
sortable: self.options.sortable,
|
2012-04-04 07:06:55 +00:00
|
|
|
sums: self.options.sums,
|
2011-04-22 22:03:10 +00:00
|
|
|
type: 'text',
|
2012-06-27 16:19:24 +00:00
|
|
|
unique: self.options.unique
|
2012-06-30 09:20:37 +00:00
|
|
|
})
|
2011-04-22 22:03:10 +00:00
|
|
|
.addClass('OxBody')
|
|
|
|
.css({
|
|
|
|
top: (self.options.columnsVisible ? 16 : 0) + 'px',
|
|
|
|
overflowY: (self.options.scrollbarVisible ? 'scroll' : 'hidden')
|
|
|
|
})
|
2014-09-22 14:23:21 +00:00
|
|
|
.on({
|
|
|
|
scroll: function() {
|
|
|
|
var scrollLeft = $(this).scrollLeft();
|
|
|
|
if (scrollLeft != self.scrollLeft) {
|
|
|
|
self.scrollLeft = scrollLeft;
|
|
|
|
that.$head && that.$head.scrollLeft(scrollLeft);
|
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
})
|
2012-06-30 09:20:37 +00:00
|
|
|
.bindEvent(function(data, event) {
|
|
|
|
if (event == 'cancel') {
|
2011-11-04 15:54:28 +00:00
|
|
|
Ox.Log('List', 'cancel edit', data);
|
2012-06-30 09:20:37 +00:00
|
|
|
} else if (event == 'edit') {
|
2011-09-04 12:19:36 +00:00
|
|
|
that.editCell(data.id, data.key);
|
2012-06-30 15:03:43 +00:00
|
|
|
} else if (event == 'select') {
|
|
|
|
self.options.selected = data.ids;
|
2012-12-29 16:43:03 +00:00
|
|
|
// updateImages();
|
2012-08-31 14:57:03 +00:00
|
|
|
updateClearButton();
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2012-06-30 15:03:43 +00:00
|
|
|
that.triggerEvent(event, data);
|
2011-04-22 22:03:10 +00:00
|
|
|
})
|
|
|
|
.appendTo(that);
|
2011-09-04 12:19:36 +00:00
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
that.$body.$content.css({
|
|
|
|
width: getItemWidth() + 'px'
|
|
|
|
});
|
|
|
|
|
2012-09-01 09:46:01 +00:00
|
|
|
self.options.disableHorizontalScrolling
|
|
|
|
? disableHorizontalScrolling()
|
|
|
|
: enableHorizontalScrolling();
|
|
|
|
|
2011-11-04 15:54:28 +00:00
|
|
|
//Ox.Log('List', 's.vC', self.visibleColumns)
|
2011-04-22 22:03:10 +00:00
|
|
|
|
|
|
|
function addColumn(id) {
|
2011-11-04 15:54:28 +00:00
|
|
|
//Ox.Log('List', 'addColumn', id);
|
2011-04-22 22:03:10 +00:00
|
|
|
var column, ids,
|
|
|
|
index = 0;
|
|
|
|
Ox.forEach(self.options.columns, function(v) {
|
|
|
|
if (v.visible) {
|
|
|
|
index++;
|
|
|
|
} else if (v.id == id) {
|
|
|
|
column = v;
|
2012-07-05 08:58:08 +00:00
|
|
|
return false; // break
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
column.visible = true;
|
|
|
|
self.visibleColumns.splice(index, 0, column);
|
|
|
|
self.columnWidths.splice(index, 0, column.width);
|
|
|
|
that.$head.$content.empty();
|
|
|
|
constructHead();
|
2012-06-27 18:28:59 +00:00
|
|
|
!self.hasItemsArray && that.$body.options({
|
2012-05-24 07:45:33 +00:00
|
|
|
keys: self.visibleColumns.map(function(column) {
|
2011-09-04 16:43:52 +00:00
|
|
|
return column.id;
|
2012-05-24 07:45:33 +00:00
|
|
|
}).concat(self.options.keys)
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
|
|
|
that.$body.reloadPages();
|
|
|
|
}
|
|
|
|
|
2011-09-17 17:39:38 +00:00
|
|
|
function changeColumns(data) {
|
2011-04-22 22:03:10 +00:00
|
|
|
var add,
|
|
|
|
ids = [];
|
2011-12-23 09:54:20 +00:00
|
|
|
Ox.forEach(data.value, function(id) {
|
|
|
|
var index = getColumnIndexById(id);
|
2011-04-22 22:03:10 +00:00
|
|
|
if (!self.options.columns[index].visible) {
|
2011-12-23 09:54:20 +00:00
|
|
|
addColumn(id);
|
2011-04-22 22:03:10 +00:00
|
|
|
add = true;
|
2012-07-05 08:58:08 +00:00
|
|
|
return false; // break
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2011-12-23 09:54:20 +00:00
|
|
|
ids.push(id);
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
|
|
|
if (!add) {
|
|
|
|
Ox.forEach(self.visibleColumns, function(column) {
|
|
|
|
if (ids.indexOf(column.id) == -1) {
|
|
|
|
removeColumn(column.id);
|
2012-07-05 08:58:08 +00:00
|
|
|
return false; // break
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
triggerColumnChangeEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
function clickColumn(id) {
|
2011-11-04 15:54:28 +00:00
|
|
|
Ox.Log('List', 'clickColumn', id);
|
2011-04-22 22:03:10 +00:00
|
|
|
var i = getColumnIndexById(id),
|
|
|
|
isSelected = self.options.sort[0].key == self.options.columns[i].id;
|
2011-05-24 13:44:02 +00:00
|
|
|
self.options.sort = [{
|
|
|
|
key: self.options.columns[i].id,
|
|
|
|
operator: isSelected ?
|
|
|
|
(self.options.sort[0].operator == '+' ? '-' : '+') :
|
2012-09-03 20:26:27 +00:00
|
|
|
self.options.columns[i].operator
|
2012-05-21 19:23:16 +00:00
|
|
|
}];
|
2011-05-24 13:44:02 +00:00
|
|
|
updateColumn();
|
|
|
|
// fixme: strangely, sorting the list blocks updating the column,
|
|
|
|
// so we use a timeout for now
|
|
|
|
setTimeout(function() {
|
|
|
|
that.$body.options({sort: self.options.sort});
|
2012-09-05 10:05:01 +00:00
|
|
|
that.gainFocus().triggerEvent('sort', {
|
|
|
|
key: self.options.sort[0].key,
|
|
|
|
operator: self.options.sort[0].operator
|
|
|
|
});
|
2011-08-18 07:55:39 +00:00
|
|
|
}, 10);
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function constructHead() {
|
2012-05-21 19:23:16 +00:00
|
|
|
var pos;
|
2011-09-09 10:41:13 +00:00
|
|
|
self.$heads = [];
|
|
|
|
self.$titles = [];
|
2012-12-28 17:02:50 +00:00
|
|
|
self.$titleImages = [];
|
2012-12-29 12:56:04 +00:00
|
|
|
self.$orderImages = [];
|
2011-09-09 10:41:13 +00:00
|
|
|
self.visibleColumns.forEach(function(column, i) {
|
|
|
|
var $resize;
|
|
|
|
self.$heads[i] = Ox.Element()
|
2013-02-08 12:19:27 +00:00
|
|
|
.addClass('OxHeadCell ' + getColumnClassName(column.id))
|
2011-09-09 10:41:13 +00:00
|
|
|
.css({width: self.columnWidths[i] - 5 + 'px'})
|
2014-09-22 14:23:21 +00:00
|
|
|
.appendTo(that.$head.$content);
|
2011-05-22 17:12:21 +00:00
|
|
|
// if sort operator is set, bind click event
|
2011-09-09 10:41:13 +00:00
|
|
|
if (column.operator) {
|
|
|
|
self.$heads[i].bindEvent({
|
|
|
|
anyclick: function() {
|
|
|
|
clickColumn(column.id);
|
2011-05-22 17:12:21 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// if columns are movable, bind drag events
|
|
|
|
if (self.options.columnsMovable) {
|
2011-09-09 10:41:13 +00:00
|
|
|
self.$heads[i].bindEvent({
|
2011-09-17 11:49:29 +00:00
|
|
|
dragstart: function(data) {
|
|
|
|
dragstartColumn(column.id, data);
|
2011-04-22 22:03:10 +00:00
|
|
|
},
|
2011-09-17 11:49:29 +00:00
|
|
|
drag: function(data) {
|
|
|
|
dragColumn(column.id, data);
|
2011-04-22 22:03:10 +00:00
|
|
|
},
|
2011-09-17 11:49:29 +00:00
|
|
|
dragpause: function(data) {
|
|
|
|
dragpauseColumn(column.id, data);
|
2011-09-09 11:37:14 +00:00
|
|
|
},
|
2011-09-17 11:49:29 +00:00
|
|
|
dragend: function(data) {
|
|
|
|
dragendColumn(column.id, data);
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2012-05-21 19:23:16 +00:00
|
|
|
});
|
2011-05-22 17:12:21 +00:00
|
|
|
}
|
2011-09-09 10:41:13 +00:00
|
|
|
self.$titles[i] = Ox.Element()
|
|
|
|
.addClass('OxTitle')
|
|
|
|
.css({
|
|
|
|
width: self.columnWidths[i] - 9 + 'px',
|
|
|
|
textAlign: column.align
|
|
|
|
})
|
|
|
|
.appendTo(self.$heads[i]);
|
2011-11-03 12:57:46 +00:00
|
|
|
if (column.titleImage) {
|
2012-12-28 17:02:50 +00:00
|
|
|
self.$titleImages[i] = $('<img>').
|
|
|
|
attr({
|
2014-09-25 10:28:47 +00:00
|
|
|
src: Ox.getImageURL(
|
2012-12-28 17:02:50 +00:00
|
|
|
'symbol' + Ox.toTitleCase(column.titleImage)
|
|
|
|
)
|
2011-11-03 12:57:46 +00:00
|
|
|
})
|
2012-12-28 17:02:50 +00:00
|
|
|
.appendTo(self.$titles[i]);
|
2011-11-03 12:57:46 +00:00
|
|
|
} else {
|
|
|
|
self.$titles[i].html(column.title);
|
|
|
|
}
|
2011-11-02 19:47:19 +00:00
|
|
|
if (column.operator) {
|
2012-12-29 12:56:04 +00:00
|
|
|
self.$orderImages[i] = $('<img>')
|
|
|
|
.attr({
|
2014-09-25 10:28:47 +00:00
|
|
|
src: Ox.getImageURL(
|
2012-12-29 12:56:04 +00:00
|
|
|
'symbol' + (column.operator == '+' ? 'Up' : 'Down'),
|
|
|
|
'selected'
|
|
|
|
)
|
2011-11-02 19:47:19 +00:00
|
|
|
})
|
|
|
|
.addClass('OxOrder')
|
2012-12-29 12:56:04 +00:00
|
|
|
.css({marginTop: (column.operator == '+' ? 3 : 2) + 'px'})
|
2011-11-02 19:47:19 +00:00
|
|
|
.click(function() {
|
|
|
|
$(this).parent().trigger('click');
|
|
|
|
})
|
|
|
|
.appendTo(self.$heads[i]);
|
|
|
|
}
|
2011-06-19 17:48:32 +00:00
|
|
|
$resize = Ox.Element()
|
2011-04-22 22:03:10 +00:00
|
|
|
.addClass('OxResize')
|
2014-09-22 14:23:21 +00:00
|
|
|
.appendTo(that.$head.$content);
|
2011-09-09 10:41:13 +00:00
|
|
|
$('<div>').appendTo($resize);
|
|
|
|
$('<div>').addClass('OxCenter').appendTo($resize);
|
|
|
|
$('<div>').appendTo($resize);
|
2013-07-20 07:57:13 +00:00
|
|
|
// if columns are resizable, bind doubleclick and drag events
|
2011-11-02 19:47:19 +00:00
|
|
|
if (self.options.columnsResizable && column.resizable !== false) {
|
2011-04-22 22:03:10 +00:00
|
|
|
$resize.addClass('OxResizable')
|
|
|
|
.bindEvent({
|
2011-09-17 11:49:29 +00:00
|
|
|
doubleclick: function(data) {
|
|
|
|
resetColumn(column.id, data);
|
2011-04-22 22:03:10 +00:00
|
|
|
},
|
2011-09-17 11:49:29 +00:00
|
|
|
dragstart: function(data) {
|
|
|
|
dragstartResize(column.id, data);
|
2011-04-22 22:03:10 +00:00
|
|
|
},
|
2011-09-17 11:49:29 +00:00
|
|
|
drag: function(data) {
|
|
|
|
dragResize(column.id, data);
|
2011-04-22 22:03:10 +00:00
|
|
|
},
|
2011-09-17 11:49:29 +00:00
|
|
|
dragend: function(data) {
|
|
|
|
dragendResize(column.id, data);
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
that.$head.$content.css({
|
|
|
|
width: (Ox.sum(self.columnWidths) + 2) + 'px'
|
|
|
|
});
|
2012-05-21 19:23:16 +00:00
|
|
|
pos = getColumnPositionById(self.options.columns[self.selectedColumn].id);
|
|
|
|
if (pos > -1) {
|
2011-04-22 22:03:10 +00:00
|
|
|
toggleSelected(self.options.columns[self.selectedColumn].id);
|
2012-05-21 19:23:16 +00:00
|
|
|
self.$titles[pos].css({
|
2011-04-22 22:03:10 +00:00
|
|
|
width: (self.options.columns[self.selectedColumn].width - 25) + 'px'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function constructItem(data) {
|
|
|
|
var $item = $('<div>')
|
2014-09-22 14:23:21 +00:00
|
|
|
.addClass('OxTarget')
|
|
|
|
.css({
|
|
|
|
width: getItemWidth(true) + 'px'
|
|
|
|
});
|
2011-04-22 22:03:10 +00:00
|
|
|
self.visibleColumns.forEach(function(v, i) {
|
|
|
|
var clickable = Ox.isBoolean(v.clickable) ? v.clickable : v.clickable(data),
|
|
|
|
editable = Ox.isBoolean(v.editable) ? v.editable : v.editable(data),
|
2014-09-22 14:23:21 +00:00
|
|
|
// if the column id is not in data, we're constructing an empty cell
|
|
|
|
value = v.id in data ? formatValue(v.id, data[v.id], data) : '',
|
2011-10-11 06:32:20 +00:00
|
|
|
$cell;
|
|
|
|
if (v.tooltip) {
|
2011-08-28 19:50:06 +00:00
|
|
|
$cell = Ox.Element({
|
2011-10-11 06:32:20 +00:00
|
|
|
tooltip: function() {
|
2012-06-27 16:19:24 +00:00
|
|
|
return self.options.selected.indexOf(data[self.options.unique]) > -1
|
2011-10-11 06:32:20 +00:00
|
|
|
? (Ox.isString(v.tooltip) ? v.tooltip : v.tooltip(data)) : '';
|
|
|
|
}
|
|
|
|
});
|
2013-08-02 09:21:37 +00:00
|
|
|
} else if (self.options.droppable) {
|
|
|
|
$cell = Ox.Element();
|
2011-10-11 06:32:20 +00:00
|
|
|
} else {
|
2011-10-11 07:05:45 +00:00
|
|
|
// this is faster
|
2011-10-11 06:32:20 +00:00
|
|
|
$cell = $('<div>');
|
|
|
|
}
|
|
|
|
$cell.addClass(
|
2013-02-08 12:19:27 +00:00
|
|
|
'OxCell ' + getColumnClassName(v.id)
|
2012-09-03 20:26:27 +00:00
|
|
|
+ (clickable ? ' OxClickable' : '')
|
|
|
|
+ (editable ? ' OxEditable' : '')
|
2011-10-11 06:32:20 +00:00
|
|
|
)
|
|
|
|
.css({
|
|
|
|
width: (self.columnWidths[i] - (self.options.columnsVisible ? 9 : 8)) + 'px',
|
|
|
|
borderRightWidth: (self.options.columnsVisible ? 1 : 0) + 'px',
|
|
|
|
textAlign: v.align
|
|
|
|
})
|
2014-09-22 14:23:21 +00:00
|
|
|
[Ox.isString(value) ? 'html' : 'append'](value)
|
2011-10-11 06:32:20 +00:00
|
|
|
.appendTo($item);
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
|
2012-08-31 06:51:30 +00:00
|
|
|
function disableHorizontalScrolling() {
|
2012-09-01 09:46:01 +00:00
|
|
|
that.$body.options({
|
|
|
|
disableHorizontalScrolling: true
|
|
|
|
})
|
|
|
|
.css({overflowX: 'hidden'});
|
2012-08-30 22:16:09 +00:00
|
|
|
// fixme: is there a way to pass an array?
|
|
|
|
that.unbindEvent('key_left').unbindEvent('key_right');
|
|
|
|
}
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
function dragstartColumn(id, e) {
|
2013-07-19 08:42:25 +00:00
|
|
|
Ox.$body.addClass('OxDragging');
|
2011-04-22 22:03:10 +00:00
|
|
|
self.drag = {
|
2011-09-09 10:41:13 +00:00
|
|
|
columnOffsets: getColumnOffsets(),
|
2014-09-22 14:23:21 +00:00
|
|
|
listOffset: that.offset().left - that.$body.scrollLeft(),
|
2011-04-22 22:03:10 +00:00
|
|
|
startPos: getColumnPositionById(id)
|
|
|
|
}
|
2011-09-09 10:41:13 +00:00
|
|
|
self.drag.stopPos = self.drag.startPos;
|
2013-07-22 08:23:50 +00:00
|
|
|
$('.' + getColumnClassName(id)).css({opacity: 0.5});
|
|
|
|
self.drag.startPos > 0 && self.$heads[self.drag.startPos].prev().children().eq(2).css({opacity: 0.5});
|
|
|
|
self.$heads[self.drag.startPos].next().children().eq(0).css({opacity: 0.5});
|
2011-09-09 10:41:13 +00:00
|
|
|
self.$heads[self.drag.startPos].addClass('OxDrag').css({ // fixme: why does the class not work?
|
2013-07-22 08:23:50 +00:00
|
|
|
cursor: 'ew-resize'
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function dragColumn(id, e) {
|
2014-09-22 14:23:21 +00:00
|
|
|
var listLeft = that.offset().left,
|
|
|
|
listRight = listLeft + that.width(),
|
2011-09-09 11:37:14 +00:00
|
|
|
pos = self.drag.stopPos;
|
2011-09-09 10:41:13 +00:00
|
|
|
Ox.forEach(self.drag.columnOffsets, function(offset, i) {
|
|
|
|
var x = self.drag.listOffset + offset + self.columnWidths[i] / 2;
|
|
|
|
if (i < self.drag.startPos && e.clientX < x) {
|
2011-04-22 22:03:10 +00:00
|
|
|
self.drag.stopPos = i;
|
2012-07-05 08:58:08 +00:00
|
|
|
return false; // break
|
2011-09-09 10:41:13 +00:00
|
|
|
} else if (i > self.drag.startPos && e.clientX > x) {
|
2011-04-22 22:03:10 +00:00
|
|
|
self.drag.stopPos = i;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (self.drag.stopPos != pos) {
|
|
|
|
moveColumn(id, self.drag.stopPos);
|
2011-09-09 10:41:13 +00:00
|
|
|
self.drag.columnOffsets = getColumnOffsets();
|
|
|
|
self.drag.startPos = self.drag.stopPos;
|
2011-09-09 11:37:14 +00:00
|
|
|
///*
|
|
|
|
var left = self.drag.columnOffsets[self.drag.startPos],
|
|
|
|
right = left + self.columnWidths[self.drag.startPos];
|
2014-09-22 14:23:21 +00:00
|
|
|
if (left < that.$body.scrollLeft() || right > that.width()) {
|
2011-09-09 11:37:14 +00:00
|
|
|
that.$body.scrollLeft(
|
2014-09-22 14:23:21 +00:00
|
|
|
left < that.$body.scrollLeft() ? left : right - that.width()
|
2011-09-09 11:37:14 +00:00
|
|
|
);
|
2014-09-22 14:23:21 +00:00
|
|
|
self.drag.listOffset = that.offset().left - that.$body.scrollLeft();
|
2011-09-09 11:37:14 +00:00
|
|
|
}
|
|
|
|
//*/
|
|
|
|
}
|
|
|
|
if (e.clientX < listLeft + 16 || e.clientX > listRight - 16) {
|
|
|
|
if (!self.scrollInterval) {
|
|
|
|
self.scrollInterval = setInterval(function() {
|
|
|
|
that.$body.scrollLeft(
|
|
|
|
that.$body.scrollLeft() + (e.clientX < listLeft + 16 ? -16 : 16)
|
|
|
|
);
|
2014-09-22 14:23:21 +00:00
|
|
|
self.drag.listOffset = that.offset().left - that.$body.scrollLeft();
|
2011-09-09 11:37:14 +00:00
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
} else if (self.scrollInterval) {
|
|
|
|
clearInterval(self.scrollInterval);
|
|
|
|
self.scrollInterval = 0;
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-09 11:37:14 +00:00
|
|
|
function dragpauseColumn(id, e) {
|
|
|
|
}
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
function dragendColumn(id, e) {
|
|
|
|
var column = self.visibleColumns.splice(self.drag.stopPos, 1)[0],
|
|
|
|
width = self.columnWidths.splice(self.drag.stopPos, 1)[0];
|
2013-07-19 08:42:25 +00:00
|
|
|
Ox.$body.removeClass('OxDragging');
|
2011-04-22 22:03:10 +00:00
|
|
|
self.visibleColumns.splice(self.drag.stopPos, 0, column);
|
|
|
|
self.columnWidths.splice(self.drag.stopPos, 0, width);
|
|
|
|
that.$head.$content.empty();
|
|
|
|
constructHead();
|
2013-02-08 12:19:27 +00:00
|
|
|
$('.' + getColumnClassName(id)).css({opacity: 1});
|
2011-09-09 10:41:13 +00:00
|
|
|
self.$heads[self.drag.stopPos].removeClass('OxDrag').css({
|
2013-07-22 08:23:50 +00:00
|
|
|
cursor: 'default'
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
|
|
|
that.$body.clearCache();
|
|
|
|
triggerColumnChangeEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
function dragstartResize(id, e) {
|
|
|
|
var pos = getColumnPositionById(id);
|
2013-07-19 08:42:25 +00:00
|
|
|
Ox.$body.addClass('OxDragging');
|
2011-04-22 22:03:10 +00:00
|
|
|
self.drag = {
|
|
|
|
startWidth: self.columnWidths[pos]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function dragResize(id, e) {
|
|
|
|
var width = Ox.limit(
|
2011-09-09 10:41:13 +00:00
|
|
|
self.drag.startWidth + e.clientDX,
|
2011-04-22 22:03:10 +00:00
|
|
|
self.options.columnWidth[0],
|
|
|
|
self.options.columnWidth[1]
|
|
|
|
);
|
|
|
|
resizeColumn(id, width);
|
|
|
|
}
|
|
|
|
|
|
|
|
function dragendResize(id, e) {
|
|
|
|
var pos = getColumnPositionById(id);
|
2011-09-17 17:39:38 +00:00
|
|
|
// fixme: shouldn't this be resizecolumn?
|
2013-07-19 08:42:25 +00:00
|
|
|
Ox.$body.removeClass('OxDragging');
|
2011-04-22 22:03:10 +00:00
|
|
|
that.triggerEvent('columnresize', {
|
|
|
|
id: id,
|
|
|
|
width: self.columnWidths[pos]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-08-31 06:51:30 +00:00
|
|
|
function enableHorizontalScrolling() {
|
2012-09-01 09:46:01 +00:00
|
|
|
that.$body.options({
|
|
|
|
disableHorizontalScrolling: false
|
|
|
|
})
|
|
|
|
.css({overflowX: 'auto'});
|
2012-08-30 22:16:09 +00:00
|
|
|
that.bindEvent({
|
|
|
|
key_left: function () {
|
2014-09-22 14:23:21 +00:00
|
|
|
that.$body.animate({
|
|
|
|
scrollLeft: that.$body[0].scrollLeft - that.$body.width()
|
|
|
|
}, 250);
|
2012-08-30 22:16:09 +00:00
|
|
|
},
|
|
|
|
key_right: function() {
|
2014-09-22 14:23:21 +00:00
|
|
|
that.$body.animate({
|
|
|
|
scrollLeft: that.$body[0].scrollLeft + that.$body.width()
|
|
|
|
}, 250);
|
2012-08-30 22:16:09 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-09-09 10:41:13 +00:00
|
|
|
function formatValue(key, value, data) {
|
|
|
|
// fixme: this may be obscure...
|
|
|
|
// since the format of a value may depend on another value,
|
|
|
|
// we pass all data as a second parameter to the supplied format function
|
2014-05-18 00:42:19 +00:00
|
|
|
var format = self.format[key];
|
2012-03-27 09:18:01 +00:00
|
|
|
// FIXME: this keeps null from ever reaching a format function!
|
2011-09-09 10:41:13 +00:00
|
|
|
if (value === null) {
|
|
|
|
value = '';
|
|
|
|
} else if (format) {
|
2011-10-26 14:52:03 +00:00
|
|
|
if (Ox.isObject(format)) {
|
|
|
|
value = (
|
|
|
|
/^color/.test(format.type.toLowerCase()) ? Ox.Theme : Ox
|
|
|
|
)['format' + Ox.toTitleCase(format.type)].apply(
|
2012-05-24 07:45:33 +00:00
|
|
|
this, [value].concat(format.args || [])
|
2011-10-26 14:52:03 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
value = format(value, data);
|
|
|
|
}
|
2011-09-09 10:41:13 +00:00
|
|
|
} else if (Ox.isArray(value)) {
|
|
|
|
value = value.join(', ');
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
function getCell(id, key) {
|
|
|
|
var $item = getItem(id);
|
2011-11-05 11:44:31 +00:00
|
|
|
key = key || ''; // fixme: what is this?
|
2014-09-22 14:23:21 +00:00
|
|
|
return $($item.find('.OxCell.' + getColumnClassName(key))[0]);
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 12:19:27 +00:00
|
|
|
function getColumnClassName(id) {
|
|
|
|
return 'OxColumn' + id[0].toUpperCase() + id.slice(1);
|
|
|
|
}
|
|
|
|
|
2011-09-09 10:41:13 +00:00
|
|
|
function getColumnOffsets() {
|
|
|
|
return self.visibleColumns.map(function(column, i) {
|
|
|
|
return Ox.sum(self.visibleColumns.map(function(column_, i_) {
|
|
|
|
return i_ < i ? self.columnWidths[i_] : 0;
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
function getColumnIndexById(id) {
|
2012-01-04 08:11:05 +00:00
|
|
|
return Ox.getIndexById(self.options.columns, id);
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getColumnPositionById(id) {
|
2012-01-04 08:11:05 +00:00
|
|
|
return Ox.getIndexById(self.visibleColumns, id);
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getItem(id) {
|
|
|
|
var $item = null;
|
2011-12-29 10:10:08 +00:00
|
|
|
that.find('.OxItem').each(function() {
|
2011-11-05 17:27:11 +00:00
|
|
|
var $this = $(this);
|
2011-09-09 10:41:13 +00:00
|
|
|
if ($this.data('id') == id) {
|
|
|
|
$item = $this;
|
2012-07-05 08:58:08 +00:00
|
|
|
return false; // break
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
|
2011-05-24 18:32:59 +00:00
|
|
|
function getItemWidth(cached) {
|
2011-05-24 17:50:53 +00:00
|
|
|
// fixme: this gets called for every constructItem and is slooow
|
|
|
|
// the proper way to fix this would be to find out how and when
|
2014-09-22 14:23:21 +00:00
|
|
|
// that.width() might change... which would probably mean binding to
|
|
|
|
// every SplitPanel and window resize... for now, use a cached value
|
2011-05-24 18:32:59 +00:00
|
|
|
if (!cached) {
|
2014-09-22 14:23:21 +00:00
|
|
|
self.cachedWidth = that.width();
|
2011-05-24 18:32:59 +00:00
|
|
|
} else if (!self.cachedWidth || self.cachedWidthTime < +new Date() - 5000) {
|
2014-09-22 14:23:21 +00:00
|
|
|
self.cachedWidth = that.width();
|
2011-05-24 17:50:53 +00:00
|
|
|
self.cachedWidthTime = +new Date();
|
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
return Math.max(
|
|
|
|
Ox.sum(self.columnWidths),
|
2011-05-24 17:50:53 +00:00
|
|
|
self.cachedWidth -
|
2014-09-25 16:35:17 +00:00
|
|
|
(self.options.scrollbarVisible ? Ox.SCROLLBAR_SIZE : 0)
|
2011-04-22 22:03:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveColumn(id, pos) {
|
2011-11-04 15:54:28 +00:00
|
|
|
//Ox.Log('List', 'moveColumn', id, pos)
|
2011-04-22 22:03:10 +00:00
|
|
|
var startPos = getColumnPositionById(id),
|
|
|
|
stopPos = pos,
|
2013-02-08 12:19:27 +00:00
|
|
|
startSelector = '.' + getColumnClassName(id),
|
|
|
|
stopSelector = '.' + getColumnClassName(self.visibleColumns[stopPos].id),
|
2011-11-06 00:19:27 +00:00
|
|
|
insert = startPos < stopPos ? 'insertAfter' : 'insertBefore',
|
2011-09-09 10:41:13 +00:00
|
|
|
$column = $('.OxHeadCell' + startSelector),
|
|
|
|
$resize = $column.next();
|
2011-11-04 15:54:28 +00:00
|
|
|
//Ox.Log('List', startSelector, insert, stopSelector)
|
2011-09-09 10:41:13 +00:00
|
|
|
$column.detach()[insert](insert == 'insertAfter'
|
|
|
|
? $('.OxHeadCell' + stopSelector).next()
|
|
|
|
: $('.OxHeadCell' + stopSelector));
|
|
|
|
$resize.detach().insertAfter($column);
|
2011-12-29 10:10:08 +00:00
|
|
|
that.$body.find('.OxItem').each(function() {
|
2011-09-09 10:41:13 +00:00
|
|
|
var $this = $(this);
|
|
|
|
$this.children(startSelector).detach()[insert](
|
|
|
|
$this.children(stopSelector)
|
|
|
|
);
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
2011-09-09 10:41:13 +00:00
|
|
|
var $head = self.$heads.splice(startPos, 1)[0],
|
|
|
|
columnWidth = self.columnWidths.splice(startPos, 1)[0],
|
|
|
|
visibleColumn = self.visibleColumns.splice(startPos, 1)[0];
|
|
|
|
self.$heads.splice(stopPos, 0, $head);
|
|
|
|
self.columnWidths.splice(stopPos, 0, columnWidth);
|
|
|
|
self.visibleColumns.splice(stopPos, 0, visibleColumn);
|
|
|
|
var pos = getColumnPositionById(self.options.columns[self.selectedColumn].id);
|
|
|
|
if (pos > -1) {
|
2011-12-29 10:10:08 +00:00
|
|
|
that.find('.OxResize .OxSelected').removeClass('OxSelected');
|
2011-09-09 10:41:13 +00:00
|
|
|
pos > 0 && self.$heads[pos].prev().children().eq(2).addClass('OxSelected');
|
|
|
|
self.$heads[pos].next().children().eq(0).addClass('OxSelected');
|
|
|
|
if (pos == stopPos) {
|
2013-07-22 08:23:50 +00:00
|
|
|
pos > 0 && self.$heads[pos].prev().children().eq(2).css({opacity: 0.5});
|
|
|
|
self.$heads[pos].next().children().eq(0).css({opacity: 0.5});
|
2011-09-09 10:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function removeColumn(id) {
|
2011-11-04 15:54:28 +00:00
|
|
|
//Ox.Log('List', 'removeColumn', id);
|
2011-09-09 10:41:13 +00:00
|
|
|
var index = getColumnIndexById(id),
|
2011-04-22 22:03:10 +00:00
|
|
|
itemWidth,
|
|
|
|
position = getColumnPositionById(id),
|
2013-02-08 12:19:27 +00:00
|
|
|
selector = '.' + getColumnClassName(id),
|
2011-09-09 10:41:13 +00:00
|
|
|
$column = $('.OxHeadCell ' + selector),
|
2011-04-22 22:03:10 +00:00
|
|
|
$order = $column.next(),
|
|
|
|
$resize = $order.next();
|
|
|
|
self.options.columns[index].visible = false;
|
|
|
|
self.visibleColumns.splice(position, 1);
|
|
|
|
self.columnWidths.splice(position, 1);
|
|
|
|
that.$head.$content.empty();
|
|
|
|
constructHead();
|
|
|
|
itemWidth = getItemWidth();
|
2011-12-29 10:10:08 +00:00
|
|
|
that.$body.find('.OxItem').each(function() {
|
2011-09-09 10:41:13 +00:00
|
|
|
var $this = $(this);
|
|
|
|
$this.children(selector).remove();
|
|
|
|
$this.css({width: itemWidth + 'px'});
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
|
|
|
that.$body.$content.css({
|
|
|
|
width: itemWidth + 'px'
|
|
|
|
});
|
2012-06-27 18:28:59 +00:00
|
|
|
!self.hasItemsArray && that.$body.options({
|
2012-05-24 07:45:33 +00:00
|
|
|
keys: self.visibleColumns.map(function(column) {
|
2011-09-09 10:41:13 +00:00
|
|
|
return column.id;
|
2012-05-24 07:45:33 +00:00
|
|
|
}).concat(self.options.keys)
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
|
|
|
//that.$body.clearCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetColumn(id) {
|
|
|
|
var width = self.defaultColumnWidths[getColumnIndexById(id)];
|
|
|
|
resizeColumn(id, width);
|
|
|
|
that.triggerEvent('columnresize', {
|
|
|
|
id: id,
|
|
|
|
width: width
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function resizeColumn(id, width) {
|
|
|
|
var i = getColumnIndexById(id),
|
|
|
|
pos = getColumnPositionById(id);
|
|
|
|
self.options.columns[i].width = width;
|
|
|
|
self.columnWidths[pos] = width;
|
2011-11-03 15:42:41 +00:00
|
|
|
if (self.options.columnsVisible) {
|
2011-04-22 22:03:10 +00:00
|
|
|
that.$head.$content.css({
|
|
|
|
width: (Ox.sum(self.columnWidths) + 2) + 'px'
|
|
|
|
});
|
2011-09-09 10:41:13 +00:00
|
|
|
self.$heads[pos].css({
|
|
|
|
width: width - 5 + 'px'
|
|
|
|
});
|
|
|
|
self.$titles[pos].css({
|
|
|
|
width: width - 9 - (i == self.selectedColumn ? 16 : 0) + 'px'
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
|
|
|
}
|
2013-02-08 12:19:27 +00:00
|
|
|
that.find(
|
|
|
|
'.OxCell.' + getColumnClassName(self.options.columns[i].id)
|
|
|
|
).css({
|
2011-09-09 10:41:13 +00:00
|
|
|
width: width - (self.options.columnsVisible ? 9 : 8) + 'px'
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
|
|
|
setWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
function setWidth() {
|
|
|
|
var width = getItemWidth();
|
2012-05-22 13:14:40 +00:00
|
|
|
that.$body.find('.OxItem').css({ // fixme: can we avoid this lookup?
|
2011-04-22 22:03:10 +00:00
|
|
|
width: width + 'px'
|
|
|
|
});
|
|
|
|
that.$body.$content.css({
|
|
|
|
width: width + 'px' // fixme: check if scrollbar visible, and listen to resize/toggle event
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleSelected(id) {
|
2012-12-28 17:02:50 +00:00
|
|
|
var isSelected,
|
|
|
|
pos = getColumnPositionById(id);
|
2011-04-22 22:03:10 +00:00
|
|
|
if (pos > -1) {
|
|
|
|
updateOrder(id);
|
2011-09-09 10:41:13 +00:00
|
|
|
pos > 0 && self.$heads[pos].prev().children().eq(2).toggleClass('OxSelected');
|
|
|
|
self.$heads[pos].toggleClass('OxSelected');
|
|
|
|
self.$heads[pos].next().children().eq(0).toggleClass('OxSelected');
|
2012-12-28 17:02:50 +00:00
|
|
|
isSelected = self.$heads[pos].hasClass('OxSelected');
|
2011-09-09 10:41:13 +00:00
|
|
|
self.$titles[pos].css({
|
2011-09-09 11:37:14 +00:00
|
|
|
width: self.$titles[pos].width()
|
2012-12-28 17:02:50 +00:00
|
|
|
+ (isSelected ? -16 : 16)
|
2011-09-09 11:37:14 +00:00
|
|
|
+ 'px'
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
2012-12-28 17:02:50 +00:00
|
|
|
if (self.visibleColumns[pos].titleImage) {
|
|
|
|
self.$titleImages[pos].attr({
|
2014-09-25 10:28:47 +00:00
|
|
|
src: Ox.getImageURL(
|
2012-12-28 17:02:50 +00:00
|
|
|
'symbol' + Ox.toTitleCase(self.visibleColumns[pos].titleImage),
|
|
|
|
isSelected ? 'selected' : ''
|
|
|
|
)
|
|
|
|
});
|
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function triggerColumnChangeEvent() {
|
|
|
|
that.triggerEvent('columnchange', {
|
2011-09-09 10:41:13 +00:00
|
|
|
ids: self.visibleColumns.map(function(column) {
|
|
|
|
return column.id;
|
2011-04-22 22:03:10 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-08-31 14:57:03 +00:00
|
|
|
function updateClearButton() {
|
|
|
|
if (self.options.clearButton) {
|
|
|
|
self.$clearButton[self.options.selected.length ? 'show' : 'hide']();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-24 13:44:02 +00:00
|
|
|
function updateColumn() {
|
2011-11-05 18:05:14 +00:00
|
|
|
var columnId = self.options.columns[self.selectedColumn].id,
|
2011-05-24 13:44:02 +00:00
|
|
|
isSelected = columnId == self.options.sort[0].key;
|
|
|
|
if (self.options.columnsVisible) {
|
|
|
|
if (isSelected) {
|
|
|
|
updateOrder(columnId);
|
|
|
|
} else {
|
|
|
|
toggleSelected(columnId);
|
|
|
|
self.selectedColumn = getColumnIndexById(self.options.sort[0].key);
|
|
|
|
toggleSelected(self.options.columns[self.selectedColumn].id);
|
|
|
|
}
|
2011-11-03 15:42:41 +00:00
|
|
|
}
|
2011-05-24 13:44:02 +00:00
|
|
|
}
|
|
|
|
|
2012-12-29 16:43:03 +00:00
|
|
|
function updateImages() {
|
|
|
|
// FIXME: not yet used
|
2014-09-22 14:23:21 +00:00
|
|
|
that.$body.find('img').each(function(i, element) {
|
2012-12-29 16:43:03 +00:00
|
|
|
var $element = $(element),
|
2014-09-25 16:35:17 +00:00
|
|
|
data = Ox.getImageData($element.attr('src'));
|
2012-12-29 16:43:03 +00:00
|
|
|
if (data && data.color == 'selected') {
|
2014-09-25 10:28:47 +00:00
|
|
|
$element.attr({src: Ox.getImageURL(data.name, 'default')});
|
2012-12-29 16:43:03 +00:00
|
|
|
}
|
|
|
|
});
|
2014-09-22 14:23:21 +00:00
|
|
|
that.$body.find('.OxSelected img').each(function(i, element) {
|
2012-12-29 16:43:03 +00:00
|
|
|
var $element = $(element),
|
2014-09-25 16:35:17 +00:00
|
|
|
data = Ox.getImageData($element.attr('src'));
|
2012-12-29 16:43:03 +00:00
|
|
|
if (data && data.color == 'default') {
|
2014-09-25 10:28:47 +00:00
|
|
|
$element.attr({src: Ox.getImageURL(data.name, 'selected')});
|
2012-12-29 16:43:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
function updateOrder(id) {
|
2011-09-09 10:41:13 +00:00
|
|
|
var operator = self.options.sort[0].operator,
|
|
|
|
pos = getColumnPositionById(id);
|
2011-08-18 07:55:39 +00:00
|
|
|
if (pos > -1) {
|
2012-12-29 12:56:04 +00:00
|
|
|
self.$orderImages[pos].attr({
|
2014-09-25 10:28:47 +00:00
|
|
|
src: Ox.getImageURL(
|
2012-12-29 12:56:04 +00:00
|
|
|
'symbol' + (operator == '+' ? 'Up' : 'Down'),
|
|
|
|
'selected'
|
|
|
|
)
|
2011-09-09 10:41:13 +00:00
|
|
|
}).css({
|
2012-12-29 12:56:04 +00:00
|
|
|
marginTop: (operator == '+' ? 3 : 2) + 'px'
|
2011-09-09 10:41:13 +00:00
|
|
|
});
|
2011-08-18 07:55:39 +00:00
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
|
2012-08-30 22:16:09 +00:00
|
|
|
that.addColumn = function(id) {
|
|
|
|
addColumn(id);
|
|
|
|
};
|
|
|
|
|
2013-07-13 21:06:03 +00:00
|
|
|
that.addItems = function(items) {
|
|
|
|
that.$body.addItems(items);
|
2012-12-11 15:36:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
that.api = that.$body.options('items');
|
2011-05-24 10:44:34 +00:00
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
closePreivew <f> closePreview
|
|
|
|
@*/
|
2012-04-03 22:34:31 +00:00
|
|
|
that.closePreview = function() {
|
|
|
|
that.$body.closePreview();
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
editCell <f> editCell
|
|
|
|
(id, key, select) -> <u> edit cell
|
|
|
|
@*/
|
2012-02-15 20:59:04 +00:00
|
|
|
that.editCell = function(id, key, select) {
|
2011-11-04 15:54:28 +00:00
|
|
|
Ox.Log('List', 'editCell', id, key)
|
2011-04-22 22:03:10 +00:00
|
|
|
var $item = getItem(id),
|
|
|
|
$cell = getCell(id, key),
|
|
|
|
$input,
|
|
|
|
html = $cell.html(),
|
2013-08-11 08:22:29 +00:00
|
|
|
clickableCells = $item.find('.OxClickable').removeClass('OxClickable'),
|
|
|
|
editableCells = $item.find('.OxEditable').removeClass('OxEditable'),
|
2011-04-22 22:03:10 +00:00
|
|
|
index = getColumnIndexById(key),
|
|
|
|
column = self.options.columns[index],
|
|
|
|
width = column.width - self.options.columnsVisible;
|
|
|
|
$cell.empty()
|
|
|
|
.addClass('OxEdit')
|
2011-09-09 11:37:14 +00:00
|
|
|
.css({width: width + 'px'});
|
2011-06-19 17:48:32 +00:00
|
|
|
$input = Ox.Input({
|
2011-04-22 22:03:10 +00:00
|
|
|
autovalidate: column.input ? column.input.autovalidate : null,
|
|
|
|
style: 'square',
|
2013-07-15 12:03:01 +00:00
|
|
|
textAlign: column.align || 'left',
|
2012-02-22 10:14:25 +00:00
|
|
|
value: column.unformat ? column.unformat(html) : html,
|
2013-08-11 08:28:03 +00:00
|
|
|
width: width - 2
|
2011-04-22 22:03:10 +00:00
|
|
|
})
|
2013-08-11 08:28:03 +00:00
|
|
|
.css({padding: '0 1px'})
|
2012-05-28 14:06:22 +00:00
|
|
|
.on({
|
2011-04-22 22:03:10 +00:00
|
|
|
mousedown: function(e) {
|
|
|
|
// keep mousedown from reaching list
|
|
|
|
e.stopPropagation();
|
2012-05-26 15:48:19 +00:00
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
blur: submit,
|
2012-01-27 18:28:44 +00:00
|
|
|
cancel: submit,
|
|
|
|
submit: submit
|
2011-04-22 22:03:10 +00:00
|
|
|
})
|
|
|
|
.appendTo($cell);
|
2012-05-21 19:23:16 +00:00
|
|
|
// use timeout to prevent key to be inserted
|
|
|
|
// into $input if triggered via keyboard shortcut
|
2012-02-15 20:59:04 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
$input.focusInput(select);
|
2013-08-11 08:10:26 +00:00
|
|
|
});
|
2011-04-22 22:03:10 +00:00
|
|
|
function submit() {
|
|
|
|
var value = $input.value();
|
2012-01-27 18:28:44 +00:00
|
|
|
$input.remove();
|
2011-04-22 22:03:10 +00:00
|
|
|
$cell.removeClass('OxEdit')
|
|
|
|
.css({
|
2011-09-01 09:16:41 +00:00
|
|
|
// account for padding
|
2011-04-22 22:03:10 +00:00
|
|
|
width: (width - 8) + 'px'
|
|
|
|
})
|
2011-09-01 09:16:41 +00:00
|
|
|
.html(value);
|
2013-08-11 08:22:29 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
clickableCells.addClass('OxClickable');
|
|
|
|
editableCells.addClass('OxEditable');
|
|
|
|
}, 250);
|
2011-04-22 22:03:10 +00:00
|
|
|
that.triggerEvent('submit', {
|
|
|
|
id: id,
|
|
|
|
key: key,
|
|
|
|
value: value
|
|
|
|
});
|
|
|
|
}
|
2012-05-21 19:23:16 +00:00
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
gainFocus <f> gainFocus
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.gainFocus = function() {
|
|
|
|
that.$body.gainFocus();
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-08-30 22:16:09 +00:00
|
|
|
that.getColumnWidth = function(id) {
|
|
|
|
var pos = getColumnPositionById(id);
|
|
|
|
return self.columnWidths[pos];
|
|
|
|
};
|
|
|
|
|
2014-02-12 13:56:54 +00:00
|
|
|
that.getPasteIndex = function() {
|
|
|
|
return that.$body.getPasteIndex();
|
|
|
|
};
|
|
|
|
|
2012-08-30 22:16:09 +00:00
|
|
|
// FIXME: needed?
|
|
|
|
that.getVisibleColumns = function() {
|
|
|
|
return self.visibleColumns.map(function(column) {
|
|
|
|
return column.id;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
hasFocus <f> hasFocus
|
|
|
|
@*/
|
2012-04-24 08:21:00 +00:00
|
|
|
that.hasFocus = function() {
|
|
|
|
return that.$body.hasFocus();
|
|
|
|
};
|
|
|
|
|
2013-08-02 12:23:43 +00:00
|
|
|
that.invertSelection = function() {
|
|
|
|
that.$body.invertSelection();
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
loseFocus <f> loseFocus
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.loseFocus = function() {
|
|
|
|
that.$body.loseFocus();
|
|
|
|
return that;
|
2012-04-03 22:34:31 +00:00
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
openPreview <f> openPreview
|
|
|
|
@*/
|
2012-04-03 22:34:31 +00:00
|
|
|
that.openPreview = function() {
|
|
|
|
that.$body.openPreview();
|
|
|
|
return that;
|
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
reloadList <f> reloadList
|
|
|
|
(stayAtPosition) -> <o> reload list
|
|
|
|
@*/
|
2011-05-29 16:05:29 +00:00
|
|
|
that.reloadList = function(stayAtPosition) {
|
|
|
|
that.$body.reloadList(stayAtPosition);
|
2011-04-22 22:03:10 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-08-30 22:16:09 +00:00
|
|
|
that.removeColumn = function(id) {
|
|
|
|
removeColumn(id);
|
2012-12-18 10:45:36 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2013-08-02 12:23:43 +00:00
|
|
|
that.selectAll = function() {
|
|
|
|
that.$body.selectAll();
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-12-18 10:45:36 +00:00
|
|
|
that.selectPosition = function(pos) {
|
|
|
|
that.$body.selectPosition(pos);
|
|
|
|
return that;
|
2012-08-30 22:16:09 +00:00
|
|
|
};
|
|
|
|
|
2014-02-02 12:34:12 +00:00
|
|
|
that.selectSelected = function(offset) {
|
|
|
|
that.$body.selectSelected(offset);
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-12-16 16:19:10 +00:00
|
|
|
that.setColumnTitle = function(id, title) {
|
|
|
|
var index = getColumnIndexById(id);
|
|
|
|
self.options.columns[index].title = title;
|
|
|
|
if (self.options.columns[index].visible) {
|
|
|
|
self.$titles[getColumnPositionById(id)].html(title);
|
|
|
|
}
|
2012-12-18 10:45:36 +00:00
|
|
|
return that;
|
2012-12-16 16:19:10 +00:00
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
resizeColumn <f> resizeColumn
|
|
|
|
(id, width) -> <o> resize column id to width
|
|
|
|
@*/
|
2012-08-30 22:16:09 +00:00
|
|
|
that.setColumnWidth = that.resizeColumn = function(id, width) {
|
2011-04-22 22:03:10 +00:00
|
|
|
resizeColumn(id, width);
|
|
|
|
return that;
|
2012-05-21 19:23:16 +00:00
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2012-08-30 22:16:09 +00:00
|
|
|
// FIXME: needed?
|
|
|
|
that.setVisibleColumns = function(ids) {
|
|
|
|
Ox.forEach(ids, function(id) {
|
|
|
|
var index = getColumnIndexById(id);
|
|
|
|
if (!self.options.columns[index].visible) {
|
|
|
|
addColumn(id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Ox.forEach(self.visibleColumns, function(column) {
|
|
|
|
if (ids.indexOf(column.id) == -1) {
|
|
|
|
removeColumn(column.id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
triggerColumnChangeEvent();
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
size <f> size
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.size = function() {
|
|
|
|
setWidth();
|
|
|
|
that.$body.size();
|
2012-08-30 22:16:09 +00:00
|
|
|
return that;
|
2012-05-21 19:23:16 +00:00
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-05-24 13:44:02 +00:00
|
|
|
// fixme: deprecated
|
2011-04-22 22:03:10 +00:00
|
|
|
that.sortList = function(key, operator) {
|
2011-11-04 15:54:28 +00:00
|
|
|
Ox.Log('List', '$$$$ DEPRECATED $$$$')
|
2011-04-22 22:03:10 +00:00
|
|
|
var isSelected = key == self.options.sort[0].key;
|
2011-05-24 12:50:16 +00:00
|
|
|
self.options.sort = [{
|
|
|
|
key: key,
|
|
|
|
operator: operator,
|
|
|
|
map: self.options.columns[self.selectedColumn].sort
|
|
|
|
}];
|
2011-04-22 22:03:10 +00:00
|
|
|
if (self.options.columnsVisible) {
|
|
|
|
if (isSelected) {
|
|
|
|
updateOrder(self.options.columns[self.selectedColumn].id);
|
|
|
|
} else {
|
|
|
|
toggleSelected(self.options.columns[self.selectedColumn].id);
|
|
|
|
self.selectedColumn = getColumnIndexById(key);
|
|
|
|
toggleSelected(self.options.columns[self.selectedColumn].id);
|
|
|
|
}
|
|
|
|
}
|
2011-05-22 17:12:21 +00:00
|
|
|
// fixme: strangely, sorting the list blocks toggling the selection,
|
|
|
|
// so we use a timeout for now
|
|
|
|
setTimeout(function() {
|
2011-05-24 13:44:02 +00:00
|
|
|
that.$body.options({sort: self.options.sort});
|
|
|
|
/*
|
2011-05-22 17:12:21 +00:00
|
|
|
that.$body.sortList(
|
|
|
|
self.options.sort[0].key,
|
|
|
|
self.options.sort[0].operator,
|
2011-05-24 12:50:16 +00:00
|
|
|
self.options.sort[0].map
|
2011-05-22 17:12:21 +00:00
|
|
|
);
|
2011-05-24 13:44:02 +00:00
|
|
|
*/
|
2011-05-22 17:12:21 +00:00
|
|
|
}, 10);
|
2011-04-22 22:03:10 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
value <f> value
|
|
|
|
(id) -> get values of row id
|
|
|
|
(id, key) -> get value of cell id, key
|
|
|
|
(id, key, value) -> set id, key to value
|
2013-12-01 13:55:10 +00:00
|
|
|
(id, {key: value, ...}) -> set id, keys to values
|
2012-05-21 10:38:18 +00:00
|
|
|
@*/
|
2013-12-01 13:55:10 +00:00
|
|
|
that.value = function() {
|
|
|
|
var $cell,
|
|
|
|
args = Ox.slice(arguments),
|
|
|
|
id = args.shift(),
|
|
|
|
sort = false;
|
2011-04-22 22:03:10 +00:00
|
|
|
if (arguments.length == 1) {
|
|
|
|
return that.$body.value(id);
|
2013-12-01 13:55:10 +00:00
|
|
|
} else if (arguments.length == 2 && Ox.isString(arguments[1])) {
|
|
|
|
return that.$body.value(id, arguments[1]);
|
2011-04-22 22:03:10 +00:00
|
|
|
} else {
|
2014-02-13 09:31:06 +00:00
|
|
|
that.$body.value(id, Ox.makeObject(args));
|
2013-12-01 13:55:10 +00:00
|
|
|
Ox.forEach(Ox.makeObject(args), function(value, key) {
|
|
|
|
if (key == self.options.unique) {
|
|
|
|
// unique id has changed
|
|
|
|
self.options.selected = self.options.selected.map(function(id_) {
|
|
|
|
return id_ == id ? value : id_
|
|
|
|
});
|
|
|
|
id = value;
|
|
|
|
}
|
|
|
|
$cell = getCell(id, key);
|
|
|
|
if ($cell && !$cell.is('.OxEdit')) {
|
|
|
|
$cell.html(formatValue(key, value, that.$body.value(id)));
|
|
|
|
}
|
|
|
|
if (!self.options.sortable && key == self.options.sort[0].key) {
|
|
|
|
// sort key has changed
|
|
|
|
sort = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
sort && that.$body.sort();
|
2011-04-22 22:03:10 +00:00
|
|
|
return that;
|
|
|
|
}
|
2012-05-21 19:23:16 +00:00
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|