slickgrid-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +75 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/fetch.sh +8 -0
- data/lib/slickgrid-rails.rb +1 -0
- data/lib/slickgrid/rails.rb +5 -0
- data/lib/slickgrid/rails/engine.rb +7 -0
- data/lib/slickgrid/rails/version.rb +6 -0
- data/lib/slickgrid/table.rb +72 -0
- data/slickgrid-rails.gemspec +22 -0
- data/vendor/assets/images/slick/actions.gif +0 -0
- data/vendor/assets/images/slick/ajax-loader-small.gif +0 -0
- data/vendor/assets/images/slick/arrow_redo.png +0 -0
- data/vendor/assets/images/slick/arrow_right_peppermint.png +0 -0
- data/vendor/assets/images/slick/arrow_right_spearmint.png +0 -0
- data/vendor/assets/images/slick/arrow_undo.png +0 -0
- data/vendor/assets/images/slick/bullet_blue.png +0 -0
- data/vendor/assets/images/slick/bullet_star.png +0 -0
- data/vendor/assets/images/slick/bullet_toggle_minus.png +0 -0
- data/vendor/assets/images/slick/bullet_toggle_plus.png +0 -0
- data/vendor/assets/images/slick/calendar.gif +0 -0
- data/vendor/assets/images/slick/collapse.gif +0 -0
- data/vendor/assets/images/slick/comment_yellow.gif +0 -0
- data/vendor/assets/images/slick/down.gif +0 -0
- data/vendor/assets/images/slick/drag-handle.png +0 -0
- data/vendor/assets/images/slick/editor-helper-bg.gif +0 -0
- data/vendor/assets/images/slick/expand.gif +0 -0
- data/vendor/assets/images/slick/header-bg.gif +0 -0
- data/vendor/assets/images/slick/header-columns-bg.gif +0 -0
- data/vendor/assets/images/slick/header-columns-over-bg.gif +0 -0
- data/vendor/assets/images/slick/help.png +0 -0
- data/vendor/assets/images/slick/info.gif +0 -0
- data/vendor/assets/images/slick/listview.gif +0 -0
- data/vendor/assets/images/slick/pencil.gif +0 -0
- data/vendor/assets/images/slick/row-over-bg.gif +0 -0
- data/vendor/assets/images/slick/sort-asc.gif +0 -0
- data/vendor/assets/images/slick/sort-asc.png +0 -0
- data/vendor/assets/images/slick/sort-desc.gif +0 -0
- data/vendor/assets/images/slick/sort-desc.png +0 -0
- data/vendor/assets/images/slick/stripes.png +0 -0
- data/vendor/assets/images/slick/tag_red.png +0 -0
- data/vendor/assets/images/slick/tick.png +0 -0
- data/vendor/assets/images/slick/user_identity.gif +0 -0
- data/vendor/assets/images/slick/user_identity_plus.gif +0 -0
- data/vendor/assets/javascripts/slick.js +4 -0
- data/vendor/assets/javascripts/slick/controls/columnpicker.js +106 -0
- data/vendor/assets/javascripts/slick/controls/pager.js +151 -0
- data/vendor/assets/javascripts/slick/core.js +424 -0
- data/vendor/assets/javascripts/slick/dataview.js +908 -0
- data/vendor/assets/javascripts/slick/editors.js +512 -0
- data/vendor/assets/javascripts/slick/formatters.js +55 -0
- data/vendor/assets/javascripts/slick/grid.js +2783 -0
- data/vendor/assets/javascripts/slick/groupitemmetadataprovider.js +139 -0
- data/vendor/assets/javascripts/slick/plugins/autotooltips.js +48 -0
- data/vendor/assets/javascripts/slick/plugins/cellcopymanager.js +86 -0
- data/vendor/assets/javascripts/slick/plugins/cellrangedecorator.js +64 -0
- data/vendor/assets/javascripts/slick/plugins/cellrangeselector.js +112 -0
- data/vendor/assets/javascripts/slick/plugins/cellselectionmodel.js +92 -0
- data/vendor/assets/javascripts/slick/plugins/checkboxselectcolumn.js +154 -0
- data/vendor/assets/javascripts/slick/plugins/rowmovemanager.js +132 -0
- data/vendor/assets/javascripts/slick/plugins/rowselectionmodel.js +187 -0
- data/vendor/assets/javascripts/slick/remotemodel.js +164 -0
- data/vendor/assets/stylesheets/slick/controls/columnpicker.css +30 -0
- data/vendor/assets/stylesheets/slick/controls/pager.css.scss +41 -0
- data/vendor/assets/stylesheets/slick/default-theme.css.scss +104 -0
- data/vendor/assets/stylesheets/slick/grid.css.scss +158 -0
- metadata +158 -0
@@ -0,0 +1,139 @@
|
|
1
|
+
(function ($) {
|
2
|
+
$.extend(true, window, {
|
3
|
+
Slick: {
|
4
|
+
Data: {
|
5
|
+
GroupItemMetadataProvider: GroupItemMetadataProvider
|
6
|
+
}
|
7
|
+
}
|
8
|
+
});
|
9
|
+
|
10
|
+
|
11
|
+
/***
|
12
|
+
* Provides item metadata for group (Slick.Group) and totals (Slick.Totals) rows produced by the DataView.
|
13
|
+
* This metadata overrides the default behavior and formatting of those rows so that they appear and function
|
14
|
+
* correctly when processed by the grid.
|
15
|
+
*
|
16
|
+
* This class also acts as a grid plugin providing event handlers to expand & collapse groups.
|
17
|
+
* If "grid.registerPlugin(...)" is not called, expand & collapse will not work.
|
18
|
+
*
|
19
|
+
* @class GroupItemMetadataProvider
|
20
|
+
* @module Data
|
21
|
+
* @namespace Slick.Data
|
22
|
+
* @constructor
|
23
|
+
* @param options
|
24
|
+
*/
|
25
|
+
function GroupItemMetadataProvider(options) {
|
26
|
+
var _grid;
|
27
|
+
var _defaults = {
|
28
|
+
groupCssClass: "slick-group",
|
29
|
+
totalsCssClass: "slick-group-totals",
|
30
|
+
groupFocusable: true,
|
31
|
+
totalsFocusable: false,
|
32
|
+
toggleCssClass: "slick-group-toggle",
|
33
|
+
toggleExpandedCssClass: "expanded",
|
34
|
+
toggleCollapsedCssClass: "collapsed",
|
35
|
+
enableExpandCollapse: true
|
36
|
+
};
|
37
|
+
|
38
|
+
options = $.extend(true, {}, _defaults, options);
|
39
|
+
|
40
|
+
|
41
|
+
function defaultGroupCellFormatter(row, cell, value, columnDef, item) {
|
42
|
+
if (!options.enableExpandCollapse) {
|
43
|
+
return item.title;
|
44
|
+
}
|
45
|
+
|
46
|
+
return "<span class='" + options.toggleCssClass + " " +
|
47
|
+
(item.collapsed ? options.toggleCollapsedCssClass : options.toggleExpandedCssClass) +
|
48
|
+
"'></span>" + item.title;
|
49
|
+
}
|
50
|
+
|
51
|
+
function defaultTotalsCellFormatter(row, cell, value, columnDef, item) {
|
52
|
+
return (columnDef.groupTotalsFormatter && columnDef.groupTotalsFormatter(item, columnDef)) || "";
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
function init(grid) {
|
57
|
+
_grid = grid;
|
58
|
+
_grid.onClick.subscribe(handleGridClick);
|
59
|
+
_grid.onKeyDown.subscribe(handleGridKeyDown);
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
function destroy() {
|
64
|
+
if (_grid) {
|
65
|
+
_grid.onClick.unsubscribe(handleGridClick);
|
66
|
+
_grid.onKeyDown.unsubscribe(handleGridKeyDown);
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
function handleGridClick(e, args) {
|
71
|
+
var item = this.getDataItem(args.row);
|
72
|
+
if (item && item instanceof Slick.Group && $(e.target).hasClass(options.toggleCssClass)) {
|
73
|
+
if (item.collapsed) {
|
74
|
+
this.getData().expandGroup(item.value);
|
75
|
+
}
|
76
|
+
else {
|
77
|
+
this.getData().collapseGroup(item.value);
|
78
|
+
}
|
79
|
+
|
80
|
+
e.stopImmediatePropagation();
|
81
|
+
e.preventDefault();
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
// TODO: add -/+ handling
|
86
|
+
function handleGridKeyDown(e, args) {
|
87
|
+
if (options.enableExpandCollapse && (e.which == $.ui.keyCode.SPACE)) {
|
88
|
+
var activeCell = this.getActiveCell();
|
89
|
+
if (activeCell) {
|
90
|
+
var item = this.getDataItem(activeCell.row);
|
91
|
+
if (item && item instanceof Slick.Group) {
|
92
|
+
if (item.collapsed) {
|
93
|
+
this.getData().expandGroup(item.value);
|
94
|
+
}
|
95
|
+
else {
|
96
|
+
this.getData().collapseGroup(item.value);
|
97
|
+
}
|
98
|
+
|
99
|
+
e.stopImmediatePropagation();
|
100
|
+
e.preventDefault();
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
function getGroupRowMetadata(item) {
|
107
|
+
return {
|
108
|
+
selectable: false,
|
109
|
+
focusable: options.groupFocusable,
|
110
|
+
cssClasses: options.groupCssClass,
|
111
|
+
columns: {
|
112
|
+
0: {
|
113
|
+
colspan: "*",
|
114
|
+
formatter: defaultGroupCellFormatter,
|
115
|
+
editor: null
|
116
|
+
}
|
117
|
+
}
|
118
|
+
};
|
119
|
+
}
|
120
|
+
|
121
|
+
function getTotalsRowMetadata(item) {
|
122
|
+
return {
|
123
|
+
selectable: false,
|
124
|
+
focusable: options.totalsFocusable,
|
125
|
+
cssClasses: options.totalsCssClass,
|
126
|
+
formatter: defaultTotalsCellFormatter,
|
127
|
+
editor: null
|
128
|
+
};
|
129
|
+
}
|
130
|
+
|
131
|
+
|
132
|
+
return {
|
133
|
+
"init": init,
|
134
|
+
"destroy": destroy,
|
135
|
+
"getGroupRowMetadata": getGroupRowMetadata,
|
136
|
+
"getTotalsRowMetadata": getTotalsRowMetadata
|
137
|
+
};
|
138
|
+
}
|
139
|
+
})(jQuery);
|
@@ -0,0 +1,48 @@
|
|
1
|
+
(function ($) {
|
2
|
+
// register namespace
|
3
|
+
$.extend(true, window, {
|
4
|
+
"Slick": {
|
5
|
+
"AutoTooltips": AutoTooltips
|
6
|
+
}
|
7
|
+
});
|
8
|
+
|
9
|
+
|
10
|
+
function AutoTooltips(options) {
|
11
|
+
var _grid;
|
12
|
+
var _self = this;
|
13
|
+
var _defaults = {
|
14
|
+
maxToolTipLength: null
|
15
|
+
};
|
16
|
+
|
17
|
+
function init(grid) {
|
18
|
+
options = $.extend(true, {}, _defaults, options);
|
19
|
+
_grid = grid;
|
20
|
+
_grid.onMouseEnter.subscribe(handleMouseEnter);
|
21
|
+
}
|
22
|
+
|
23
|
+
function destroy() {
|
24
|
+
_grid.onMouseEnter.unsubscribe(handleMouseEnter);
|
25
|
+
}
|
26
|
+
|
27
|
+
function handleMouseEnter(e, args) {
|
28
|
+
var cell = _grid.getCellFromEvent(e);
|
29
|
+
if (cell) {
|
30
|
+
var node = _grid.getCellNode(cell.row, cell.cell);
|
31
|
+
if ($(node).innerWidth() < node.scrollWidth) {
|
32
|
+
var text = $.trim($(node).text());
|
33
|
+
if (options.maxToolTipLength && text.length > options.maxToolTipLength) {
|
34
|
+
text = text.substr(0, options.maxToolTipLength - 3) + "...";
|
35
|
+
}
|
36
|
+
$(node).attr("title", text);
|
37
|
+
} else {
|
38
|
+
$(node).attr("title", "");
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
$.extend(this, {
|
44
|
+
"init": init,
|
45
|
+
"destroy": destroy
|
46
|
+
});
|
47
|
+
}
|
48
|
+
})(jQuery);
|
@@ -0,0 +1,86 @@
|
|
1
|
+
(function ($) {
|
2
|
+
// register namespace
|
3
|
+
$.extend(true, window, {
|
4
|
+
"Slick": {
|
5
|
+
"CellCopyManager": CellCopyManager
|
6
|
+
}
|
7
|
+
});
|
8
|
+
|
9
|
+
|
10
|
+
function CellCopyManager() {
|
11
|
+
var _grid;
|
12
|
+
var _self = this;
|
13
|
+
var _copiedRanges;
|
14
|
+
|
15
|
+
function init(grid) {
|
16
|
+
_grid = grid;
|
17
|
+
_grid.onKeyDown.subscribe(handleKeyDown);
|
18
|
+
}
|
19
|
+
|
20
|
+
function destroy() {
|
21
|
+
_grid.onKeyDown.unsubscribe(handleKeyDown);
|
22
|
+
}
|
23
|
+
|
24
|
+
function handleKeyDown(e, args) {
|
25
|
+
var ranges;
|
26
|
+
if (!_grid.getEditorLock().isActive()) {
|
27
|
+
if (e.which == $.ui.keyCode.ESCAPE) {
|
28
|
+
if (_copiedRanges) {
|
29
|
+
e.preventDefault();
|
30
|
+
clearCopySelection();
|
31
|
+
_self.onCopyCancelled.notify({ranges: _copiedRanges});
|
32
|
+
_copiedRanges = null;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
if (e.which == 67 && (e.ctrlKey || e.metaKey)) {
|
37
|
+
ranges = _grid.getSelectionModel().getSelectedRanges();
|
38
|
+
if (ranges.length != 0) {
|
39
|
+
e.preventDefault();
|
40
|
+
_copiedRanges = ranges;
|
41
|
+
markCopySelection(ranges);
|
42
|
+
_self.onCopyCells.notify({ranges: ranges});
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
if (e.which == 86 && (e.ctrlKey || e.metaKey)) {
|
47
|
+
if (_copiedRanges) {
|
48
|
+
e.preventDefault();
|
49
|
+
clearCopySelection();
|
50
|
+
ranges = _grid.getSelectionModel().getSelectedRanges();
|
51
|
+
_self.onPasteCells.notify({from: _copiedRanges, to: ranges});
|
52
|
+
_copiedRanges = null;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
function markCopySelection(ranges) {
|
59
|
+
var columns = _grid.getColumns();
|
60
|
+
var hash = {};
|
61
|
+
for (var i = 0; i < ranges.length; i++) {
|
62
|
+
for (var j = ranges[i].fromRow; j <= ranges[i].toRow; j++) {
|
63
|
+
hash[j] = {};
|
64
|
+
for (var k = ranges[i].fromCell; k <= ranges[i].toCell; k++) {
|
65
|
+
hash[j][columns[k].id] = "copied";
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
_grid.setCellCssStyles("copy-manager", hash);
|
70
|
+
}
|
71
|
+
|
72
|
+
function clearCopySelection() {
|
73
|
+
_grid.removeCellCssStyles("copy-manager");
|
74
|
+
}
|
75
|
+
|
76
|
+
$.extend(this, {
|
77
|
+
"init": init,
|
78
|
+
"destroy": destroy,
|
79
|
+
"clearCopySelection": clearCopySelection,
|
80
|
+
|
81
|
+
"onCopyCells": new Slick.Event(),
|
82
|
+
"onCopyCancelled": new Slick.Event(),
|
83
|
+
"onPasteCells": new Slick.Event()
|
84
|
+
});
|
85
|
+
}
|
86
|
+
})(jQuery);
|
@@ -0,0 +1,64 @@
|
|
1
|
+
(function ($) {
|
2
|
+
// register namespace
|
3
|
+
$.extend(true, window, {
|
4
|
+
"Slick": {
|
5
|
+
"CellRangeDecorator": CellRangeDecorator
|
6
|
+
}
|
7
|
+
});
|
8
|
+
|
9
|
+
/***
|
10
|
+
* Displays an overlay on top of a given cell range.
|
11
|
+
*
|
12
|
+
* TODO:
|
13
|
+
* Currently, it blocks mouse events to DOM nodes behind it.
|
14
|
+
* Use FF and WebKit-specific "pointer-events" CSS style, or some kind of event forwarding.
|
15
|
+
* Could also construct the borders separately using 4 individual DIVs.
|
16
|
+
*
|
17
|
+
* @param {Grid} grid
|
18
|
+
* @param {Object} options
|
19
|
+
*/
|
20
|
+
function CellRangeDecorator(grid, options) {
|
21
|
+
var _elem;
|
22
|
+
var _defaults = {
|
23
|
+
selectionCss: {
|
24
|
+
"zIndex": "9999",
|
25
|
+
"border": "2px dashed red"
|
26
|
+
}
|
27
|
+
};
|
28
|
+
|
29
|
+
options = $.extend(true, {}, _defaults, options);
|
30
|
+
|
31
|
+
|
32
|
+
function show(range) {
|
33
|
+
if (!_elem) {
|
34
|
+
_elem = $("<div></div>", {css: options.selectionCss})
|
35
|
+
.css("position", "absolute")
|
36
|
+
.appendTo(grid.getCanvasNode());
|
37
|
+
}
|
38
|
+
|
39
|
+
var from = grid.getCellNodeBox(range.fromRow, range.fromCell);
|
40
|
+
var to = grid.getCellNodeBox(range.toRow, range.toCell);
|
41
|
+
|
42
|
+
_elem.css({
|
43
|
+
top: from.top - 1,
|
44
|
+
left: from.left - 1,
|
45
|
+
height: to.bottom - from.top - 2,
|
46
|
+
width: to.right - from.left - 2
|
47
|
+
});
|
48
|
+
|
49
|
+
return _elem;
|
50
|
+
}
|
51
|
+
|
52
|
+
function hide() {
|
53
|
+
if (_elem) {
|
54
|
+
_elem.remove();
|
55
|
+
_elem = null;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
$.extend(this, {
|
60
|
+
"show": show,
|
61
|
+
"hide": hide
|
62
|
+
});
|
63
|
+
}
|
64
|
+
})(jQuery);
|
@@ -0,0 +1,112 @@
|
|
1
|
+
(function ($) {
|
2
|
+
// register namespace
|
3
|
+
$.extend(true, window, {
|
4
|
+
"Slick": {
|
5
|
+
"CellRangeSelector": CellRangeSelector
|
6
|
+
}
|
7
|
+
});
|
8
|
+
|
9
|
+
|
10
|
+
function CellRangeSelector(options) {
|
11
|
+
var _grid;
|
12
|
+
var _canvas;
|
13
|
+
var _dragging;
|
14
|
+
var _decorator;
|
15
|
+
var _self = this;
|
16
|
+
var _defaults = {
|
17
|
+
selectionCss: {
|
18
|
+
"border": "2px dashed blue"
|
19
|
+
}
|
20
|
+
};
|
21
|
+
|
22
|
+
|
23
|
+
function init(grid) {
|
24
|
+
options = $.extend(true, {}, _defaults, options);
|
25
|
+
_decorator = new Slick.CellRangeDecorator(grid, options);
|
26
|
+
_grid = grid;
|
27
|
+
_canvas = _grid.getCanvasNode();
|
28
|
+
_grid.onDragInit.subscribe(handleDragInit);
|
29
|
+
_grid.onDragStart.subscribe(handleDragStart);
|
30
|
+
_grid.onDrag.subscribe(handleDrag);
|
31
|
+
_grid.onDragEnd.subscribe(handleDragEnd);
|
32
|
+
}
|
33
|
+
|
34
|
+
function destroy() {
|
35
|
+
_grid.onDragInit.unsubscribe(handleDragInit);
|
36
|
+
_grid.onDragStart.unsubscribe(handleDragStart);
|
37
|
+
_grid.onDrag.unsubscribe(handleDrag);
|
38
|
+
_grid.onDragEnd.unsubscribe(handleDragEnd);
|
39
|
+
}
|
40
|
+
|
41
|
+
function handleDragInit(e, dd) {
|
42
|
+
// prevent the grid from cancelling drag'n'drop by default
|
43
|
+
e.stopImmediatePropagation();
|
44
|
+
}
|
45
|
+
|
46
|
+
function handleDragStart(e, dd) {
|
47
|
+
var cell = _grid.getCellFromEvent(e);
|
48
|
+
if (_self.onBeforeCellRangeSelected.notify(cell) !== false) {
|
49
|
+
if (_grid.canCellBeSelected(cell.row, cell.cell)) {
|
50
|
+
_dragging = true;
|
51
|
+
e.stopImmediatePropagation();
|
52
|
+
}
|
53
|
+
}
|
54
|
+
if (!_dragging) {
|
55
|
+
return;
|
56
|
+
}
|
57
|
+
|
58
|
+
var start = _grid.getCellFromPoint(
|
59
|
+
dd.startX - $(_canvas).offset().left,
|
60
|
+
dd.startY - $(_canvas).offset().top);
|
61
|
+
|
62
|
+
dd.range = {start: start, end: {}};
|
63
|
+
|
64
|
+
return _decorator.show(new Slick.Range(start.row, start.cell));
|
65
|
+
}
|
66
|
+
|
67
|
+
function handleDrag(e, dd) {
|
68
|
+
if (!_dragging) {
|
69
|
+
return;
|
70
|
+
}
|
71
|
+
e.stopImmediatePropagation();
|
72
|
+
|
73
|
+
var end = _grid.getCellFromPoint(
|
74
|
+
e.pageX - $(_canvas).offset().left,
|
75
|
+
e.pageY - $(_canvas).offset().top);
|
76
|
+
|
77
|
+
if (!_grid.canCellBeSelected(end.row, end.cell)) {
|
78
|
+
return;
|
79
|
+
}
|
80
|
+
|
81
|
+
dd.range.end = end;
|
82
|
+
_decorator.show(new Slick.Range(dd.range.start.row, dd.range.start.cell, end.row, end.cell));
|
83
|
+
}
|
84
|
+
|
85
|
+
function handleDragEnd(e, dd) {
|
86
|
+
if (!_dragging) {
|
87
|
+
return;
|
88
|
+
}
|
89
|
+
|
90
|
+
_dragging = false;
|
91
|
+
e.stopImmediatePropagation();
|
92
|
+
|
93
|
+
_decorator.hide();
|
94
|
+
_self.onCellRangeSelected.notify({
|
95
|
+
range: new Slick.Range(
|
96
|
+
dd.range.start.row,
|
97
|
+
dd.range.start.cell,
|
98
|
+
dd.range.end.row,
|
99
|
+
dd.range.end.cell
|
100
|
+
)
|
101
|
+
});
|
102
|
+
}
|
103
|
+
|
104
|
+
$.extend(this, {
|
105
|
+
"init": init,
|
106
|
+
"destroy": destroy,
|
107
|
+
|
108
|
+
"onBeforeCellRangeSelected": new Slick.Event(),
|
109
|
+
"onCellRangeSelected": new Slick.Event()
|
110
|
+
});
|
111
|
+
}
|
112
|
+
})(jQuery);
|