slickgrid 2.3.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +30 -0
- data/lib/slickgrid.rb +6 -0
- data/lib/slickgrid/version.rb +3 -0
- data/slickgrid.gemspec +20 -0
- data/vendor/assets/images/slickgrid/CheckboxN.png +0 -0
- data/vendor/assets/images/slickgrid/CheckboxY.png +0 -0
- data/vendor/assets/images/slickgrid/GrpCheckboxN.png +0 -0
- data/vendor/assets/images/slickgrid/GrpCheckboxY.png +0 -0
- data/vendor/assets/images/slickgrid/actions.gif +0 -0
- data/vendor/assets/images/slickgrid/ajax-loader-small.gif +0 -0
- data/vendor/assets/images/slickgrid/arrow-right.gif +0 -0
- data/vendor/assets/images/slickgrid/arrow_redo.png +0 -0
- data/vendor/assets/images/slickgrid/arrow_right_peppermint.png +0 -0
- data/vendor/assets/images/slickgrid/arrow_right_spearmint.png +0 -0
- data/vendor/assets/images/slickgrid/arrow_undo.png +0 -0
- data/vendor/assets/images/slickgrid/bullet_blue.png +0 -0
- data/vendor/assets/images/slickgrid/bullet_star.png +0 -0
- data/vendor/assets/images/slickgrid/bullet_toggle_minus.png +0 -0
- data/vendor/assets/images/slickgrid/bullet_toggle_plus.png +0 -0
- data/vendor/assets/images/slickgrid/calendar.gif +0 -0
- data/vendor/assets/images/slickgrid/collapse.gif +0 -0
- data/vendor/assets/images/slickgrid/comment_yellow.gif +0 -0
- data/vendor/assets/images/slickgrid/delete.png +0 -0
- data/vendor/assets/images/slickgrid/down.gif +0 -0
- data/vendor/assets/images/slickgrid/drag-handle.png +0 -0
- data/vendor/assets/images/slickgrid/editor-helper-bg.gif +0 -0
- data/vendor/assets/images/slickgrid/expand.gif +0 -0
- data/vendor/assets/images/slickgrid/header-bg.gif +0 -0
- data/vendor/assets/images/slickgrid/header-columns-bg.gif +0 -0
- data/vendor/assets/images/slickgrid/header-columns-over-bg.gif +0 -0
- data/vendor/assets/images/slickgrid/help.png +0 -0
- data/vendor/assets/images/slickgrid/info.gif +0 -0
- data/vendor/assets/images/slickgrid/listview.gif +0 -0
- data/vendor/assets/images/slickgrid/pencil.gif +0 -0
- data/vendor/assets/images/slickgrid/row-over-bg.gif +0 -0
- data/vendor/assets/images/slickgrid/sort-asc.gif +0 -0
- data/vendor/assets/images/slickgrid/sort-asc.png +0 -0
- data/vendor/assets/images/slickgrid/sort-desc.gif +0 -0
- data/vendor/assets/images/slickgrid/sort-desc.png +0 -0
- data/vendor/assets/images/slickgrid/stripes.png +0 -0
- data/vendor/assets/images/slickgrid/tag_red.png +0 -0
- data/vendor/assets/images/slickgrid/tick.png +0 -0
- data/vendor/assets/images/slickgrid/user_identity.gif +0 -0
- data/vendor/assets/images/slickgrid/user_identity_plus.gif +0 -0
- data/vendor/assets/javascripts/slickgrid.js +5 -0
- data/vendor/assets/javascripts/slickgrid/controls/columnpicker.js +221 -0
- data/vendor/assets/javascripts/slickgrid/controls/gridmenu.js +429 -0
- data/vendor/assets/javascripts/slickgrid/controls/pager.js +154 -0
- data/vendor/assets/javascripts/slickgrid/core.js +493 -0
- data/vendor/assets/javascripts/slickgrid/dataview.js +1220 -0
- data/vendor/assets/javascripts/slickgrid/editors.js +640 -0
- data/vendor/assets/javascripts/slickgrid/formatters.js +65 -0
- data/vendor/assets/javascripts/slickgrid/grid.js +3990 -0
- data/vendor/assets/javascripts/slickgrid/groupitemmetadataprovider.js +172 -0
- data/vendor/assets/javascripts/slickgrid/plugins/autotooltips.js +83 -0
- data/vendor/assets/javascripts/slickgrid/plugins/cellcopymanager.js +88 -0
- data/vendor/assets/javascripts/slickgrid/plugins/cellexternalcopymanager.js +452 -0
- data/vendor/assets/javascripts/slickgrid/plugins/cellrangedecorator.js +72 -0
- data/vendor/assets/javascripts/slickgrid/plugins/cellrangeselector.js +123 -0
- data/vendor/assets/javascripts/slickgrid/plugins/cellselectionmodel.js +168 -0
- data/vendor/assets/javascripts/slickgrid/plugins/checkboxselectcolumn.js +202 -0
- data/vendor/assets/javascripts/slickgrid/plugins/draggablegrouping.js +207 -0
- data/vendor/assets/javascripts/slickgrid/plugins/headerbuttons.js +177 -0
- data/vendor/assets/javascripts/slickgrid/plugins/headermenu.js +296 -0
- data/vendor/assets/javascripts/slickgrid/plugins/rowdetailview.js +455 -0
- data/vendor/assets/javascripts/slickgrid/plugins/rowmovemanager.js +138 -0
- data/vendor/assets/javascripts/slickgrid/plugins/rowselectionmodel.js +191 -0
- data/vendor/assets/javascripts/slickgrid/remotemodel.js +169 -0
- data/vendor/assets/stylesheets/slickgrid.scss +1 -0
- data/vendor/assets/stylesheets/slickgrid/controls/columnpicker.css +46 -0
- data/vendor/assets/stylesheets/slickgrid/controls/gridmenu.css +113 -0
- data/vendor/assets/stylesheets/slickgrid/controls/pager.css +41 -0
- data/vendor/assets/stylesheets/slickgrid/default-theme.css +132 -0
- data/vendor/assets/stylesheets/slickgrid/grid.css +189 -0
- data/vendor/assets/stylesheets/slickgrid/plugins/headerbuttons.css +39 -0
- data/vendor/assets/stylesheets/slickgrid/plugins/headermenu.css +59 -0
- data/vendor/assets/stylesheets/slickgrid/plugins/rowdetailview.css +39 -0
- metadata +165 -0
@@ -0,0 +1,138 @@
|
|
1
|
+
(function ($) {
|
2
|
+
// register namespace
|
3
|
+
$.extend(true, window, {
|
4
|
+
"Slick": {
|
5
|
+
"RowMoveManager": RowMoveManager
|
6
|
+
}
|
7
|
+
});
|
8
|
+
|
9
|
+
function RowMoveManager(options) {
|
10
|
+
var _grid;
|
11
|
+
var _canvas;
|
12
|
+
var _dragging;
|
13
|
+
var _self = this;
|
14
|
+
var _handler = new Slick.EventHandler();
|
15
|
+
var _defaults = {
|
16
|
+
cancelEditOnDrag: false
|
17
|
+
};
|
18
|
+
|
19
|
+
function init(grid) {
|
20
|
+
options = $.extend(true, {}, _defaults, options);
|
21
|
+
_grid = grid;
|
22
|
+
_canvas = _grid.getCanvasNode();
|
23
|
+
_handler
|
24
|
+
.subscribe(_grid.onDragInit, handleDragInit)
|
25
|
+
.subscribe(_grid.onDragStart, handleDragStart)
|
26
|
+
.subscribe(_grid.onDrag, handleDrag)
|
27
|
+
.subscribe(_grid.onDragEnd, handleDragEnd);
|
28
|
+
}
|
29
|
+
|
30
|
+
function destroy() {
|
31
|
+
_handler.unsubscribeAll();
|
32
|
+
}
|
33
|
+
|
34
|
+
function handleDragInit(e, dd) {
|
35
|
+
// prevent the grid from cancelling drag'n'drop by default
|
36
|
+
e.stopImmediatePropagation();
|
37
|
+
}
|
38
|
+
|
39
|
+
function handleDragStart(e, dd) {
|
40
|
+
var cell = _grid.getCellFromEvent(e);
|
41
|
+
|
42
|
+
if (options.cancelEditOnDrag && _grid.getEditorLock().isActive()) {
|
43
|
+
_grid.getEditorLock().cancelCurrentEdit();
|
44
|
+
}
|
45
|
+
|
46
|
+
if (_grid.getEditorLock().isActive() || !/move|selectAndMove/.test(_grid.getColumns()[cell.cell].behavior)) {
|
47
|
+
return false;
|
48
|
+
}
|
49
|
+
|
50
|
+
_dragging = true;
|
51
|
+
e.stopImmediatePropagation();
|
52
|
+
|
53
|
+
var selectedRows = _grid.getSelectedRows();
|
54
|
+
|
55
|
+
if (selectedRows.length == 0 || $.inArray(cell.row, selectedRows) == -1) {
|
56
|
+
selectedRows = [cell.row];
|
57
|
+
_grid.setSelectedRows(selectedRows);
|
58
|
+
}
|
59
|
+
|
60
|
+
var rowHeight = _grid.getOptions().rowHeight;
|
61
|
+
|
62
|
+
dd.selectedRows = selectedRows;
|
63
|
+
|
64
|
+
dd.selectionProxy = $("<div class='slick-reorder-proxy'/>")
|
65
|
+
.css("position", "absolute")
|
66
|
+
.css("zIndex", "99999")
|
67
|
+
.css("width", $(_canvas).innerWidth())
|
68
|
+
.css("height", rowHeight * selectedRows.length)
|
69
|
+
.appendTo(_canvas);
|
70
|
+
|
71
|
+
dd.guide = $("<div class='slick-reorder-guide'/>")
|
72
|
+
.css("position", "absolute")
|
73
|
+
.css("zIndex", "99998")
|
74
|
+
.css("width", $(_canvas).innerWidth())
|
75
|
+
.css("top", -1000)
|
76
|
+
.appendTo(_canvas);
|
77
|
+
|
78
|
+
dd.insertBefore = -1;
|
79
|
+
}
|
80
|
+
|
81
|
+
function handleDrag(e, dd) {
|
82
|
+
if (!_dragging) {
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
|
86
|
+
e.stopImmediatePropagation();
|
87
|
+
|
88
|
+
var top = e.pageY - $(_canvas).offset().top;
|
89
|
+
dd.selectionProxy.css("top", top - 5);
|
90
|
+
|
91
|
+
var insertBefore = Math.max(0, Math.min(Math.round(top / _grid.getOptions().rowHeight), _grid.getDataLength()));
|
92
|
+
if (insertBefore !== dd.insertBefore) {
|
93
|
+
var eventData = {
|
94
|
+
"rows": dd.selectedRows,
|
95
|
+
"insertBefore": insertBefore
|
96
|
+
};
|
97
|
+
|
98
|
+
if (_self.onBeforeMoveRows.notify(eventData) === false) {
|
99
|
+
dd.guide.css("top", -1000);
|
100
|
+
dd.canMove = false;
|
101
|
+
} else {
|
102
|
+
dd.guide.css("top", insertBefore * _grid.getOptions().rowHeight);
|
103
|
+
dd.canMove = true;
|
104
|
+
}
|
105
|
+
|
106
|
+
dd.insertBefore = insertBefore;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
function handleDragEnd(e, dd) {
|
111
|
+
if (!_dragging) {
|
112
|
+
return;
|
113
|
+
}
|
114
|
+
_dragging = false;
|
115
|
+
e.stopImmediatePropagation();
|
116
|
+
|
117
|
+
dd.guide.remove();
|
118
|
+
dd.selectionProxy.remove();
|
119
|
+
|
120
|
+
if (dd.canMove) {
|
121
|
+
var eventData = {
|
122
|
+
"rows": dd.selectedRows,
|
123
|
+
"insertBefore": dd.insertBefore
|
124
|
+
};
|
125
|
+
// TODO: _grid.remapCellCssClasses ?
|
126
|
+
_self.onMoveRows.notify(eventData);
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
$.extend(this, {
|
131
|
+
"onBeforeMoveRows": new Slick.Event(),
|
132
|
+
"onMoveRows": new Slick.Event(),
|
133
|
+
|
134
|
+
"init": init,
|
135
|
+
"destroy": destroy
|
136
|
+
});
|
137
|
+
}
|
138
|
+
})(jQuery);
|
@@ -0,0 +1,191 @@
|
|
1
|
+
(function ($) {
|
2
|
+
// register namespace
|
3
|
+
$.extend(true, window, {
|
4
|
+
"Slick": {
|
5
|
+
"RowSelectionModel": RowSelectionModel
|
6
|
+
}
|
7
|
+
});
|
8
|
+
|
9
|
+
function RowSelectionModel(options) {
|
10
|
+
var _grid;
|
11
|
+
var _ranges = [];
|
12
|
+
var _self = this;
|
13
|
+
var _handler = new Slick.EventHandler();
|
14
|
+
var _inHandler;
|
15
|
+
var _options;
|
16
|
+
var _defaults = {
|
17
|
+
selectActiveRow: true
|
18
|
+
};
|
19
|
+
|
20
|
+
function init(grid) {
|
21
|
+
_options = $.extend(true, {}, _defaults, options);
|
22
|
+
_grid = grid;
|
23
|
+
_handler.subscribe(_grid.onActiveCellChanged,
|
24
|
+
wrapHandler(handleActiveCellChange));
|
25
|
+
_handler.subscribe(_grid.onKeyDown,
|
26
|
+
wrapHandler(handleKeyDown));
|
27
|
+
_handler.subscribe(_grid.onClick,
|
28
|
+
wrapHandler(handleClick));
|
29
|
+
}
|
30
|
+
|
31
|
+
function destroy() {
|
32
|
+
_handler.unsubscribeAll();
|
33
|
+
}
|
34
|
+
|
35
|
+
function wrapHandler(handler) {
|
36
|
+
return function () {
|
37
|
+
if (!_inHandler) {
|
38
|
+
_inHandler = true;
|
39
|
+
handler.apply(this, arguments);
|
40
|
+
_inHandler = false;
|
41
|
+
}
|
42
|
+
};
|
43
|
+
}
|
44
|
+
|
45
|
+
function rangesToRows(ranges) {
|
46
|
+
var rows = [];
|
47
|
+
for (var i = 0; i < ranges.length; i++) {
|
48
|
+
for (var j = ranges[i].fromRow; j <= ranges[i].toRow; j++) {
|
49
|
+
rows.push(j);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
return rows;
|
53
|
+
}
|
54
|
+
|
55
|
+
function rowsToRanges(rows) {
|
56
|
+
var ranges = [];
|
57
|
+
var lastCell = _grid.getColumns().length - 1;
|
58
|
+
for (var i = 0; i < rows.length; i++) {
|
59
|
+
ranges.push(new Slick.Range(rows[i], 0, rows[i], lastCell));
|
60
|
+
}
|
61
|
+
return ranges;
|
62
|
+
}
|
63
|
+
|
64
|
+
function getRowsRange(from, to) {
|
65
|
+
var i, rows = [];
|
66
|
+
for (i = from; i <= to; i++) {
|
67
|
+
rows.push(i);
|
68
|
+
}
|
69
|
+
for (i = to; i < from; i++) {
|
70
|
+
rows.push(i);
|
71
|
+
}
|
72
|
+
return rows;
|
73
|
+
}
|
74
|
+
|
75
|
+
function getSelectedRows() {
|
76
|
+
return rangesToRows(_ranges);
|
77
|
+
}
|
78
|
+
|
79
|
+
function setSelectedRows(rows) {
|
80
|
+
setSelectedRanges(rowsToRanges(rows));
|
81
|
+
}
|
82
|
+
|
83
|
+
function setSelectedRanges(ranges) {
|
84
|
+
// simple check for: empty selection didn't change, prevent firing onSelectedRangesChanged
|
85
|
+
if ((!_ranges || _ranges.length === 0) && (!ranges || ranges.length === 0)) { return; }
|
86
|
+
_ranges = ranges;
|
87
|
+
_self.onSelectedRangesChanged.notify(_ranges);
|
88
|
+
}
|
89
|
+
|
90
|
+
function getSelectedRanges() {
|
91
|
+
return _ranges;
|
92
|
+
}
|
93
|
+
|
94
|
+
function handleActiveCellChange(e, data) {
|
95
|
+
if (_options.selectActiveRow && data.row != null) {
|
96
|
+
setSelectedRanges([new Slick.Range(data.row, 0, data.row, _grid.getColumns().length - 1)]);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
function handleKeyDown(e) {
|
101
|
+
var activeRow = _grid.getActiveCell();
|
102
|
+
if (_grid.getOptions().multiSelect && activeRow
|
103
|
+
&& e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey
|
104
|
+
&& (e.which == Slick.keyCode.UP || e.which == Slick.keyCode.DOWN)) {
|
105
|
+
var selectedRows = getSelectedRows();
|
106
|
+
selectedRows.sort(function (x, y) {
|
107
|
+
return x - y
|
108
|
+
});
|
109
|
+
|
110
|
+
if (!selectedRows.length) {
|
111
|
+
selectedRows = [activeRow.row];
|
112
|
+
}
|
113
|
+
|
114
|
+
var top = selectedRows[0];
|
115
|
+
var bottom = selectedRows[selectedRows.length - 1];
|
116
|
+
var active;
|
117
|
+
|
118
|
+
if (e.which == Slick.keyCode.DOWN) {
|
119
|
+
active = activeRow.row < bottom || top == bottom ? ++bottom : ++top;
|
120
|
+
} else {
|
121
|
+
active = activeRow.row < bottom ? --bottom : --top;
|
122
|
+
}
|
123
|
+
|
124
|
+
if (active >= 0 && active < _grid.getDataLength()) {
|
125
|
+
_grid.scrollRowIntoView(active);
|
126
|
+
var tempRanges = rowsToRanges(getRowsRange(top, bottom));
|
127
|
+
setSelectedRanges(tempRanges);
|
128
|
+
}
|
129
|
+
|
130
|
+
e.preventDefault();
|
131
|
+
e.stopPropagation();
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
function handleClick(e) {
|
136
|
+
var cell = _grid.getCellFromEvent(e);
|
137
|
+
if (!cell || !_grid.canCellBeActive(cell.row, cell.cell)) {
|
138
|
+
return false;
|
139
|
+
}
|
140
|
+
|
141
|
+
if (!_grid.getOptions().multiSelect || (
|
142
|
+
!e.ctrlKey && !e.shiftKey && !e.metaKey)) {
|
143
|
+
return false;
|
144
|
+
}
|
145
|
+
|
146
|
+
var selection = rangesToRows(_ranges);
|
147
|
+
var idx = $.inArray(cell.row, selection);
|
148
|
+
|
149
|
+
if (idx === -1 && (e.ctrlKey || e.metaKey)) {
|
150
|
+
selection.push(cell.row);
|
151
|
+
_grid.setActiveCell(cell.row, cell.cell);
|
152
|
+
} else if (idx !== -1 && (e.ctrlKey || e.metaKey)) {
|
153
|
+
selection = $.grep(selection, function (o, i) {
|
154
|
+
return (o !== cell.row);
|
155
|
+
});
|
156
|
+
_grid.setActiveCell(cell.row, cell.cell);
|
157
|
+
} else if (selection.length && e.shiftKey) {
|
158
|
+
var last = selection.pop();
|
159
|
+
var from = Math.min(cell.row, last);
|
160
|
+
var to = Math.max(cell.row, last);
|
161
|
+
selection = [];
|
162
|
+
for (var i = from; i <= to; i++) {
|
163
|
+
if (i !== last) {
|
164
|
+
selection.push(i);
|
165
|
+
}
|
166
|
+
}
|
167
|
+
selection.push(last);
|
168
|
+
_grid.setActiveCell(cell.row, cell.cell);
|
169
|
+
}
|
170
|
+
|
171
|
+
var tempRanges = rowsToRanges(selection);
|
172
|
+
setSelectedRanges(tempRanges);
|
173
|
+
e.stopImmediatePropagation();
|
174
|
+
|
175
|
+
return true;
|
176
|
+
}
|
177
|
+
|
178
|
+
$.extend(this, {
|
179
|
+
"getSelectedRows": getSelectedRows,
|
180
|
+
"setSelectedRows": setSelectedRows,
|
181
|
+
|
182
|
+
"getSelectedRanges": getSelectedRanges,
|
183
|
+
"setSelectedRanges": setSelectedRanges,
|
184
|
+
|
185
|
+
"init": init,
|
186
|
+
"destroy": destroy,
|
187
|
+
|
188
|
+
"onSelectedRangesChanged": new Slick.Event()
|
189
|
+
});
|
190
|
+
}
|
191
|
+
})(jQuery);
|
@@ -0,0 +1,169 @@
|
|
1
|
+
(function ($) {
|
2
|
+
/***
|
3
|
+
* A sample AJAX data store implementation.
|
4
|
+
* Right now, it's hooked up to load search results from Octopart, but can
|
5
|
+
* easily be extended to support any JSONP-compatible backend that accepts paging parameters.
|
6
|
+
*/
|
7
|
+
function RemoteModel() {
|
8
|
+
// private
|
9
|
+
var PAGESIZE = 50;
|
10
|
+
var data = {length: 0};
|
11
|
+
var searchstr = "";
|
12
|
+
var sortcol = null;
|
13
|
+
var sortdir = 1;
|
14
|
+
var h_request = null;
|
15
|
+
var req = null; // ajax request
|
16
|
+
|
17
|
+
// events
|
18
|
+
var onDataLoading = new Slick.Event();
|
19
|
+
var onDataLoaded = new Slick.Event();
|
20
|
+
|
21
|
+
|
22
|
+
function init() {
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
function isDataLoaded(from, to) {
|
27
|
+
for (var i = from; i <= to; i++) {
|
28
|
+
if (data[i] == undefined || data[i] == null) {
|
29
|
+
return false;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
return true;
|
34
|
+
}
|
35
|
+
|
36
|
+
|
37
|
+
function clear() {
|
38
|
+
for (var key in data) {
|
39
|
+
delete data[key];
|
40
|
+
}
|
41
|
+
data.length = 0;
|
42
|
+
}
|
43
|
+
|
44
|
+
|
45
|
+
function ensureData(from, to) {
|
46
|
+
if (req) {
|
47
|
+
req.abort();
|
48
|
+
for (var i = req.fromPage; i <= req.toPage; i++)
|
49
|
+
data[i * PAGESIZE] = undefined;
|
50
|
+
}
|
51
|
+
|
52
|
+
if (from < 0) {
|
53
|
+
from = 0;
|
54
|
+
}
|
55
|
+
|
56
|
+
if (data.length > 0) {
|
57
|
+
to = Math.min(to, data.length - 1);
|
58
|
+
}
|
59
|
+
|
60
|
+
var fromPage = Math.floor(from / PAGESIZE);
|
61
|
+
var toPage = Math.floor(to / PAGESIZE);
|
62
|
+
|
63
|
+
while (data[fromPage * PAGESIZE] !== undefined && fromPage < toPage)
|
64
|
+
fromPage++;
|
65
|
+
|
66
|
+
while (data[toPage * PAGESIZE] !== undefined && fromPage < toPage)
|
67
|
+
toPage--;
|
68
|
+
|
69
|
+
if (fromPage > toPage || ((fromPage == toPage) && data[fromPage * PAGESIZE] !== undefined)) {
|
70
|
+
// TODO: look-ahead
|
71
|
+
onDataLoaded.notify({from: from, to: to});
|
72
|
+
return;
|
73
|
+
}
|
74
|
+
|
75
|
+
var url = "http://octopart.com/api/v3/parts/search?apikey=68b25f31&include[]=short_description&show[]=uid&show[]=manufacturer&show[]=mpn&show[]=brand&show[]=octopart_url&show[]=short_description&q=" + searchstr + "&start=" + (fromPage * PAGESIZE) + "&limit=" + (((toPage - fromPage) * PAGESIZE) + PAGESIZE);
|
76
|
+
|
77
|
+
if (sortcol != null) {
|
78
|
+
url += ("&sortby=" + sortcol + ((sortdir > 0) ? "+asc" : "+desc"));
|
79
|
+
}
|
80
|
+
|
81
|
+
if (h_request != null) {
|
82
|
+
clearTimeout(h_request);
|
83
|
+
}
|
84
|
+
|
85
|
+
h_request = setTimeout(function () {
|
86
|
+
for (var i = fromPage; i <= toPage; i++)
|
87
|
+
data[i * PAGESIZE] = null; // null indicates a 'requested but not available yet'
|
88
|
+
|
89
|
+
onDataLoading.notify({from: from, to: to});
|
90
|
+
|
91
|
+
req = $.jsonp({
|
92
|
+
url: url,
|
93
|
+
callbackParameter: "callback",
|
94
|
+
cache: true,
|
95
|
+
success: onSuccess,
|
96
|
+
error: function () {
|
97
|
+
onError(fromPage, toPage)
|
98
|
+
}
|
99
|
+
});
|
100
|
+
req.fromPage = fromPage;
|
101
|
+
req.toPage = toPage;
|
102
|
+
}, 50);
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
function onError(fromPage, toPage) {
|
107
|
+
alert("error loading pages " + fromPage + " to " + toPage);
|
108
|
+
}
|
109
|
+
|
110
|
+
function onSuccess(resp) {
|
111
|
+
var from = resp.request.start, to = from + resp.results.length;
|
112
|
+
data.length = Math.min(parseInt(resp.hits),1000); // limitation of the API
|
113
|
+
|
114
|
+
for (var i = 0; i < resp.results.length; i++) {
|
115
|
+
var item = resp.results[i].item;
|
116
|
+
|
117
|
+
data[from + i] = item;
|
118
|
+
data[from + i].index = from + i;
|
119
|
+
}
|
120
|
+
|
121
|
+
req = null;
|
122
|
+
|
123
|
+
onDataLoaded.notify({from: from, to: to});
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
function reloadData(from, to) {
|
128
|
+
for (var i = from; i <= to; i++)
|
129
|
+
delete data[i];
|
130
|
+
|
131
|
+
ensureData(from, to);
|
132
|
+
}
|
133
|
+
|
134
|
+
|
135
|
+
function setSort(column, dir) {
|
136
|
+
sortcol = column;
|
137
|
+
sortdir = dir;
|
138
|
+
clear();
|
139
|
+
}
|
140
|
+
|
141
|
+
function setSearch(str) {
|
142
|
+
searchstr = str;
|
143
|
+
clear();
|
144
|
+
}
|
145
|
+
|
146
|
+
|
147
|
+
init();
|
148
|
+
|
149
|
+
return {
|
150
|
+
// properties
|
151
|
+
"data": data,
|
152
|
+
|
153
|
+
// methods
|
154
|
+
"clear": clear,
|
155
|
+
"isDataLoaded": isDataLoaded,
|
156
|
+
"ensureData": ensureData,
|
157
|
+
"reloadData": reloadData,
|
158
|
+
"setSort": setSort,
|
159
|
+
"setSearch": setSearch,
|
160
|
+
|
161
|
+
// events
|
162
|
+
"onDataLoading": onDataLoading,
|
163
|
+
"onDataLoaded": onDataLoaded
|
164
|
+
};
|
165
|
+
}
|
166
|
+
|
167
|
+
// Slick.Data.RemoteModel
|
168
|
+
$.extend(true, window, { Slick: { Data: { RemoteModel: RemoteModel }}});
|
169
|
+
})(jQuery);
|