jqgrid_rails 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ == v1.2.1
2
+ * Auto select blank values in filter select boxes to combat Webkit ordering issues
3
+
1
4
  == v1.2.0
2
5
  * Forked to provide proper gem releases
3
6
  * Only load generator methods if appropriate
@@ -16,6 +16,8 @@ module JqGridRails
16
16
  attr_accessor :table_id
17
17
  # Options used for links toolbar
18
18
  attr_reader :link_toolbar_options
19
+ # Detached javascript
20
+ attr_reader :detached_javascript
19
21
 
20
22
 
21
23
  # table_id:: DOM ID of table for grid to use
@@ -49,6 +51,13 @@ module JqGridRails
49
51
  end
50
52
  @local = []
51
53
  @output = ''
54
+ @detached_javascript = []
55
+ end
56
+
57
+ # js:: Javascript string
58
+ # Adds javascript to run on document ready
59
+ def add_javascript(js)
60
+ @detached_javascript << js
52
61
  end
53
62
 
54
63
  # name:: Name of column (Invoice)
@@ -158,23 +167,35 @@ module JqGridRails
158
167
 
159
168
  # Resizes grid after loading has completed to prevent blowing out container
160
169
  def fix_grid_width
161
- js = "jQuery(#{convert_dom_id(@table_id)}).jqGrid('setGridWidth', jQuery(#{convert_dom_id(@table_id)} + '_holder').innerWidth(), true);"
162
- if(@options[:load_complete])
163
- @options[:load_complete] = RawJS.new(@options[:load_complete].to_s.sub(/^(\s*function.*?\{)/, "\\1#{js}"))
164
- else
165
- @options[:load_complete] = RawJS.new("function(){ #{js} return true; }")
166
- end
170
+ insert_into_callback(
171
+ :load_complete,
172
+ "jQuery(#{convert_dom_id(@table_id)}).jqGrid('setGridWidth', jQuery(#{convert_dom_id(@table_id)} + '_holder').innerWidth(), true);"
173
+ )
174
+ end
175
+
176
+ # Auto selects blank drop down option to combat Chrome/webkit's unordered hashing
177
+ def filter_toolbar_autoselect_blanks
178
+ add_javascript(
179
+ "jQuery(#{convert_dom_id(@table_id)} + '_holder')" <<
180
+ ".find('th[role=\"columnheader\"]')" <<
181
+ ".find('option[value=\"\"]').each(" <<
182
+ 'function(){' <<
183
+ "jQuery(this).attr('selected', true);" <<
184
+ '});'
185
+ )
167
186
  end
168
187
 
169
188
  # Builds out the jqGrid javascript and returns the string
170
189
  def build
171
190
  output = ''
172
191
  fix_grid_width
192
+ filter_toolbar_autoselect_blanks unless @options[:no_filter_toolbar_autoselect_blanks]
173
193
  @options[:datatype] = 'local' unless @local.blank?
174
194
  resizable = @options.delete(:resizable_grid)
175
195
  #############################################################
176
196
  load_multi_select_fix unless @options[:no_multi_select_fix] # TODO: Remove this when fixed in jqGrid
177
197
  #############################################################
198
+
178
199
  map_double_click
179
200
  map_single_click
180
201
  set_search_options
@@ -327,5 +348,16 @@ module JqGridRails
327
348
  }
328
349
  }).trigger('resize');"
329
350
  end
351
+
352
+ # key:: callback name
353
+ # js:: JS string
354
+ # Insert JS into callback leaving existing callback code intact
355
+ def insert_into_callback(key, js)
356
+ if(@options[key])
357
+ @options[key] = RawJS.new(@options[key].to_s.sub(/^(\s*function.*?\{)/, "\\1#{js}"))
358
+ else
359
+ @options[key] = RawJS.new("function(){ #{js} return true; }")
360
+ end
361
+ end
330
362
  end
331
363
  end
@@ -31,6 +31,9 @@ module JqGridRails
31
31
  def jq_grid(grid)
32
32
  output = jqgrid_html(grid)
33
33
  output << jqgrid_js(grid)
34
+ if grid.detached_javascript.present?
35
+ output << javascript_tag{ "jQuery(document).ready(function(){ #{grid.detached_javascript.join("\n")}});".html_safe }
36
+ end
34
37
  output.html_safe
35
38
  end
36
39
  alias_method :jqgrid, :jq_grid
@@ -13,5 +13,5 @@ module JqGridRails
13
13
  end
14
14
  end
15
15
 
16
- VERSION = Version.new('1.2.0')
16
+ VERSION = Version.new('1.2.1')
17
17
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jqgrid_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 0
10
- version: 1.2.0
9
+ - 1
10
+ version: 1.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Roberts
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-23 00:00:00 -08:00
18
+ date: 2012-02-29 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency