jtable-rails 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
data/jtable-rails.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jtable-rails}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Taylor Yelverton"]
@@ -30,10 +30,14 @@ Gem::Specification.new do |s|
30
30
  "lib/jtable-rails.rb",
31
31
  "lib/jtable-rails/action_controller.rb",
32
32
  "lib/jtable-rails/active_record.rb",
33
+ "lib/jtable-rails/railtie.rb",
34
+ "lib/jtable-rails/version.rb",
35
+ "lib/tasks/jtable_rails.rake",
33
36
  "spec/controller_specs/people_controller_spec.rb",
34
37
  "spec/fabricators/person.rb",
35
38
  "spec/model_specs/person_spec.rb",
36
39
  "spec/spec_helper.rb",
40
+ "spec/support/rails_app/.DS_Store",
37
41
  "spec/support/rails_app/.gitignore",
38
42
  "spec/support/rails_app/Gemfile",
39
43
  "spec/support/rails_app/Gemfile.lock",
@@ -67,8 +71,14 @@ Gem::Specification.new do |s|
67
71
  "spec/support/rails_app/db/migrate/20110207142623_create_people.rb",
68
72
  "spec/support/rails_app/db/schema.rb",
69
73
  "spec/support/rails_app/db/seeds.rb",
74
+ "spec/support/rails_app/public/images/jTable-icons.png",
75
+ "spec/support/rails_app/public/images/jTable-processing_bg.png",
76
+ "spec/support/rails_app/public/javascripts/jTable.js",
77
+ "spec/support/rails_app/public/stylesheets/jTable.css",
70
78
  "spec/support/rails_app/public/stylesheets/scaffold.css",
71
- "spec/support/rails_app/script/rails"
79
+ "spec/support/rails_app/script/rails",
80
+ "spec/support/rails_app/tmp/.DS_Store",
81
+ "spec/support/rails_app/tmp/jtable.zip"
72
82
  ]
73
83
  s.homepage = %q{http://github.com/yelvert/jtable-rails}
74
84
  s.licenses = ["Ms-PL"]
@@ -0,0 +1,7 @@
1
+ module JTable
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ load "tasks/jtable_rails.rake"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ JTABLE_RAILS_VERSION = "0.1.4"
2
+ JTABLE_VERSION = "0.1.1"
data/lib/jtable-rails.rb CHANGED
@@ -1,5 +1,9 @@
1
+ require 'jtable-rails/version'
1
2
  require 'rails/all'
2
3
  require 'jtable-rails/active_record'
3
4
  require 'jtable-rails/action_controller'
4
5
  ::ActiveRecord::Base.send(:include, JTable::ActiveRecord) if defined? ::ActiveRecord
5
- ::ActionController::Base.send(:include, JTable::ActionController) if defined? ::ActionController
6
+ ::ActionController::Base.send(:include, JTable::ActionController) if defined? ::ActionController
7
+ module JTable
8
+ require 'jtable-rails/railtie' if defined?(Rails)
9
+ end
@@ -0,0 +1,29 @@
1
+ namespace :jtable do
2
+ desc 'Fetch latest jTable code'
3
+ task :update => :environment do
4
+ require 'net/http'
5
+ require 'open-uri'
6
+ url = "http://www.jtable.net/downloads/#{JTABLE_VERSION.gsub('.', '_')}"
7
+ Net::HTTP.start(URI.parse(url).host) do |http|
8
+ resp = http.get(URI.parse("#{url}/jTable.js").path)
9
+ File.open(File.join(Rails.root, 'public', 'javascripts', 'jTable.js'), 'w+') do |file|
10
+ file.write resp.body
11
+ end
12
+
13
+ resp = http.get(URI.parse("#{url}/jTable.css").path)
14
+ File.open(File.join(Rails.root, 'public', 'stylesheets', 'jTable.css'), 'w+') do |file|
15
+ file.write resp.body
16
+ end
17
+
18
+ resp = http.get(URI.parse("#{url}/jTable-icons.png").path)
19
+ File.open(File.join(Rails.root, 'public', 'images', 'jTable-icons.png'), 'wb') do |file|
20
+ file.write resp.body
21
+ end
22
+
23
+ resp = http.get(URI.parse("#{url}/jTable-processing_bg.png").path)
24
+ File.open(File.join(Rails.root, 'public', 'images', 'jTable-processing_bg.png'), 'wb') do |file|
25
+ file.write resp.body
26
+ end
27
+ end
28
+ end
29
+ end
Binary file
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/yelvert/projects/jtable/jtable-rails
3
3
  specs:
4
- jtable-rails (0.1.2)
4
+ jtable-rails (0.1.3)
5
5
  rails (= 3.0.5)
6
6
 
7
7
  GEM
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,516 @@
1
+ /*
2
+ jTable jQuery Plugin v0.1.1
3
+ (c) 2011 Taylor Yelverton - http://www.jtable.net
4
+ License: MIT (http://www.opensource.org/licenses/mit-license.php)
5
+
6
+ Compiled with CoffeeScript version 1.0.0
7
+ coffee -b -c jtable.coffee
8
+
9
+ */var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
10
+ (function($) {
11
+ $.jTable = {
12
+ defaults: {
13
+ settings: {
14
+ columns: [],
15
+ identifierAttribute: 'id',
16
+ singleColumnSearch: false,
17
+ perPage: 25,
18
+ perPageOptions: [25, 50, 100],
19
+ fullPagination: true,
20
+ ajaxInterval: 250,
21
+ rowClass: '',
22
+ width: '',
23
+ indexUrl: '',
24
+ viewLink: true,
25
+ viewUrl: '?id=:id:',
26
+ inlineView: true,
27
+ editLink: true,
28
+ editUrl: 'edit?id=:id:',
29
+ destroyLink: true,
30
+ destroyUrl: '?id=:id:',
31
+ onDestroy: function() {},
32
+ otherActions: [],
33
+ language: {
34
+ viewLinkText: "View",
35
+ editLinkText: "Edit",
36
+ destroyLinkText: "Destroy",
37
+ noItemsMsg: "No Records were found.",
38
+ destroyConfirmMsg: "Are you sure?"
39
+ }
40
+ },
41
+ column: {
42
+ searchable: true,
43
+ sortable: true,
44
+ dataType: 'string',
45
+ trueValue: 'True',
46
+ falseValue: 'False',
47
+ columnClass: ''
48
+ }
49
+ }
50
+ };
51
+ return $.fn.jTable = function(options) {
52
+ if (options == null) {
53
+ options = {};
54
+ }
55
+ return this.each(function() {
56
+ var buildAll, buildBottomToolbar, buildPerPageSelect, buildSearch, buildTable, buildTableFoot, buildTableHead, buildTopToolbar, changePage, column, fetchItems, generateBaseQuery, i, insertInfoRowForItem, insertItemAttributesIntoString, updateItems, updatePageInfo, updatePagination, updateProcessingOverlay, updateTableRows, _len, _ref;
57
+ buildAll = __bind(function() {
58
+ buildTopToolbar();
59
+ buildTable();
60
+ buildBottomToolbar();
61
+ return fetchItems();
62
+ }, this);
63
+ generateBaseQuery = __bind(function() {
64
+ var column, searchable_columns, _i, _len, _ref;
65
+ searchable_columns = [];
66
+ _ref = this.settings.columns;
67
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
68
+ column = _ref[_i];
69
+ if (column.searchable) {
70
+ searchable_columns.push(column.attribute);
71
+ }
72
+ }
73
+ this.query.searchable_columns = searchable_columns;
74
+ this.query.search = "";
75
+ this.query.limit = this.settings.perPage;
76
+ this.query.offset = 0;
77
+ return this.query.column_search = {};
78
+ }, this);
79
+ fetchItems = __bind(function() {
80
+ var ajax, current_query;
81
+ if (this.query !== this.previous_query || this.query.search === "") {
82
+ current_query = $.extend(true, {}, this.query);
83
+ this.stale_paging = false;
84
+ updateProcessingOverlay();
85
+ this.processing_overlay.show();
86
+ ajax = $.ajax({
87
+ url: this.settings.indexUrl,
88
+ data: {
89
+ jTableQuery: current_query
90
+ },
91
+ cache: false,
92
+ success: __bind(function(data, textStatus, XMLHttpRequest) {
93
+ updateItems(data);
94
+ this.initial_load = false;
95
+ return this.processing_overlay.hide();
96
+ }, this)
97
+ });
98
+ return this.previous_query = $.extend(true, {}, current_query);
99
+ }
100
+ }, this);
101
+ updateItems = __bind(function(data) {
102
+ var item, items, _i, _len;
103
+ this.items_count = data.total_items;
104
+ items = data.items;
105
+ this.items = [];
106
+ for (_i = 0, _len = items.length; _i < _len; _i++) {
107
+ item = items[_i];
108
+ this.items.push(item);
109
+ }
110
+ this.container.data('jTable').items = this.items;
111
+ updateTableRows();
112
+ return changePage(this.page);
113
+ }, this);
114
+ updateProcessingOverlay = __bind(function() {
115
+ var box, box_css, container_css;
116
+ container_css = {
117
+ left: this.container.position().left,
118
+ top: this.container.position().top,
119
+ width: this.container.width(),
120
+ height: this.container.height()
121
+ };
122
+ this.processing_overlay.css(container_css);
123
+ box = $('div', this.processing_overlay);
124
+ box_css = {
125
+ left: (parseInt(container_css.width, 10) / 2) - 75,
126
+ top: parseInt(container_css.height, 10) / 2
127
+ };
128
+ return box.css(box_css);
129
+ }, this);
130
+ buildTopToolbar = __bind(function() {
131
+ var toolbar;
132
+ toolbar = $('<div class="jTable-top-toolbar"></div>');
133
+ this.container.append(toolbar);
134
+ buildSearch();
135
+ return buildPerPageSelect();
136
+ }, this);
137
+ buildTable = __bind(function() {
138
+ this.container.append('<div class="jTable-table-container"><table class="jTable-table"><thead></thead><tbody></tbody><tfoot></tfoot></table></div>');
139
+ this.table = $('table', this.container);
140
+ buildTableHead();
141
+ if (this.settings.singleColumnSearch) {
142
+ return buildTableFoot();
143
+ }
144
+ }, this);
145
+ buildTableHead = __bind(function() {
146
+ var column, table_head, th, _i, _len, _ref;
147
+ table_head = $('thead', this.table);
148
+ _ref = this.settings.columns;
149
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
150
+ column = _ref[_i];
151
+ th = $('<th class="jTable-column-heading"></th>');
152
+ th.attr('data-jTable-column-attribute', column.attribute);
153
+ if (column.heading === void 0) {
154
+ th.html("<div>" + column.attribute + "</div>");
155
+ } else {
156
+ th.html("<div>" + column.heading + "</div>");
157
+ }
158
+ if (column.sortable) {
159
+ $('div', th).append('<span class="jTable-sort jTable-sort-none"></span>');
160
+ th.click(__bind(function(event) {
161
+ var attribute, sort_icon;
162
+ $('.jTable-column-heading span', this.container).removeClass('jTable-sort-asc jTable-sort-desc');
163
+ attribute = $(event.currentTarget).attr('data-jTable-column-attribute');
164
+ sort_icon = $('span', $(event.currentTarget));
165
+ if (this.query.sort_column === attribute) {
166
+ if (this.query.sort_direction === '') {
167
+ this.query.sort_direction = 'ASC';
168
+ sort.addClass('jTable-sort-asc');
169
+ } else if (this.query.sort_direction === 'ASC') {
170
+ this.query.sort_direction = 'DESC';
171
+ sort_icon.addClass('jTable-sort-desc');
172
+ } else {
173
+ this.query.sort_column = '';
174
+ this.query.sort_direction = '';
175
+ sort_icon.addClass('jTable-sort-none');
176
+ }
177
+ } else {
178
+ this.query.sort_column = attribute;
179
+ this.query.sort_direction = 'ASC';
180
+ sort_icon.addClass('jTable-sort-asc');
181
+ }
182
+ return fetchItems();
183
+ }, this));
184
+ }
185
+ table_head.append($(th));
186
+ }
187
+ if (this.show_links) {
188
+ return table_head.append($('<th class="jTable-column-heading">&nbsp</th>'));
189
+ }
190
+ }, this);
191
+ buildTableFoot = __bind(function() {
192
+ var column, search_field, table_foot, th, _i, _len, _ref;
193
+ if (this.settings.singleColumnSearch) {
194
+ table_foot = $('tfoot', this.table);
195
+ _ref = this.settings.columns;
196
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
197
+ column = _ref[_i];
198
+ if (column.searchable) {
199
+ th = $('<th class="jTable-column-footer"></th>');
200
+ search_field = $("<input type='text' jTable-column-attribute='" + column.attribute + "'>");
201
+ search_field.keyup(__bind(function(event) {
202
+ var attribute, current_search, field;
203
+ field = $(event.currentTarget);
204
+ attribute = field.attr('jTable-column-attribute');
205
+ this.query.column_search[attribute] = field.val();
206
+ current_search = String(this.query.column_search[attribute]);
207
+ return setTimeout(__bind(function() {
208
+ if (current_search === field.val()) {
209
+ this.page = 1;
210
+ this.query.offset = 0;
211
+ return fetchItems();
212
+ }
213
+ }, this), this.settings.ajaxInterval);
214
+ }, this));
215
+ th.append(search_field);
216
+ } else {
217
+ th = $('<th class="jTable-column-footer">&nbsp;</th>');
218
+ }
219
+ table_foot.append(th);
220
+ }
221
+ if (this.show_links) {
222
+ return table_foot.append($('<th class="jTable-column-footer">&nbsp;</th>'));
223
+ }
224
+ }
225
+ }, this);
226
+ updateTableRows = __bind(function() {
227
+ var action, action_link, actions_cell, blank_row, column, column_count, destroy_link, edit_link, i, item, name, new_cell, new_row, table_body, value, view_link, _i, _j, _len, _len2, _len3, _ref, _ref2, _ref3, _results;
228
+ table_body = $('tbody', this.table);
229
+ table_body.html('');
230
+ if (this.items_count === 0) {
231
+ column_count = this.settings.columns.length;
232
+ if (this.show_links) {
233
+ column_count += 1;
234
+ }
235
+ blank_row = $("<tr><td colspan='" + column_count + "' class='jTable-cell jTable-no-items-row'>" + this.settings.language.noItemsMsg + "</td></tr>");
236
+ return table_body.append(blank_row);
237
+ } else {
238
+ _ref = this.items;
239
+ _results = [];
240
+ for (i = 0, _len = _ref.length; i < _len; i++) {
241
+ item = _ref[i];
242
+ new_row = $("<tr data-jTable-row-index='" + i + "'></tr>");
243
+ if (i % 2 === 0) {
244
+ new_row.addClass("jTable-row-even");
245
+ } else {
246
+ new_row.addClass("jTable-row-odd");
247
+ }
248
+ new_row.addClass(this.settings.rowClass);
249
+ new_row.attr('data-jTable-item-identifier', item[this.settings.identifierAttribute]);
250
+ _ref2 = this.settings.columns;
251
+ for (_i = 0, _len2 = _ref2.length; _i < _len2; _i++) {
252
+ column = _ref2[_i];
253
+ new_cell = $('<td class="jTable-cell"></td>');
254
+ new_cell.addClass(column.columnClass);
255
+ new_cell.attr({
256
+ 'data-jTable-cell-attribute': column.attribute,
257
+ 'data-jTable-cell-value': item[column.attribute]
258
+ });
259
+ if (column.dataType === 'boolean') {
260
+ if (item[column.attribute]) {
261
+ new_cell.html(column.trueValue);
262
+ } else {
263
+ new_cell.html(column.falseValue);
264
+ }
265
+ } else {
266
+ new_cell.html(item[column.attribute]);
267
+ }
268
+ new_row.append(new_cell);
269
+ }
270
+ if (this.show_links) {
271
+ actions_cell = $('<td class="jTable-actions-cell jTable-cell"></td>');
272
+ _ref3 = this.settings.otherActions;
273
+ for (_j = 0, _len3 = _ref3.length; _j < _len3; _j++) {
274
+ action = _ref3[_j];
275
+ action_link = $("<a>" + action.title + "</a>");
276
+ for (name in action) {
277
+ value = action[name];
278
+ if (name !== "title") {
279
+ action_link.attr(name, insertItemAttributesIntoString(item, value));
280
+ }
281
+ }
282
+ actions_cell.append(action_link);
283
+ }
284
+ if (this.settings.viewLink) {
285
+ if (this.settings.inlineView) {
286
+ view_link = $("<a href='#'>" + this.settings.language.viewLinkText + "</a>");
287
+ view_link.attr('data-jTable-view-url', insertItemAttributesIntoString(item, this.settings.viewUrl));
288
+ view_link.click(__bind(function(event) {
289
+ $("tr.jTable-info-row[data-jTable-item-identifier=" + ($(event.target).closest('tr').attr('data-jTable-item-identifier')) + "]").remove();
290
+ return $.ajax({
291
+ url: $(event.currentTarget).attr('data-jTable-view-url'),
292
+ type: 'GET',
293
+ success: __bind(function(data, status, xhr) {
294
+ return insertInfoRowForItem($(event.currentTarget), data);
295
+ }, this),
296
+ error: __bind(function(xhr, status, error) {
297
+ return this.element.trigger('ajax:error', [xhr, status, error]);
298
+ }, this)
299
+ });
300
+ }, this));
301
+ } else {
302
+ view_link = $("<a>" + this.settings.language.viewLinkText + "</a>");
303
+ view_link.attr('href', insertItemAttributesIntoString(item, this.settings.viewUrl));
304
+ }
305
+ actions_cell.append(view_link);
306
+ }
307
+ if (this.settings.editLink) {
308
+ edit_link = $("<a>" + this.settings.language.editLinkText + "</a>");
309
+ edit_link.attr('href', insertItemAttributesIntoString(item, this.settings.editUrl));
310
+ actions_cell.append(edit_link);
311
+ }
312
+ if (this.settings.destroyLink) {
313
+ destroy_link = $("<a href='#'>" + this.settings.language.destroyLinkText + "</a>");
314
+ destroy_link.attr('data-jTable-destroy-url', insertItemAttributesIntoString(item, this.settings.destroyUrl));
315
+ destroy_link.click(__bind(function(event) {
316
+ if (confirm(this.settings.language.destroyConfirmMsg)) {
317
+ $.ajax({
318
+ url: $(event.currentTarget).attr('data-jTable-destroy-url'),
319
+ type: 'POST',
320
+ data: {
321
+ '_method': 'DELETE'
322
+ },
323
+ success: __bind(function(data, status, xhr) {
324
+ return this.settings.onDestroy(data);
325
+ }, this),
326
+ error: __bind(function(xhr, status, error) {
327
+ return this.element.trigger('ajax:error', [xhr, status, error]);
328
+ }, this)
329
+ });
330
+ return fetchItems();
331
+ }
332
+ }, this));
333
+ actions_cell.append(destroy_link);
334
+ }
335
+ new_row.append(actions_cell);
336
+ }
337
+ _results.push(table_body.append(new_row));
338
+ }
339
+ return _results;
340
+ }
341
+ }, this);
342
+ buildSearch = __bind(function() {
343
+ var search_container, search_field;
344
+ $('.jTable-full-search-container.', this.container).remove();
345
+ search_field = $('<input type="text" />');
346
+ search_field.keyup(__bind(function() {
347
+ var current_search;
348
+ this.query.search = search_field.val();
349
+ current_search = String(this.query.search);
350
+ return setTimeout(__bind(function() {
351
+ if (current_search === search_field.val()) {
352
+ this.page = 1;
353
+ this.query.offset = 0;
354
+ return fetchItems();
355
+ }
356
+ }, this), this.settings.ajaxInterval);
357
+ }, this));
358
+ search_container = $('<div class="jTable-full-search-container"></div>');
359
+ search_container.html('Search: ');
360
+ search_container.append(search_field);
361
+ return $('.jTable-top-toolbar', this.container).prepend(search_container);
362
+ }, this);
363
+ buildPerPageSelect = __bind(function() {
364
+ var opt, option, per_page_container, select_box, _i, _len, _ref;
365
+ $('.jTable-per-page-container', this.container).remove();
366
+ select_box = $('<select class="jTable-per-page-select"></select>');
367
+ _ref = this.settings.perPageOptions;
368
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
369
+ option = _ref[_i];
370
+ opt = $("<option value='" + option + "'>" + option + "</option>");
371
+ select_box.append(opt);
372
+ }
373
+ select_box.change(__bind(function() {
374
+ this.query.limit = parseInt(select_box.val(), 10);
375
+ this.settings.perPage = parseInt(select_box.val(), 10);
376
+ return fetchItems();
377
+ }, this));
378
+ per_page_container = $('<div class="jTable-per-page-container">Items Per Page: </div>');
379
+ per_page_container.append(select_box);
380
+ return $('.jTable-top-toolbar', this.container).append(per_page_container);
381
+ }, this);
382
+ buildBottomToolbar = __bind(function() {
383
+ var toolbar;
384
+ toolbar = $('<div class="jTable-bottom-toolbar"><div class="jTable-page-info"></div><div class="jTable-pagination-container"></div></div>');
385
+ this.container.append(toolbar);
386
+ updatePageInfo();
387
+ return updatePagination();
388
+ }, this);
389
+ updatePageInfo = __bind(function() {
390
+ var end_items, page_info, start_items, total_items;
391
+ page_info = $('.jTable-page-info', this.container);
392
+ start_items = this.items_count === 0 ? 0 : ((this.page - 1) * this.settings.perPage) + 1;
393
+ end_items = this.items_count - start_items > this.settings.perPage ? start_items + this.settings.perPage - 1 : this.items_count;
394
+ total_items = this.items_count;
395
+ return page_info.html("Displaying " + start_items + " to " + end_items + " of " + total_items + " items.");
396
+ }, this);
397
+ updatePagination = __bind(function() {
398
+ var end_page, generatePaginationButton, i, next_page_link, number_of_pages, page_div, page_link, prev_page_link, start_page;
399
+ page_div = $('.jTable-pagination-container', this.container);
400
+ page_div.html('');
401
+ generatePaginationButton = __bind(function(page_number) {
402
+ return $("<span class='jTable-button jTable-pagination-button' data-jTable-pagination-page='" + page_number + "'>" + page_number + "</span>").click(__bind(function(event) {
403
+ this.stale_paging = true;
404
+ return changePage(parseInt($(event.currentTarget).attr('data-jTable-pagination-page'), 10));
405
+ }, this));
406
+ }, this);
407
+ if (!((this.page - 1) * this.settings.perPage <= 0)) {
408
+ prev_page_link = $("<span class='jTable-button jTable-pagination-button'>Prev</span>");
409
+ prev_page_link.click(__bind(function(event) {
410
+ this.stale_paging = true;
411
+ return changePage(this.page - 1);
412
+ }, this));
413
+ page_div.append(prev_page_link);
414
+ }
415
+ if (this.settings.fullPagination) {
416
+ if (Math.ceil(this.items_count / this.settings.perPage) === 0) {
417
+ page_link = generatePaginationButton(1);
418
+ page_div.append(page_link);
419
+ } else {
420
+ number_of_pages = Math.ceil(this.items_count / this.settings.perPage);
421
+ start_page = this.page - 2 < 1 ? 1 : this.page - 2;
422
+ end_page = this.page + 2 > number_of_pages ? number_of_pages : this.page + 2;
423
+ for (i = start_page; (start_page <= end_page ? i <= end_page : i >= end_page); (start_page <= end_page ? i += 1 : i -= 1)) {
424
+ page_link = generatePaginationButton(i);
425
+ page_div.append(page_link);
426
+ }
427
+ }
428
+ }
429
+ if (!(this.items_count <= this.page * this.settings.perPage)) {
430
+ next_page_link = $("<span class='jTable-button jTable-pagination-button'>Next</span>");
431
+ next_page_link.click(__bind(function(event) {
432
+ this.stale_paging = true;
433
+ return changePage(this.page + 1);
434
+ }, this));
435
+ page_div.append(next_page_link);
436
+ }
437
+ return $(".jTable-pagination-button[data-jTable-pagination-page=" + this.page + "]", this.container).addClass('jTable-pagination-current-page');
438
+ }, this);
439
+ changePage = __bind(function(new_page) {
440
+ if (this.initial_load) {
441
+ this.page = new_page;
442
+ updatePageInfo();
443
+ return updatePagination();
444
+ } else {
445
+ if (this.stale_paging) {
446
+ this.query.offset = (new_page - 1) * this.settings.perPage;
447
+ this.page = new_page;
448
+ return fetchItems();
449
+ } else {
450
+ this.page = new_page;
451
+ updatePageInfo();
452
+ return updatePagination();
453
+ }
454
+ }
455
+ }, this);
456
+ insertItemAttributesIntoString = __bind(function(item, str) {
457
+ var name, value;
458
+ str = str.toString();
459
+ for (name in item) {
460
+ value = item[name];
461
+ str = str.replace(RegExp("(:" + name + ":)"), encodeURIComponent(value));
462
+ }
463
+ return str;
464
+ }, this);
465
+ insertInfoRowForItem = __bind(function(target, data) {
466
+ var close_btn, info_container, info_row, item_row;
467
+ item_row = target.closest('tr');
468
+ info_row = $("<tr class='jTable-info-row'></tr>");
469
+ info_row.attr('data-jTable-item-identifier', item_row.attr('data-jTable-item-identifier'));
470
+ info_container = $('<td></td>');
471
+ info_container.attr('colspan', this.show_links ? this.settings.columns.length + 1 : this.settings.columns.length);
472
+ close_btn = $("<span class='jTable-close-info-row'></span>");
473
+ close_btn.click(__bind(function(event) {
474
+ return $(event.currentTarget).closest('tr').remove();
475
+ }, this));
476
+ info_container.append(close_btn);
477
+ info_container.append(data);
478
+ info_row.append(info_container);
479
+ info_row.insertAfter(item_row);
480
+ return window.scrollTo(item_row.position().left, item_row.position().top);
481
+ }, this);
482
+ this.settings = $.extend(true, {}, $.jTable.defaults.settings);
483
+ this.query = {};
484
+ $.extend(true, this.settings, options);
485
+ _ref = this.settings.columns;
486
+ for (i = 0, _len = _ref.length; i < _len; i++) {
487
+ column = _ref[i];
488
+ this.settings.columns[i] = $.extend(true, {}, $.jTable.defaults.column, column);
489
+ if (this.settings.columns[i].dataType === 'boolean') {
490
+ this.settings.columns[i].searchable = false;
491
+ }
492
+ }
493
+ generateBaseQuery();
494
+ this.container = $(this);
495
+ if (this.settings.width !== '') {
496
+ this.container.css({
497
+ width: this.settings.width
498
+ });
499
+ }
500
+ this.container.addClass('jTable-container');
501
+ this.initial_load = true;
502
+ this.stale_paging = false;
503
+ this.items = [];
504
+ this.show_links = this.settings.viewLink || this.settings.editLink || this.settings.destroyLink || this.settings.otherActions !== [];
505
+ this.container.data('jTable', {});
506
+ this.container.data('jTable').settings = this.settings;
507
+ this.previous_query = $.extend(true, {}, this.query);
508
+ this.table = null;
509
+ this.processing_overlay = $("<div class='jTable-processing-overlay'><div>Processing...</div></div>");
510
+ $(document.body).append(this.processing_overlay);
511
+ this.page = 1;
512
+ buildAll();
513
+ return changePage(1);
514
+ });
515
+ };
516
+ })(jQuery);
@@ -0,0 +1,244 @@
1
+ /* Colors
2
+ light-blue: rgb(174,208,234)
3
+ mid-blue: rgb(222,237,247)
4
+ dark-blue: rgb(39,121,170)
5
+ */
6
+
7
+
8
+ .jTable-container {
9
+ width: 100%;
10
+ }
11
+
12
+ .jTable-container a {
13
+ color: rgb(39,121,170);
14
+ text-decoration: none;
15
+ }
16
+
17
+ .jTable-top-toolbar {
18
+ padding: 5px;
19
+ -moz-border-radius-topright: 6px;
20
+ -webkit-border-top-right-radius: 6px;
21
+ border-top-right-radius: 6px;
22
+ -moz-border-radius-topleft: 6px;
23
+ -webkit-border-top-left-radius: 6px;
24
+ border-top-left-radius: 6px;
25
+ border: 1px solid rgb(39,121,170);
26
+ border-bottom: none;
27
+ background-color: rgb(222,237,247);
28
+ height: 23px;
29
+ }
30
+
31
+ .jTable-full-search-container {
32
+ float: left;
33
+ width: 50%;
34
+ text-align: left;
35
+ }
36
+
37
+ .jTable-per-page-container {
38
+ float: right;
39
+ width: 50%;
40
+ text-align: right;
41
+ }
42
+
43
+ .jTable-table-container {
44
+ border: 1px solid rgb(39,121,170);
45
+ background-color: rgb(222,237,247);
46
+ }
47
+
48
+ .jTable-table {
49
+ border-spacing: 0;
50
+ border-padding: 0;
51
+ width: 100%;
52
+ }
53
+
54
+ .jTable-column-heading {
55
+ border-left: 1px solid rgb(39,121,170);
56
+ border-bottom: 1px solid rgb(39,121,170);
57
+ color: rgb(39,121,170);
58
+ }
59
+
60
+ .jTable-column-heading:first-child {
61
+ border-left: none;
62
+ }
63
+
64
+ .jTable-column-heading div {
65
+ position: relative;
66
+ padding-right: 20px;
67
+ }
68
+
69
+ .jTable-column-heading div span {
70
+ position: absolute;
71
+ top: 50%;
72
+ margin-top: -8px;
73
+ right: 0;
74
+ }
75
+
76
+ .jTable-column-heading div span.jTable-sort {
77
+ width: 16px;
78
+ height: 16px;
79
+ background-image: url(/images/jTable-icons.png);
80
+ display: block;
81
+ text-indent: -99999px;
82
+ overflow: hidden;
83
+ background-repeat: no-repeat;
84
+ float: right;
85
+ }
86
+
87
+ .jTable-column-heading div span.jTable-sort-none {
88
+ background-position: -128px 0;
89
+ }
90
+
91
+ .jTable-column-heading div span.jTable-sort-asc {
92
+ background-position: 0 -16px;
93
+ }
94
+
95
+ .jTable-column-heading div span.jTable-sort-desc {
96
+ background-position: -64px -16px;
97
+ }
98
+
99
+ .jTable-row-odd {
100
+ background-color: rgb(222,237,247);
101
+ }
102
+
103
+ .jTable-row-even {
104
+ background-color: rgb(174,208,234);
105
+ }
106
+
107
+ .jTable-table td {
108
+ padding: 1px 3px;
109
+ }
110
+
111
+ .jTable-no-items-row {
112
+ text-align: center;
113
+ background-color: rgb(174,208,234);
114
+ }
115
+
116
+ .jTable-actions-cell {
117
+ text-align: center;
118
+ }
119
+
120
+ .jTable-actions-cell a {
121
+ padding: 0 5px;
122
+ }
123
+
124
+ .jTable-info-row {
125
+
126
+ }
127
+
128
+ .jTable-info-row td {
129
+ border-top: 1px solid rgb(39,121,170);
130
+ border-bottom: 1px solid rgb(39,121,170);
131
+ }
132
+
133
+ .jTable-info-row td span.jTable-close-info-row {
134
+ width: 16px;
135
+ height: 16px;
136
+ background-image: url(/images/jTable-icons.png);
137
+ display: block;
138
+ text-indent: -99999px;
139
+ overflow: hidden;
140
+ background-repeat: no-repeat;
141
+ float: right;
142
+ background-position: -96px -128px;
143
+ -moz-border-radius: 6px;
144
+ -webkit-border-radius: 6px;
145
+ border-radius: 6px;
146
+ border: 1px solid rgb(39,121,170);
147
+ padding: 0 1px 1px 0;
148
+ margin: 2px;
149
+ }
150
+
151
+ .jTable-column-footer {
152
+ border-left: 1px solid rgb(39,121,170);
153
+ border-top: 1px solid rgb(39,121,170);
154
+ color: rgb(39,121,170);
155
+ }
156
+
157
+ .jTable-column-footer:first-child {
158
+ border-left: none;
159
+ }
160
+
161
+ .jTable-column-footer input {
162
+ width: 90%;
163
+ }
164
+
165
+ .jTable-bottom-toolbar {
166
+ padding: 5px;
167
+ -moz-border-radius-bottomright: 6px;
168
+ -webkit-border-bottom-right-radius: 6px;
169
+ border-bottom-right-radius: 6px;
170
+ -moz-border-radius-bottomleft: 6px;
171
+ -webkit-border-bottom-left-radius: 6px;
172
+ border-bottom-left-radius: 6px;
173
+ border: 1px solid rgb(39,121,170);
174
+ border-top: none;
175
+ background-color: rgb(222,237,247);
176
+ height: 23px;
177
+ }
178
+
179
+ .jTable-page-info {
180
+ margin-top: 2px;
181
+ float: left;
182
+ font-size: .8em;
183
+ }
184
+
185
+ .jTable-pagination-container {
186
+ margin-top: 2px;
187
+ float: right;
188
+ }
189
+
190
+ .jTable-pagination-container span.jTable-pagination-button {
191
+
192
+ }
193
+
194
+ .jTable-pagination-container span.jTable-pagination-button:hover {
195
+ background-color: rgb(174,208,234);
196
+ }
197
+
198
+ .jTable-pagination-container .jTable-pagination-current-page {
199
+ background-color: rgb(174,208,234);
200
+ }
201
+
202
+ .jTable-button {
203
+ color: rgb(39,121,170);
204
+ padding: 1px 3px;
205
+ margin: 0 2px;
206
+ cursor: pointer;
207
+ -moz-border-radius: 6px;
208
+ -webkit-border-radius: 6px;
209
+ border-radius: 6px;
210
+ border: 1px solid rgb(39,121,170);
211
+ background-color: rgb(222,237,247);
212
+ }
213
+
214
+ .jTable-processing-overlay {
215
+ position: absolute;
216
+ z-index: 1000;
217
+ line-height: 50%;
218
+ background: url(/images/jtable_processing_bg.png) repeat;
219
+ }
220
+
221
+ .jTable-processing-overlay div {
222
+ position: absolute;
223
+ padding: 25px;
224
+ border: 1px solid black;
225
+ background-color: white;
226
+ width: 150px;
227
+ text-align: center;
228
+ -moz-border-radius: 15px;
229
+ -webkit-border-radius: 15px;
230
+ border-radius: 15px;
231
+ z-index: 1001;
232
+ }
233
+
234
+ .left {
235
+ text-align: left;
236
+ }
237
+
238
+ .center {
239
+ text-align: center;
240
+ }
241
+
242
+ .right {
243
+ text-align: right;
244
+ }
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Taylor Yelverton
@@ -137,10 +137,14 @@ files:
137
137
  - lib/jtable-rails.rb
138
138
  - lib/jtable-rails/action_controller.rb
139
139
  - lib/jtable-rails/active_record.rb
140
+ - lib/jtable-rails/railtie.rb
141
+ - lib/jtable-rails/version.rb
142
+ - lib/tasks/jtable_rails.rake
140
143
  - spec/controller_specs/people_controller_spec.rb
141
144
  - spec/fabricators/person.rb
142
145
  - spec/model_specs/person_spec.rb
143
146
  - spec/spec_helper.rb
147
+ - spec/support/rails_app/.DS_Store
144
148
  - spec/support/rails_app/.gitignore
145
149
  - spec/support/rails_app/Gemfile
146
150
  - spec/support/rails_app/Gemfile.lock
@@ -174,8 +178,14 @@ files:
174
178
  - spec/support/rails_app/db/migrate/20110207142623_create_people.rb
175
179
  - spec/support/rails_app/db/schema.rb
176
180
  - spec/support/rails_app/db/seeds.rb
181
+ - spec/support/rails_app/public/images/jTable-icons.png
182
+ - spec/support/rails_app/public/images/jTable-processing_bg.png
183
+ - spec/support/rails_app/public/javascripts/jTable.js
184
+ - spec/support/rails_app/public/stylesheets/jTable.css
177
185
  - spec/support/rails_app/public/stylesheets/scaffold.css
178
186
  - spec/support/rails_app/script/rails
187
+ - spec/support/rails_app/tmp/.DS_Store
188
+ - spec/support/rails_app/tmp/jtable.zip
179
189
  has_rdoc: true
180
190
  homepage: http://github.com/yelvert/jtable-rails
181
191
  licenses:
@@ -190,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
200
  requirements:
191
201
  - - ">="
192
202
  - !ruby/object:Gem::Version
193
- hash: 626560608574340471
203
+ hash: 2776022680366934975
194
204
  segments:
195
205
  - 0
196
206
  version: "0"