rails_jq_grid 0.0.2 → 0.0.3.pre1
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.
- data/README.rdoc +46 -6
- data/Rakefile +12 -1
- data/VERSION +1 -1
- data/app/helpers/rails_jq_grid/jq_grid_css_helper.rb +13 -2
- data/app/helpers/rails_jq_grid/jq_grid_helper.rb +10 -2
- data/app/helpers/rails_jq_grid/jq_grid_js_helper.rb +15 -2
- data/app/models/rails_jq_grid/jq_grid.rb +19 -57
- data/app/models/rails_jq_grid/jq_grid_column.rb +13 -12
- data/app/models/rails_jq_grid/jq_grid_method_missing.rb +26 -16
- data/app/models/rails_jq_grid/jq_grid_nav_grid.rb +133 -0
- data/app/models/rails_jq_grid/jq_grid_nav_grid_parameter.rb +31 -0
- data/app/models/rails_jq_grid/jq_grid_option_or_method.rb +17 -2
- data/lib/rails_jq_grid/acts_as_jq_grid_able.rb +29 -5
- data/lib/rails_jq_grid/engine.rb +11 -10
- data/lib/rails_jq_grid.rb +11 -2
- data/rails_jq_grid.gemspec +6 -4
- metadata +15 -11
- data/lib/rails_jq_grid/acts_as_jq_grid_data_source.rb +0 -34
data/README.rdoc
CHANGED
@@ -18,8 +18,8 @@ RAILS_ROOT\public\stylesheets\rails-jqgrid\themes
|
|
18
18
|
|
19
19
|
def action
|
20
20
|
...
|
21
|
-
|
22
|
-
@records =
|
21
|
+
relation = MyModel.order(order_by).limit(records_per_page).offset(current_offset)
|
22
|
+
@records = relation.all
|
23
23
|
|
24
24
|
respond_to do |format|
|
25
25
|
format.html { }
|
@@ -35,6 +35,14 @@ RAILS_ROOT\public\stylesheets\rails-jqgrid\themes
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
# or shorter
|
39
|
+
respond_to :html, :json
|
40
|
+
|
41
|
+
def action
|
42
|
+
...
|
43
|
+
respond_with(jqgrid_json(:data => @records))
|
44
|
+
end
|
45
|
+
|
38
46
|
=== View
|
39
47
|
<head>
|
40
48
|
...
|
@@ -59,6 +67,35 @@ RAILS_ROOT\public\stylesheets\rails-jqgrid\themes
|
|
59
67
|
|
60
68
|
a.on_select_row raw "function(){alert('test');}"
|
61
69
|
|
70
|
+
a.nav_grid do |n|
|
71
|
+
# Defaults
|
72
|
+
# n.add true
|
73
|
+
# n.del true
|
74
|
+
# n.edit true
|
75
|
+
# n.refresh true
|
76
|
+
# n.search true
|
77
|
+
|
78
|
+
n.prm_edit do |p|
|
79
|
+
p.close_after_edit false
|
80
|
+
end
|
81
|
+
|
82
|
+
n.prm_add do |p|
|
83
|
+
# set some options
|
84
|
+
end
|
85
|
+
|
86
|
+
n.prm_del do |p|
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
n.prm_search do |p|
|
91
|
+
end
|
92
|
+
|
93
|
+
n.prm_view do |p|
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
|
62
99
|
a.column "ean" do |c|
|
63
100
|
c.label "EAN"
|
64
101
|
c.autowidth true
|
@@ -98,7 +135,7 @@ RAILS_ROOT\public\stylesheets\rails-jqgrid\themes
|
|
98
135
|
|
99
136
|
end
|
100
137
|
|
101
|
-
a.jqgrid "
|
138
|
+
a.jqgrid "prices_detail", "prices_detail",
|
102
139
|
url_for(:controller => :prices ,
|
103
140
|
:action => "index"),
|
104
141
|
:caption_append_ids => true,
|
@@ -156,7 +193,9 @@ RAILS_ROOT\public\stylesheets\rails-jqgrid\themes
|
|
156
193
|
=== I18N
|
157
194
|
|
158
195
|
When a column doesn't set label then human_attribute_name is used for the fieldname
|
159
|
-
to guess the label.
|
196
|
+
to guess the label. This also applys to grid title.
|
197
|
+
|
198
|
+
To use I18N just setup your local and create a local file like:
|
160
199
|
|
161
200
|
-RAILS_ROOT
|
162
201
|
|-config
|
@@ -166,8 +205,9 @@ RAILS_ROOT\public\stylesheets\rails-jqgrid\themes
|
|
166
205
|
content for en.yml:
|
167
206
|
en:
|
168
207
|
attributes:
|
169
|
-
|
170
|
-
|
208
|
+
prices_detail: "Prices details table"
|
209
|
+
col1: "Label for col1"
|
210
|
+
col2: "Label for col2"
|
171
211
|
|
172
212
|
|
173
213
|
|
data/Rakefile
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
|
2
|
+
# This program is free software; you can redistribute it and/or
|
3
|
+
# modify it under the terms of the GNU General Public License
|
4
|
+
# as published by the Free Software Foundation; either version 3
|
5
|
+
# of the License, or (at your option) any later version.
|
6
|
+
|
7
|
+
# Author:: Dieter Spaeth (mailto:dieter.spaeth@gmx.de)
|
8
|
+
# Copyright:: Copyright (c) 2010 Dieter Spaeth
|
9
|
+
|
10
|
+
|
1
11
|
require 'rubygems'
|
2
12
|
require "rake"
|
3
13
|
require 'rake/testtask'
|
@@ -8,6 +18,7 @@ begin
|
|
8
18
|
Jeweler::Tasks.new do |gem|
|
9
19
|
gem.name = "rails_jq_grid"
|
10
20
|
gem.summary = "Add JqGrid to your Rails 3 app"
|
21
|
+
gem.description = "This gems is a Rails 3 Enginge that helps you to create jqGrid. It's bundled with jqGrid and some themes."
|
11
22
|
gem.email = "dieter.spaeth@gmx.de"
|
12
23
|
gem.authors = ["Dieter Spaeth"]
|
13
24
|
gem.homepage = "http://github.com/consu/rails-jqgrid"
|
@@ -43,5 +54,5 @@ Rake::RDocTask.new do |rdoc|
|
|
43
54
|
rdoc.rdoc_dir = 'rdoc'
|
44
55
|
rdoc.title = "ko #{version}"
|
45
56
|
rdoc.rdoc_files.include('README*')
|
46
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
rdoc.rdoc_files.include('lib/**/*.rb', 'app/**/*.rb')
|
47
58
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3.pre1
|
@@ -1,5 +1,11 @@
|
|
1
|
-
|
2
|
-
#
|
1
|
+
|
2
|
+
# This program is free software; you can redistribute it and/or
|
3
|
+
# modify it under the terms of the GNU General Public License
|
4
|
+
# as published by the Free Software Foundation; either version 3
|
5
|
+
# of the License, or (at your option) any later version.
|
6
|
+
|
7
|
+
# Author:: Dieter Spaeth (mailto:dieter.spaeth@gmx.de)
|
8
|
+
# Copyright:: Copyright (c) 2010 Dieter Spaeth
|
3
9
|
|
4
10
|
module RailsJqGrid
|
5
11
|
module JqGridCssHelper
|
@@ -7,12 +13,17 @@ module RailsJqGrid
|
|
7
13
|
JQUERY_UI_THEMES_BASE = STYLESHEETS_BASE + "/themes"
|
8
14
|
JQUERY_UI_VERSION = "1.8.4"
|
9
15
|
|
16
|
+
# Includes the following stylesheets:
|
17
|
+
# * ui.jqgrid.css
|
18
|
+
# * /stylesheets/rails-jqgrid/themes/[theme_name]/jquery-ui-...custom.css
|
19
|
+
# options:: :theme name of the theme folder, default start
|
10
20
|
def jqgrid_stylesheets_tags(options={})
|
11
21
|
[jqgrid_ui_stylesheet_tag(options),
|
12
22
|
jquery_ui_stylesheet_tag(options)
|
13
23
|
].join("\n").html_safe
|
14
24
|
end
|
15
25
|
|
26
|
+
protected
|
16
27
|
def jqgrid_ui_stylesheet_tag(options={})
|
17
28
|
(stylesheet_link_tag STYLESHEETS_BASE + "/ui.jqgrid.css").html_safe
|
18
29
|
end
|
@@ -1,5 +1,12 @@
|
|
1
|
-
|
2
|
-
#
|
1
|
+
|
2
|
+
# This program is free software; you can redistribute it and/or
|
3
|
+
# modify it under the terms of the GNU General Public License
|
4
|
+
# as published by the Free Software Foundation; either version 3
|
5
|
+
# of the License, or (at your option) any later version.
|
6
|
+
|
7
|
+
# Author:: Dieter Spaeth (mailto:dieter.spaeth@gmx.de)
|
8
|
+
# Copyright:: Copyright (c) 2010 Dieter Spaeth
|
9
|
+
|
3
10
|
|
4
11
|
require 'rails_jq_grid/jq_grid'
|
5
12
|
|
@@ -9,6 +16,7 @@ module RailsJqGrid
|
|
9
16
|
include JqGridJsHelper
|
10
17
|
include JqGridCssHelper
|
11
18
|
|
19
|
+
# Creates javascript-code for jqGrid
|
12
20
|
def jqgrid(title, dom_id, url_for_options, options={}, &option_block)
|
13
21
|
if url_for_options.is_a?(Hash)
|
14
22
|
url_for_options[:controller]||=controller.controller_name
|
@@ -1,11 +1,23 @@
|
|
1
|
-
|
2
|
-
#
|
1
|
+
|
2
|
+
# This program is free software; you can redistribute it and/or
|
3
|
+
# modify it under the terms of the GNU General Public License
|
4
|
+
# as published by the Free Software Foundation; either version 3
|
5
|
+
# of the License, or (at your option) any later version.
|
6
|
+
|
7
|
+
# Author:: Dieter Spaeth (mailto:dieter.spaeth@gmx.de)
|
8
|
+
# Copyright:: Copyright (c) 2010 Dieter Spaeth
|
9
|
+
|
3
10
|
|
4
11
|
module RailsJqGrid
|
5
12
|
module JqGridJsHelper
|
6
13
|
JS_BASE = "/javascripts/rails-jqgrid"
|
7
14
|
JQUERY_VERSION = "1.4.2"
|
8
15
|
|
16
|
+
# Includes the following javascript libraries:
|
17
|
+
# * jquery-...min.js
|
18
|
+
# * jquery.jqGrid.min.js
|
19
|
+
# * grid.locale-...js
|
20
|
+
# options:: :local local to use, default :en
|
9
21
|
def jqgrid_js_tags(options={})
|
10
22
|
[jquery_js_tag,
|
11
23
|
jqgrid_i18n_js_tag(options),
|
@@ -13,6 +25,7 @@ module RailsJqGrid
|
|
13
25
|
].join("\n").html_safe
|
14
26
|
end
|
15
27
|
|
28
|
+
protected
|
16
29
|
def jquery_js_tag
|
17
30
|
(javascript_include_tag JS_BASE + "/jquery-#{JQUERY_VERSION}.min.js").html_safe
|
18
31
|
end
|
@@ -1,5 +1,11 @@
|
|
1
|
-
|
2
|
-
#
|
1
|
+
|
2
|
+
# This program is free software; you can redistribute it and/or
|
3
|
+
# modify it under the terms of the GNU General Public License
|
4
|
+
# as published by the Free Software Foundation; either version 3
|
5
|
+
# of the License, or (at your option) any later version.
|
6
|
+
|
7
|
+
# Author:: Dieter Spaeth (mailto:dieter.spaeth@gmx.de)
|
8
|
+
# Copyright:: Copyright (c) 2010 Dieter Spaeth
|
3
9
|
|
4
10
|
module RailsJqGrid
|
5
11
|
class JqGrid
|
@@ -12,7 +18,7 @@ module RailsJqGrid
|
|
12
18
|
include JqGridMethodMissing
|
13
19
|
|
14
20
|
attr_accessor :title, :dom_id, :columns_data, :detail_grids, :sub_grid_data,
|
15
|
-
:proc_binding, :options
|
21
|
+
:proc_binding, :options, :nav_grid_data
|
16
22
|
|
17
23
|
DEFAULT_OPTIONS = {:row_num => '10',
|
18
24
|
:row_list => [10,25,50,100],
|
@@ -53,6 +59,8 @@ module RailsJqGrid
|
|
53
59
|
self.proc_binding = option_block.binding
|
54
60
|
self.options = options
|
55
61
|
|
62
|
+
self.nav_grid_data = JqGridNavGrid.new(dom_id, pager_id)
|
63
|
+
|
56
64
|
#fancier syntax, but heavier to handle
|
57
65
|
#self.instance_eval(&option_block) if block_given?
|
58
66
|
|
@@ -102,7 +110,7 @@ module RailsJqGrid
|
|
102
110
|
end
|
103
111
|
|
104
112
|
def column(field,&block)
|
105
|
-
find_or_create_column(field).
|
113
|
+
find_or_create_column(field).set_jqgrid_options(&block)
|
106
114
|
end
|
107
115
|
|
108
116
|
def find_or_create_column(field)
|
@@ -114,6 +122,10 @@ module RailsJqGrid
|
|
114
122
|
col
|
115
123
|
end
|
116
124
|
|
125
|
+
def nav_grid(&block)
|
126
|
+
self.nav_grid_data.set_jqgrid_options(&block)
|
127
|
+
end
|
128
|
+
|
117
129
|
def to_html
|
118
130
|
parts =[]
|
119
131
|
parts << javascript_tag(jq_grid_function_js)
|
@@ -171,64 +183,14 @@ module RailsJqGrid
|
|
171
183
|
end
|
172
184
|
|
173
185
|
def nav_grid_js
|
174
|
-
|
175
|
-
params.push(nav_grid_restful_extensions).flatten! if is_restful?
|
186
|
+
self.nav_grid_data.restfull = is_restful?
|
176
187
|
|
177
|
-
|
178
|
-
jQuery("##{dom_id}").jqGrid('navGrid','##{pager_id}',#{params.join(",\n")} );
|
179
|
-
EO_JS
|
188
|
+
nav_grid_data.to_js
|
180
189
|
end
|
181
190
|
|
182
191
|
def is_restful?
|
183
192
|
self.options[:restful]
|
184
|
-
end
|
185
|
-
|
186
|
-
def nav_grid_parameters
|
187
|
-
<<-EO_JS
|
188
|
-
{edit:#{jq_grid_js_options[:edit]},
|
189
|
-
add:#{jq_grid_js_options[:add]},
|
190
|
-
del:#{jq_grid_js_options[:delete]},
|
191
|
-
search:#{jq_grid_js_options[:search]},
|
192
|
-
refresh:#{jq_grid_js_options[:refresh]}
|
193
|
-
}
|
194
|
-
EO_JS
|
195
|
-
end
|
196
|
-
|
197
|
-
def nav_grid_restful_extensions
|
198
|
-
#url = articles_path
|
199
|
-
[restful_param_edit, restful_param_add, restful_param_delete]
|
200
|
-
end
|
201
|
-
|
202
|
-
def restful_param_edit
|
203
|
-
<<-EO_JS
|
204
|
-
{ mtype: "PUT",
|
205
|
-
onclickSubmit: function(rp_ge, postdata) {
|
206
|
-
selrow = jQuery("##{dom_id}").jqGrid('getGridParam','selrow');
|
207
|
-
if (selrow!=null){
|
208
|
-
rp_ge.url = jQuery("##{dom_id}").jqGrid('getGridParam','editurl') + '/' + selrow;
|
209
|
-
}
|
210
|
-
return {};
|
211
|
-
}
|
212
|
-
}
|
213
|
-
EO_JS
|
214
|
-
end
|
215
|
-
|
216
|
-
def restful_param_add
|
217
|
-
<<-EO_JS
|
218
|
-
{ mtype: "POST" }
|
219
|
-
EO_JS
|
220
|
-
end
|
221
|
-
|
222
|
-
def restful_param_delete
|
223
|
-
<<-EO_JS
|
224
|
-
{ mtype: "DELETE",
|
225
|
-
onclickSubmit: function(rp_ge, postdata) {
|
226
|
-
rp_ge.url = jQuery("##{dom_id}").jqGrid('getGridParam','editurl') + '/' + postdata
|
227
|
-
return {};
|
228
|
-
}
|
229
|
-
}
|
230
|
-
EO_JS
|
231
|
-
end
|
193
|
+
end
|
232
194
|
|
233
195
|
def detail_grids_html
|
234
196
|
self.detail_grids.map do |detail_grid|
|
@@ -1,7 +1,15 @@
|
|
1
|
-
|
2
|
-
#
|
1
|
+
|
2
|
+
# This program is free software; you can redistribute it and/or
|
3
|
+
# modify it under the terms of the GNU General Public License
|
4
|
+
# as published by the Free Software Foundation; either version 3
|
5
|
+
# of the License, or (at your option) any later version.
|
6
|
+
|
7
|
+
# Author:: Dieter Spaeth (mailto:dieter.spaeth@gmx.de)
|
8
|
+
# Copyright:: Copyright (c) 2010 Dieter Spaeth
|
9
|
+
|
3
10
|
|
4
11
|
module RailsJqGrid
|
12
|
+
# Container for all options and methods for a column in jqgrid
|
5
13
|
class JqGridColumn
|
6
14
|
extend ActiveModel::Translation
|
7
15
|
|
@@ -13,17 +21,10 @@ module RailsJqGrid
|
|
13
21
|
self.field = field
|
14
22
|
self.init_jq_grid_js_options "name" => field, "index" => field
|
15
23
|
|
16
|
-
self.label JqGridColumn.human_attribute_name(field)
|
17
|
-
|
18
|
-
#fancier syntax, but heavier to handle
|
19
|
-
#self.instance_eval(&option_block) if block_given?
|
20
|
-
|
21
|
-
set_column_options(&option_block)
|
22
|
-
end
|
24
|
+
self.label JqGridColumn.human_attribute_name(field)
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
end
|
26
|
+
set_jqgrid_options(&option_block)
|
27
|
+
end
|
27
28
|
|
28
29
|
def name
|
29
30
|
self.jq_grid_js_options[:label]
|
@@ -1,36 +1,41 @@
|
|
1
|
-
|
2
|
-
#
|
1
|
+
|
2
|
+
# This program is free software; you can redistribute it and/or
|
3
|
+
# modify it under the terms of the GNU General Public License
|
4
|
+
# as published by the Free Software Foundation; either version 3
|
5
|
+
# of the License, or (at your option) any later version.
|
6
|
+
|
7
|
+
# Author:: Dieter Spaeth (mailto:dieter.spaeth@gmx.de)
|
8
|
+
# Copyright:: Copyright (c) 2010 Dieter Spaeth
|
9
|
+
|
3
10
|
|
4
11
|
module RailsJqGrid
|
12
|
+
|
13
|
+
# Method-Missing implementation
|
14
|
+
# converts unknown method to options
|
15
|
+
# and save it's values
|
5
16
|
module JqGridMethodMissing
|
6
17
|
attr_accessor :jq_grid_js_options
|
7
18
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
# call_parent symbol, *args, &block
|
12
|
-
#else
|
13
|
-
# RAILS_DEFAULT_LOGGER.debug "Method Missing #{symbol} #{args.inspect}"
|
19
|
+
# every unknown method is treated as a jqgrid
|
20
|
+
# option oder method name
|
21
|
+
def method_missing(symbol, *args, &block)
|
14
22
|
self.jq_grid_js_options ||={}
|
15
23
|
self.jq_grid_js_options[symbol] = JqGridOptionOrMethod.new(symbol, args[0])
|
16
24
|
#end
|
17
|
-
end
|
18
|
-
|
19
|
-
# def call_parent(*args)
|
20
|
-
# # Dirty Hack to get url_for to work
|
21
|
-
# # when called from a detail jqgrid in a block
|
22
|
-
# parent_context = eval('self', self.proc_binding)
|
23
|
-
# parent_context.send *args
|
24
|
-
# end
|
25
|
+
end
|
25
26
|
|
27
|
+
# Values market with raw are not convertet to_json
|
28
|
+
# they will be outputet as they are see JqGridOptionOrMethod.escaped_value
|
26
29
|
def raw(*args)
|
27
30
|
{:type => :raw, :value => args[0]}
|
28
31
|
end
|
29
32
|
|
33
|
+
# returns the value of a option
|
30
34
|
def get_jq_grid_js_options(symbol)
|
31
35
|
self.jq_grid_js_options[symbol]
|
32
36
|
end
|
33
37
|
|
38
|
+
# initialize options with default values
|
34
39
|
def init_jq_grid_js_options(new_options)
|
35
40
|
self.jq_grid_js_options ||={}
|
36
41
|
new_options.each do |key, value|
|
@@ -38,6 +43,7 @@ module RailsJqGrid
|
|
38
43
|
end
|
39
44
|
end
|
40
45
|
|
46
|
+
# converts options to a string for jqgrid
|
41
47
|
def options_to_jqgrid_options
|
42
48
|
jqgrid_options = []
|
43
49
|
self.jq_grid_js_options.each_value { |option|
|
@@ -46,5 +52,9 @@ module RailsJqGrid
|
|
46
52
|
jqgrid_options.sort.join(",\n ")
|
47
53
|
end
|
48
54
|
|
55
|
+
def set_jqgrid_options(&option_block)
|
56
|
+
option_block.call(self) if block_given?
|
57
|
+
end
|
58
|
+
|
49
59
|
end
|
50
60
|
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
|
2
|
+
# This program is free software; you can redistribute it and/or
|
3
|
+
# modify it under the terms of the GNU General Public License
|
4
|
+
# as published by the Free Software Foundation; either version 3
|
5
|
+
# of the License, or (at your option) any later version.
|
6
|
+
|
7
|
+
# Author:: Dieter Spaeth (mailto:dieter.spaeth@gmx.de)
|
8
|
+
# Copyright:: Copyright (c) 2010 Dieter Spaeth
|
9
|
+
|
10
|
+
module RailsJqGrid
|
11
|
+
class JqGridNavGrid
|
12
|
+
include JqGridMethodMissing
|
13
|
+
|
14
|
+
DEFAULT_OPTIONS = {:add => true,
|
15
|
+
:del => true,
|
16
|
+
:edit => true,
|
17
|
+
:refresh => true,
|
18
|
+
:search => true,
|
19
|
+
}
|
20
|
+
|
21
|
+
DEFAULT_PRM_OPTIONS = { :close_after_add => true,
|
22
|
+
:close_after_edit => true,
|
23
|
+
:close_on_escape => true
|
24
|
+
}
|
25
|
+
|
26
|
+
attr_accessor :dom_id, :pager_id, :restfull,
|
27
|
+
:prm_edit_data, :prm_add_data, :prm_del_data, :prm_search_data,
|
28
|
+
:prm_view_data
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
def initialize(dom_id, pager_id , &option_block)
|
33
|
+
self.dom_id = dom_id
|
34
|
+
self.pager_id = pager_id
|
35
|
+
|
36
|
+
self.prm_edit_data = JqGridNavGridParameter.new(DEFAULT_PRM_OPTIONS)
|
37
|
+
self.prm_add_data = JqGridNavGridParameter.new(DEFAULT_PRM_OPTIONS)
|
38
|
+
self.prm_del_data = JqGridNavGridParameter.new(DEFAULT_PRM_OPTIONS)
|
39
|
+
self.prm_search_data = JqGridNavGridParameter.new(DEFAULT_PRM_OPTIONS)
|
40
|
+
self.prm_view_data = JqGridNavGridParameter.new(DEFAULT_PRM_OPTIONS)
|
41
|
+
|
42
|
+
self.init_jq_grid_js_options DEFAULT_OPTIONS
|
43
|
+
|
44
|
+
option_block.call(self) if block_given?
|
45
|
+
end
|
46
|
+
|
47
|
+
def prm_edit(&block)
|
48
|
+
prm_edit_data.set_jqgrid_options(&block)
|
49
|
+
end
|
50
|
+
|
51
|
+
def prm_add(&block)
|
52
|
+
prm_add_data.set_jqgrid_options(&block)
|
53
|
+
end
|
54
|
+
|
55
|
+
def prm_del(&block)
|
56
|
+
prm_del_data.set_jqgrid_options(&block)
|
57
|
+
end
|
58
|
+
|
59
|
+
def prm_search(&block)
|
60
|
+
prm_search_data.set_jqgrid_options(&block)
|
61
|
+
end
|
62
|
+
|
63
|
+
def prm_view(&block)
|
64
|
+
prm_view_data.set_jqgrid_options(&block)
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def to_js
|
69
|
+
params=[nav_grid_parameters]
|
70
|
+
|
71
|
+
if is_restful?
|
72
|
+
set_nav_grid_restful_extensions
|
73
|
+
end
|
74
|
+
|
75
|
+
params.push([prm_edit_data.to_js,
|
76
|
+
prm_add_data.to_js,
|
77
|
+
prm_del_data.to_js,
|
78
|
+
prm_search_data.to_js,
|
79
|
+
prm_view_data.to_js]).flatten!
|
80
|
+
|
81
|
+
<<-EO_JS
|
82
|
+
jQuery("##{dom_id}").jqGrid('navGrid','##{pager_id}',#{params.join(",\n")} );
|
83
|
+
EO_JS
|
84
|
+
end
|
85
|
+
|
86
|
+
def nav_grid_parameters
|
87
|
+
<<-EO_JS
|
88
|
+
{
|
89
|
+
#{options_to_jqgrid_options}
|
90
|
+
}
|
91
|
+
EO_JS
|
92
|
+
end
|
93
|
+
|
94
|
+
def set_nav_grid_restful_extensions
|
95
|
+
restful_param_edit
|
96
|
+
restful_param_add
|
97
|
+
restful_param_delete
|
98
|
+
end
|
99
|
+
|
100
|
+
def restful_param_edit
|
101
|
+
prm_edit_data.mtype "PUT"
|
102
|
+
prm_edit_data.onclick_submit raw <<-EO_JS
|
103
|
+
function(rp_ge, postdata) {
|
104
|
+
selrow = jQuery("##{dom_id}").jqGrid('getGridParam','selrow');
|
105
|
+
if (selrow!=null){
|
106
|
+
rp_ge.url = jQuery("##{dom_id}").jqGrid('getGridParam','editurl') + '/' + selrow;
|
107
|
+
}
|
108
|
+
return {};
|
109
|
+
}
|
110
|
+
EO_JS
|
111
|
+
end
|
112
|
+
|
113
|
+
def restful_param_add
|
114
|
+
prm_add_data.mtype "POST"
|
115
|
+
end
|
116
|
+
|
117
|
+
def restful_param_delete
|
118
|
+
prm_del_data.mtype "DELETE"
|
119
|
+
prm_del_data.onclick_submit raw <<-EO_JS
|
120
|
+
function(rp_ge, postdata) {
|
121
|
+
rp_ge.url = jQuery("##{dom_id}").jqGrid('getGridParam','editurl') + '/' + postdata
|
122
|
+
return {};
|
123
|
+
}
|
124
|
+
EO_JS
|
125
|
+
end
|
126
|
+
|
127
|
+
def is_restfull?
|
128
|
+
self.restfull
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
# This program is free software; you can redistribute it and/or
|
3
|
+
# modify it under the terms of the GNU General Public License
|
4
|
+
# as published by the Free Software Foundation; either version 3
|
5
|
+
# of the License, or (at your option) any later version.
|
6
|
+
|
7
|
+
# Author:: Dieter Spaeth (mailto:dieter.spaeth@gmx.de)
|
8
|
+
# Copyright:: Copyright (c) 2010 Dieter Spaeth
|
9
|
+
|
10
|
+
module RailsJqGrid
|
11
|
+
class JqGridNavGridParameter
|
12
|
+
include JqGridMethodMissing
|
13
|
+
|
14
|
+
def initialize(default_options = {}, &option_block)
|
15
|
+
self.jq_grid_js_options ||={}
|
16
|
+
|
17
|
+
self.init_jq_grid_js_options default_options
|
18
|
+
|
19
|
+
option_block.call(self) if block_given?
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_js
|
23
|
+
<<-EO_JS
|
24
|
+
{
|
25
|
+
#{options_to_jqgrid_options}
|
26
|
+
}
|
27
|
+
EO_JS
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -1,7 +1,16 @@
|
|
1
|
-
|
2
|
-
#
|
1
|
+
|
2
|
+
# This program is free software; you can redistribute it and/or
|
3
|
+
# modify it under the terms of the GNU General Public License
|
4
|
+
# as published by the Free Software Foundation; either version 3
|
5
|
+
# of the License, or (at your option) any later version.
|
6
|
+
|
7
|
+
# Author:: Dieter Spaeth (mailto:dieter.spaeth@gmx.de)
|
8
|
+
# Copyright:: Copyright (c) 2010 Dieter Spaeth
|
9
|
+
|
3
10
|
|
4
11
|
module RailsJqGrid
|
12
|
+
|
13
|
+
# Contains all information for one option or method
|
5
14
|
class JqGridOptionOrMethod
|
6
15
|
include ActiveSupport::Inflector
|
7
16
|
|
@@ -20,16 +29,22 @@ module RailsJqGrid
|
|
20
29
|
|
21
30
|
end
|
22
31
|
|
32
|
+
# works like JqGridMethodMissing.raw
|
23
33
|
def <<(*args)
|
24
34
|
RAILS_DEFAULT_LOGGER.debug "#{args.inspect}"
|
25
35
|
self.type = :raw
|
26
36
|
self.value = args[0]
|
27
37
|
end
|
28
38
|
|
39
|
+
# option name ist camalized with a lower start character
|
40
|
+
# transforms from ruby style to jqgrid style
|
41
|
+
# before_submit => beforeSubmit
|
29
42
|
def escaped_name
|
30
43
|
self.name.to_s.camelize(:lower)
|
31
44
|
end
|
32
45
|
|
46
|
+
# every value is transformed to json
|
47
|
+
# as lang es it isn't marked es raw
|
33
48
|
def escaped_value
|
34
49
|
if self.type == :raw
|
35
50
|
self.value
|
@@ -1,5 +1,12 @@
|
|
1
|
-
|
2
|
-
#
|
1
|
+
|
2
|
+
# This program is free software; you can redistribute it and/or
|
3
|
+
# modify it under the terms of the GNU General Public License
|
4
|
+
# as published by the Free Software Foundation; either version 3
|
5
|
+
# of the License, or (at your option) any later version.
|
6
|
+
|
7
|
+
# Author:: Dieter Spaeth (mailto:dieter.spaeth@gmx.de)
|
8
|
+
# Copyright:: Copyright (c) 2010 Dieter Spaeth
|
9
|
+
|
3
10
|
|
4
11
|
module RailsJqGrid
|
5
12
|
module ActsAsJqGridAble
|
@@ -8,7 +15,8 @@ module RailsJqGrid
|
|
8
15
|
end
|
9
16
|
|
10
17
|
module ActsAsClassMethod
|
11
|
-
|
18
|
+
# any method placed here will apply to classes
|
19
|
+
|
12
20
|
def acts_as_jqgrid_able
|
13
21
|
send :include, InstanceMethods
|
14
22
|
cattr_accessor :allowed_order_by_cols
|
@@ -18,16 +26,25 @@ module RailsJqGrid
|
|
18
26
|
end
|
19
27
|
|
20
28
|
module ClassMethods
|
29
|
+
|
30
|
+
# Contains an array of column names which can safely be used
|
31
|
+
# for order by. Columns not configured here can't be user
|
32
|
+
# by #order_by
|
21
33
|
def order_by_cols(*args)
|
22
34
|
self.allowed_order_by_cols ||= []
|
23
35
|
self.allowed_order_by_cols.push(args.map{|arg| arg.to_s})
|
24
36
|
self.allowed_order_by_cols.flatten!
|
25
|
-
|
26
|
-
logger.info "Array: " + self.allowed_order_by_cols.inspect
|
37
|
+
|
27
38
|
end
|
28
39
|
end
|
29
40
|
|
30
41
|
module InstanceMethods
|
42
|
+
|
43
|
+
# creates json string for jqGrid
|
44
|
+
# options:: :total_records count records totaly to display in grid, default :data.count
|
45
|
+
# :default_records_per_page when nothing is specified how many
|
46
|
+
# records are shown on a page, default :data.count
|
47
|
+
# :data the records as an array
|
31
48
|
def jqgrid_json(options)
|
32
49
|
options[:total_records] ||= options[:data].count
|
33
50
|
options[:default_records_per_page] ||= options[:data].count
|
@@ -41,18 +58,25 @@ module RailsJqGrid
|
|
41
58
|
json_data.to_json
|
42
59
|
end
|
43
60
|
|
61
|
+
# calculates the current offset by page and records per page
|
44
62
|
def current_offset(default_recs_per_page = 10)
|
45
63
|
(current_page - 1) * records_per_page(default_recs_per_page)
|
46
64
|
end
|
47
65
|
|
66
|
+
# returns the current page retrieved from jqgrid request
|
67
|
+
# default 1
|
48
68
|
def current_page
|
49
69
|
(params[:page] || 1).to_i
|
50
70
|
end
|
51
71
|
|
72
|
+
# returns records per page retrieved from jqgrid request
|
73
|
+
# default 1
|
52
74
|
def records_per_page(default_recs_per_page = 10)
|
53
75
|
(params[:rows] || default_recs_per_page).to_i
|
54
76
|
end
|
55
77
|
|
78
|
+
# tests jqgrid request parameter sidx and sord
|
79
|
+
# and returns a sanatized order by statement
|
56
80
|
def order_by
|
57
81
|
order_column = params[:sidx] || ""
|
58
82
|
|
data/lib/rails_jq_grid/engine.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
|
+
|
2
|
+
# This program is free software; you can redistribute it and/or
|
3
|
+
# modify it under the terms of the GNU General Public License
|
4
|
+
# as published by the Free Software Foundation; either version 3
|
5
|
+
# of the License, or (at your option) any later version.
|
6
|
+
|
7
|
+
# Author:: Dieter Spaeth (mailto:dieter.spaeth@gmx.de)
|
8
|
+
# Copyright:: Copyright (c) 2010 Dieter Spaeth
|
9
|
+
|
10
|
+
|
1
11
|
require 'rails_jq_grid'
|
2
12
|
require 'rails'
|
3
13
|
|
4
14
|
module RailsJqGrid
|
5
15
|
class Engine < Rails::Engine
|
6
|
-
config.autoload_paths += %W(#{config.root}/lib)
|
7
|
-
|
8
|
-
# paths.app.controllers = "app/controllers"
|
9
|
-
# paths.app.helpers = "app/helpers"
|
10
|
-
# paths.app.models = "app/models"
|
11
|
-
# paths.app.views = "app/views"
|
12
|
-
# paths.lib "lib"
|
13
|
-
# paths.lib.tasks "lib/tasks", :glob => "**/*.rake"
|
14
|
-
|
15
|
-
|
16
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
16
17
|
|
17
18
|
initializer "static assets" do |app|
|
18
19
|
app.middleware.use ::ActionDispatch::Static, "#{root}/public"
|
data/lib/rails_jq_grid.rb
CHANGED
@@ -1,7 +1,16 @@
|
|
1
|
+
|
2
|
+
# This program is free software; you can redistribute it and/or
|
3
|
+
# modify it under the terms of the GNU General Public License
|
4
|
+
# as published by the Free Software Foundation; either version 3
|
5
|
+
# of the License, or (at your option) any later version.
|
6
|
+
|
7
|
+
# Author:: Dieter Spaeth (mailto:dieter.spaeth@gmx.de)
|
8
|
+
# Copyright:: Copyright (c) 2010 Dieter Spaeth
|
9
|
+
|
10
|
+
|
1
11
|
module RailsJqGrid
|
2
12
|
if defined?(Rails)
|
3
|
-
require 'rails_jq_grid/engine'
|
4
|
-
#require 'rails_jq_grid/jq_grid'
|
13
|
+
require 'rails_jq_grid/engine'
|
5
14
|
end
|
6
15
|
end
|
7
16
|
|
data/rails_jq_grid.gemspec
CHANGED
@@ -5,11 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rails_jq_grid}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3.pre1"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dieter Spaeth"]
|
12
|
-
s.date = %q{2010-10-
|
12
|
+
s.date = %q{2010-10-10}
|
13
|
+
s.description = %q{This gems is a Rails 3 Enginge that helps you to create jqGrid. It's bundled with jqGrid and some themes.}
|
13
14
|
s.email = %q{dieter.spaeth@gmx.de}
|
14
15
|
s.extra_rdoc_files = [
|
15
16
|
"README.rdoc"
|
@@ -26,10 +27,11 @@ Gem::Specification.new do |s|
|
|
26
27
|
"app/models/rails_jq_grid/jq_grid.rb",
|
27
28
|
"app/models/rails_jq_grid/jq_grid_column.rb",
|
28
29
|
"app/models/rails_jq_grid/jq_grid_method_missing.rb",
|
30
|
+
"app/models/rails_jq_grid/jq_grid_nav_grid.rb",
|
31
|
+
"app/models/rails_jq_grid/jq_grid_nav_grid_parameter.rb",
|
29
32
|
"app/models/rails_jq_grid/jq_grid_option_or_method.rb",
|
30
33
|
"lib/rails_jq_grid.rb",
|
31
34
|
"lib/rails_jq_grid/acts_as_jq_grid_able.rb",
|
32
|
-
"lib/rails_jq_grid/acts_as_jq_grid_data_source.rb",
|
33
35
|
"lib/rails_jq_grid/engine.rb",
|
34
36
|
"lib/tasks/rails_jq_grid.rake",
|
35
37
|
"public/javascripts/rails-jqgrid/Changes.txt",
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_jq_grid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 270495468
|
5
|
+
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
|
9
|
+
- 3
|
10
|
+
- pre1
|
11
|
+
version: 0.0.3.pre1
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Dieter Spaeth
|
@@ -15,7 +16,7 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-10-
|
19
|
+
date: 2010-10-10 00:00:00 +02:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
@@ -34,7 +35,7 @@ dependencies:
|
|
34
35
|
version: 1.2.9
|
35
36
|
type: :development
|
36
37
|
version_requirements: *id001
|
37
|
-
description:
|
38
|
+
description: This gems is a Rails 3 Enginge that helps you to create jqGrid. It's bundled with jqGrid and some themes.
|
38
39
|
email: dieter.spaeth@gmx.de
|
39
40
|
executables: []
|
40
41
|
|
@@ -54,10 +55,11 @@ files:
|
|
54
55
|
- app/models/rails_jq_grid/jq_grid.rb
|
55
56
|
- app/models/rails_jq_grid/jq_grid_column.rb
|
56
57
|
- app/models/rails_jq_grid/jq_grid_method_missing.rb
|
58
|
+
- app/models/rails_jq_grid/jq_grid_nav_grid.rb
|
59
|
+
- app/models/rails_jq_grid/jq_grid_nav_grid_parameter.rb
|
57
60
|
- app/models/rails_jq_grid/jq_grid_option_or_method.rb
|
58
61
|
- lib/rails_jq_grid.rb
|
59
62
|
- lib/rails_jq_grid/acts_as_jq_grid_able.rb
|
60
|
-
- lib/rails_jq_grid/acts_as_jq_grid_data_source.rb
|
61
63
|
- lib/rails_jq_grid/engine.rb
|
62
64
|
- lib/tasks/rails_jq_grid.rake
|
63
65
|
- public/javascripts/rails-jqgrid/Changes.txt
|
@@ -223,12 +225,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
223
225
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
224
226
|
none: false
|
225
227
|
requirements:
|
226
|
-
- - "
|
228
|
+
- - ">"
|
227
229
|
- !ruby/object:Gem::Version
|
228
|
-
hash:
|
230
|
+
hash: 25
|
229
231
|
segments:
|
230
|
-
-
|
231
|
-
|
232
|
+
- 1
|
233
|
+
- 3
|
234
|
+
- 1
|
235
|
+
version: 1.3.1
|
232
236
|
requirements: []
|
233
237
|
|
234
238
|
rubyforge_project:
|
@@ -1,34 +0,0 @@
|
|
1
|
-
|
2
|
-
module RailsJqGrid
|
3
|
-
module ActsAsJqGridDataSource
|
4
|
-
|
5
|
-
# To include this Module parente Class has to define
|
6
|
-
# [] each and count
|
7
|
-
def self.included(base)
|
8
|
-
base.send :extend, ClassMethods
|
9
|
-
end
|
10
|
-
|
11
|
-
module ClassMethods
|
12
|
-
## any method placed here will apply to classes, like Hickwall
|
13
|
-
def acts_as_jqgrid
|
14
|
-
send :include, InstanceMethods
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_jqgrid_data(current_page=nil, records_per_page=nil)
|
18
|
-
current_page ||= 1
|
19
|
-
records_per_page ||= count
|
20
|
-
total_records = count
|
21
|
-
total_pages = (count + records_per_page - 1).div(records_per_page)
|
22
|
-
|
23
|
-
json_data = {:currentpage => current_page, :totalpages => total_pages , :totalrecords => total_records }
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
module InstanceMethods
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|