jqgrid_rails 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,71 @@
1
+ require 'jqgrid_rails/jqgrid_rails_helpers'
2
+
3
+ module JqGridRails
4
+ module View
5
+ include ActionView::Helpers::JavaScriptHelper
6
+ include JqGridRails::Helpers
7
+ include ActionView::Helpers::TagHelper
8
+
9
+ # grid_or_id:: JqGrid Object or ID
10
+ # Returns required HTML for grid
11
+ def jqgrid_html(grid_or_id, *args)
12
+ dom_id = grid_or_id.respond_to?(:table_id) ? grid_or_id.table_id : grid_or_id
13
+ output = "<div id=\"#{dom_id}_holder\" style=\"width:100%\"><table id=\"#{dom_id}\" width=\"100%\"></table></div>"
14
+ if((grid_or_id.respond_to?(:has_link_toolbar?) && grid_or_id.has_link_toolbar?) || args.include?(:with_link_toolbar))
15
+ output << "<div id=\"#{dom_id}_linkbar\" class=\"jqgrid_linkbar\"></div>"
16
+ end
17
+ if((grid_or_id.respond_to?(:has_pager?) && grid_or_id.has_pager?) || args.include?(:with_pager))
18
+ output << "<div id=\"#{dom_id}_pager\"></div>"
19
+ end
20
+ output.html_safe
21
+ end
22
+
23
+ # grid:: JqGrid Object
24
+ # Returns required javascript for grid
25
+ def jqgrid_js(grid, *args)
26
+ args.include?(:notag) || args.include?(:raw) ? grid.build : javascript_tag(grid.build)
27
+ end
28
+
29
+ # grid:: JqGrid Object
30
+ # Returns complete jqGrid instructions for building within HTML document
31
+ def jq_grid(grid)
32
+ output = jqgrid_html(grid)
33
+ output << jqgrid_js(grid)
34
+ output.html_safe
35
+ end
36
+ alias_method :jqgrid, :jq_grid
37
+
38
+ def jqgrid_addrow(dom_id, idx, row_hash)
39
+ "jQuery(#{convert_dom_id(dom_id)}).add_row(#{format_type_to_js(idx)}, #{format_type_to_js(row_hash)});".html_safe
40
+ end
41
+
42
+ # dom_id:: DOM ID of existing table
43
+ # options:: Options hash for jqgrid
44
+ def table_to_grid(dom_id, options={})
45
+ [:ondbl_click_row,:on_cell_select].each do |key|
46
+ map_click(key, options)
47
+ end
48
+ options.each do |key,val|
49
+ if(val.is_a?(Hash))
50
+ options[key] = hash_to_callback(val)
51
+ end
52
+ end
53
+ javascript_tag("tableToGrid(#{convert_dom_id(dom_id)}, #{format_type_to_js(options)}); jQuery(#{convert_dom_id(dom_id)}).trigger('reloadGrid');")
54
+ end
55
+
56
+ # dom_id:: Grid DOM ID
57
+ # args:: Extra arguments. :raw for no tag wrapping
58
+ # Reload given table
59
+ def reload_grid(dom_id, *args)
60
+ dom_id = "##{dom_id}" unless dom_id.start_with?('#')
61
+ output = "jQuery('#{dom_id}').trigger('reloadGrid');".html_safe
62
+ if(args.include?(:wrapped))
63
+ javascript_tag(output)
64
+ else
65
+ output
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ ActionView::Base.send :include, JqGridRails::View
@@ -0,0 +1,45 @@
1
+ require 'writeexcel'
2
+
3
+ module JqGridRails
4
+ module WriteExcel
5
+ def write_excel(klass, params, fields, heading_format=nil)
6
+ table = raw_response(klass, params, fields)
7
+ heading_format ||= {:bold => 1, :align => :center, :bg_color => 5}
8
+ path = self.respond_to?(:create_tmpfile) ? create_tmpfile(:name => 'grid_export').path : Rails.root.join('tmp', "grid_export_#{Time.now.to_i.to_s + rand(999).to_s}.xls")
9
+ book = ::WriteExcel.new(path)
10
+ worksheet = book.add_worksheet
11
+ h_format = book.add_format(heading_format)
12
+ formats = {}
13
+ worksheet.split_panes
14
+ fields = scrub_fields(fields)
15
+ headings = ActiveSupport::OrderedHash.new
16
+ if(fields.is_a?(Array))
17
+ fields.each do |x|
18
+ headings[x] = x.to_s.titlecase
19
+ end
20
+ else
21
+ fields.each_pair do |key, value|
22
+ headings[key] = value[:excel_heading] || key.to_s.titlecase
23
+ if(value[:excel_format])
24
+ format = book.add_format(value[:excel_format])
25
+ formats[key] = format
26
+ end
27
+ end
28
+ end
29
+ idx = 0
30
+ headings.each_pair do |key, heading|
31
+ worksheet.write(0, idx, heading, h_format)
32
+ idx += 1
33
+ end
34
+ row = 1
35
+ table['rows'].each do |hash|
36
+ headings.keys.each_with_index do |key, idx|
37
+ worksheet.write(row, idx, hash[key], formats[key])
38
+ end
39
+ row += 1
40
+ end
41
+ book.close
42
+ path
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,9 @@
1
+ module JqGridRails
2
+ class UrlGenerator
3
+ if(Rails.version.to_s.split('.').first == '3')
4
+ include Rails.application.routes.url_helpers
5
+ else
6
+ include ActionController::UrlWriter
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ module JqGridRails
2
+ class Railtie < Rails::Railtie
3
+
4
+ rake_tasks do
5
+ require 'jqgrid_rails/tasks'
6
+ end
7
+
8
+ # We do all our setup in here
9
+ config.to_prepare do
10
+ ActionView::Helpers::AssetTagHelper.register_javascript_expansion(
11
+ :plugins => %w(/jqgrid_rails/javascripts/jqgrid/grid.locale-en.js /jqgrid_rails/javascripts/jqgrid/jquery.jqGrid.min.js)
12
+ )
13
+ ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion(
14
+ :plugins => %w(/jqgrid_rails/stylesheets/jqgrid/ui.jqgrid.css)
15
+ )
16
+ ActionView::Helpers::AssetTagHelper.register_javascript_expansion(
17
+ :jqgrid_rails => %w(/jqgrid_rails/javascripts/jqgrid/grid.locale-en.js /jqgrid_rails/javascripts/jqgrid/jquery.jqGrid.min.js)
18
+ )
19
+ ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion(
20
+ :jqgrid_rails => %w(/jqgrid_rails/stylesheets/jqgrid/ui.jqgrid.css)
21
+ )
22
+ Dir.glob(File.join(File.dirname(__FILE__), '*.rb')).each do |file|
23
+ unless(%w(railtie.rb tasks.rb version.rb).find{|skip| file.ends_with?(skip)})
24
+ require file
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ namespace :jqgrid_rails do
2
+
3
+ desc' Install required assets'
4
+ task :install do
5
+ print 'Checking for asset directory... '
6
+ FileUtils.mkdir_p(File.join(Rails.root, 'public', 'jqgrid_rails'))
7
+ puts 'OK'
8
+ print 'Removing any legacy assets... '
9
+ FileUtils.rm_rf(File.join(Rails.root, 'public', 'jqgrid_rails', '*'))
10
+ puts 'OK'
11
+ print 'Installing assets... '
12
+ FileUtils.cp_r(File.join(File.dirname(__FILE__), '..', '..', 'files', '.'), File.join(Rails.root, 'public', 'jqgrid_rails'))
13
+ puts 'Done'
14
+ end
15
+
16
+ desc 'Upgrade required assets'
17
+ task :upgrade do
18
+ Rake::Task['jqgrid_rails:install'].invoke
19
+ end
20
+
21
+ end
@@ -0,0 +1,17 @@
1
+ module JqGridRails
2
+ class Version
3
+
4
+ attr_reader :major, :minor, :tiny
5
+
6
+ def initialize(version)
7
+ version = version.split('.')
8
+ @major, @minor, @tiny = [version[0].to_i, version[1].to_i, version[2].to_i]
9
+ end
10
+
11
+ def to_s
12
+ "#{@major}.#{@minor}.#{@tiny}"
13
+ end
14
+ end
15
+
16
+ VERSION = Version.new('1.2.0')
17
+ end
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'jqgrid_rails'
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jqgrid_rails
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 2
9
+ - 0
10
+ version: 1.2.0
11
+ platform: ruby
12
+ authors:
13
+ - Chris Roberts
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-01-23 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails_javascript_helpers
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 1
32
+ - 4
33
+ version: "1.4"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rails
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 5
45
+ segments:
46
+ - 2
47
+ - 3
48
+ version: "2.3"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: jqGrid for Rails
52
+ email: chrisroberts.code@gmail.com
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files:
58
+ - README.rdoc
59
+ - LICENSE.rdoc
60
+ - CHANGELOG.rdoc
61
+ files:
62
+ - init.rb
63
+ - jqgrid_rails.gemspec
64
+ - LICENSE.rdoc
65
+ - README.rdoc
66
+ - lib/jqgrid_rails/railtie.rb
67
+ - lib/jqgrid_rails/jqgrid_rails_writeexcel.rb
68
+ - lib/jqgrid_rails/jqgrid_rails_view.rb
69
+ - lib/jqgrid_rails/jqgrid_rails_controller.rb
70
+ - lib/jqgrid_rails/tasks.rb
71
+ - lib/jqgrid_rails/jqgrid_rails_helper.rb
72
+ - lib/jqgrid_rails/jqgrid.rb
73
+ - lib/jqgrid_rails/escape_mappings.rb
74
+ - lib/jqgrid_rails/jqgrid_rails_helpers.rb
75
+ - lib/jqgrid_rails/version.rb
76
+ - lib/jqgrid_rails/jqgrid_rails_generators.rb
77
+ - lib/jqgrid_rails/jqgrid_url_generator.rb
78
+ - lib/jqgrid_rails.rb
79
+ - files/stylesheets/jqgrid/ui.jqgrid.css
80
+ - files/stylesheets/jqgrid/ellipsis-xbl.xml
81
+ - files/javascripts/jqgrid/grid.locale-en.js
82
+ - files/javascripts/jqgrid/README.md
83
+ - files/javascripts/jqgrid/jquery.jqGrid.min.js
84
+ - examples/quick_ref.rdoc
85
+ - examples/usage.rdoc
86
+ - rails/init.rb
87
+ - CHANGELOG.rdoc
88
+ has_rdoc: true
89
+ homepage: http://github.com/chrisroberts/jqgrid_rails
90
+ licenses: []
91
+
92
+ post_install_message:
93
+ rdoc_options: []
94
+
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ requirements: []
116
+
117
+ rubyforge_project:
118
+ rubygems_version: 1.4.2
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: jqGrid for Rails
122
+ test_files: []
123
+