jqgrid_rails 1.2.3 → 1.2.4

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.
@@ -1,3 +1,6 @@
1
+ == v1.2.4
2
+ * Add Registry/Structure support (thanks {Chris Kuttruff}[https://github.com/ckuttruff])
3
+
1
4
  == v1.2.3
2
5
  * Add more parameter grabbing for excel generation
3
6
 
@@ -47,6 +47,7 @@ jqgrid_rails was originally created by {Nick Ewing}[http://github.com/nickewing]
47
47
 
48
48
  * {Nick Ewing}[http://github.com/nickewing]
49
49
  * {David Cato}[http://github.com/davec]
50
+ * {Christopher Kuttruff}[http://github.com/ckuttruff]
50
51
  * {Ryan Golec}[http://github.com/ryangolec]
51
52
 
52
53
  == Resources
@@ -119,3 +119,74 @@ The first parameter is what we are actually querying against. For simple tables
119
119
  end
120
120
  end
121
121
  end
122
+
123
+ === Registry/Structure
124
+
125
+ As a convenient structure to contain and generate grids with sensible (and
126
+ easily customizable) default options, JqGridRails provides registry and
127
+ structure modules that aid in storage grid creation.
128
+
129
+ Within the model that you want to associate the registry, provide the following...
130
+
131
+ # app/models/grid_model.rb
132
+
133
+ class GridModel < ActiveRecord::Base
134
+ include JqGridRails::StructureRegistry
135
+ self.register_grid(:index_grid)
136
+ end
137
+
138
+ This will create a slot for a JqGridRails::Structure object that can be retrieved
139
+ later with GridModel.get_grid(:index_grid)
140
+
141
+ # app/controllers/grids_controller.rb
142
+ class GridsController < ApplicationController
143
+
144
+ def index
145
+ structure = GridModel.get_grid(:index_grid)
146
+
147
+ # columns
148
+ structure.add_column('Label', 'unique_field_id', { :columns => { :hidden => true }, :response => {} })
149
+ structure.add_scope(GridModel.scoped)
150
+
151
+ respond_to do |format|
152
+ @grid = gs.create_grid( { :sortname => "unique_field_id", :sortorder => "asc" } )
153
+
154
+ format.html
155
+ format.json { render :json => grid_response(structure.scope, params, structure.response) }
156
+ end
157
+ end
158
+
159
+ JqGridRails::Structure#add_column is very similar to JqGrid#add_column... the :columns
160
+ key corresponds to the third argument of JqGrid#add_column and accepts all the
161
+ same options. The :response key is used to pass on options to the grid_response
162
+ (see "Populating the grid" above).
163
+
164
+ These options along with the #add_scope provide all the necessary information to
165
+ create the grid. The #create_grid method accepts an optional argument (see
166
+ "Options Hash" above) that is merged into a hash of reasonable default options.
167
+
168
+ The advantage of this registry structure, besides the convenience that it
169
+ provides, is that it gives greater flexibility regarding where grids can be
170
+ constructed. A good use case for this would involve adding columns in a model
171
+ extension.
172
+
173
+ # lib/extensions/models/grid_model_extension.rb
174
+ # (this would be from a rails application using the above model, etc as an engine)
175
+ require_dependency 'grid_model'
176
+
177
+ GridModel.class_eval do
178
+
179
+ has_one :foo_join_table, :dependent => :destroy
180
+ has_one :foo, :through => :foo_join_table
181
+
182
+ # Add nifty_association to grid_model index grid
183
+
184
+ grid = GridModel.get_grid(:index_grid)
185
+ grid.add_scope(GridModel.include(:foo).select("foos.name AS foo_name"))
186
+ grid.add_column('Foo', 'foo_name',
187
+ :response => {
188
+ :where => 'foos.name',
189
+ :order => 'foo_name'
190
+ }
191
+ )
192
+ end
@@ -0,0 +1,91 @@
1
+ module JqGridRails
2
+ # GridStructure acts as a container for the various jqgrid_rails elements. It is used to store
3
+ # the grid's scopes, column data, and response options. These elements can then be used to
4
+ # generate the ultimate, grid, response and scope meant to be used in the controller
5
+ class Structure
6
+ # base_class:: name of model containing GridStructure (used to generate some grid defaults)
7
+ # grid_name:: used to identify grid (convention is action_name_grid; eg: index_grid)
8
+ def initialize(base_class, grid_name)
9
+ @grid_name = grid_name
10
+ @base_class = base_class
11
+ @columns = []
12
+ @scopes = []
13
+ @response = {}
14
+ end
15
+
16
+ # Get scope (1st arg of grid_response) by merging @scopes together (first added is the base)
17
+ def scope
18
+ scope = @scopes.first
19
+ last_index = @scopes.length - 1
20
+ 1.upto(last_index) { |i| scope = scope.merge(@scopes[i]) }
21
+ scope
22
+ end
23
+
24
+ # Returns response for grid (last argument in json grid_response call)
25
+ def response
26
+ @response
27
+ end
28
+
29
+ # Adds column info for later grid creation; arguments accepted are similar to Grid#add_column
30
+ # Only adds column if the unique key (field_name) does not exist in the response hash
31
+ # label:: label for grid column
32
+ # field_name:: used during the grid response
33
+ # opts:: hash containing :columns and :response keys to specify these options for column
34
+ def add_column(label, field_name, opts = {})
35
+ unless(@response.has_key?(field_name))
36
+ @columns << { :label => label, :field_name => field_name, :column_opts => (opts[:columns] || {}) }
37
+ @response[field_name] = opts[:response]
38
+ end
39
+ end
40
+
41
+ # Remove grid element from columns and response based on field_name
42
+ # field_name:: element to delete from columns and response
43
+ def remove_column(field_name)
44
+ @columns.delete_if { |col_hash| col_hash[:field_name] == field_name }
45
+ @response.delete(field_name)
46
+ end
47
+
48
+ # Adds scope to be used in grid response
49
+ # scope:: scope to be merged with the rest in the array (array acts as a queue)
50
+ # location:: optional location of scope (:first or :last (:last is default))
51
+ def add_scope(scope, location = :last)
52
+ insert_location = (location.to_sym == :first)? 0 : -1
53
+ @scopes.insert(insert_location, scope)
54
+ end
55
+
56
+ # Generates grid that will be used in controller
57
+ # custom_grid_options:: hash that will be added to default options for grid
58
+ def create_grid(custom_grid_options = {})
59
+ grid = JqGridRails::JqGrid.new(@grid_name, default_options(custom_grid_options))
60
+ @columns.each { |c| grid.add_column(c[:label], c[:field_name], c[:column_opts]) }
61
+ grid
62
+ end
63
+
64
+ # Main grid options (last arg or Grid#new); contains reasonable defaults that may be overriden
65
+ # options:: custom options to override any defaults or to add other options not specified
66
+ def default_options(options = {})
67
+ tbl = @base_class.table_name
68
+ { :caption => "#{@base_class.to_s.pluralize} List",
69
+ :url => "/#{tbl}/",
70
+ :ondbl_click_row => { :url => "#{tbl.singularize}_path".to_sym},
71
+ :link_toolbar => true,
72
+ :filter_toolbar => true,
73
+
74
+ :sortname => "#{tbl}.id",
75
+ :sortorder => "desc",
76
+
77
+ :height => '100%',
78
+ :width => '100%',
79
+ :autowidth => true,
80
+ :ignore_case => true,
81
+
82
+ :row_id => :id,
83
+ :row_num => 50,
84
+ :pager => true,
85
+ :multiselect => true }.merge(options)
86
+ end
87
+
88
+ end
89
+ end
90
+
91
+
@@ -0,0 +1,28 @@
1
+ require 'jqgrid_rails/jqgrid_rails_structure'
2
+
3
+ module JqGridRails
4
+ # JqGridStructureRegistry is a module that, once included, adds some class methods to enable
5
+ # registering and fetching of grid structures by the grid's name
6
+ # see examples/usage.rb file for more details
7
+ module StructureRegistry
8
+
9
+ def self.included(base)
10
+ base.extend(ClassMethods)
11
+ end
12
+
13
+ module ClassMethods
14
+ # Creates a new GridStructure object and stores it in a slot with grid_name as key
15
+ # grid_name:: grid name symbol (first arg of JqGrid.new(...))
16
+ def register_grid(grid_name)
17
+ @grids ||= {}
18
+ @grids[grid_name.to_sym] = JqGridRails::Structure.new(self, grid_name)
19
+ end
20
+
21
+ # Fetches grid from grid_name symbol
22
+ def get_grid(grid_name)
23
+ @grids[grid_name.to_sym]
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -13,5 +13,5 @@ module JqGridRails
13
13
  end
14
14
  end
15
15
 
16
- VERSION = Version.new('1.2.3')
16
+ VERSION = Version.new('1.2.4')
17
17
  end
metadata CHANGED
@@ -1,124 +1,98 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: jqgrid_rails
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.4
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 2
9
- - 3
10
- version: 1.2.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Chris Roberts
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-03-02 00:00:00 -08:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-04-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rails_javascript_helpers
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &20892840 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 1
32
- - 4
33
- version: "1.4"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.4'
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rails
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *20892840
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &20891880 !ruby/object:Gem::Requirement
40
28
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 5
45
- segments:
46
- - 2
47
- - 3
48
- version: "2.3"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '2.3'
49
33
  type: :runtime
50
- version_requirements: *id002
34
+ prerelease: false
35
+ version_requirements: *20891880
51
36
  description: jqGrid for Rails
52
37
  email: chrisroberts.code@gmail.com
53
38
  executables: []
54
-
55
39
  extensions: []
56
-
57
- extra_rdoc_files:
40
+ extra_rdoc_files:
58
41
  - README.rdoc
59
42
  - LICENSE.rdoc
60
43
  - CHANGELOG.rdoc
61
- files:
62
- - init.rb
63
- - jqgrid_rails.gemspec
64
- - jqgrid_rails-1.2.2.gem
44
+ files:
65
45
  - LICENSE.rdoc
46
+ - examples/usage.rdoc
47
+ - examples/quick_ref.rdoc
48
+ - jqgrid_rails.gemspec
49
+ - CHANGELOG.rdoc
50
+ - init.rb
66
51
  - README.rdoc
67
- - lib/jqgrid_rails/railtie.rb
68
- - lib/jqgrid_rails/jqgrid_rails_writeexcel.rb
69
- - lib/jqgrid_rails/jqgrid_rails_view.rb
52
+ - rails/init.rb
70
53
  - lib/jqgrid_rails/jqgrid_rails_controller.rb
71
- - lib/jqgrid_rails/tasks.rb
72
54
  - lib/jqgrid_rails/jqgrid_rails_helper.rb
73
- - lib/jqgrid_rails/jqgrid.rb
74
- - lib/jqgrid_rails/escape_mappings.rb
75
- - lib/jqgrid_rails/jqgrid_rails_helpers.rb
76
- - lib/jqgrid_rails/version.rb
77
55
  - lib/jqgrid_rails/jqgrid_rails_generators.rb
56
+ - lib/jqgrid_rails/version.rb
57
+ - lib/jqgrid_rails/tasks.rb
58
+ - lib/jqgrid_rails/jqgrid_rails_helpers.rb
59
+ - lib/jqgrid_rails/jqgrid_rails_structure_registry.rb
60
+ - lib/jqgrid_rails/railtie.rb
61
+ - lib/jqgrid_rails/jqgrid_rails_view.rb
78
62
  - lib/jqgrid_rails/jqgrid_url_generator.rb
63
+ - lib/jqgrid_rails/jqgrid_rails_structure.rb
64
+ - lib/jqgrid_rails/jqgrid.rb
65
+ - lib/jqgrid_rails/escape_mappings.rb
66
+ - lib/jqgrid_rails/jqgrid_rails_writeexcel.rb
79
67
  - lib/jqgrid_rails.rb
80
68
  - files/stylesheets/jqgrid/ui.jqgrid.css
81
69
  - files/stylesheets/jqgrid/ellipsis-xbl.xml
82
- - files/javascripts/jqgrid/grid.locale-en.js
83
70
  - files/javascripts/jqgrid/README.md
71
+ - files/javascripts/jqgrid/grid.locale-en.js
84
72
  - files/javascripts/jqgrid/jquery.jqGrid.min.js
85
- - examples/quick_ref.rdoc
86
- - examples/usage.rdoc
87
- - rails/init.rb
88
- - CHANGELOG.rdoc
89
- has_rdoc: true
90
73
  homepage: http://github.com/chrisroberts/jqgrid_rails
91
74
  licenses: []
92
-
93
75
  post_install_message:
94
76
  rdoc_options: []
95
-
96
- require_paths:
77
+ require_paths:
97
78
  - lib
98
- required_ruby_version: !ruby/object:Gem::Requirement
79
+ required_ruby_version: !ruby/object:Gem::Requirement
99
80
  none: false
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- hash: 3
104
- segments:
105
- - 0
106
- version: "0"
107
- required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
86
  none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- hash: 3
113
- segments:
114
- - 0
115
- version: "0"
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
116
91
  requirements: []
117
-
118
92
  rubyforge_project:
119
- rubygems_version: 1.4.2
93
+ rubygems_version: 1.8.17
120
94
  signing_key:
121
95
  specification_version: 3
122
96
  summary: jqGrid for Rails
123
97
  test_files: []
124
-
98
+ has_rdoc: true
Binary file