rails_jq_grid 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. data/COPYRIGHT.txt +17 -0
  2. data/GPL-LICENSE +675 -0
  3. data/README.rdoc +176 -0
  4. data/Rakefile +47 -0
  5. data/VERSION +1 -0
  6. data/app/helpers/rails_jq_grid/jq_grid_css_helper.rb +29 -0
  7. data/app/helpers/rails_jq_grid/jq_grid_helper.rb +21 -0
  8. data/app/helpers/rails_jq_grid/jq_grid_js_helper.rb +30 -0
  9. data/app/models/rails_jq_grid/jq_grid.rb +315 -0
  10. data/app/models/rails_jq_grid/jq_grid_column.rb +33 -0
  11. data/app/models/rails_jq_grid/jq_grid_method_missing.rb +50 -0
  12. data/app/models/rails_jq_grid/jq_grid_option_or_method.rb +46 -0
  13. data/lib/rails_jq_grid/acts_as_jq_grid_able.rb +76 -0
  14. data/lib/rails_jq_grid/acts_as_jq_grid_data_source.rb +34 -0
  15. data/lib/rails_jq_grid/engine.rb +23 -0
  16. data/lib/rails_jq_grid.rb +7 -0
  17. data/lib/tasks/rails_jq_grid.rake +1 -0
  18. data/public/javascripts/rails-jqgrid/Changes.txt +1160 -0
  19. data/public/javascripts/rails-jqgrid/i18n/grid.locale-bg.js +1 -0
  20. data/public/javascripts/rails-jqgrid/i18n/grid.locale-bg1251.js +1 -0
  21. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cat.js +1 -0
  22. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cn.js +1 -0
  23. data/public/javascripts/rails-jqgrid/i18n/grid.locale-cs.js +1 -0
  24. data/public/javascripts/rails-jqgrid/i18n/grid.locale-de.js +1 -0
  25. data/public/javascripts/rails-jqgrid/i18n/grid.locale-dk.js +1 -0
  26. data/public/javascripts/rails-jqgrid/i18n/grid.locale-el.js +1 -0
  27. data/public/javascripts/rails-jqgrid/i18n/grid.locale-en.js +1 -0
  28. data/public/javascripts/rails-jqgrid/i18n/grid.locale-es.js +1 -0
  29. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fa.js +1 -0
  30. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fi.js +1 -0
  31. data/public/javascripts/rails-jqgrid/i18n/grid.locale-fr.js +1 -0
  32. data/public/javascripts/rails-jqgrid/i18n/grid.locale-he.js +1 -0
  33. data/public/javascripts/rails-jqgrid/i18n/grid.locale-hu.js +1 -0
  34. data/public/javascripts/rails-jqgrid/i18n/grid.locale-is.js +1 -0
  35. data/public/javascripts/rails-jqgrid/i18n/grid.locale-it.js +1 -0
  36. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ja.js +1 -0
  37. data/public/javascripts/rails-jqgrid/i18n/grid.locale-nl.js +1 -0
  38. data/public/javascripts/rails-jqgrid/i18n/grid.locale-no.js +1 -0
  39. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pl.js +1 -0
  40. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pt-br.js +1 -0
  41. data/public/javascripts/rails-jqgrid/i18n/grid.locale-pt.js +1 -0
  42. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ro.js +1 -0
  43. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ru.js +1 -0
  44. data/public/javascripts/rails-jqgrid/i18n/grid.locale-sk.js +1 -0
  45. data/public/javascripts/rails-jqgrid/i18n/grid.locale-sv.js +1 -0
  46. data/public/javascripts/rails-jqgrid/i18n/grid.locale-tr.js +1 -0
  47. data/public/javascripts/rails-jqgrid/i18n/grid.locale-ua.js +1 -0
  48. data/public/javascripts/rails-jqgrid/install.txt +43 -0
  49. data/public/javascripts/rails-jqgrid/jquery-1.4.2.min.js +154 -0
  50. data/public/javascripts/rails-jqgrid/jquery-ui-1.8.4.custom.min.js +763 -0
  51. data/public/javascripts/rails-jqgrid/jquery.jqGrid.min.js +445 -0
  52. data/public/javascripts/rails-jqgrid/src/JsonXml.js +330 -0
  53. data/public/javascripts/rails-jqgrid/src/css/ellipsis-xbl.xml +13 -0
  54. data/public/javascripts/rails-jqgrid/src/css/jquery.searchFilter.css +7 -0
  55. data/public/javascripts/rails-jqgrid/src/css/ui.jqgrid.css +129 -0
  56. data/public/javascripts/rails-jqgrid/src/css/ui.multiselect.css +30 -0
  57. data/public/javascripts/rails-jqgrid/src/grid.base.js +3003 -0
  58. data/public/javascripts/rails-jqgrid/src/grid.celledit.js +486 -0
  59. data/public/javascripts/rails-jqgrid/src/grid.common.js +636 -0
  60. data/public/javascripts/rails-jqgrid/src/grid.custom.js +818 -0
  61. data/public/javascripts/rails-jqgrid/src/grid.formedit.js +1872 -0
  62. data/public/javascripts/rails-jqgrid/src/grid.import.js +201 -0
  63. data/public/javascripts/rails-jqgrid/src/grid.inlinedit.js +250 -0
  64. data/public/javascripts/rails-jqgrid/src/grid.jqueryui.js +503 -0
  65. data/public/javascripts/rails-jqgrid/src/grid.loader.js +47 -0
  66. data/public/javascripts/rails-jqgrid/src/grid.postext.js +64 -0
  67. data/public/javascripts/rails-jqgrid/src/grid.setcolumns.js +126 -0
  68. data/public/javascripts/rails-jqgrid/src/grid.subgrid.js +260 -0
  69. data/public/javascripts/rails-jqgrid/src/grid.tbltogrid.js +106 -0
  70. data/public/javascripts/rails-jqgrid/src/grid.treegrid.js +483 -0
  71. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-bg.js +132 -0
  72. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-bg1251.js +132 -0
  73. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cat.js +128 -0
  74. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cn.js +132 -0
  75. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-cs.js +128 -0
  76. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-de.js +128 -0
  77. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-dk.js +128 -0
  78. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-el.js +126 -0
  79. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-en.js +128 -0
  80. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-es.js +128 -0
  81. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fa.js +125 -0
  82. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fi.js +130 -0
  83. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-fr.js +126 -0
  84. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-he.js +127 -0
  85. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-hu.js +129 -0
  86. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-is.js +126 -0
  87. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-it.js +1 -0
  88. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ja.js +155 -0
  89. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-nl.js +149 -0
  90. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-no.js +1 -0
  91. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pl.js +127 -0
  92. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pt-br.js +127 -0
  93. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-pt.js +125 -0
  94. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ro.js +139 -0
  95. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ru.js +127 -0
  96. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sk.js +127 -0
  97. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-sv.js +127 -0
  98. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-tr.js +126 -0
  99. data/public/javascripts/rails-jqgrid/src/i18n/grid.locale-ua.js +127 -0
  100. data/public/javascripts/rails-jqgrid/src/jqDnR.js +68 -0
  101. data/public/javascripts/rails-jqgrid/src/jqModal.js +69 -0
  102. data/public/javascripts/rails-jqgrid/src/jquery.fmatter.js +542 -0
  103. data/public/javascripts/rails-jqgrid/src/jquery.searchFilter.js +716 -0
  104. data/public/javascripts/rails-jqgrid/src/ui.multiselect.js +314 -0
  105. data/public/stylesheets/rails-jqgrid/ellipsis-xbl.xml +13 -0
  106. data/public/stylesheets/rails-jqgrid/themes/AUTHORS.txt +30 -0
  107. data/public/stylesheets/rails-jqgrid/themes/GPL-LICENSE.txt +278 -0
  108. data/public/stylesheets/rails-jqgrid/themes/MIT-LICENSE.txt +25 -0
  109. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  110. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  111. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  112. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  113. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  114. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  115. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  116. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  117. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-icons_222222_256x240.png +0 -0
  118. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  119. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-icons_454545_256x240.png +0 -0
  120. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-icons_888888_256x240.png +0 -0
  121. data/public/stylesheets/rails-jqgrid/themes/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  122. data/public/stylesheets/rails-jqgrid/themes/smoothness/jquery-ui-1.8.4.custom.css +572 -0
  123. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_flat_55_999999_40x100.png +0 -0
  124. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_flat_75_aaaaaa_40x100.png +0 -0
  125. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_glass_45_0078ae_1x400.png +0 -0
  126. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_glass_55_f8da4e_1x400.png +0 -0
  127. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_glass_75_79c9ec_1x400.png +0 -0
  128. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_gloss-wave_45_e14f1c_500x100.png +0 -0
  129. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_gloss-wave_50_6eac2c_500x100.png +0 -0
  130. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_gloss-wave_75_2191c0_500x100.png +0 -0
  131. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-bg_inset-hard_100_fcfdfd_1x100.png +0 -0
  132. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_0078ae_256x240.png +0 -0
  133. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_056b93_256x240.png +0 -0
  134. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_d8e7f3_256x240.png +0 -0
  135. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_e0fdff_256x240.png +0 -0
  136. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_f5e175_256x240.png +0 -0
  137. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_f7a50d_256x240.png +0 -0
  138. data/public/stylesheets/rails-jqgrid/themes/start/images/ui-icons_fcd113_256x240.png +0 -0
  139. data/public/stylesheets/rails-jqgrid/themes/start/jquery-ui-1.8.4.custom.css +573 -0
  140. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_flat_30_cccccc_40x100.png +0 -0
  141. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_flat_50_5c5c5c_40x100.png +0 -0
  142. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_glass_20_555555_1x400.png +0 -0
  143. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_glass_40_0078a3_1x400.png +0 -0
  144. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_glass_40_ffc73d_1x400.png +0 -0
  145. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_gloss-wave_25_333333_500x100.png +0 -0
  146. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_highlight-soft_80_eeeeee_1x100.png +0 -0
  147. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_inset-soft_25_000000_1x100.png +0 -0
  148. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-bg_inset-soft_30_f58400_1x100.png +0 -0
  149. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-icons_222222_256x240.png +0 -0
  150. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-icons_4b8e0b_256x240.png +0 -0
  151. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-icons_a83300_256x240.png +0 -0
  152. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-icons_cccccc_256x240.png +0 -0
  153. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/images/ui-icons_ffffff_256x240.png +0 -0
  154. data/public/stylesheets/rails-jqgrid/themes/ui-darkness/jquery-ui-1.8.4.custom.css +572 -0
  155. data/public/stylesheets/rails-jqgrid/themes/version.txt +1 -0
  156. data/public/stylesheets/rails-jqgrid/ui.jqgrid.css +2 -0
  157. data/rails_jq_grid.gemspec +200 -0
  158. data/spec/spec.opts +1 -0
  159. data/spec/spec_helper.rb +8 -0
  160. metadata +240 -0
data/README.rdoc ADDED
@@ -0,0 +1,176 @@
1
+ = Rails JqGrid
2
+
3
+ This Rails 3 Enginge allows you to use jQGrid into your applications with REST support.
4
+ When used with rest sudgrids and details grids are treated as nestet resources. URL's
5
+ are constructect from mastergrid-url + selecedted id + detail/sub-grid-url.
6
+
7
+ It' is bundled with jqGrid 3.7.2 and some themes. To use your
8
+ custom themes put them under
9
+
10
+ RAILS_ROOT\public\stylesheets\rails-jqgrid\themes
11
+
12
+ == Usage
13
+
14
+ === Controller
15
+ include RailsJqGrid::ActsAsJqGridAble
16
+ acts_as_jqgrid_able
17
+ order_by_cols :col_name1, :col_name2
18
+
19
+ def action
20
+ ...
21
+
22
+ @records = MyModel.all(:order => order_by, :limit => records_per_page, :offset => current_offset)
23
+
24
+ respond_to do |format|
25
+ format.html { }
26
+ format.xml { }
27
+ format.json {
28
+ #for multiple pages
29
+ render :json => jqgrid_json(:total_records => @total_records,
30
+ :default_records_per_page => @default_records_per_page,
31
+ :data => @records)
32
+ #or for a single page
33
+ #render :json => jqgrid_json(:data => @records)
34
+ }
35
+ end
36
+ end
37
+
38
+ === View
39
+ <head>
40
+ ...
41
+ <%= jqgrid_stylesheets_tags(:theme => "start") %>
42
+ <%= jqgrid_js_tags %>
43
+ ...
44
+ </head>
45
+
46
+ ...
47
+
48
+ <%=jqgrid("Article", "article", url_for(:action => "index"), :restful => true) do |a|
49
+
50
+ a.autowidth true
51
+ a.width 300
52
+ a.height 500
53
+ a.shrink_to_fit true
54
+ a.row_num 10
55
+ a.row_list [10,20,50,100]
56
+ a.search true
57
+ a.gridview true
58
+ a.multiselect false
59
+
60
+ a.on_select_row raw "function(){alert('test');}"
61
+
62
+ a.column "ean" do |c|
63
+ c.label "EAN"
64
+ c.autowidth true
65
+ c.resizable true
66
+ c.editable true
67
+ end
68
+
69
+ a.column "article_number" do |c|
70
+ c.label "Article"
71
+ c.resizable true
72
+ c.editable true
73
+ end
74
+
75
+ a.jqgrid "Prices", "prices", url_for(:controller => :prices),
76
+ :url_append_ids => true,
77
+ :type => :sub_grid,
78
+ :restful => true do |p|
79
+ p.autowidth true
80
+ p.width 300
81
+ p.height 500
82
+ p.shrink_to_fit true
83
+ p.row_num 10
84
+ p.row_list [10,20,50,100]
85
+ p.search true
86
+ p.gridview true
87
+ p.multiselect false
88
+
89
+ p.on_select_row << "function(id,status){alert('test2');}"
90
+
91
+
92
+ p.column "price" do
93
+ c.autowidth true
94
+ c.resizable true
95
+ end
96
+
97
+ p.column "valid_from"
98
+
99
+ end
100
+
101
+ a.jqgrid "Prices Detail", "prices_detail",
102
+ url_for(:controller => :prices ,
103
+ :action => "index"),
104
+ :caption_append_ids => true,
105
+ :type => :detail_grid do |p|
106
+ p.autowidth true
107
+ p.width 300
108
+ p.height 500
109
+ p.shrink_to_fit true
110
+ p.row_num 10
111
+ p.row_list [10,20,50,100]
112
+ p.search true
113
+ p.gridview true
114
+ p.multiselect false
115
+
116
+ p.on_select_row << "function(id,status){alert('test2');}"
117
+
118
+
119
+ p.column "ean" do
120
+ c.label "EAN"
121
+ c.autowidth true
122
+ c.resizable true
123
+ end
124
+
125
+ p.column "article_number" do
126
+ c.label "Article"
127
+ c.resizable true
128
+ end
129
+
130
+
131
+ # some columns with the same options
132
+ p.columns "col1", "col2" , "col3", "col4" do |c|
133
+ c.autowidth true
134
+ c.resizable true
135
+ c.editable true
136
+ c.height "30px"
137
+ end
138
+
139
+ #alter options for one column
140
+ p.column "col1" do |c|
141
+ c.editable false
142
+ c.height "40px"
143
+ end
144
+ end
145
+
146
+
147
+ end %>
148
+
149
+ === Model
150
+
151
+ class MyModel < ActiveRecord::Base
152
+ self.include_root_in_json = false
153
+ end
154
+
155
+
156
+ === I18N
157
+
158
+ When a column doesn't set label then human_attribute_name is used for the fieldname
159
+ to guess the label. To use I18N just setup your local and create a local file like:
160
+
161
+ -RAILS_ROOT
162
+ |-config
163
+ |-locales
164
+ | - en.yml
165
+
166
+ content for en.yml:
167
+ en:
168
+ attributes:
169
+ col1: "Label for Col1"
170
+ col2: "Label for Col2"
171
+
172
+
173
+
174
+ == Copyright
175
+
176
+ Copyright (c) 2010 Dieter Spaeth. See GPL-LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require "rake"
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+
6
+ begin
7
+ require "jeweler"
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "rails_jq_grid"
10
+ gem.summary = "Add JqGrid to your Rails 3 app"
11
+ gem.email = "dieter.spaeth@gmx.de"
12
+ gem.authors = ["Dieter Spaeth"]
13
+ gem.homepage = "http://github.com/consu/rails-jqgrid"
14
+ gem.add_development_dependency "rspec", ">= 1.2.9"
15
+ gem.files = Dir["*", "{lib}/**/*", "{public}/**/*", "{spec}/**/*", "{app}/**/*"]
16
+ end
17
+
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "ko #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,29 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module RailsJqGrid
5
+ module JqGridCssHelper
6
+ STYLESHEETS_BASE = "/stylesheets/rails-jqgrid"
7
+ JQUERY_UI_THEMES_BASE = STYLESHEETS_BASE + "/themes"
8
+ JQUERY_UI_VERSION = "1.8.4"
9
+
10
+ def jqgrid_stylesheets_tags(options={})
11
+ [jqgrid_ui_stylesheet_tag(options),
12
+ jquery_ui_stylesheet_tag(options)
13
+ ].join("\n").html_safe
14
+ end
15
+
16
+ def jqgrid_ui_stylesheet_tag(options={})
17
+ (stylesheet_link_tag STYLESHEETS_BASE + "/ui.jqgrid.css").html_safe
18
+ end
19
+
20
+ def jquery_ui_stylesheet_tag(options={})
21
+ (stylesheet_link_tag JQUERY_UI_THEMES_BASE + "/#{jquery_theme(options)}" +"/jquery-ui-#{JQUERY_UI_VERSION}.custom.css").html_safe
22
+ end
23
+
24
+ def jquery_theme(options={})
25
+ options[:theme] || "start"
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ require 'rails_jq_grid/jq_grid'
5
+
6
+ module RailsJqGrid
7
+ module JqGridHelper
8
+
9
+ include JqGridJsHelper
10
+ include JqGridCssHelper
11
+
12
+ def jqgrid(title, dom_id, url_for_options, options={}, &option_block)
13
+ if url_for_options.is_a?(Hash)
14
+ url_for_options[:controller]||=controller.controller_name
15
+ end
16
+ ::RailsJqGrid::JqGrid.new(title, dom_id, url_for_options, options, &option_block).to_html
17
+ end
18
+
19
+
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module RailsJqGrid
5
+ module JqGridJsHelper
6
+ JS_BASE = "/javascripts/rails-jqgrid"
7
+ JQUERY_VERSION = "1.4.2"
8
+
9
+ def jqgrid_js_tags(options={})
10
+ [jquery_js_tag,
11
+ jqgrid_i18n_js_tag(options),
12
+ jqgrid_js_tag
13
+ ].join("\n").html_safe
14
+ end
15
+
16
+ def jquery_js_tag
17
+ (javascript_include_tag JS_BASE + "/jquery-#{JQUERY_VERSION}.min.js").html_safe
18
+ end
19
+
20
+ def jqgrid_js_tag
21
+ (javascript_include_tag JS_BASE + "/jquery.jqGrid.min.js").html_safe
22
+ end
23
+
24
+ def jqgrid_i18n_js_tag(options={})
25
+ options[:local] ||= I18n.locale rescue :en
26
+ (javascript_include_tag JS_BASE + "/i18n/grid.locale-#{options[:local]}.js").html_safe
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,315 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module RailsJqGrid
5
+ class JqGrid
6
+ extend ActiveModel::Translation
7
+
8
+ include ActionView::Helpers::JavaScriptHelper
9
+ include ActionView::Helpers::TagHelper
10
+ include Rails.application.routes.url_helpers
11
+
12
+ include JqGridMethodMissing
13
+
14
+ attr_accessor :title, :dom_id, :columns_data, :detail_grids, :sub_grid_data,
15
+ :proc_binding, :options
16
+
17
+ DEFAULT_OPTIONS = {:row_num => '10',
18
+ :row_list => [10,25,50,100],
19
+ :sortname => '',
20
+ :sortcolumn => '',
21
+ :sortorder => '',
22
+ :scroll => false,
23
+ :scrollrows => false,
24
+ :shrink_to_fit => true,
25
+ :height => 150,
26
+ :width => 150,
27
+ :gridview => false,
28
+ :error_handler => 'null',
29
+ :inline_edit_handler => 'null',
30
+ :inline_edit => false,
31
+ :add => true,
32
+ :delete => true,
33
+ :edit => true,
34
+ :refresh => true,
35
+ :search => true,
36
+ :editurl => '',
37
+ :autowidth => false,
38
+ :rownumbers => false,
39
+ :footerrow => false,
40
+ :user_data_on_footer => false,
41
+ :initial_empty => false,
42
+ :viewrecords => true,
43
+ :col_names => [],
44
+ }
45
+
46
+
47
+ def initialize(title, dom_id, url_for_options, options={},&option_block)
48
+ self.title = JqGrid.human_attribute_name(title)
49
+ self.dom_id = dom_id
50
+ self.init_jq_grid_js_options DEFAULT_OPTIONS
51
+ self.columns_data = []
52
+ self.detail_grids = []
53
+ self.proc_binding = option_block.binding
54
+ self.options = options
55
+
56
+ #fancier syntax, but heavier to handle
57
+ #self.instance_eval(&option_block) if block_given?
58
+
59
+ self.url my_url_for(url_for_options)
60
+
61
+ if self.is_restful?
62
+ self.editurl my_url_for(url_for_options)
63
+ end
64
+
65
+ option_block.call(self) if block_given?
66
+
67
+ detail_grids_connect_js_to_options
68
+ sub_grid_js_to_options
69
+ end
70
+
71
+ def my_url_for(url_for_options = nil)
72
+ case url_for_options
73
+ when String
74
+ url_for_options
75
+ when nil, Hash
76
+ url_for_options ||= {:action => "blub"}
77
+ url_for_options[:only_path]=true
78
+ url_for(url_for_options)
79
+ else
80
+ polymorphic_url(url_for_options, :only_path => true)
81
+ end
82
+ end
83
+
84
+ def jqgrid(title, dom_id, url, options={} ,&option_block)
85
+ options[:type] ||= :detail_grid
86
+ grid = {:jqgrid => JqGrid.new(title, dom_id, url, options, &option_block), :options => options}
87
+ if options[:type] == :detail_grid
88
+ self.detail_grids << grid
89
+ else
90
+ self.sub_grid_data = grid
91
+ end
92
+ end
93
+
94
+ def pager_id
95
+ "#{dom_id}pager"
96
+ end
97
+
98
+ def columns(*fields,&block)
99
+ fields.each do |field|
100
+ self.column(field,&block)
101
+ end
102
+ end
103
+
104
+ def column(field,&block)
105
+ find_or_create_column(field).set_column_options(&block)
106
+ end
107
+
108
+ def find_or_create_column(field)
109
+ col = self.columns_data.find{|col| col.field == field}
110
+ if col.nil?
111
+ col = JqGridColumn.new(field)
112
+ self.columns_data << col
113
+ end
114
+ col
115
+ end
116
+
117
+ def to_html
118
+ parts =[]
119
+ parts << javascript_tag(jq_grid_function_js)
120
+ parts << "<table id='#{dom_id}'></table> <div id='#{pager_id}'></div> ".html_safe
121
+ parts << detail_grids_html
122
+
123
+ parts.join("\n").html_safe
124
+ end
125
+
126
+ def jq_grid_function_js
127
+ js_str=<<-EO_JS
128
+ jQuery(document).ready(function(){
129
+ #{jq_grid_js}
130
+ #{nav_grid_js}
131
+ });
132
+
133
+ EO_JS
134
+ js_str.html_safe
135
+ end
136
+
137
+ def jq_grid_js
138
+ <<-EO_JS
139
+ var jqgrid_#{dom_id} = jQuery("##{dom_id}").jqGrid({
140
+ caption: "#{self.title}",
141
+ datatype: '#{jq_grid_js_options[:initial_empty] == "true" ? "local" : "json"}',
142
+ pager: '##{pager_id}',
143
+ jsonReader: {
144
+ repeatitems: false, cell: "",
145
+ root: "data",
146
+ page: "currentpage",
147
+ total: "totalpages",
148
+ records: "totalrecords"
149
+ },
150
+ colModel: #{col_models},
151
+ colNames: #{col_names},
152
+ #{options_to_jqgrid_options}
153
+ });
154
+ EO_JS
155
+ end
156
+
157
+ def col_models
158
+ "[" +
159
+ self.columns_data.map {|col|
160
+ "{ " + col.options_to_jqgrid_options + "}\n"
161
+ }.join(",\n") +
162
+ "]"
163
+ end
164
+
165
+ def col_names
166
+ "[" +
167
+ self.columns_data.map {|col|
168
+ col.name.to_json
169
+ }.join(",\n") +
170
+ "]"
171
+ end
172
+
173
+ def nav_grid_js
174
+ params=[nav_grid_parameters]
175
+ params.push(nav_grid_restful_extensions).flatten! if is_restful?
176
+
177
+ <<-EO_JS
178
+ jQuery("##{dom_id}").jqGrid('navGrid','##{pager_id}',#{params.join(",\n")} );
179
+ EO_JS
180
+ end
181
+
182
+ def is_restful?
183
+ 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
232
+
233
+ def detail_grids_html
234
+ self.detail_grids.map do |detail_grid|
235
+ detail_grid[:jqgrid].to_html
236
+ end.join("\n").html_safe
237
+ end
238
+
239
+ def detail_grids_connect_js_to_options
240
+ if self.detail_grids.count > 0
241
+ # it hast to be raw and not << because of execution order and key creation
242
+ on_select_row raw detail_grids_connect_js
243
+ end
244
+ end
245
+
246
+ def detail_grids_connect_js
247
+ parts = ["function(ids,status){"]
248
+
249
+ if self.jq_grid_js_options.has_key? :on_select_row
250
+ parts << "custom_function = #{self.jq_grid_js_options[:on_select_row].escaped_value};"
251
+ parts << "custom_function(ids,status);"
252
+ end
253
+
254
+ parts << self.detail_grids.map do |detail_grid|
255
+ detail_grid_connect_js(detail_grid[:jqgrid],detail_grid[:options])
256
+ end
257
+
258
+ parts << "}"
259
+
260
+ parts.flatten.join("\n").html_safe
261
+ end
262
+
263
+ def detail_grid_connect_js(detail_grid, options)
264
+
265
+ caption = "'#{detail_grid.title}'"
266
+
267
+ if options[:js_caption]
268
+ caption = options[:js_caption]
269
+ elsif options[:caption_append_ids]
270
+ caption = "'#{detail_grid.title}: '+ids"
271
+ end
272
+
273
+ detail_grid_url = detail_grid.get_jq_grid_js_options(:url).escaped_value
274
+ js_url = %Q("#{detail_grid_url}?&id="+ids)
275
+
276
+ if detail_grid.is_restful? && self.is_restful?
277
+ js_url = %Q(#{self.get_jq_grid_js_options(:url).escaped_value}+'/'+ids+#{detail_grid_url})
278
+ js_url ="#{js_url}, editurl:#{js_url}"
279
+ end
280
+
281
+ <<-EO_JS
282
+ jQuery("##{detail_grid.dom_id}").setGridParam({url:#{js_url},page:1})
283
+ .setCaption(#{caption})
284
+ .trigger('reloadGrid');
285
+ EO_JS
286
+ end
287
+
288
+ def sub_grid_js_to_options
289
+ unless self.sub_grid_data.nil?
290
+ grid = self.sub_grid_data[:jqgrid]
291
+ sub_grid true
292
+ # Grid-View and SubGrid doesn't work together http://www.trirand.com/jqgridwiki/doku.php?id=wiki:jq_grid_js_options
293
+ grid_view false
294
+
295
+ if self.sub_grid_data[:options] && self.sub_grid_data[:options][:url_append_ids] && ! (grid.is_restful? && self.is_restful?)
296
+ grid.url raw grid.get_jq_grid_js_options(:url).escaped_value + "+'&id='+row_id"
297
+ end
298
+
299
+ if grid.is_restful? && self.is_restful?
300
+ grid.url raw self.get_jq_grid_js_options(:url).escaped_value + "+'/'+row_id+" + grid.get_jq_grid_js_options(:url).escaped_value
301
+ grid.editurl raw grid.get_jq_grid_js_options(:url).escaped_value
302
+ end
303
+
304
+ sub_grid_row_expanded raw <<-EO_JS
305
+ function(subgrid_id, row_id) {
306
+ subgrid_table_id = subgrid_id+"_t";
307
+ jQuery("#"+subgrid_id).html("<table id='#{grid.dom_id}' class='scroll'></table><div id='#{grid.pager_id}'></div>");
308
+ #{grid.jq_grid_js}
309
+ }
310
+ EO_JS
311
+ end
312
+ end
313
+
314
+ end
315
+ end
@@ -0,0 +1,33 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module RailsJqGrid
5
+ class JqGridColumn
6
+ extend ActiveModel::Translation
7
+
8
+ include JqGridMethodMissing
9
+
10
+ attr_accessor :field
11
+
12
+ def initialize(field, &option_block)
13
+ self.field = field
14
+ self.init_jq_grid_js_options "name" => field, "index" => field
15
+
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
23
+
24
+ def set_column_options(&option_block)
25
+ option_block.call(self) if block_given?
26
+ end
27
+
28
+ def name
29
+ self.jq_grid_js_options[:label]
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,50 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module RailsJqGrid
5
+ module JqGridMethodMissing
6
+ attr_accessor :jq_grid_js_options
7
+
8
+ def method_missing(symbol, *args, &block)
9
+ #method_name = symbol.to_s
10
+ #if method_name.eql?("url_for") || method_name =~ /_path$/
11
+ # call_parent symbol, *args, &block
12
+ #else
13
+ # RAILS_DEFAULT_LOGGER.debug "Method Missing #{symbol} #{args.inspect}"
14
+ self.jq_grid_js_options ||={}
15
+ self.jq_grid_js_options[symbol] = JqGridOptionOrMethod.new(symbol, args[0])
16
+ #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
+
26
+ def raw(*args)
27
+ {:type => :raw, :value => args[0]}
28
+ end
29
+
30
+ def get_jq_grid_js_options(symbol)
31
+ self.jq_grid_js_options[symbol]
32
+ end
33
+
34
+ def init_jq_grid_js_options(new_options)
35
+ self.jq_grid_js_options ||={}
36
+ new_options.each do |key, value|
37
+ self.jq_grid_js_options[key] = JqGridOptionOrMethod.new(key, value)
38
+ end
39
+ end
40
+
41
+ def options_to_jqgrid_options
42
+ jqgrid_options = []
43
+ self.jq_grid_js_options.each_value { |option|
44
+ jqgrid_options << "#{option.escaped_name}: #{option.escaped_value}"
45
+ }
46
+ jqgrid_options.sort.join(",\n ")
47
+ end
48
+
49
+ end
50
+ end