midas-g_already_grid 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/Manifest.txt +26 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +62 -0
- data/Rakefile +30 -0
- data/lib/g_already_grid/templates/guilded.already_grid.html.erb +64 -0
- data/lib/g_already_grid/view_helpers.rb +239 -0
- data/lib/g_already_grid.rb +12 -0
- data/rails_generators/already_grid_assets/already_grid_assets_generator.rb +22 -0
- data/rails_generators/already_grid_assets/templates/default.css +61 -0
- data/rails_generators/already_grid_assets/templates/guilded.already_grid.js +15 -0
- data/rails_generators/already_grid_assets/templates/guilded.already_grid.min.js +4 -0
- data/rails_generators/already_grid_assets/templates/jquery-already_grid-0.1.js +66 -0
- data/rails_generators/already_grid_assets/templates/jquery-already_grid-0.1.min.js +66 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/g_already_grid_spec.rb +11 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/tasks/rspec.rake +21 -0
- metadata +118 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
g_already_grid.gemspec
|
7
|
+
lib/g_already_grid.rb
|
8
|
+
lib/g_already_grid/templates/guilded.already_grid.html.erb
|
9
|
+
lib/g_already_grid/view_helpers.rb
|
10
|
+
rails_generators/already_grid_assets/already_grid_assets_generator.rb
|
11
|
+
rails_generators/already_grid_assets/templates/default.css
|
12
|
+
rails_generators/already_grid_assets/templates/gridHeadBg.gif
|
13
|
+
rails_generators/already_grid_assets/templates/gridSort.gif
|
14
|
+
rails_generators/already_grid_assets/templates/gridSortAsc.gif
|
15
|
+
rails_generators/already_grid_assets/templates/gridSortDesc.gif
|
16
|
+
rails_generators/already_grid_assets/templates/guilded.already_grid.js
|
17
|
+
rails_generators/already_grid_assets/templates/guilded.already_grid.min.js
|
18
|
+
rails_generators/already_grid_assets/templates/jquery-already_grid-0.1.js
|
19
|
+
rails_generators/already_grid_assets/templates/jquery-already_grid-0.1.min.js
|
20
|
+
script/console
|
21
|
+
script/destroy
|
22
|
+
script/generate
|
23
|
+
spec/g_already_grid_spec.rb
|
24
|
+
spec/spec.opts
|
25
|
+
spec/spec_helper.rb
|
26
|
+
tasks/rspec.rake
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
= g_already_grid
|
2
|
+
|
3
|
+
http://github.com/midas/g_already_grid/tree/master
|
4
|
+
|
5
|
+
|
6
|
+
== DESCRIPTION:
|
7
|
+
|
8
|
+
A Guilded (http://github.com/midas/guilded/tree/master) Rails component that generates a rich grid control from an
|
9
|
+
ActiveRecord collection.
|
10
|
+
|
11
|
+
|
12
|
+
== FEATURES:
|
13
|
+
|
14
|
+
* Easily generate a rich grid from an ActiveRecord collection
|
15
|
+
* Can integrate with mislav-will_paginate to provide paging controls
|
16
|
+
* Can generate sorting links in headers
|
17
|
+
|
18
|
+
|
19
|
+
== INSTALL:
|
20
|
+
|
21
|
+
sudo gem install midas-g_already_grid
|
22
|
+
|
23
|
+
In Rails environemnt.eb file:
|
24
|
+
|
25
|
+
config.gem 'midas-g_already_grid', :version => '1.0.0', :lib => 'g_already_grid', :source => 'http://gems.github.com'
|
26
|
+
|
27
|
+
|
28
|
+
== USAGE:
|
29
|
+
|
30
|
+
<%= %>
|
31
|
+
|
32
|
+
|
33
|
+
== REQUIREMENTS:
|
34
|
+
|
35
|
+
* Rails >= 2.2.0
|
36
|
+
* Guilded >= 0.1.0 (http://github.com/midas/guilded/tree/master)
|
37
|
+
|
38
|
+
|
39
|
+
== LICENSE:
|
40
|
+
|
41
|
+
(The MIT License)
|
42
|
+
|
43
|
+
Copyright (c) 2009 C. Jason Harrelson (midas)
|
44
|
+
|
45
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
46
|
+
a copy of this software and associated documentation files (the
|
47
|
+
'Software'), to deal in the Software without restriction, including
|
48
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
49
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
50
|
+
permit persons to whom the Software is furnished to do so, subject to
|
51
|
+
the following conditions:
|
52
|
+
|
53
|
+
The above copyright notice and this permission notice shall be
|
54
|
+
included in all copies or substantial portions of the Software.
|
55
|
+
|
56
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
57
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
58
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
59
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
60
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
61
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
62
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/g_already_grid'
|
3
|
+
|
4
|
+
# Generate all the Rake tasks
|
5
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
+
$hoe = Hoe.new('g_already_grid', GAlreadyGrid::VERSION) do |p|
|
7
|
+
p.developer('C. Jason Harrelson (midas)', 'jason@lookforwardenterprises.com')
|
8
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
+
p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
10
|
+
p.rubyforge_name = p.name # TODO this is default value
|
11
|
+
# p.extra_deps = [
|
12
|
+
# ['activesupport','>= 2.0.2'],
|
13
|
+
# ]
|
14
|
+
p.extra_dev_deps = [
|
15
|
+
['newgem', ">= #{::Newgem::VERSION}"],
|
16
|
+
['rails', ">= 2.2.0"],
|
17
|
+
['midas-guilded', ">=0.1.0"]
|
18
|
+
]
|
19
|
+
|
20
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
21
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
22
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
23
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
27
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
28
|
+
|
29
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
30
|
+
# task :default => [:spec, :features]
|
@@ -0,0 +1,64 @@
|
|
1
|
+
<div class="<%= grid_class %>" id="<%= grid_id %>">
|
2
|
+
<table cellspacing="0" cellpadding="0">
|
3
|
+
<thead>
|
4
|
+
<tr>
|
5
|
+
<% if do_checkboxes %>
|
6
|
+
<th class="chkBox"><input type="checkbox" class="<%= check_all_class %>" /></th>
|
7
|
+
<% end %>
|
8
|
+
<% unless no_actions %><th>Actions</th><% end %>
|
9
|
+
<% col_titles.each_with_index do |col, i| %>
|
10
|
+
<th><%= sort_by.include?( cols[i].to_sym ) ? sortable_header( col, cols[i], index_rest_method ) : col %></th>
|
11
|
+
<% end %>
|
12
|
+
<th class="right"></th>
|
13
|
+
</tr>
|
14
|
+
</thead>
|
15
|
+
<tbody>
|
16
|
+
<% ar_col.each do |record| %>
|
17
|
+
<tr class="<%= cycle( 'even', 'odd' ) %>">
|
18
|
+
<% shallow ? path_args = [record] : path_args = [scoped_by, record] %>
|
19
|
+
<% if do_checkboxes %>
|
20
|
+
<td class="chkBox"><input type="checkbox" class="<%= checkbox_class %>" name="<%= record.class.to_s.tableize %>[<%= record.id %>]" /></td>
|
21
|
+
<% end %>
|
22
|
+
<% unless no_actions %>
|
23
|
+
<td>
|
24
|
+
<%= link_to 'show', @controller.send( show_rest_method, *path_args ) unless show_rest_method.nil? %>
|
25
|
+
<%= link_to 'edit', @controller.send( edit_rest_method, *path_args ) unless edit_rest_method.nil? %>
|
26
|
+
<%= link_to( 'del', @controller.send( delete_rest_method, *path_args ),
|
27
|
+
:method => :delete, :confirm => del_confirmation ) unless delete_rest_method.nil? %>
|
28
|
+
</td>
|
29
|
+
<% end %>
|
30
|
+
<% cols.each do |col|
|
31
|
+
translate_method = "translate_#{col}".to_sym
|
32
|
+
|
33
|
+
if polymorphic_as && col.to_s.include?( polymorphic_as.to_s )
|
34
|
+
col_name = col.to_s.gsub( /#{polymorphic_as}_/, "" )
|
35
|
+
col_val = record.send( polymorphic_as.to_sym ).send( col_name.to_sym )
|
36
|
+
else
|
37
|
+
col_val = record.send( col.to_sym )
|
38
|
+
end
|
39
|
+
|
40
|
+
if col_val.is_a?( Time )
|
41
|
+
record_val = col_val.to_formatted_s( date_format.to_sym )
|
42
|
+
elsif respond_to?( translate_method )
|
43
|
+
record_val = send( translate_method, col_val )
|
44
|
+
#elsif col_val.is_a?( TrueClass ) || col_val.is_a?( NilClass )
|
45
|
+
# record_val = respond_to?( :translate_boolean ) ? translate_boolean( col_val ) : col_val
|
46
|
+
else
|
47
|
+
record_val = col_val.to_s
|
48
|
+
end %>
|
49
|
+
<td>
|
50
|
+
<%= no_actions ? link_to( record_val, @controller.send( show_rest_method, *path_args ) ) : record_val %>
|
51
|
+
</td>
|
52
|
+
<% end %>
|
53
|
+
<td class="right"></td>
|
54
|
+
<% end %>
|
55
|
+
</tbody>
|
56
|
+
<tfoot>
|
57
|
+
<tr>
|
58
|
+
<td colspan="<%= total_columns.to_s %>">
|
59
|
+
<% if do_paginate %><p><%= will_paginate( ar_col ) %></p><p><%= page_entries_info( ar_col ) %></p><% end %>
|
60
|
+
</td>
|
61
|
+
</tr>
|
62
|
+
</tfoot>
|
63
|
+
</table>
|
64
|
+
</div>
|
@@ -0,0 +1,239 @@
|
|
1
|
+
module GAlreadyGrid
|
2
|
+
module ViewHelpers
|
3
|
+
|
4
|
+
# GUIlded element. This is a grid that is utilizing the already grid jQuery plugin. It is
|
5
|
+
# a progressively enhanced table.
|
6
|
+
#
|
7
|
+
# *parameters*
|
8
|
+
# ar_col:: (required) An ActiveRecord collection.
|
9
|
+
# options:: As follows.
|
10
|
+
#
|
11
|
+
# *options*
|
12
|
+
# id:: (required) The id of the element. Must be unique on the page.
|
13
|
+
# cols:: (required) An array of column names to include in the table. Each position of
|
14
|
+
# the array can be a symbol, string, or hash with 1 entry. The hash entry is the
|
15
|
+
# database field name as a key and the name to use in the gird as the value. Each
|
16
|
+
# key and value in the hash can be a symbol or string.
|
17
|
+
# skin:: The name of the skin to use for this Guilded element. Defaults to default => which is default.css.
|
18
|
+
# exclude_css:: A boolean indicating if Guilded should create a stylesheet inlcude tag for
|
19
|
+
# this element. Defaults to false.
|
20
|
+
# actions:: Action links to include in the action column of grid. A boolean or Array of symbols. When
|
21
|
+
# boolean, if true, add show, edit and delete actions. When boolean, if false, hide actions column.
|
22
|
+
# When Array of symbols, add only actions present in array.
|
23
|
+
# paginate:: A boolean indicating whether to output pagination controls. Defaults to
|
24
|
+
# true. Utilizes will_paginate plugin features.
|
25
|
+
# polymorphic_type:: The type of this polymorphic record. Should be a string representing the class name.
|
26
|
+
# polymorphic_as:: The as used for the polymorphic type. Can be a symbol or string.
|
27
|
+
#
|
28
|
+
def g_already_grid( ar_col, *args )
|
29
|
+
options = args.extract_options!
|
30
|
+
raise ArgumentError, "'cols' option required" unless options.include?( :cols )
|
31
|
+
raise ArgumentError, "'cols' option must be an array of columns" unless options[:cols].is_a? Array
|
32
|
+
|
33
|
+
Guilded::Guilder.instance.add( :already_grid, options, [ 'jquery/jquery-already_grid-0.1.min.js' ] )
|
34
|
+
|
35
|
+
plural_ar_type = ar_col[0].class.to_s.tableize
|
36
|
+
singular_ar_type = plural_ar_type.singularize
|
37
|
+
polymorphic_as = options[:polymorphic_as]
|
38
|
+
polymorphic_type = options[:polymorphic_type]
|
39
|
+
plural_polymorphic_type = polymorphic_type.to_s.tableize if polymorphic_type
|
40
|
+
singular_polymorphic_type = plural_polymorphic_type.singularize if polymorphic_type
|
41
|
+
options[:checkbox_class] = "chk"
|
42
|
+
options[:check_all_class] = "checkAll"
|
43
|
+
date_format = options[:date_format] || :default
|
44
|
+
scoped_by = options.delete( :scoped_by )
|
45
|
+
shallow = options.delete( :shallow ) || false
|
46
|
+
|
47
|
+
# Resolve sorting
|
48
|
+
if options[:sort]
|
49
|
+
if options[:sort].is_a?( Array )
|
50
|
+
sort_by = options[:sort].map { |a| a.to_sym }
|
51
|
+
elsif options[:sort].is_a?( Symbol ) || options[:sort].is_a?( String )
|
52
|
+
sort_by = Array.new << options[:sort].to_sym
|
53
|
+
else
|
54
|
+
throw "Option 'sort' must be a string, symbol or an array of strings or symbols."
|
55
|
+
end
|
56
|
+
end
|
57
|
+
sort_by = Array.new unless sort_by
|
58
|
+
|
59
|
+
# Set up the options booleans we need to decide on output HTML
|
60
|
+
no_actions = !(options[:actions] == true || options[:actions] == 'true')
|
61
|
+
no_actions ||= true
|
62
|
+
|
63
|
+
if no_actions
|
64
|
+
options[:actions] = [ :show ]
|
65
|
+
elsif !options[:actions].is_a?( Array )
|
66
|
+
options[:actions] = [ :show, :edit, :delete ]
|
67
|
+
end
|
68
|
+
|
69
|
+
controller_name_parts = @controller.class.to_s.underscore.split( '/' )
|
70
|
+
controller_name_parts.pop
|
71
|
+
pre = controller_name_parts.join( '_' )
|
72
|
+
|
73
|
+
unless ar_col.empty?
|
74
|
+
if options.has_key?( :index_path_helper )
|
75
|
+
index_rest_method = options[:index_path_helper].to_s
|
76
|
+
elsif scoped_by
|
77
|
+
if pre.empty?
|
78
|
+
index_rest_method = "#{scoped_by.class.to_s.underscore}_#{plural_ar_type}_path" if ar_col.size > 0
|
79
|
+
else
|
80
|
+
index_rest_method = "#{pre}_#{scoped_by.class.to_s.underscore}_#{plural_ar_type}_path" if ar_col.size > 0
|
81
|
+
end
|
82
|
+
elsif pre.empty?
|
83
|
+
index_rest_method = "#{plural_ar_type}_path" if ar_col.size > 0
|
84
|
+
index_rest_method.gsub!( /#{plural_ar_type}/, "#{plural_polymorphic_type}") if plural_polymorphic_type
|
85
|
+
else
|
86
|
+
index_rest_method = "#{pre}_#{plural_ar_type}_path" if ar_col.size > 0
|
87
|
+
index_rest_method.gsub!( /#{plural_ar_type}/, "#{plural_polymorphic_type}") if plural_polymorphic_type
|
88
|
+
end
|
89
|
+
|
90
|
+
if options.has_key?( :show_path_helper )
|
91
|
+
show_rest_method = options[:show_path_helper].to_s
|
92
|
+
elsif scoped_by && !shallow
|
93
|
+
if pre.empty?
|
94
|
+
show_rest_method = "#{scoped_by.class.to_s.underscore}_#{singular_ar_type}_path" if ar_col.size > 0
|
95
|
+
else
|
96
|
+
show_rest_method = "#{pre}_#{scoped_by.class.to_s.underscore}_#{singular_ar_type }_path" if ar_col.size > 0
|
97
|
+
end
|
98
|
+
elsif pre.empty?
|
99
|
+
show_rest_method = "#{singular_ar_type}_path" if ar_col.size > 0
|
100
|
+
show_rest_method.gsub!( /#{singular_ar_type}/, "#{singular_polymorphic_type}") if singular_polymorphic_type
|
101
|
+
else
|
102
|
+
show_rest_method = "#{pre}_#{singular_ar_type}_path" if ar_col.size > 0
|
103
|
+
show_rest_method.gsub!( /#{singular_ar_type}/, "#{singular_polymorphic_type}") if singular_polymorphic_type
|
104
|
+
end
|
105
|
+
|
106
|
+
unless no_actions
|
107
|
+
# Build the name of the REST path helper methods
|
108
|
+
if options.has_key?( :edit_path_helper )
|
109
|
+
edit_rest_method = options[:edit_path_helper].to_s
|
110
|
+
elsif scoped_by && !shallow
|
111
|
+
if pre.empty?
|
112
|
+
edit_rest_method = "edit_#{scoped_by.class.to_s.underscore}_#{singular_ar_type}_path" if ar_col.size > 0
|
113
|
+
else
|
114
|
+
edit_rest_method = "edit_#{pre}_#{scoped_by.class.to_s.underscore}_#{singular_ar_type }_path" if ar_col.size > 0
|
115
|
+
end
|
116
|
+
elsif pre.empty?
|
117
|
+
edit_rest_method = "edit_#{singular_ar_type}_path" if ar_col.size > 0
|
118
|
+
else
|
119
|
+
edit_rest_method = "edit_#{pre}_#{singular_ar_type}_path" if ar_col.size > 0
|
120
|
+
end
|
121
|
+
|
122
|
+
if options.has_key?( :delete_path_helper )
|
123
|
+
delete_rest_method = options[:delete_path_helper].to_s
|
124
|
+
elsif pre.empty?
|
125
|
+
delete_rest_method = "#{singular_ar_type}_path" if ar_col.size > 0
|
126
|
+
else
|
127
|
+
delete_rest_method = "#{pre}_#{singular_ar_type}_path" if ar_col.size > 0
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
cols, col_titles = Guilded::Rails::Helpers.resolve_field_methods_and_titles( options[:cols], ar_col[0] )
|
133
|
+
|
134
|
+
do_paginate = true
|
135
|
+
begin
|
136
|
+
if options[:paginate] == false || options[:paginate] == 'false' #ar_col.total_pages <= 1
|
137
|
+
do_paginate = false
|
138
|
+
end
|
139
|
+
rescue => e
|
140
|
+
if e.is_a? NoMethodError # This just means no will_paginate methods are present.
|
141
|
+
do_paginate = false
|
142
|
+
else
|
143
|
+
throw e
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
do_checkboxes = true
|
148
|
+
do_checkboxes = false if options[:checkboxes] == false || options[:checkboxes] == 'false'
|
149
|
+
options[:checkboxes] = do_checkboxes unless options[:checkboxes]
|
150
|
+
|
151
|
+
total_columns = cols.size
|
152
|
+
total_columns = total_columns + 1 if do_checkboxes
|
153
|
+
total_columns = total_columns + 1 unless no_actions
|
154
|
+
options[:total_columns] = total_columns
|
155
|
+
|
156
|
+
vars = {
|
157
|
+
:no_actions => no_actions, :actions => options[:actions], :do_checkboxes => do_checkboxes,
|
158
|
+
:total_columns => total_columns, :del_confirmation => 'Are you sure you would like to delete this record?',
|
159
|
+
:col_titles => col_titles, :cols => cols, :grid_class => 'already-grid', :checkbox_class => options[:checkbox_class],
|
160
|
+
:check_all_class => options[:check_all_class], :grid_id => options[:id], :ar_col => ar_col, :do_paginate => do_paginate,
|
161
|
+
:date_format => date_format, :polymorphic_type => polymorphic_type, :polymorphic_as => polymorphic_as,
|
162
|
+
:sort_by => sort_by, :index_rest_method => index_rest_method, :shallow => shallow, :scoped_by => scoped_by
|
163
|
+
}
|
164
|
+
|
165
|
+
if ( !options[:actions].nil? && options[:actions].include?( :show ) ) || options[:actions].nil?
|
166
|
+
vars.merge!( :show_rest_method => show_rest_method )
|
167
|
+
else
|
168
|
+
vars.merge!( :show_rest_method => nil )
|
169
|
+
end
|
170
|
+
if ( !options[:actions].nil? && options[:actions].include?( :edit ) ) || options[:actions].nil?
|
171
|
+
vars.merge!( :edit_rest_method => edit_rest_method )
|
172
|
+
else
|
173
|
+
vars.merge!( :edit_rest_method => nil )
|
174
|
+
end
|
175
|
+
if ( !options[:actions].nil? && options[:actions].include?( :delete ) ) || options[:actions].nil?
|
176
|
+
vars.merge!( :delete_rest_method => delete_rest_method )
|
177
|
+
else
|
178
|
+
vars.merge!( :delete_rest_method => nil )
|
179
|
+
end
|
180
|
+
|
181
|
+
path = File.dirname(__FILE__)
|
182
|
+
full_path = "#{path}/templates/guilded.already_grid.html.erb"
|
183
|
+
self.render( :file => full_path, :use_full_path => false, :locals => vars )
|
184
|
+
end
|
185
|
+
|
186
|
+
private
|
187
|
+
|
188
|
+
# Creates a link to sort this column of a table. Utilizes the link_to helper,
|
189
|
+
# but resolves sort by, direction and adds correct CSS classes for UI elements to
|
190
|
+
# be displayed.
|
191
|
+
#
|
192
|
+
# *parameters*
|
193
|
+
# name:: The text to use for the link
|
194
|
+
# method:: The actual name of this column's field.
|
195
|
+
# path:: (Symbol) The name of the path method to call from routing.
|
196
|
+
# options:: see link_to helper.
|
197
|
+
#
|
198
|
+
def sortable_header( name, method, path, options={} )
|
199
|
+
|
200
|
+
is_sorted_link = ( method.to_s == params[:order].to_s )
|
201
|
+
|
202
|
+
if is_sorted_link
|
203
|
+
if params[:direction] == "ASC"
|
204
|
+
options.merge! :class => "sort-asc"
|
205
|
+
elsif params[:direction] == "DESC"
|
206
|
+
options.merge! :class => "sort-desc"
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
direction = "ASC"
|
211
|
+
direction = "DESC" if params[:direction] == "ASC"
|
212
|
+
|
213
|
+
sort_options = { :order => method, :direction => direction }
|
214
|
+
sort_options.merge!( :filter => params[:filter] ) if params[:filter]
|
215
|
+
unsorted_options = { :order => method, :direction => 'ASC' } # always sort ascending on first sort
|
216
|
+
unsorted_options.merge!( :filter => params[:filter] ) if params[:filter]
|
217
|
+
|
218
|
+
path = path.to_sym unless path.is_a?( Symbol )
|
219
|
+
|
220
|
+
if is_sorted_link
|
221
|
+
# Handle the currently sorted by link
|
222
|
+
path = @controller.send( path, sort_options )
|
223
|
+
else
|
224
|
+
# Handle the the other currently unsorted by links (we will always sort in
|
225
|
+
# an ASC direction the first time)
|
226
|
+
path = @controller.send( path, unsorted_options )
|
227
|
+
end
|
228
|
+
#end
|
229
|
+
|
230
|
+
# Load the params to an args array to send to the link_to helper
|
231
|
+
args = Array.new
|
232
|
+
args << name << path << options
|
233
|
+
|
234
|
+
link_to( *args )
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
239
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'g_already_grid/view_helpers'
|
5
|
+
|
6
|
+
module GAlreadyGrid
|
7
|
+
VERSION = '1.0.0'
|
8
|
+
end
|
9
|
+
|
10
|
+
if defined?( ActionView::Base )
|
11
|
+
ActionView::Base.send( :include, GAlreadyGrid::ViewHelpers ) unless ActionView::Base.include?( GAlreadyGrid::ViewHelpers )
|
12
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class AlreadyGridAssetsGenerator < Rails::Generator::Base
|
2
|
+
def initialize(runtime_args, runtime_options = {})
|
3
|
+
super
|
4
|
+
end
|
5
|
+
|
6
|
+
def manifest
|
7
|
+
record do |m|
|
8
|
+
m.file "guilded.already_grid.js", "public/javascripts/guilded.already_grid.js"
|
9
|
+
m.file "guilded.already_grid.min.js", "public/javascripts/guilded.already_grid.min.js"
|
10
|
+
m.directory "public/javascripts/jquery"
|
11
|
+
m.file "jquery-already_grid-0.1.js", "public/javascripts/jquery/jquery-already_grid-0.1.js"
|
12
|
+
m.file "jquery-already_grid-0.1.min.js", "public/javascripts/jquery/jquery-already_grid-0.1.min.js"
|
13
|
+
m.directory "public/stylesheets/guilded/already_grid"
|
14
|
+
m.directory "public/stylesheets/guilded/already_grid/default"
|
15
|
+
m.file "default.css", "public/stylesheets/guilded/already_grid/default.css"
|
16
|
+
m.file "gridHeadBg.gif", "public/stylesheets/guilded/already_grid/default/gridHeadBg.gif"
|
17
|
+
m.file "gridSort.gif", "public/stylesheets/guilded/already_grid/default/gridSort.gif"
|
18
|
+
m.file "gridSortAsc.gif", "public/stylesheets/guilded/already_grid/default/gridSortAsc.gif"
|
19
|
+
m.file "gridSortDesc.gif", "public/stylesheets/guilded/already_grid/default/gridSortDesc.gif"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
.already-grid table {
|
2
|
+
width:100%;
|
3
|
+
position:relative;
|
4
|
+
top:0;
|
5
|
+
border-collapse:collapse !important;
|
6
|
+
}
|
7
|
+
.already-grid table thead {
|
8
|
+
text-align:left;
|
9
|
+
color:#636363;
|
10
|
+
background:url(/stylesheets/guilded/already_grid/default/gridHeadBg.gif) #e9e9e9 repeat-x;
|
11
|
+
font-weight:normal;
|
12
|
+
}
|
13
|
+
.already-grid table thead th {
|
14
|
+
padding:0.6em 0.75em;
|
15
|
+
border-top:1px solid #c2c2c2;
|
16
|
+
border-bottom:1px solid #c2c2c2;
|
17
|
+
border-right:1px solid #c2c2c2;
|
18
|
+
border-left-color:#c2c2c2;
|
19
|
+
white-space:nowrap;
|
20
|
+
font-size:0.7em;
|
21
|
+
}
|
22
|
+
.already-grid table tbody tr:hover a { color:#585858; }
|
23
|
+
.already-grid table tbody td {
|
24
|
+
border-bottom: 1px solid #e5e7f2;
|
25
|
+
border-right: 1px solid #e5e7f2;
|
26
|
+
font-size: 0.8em;
|
27
|
+
white-space: nowrap
|
28
|
+
}
|
29
|
+
.already-grid table tbody td a {
|
30
|
+
display: block;
|
31
|
+
padding: 0.5em 0.75em;
|
32
|
+
}
|
33
|
+
.already-grid table tfoot td {
|
34
|
+
padding: 0.75em;
|
35
|
+
text-align: center;
|
36
|
+
color: #898989;
|
37
|
+
font-size: 0.75em;
|
38
|
+
}
|
39
|
+
.already-grid table tbody .odd { background:#f0f5fa; }
|
40
|
+
.already-grid table tbody .selected { background:#029dd7; }
|
41
|
+
.already-grid table tbody .selected td a { color: white; }
|
42
|
+
|
43
|
+
.already-grid table th a {
|
44
|
+
color:#636363;
|
45
|
+
text-decoration: underline;
|
46
|
+
background: url(/stylesheets/guilded/already_grid/default/gridSort.gif) right no-repeat;
|
47
|
+
display: block;
|
48
|
+
padding-right: 10px;
|
49
|
+
}
|
50
|
+
|
51
|
+
.already-grid table th a:hover {color:black;}
|
52
|
+
|
53
|
+
.already-grid table .sort-asc {
|
54
|
+
background: url(/stylesheets/guilded/already_grid/default/gridSortAsc.gif) right no-repeat;
|
55
|
+
display: block;
|
56
|
+
}
|
57
|
+
|
58
|
+
.already-grid table .sort-desc {
|
59
|
+
background: url(/stylesheets/guilded/already_grid/default/gridSortDesc.gif) right no-repeat;
|
60
|
+
display: block;
|
61
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/* Guilded Already 1.0.0
|
2
|
+
* Copyright (c) 2009 C. Jason Harrelson (midas)
|
3
|
+
* Guilded Flash Growler is licensed under the terms of the MIT License */
|
4
|
+
|
5
|
+
g.alreadyGridInit = function( options )
|
6
|
+
{
|
7
|
+
if( g.beforeAlreadyGridInit )
|
8
|
+
g.beforeAlreadyGridInit( options );
|
9
|
+
|
10
|
+
var grid = $j( '#' + options.id );
|
11
|
+
grid.alreadyGrid( options );
|
12
|
+
|
13
|
+
if( g.afterAlreadyGridInit )
|
14
|
+
g.afterAlreadyGridInit( options );
|
15
|
+
};
|
@@ -0,0 +1,4 @@
|
|
1
|
+
/* Guilded Already 1.0.0
|
2
|
+
* Copyright (c) 2009 C. Jason Harrelson (midas)
|
3
|
+
* Guilded Flash Growler is licensed under the terms of the MIT License */
|
4
|
+
g.alreadyGridInit=function(options){if(g.beforeAlreadyGridInit)g.beforeAlreadyGridInit(options);var grid=$j('#'+options.id);grid.alreadyGrid(options);if(g.afterAlreadyGridInit)g.afterAlreadyGridInit(options);};
|
@@ -0,0 +1,66 @@
|
|
1
|
+
(function($){
|
2
|
+
|
3
|
+
jQuery.fn.alreadyGrid = function( /* Object literal */ options )
|
4
|
+
{
|
5
|
+
opts = $j.extend( $j.fn.alreadyGrid.defaults, options );
|
6
|
+
|
7
|
+
// Set up check box events
|
8
|
+
checkAllBox = $j( '.' + opts.check_all_class );
|
9
|
+
checkboxes = $j( '.' + opts.checkbox_class );
|
10
|
+
$j( 'document' ).ready( updateSelecteds );
|
11
|
+
checkAllBox.click( checkAllClicked );
|
12
|
+
checkboxes.click( checkboxClicked );
|
13
|
+
|
14
|
+
return jQuery;
|
15
|
+
}
|
16
|
+
|
17
|
+
/* *************** public *************** */
|
18
|
+
|
19
|
+
jQuery.fn.alreadyGrid.defaults =
|
20
|
+
{
|
21
|
+
paginate: true,
|
22
|
+
checkboxes: false,
|
23
|
+
checkbox_class: 'chk',
|
24
|
+
check_all_class: 'checkAll'
|
25
|
+
};
|
26
|
+
|
27
|
+
/* *************** private *************** */
|
28
|
+
|
29
|
+
checkAllClicked = function( /* jquery Event */ e )
|
30
|
+
{
|
31
|
+
if( $j( this ).is(':checked') )
|
32
|
+
{
|
33
|
+
//$j( '.' + opts.checkbox_class ).click();
|
34
|
+
checkboxes.attr( 'checked', true );
|
35
|
+
checkboxes.parent().parent().addClass( 'selected' );
|
36
|
+
}
|
37
|
+
else
|
38
|
+
{
|
39
|
+
checkboxes.attr( 'checked', false );
|
40
|
+
checkboxes.parent().parent().removeClass( 'selected' );
|
41
|
+
}
|
42
|
+
};
|
43
|
+
|
44
|
+
checkboxClicked = function( /* jquery Event */ e )
|
45
|
+
{
|
46
|
+
if( $j( this ).is(':checked') )
|
47
|
+
$j( this ).parent().parent().addClass( 'selected' );
|
48
|
+
else
|
49
|
+
{
|
50
|
+
$j( this ).parent().parent().removeClass( 'selected' );
|
51
|
+
if( checkAllBox.is(':checked') )
|
52
|
+
{
|
53
|
+
checkAllBox.attr( 'checked', false );
|
54
|
+
}
|
55
|
+
}
|
56
|
+
};
|
57
|
+
|
58
|
+
/* Used after load to update selected based on check boxes when the
|
59
|
+
* grid loads. */
|
60
|
+
updateSelecteds = function( /* jquery Event */ e )
|
61
|
+
{
|
62
|
+
var checkboxes = $j( "." + opts.checkbox_class + "[checked]");
|
63
|
+
checkboxes.parent().parent().addClass( 'selected' );
|
64
|
+
};
|
65
|
+
|
66
|
+
})(jQuery);
|
@@ -0,0 +1,66 @@
|
|
1
|
+
(function($){
|
2
|
+
|
3
|
+
jQuery.fn.alreadyGrid = function( /* Object literal */ options )
|
4
|
+
{
|
5
|
+
opts = $j.extend( $j.fn.alreadyGrid.defaults, options );
|
6
|
+
|
7
|
+
// Set up check box events
|
8
|
+
checkAllBox = $j( '.' + opts.check_all_class );
|
9
|
+
checkboxes = $j( '.' + opts.checkbox_class );
|
10
|
+
$j( 'document' ).ready( updateSelecteds );
|
11
|
+
checkAllBox.click( checkAllClicked );
|
12
|
+
checkboxes.click( checkboxClicked );
|
13
|
+
|
14
|
+
return jQuery;
|
15
|
+
}
|
16
|
+
|
17
|
+
/* *************** public *************** */
|
18
|
+
|
19
|
+
jQuery.fn.alreadyGrid.defaults =
|
20
|
+
{
|
21
|
+
paginate: true,
|
22
|
+
checkboxes: false,
|
23
|
+
checkbox_class: 'chk',
|
24
|
+
check_all_class: 'checkAll'
|
25
|
+
};
|
26
|
+
|
27
|
+
/* *************** private *************** */
|
28
|
+
|
29
|
+
checkAllClicked = function( /* jquery Event */ e )
|
30
|
+
{
|
31
|
+
if( $j( this ).is(':checked') )
|
32
|
+
{
|
33
|
+
//$j( '.' + opts.checkbox_class ).click();
|
34
|
+
checkboxes.attr( 'checked', true );
|
35
|
+
checkboxes.parent().parent().addClass( 'selected' );
|
36
|
+
}
|
37
|
+
else
|
38
|
+
{
|
39
|
+
checkboxes.attr( 'checked', false );
|
40
|
+
checkboxes.parent().parent().removeClass( 'selected' );
|
41
|
+
}
|
42
|
+
};
|
43
|
+
|
44
|
+
checkboxClicked = function( /* jquery Event */ e )
|
45
|
+
{
|
46
|
+
if( $j( this ).is(':checked') )
|
47
|
+
$j( this ).parent().parent().addClass( 'selected' );
|
48
|
+
else
|
49
|
+
{
|
50
|
+
$j( this ).parent().parent().removeClass( 'selected' );
|
51
|
+
if( checkAllBox.is(':checked') )
|
52
|
+
{
|
53
|
+
checkAllBox.attr( 'checked', false );
|
54
|
+
}
|
55
|
+
}
|
56
|
+
};
|
57
|
+
|
58
|
+
/* Used after load to update selected based on check boxes when the
|
59
|
+
* grid loads. */
|
60
|
+
updateSelecteds = function( /* jquery Event */ e )
|
61
|
+
{
|
62
|
+
var checkboxes = $j( "." + opts.checkbox_class + "[checked]");
|
63
|
+
checkboxes.parent().parent().addClass( 'selected' );
|
64
|
+
};
|
65
|
+
|
66
|
+
})(jQuery);
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/g_already_grid.rb'}"
|
9
|
+
puts "Loading g_already_grid gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: midas-g_already_grid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- C. Jason Harrelson (midas)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-12 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: newgem
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.3
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rails
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.2.0
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: midas-guilded
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.1.0
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: hoe
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.8.0
|
54
|
+
version:
|
55
|
+
description: A Guilded (http://github.com/midas/guilded/tree/master) Rails component that generates a rich grid control from an ActiveRecord collection.
|
56
|
+
email:
|
57
|
+
- jason@lookforwardenterprises.com
|
58
|
+
executables: []
|
59
|
+
|
60
|
+
extensions: []
|
61
|
+
|
62
|
+
extra_rdoc_files:
|
63
|
+
- History.txt
|
64
|
+
- Manifest.txt
|
65
|
+
- PostInstall.txt
|
66
|
+
- README.rdoc
|
67
|
+
files:
|
68
|
+
- History.txt
|
69
|
+
- Manifest.txt
|
70
|
+
- PostInstall.txt
|
71
|
+
- README.rdoc
|
72
|
+
- Rakefile
|
73
|
+
- lib/g_already_grid.rb
|
74
|
+
- lib/g_already_grid/templates/guilded.already_grid.html.erb
|
75
|
+
- lib/g_already_grid/view_helpers.rb
|
76
|
+
- rails_generators/already_grid_assets/already_grid_assets_generator.rb
|
77
|
+
- rails_generators/already_grid_assets/templates/bg.gif
|
78
|
+
- rails_generators/already_grid_assets/templates/default.css
|
79
|
+
- rails_generators/already_grid_assets/templates/guilded.already_grid.js
|
80
|
+
- rails_generators/already_grid_assets/templates/guilded.already_grid.min.js
|
81
|
+
- rails_generators/already_grid_assets/templates/jquery-already_grid-0.1.js
|
82
|
+
- rails_generators/already_grid_assets/templates/jquery-already_grid-0.1.min.js
|
83
|
+
- script/console
|
84
|
+
- script/destroy
|
85
|
+
- script/generate
|
86
|
+
- spec/g_already_grid_spec.rb
|
87
|
+
- spec/spec.opts
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
- tasks/rspec.rake
|
90
|
+
has_rdoc: true
|
91
|
+
homepage: http://github.com/midas/g_already_grid/tree/master
|
92
|
+
post_install_message: PostInstall.txt
|
93
|
+
rdoc_options:
|
94
|
+
- --main
|
95
|
+
- README.rdoc
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: "0"
|
103
|
+
version:
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: "0"
|
109
|
+
version:
|
110
|
+
requirements: []
|
111
|
+
|
112
|
+
rubyforge_project: g_already_grid
|
113
|
+
rubygems_version: 1.2.0
|
114
|
+
signing_key:
|
115
|
+
specification_version: 2
|
116
|
+
summary: A Guilded (http://github.com/midas/guilded/tree/master) Rails component that generates a rich grid control from an ActiveRecord collection.
|
117
|
+
test_files: []
|
118
|
+
|