caboose-cms 0.4.115 → 0.4.116
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/app/assets/javascripts/caboose/model/index_table.js +530 -0
- data/app/assets/javascripts/caboose/model/pager.js +99 -0
- data/app/controllers/caboose/application_controller.rb +9 -0
- data/app/models/caboose/page_bar_generator.rb +20 -9
- data/lib/caboose/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDViMmY2NGZhYTI0OWZiNTMzYzY3OTQ1NjBlY2M1MDlmYTc5YTE5MA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODM5NTBhOGE5ODRiOTlkMDlmOTEzOTM0MzdjZDI2YWJkMTA3NTMwZg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGYxMGM1YWEzYmYwMTExOGM3ODJlN2M0ZjAxMDk2NGY1NDRlMzQ3OWExMjFh
|
10
|
+
MmJmYmJmOGJjOTI4YzBlYjFlNjA2N2IyOTlmNTIxYWM3MTM5YzllNThlOTNi
|
11
|
+
MTJlOGE1Mjk0ZTgyNjZkNzE0ODg2YTcwYjFlOWU5ODIyYzU3ZDk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjlkOWNkMzhkN2U4NjI5M2E3ZmQ5ZGU0OTE5ZWM2NDg3ZTUyNmRhNGJlYTgx
|
14
|
+
YjczMmIxOGRiZTY2M2VhZDNjYmFmNzU0YWQ3ZGJiNWE3M2VjNmUwNTg4MWEy
|
15
|
+
NWRiZjJjNjdkMmY1OThkZTQ2NDZjY2NmMzI5ZmM2MGMzOTkwODE=
|
@@ -0,0 +1,530 @@
|
|
1
|
+
|
2
|
+
var IndexTable = function(params) { this.init(params); }
|
3
|
+
IndexTable.prototype = {
|
4
|
+
|
5
|
+
//============================================================================
|
6
|
+
// Required parameters
|
7
|
+
//============================================================================
|
8
|
+
|
9
|
+
form_authenticity_token: false,
|
10
|
+
|
11
|
+
// Container for the table
|
12
|
+
container: 'models',
|
13
|
+
|
14
|
+
// Base URL used for default refresh/update/delete/bulk URLs
|
15
|
+
base_url: false,
|
16
|
+
|
17
|
+
// Where to get model json data
|
18
|
+
refresh_url: false,
|
19
|
+
|
20
|
+
// Where to send bulk updates
|
21
|
+
bulk_update_url: false,
|
22
|
+
|
23
|
+
// Where to send bulk deletes
|
24
|
+
bulk_delete_url: false,
|
25
|
+
|
26
|
+
// Where to send normal updates
|
27
|
+
// Example: function(model_id) { return '/admin/models/' + model_id; }
|
28
|
+
update_url: false,
|
29
|
+
|
30
|
+
// Where to send duplicate calls
|
31
|
+
// Example: function(model_id) { return '/admin/models/' + model_id + '/duplicate' },
|
32
|
+
duplicate_url: false,
|
33
|
+
|
34
|
+
// What to do when a row is clicked
|
35
|
+
// Example: function (model_id) { return '/admin/models/' + model_id; }
|
36
|
+
row_click_handler: false,
|
37
|
+
|
38
|
+
// Array of fields you want to show in the table (given as model binder attributes with additional text and value functions)
|
39
|
+
// [{
|
40
|
+
// show: true,
|
41
|
+
// bulk_edit: true,
|
42
|
+
// name: 'title',
|
43
|
+
// nice_name: 'Title',
|
44
|
+
// type: 'text',
|
45
|
+
// text: function(obj) { return obj.title; },
|
46
|
+
// value: function(obj) { return obj.id; },
|
47
|
+
// options_url: '/admin/dogs/collar-options'
|
48
|
+
// fixed_placeholder: false,
|
49
|
+
// width: 200,
|
50
|
+
// }]
|
51
|
+
fields: [],
|
52
|
+
|
53
|
+
// The post/get in the original request
|
54
|
+
post_get: false,
|
55
|
+
|
56
|
+
//============================================================================
|
57
|
+
// End of required parameters
|
58
|
+
//============================================================================
|
59
|
+
|
60
|
+
models: [],
|
61
|
+
model_ids: [],
|
62
|
+
quick_edit_field: false, // The field currently being edited
|
63
|
+
refresh_count: 0,
|
64
|
+
|
65
|
+
// Pager fields
|
66
|
+
pager_params: {
|
67
|
+
//sort: '',
|
68
|
+
//desc: false,
|
69
|
+
//item_count: 0,
|
70
|
+
//items_per_page: 4,
|
71
|
+
//page: 1
|
72
|
+
},
|
73
|
+
|
74
|
+
init: function(params) {
|
75
|
+
for (var thing in params)
|
76
|
+
this[thing] = params[thing];
|
77
|
+
|
78
|
+
var that = this;
|
79
|
+
if (!this.refresh_url ) this.refresh_url = this.base_url + '/json';
|
80
|
+
if (!this.bulk_update_url ) this.bulk_update_url = this.base_url + '/bulk';
|
81
|
+
if (!this.bulk_delete_url ) this.bulk_delete_url = this.base_url + '/bulk';
|
82
|
+
if (!this.update_url ) this.update_url = function(model_id) { return this.base_url + '/' + model_id; };
|
83
|
+
if (!this.duplicate_url ) this.duplicate_url = function(model_id) { return this.base_url + '/' + model_id + '/duplicate'; };
|
84
|
+
if (!this.row_click_handler ) this.row_click_handler = function(model_id) { window.location = this.base_url + '/' + model_id; };
|
85
|
+
|
86
|
+
$(window).on('hashchange', function() { that.refresh(); });
|
87
|
+
this.refresh();
|
88
|
+
},
|
89
|
+
|
90
|
+
parse_querystring: function()
|
91
|
+
{
|
92
|
+
var b = {};
|
93
|
+
|
94
|
+
// Get the hash values
|
95
|
+
var a = window.location.hash;
|
96
|
+
if (a.length > 0)
|
97
|
+
{
|
98
|
+
a = a.substr(1).split('&');
|
99
|
+
for (var i=0; i<a.length; ++i)
|
100
|
+
{
|
101
|
+
var p = a[i].split('=', 2);
|
102
|
+
if (p.length == 1) b[p[0]] = "";
|
103
|
+
else b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
// Get the querystring values
|
108
|
+
a = window.location.search;
|
109
|
+
if (a.length > 0)
|
110
|
+
{
|
111
|
+
a = a.substr(1).split('&');
|
112
|
+
for (var i=0; i<a.length; ++i)
|
113
|
+
{
|
114
|
+
var p = a[i].split('=', 2);
|
115
|
+
if (p.length == 1) b[p[0]] = "";
|
116
|
+
else b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
// Set both hash and querystring values in the pager
|
121
|
+
for (var i in b)
|
122
|
+
this.pager_params[i] = b[i];
|
123
|
+
|
124
|
+
// If there's a querystring, then redirect to hash
|
125
|
+
//if (window.location.search.length > 0)
|
126
|
+
//{
|
127
|
+
// //alert('Testing');
|
128
|
+
// //window.location = this.pager_url({ base_url: window.location.pathname }).replace('?', '#');
|
129
|
+
//}
|
130
|
+
},
|
131
|
+
|
132
|
+
refresh: function()
|
133
|
+
{
|
134
|
+
this.parse_querystring();
|
135
|
+
|
136
|
+
var that = this;
|
137
|
+
var $el = $('#columns').length > 0 ? $('#table_container') : $('#'+this.container);
|
138
|
+
$el.html("<p class='loading'>Refreshing...</p>");
|
139
|
+
$.ajax({
|
140
|
+
url: that.refresh_url,
|
141
|
+
type: 'get',
|
142
|
+
data: that.pager_params,
|
143
|
+
success: function(resp) {
|
144
|
+
for (var thing in resp['pager'])
|
145
|
+
that.pager_params[thing] = resp['pager'][thing];
|
146
|
+
that.models = resp['models'];
|
147
|
+
$.each(that.models, function(i, m) {
|
148
|
+
m.id = parseInt(m.id);
|
149
|
+
});
|
150
|
+
that.print();
|
151
|
+
|
152
|
+
// Set the history state
|
153
|
+
//var qs = that.pager_querystring();
|
154
|
+
//if (that.refresh_count > 0 && qs != window.location.hash)
|
155
|
+
//{
|
156
|
+
// if(history.pushState) history.pushState(null, null, '#' + qs);
|
157
|
+
// else location.hash = '#' + qs;
|
158
|
+
//}
|
159
|
+
that.refresh_count += 1;
|
160
|
+
},
|
161
|
+
error: function() { $('#' + this.container).html("<p class='note error'>Error retrieving data.</p>"); }
|
162
|
+
});
|
163
|
+
},
|
164
|
+
|
165
|
+
print: function()
|
166
|
+
{
|
167
|
+
var that = this;
|
168
|
+
|
169
|
+
var tbody = $('<tbody/>').append(this.table_headers());
|
170
|
+
$.each(that.models, function(i, m) {
|
171
|
+
tbody.append(that.table_row(m));
|
172
|
+
});
|
173
|
+
var table = $('<table/>').addClass('data').css('margin-bottom', '10px').append(tbody);
|
174
|
+
var pager = this.pager();
|
175
|
+
|
176
|
+
if ($('#columns').length > 0)
|
177
|
+
{
|
178
|
+
$('#table_container').empty().append(table);
|
179
|
+
$('#pager').empty().append(pager);
|
180
|
+
}
|
181
|
+
else
|
182
|
+
{
|
183
|
+
var columns = this.column_checkboxes();
|
184
|
+
|
185
|
+
$('#' + that.container).empty()
|
186
|
+
.append($('<a/>').attr('href', '#').html('Show/Hide Columns').click(function(e) { e.preventDefault(); $('#columns').slideToggle(); }))
|
187
|
+
.append($('<div/>').attr('id', 'columns').append(columns))
|
188
|
+
.append($('<div/>').attr('id', 'table_container').append(table))
|
189
|
+
.append($('<div/>').attr('id', 'pager').append(pager))
|
190
|
+
.append($('<div/>').attr('id', 'message'))
|
191
|
+
.append($('<p/>')
|
192
|
+
.append($('<input/>').attr('type', 'button').attr('id', 'bulk_edit' ).val('Bulk Edit' ).click(function(e) { that.bulk_edit(); })).append(' ')
|
193
|
+
.append($('<input/>').attr('type', 'button').attr('id', 'bulk_delete').val('Bulk Delete').click(function(e) { that.bulk_delete(); })).append(' ')
|
194
|
+
.append($('<input/>').attr('type', 'button').attr('id', 'duplicate' ).val('Duplicate' ).click(function(e) { that.duplicate(); }))
|
195
|
+
);
|
196
|
+
$('#columns').hide();
|
197
|
+
}
|
198
|
+
|
199
|
+
if (that.quick_edit_field)
|
200
|
+
{
|
201
|
+
$.each(that.models, function(i, m) {
|
202
|
+
$.each(that.fields, function(j, field) {
|
203
|
+
if (field.show && field.name == that.quick_edit_field)
|
204
|
+
{
|
205
|
+
var attrib = $.extend({}, field);
|
206
|
+
attrib['value'] = field.value(m);
|
207
|
+
attrib['fixed_placeholder'] = false;
|
208
|
+
//if (field.text)
|
209
|
+
// attrib['text'] = field.text(m);
|
210
|
+
new ModelBinder({
|
211
|
+
name: 'Model',
|
212
|
+
id: m.id,
|
213
|
+
update_url: that.update_url(m.id),
|
214
|
+
authenticity_token: that.form_authenticity_token,
|
215
|
+
attributes: [attrib]
|
216
|
+
});
|
217
|
+
}
|
218
|
+
});
|
219
|
+
});
|
220
|
+
}
|
221
|
+
},
|
222
|
+
|
223
|
+
table_headers: function()
|
224
|
+
{
|
225
|
+
var that = this;
|
226
|
+
var tr = $('<tr/>').append($('<th/>').html(' '));
|
227
|
+
//var url = this.base_url + this.base_url.indexOf('?') > -1 ? '&' : '?';
|
228
|
+
|
229
|
+
$.each(this.fields, function(i, field) {
|
230
|
+
if (field.show)
|
231
|
+
{
|
232
|
+
var arrow = that.pager_params.sort == field.sort ? (parseInt(that.pager_params.desc) == 1 ? ' ↑' : ' ↓') : '';
|
233
|
+
//var link = url + "sort=" + field.sort + "&desc=" + (that.pager_params.sort == field.sort ? (parseInt(that.pager_params.desc) == 1 ? '0' : '1') : '0');
|
234
|
+
//var link = that.pager_url({
|
235
|
+
var link = that.pager_hash({
|
236
|
+
sort: field.sort,
|
237
|
+
desc: (that.pager_params.sort == field.sort ? (parseInt(that.pager_params.desc) == 1 ? '0' : '1') : '0')
|
238
|
+
});
|
239
|
+
|
240
|
+
var input = $('<input/>').attr('type', 'checkbox').attr('id', 'quick_edit_' + field.name).val(field.name)
|
241
|
+
.change(function() {
|
242
|
+
that.quick_edit_field = $(this).prop('checked') ? $(this).val() : false;
|
243
|
+
that.refresh();
|
244
|
+
});
|
245
|
+
if (field.name == that.quick_edit_field)
|
246
|
+
input.prop('checked', 'true');
|
247
|
+
tr.append($('<th/>').append(input).append('<br/>')
|
248
|
+
.append($('<a/>')
|
249
|
+
.attr('href', link)
|
250
|
+
.data('sort', field.sort)
|
251
|
+
.html(field.nice_name + arrow)
|
252
|
+
)
|
253
|
+
);
|
254
|
+
}
|
255
|
+
});
|
256
|
+
return tr;
|
257
|
+
},
|
258
|
+
|
259
|
+
table_row: function(m)
|
260
|
+
{
|
261
|
+
var that = this;
|
262
|
+
var checkbox = $('<input/>').attr('type', 'checkbox').attr('id', 'model_' + m.id)
|
263
|
+
.click(function(e) {
|
264
|
+
e.stopPropagation();
|
265
|
+
var model_id = $(this).attr('id').replace('model_', '');
|
266
|
+
if (model_id == 'NaN')
|
267
|
+
alert("Error: invalid model id.");
|
268
|
+
else
|
269
|
+
{
|
270
|
+
model_id = parseInt(model_id);
|
271
|
+
var checked = $(this).prop('checked');
|
272
|
+
var i = that.model_ids.indexOf(model_id);
|
273
|
+
if (checked && i == -1) that.model_ids.push(model_id);
|
274
|
+
if (!checked && i > -1) that.model_ids.splice(i, 1);
|
275
|
+
}
|
276
|
+
});
|
277
|
+
if (that.model_ids.indexOf(m.id) > -1)
|
278
|
+
checkbox.prop('checked', 'true');
|
279
|
+
|
280
|
+
var tr = $('<tr/>')
|
281
|
+
.attr('id', 'model_row_' + m.id)
|
282
|
+
.append($('<td/>').append(checkbox));
|
283
|
+
if (!that.quick_edit_field)
|
284
|
+
{
|
285
|
+
tr.click(function(e) {
|
286
|
+
var model_id = $(this).attr('id').replace('model_row_', '');
|
287
|
+
that.row_click_handler(model_id);
|
288
|
+
});
|
289
|
+
}
|
290
|
+
|
291
|
+
$.each(that.fields, function(j, field) {
|
292
|
+
if (field.show)
|
293
|
+
{
|
294
|
+
var td = $('<td/>');
|
295
|
+
if (that.quick_edit_field == field.name)
|
296
|
+
td.append($('<div/>').attr('id', 'model_' + m.id + '_' + field.name));
|
297
|
+
else
|
298
|
+
td.html(field.text ? field.text(m) : field.value(m));
|
299
|
+
tr.append(td);
|
300
|
+
}
|
301
|
+
});
|
302
|
+
return tr;
|
303
|
+
},
|
304
|
+
|
305
|
+
column_checkboxes: function()
|
306
|
+
{
|
307
|
+
var that = this;
|
308
|
+
var div = $('<div/>').attr('id', 'columns');
|
309
|
+
$.each(this.fields, function(i, field) {
|
310
|
+
var input = $('<input/>')
|
311
|
+
.attr('type', 'checkbox')
|
312
|
+
.attr('id', 'field_' + field.name)
|
313
|
+
.click(function(e) {
|
314
|
+
var field_name = $(this).attr('id').replace('field_', '');
|
315
|
+
var checked = $(this).prop('checked');
|
316
|
+
$.each(that.fields, function(j, f) {
|
317
|
+
if (f.name == field_name)
|
318
|
+
{
|
319
|
+
f.show = checked;
|
320
|
+
that.print();
|
321
|
+
}
|
322
|
+
});
|
323
|
+
});
|
324
|
+
if (field.show)
|
325
|
+
input.prop('checked', 'true');
|
326
|
+
|
327
|
+
div.append($('<div/>').addClass('label_with_checkbox')
|
328
|
+
.append(input)
|
329
|
+
.append($('<label/>').attr('for', 'field_' + field.name).html(field.nice_name))
|
330
|
+
);
|
331
|
+
});
|
332
|
+
return div;
|
333
|
+
},
|
334
|
+
|
335
|
+
bulk_edit: function()
|
336
|
+
{
|
337
|
+
var that = this;
|
338
|
+
if (this.model_ids.length == 0)
|
339
|
+
{
|
340
|
+
$('#message').html("<p class='note error'>Please select at least one row.</p>");
|
341
|
+
return;
|
342
|
+
}
|
343
|
+
var div = $('<div/>')
|
344
|
+
.append($('<h2/>').html('Bulk Edit Jobs'))
|
345
|
+
.append($('<p/>').html('Any change you make the fields below will apply to all the selected rows.'));
|
346
|
+
$.each(this.fields, function(i, field) {
|
347
|
+
if (field.bulk_edit == true)
|
348
|
+
div.append($('<p/>').append($('<div/>').attr('id', 'bulkmodel_1_' + field.name)));
|
349
|
+
});
|
350
|
+
div.append($('<input/>').attr('type','button').val('Finished').click(function() { $('#message').empty(); }));
|
351
|
+
$('#message').empty().append(div);
|
352
|
+
|
353
|
+
var params = this.model_ids.map(function(model_id) { return 'model_ids[]=' + model_id; }).join('&');
|
354
|
+
var attribs = [];
|
355
|
+
$.each(this.fields, function(i, field) {
|
356
|
+
if (field.bulk_edit == true)
|
357
|
+
{
|
358
|
+
var attrib = $.extend({}, field);
|
359
|
+
attrib['value'] = '';
|
360
|
+
attrib['after_update'] = function() { that.refresh(); };
|
361
|
+
attrib['width'] = 600;
|
362
|
+
attribs.push(attrib);
|
363
|
+
}
|
364
|
+
});
|
365
|
+
|
366
|
+
m = new ModelBinder({
|
367
|
+
name: 'BulkModel',
|
368
|
+
id: 1,
|
369
|
+
update_url: that.bulk_update_url + '?' + params,
|
370
|
+
authenticity_token: this.form_authenticity_token,
|
371
|
+
attributes: attribs
|
372
|
+
});
|
373
|
+
},
|
374
|
+
|
375
|
+
bulk_delete: function(confirm)
|
376
|
+
{
|
377
|
+
var that = this;
|
378
|
+
if (this.model_ids.length == 0)
|
379
|
+
{
|
380
|
+
$('#message').html("<p class='note error'>Please select at least one row.</p>");
|
381
|
+
return;
|
382
|
+
}
|
383
|
+
if (!confirm)
|
384
|
+
{
|
385
|
+
var p = $('<p/>').addClass('note').addClass('warning')
|
386
|
+
.append('Are you sure you want to delete the selected rows? ')
|
387
|
+
.append($('<input/>').attr('type','button').val('Yes').click(function() { that.bulk_delete(true); }))
|
388
|
+
.append($('<input/>').attr('type','button').val('No').click(function() { $('#message').empty(); }));
|
389
|
+
$('#message').empty().append(p);
|
390
|
+
return;
|
391
|
+
}
|
392
|
+
var params = this.model_ids.map(function(model_id) { return 'model_ids[]=' + model_id; }).join('&');
|
393
|
+
$('#' + this.container).html("<p class='loading'>Refreshing...</p>");
|
394
|
+
$.ajax({
|
395
|
+
url: that.bulk_delete_url,
|
396
|
+
type: 'delete',
|
397
|
+
data: {
|
398
|
+
model_ids: that.model_ids
|
399
|
+
},
|
400
|
+
success: function(resp) {
|
401
|
+
$('#message').empty();
|
402
|
+
that.refresh();
|
403
|
+
}
|
404
|
+
});
|
405
|
+
},
|
406
|
+
|
407
|
+
model_for_id: function(model_id)
|
408
|
+
{
|
409
|
+
for (var i=0; i<this.models.length; i++)
|
410
|
+
if (this.models[i].id == model_id)
|
411
|
+
return this.models[i];
|
412
|
+
return false;
|
413
|
+
},
|
414
|
+
|
415
|
+
duplicate: function(count)
|
416
|
+
{
|
417
|
+
var that = this;
|
418
|
+
if (this.model_ids.length == 0)
|
419
|
+
{
|
420
|
+
var p = $('<p/>').addClass('note error').html("Please select a row.");
|
421
|
+
$('#message').empty().append(p);
|
422
|
+
return;
|
423
|
+
}
|
424
|
+
if (this.model_ids.length > 1)
|
425
|
+
{
|
426
|
+
var p = $('<p/>').addClass('note error').html("Please select a single row.");
|
427
|
+
$('#message').empty().append(p);
|
428
|
+
return;
|
429
|
+
}
|
430
|
+
if (!count)
|
431
|
+
{
|
432
|
+
var p = $('<p/>').addClass('note')
|
433
|
+
.append('How many times do you want this duplicated?')
|
434
|
+
.append($('<input/>').attr('type', 'text').attr('id', 'count').css('width', '50'))
|
435
|
+
.append('<br />')
|
436
|
+
.append($('<input/>').attr('type', 'button').val('Cancel').click(function(e) { $('#message').empty(); })).append(' ')
|
437
|
+
.append($('<input/>').attr('type', 'button').val('Duplicate').click(function(e) { that.duplicate($('#count').val()); return false; }));
|
438
|
+
$('#message').empty().append(p);
|
439
|
+
return;
|
440
|
+
}
|
441
|
+
$('#message').html("<p class='loading'>Duplicating...</p>");
|
442
|
+
$.ajax({
|
443
|
+
url: that.duplicate_url(that.model_ids[0]),
|
444
|
+
type: 'post',
|
445
|
+
data: { count: count },
|
446
|
+
success: function(resp) {
|
447
|
+
if (resp.error) $('#message').html("<p class='note error'>" + resp.error + "</p>");
|
448
|
+
if (resp.success) { $('#message').empty(); that.refresh(); }
|
449
|
+
}
|
450
|
+
});
|
451
|
+
},
|
452
|
+
|
453
|
+
pager: function(summary)
|
454
|
+
{
|
455
|
+
var that = this;
|
456
|
+
var pp = this.pager_params;
|
457
|
+
|
458
|
+
// Set default parameter values if not present
|
459
|
+
if (!pp.items_per_page) pp.items_per_page = 10
|
460
|
+
if (!pp.page) pp.page = 1
|
461
|
+
|
462
|
+
var page = parseInt(pp.page);
|
463
|
+
|
464
|
+
// Max links to show (must be odd)
|
465
|
+
var total_links = 5;
|
466
|
+
var prev_page = page - 1;
|
467
|
+
var next_page = page + 1;
|
468
|
+
var total_pages = Math.ceil(parseFloat(pp.item_count)/parseFloat(pp.items_per_page));
|
469
|
+
var start = 1;
|
470
|
+
var stop = 1;
|
471
|
+
|
472
|
+
if (total_pages < total_links)
|
473
|
+
{
|
474
|
+
start = 1;
|
475
|
+
stop = total_pages;
|
476
|
+
}
|
477
|
+
else
|
478
|
+
{
|
479
|
+
start = page - Math.floor(total_links/2);
|
480
|
+
if (start < 1) start = 1;
|
481
|
+
stop = start + total_links - 1
|
482
|
+
|
483
|
+
if (stop > total_pages)
|
484
|
+
{
|
485
|
+
stop = total_pages;
|
486
|
+
start = stop - total_links;
|
487
|
+
if (start < 1) start = 1;
|
488
|
+
}
|
489
|
+
}
|
490
|
+
|
491
|
+
var div = $('<div/>').addClass('pager');
|
492
|
+
if (summary)
|
493
|
+
div.append($('<p/>').html("Results: showing page " + page + " of " + total_pages));
|
494
|
+
|
495
|
+
if (total_pages > 1)
|
496
|
+
{
|
497
|
+
var div2 = $('<div/>').addClass('page_links');
|
498
|
+
if (page > 1)
|
499
|
+
div2.append($('<a/>').attr('href', this.pager_hash({ page: prev_page })).html('Previous'));
|
500
|
+
for (i=start; i<=stop; i++)
|
501
|
+
{
|
502
|
+
if (page != i)
|
503
|
+
div2.append($('<a/>').attr('href', this.pager_hash({ page: i })).html(i));
|
504
|
+
else
|
505
|
+
div2.append($('<span/>').addClass('current_page').html(i));
|
506
|
+
}
|
507
|
+
if (page < total_pages)
|
508
|
+
div2.append($('<a/>').attr('href', this.pager_hash({ page: next_page })).html('Next'));
|
509
|
+
div.append(div2);
|
510
|
+
}
|
511
|
+
return div;
|
512
|
+
},
|
513
|
+
|
514
|
+
pager_hash: function(h)
|
515
|
+
{
|
516
|
+
var that = this;
|
517
|
+
var pp = $.extend({}, this.pager_params);
|
518
|
+
for (var i in h)
|
519
|
+
pp[i] = h[i];
|
520
|
+
|
521
|
+
var qs = [];
|
522
|
+
$.each(pp, function(k,v) {
|
523
|
+
if (k == 'base_url' || k == 'item_count' || k == 'items_per_page' || k == 'use_url_params')
|
524
|
+
return;
|
525
|
+
qs.push('' + k + '=' + encodeURIComponent(v));
|
526
|
+
});
|
527
|
+
return '#' + qs.join('&');
|
528
|
+
}
|
529
|
+
|
530
|
+
};
|
@@ -0,0 +1,99 @@
|
|
1
|
+
|
2
|
+
var Pager = function(params) { this.init(params); }
|
3
|
+
Pager.prototype = {
|
4
|
+
|
5
|
+
base_url: '',
|
6
|
+
sort: '',
|
7
|
+
desc: false,
|
8
|
+
item_count: 0,
|
9
|
+
items_per_page: 10,
|
10
|
+
page: 1,
|
11
|
+
use_url_params: false,
|
12
|
+
|
13
|
+
init: function(params)
|
14
|
+
{
|
15
|
+
for (var thing in params)
|
16
|
+
this[thing] = params[thing];
|
17
|
+
}
|
18
|
+
|
19
|
+
// Paramters:
|
20
|
+
// cols: Hash { key = sort field, value = text to display }
|
21
|
+
sortable_table_headings: function(cols)
|
22
|
+
{
|
23
|
+
var that = this;
|
24
|
+
this.base_url += this.base_url.indexOf('?') > -1 ? '&' : '?';
|
25
|
+
var str = '';
|
26
|
+
|
27
|
+
var tr = $('<tr/>');
|
28
|
+
$.each(cols, function(sort, text) {
|
29
|
+
var arrow = that.sort == sort ? (that.desc == 1 ? ' ↑' : ' ↓') : '';
|
30
|
+
var link = that.base_url + 'sort=' + sort + '&desc=' + (that.desc == 1 ? '0' : '1');
|
31
|
+
tr.append($('<th/>').append(
|
32
|
+
str += "<th><a href='#{link}'>#{text}#{arrow}</a></th>\n"
|
33
|
+
end
|
34
|
+
return str
|
35
|
+
end
|
36
|
+
|
37
|
+
def generate(summary = true)
|
38
|
+
|
39
|
+
# Check for necessary parameter values
|
40
|
+
return false if !ok(@options['base_url']) # Error: base_url is required for the page bar generator to work.
|
41
|
+
return false if !ok(@options['item_count']) # Error: itemCount is required for the page bar generator to work.
|
42
|
+
|
43
|
+
# Set default parameter values if not present
|
44
|
+
@options['items_per_page'] = 10 if @options["items_per_page"].nil?
|
45
|
+
@options['page'] = 1 if @options["page"].nil?
|
46
|
+
|
47
|
+
page = @options["page"].to_i
|
48
|
+
|
49
|
+
# Max links to show (must be odd)
|
50
|
+
total_links = 5
|
51
|
+
prev_page = page - 1
|
52
|
+
next_page = page + 1
|
53
|
+
total_pages = (@options['item_count'].to_f / @options['items_per_page'].to_f).ceil
|
54
|
+
|
55
|
+
if (total_pages < total_links)
|
56
|
+
start = 1
|
57
|
+
stop = total_pages
|
58
|
+
else
|
59
|
+
start = page - (total_links/2).floor
|
60
|
+
start = 1 if start < 1
|
61
|
+
stop = start + total_links - 1
|
62
|
+
|
63
|
+
if (stop > total_pages)
|
64
|
+
stop = total_pages
|
65
|
+
start = stop - total_links
|
66
|
+
start = 1 if start < 1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
base_url = url_with_vars
|
71
|
+
base_url << (@use_url_params ? "/" : (base_url.include?("?") ? "&" : "?"))
|
72
|
+
keyval_delim = @use_url_params ? "/" : "="
|
73
|
+
var_delim = @use_url_params ? "/" : "&"
|
74
|
+
|
75
|
+
str = ''
|
76
|
+
str << "<p>Results: showing page #{page} of #{total_pages}</p>\n" if summary
|
77
|
+
|
78
|
+
if (total_pages > 1)
|
79
|
+
str << "<div class='page_links'>\n"
|
80
|
+
if (page > 1)
|
81
|
+
str << "<a href='#{base_url}page#{keyval_delim}#{prev_page}'>Previous</a>"
|
82
|
+
end
|
83
|
+
for i in start..stop
|
84
|
+
if (page != i)
|
85
|
+
str << "<a href='#{base_url}page#{keyval_delim}#{i}'>#{i}</a>"
|
86
|
+
else
|
87
|
+
str << "<span class='current_page'>#{i}</span>"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
if (page < total_pages)
|
91
|
+
str << "<a href='#{base_url}page#{keyval_delim}#{next_page}'>Next</a>"
|
92
|
+
end
|
93
|
+
str << "</div>\n"
|
94
|
+
end
|
95
|
+
|
96
|
+
return str
|
97
|
+
end
|
98
|
+
|
99
|
+
};
|
@@ -202,6 +202,15 @@ module Caboose
|
|
202
202
|
return "" if s.nil?
|
203
203
|
return s.value
|
204
204
|
end
|
205
|
+
|
206
|
+
# RedirectsConverts querystrings into hashes
|
207
|
+
def hashify_query_string
|
208
|
+
if request.query_string && request.query_string.length > 0
|
209
|
+
redirect_to request.url.gsub('?', '#')
|
210
|
+
return true
|
211
|
+
end
|
212
|
+
return false
|
213
|
+
end
|
205
214
|
|
206
215
|
end
|
207
216
|
end
|
@@ -69,13 +69,12 @@ module Caboose
|
|
69
69
|
long_key = @options['abbreviations'][key]
|
70
70
|
new_params[long_key] = post_get[key] ? post_get[key] : val
|
71
71
|
keys_to_delete << key
|
72
|
-
}
|
72
|
+
}
|
73
73
|
keys_to_delete.each { |k| @params.delete(k) }
|
74
|
-
new_params.each { |k,v| @params[k] = v }
|
75
|
-
@original_params.each { |k,v| @original_params[k] = post_get[k] ? post_get[k] : v }
|
76
|
-
@params.each { |k,v| @params[k] = post_get[k] ? post_get[k] : v }
|
77
|
-
@options.each { |k,v| @options[k] = post_get[k] ? post_get[k] : v }
|
78
|
-
|
74
|
+
new_params.each { |k,v| @params[k] = v }
|
75
|
+
@original_params.each { |k,v| @original_params[k] = post_get[k] ? post_get[k] : v }
|
76
|
+
@params.each { |k,v| @params[k] = post_get[k] ? post_get[k] : v }
|
77
|
+
@options.each { |k,v| @options[k] = ok(post_get[k]) ? post_get[k] : v }
|
79
78
|
#@custom_url_vars = custom_url_vars if !custom_url_vars.nil?
|
80
79
|
@use_url_params = @options['use_url_params'].nil? ? Caboose.use_url_params : @options['use_url_params']
|
81
80
|
|
@@ -148,10 +147,10 @@ module Caboose
|
|
148
147
|
return true
|
149
148
|
end
|
150
149
|
|
151
|
-
def items
|
150
|
+
def items
|
152
151
|
assoc = model_with_includes.where(self.where)
|
153
152
|
n = self.near
|
154
|
-
assoc = assoc.near(n[0], n[1]) if n
|
153
|
+
assoc = assoc.near(n[0], n[1]) if n
|
155
154
|
if @options['items_per_page'] != -1
|
156
155
|
assoc = assoc.limit(self.limit).offset(self.offset)
|
157
156
|
end
|
@@ -438,6 +437,18 @@ module Caboose
|
|
438
437
|
end
|
439
438
|
str << " desc" if @options['desc'] == 1
|
440
439
|
return str
|
441
|
-
end
|
440
|
+
end
|
441
|
+
|
442
|
+
def to_json
|
443
|
+
{
|
444
|
+
:base_url => @options['base_url'],
|
445
|
+
:sort => @options['sort'],
|
446
|
+
:desc => @options['desc'],
|
447
|
+
:item_count => @options['item_count'],
|
448
|
+
:items_per_page => @options['items_per_page'],
|
449
|
+
:page => @options['page'],
|
450
|
+
:use_url_params => @use_url_params
|
451
|
+
}
|
452
|
+
end
|
442
453
|
end
|
443
454
|
end
|
data/lib/caboose/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caboose-cms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.116
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Barry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -223,8 +223,10 @@ files:
|
|
223
223
|
- app/assets/javascripts/caboose/model/bound_textarea.js
|
224
224
|
- app/assets/javascripts/caboose/model/bound_time.js
|
225
225
|
- app/assets/javascripts/caboose/model/class.js
|
226
|
+
- app/assets/javascripts/caboose/model/index_table.js
|
226
227
|
- app/assets/javascripts/caboose/model/model.js
|
227
228
|
- app/assets/javascripts/caboose/model/model_binder.js
|
229
|
+
- app/assets/javascripts/caboose/model/pager.js
|
228
230
|
- app/assets/javascripts/caboose/model/s3.js
|
229
231
|
- app/assets/javascripts/caboose/model.form.page.js
|
230
232
|
- app/assets/javascripts/caboose/model.form.user.js
|