fancygrid 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. data/CHANGELOG +9 -2
  2. data/Gemfile +6 -9
  3. data/Gemfile.lock +88 -103
  4. data/README.md +226 -0
  5. data/ROADMAP +0 -1
  6. data/Rakefile +2 -2
  7. data/VERSION +1 -1
  8. data/app/views/fancygrid/controls.html.haml +34 -0
  9. data/app/views/fancygrid/fancygrid.html.haml +18 -0
  10. data/app/views/fancygrid/search.html.haml +24 -0
  11. data/app/views/fancygrid/sort.html.haml +8 -0
  12. data/app/views/fancygrid/table.html.haml +25 -0
  13. data/config/locales/fancygrid.de.yml +17 -19
  14. data/config/locales/fancygrid.en.yml +14 -17
  15. data/fancygrid.gemspec +48 -88
  16. data/lib/assets/javascripts/fancygrid.js +425 -0
  17. data/lib/assets/javascripts/fancygrid.min.js +15 -0
  18. data/lib/assets/stylesheets/fancygrid.css +177 -0
  19. data/lib/fancygrid.rb +63 -44
  20. data/lib/fancygrid/column.rb +165 -0
  21. data/lib/fancygrid/controller/helper.rb +46 -0
  22. data/lib/fancygrid/grid.rb +171 -317
  23. data/lib/fancygrid/node.rb +85 -490
  24. data/lib/fancygrid/object_wrapper.rb +24 -0
  25. data/lib/fancygrid/orm/active_record.rb +39 -0
  26. data/lib/fancygrid/orm/sql_generator.rb +127 -0
  27. data/lib/fancygrid/view/helper.rb +44 -0
  28. data/lib/fancygrid/view_state.rb +161 -0
  29. data/spec/column_spec.rb +29 -0
  30. data/spec/dummy/app/controllers/application_controller.rb +48 -0
  31. data/spec/dummy/app/views/application/index.html.haml +11 -0
  32. data/spec/dummy/app/views/layouts/application.html.erb +1 -1
  33. data/spec/dummy/config/application.rb +1 -1
  34. data/spec/dummy/config/environments/development.rb +2 -2
  35. data/spec/dummy/config/environments/test.rb +2 -2
  36. data/spec/dummy/config/routes.rb +3 -2
  37. data/spec/dummy/db/development.sqlite3 +0 -0
  38. data/spec/dummy/db/schema.rb +26 -0
  39. data/spec/dummy/public/javascripts/jquery-1.4.2.js +6240 -0
  40. data/spec/dummy/public/javascripts/jquery-fancygrid.js +425 -0
  41. data/spec/dummy/public/javascripts/jquery-ui.js +41 -0
  42. data/spec/dummy/public/stylesheets/fancygrid.css +183 -0
  43. data/spec/node_spec.rb +79 -301
  44. data/spec/spec_helper.rb +0 -29
  45. data/spec/view_state_spec.rb +91 -0
  46. metadata +124 -137
  47. data/.bundle/config +0 -2
  48. data/README.rdoc +0 -299
  49. data/app/views/fancygrid/_cells.html.haml +0 -13
  50. data/app/views/fancygrid/base/controls.html.haml +0 -40
  51. data/app/views/fancygrid/base/list_frame.html.haml +0 -37
  52. data/app/views/fancygrid/base/search.html.haml +0 -33
  53. data/app/views/fancygrid/base/sort.html.haml +0 -20
  54. data/app/views/fancygrid/base/table_frame.html.haml +0 -45
  55. data/config/initializers/fancygrid.rb +0 -67
  56. data/lib/fancygrid/helper.rb +0 -129
  57. data/lib/fancygrid/query_generator.rb +0 -340
  58. data/lib/fancygrid/view.rb +0 -148
  59. data/lib/generators/install_generator.rb +0 -61
  60. data/lib/generators/views_generator.rb +0 -25
  61. data/lib/version.rb +0 -0
  62. data/public/images/fancygrid/add.png +0 -0
  63. data/public/images/fancygrid/clear.png +0 -0
  64. data/public/images/fancygrid/ddn.png +0 -0
  65. data/public/images/fancygrid/dn.png +0 -0
  66. data/public/images/fancygrid/dots.png +0 -0
  67. data/public/images/fancygrid/loading.gif +0 -0
  68. data/public/images/fancygrid/magnifier.png +0 -0
  69. data/public/images/fancygrid/next.png +0 -0
  70. data/public/images/fancygrid/order.png +0 -0
  71. data/public/images/fancygrid/prev.png +0 -0
  72. data/public/images/fancygrid/reload.png +0 -0
  73. data/public/images/fancygrid/remove.png +0 -0
  74. data/public/images/fancygrid/spacer.gif +0 -0
  75. data/public/images/fancygrid/submit.png +0 -0
  76. data/public/images/fancygrid/th_bg.png +0 -0
  77. data/public/images/fancygrid/up.png +0 -0
  78. data/public/images/fancygrid/uup.png +0 -0
  79. data/public/javascripts/fancygrid.js +0 -477
  80. data/public/javascripts/fancygrid.min.js +0 -17
  81. data/public/stylesheets/fancygrid.css +0 -289
  82. data/public/stylesheets/fancygrid.scss +0 -302
  83. data/spec/dummy/log/development.log +0 -0
  84. data/spec/dummy/log/production.log +0 -0
  85. data/spec/dummy/log/server.log +0 -0
  86. data/spec/dummy/log/test.log +0 -1026
  87. data/spec/dummy/public/javascripts/application.js +0 -2
  88. data/spec/dummy/public/javascripts/controls.js +0 -965
  89. data/spec/dummy/public/javascripts/dragdrop.js +0 -974
  90. data/spec/dummy/public/javascripts/effects.js +0 -1123
  91. data/spec/dummy/public/javascripts/prototype.js +0 -6001
  92. data/spec/dummy/public/javascripts/rails.js +0 -175
  93. data/spec/grid_spec.rb +0 -15
  94. data/spec/integration/navigation_spec.rb +0 -9
  95. data/spec/query_generator_spec.rb +0 -358
@@ -1,175 +0,0 @@
1
- (function() {
2
- // Technique from Juriy Zaytsev
3
- // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
4
- function isEventSupported(eventName) {
5
- var el = document.createElement('div');
6
- eventName = 'on' + eventName;
7
- var isSupported = (eventName in el);
8
- if (!isSupported) {
9
- el.setAttribute(eventName, 'return;');
10
- isSupported = typeof el[eventName] == 'function';
11
- }
12
- el = null;
13
- return isSupported;
14
- }
15
-
16
- function isForm(element) {
17
- return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
18
- }
19
-
20
- function isInput(element) {
21
- if (Object.isElement(element)) {
22
- var name = element.nodeName.toUpperCase()
23
- return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
24
- }
25
- else return false
26
- }
27
-
28
- var submitBubbles = isEventSupported('submit'),
29
- changeBubbles = isEventSupported('change')
30
-
31
- if (!submitBubbles || !changeBubbles) {
32
- // augment the Event.Handler class to observe custom events when needed
33
- Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
34
- function(init, element, eventName, selector, callback) {
35
- init(element, eventName, selector, callback)
36
- // is the handler being attached to an element that doesn't support this event?
37
- if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
38
- (!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
39
- // "submit" => "emulated:submit"
40
- this.eventName = 'emulated:' + this.eventName
41
- }
42
- }
43
- )
44
- }
45
-
46
- if (!submitBubbles) {
47
- // discover forms on the page by observing focus events which always bubble
48
- document.on('focusin', 'form', function(focusEvent, form) {
49
- // special handler for the real "submit" event (one-time operation)
50
- if (!form.retrieve('emulated:submit')) {
51
- form.on('submit', function(submitEvent) {
52
- var emulated = form.fire('emulated:submit', submitEvent, true)
53
- // if custom event received preventDefault, cancel the real one too
54
- if (emulated.returnValue === false) submitEvent.preventDefault()
55
- })
56
- form.store('emulated:submit', true)
57
- }
58
- })
59
- }
60
-
61
- if (!changeBubbles) {
62
- // discover form inputs on the page
63
- document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
64
- // special handler for real "change" events
65
- if (!input.retrieve('emulated:change')) {
66
- input.on('change', function(changeEvent) {
67
- input.fire('emulated:change', changeEvent, true)
68
- })
69
- input.store('emulated:change', true)
70
- }
71
- })
72
- }
73
-
74
- function handleRemote(element) {
75
- var method, url, params;
76
-
77
- var event = element.fire("ajax:before");
78
- if (event.stopped) return false;
79
-
80
- if (element.tagName.toLowerCase() === 'form') {
81
- method = element.readAttribute('method') || 'post';
82
- url = element.readAttribute('action');
83
- params = element.serialize();
84
- } else {
85
- method = element.readAttribute('data-method') || 'get';
86
- url = element.readAttribute('href');
87
- params = {};
88
- }
89
-
90
- new Ajax.Request(url, {
91
- method: method,
92
- parameters: params,
93
- evalScripts: true,
94
-
95
- onComplete: function(request) { element.fire("ajax:complete", request); },
96
- onSuccess: function(request) { element.fire("ajax:success", request); },
97
- onFailure: function(request) { element.fire("ajax:failure", request); }
98
- });
99
-
100
- element.fire("ajax:after");
101
- }
102
-
103
- function handleMethod(element) {
104
- var method = element.readAttribute('data-method'),
105
- url = element.readAttribute('href'),
106
- csrf_param = $$('meta[name=csrf-param]')[0],
107
- csrf_token = $$('meta[name=csrf-token]')[0];
108
-
109
- var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
110
- element.parentNode.insert(form);
111
-
112
- if (method !== 'post') {
113
- var field = new Element('input', { type: 'hidden', name: '_method', value: method });
114
- form.insert(field);
115
- }
116
-
117
- if (csrf_param) {
118
- var param = csrf_param.readAttribute('content'),
119
- token = csrf_token.readAttribute('content'),
120
- field = new Element('input', { type: 'hidden', name: param, value: token });
121
- form.insert(field);
122
- }
123
-
124
- form.submit();
125
- }
126
-
127
-
128
- document.on("click", "*[data-confirm]", function(event, element) {
129
- var message = element.readAttribute('data-confirm');
130
- if (!confirm(message)) event.stop();
131
- });
132
-
133
- document.on("click", "a[data-remote]", function(event, element) {
134
- if (event.stopped) return;
135
- handleRemote(element);
136
- event.stop();
137
- });
138
-
139
- document.on("click", "a[data-method]", function(event, element) {
140
- if (event.stopped) return;
141
- handleMethod(element);
142
- event.stop();
143
- });
144
-
145
- document.on("submit", function(event) {
146
- var element = event.findElement(),
147
- message = element.readAttribute('data-confirm');
148
- if (message && !confirm(message)) {
149
- event.stop();
150
- return false;
151
- }
152
-
153
- var inputs = element.select("input[type=submit][data-disable-with]");
154
- inputs.each(function(input) {
155
- input.disabled = true;
156
- input.writeAttribute('data-original-value', input.value);
157
- input.value = input.readAttribute('data-disable-with');
158
- });
159
-
160
- var element = event.findElement("form[data-remote]");
161
- if (element) {
162
- handleRemote(element);
163
- event.stop();
164
- }
165
- });
166
-
167
- document.on("ajax:after", "form", function(event, element) {
168
- var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
169
- inputs.each(function(input) {
170
- input.value = input.readAttribute('data-original-value');
171
- input.removeAttribute('data-original-value');
172
- input.disabled = false;
173
- });
174
- });
175
- })();
data/spec/grid_spec.rb DELETED
@@ -1,15 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Fancygrid::Grid do
4
- it "should get table name from model name" do
5
- grid = Fancygrid::Grid.new(:ticket)
6
- grid.record_table_name.should == "tickets"
7
- end
8
-
9
- it "should get table name from class constant" do
10
- grid = Fancygrid::Grid.new(:foo, Ticket)
11
- grid.record_table_name.should == "tickets"
12
- end
13
-
14
-
15
- end
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Navigation" do
4
- include Capybara
5
-
6
- it "should be a valid app" do
7
- ::Rails.application.should be_a(Dummy::Application)
8
- end
9
- end
@@ -1,358 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Fancygrid::QueryGenerator do
4
-
5
- def build_generator
6
- Fancygrid::QueryGenerator.new({
7
- :pagination => {
8
- :page => 5,
9
- :per_page => 10
10
- },
11
- :order => {
12
- :column => "users.name",
13
- :order => "asc"
14
- },
15
- :operator => :all,
16
- :conditions => {
17
- :table_name => {
18
- :a => { :operator => :equal, :value => "value_a" },
19
- :b => { :operator => :not_equal, :value => "value_b" }
20
- }
21
- }
22
- })
23
- end
24
-
25
- def build_generator_with_array
26
- Fancygrid::QueryGenerator.new({
27
- :pagination => {
28
- :page => 5,
29
- :per_page => 10
30
- },
31
- :order => {
32
- :column => "users.name",
33
- :order => "asc"
34
- },
35
- :operator => :all,
36
- :conditions => {
37
- :table_name => {
38
- :a => [
39
- { :operator => :equal, :value => "value_a" },
40
- { :operator => :equal, :value => "value_a2" }
41
- ],
42
- :b => { :operator => :not_equal, :value => "value_b" }
43
- }
44
- }
45
- })
46
- end
47
-
48
- def build_generator_with_pseudo_array
49
- Fancygrid::QueryGenerator.new({
50
- :pagination => {
51
- :page => 5,
52
- :per_page => 10
53
- },
54
- :order => {
55
- :column => "users.name",
56
- :order => "asc"
57
- },
58
- :operator => :all,
59
- :conditions => {
60
- :table_name => {
61
- :a => {
62
- "0" => { :operator => :equal, :value => "value_a" },
63
- "1" => { :operator => :equal, :value => "value_a2" },
64
- },
65
- :b => { :operator => :not_equal, :value => "value_b" }
66
- }
67
- }
68
- })
69
- end
70
-
71
- it "should be an instance of Fancygrid::Query" do
72
- generator = build_generator
73
- generator.should be_an_instance_of Fancygrid::QueryGenerator
74
- end
75
-
76
- it "should initialize with a valid limit" do
77
- build_generator.limit.should be(10)
78
- end
79
-
80
- it "should initialize with a valid offset" do
81
- build_generator.offset.should be(50)
82
- end
83
-
84
- it "should initialize with a valid order" do
85
- build_generator.order.should == "users.name ASC"
86
- end
87
-
88
- it "should initialize with valid conditions" do
89
- build_generator.conditions.should == ["( table_name.a = (?) ) AND ( table_name.b != (?) )", "value_a", "value_b"]
90
- end
91
-
92
- it "should append conditions" do
93
- generator = build_generator
94
- generator.conditions(["roles.name = ?", "foo"])
95
- generator.conditions.should == ["(( table_name.a = (?) ) AND ( table_name.b != (?) )) AND (roles.name = ?)", "value_a", "value_b", "foo"]
96
- end
97
-
98
- it "should override order" do
99
- generator = build_generator
100
- generator.order("order")
101
- generator.order.should == "order"
102
- end
103
-
104
- it "should override group" do
105
- generator = build_generator
106
- generator.group("group")
107
- generator.group.should == "group"
108
- end
109
-
110
- it "should override having" do
111
- generator = build_generator
112
- generator.having("having")
113
- generator.having.should == "having"
114
- end
115
-
116
- it "should override limit" do
117
- generator = build_generator
118
- generator.limit("limit")
119
- generator.limit.should == "limit"
120
- end
121
-
122
- it "should override offset" do
123
- generator = build_generator
124
- generator.offset("offset")
125
- generator.offset.should == "offset"
126
- end
127
-
128
- it "should override joins" do
129
- generator = build_generator
130
- generator.joins("joins")
131
- generator.joins.should == "joins"
132
- end
133
-
134
- it "should override include" do
135
- generator = build_generator
136
- generator.include("include")
137
- generator.include.should == "include"
138
- end
139
-
140
- it "should append select" do
141
- generator = build_generator
142
- generator.select("select")
143
- generator.select.should == ["select"]
144
- end
145
-
146
- it "should override and keep select with star '*'" do
147
- generator = build_generator
148
- generator.select("select")
149
- generator.select.should == ["select"]
150
- generator.select("*")
151
- generator.select.should == ["*"]
152
- generator.select("select")
153
- generator.select.should == ["*"]
154
- end
155
-
156
- it "should override from" do
157
- generator = build_generator
158
- generator.from("from")
159
- generator.from.should == "from"
160
- end
161
-
162
- it "should override readonly" do
163
- generator = build_generator
164
- generator.readonly("readonly")
165
- generator.readonly.should == "readonly"
166
- end
167
-
168
- it "should override lock" do
169
- generator = build_generator
170
- generator.lock("lock")
171
- generator.lock.should == "lock"
172
- end
173
-
174
- it "should be backward compatible with old fancygrid" do
175
- query = Fancygrid::QueryGenerator.new({
176
- :pagination => {
177
- :page => 5,
178
- :per_page => 10
179
- },
180
- :order => {
181
- :column => "users.name",
182
- :order => "asc"
183
- },
184
- :operator => :all,
185
- :conditions => {
186
- :events => {
187
- :name => "a",
188
- :id => "b"
189
- }
190
- }
191
- })
192
- query.conditions.should == ["( events.name LIKE (?) ) AND ( events.id LIKE (?) )", "%a%", "%b%"]
193
- end
194
-
195
- it "should generate query using array" do
196
- build_generator_with_array.conditions.should == ["( table_name.a = (?) ) AND ( table_name.a = (?) ) AND ( table_name.b != (?) )", "value_a", "value_a2", "value_b"]
197
- end
198
-
199
- it "should generate query using pseudo array" do
200
- build_generator_with_pseudo_array.conditions.should == ["( table_name.a = (?) ) AND ( table_name.a = (?) ) AND ( table_name.b != (?) )", "value_a", "value_a2", "value_b"]
201
- end
202
-
203
- #it "should evaluate" do
204
- # @query = {
205
- # :conditions => {
206
- # :tickets => {
207
- # :title => {
208
- # :operator => "is_equal_to",
209
- # :value => "a string"
210
- # }
211
- # },
212
- # :projects => {
213
- # :title => {
214
- # :operator => "is_equal_to",
215
- # :value => "a string"
216
- # }
217
- # }
218
- # },
219
- # :order => 'projects.title ASC',
220
- # :pagination => {
221
- # :page => 1,
222
- # :per_page => 5
223
- # }
224
- # }
225
- # @generator = Fancygrid::QueryGenerator.new
226
- # @generator.evaluate(@query).should be_a(Hash)
227
- #end
228
- #
229
- #
230
- #describe "evaluating select" do
231
- # before(:each) do
232
- # leafs = [stub(:select_name => 'tickets.title'), stub(:select_name => 'projects.title')]
233
- # defaults = {
234
- # :select => leafs.map{|l| l.select_name}
235
- # }
236
- # @generator = Fancygrid::QueryGenerator.new(defaults)
237
- # end
238
- #
239
- # it "should evaluate" do
240
- # @generator.evaluate[:select].should == ["tickets.title", "projects.title"]
241
- # end
242
- #
243
- # describe "overriding select" do
244
- # it "should evaluate to * overriding with *" do
245
- # @generator.evaluate(:select => "*")[:select].should == "*"
246
- # end
247
- #
248
- # it "should evaluate with selects" do
249
- # @generator.evaluate(:select => "tickets.price")[:select].should == ["tickets.price", "tickets.title", "projects.title"]
250
- # end
251
- # end
252
- #end
253
- #
254
- #describe "evaluating where" do
255
- # before(:each) do
256
- # @query = {
257
- # :conditions => {
258
- # :tickets => {
259
- # :title => {
260
- # :operator => "is_equal_to",
261
- # :value => "a string"
262
- # }
263
- # }
264
- # }
265
- # }
266
- # @generator = Fancygrid::QueryGenerator.new
267
- # end
268
- #
269
- # it "should evaluate new conditions syntax" do
270
- # @generator.evaluate(@query)[:conditions].should == ["tickets.title = ?", "a string"]
271
- # end
272
- #
273
- # it "should evaluate old conditions syntax" do
274
- # query = {
275
- # :conditions => {
276
- # :tickets => {
277
- # :title => "a string"
278
- # }
279
- # }
280
- # }
281
- # @generator.evaluate(query)[:conditions].should == ["tickets.title LIKE ?", "%a string%"]
282
- # end
283
- #
284
- # it "should append default conditions with params conditions" do
285
- # defaults = {:conditions => ['tickets.open = ?', 1]}
286
- # @generator = Fancygrid::QueryGenerator.new(defaults)
287
- # @generator.evaluate(@query)[:conditions].should == ["(tickets.open = ?) AND (tickets.title = ?)", 1, "a string"]
288
- # end
289
- #
290
- # it "should join conditions with OR by default" do
291
- # new_condition = {
292
- # :projects => {
293
- # :title => {
294
- # :operator => "is_equal_to",
295
- # :value => "a project"
296
- # }
297
- # }
298
- # }
299
- # @query[:conditions].merge!(new_condition)
300
- # @generator.evaluate(@query)[:conditions].should == ["projects.title = ? OR tickets.title = ?", "a project", "a string"]
301
- # end
302
- #
303
- # it "should join conditions with AND" do
304
- # new_condition = {
305
- # :projects => {
306
- # :title => {
307
- # :operator => "is_equal_to",
308
- # :value => "a project"
309
- # }
310
- # }
311
- # }
312
- # @query[:conditions].merge!(new_condition)
313
- # @query[:all] = "1"
314
- # @generator.evaluate(@query)[:conditions].should == ["projects.title = ? AND tickets.title = ?", "a project", "a string"]
315
- # end
316
- #end
317
- #
318
- #describe "evaluating pagination" do
319
- # before(:each) do
320
- # @query = {
321
- # :pagination => {
322
- # :page => 2, # pages starts by 0
323
- # :per_page => 5
324
- # }
325
- # }
326
- # @generator = Fancygrid::QueryGenerator.new
327
- # end
328
- #
329
- # it "should evaluate limit" do
330
- # @generator.evaluate(@query)[:limit].should == 5
331
- # end
332
- # it "should evaluate offset" do
333
- # @generator.evaluate(@query)[:offset].should == 10
334
- # end
335
- #end
336
- #
337
- #describe "evaluation order" do
338
- # before(:each) do
339
- # defaults = {
340
- # :order => "title DESC"
341
- # }
342
- # @generator = Fancygrid::QueryGenerator.new(defaults)
343
- # end
344
- #
345
- # it "should evaluate order" do
346
- # @generator.evaluate[:order].should == "title DESC"
347
- # end
348
- #
349
- # describe "overriding order" do
350
- # it "should override order" do
351
- # query = {
352
- # :order => 'title ASC'
353
- # }
354
- # @generator.evaluate(query)[:order].should == "title ASC"
355
- # end
356
- # end
357
- #end
358
- end