tableling 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/LICENSE.txt +20 -0
  2. data/README.md +8 -0
  3. data/Rakefile +19 -0
  4. data/lib/tableling.rb +6 -0
  5. data/lib/tableling/activerecord.rb +27 -0
  6. data/lib/tableling/engine.rb +5 -0
  7. data/lib/tableling/field.rb +43 -0
  8. data/lib/tableling/model.rb +67 -0
  9. data/lib/tableling/version.rb +3 -0
  10. data/spec/dummy/README.rdoc +261 -0
  11. data/spec/dummy/Rakefile +7 -0
  12. data/spec/dummy/app/assets/javascripts/application.js +23 -0
  13. data/spec/dummy/app/assets/javascripts/books.js +47 -0
  14. data/spec/dummy/app/assets/javascripts/bootstrap.js +2027 -0
  15. data/spec/dummy/app/assets/javascripts/init.js +12 -0
  16. data/spec/dummy/app/assets/stylesheets/application.css.sass +17 -0
  17. data/spec/dummy/app/assets/stylesheets/books.css.sass +19 -0
  18. data/spec/dummy/app/assets/stylesheets/bootstrap/css/bootstrap-responsive.css +1058 -0
  19. data/spec/dummy/app/assets/stylesheets/bootstrap/css/bootstrap.css +5774 -0
  20. data/spec/dummy/app/assets/stylesheets/bootstrap/img/glyphicons-halflings-white.png +0 -0
  21. data/spec/dummy/app/assets/stylesheets/bootstrap/img/glyphicons-halflings.png +0 -0
  22. data/spec/dummy/app/assets/stylesheets/bootstrap/index.css +4 -0
  23. data/spec/dummy/app/assets/stylesheets/img/sort_asc.png +0 -0
  24. data/spec/dummy/app/assets/stylesheets/img/sort_asc_disabled.png +0 -0
  25. data/spec/dummy/app/assets/stylesheets/img/sort_both.png +0 -0
  26. data/spec/dummy/app/assets/stylesheets/img/sort_desc.png +0 -0
  27. data/spec/dummy/app/assets/stylesheets/img/sort_desc_disabled.png +0 -0
  28. data/spec/dummy/app/assets/templates/booksTableEmptyRow.hamlc +1 -0
  29. data/spec/dummy/app/assets/templates/booksTableRow.hamlc +2 -0
  30. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  31. data/spec/dummy/app/controllers/books_controller.rb +6 -0
  32. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  33. data/spec/dummy/app/helpers/books_helper.rb +2 -0
  34. data/spec/dummy/app/models/book.rb +13 -0
  35. data/spec/dummy/app/views/books/index.html.haml +32 -0
  36. data/spec/dummy/app/views/layouts/application.html.haml +16 -0
  37. data/spec/dummy/config.ru +4 -0
  38. data/spec/dummy/config/application.rb +59 -0
  39. data/spec/dummy/config/boot.rb +10 -0
  40. data/spec/dummy/config/database.yml +25 -0
  41. data/spec/dummy/config/environment.rb +5 -0
  42. data/spec/dummy/config/environments/development.rb +37 -0
  43. data/spec/dummy/config/environments/production.rb +67 -0
  44. data/spec/dummy/config/environments/test.rb +37 -0
  45. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  46. data/spec/dummy/config/initializers/inflections.rb +15 -0
  47. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  48. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  49. data/spec/dummy/config/initializers/session_store.rb +8 -0
  50. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  51. data/spec/dummy/config/locales/en.yml +5 -0
  52. data/spec/dummy/config/routes.rb +66 -0
  53. data/spec/dummy/db/development.sqlite3 +0 -0
  54. data/spec/dummy/db/migrate/20121008115302_create_books.rb +12 -0
  55. data/spec/dummy/db/schema.rb +26 -0
  56. data/spec/dummy/db/seeds.rb +73 -0
  57. data/spec/dummy/log/development.log +4938 -0
  58. data/spec/dummy/public/404.html +26 -0
  59. data/spec/dummy/public/422.html +26 -0
  60. data/spec/dummy/public/500.html +25 -0
  61. data/spec/dummy/public/favicon.ico +0 -0
  62. data/spec/dummy/script/rails +6 -0
  63. data/spec/dummy/tmp/cache/assets/BF1/770/sprockets%2F8228a53c539c582499241527570aa216 +0 -0
  64. data/spec/dummy/tmp/cache/assets/C3F/0C0/sprockets%2F4643701467ac62c314510c8dd021916f +0 -0
  65. data/spec/dummy/tmp/cache/assets/C53/AD0/sprockets%2F712078516a81502575c831cb0a8e898e +0 -0
  66. data/spec/dummy/tmp/cache/assets/C59/0F0/sprockets%2F099f4e84a443568245ff0674030f6e05 +0 -0
  67. data/spec/dummy/tmp/cache/assets/C60/CF0/sprockets%2F32a45292ee67867d8715952f3072ad84 +0 -0
  68. data/spec/dummy/tmp/cache/assets/C80/840/sprockets%2F562c2d168da585f80579347d10790a0a +0 -0
  69. data/spec/dummy/tmp/cache/assets/C82/F20/sprockets%2F117015d65237e3682f5b21c87d58ab95 +0 -0
  70. data/spec/dummy/tmp/cache/assets/C86/280/sprockets%2F1345c9947753f018f45371ec5083fa2d +0 -0
  71. data/spec/dummy/tmp/cache/assets/C9A/900/sprockets%2Fc1b5b7611d7c10e124512724f29f241d +0 -0
  72. data/spec/dummy/tmp/cache/assets/CAF/540/sprockets%2F8f42e689b84f0b25c0180046467adf31 +0 -0
  73. data/spec/dummy/tmp/cache/assets/CC1/4E0/sprockets%2F6ef77414c793c84a437244d7d965ba90 +0 -0
  74. data/spec/dummy/tmp/cache/assets/CC3/B10/sprockets%2F0a2c59284c7a5d99581883a9763b5ad8 +0 -0
  75. data/spec/dummy/tmp/cache/assets/CC9/940/sprockets%2F8128c279185cf97dba7914278ce838b4 +0 -0
  76. data/spec/dummy/tmp/cache/assets/CCA/0C0/sprockets%2F6c3e053393afe303432ca73f1b41490b +0 -0
  77. data/spec/dummy/tmp/cache/assets/CD5/2C0/sprockets%2F166c056119ebdfb8b7104c97b424b423 +0 -0
  78. data/spec/dummy/tmp/cache/assets/CE9/760/sprockets%2F5ae7fab601683996918936cad21fc244 +0 -0
  79. data/spec/dummy/tmp/cache/assets/CF1/AF0/sprockets%2F14dc9633b61024231ebec0c1a4a0259f +0 -0
  80. data/spec/dummy/tmp/cache/assets/D02/340/sprockets%2Fae58ed66f72137a594b0912bab600e03 +0 -0
  81. data/spec/dummy/tmp/cache/assets/D0B/190/sprockets%2F68cb0d1054ca546fc473274c4ac8737c +0 -0
  82. data/spec/dummy/tmp/cache/assets/D11/530/sprockets%2F13bc8c66140adef2e97648630866aae3 +0 -0
  83. data/spec/dummy/tmp/cache/assets/D16/AA0/sprockets%2Ff181e659a47e2cf9c257f32d80452bd3 +0 -0
  84. data/spec/dummy/tmp/cache/assets/D18/840/sprockets%2F50c1885539f61359c48af74fcae1df31 +0 -0
  85. data/spec/dummy/tmp/cache/assets/D1B/940/sprockets%2F7c4819d1dd9b64a22941d8c7bd1e6954 +0 -0
  86. data/spec/dummy/tmp/cache/assets/D2B/1F0/sprockets%2F6a4c116e8316d082bb0ffae02e94b107 +0 -0
  87. data/spec/dummy/tmp/cache/assets/D4B/C30/sprockets%2Fe8aa746e637d69ff0ac1e71e528c5292 +0 -0
  88. data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  89. data/spec/dummy/tmp/cache/assets/D5A/E20/sprockets%2Febf23d670481ba70b341aa2eb6e37b08 +0 -0
  90. data/spec/dummy/tmp/cache/assets/D5C/1F0/sprockets%2F2d3f2cfd98bf787168fb59f84ab24784 +0 -0
  91. data/spec/dummy/tmp/cache/assets/D5D/C60/sprockets%2Ffa0336b42d01aa9173d9d4c12fc4e82d +0 -0
  92. data/spec/dummy/tmp/cache/assets/D68/930/sprockets%2F5a15e52e84502f9fceb7ea04020f65fc +0 -0
  93. data/spec/dummy/tmp/cache/assets/D8C/140/sprockets%2F2afdbb3902a1be5d2f045cfc837903a3 +0 -0
  94. data/spec/dummy/tmp/cache/assets/D8E/660/sprockets%2F3a3eed926bdf64000ccacb36022f78d4 +0 -0
  95. data/spec/dummy/tmp/cache/assets/D95/690/sprockets%2Fe4d19a04705ee5d72c7fa64dc2070ddb +0 -0
  96. data/spec/dummy/tmp/cache/assets/DA4/EC0/sprockets%2F8da2289e16c1d0cac94aa825ee18d99d +0 -0
  97. data/spec/dummy/tmp/cache/assets/DA6/120/sprockets%2Fc5880aca76ccbb51f9388362e8afc1e6 +0 -0
  98. data/spec/dummy/tmp/cache/assets/DA7/390/sprockets%2F25e744cd1b6f8f7ce1d52c1e86a8f19a +0 -0
  99. data/spec/dummy/tmp/cache/assets/DAB/3E0/sprockets%2F63d2fa621beec4fe878f9eb2884426ab +0 -0
  100. data/spec/dummy/tmp/cache/assets/DAB/660/sprockets%2F9a8c36769afcc7027b4b6ee0c3e77ce5 +0 -0
  101. data/spec/dummy/tmp/cache/assets/DBF/EB0/sprockets%2F2afcec323c8ba12a2b7c852f23aa589e +0 -0
  102. data/spec/dummy/tmp/cache/assets/DCE/9F0/sprockets%2F8fa8c08ea8da97c06cd6c32fe3e613b0 +0 -0
  103. data/spec/dummy/tmp/cache/assets/DD8/0A0/sprockets%2Fb2c3097effcd6084ec75e1f745d1d7dd +0 -0
  104. data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  105. data/spec/dummy/tmp/cache/assets/DF0/040/sprockets%2F04bbbe1ee5ca914173cd90cf6e8a4e0b +0 -0
  106. data/spec/dummy/tmp/cache/assets/DF7/C80/sprockets%2Ff503b3666caf04beb7cfe54cbdb0575e +0 -0
  107. data/spec/dummy/tmp/cache/assets/DFA/B70/sprockets%2F262fb95d3f7cfc16febb0f0128ac38ce +0 -0
  108. data/spec/dummy/tmp/cache/assets/E03/260/sprockets%2Fd1fcfea59ff53c32557ffcd93016cb2e +0 -0
  109. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  110. data/spec/dummy/tmp/cache/assets/E43/810/sprockets%2F79b0ef75ceb26a9c8fca797db3efba96 +0 -0
  111. data/spec/dummy/tmp/cache/assets/E96/1B0/sprockets%2F6d5fe51f9c1a3d2f898becd0bcddef3e +0 -0
  112. data/spec/dummy/tmp/cache/assets/ED4/410/sprockets%2F082adbb8e2abd8a21c8b34aebbbfbfad +0 -0
  113. data/spec/dummy/tmp/pids/server.pid +1 -0
  114. data/spec/models/book_spec.rb +7 -0
  115. data/spec/spec_helper.rb +94 -0
  116. data/spec/version_spec.rb +8 -0
  117. data/vendor/assets/javascripts/tableling.js +210 -0
  118. metadata +301 -0
@@ -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,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</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/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</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/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1 @@
1
+ 5328
@@ -0,0 +1,7 @@
1
+
2
+ describe Book do
3
+
4
+ it "should respond to #tableling" do
5
+ Book.respond_to?(:tableling).should be_true
6
+ end
7
+ end
@@ -0,0 +1,94 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../dummy/config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'rspec/autorun'
6
+ require 'capybara/rspec'
7
+ require 'database_cleaner'
8
+ require 'factory_girl'
9
+
10
+ DatabaseCleaner.strategy = :truncation
11
+ Capybara.default_driver = :selenium
12
+ FactoryGirl.find_definitions
13
+
14
+ # Run any available migration
15
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
16
+
17
+ # Requires supporting ruby files with custom matchers and macros, etc,
18
+ # in spec/support/ and its subdirectories.
19
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
20
+
21
+ module TestServerHelper
22
+ def visit_test_server *args
23
+ args.unshift test_server_root_url
24
+ visit URI.join(*args).to_s
25
+ end
26
+
27
+ def test_server_root_url
28
+ "http://localhost:#{RSpec.configuration.test_server_port}"
29
+ end
30
+ end
31
+
32
+ RSpec.configure do |config|
33
+ # ## Mock Framework
34
+ #
35
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
36
+ #
37
+ # config.mock_with :mocha
38
+ # config.mock_with :flexmock
39
+ # config.mock_with :rr
40
+
41
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
42
+ #config.fixture_path = "#{::Rails.root}/spec/fixtures"
43
+ config.include FactoryGirl::Syntax::Methods
44
+
45
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
46
+ # examples within a transaction, remove the following line or assign false
47
+ # instead of true.
48
+ config.use_transactional_fixtures = true
49
+
50
+ # If true, the base class of anonymous controllers will be inferred
51
+ # automatically. This will be the default behavior in future versions of
52
+ # rspec-rails.
53
+ config.infer_base_class_for_anonymous_controllers = false
54
+
55
+ # Run specs in random order to surface order dependencies. If you find an
56
+ # order dependency and want to debug it, you can fix the order by providing
57
+ # the seed, which is printed after each run.
58
+ # --seed 1234
59
+ config.order = "random"
60
+
61
+ # Test server for capybara tests
62
+ # Skip it for fast specs
63
+ =begin
64
+ unless config.try(:exclusion_filter).try(:[], :type) == 'request'
65
+
66
+ # Test server settings
67
+ config.add_setting :test_server_wait
68
+ config.add_setting :test_server_port
69
+ config.test_server_wait = 3
70
+ config.test_server_port = 3001
71
+ config.include TestServerHelper
72
+
73
+ # Start test server before all tests
74
+ config.before :suite do
75
+ puts
76
+ port = config.test_server_port
77
+ wait = config.test_server_wait
78
+ puts Paint["Starting test server...", :magenta]
79
+ raise 'Could not start test server' unless system "bundle exec thin start -e test -p #{port} -d"
80
+ puts Paint["Waiting #{wait} seconds for test server to start...", :magenta]
81
+ sleep wait
82
+ puts Paint["Successfully started test server on port #{port}.", :cyan, :bold]
83
+ end
84
+
85
+ # Stop test server after all tests
86
+ config.after :suite do
87
+ puts
88
+ puts Paint["Stopping test server...", :magenta]
89
+ raise 'Could not stop test server' unless system "bundle exec thin stop -e test"
90
+ puts Paint["Successfully stopped test server.", :cyan, :bold]
91
+ end
92
+ end
93
+ =end
94
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Version" do
4
+ it "should be correct" do
5
+ version_file = File.expand_path '../../VERSION', __FILE__
6
+ Tableling::VERSION.should == File.open(version_file, 'r').read
7
+ end
8
+ end
@@ -0,0 +1,210 @@
1
+
2
+ var Tableling = {};
3
+
4
+ Tableling.Collection = Backbone.Collection.extend({
5
+
6
+ parse : function(response) {
7
+ return response.data;
8
+ }
9
+ });
10
+
11
+ Tableling.Table = Backbone.Marionette.CompositeView.extend({
12
+
13
+ itemViewContainer: 'tbody',
14
+
15
+ ui : {
16
+ pageSize : '.tableling_page_size',
17
+ quickSearch : '.tableling_quick_search',
18
+ firstPage : '.tableling_page .first',
19
+ previousPage : '.tableling_page .previous',
20
+ nextPage : '.tableling_page .next',
21
+ lastPage : '.tableling_page .last',
22
+ infoFirst : '.tableling_info .first',
23
+ infoLast : '.tableling_info .last',
24
+ infoTotal : '.tableling_info .total'
25
+ },
26
+
27
+ events : {
28
+ 'click .sorting': 'changeSort',
29
+ 'click .sorting-asc': 'changeSort',
30
+ 'click .sorting-desc': 'changeSort'
31
+ },
32
+
33
+ triggers : {
34
+ 'change .tableling_page_size' : 'changePageSize',
35
+ 'change .tableling_quick_search' : 'changeQuickSearch',
36
+ 'click .tableling_page .first:not(.disabled)' : 'goToFirstPage',
37
+ 'click .tableling_page .previous:not(.disabled)' : 'goToPreviousPage',
38
+ 'click .tableling_page .next:not(.disabled)' : 'goToNextPage',
39
+ 'click .tableling_page .last:not(.disabled)' : 'goToLastPage',
40
+ },
41
+
42
+ initialize : function() {
43
+ this.collection.on('reset', this.clearLoading, this);
44
+ this.bind('composite:rendered', this.setup, this);
45
+ this.on('refreshTable', _.bind(this.refresh, this));
46
+ this.on('goToFirstPage', _.bind(this.goToFirstPage, this));
47
+ this.on('goToPreviousPage', _.bind(this.goToPreviousPage, this));
48
+ this.on('goToNextPage', _.bind(this.goToNextPage, this));
49
+ this.on('goToLastPage', _.bind(this.goToLastPage, this));
50
+ this.on('changeSort', _.bind(this.changeSort, this));
51
+ this.on('changePageSize', _.bind(this.changePageSize, this));
52
+ this.on('changeQuickSearch', _.bind(this.changeQuickSearch, this));
53
+ this.tableling = {};
54
+ this.tableling.currentPage = 1;
55
+ this.tableling.sort = [];
56
+ },
57
+
58
+ changePageSize : function() {
59
+ this.tableling.currentPage = 1;
60
+ this.refresh();
61
+ },
62
+
63
+ changeQuickSearch : function() {
64
+ this.tableling.currentPage = 1;
65
+ this.refresh();
66
+ },
67
+
68
+ changeSort : function(ev) {
69
+
70
+ var el = $(ev.currentTarget);
71
+ var field = this.fieldName(el);
72
+
73
+ this.tableling.currentPage = 1;
74
+
75
+ if (ev.shiftKey || this.tableling.sort.length == 1) {
76
+
77
+ var existing = _.find(this.tableling.sort, function(item) {
78
+ return item.field == field;
79
+ });
80
+
81
+ if (existing) {
82
+ existing.direction = existing.direction == 'asc' ? 'desc' : 'asc';
83
+ el.removeClass('sorting sorting-asc sorting-desc');
84
+ el.addClass('sorting-' + existing.direction);
85
+ return this.refresh();
86
+ };
87
+ }
88
+
89
+ if (!ev.shiftKey) {
90
+ this.tableling.sort = [];
91
+ this.$el.find('thead th').removeClass('sorting sorting-asc sorting-desc').addClass('sorting');
92
+ }
93
+
94
+ this.tableling.sort.push({
95
+ field: field,
96
+ direction: 'asc'
97
+ });
98
+
99
+ el.removeClass('sorting sorting-asc sorting-desc').addClass('sorting-asc');
100
+
101
+ this.refresh();
102
+ },
103
+
104
+ fieldName : function(element) {
105
+ return element.data('field') || element.text().toLowerCase();
106
+ },
107
+
108
+ goToFirstPage : function() {
109
+ this.tableling.currentPage = 1;
110
+ this.updatePageControls();
111
+ this.refresh();
112
+ },
113
+
114
+ goToPreviousPage : function() {
115
+ this.tableling.currentPage--;
116
+ this.updatePageControls();
117
+ this.refresh();
118
+ },
119
+
120
+ goToNextPage : function() {
121
+ this.tableling.currentPage++;
122
+ this.updatePageControls();
123
+ this.refresh();
124
+ },
125
+
126
+ goToLastPage : function() {
127
+ this.tableling.currentPage = Math.ceil(this.tableling.total / this.pageSize());
128
+ this.updatePageControls();
129
+ this.refresh();
130
+ },
131
+
132
+ updatePageControls : function() {
133
+ this.ui.firstPage.addClass('disabled');
134
+ this.ui.previousPage.addClass('disabled');
135
+ this.ui.nextPage.addClass('disabled');
136
+ this.ui.lastPage.addClass('disabled');
137
+ if (this.tableling.currentPage > 1) {
138
+ this.ui.firstPage.removeClass('disabled');
139
+ this.ui.previousPage.removeClass('disabled');
140
+ }
141
+ if (this.tableling.currentPage * this.pageSize() < this.tableling.total) {
142
+ this.ui.nextPage.removeClass('disabled');
143
+ this.ui.lastPage.removeClass('disabled');
144
+ }
145
+ },
146
+
147
+ setup : function() {
148
+ this.updatePageControls();
149
+ this.refresh();
150
+ },
151
+
152
+ refresh : function() {
153
+ this.collection.fetch({
154
+ type: 'POST',
155
+ data: this.requestData(),
156
+ success: _.bind(this.processResponse, this)
157
+ });
158
+ },
159
+
160
+ processResponse : function(collection, response) {
161
+ this.tableling.total = response.total;
162
+ var first = (this.tableling.currentPage - 1) * this.pageSize() + 1;
163
+ var last = first + this.collection.length - 1;
164
+ if (!this.collection.length) {
165
+ first = 0;
166
+ last = 0;
167
+ };
168
+ this.ui.infoFirst.text(first);
169
+ this.ui.infoLast.text(last);
170
+ this.ui.infoTotal.text(this.tableling.total);
171
+ this.updatePageControls();
172
+ },
173
+
174
+ pageSize : function() {
175
+ var pageSize = this.ui.pageSize.val();
176
+ return pageSize.length ? pageSize : 10;
177
+ },
178
+
179
+ requestData : function() {
180
+
181
+ var data = {
182
+ page: this.tableling.currentPage,
183
+ page_size: this.pageSize()
184
+ };
185
+
186
+ if (this.tableling.sort.length) {
187
+ data.sort = this.sortData();
188
+ }
189
+
190
+ if (this.ui.quickSearch.val().length) {
191
+ data.quick_search = this.ui.quickSearch.val();
192
+ }
193
+
194
+ if (Tableling.debug) {
195
+ console.log(JSON.stringify(data));
196
+ }
197
+
198
+ return data;
199
+ },
200
+
201
+ sortData : function() {
202
+ return _.map(this.tableling.sort, function(item) {
203
+ return item.field + ' ' + item.direction;
204
+ });
205
+ },
206
+
207
+ clearLoading : function() {
208
+ this.$el.find('tr.loading').remove();
209
+ }
210
+ });