ajax_scaffold_generator 3.1.2 → 3.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -52,7 +52,6 @@ class AjaxScaffoldGenerator < ScaffoldGenerator
52
52
  m.class_collisions class_path, class_name, "#{singular_name}Test"
53
53
 
54
54
  # Model, controller, helper, views, and test directories.
55
- m.directory File.join('app/models', class_path)
56
55
  m.directory File.join('test/unit', class_path)
57
56
  m.directory File.join('test/fixtures', class_path)
58
57
  m.directory File.join('app/controllers', controller_class_path)
@@ -65,7 +64,7 @@ class AjaxScaffoldGenerator < ScaffoldGenerator
65
64
  # Model class, unit test, and fixtures.
66
65
  m.template 'model.rb', File.join('app/models', "#{singular_name}.rb")
67
66
  m.template 'unit_test.rb', File.join('test/unit', "#{singular_name}_test.rb")
68
- m.template 'fixtures.yml', File.join('test/fixtures', "#{singular_name}.yml")
67
+ m.template 'fixtures.yml', File.join('test/fixtures', "#{plural_name}.yml")
69
68
 
70
69
  # Scaffolded forms.
71
70
  m.complex_template 'form.rhtml',
@@ -2,18 +2,16 @@ class <%= controller_class_name %>Controller < ApplicationController
2
2
  include AjaxScaffold::Controller
3
3
 
4
4
  after_filter :clear_flashes
5
+ before_filter :update_params_filter
5
6
 
7
+ def update_params_filter
8
+ update_params :default_scaffold_id => "<%= singular_name %>", :default_sort => nil, :default_sort_direction => "asc"
9
+ end
6
10
  <% unless suffix -%>
7
11
  def index
8
12
  redirect_to :action => 'list'
9
13
  end
10
14
  <% end -%>
11
-
12
- <% for action in unscaffolded_actions -%>
13
- def <%= action %><%= suffix %>
14
- end
15
- <% end -%>
16
-
17
15
  def return_to_main
18
16
  # If you have multiple scaffolds on the same view then you will want to change this to
19
17
  # to whatever controller/action shows all the views
@@ -25,21 +23,20 @@ class <%= controller_class_name %>Controller < ApplicationController
25
23
  end
26
24
 
27
25
  # All posts to change scaffold level variables like sort values or page changes go through this action
28
- def component_update
26
+ def component_update
27
+ @show_wrapper = false # don't show the outer wrapper elements if we are just updating an existing scaffold
29
28
  if request.xhr?
30
29
  # If this is an AJAX request then we just want to delegate to the component to rerender itself
31
30
  component
32
31
  else
33
32
  # If this is from a client without javascript we want to update the session parameters and then delegate
34
33
  # back to whatever page is displaying the scaffold, which will then rerender all scaffolds with these update parameters
35
- update_params :default_scaffold_id => "<%= singular_name %>", :default_sort => nil, :default_sort_direction => "asc"
36
34
  return_to_main
37
35
  end
38
36
  end
39
37
 
40
- def component
41
- update_params :default_scaffold_id => "<%= singular_name %>", :default_sort => nil, :default_sort_direction => "asc"
42
-
38
+ def component
39
+ @show_wrapper = true if @show_wrapper.nil?
43
40
  @sort_sql = <%= model_name %>.scaffold_columns_hash[current_sort(params)].sort_sql rescue nil
44
41
  @sort_by = @sort_sql.nil? ? "#{<%= model_name %>.table_name}.#{<%= model_name %>.primary_key} asc" : @sort_sql + " " + current_sort_direction(params)
45
42
  @paginator, @<%= plural_name %> = paginate(:<%= plural_name %>, :order => @sort_by, :per_page => default_per_page)
@@ -51,7 +48,7 @@ class <%= controller_class_name %>Controller < ApplicationController
51
48
  @<%= singular_name %> = <%= model_name %>.new
52
49
  @successful = true
53
50
 
54
- return render :action => 'new.rjs' if request.xhr?
51
+ return render(:action => 'new.rjs') if request.xhr?
55
52
 
56
53
  # Javascript disabled fallback
57
54
  if @successful
@@ -70,7 +67,7 @@ class <%= controller_class_name %>Controller < ApplicationController
70
67
  flash[:error], @successful = $!.to_s, false
71
68
  end
72
69
 
73
- return render :action => 'create.rjs' if request.xhr?
70
+ return render(:action => 'create.rjs') if request.xhr?
74
71
  if @successful
75
72
  return_to_main
76
73
  else
@@ -87,7 +84,7 @@ class <%= controller_class_name %>Controller < ApplicationController
87
84
  flash[:error], @successful = $!.to_s, false
88
85
  end
89
86
 
90
- return render :action => 'edit.rjs' if request.xhr?
87
+ return render(:action => 'edit.rjs') if request.xhr?
91
88
 
92
89
  if @successful
93
90
  @options = { :scaffold_id => params[:scaffold_id], :action => "update", :id => params[:id] }
@@ -105,7 +102,7 @@ class <%= controller_class_name %>Controller < ApplicationController
105
102
  flash[:error], @successful = $!.to_s, false
106
103
  end
107
104
 
108
- return render :action => 'update.rjs' if request.xhr?
105
+ return render(:action => 'update.rjs') if request.xhr?
109
106
 
110
107
  if @successful
111
108
  return_to_main
@@ -122,7 +119,7 @@ class <%= controller_class_name %>Controller < ApplicationController
122
119
  flash[:error], @successful = $!.to_s, false
123
120
  end
124
121
 
125
- return render :action => 'destroy.rjs' if request.xhr?
122
+ return render(:action => 'destroy.rjs') if request.xhr?
126
123
 
127
124
  # Javascript disabled fallback
128
125
  return_to_main
@@ -131,7 +128,7 @@ class <%= controller_class_name %>Controller < ApplicationController
131
128
  def cancel
132
129
  @successful = true
133
130
 
134
- return render :action => 'cancel.rjs' if request.xhr?
131
+ return render(:action => 'cancel.rjs') if request.xhr?
135
132
 
136
133
  return_to_main
137
134
  end
@@ -1,5 +1,5 @@
1
1
  require File.dirname(__FILE__) + '<%= "/.." * controller_class_nesting_depth %>/../test_helper'
2
- require '<%= controller_file_path %>_controller'
2
+ require '<%= base_controller_file_path %>_controller'
3
3
 
4
4
  # Re-raise errors caught by the controller.
5
5
  class <%= controller_class_name %>Controller; def rescue_action(e) raise e end; end
@@ -14,5 +14,7 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
14
14
  end
15
15
 
16
16
  # A better generator might actually keep updated tests in here, until then its probably better to have nothing than something broken
17
-
17
+ def test_truth
18
+ assert true
19
+ end
18
20
  end
@@ -8,10 +8,11 @@ module AjaxScaffold
8
8
  # based on the given class.
9
9
  def initialize(klass, options)
10
10
  @name = options[:name]
11
- @eval = options[:eval].nil? ? Inflector.tableize(klass.to_s).singularize + "." + @name : options[:eval]
11
+ @eval = options[:eval].nil? ? "h(#{klass.to_s.downcase}.#{@name})" : options[:eval]
12
12
  @label = options[:label].nil? ? Inflector.titleize(@name) : options[:label]
13
13
  @sortable = options[:sortable].nil? ? true : options[:sortable]
14
- @sort_sql = options[:sort_sql].nil? ? klass.table_name + "." + @name : options[:sort_sql] unless !@sortable
14
+ @sort_sql = options[:sort_sql].nil? ? Inflector.tableize(klass.to_s) + "." + @name : options[:sort_sql] unless !@sortable
15
+ @class = options[:class] unless options[:class].nil?
15
16
  end
16
17
 
17
18
  def sortable?
@@ -54,9 +55,7 @@ module AjaxScaffold
54
55
  module Controller
55
56
  include AjaxScaffold::Common
56
57
 
57
- def default_per_page
58
- 25
59
- end
58
+ # Filters
60
59
 
61
60
  def clear_flashes
62
61
  #We want to clear flashes so they don't appear on a page reload
@@ -67,6 +66,12 @@ module AjaxScaffold
67
66
  end
68
67
  end
69
68
 
69
+ # Helper Methods
70
+
71
+ def default_per_page
72
+ 5
73
+ end
74
+
70
75
  def store_or_get_from_session(id_key, value_key)
71
76
  session[id_key][value_key] = params[value_key] if !params[value_key].nil?
72
77
  params[value_key] ||= session[id_key][value_key]
@@ -131,6 +136,12 @@ module AjaxScaffold
131
136
 
132
137
  def column_sort_direction(column_name, params)
133
138
  column_name && current_sort_direction(params) == "asc" ? "desc" : "asc"
139
+
140
+ if column_name && column_name == current_sort(params)
141
+ current_sort_direction(params) == "asc" ? "desc" : "asc"
142
+ else
143
+ "asc"
144
+ end
134
145
  end
135
146
 
136
147
  def column_class(column_name, column_value, sort_column)
@@ -141,8 +152,7 @@ module AjaxScaffold
141
152
  end
142
153
 
143
154
  def loading_indicator_tag(options)
144
- image_filename = "indicator.gif"
145
- "<img src=\"/images/#{image_filename}\" style=\"display: none;\" id=\"#{loading_indicator_id(options)}\" alt=\"loading indicator\" class=\"loading-indicator\" />"
155
+ image_tag "indicator.gif", :style => "display:none;", :id => loading_indicator_id(options), :alt => "loading indicator", :class => "loading-indicator"
146
156
  end
147
157
 
148
158
  # The following are a bunch of helper methods to produce the common scaffold view id's
@@ -6,7 +6,7 @@
6
6
  <td id="<%%= element_cell_id(@options) %>" class="<%%= @options[:action] %>" colspan="<%%= num_columns %>">
7
7
 
8
8
  <%%= form_remote_tag :url => @options.merge(:controller => '<%= controller_file_path %>'),
9
- :loading => "Element.show('#{loading_indicator_id(@options)}');",
9
+ :loading => "Element.show('#{loading_indicator_id(@options)}'); Form.disable('#{element_form_id(@options)}');",
10
10
  :html => { :href => url_for(@options.merge(:controller => '<%= controller_file_path %>')),
11
11
  :id => element_form_id(@options) } %>
12
12
 
@@ -11,6 +11,7 @@ if @successful
11
11
  page.replace_html scaffold_messages_id(@options), :partial => 'messages'
12
12
  else
13
13
  page.replace_html element_messages_id(@create_options), :partial => 'form_messages'
14
+ page << "Form.enable('#{element_form_id(@create_options)}');"
14
15
  page.hide loading_indicator_id(@create_options)
15
16
  end
16
17
 
@@ -12,6 +12,7 @@ if @successful
12
12
  page.replace_html scaffold_messages_id(@options), :partial => 'messages'
13
13
  else
14
14
  page.replace_html element_messages_id(@update_options), :partial => 'form_messages'
15
+ page << "Form.enable('#{element_form_id(@update_options)}');"
15
16
  page.hide loading_indicator_id(@update_options)
16
17
  end
17
18
 
@@ -1,4 +1,4 @@
1
- <%% if not request.xhr? %>
1
+ <%% if @show_wrapper %>
2
2
  <div id="<%%= params[:scaffold_id] %>" class="ajax-scaffold">
3
3
  <div id="<%%= scaffold_content_id(params) %>">
4
4
  <%% end %>
@@ -41,10 +41,9 @@
41
41
  <div class="ajax-scaffold-footer">
42
42
  <%%= render :partial => 'pagination_links', :locals => { :paginator => @paginator } %>
43
43
  </div>
44
- <%% if not request.xhr? %>
44
+ <%% if @show_wrapper %>
45
45
  </div>
46
46
  </div>
47
-
48
47
  <script type="text/javascript">
49
48
  Rico.Corner.round('<%%= params[:scaffold_id] %>', {color: '#005CB8', bgColor: '#fff', compact: true});
50
49
  </script>
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: ajax_scaffold_generator
5
5
  version: !ruby/object:Gem::Version
6
- version: 3.1.2
7
- date: 2006-04-27 00:00:00 -04:00
6
+ version: 3.1.3
7
+ date: 2006-07-13 00:00:00 -06:00
8
8
  summary: Ajax scaffold generator is a rails generator for ajaxified scaffolds
9
9
  require_paths:
10
10
  - lib
@@ -50,8 +50,6 @@ files:
50
50
  - templates/partial_form_messages.rhtml
51
51
  - templates/partial_column_headings.rhtml
52
52
  - templates/model.rb
53
- - templates/lib_content_column_patch.rb
54
- - templates/lib_ajax_scaffold_util.rb
55
53
  - templates/lib_ajax_scaffold.rb
56
54
  - templates/layout.rhtml
57
55
  - templates/information.gif
@@ -1,30 +0,0 @@
1
- module AjaxScaffoldUtil
2
-
3
- def default_per_page
4
- 25
5
- end
6
-
7
- def clear_flashes
8
- #We want to clear flashes so they don't appear on a page reload
9
- if request.xhr?
10
- flash.keys.each do |flash_key|
11
- flash[flash_key] = nil
12
- end
13
- end
14
- end
15
-
16
- def store_or_get_from_session(id_key, value_key)
17
- session[id_key][value_key] = params[value_key] if !params[value_key].nil?
18
- params[value_key] ||= session[id_key][value_key]
19
- end
20
-
21
- def update_params(options)
22
- @scaffold_id = params[:scaffold_id] ||= options[:default_scaffold_id]
23
- session[@scaffold_id] ||= {:sort => options[:default_sort], :sort_direction => options[:default_sort_direction], :page => 1}
24
-
25
- store_or_get_from_session(@scaffold_id, :sort)
26
- store_or_get_from_session(@scaffold_id, :sort_direction)
27
- store_or_get_from_session(@scaffold_id, :page)
28
- end
29
-
30
- end
@@ -1,10 +0,0 @@
1
- class ActiveRecord::Base
2
- def self.get_desired_columns(wanted, cache=nil)
3
- cache ||= nil
4
- if cache.nil?
5
- h= columns_hash
6
- cache = wanted.collect { |n| h[n] }
7
- end
8
- cache
9
- end
10
- end