ajax_scaffold_generator 3.0.4 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ class AjaxScaffoldingSandbox < ScaffoldingSandbox
5
5
  Proc.new { |record, column| "<div class=\"form-element\">\n <label for=\"#{record}_#{column.name}\">#{column.human_name}</label>\n #{input(record, column.name)}\n</div>\n" }
6
6
  end
7
7
 
8
- def all_input_tags(record, record_name, options)
8
+ def all_input_tags(record, record_name, options)
9
9
  input_block = options[:input_block] || default_input_block
10
10
 
11
11
  if !options[:exclude].blank?
@@ -49,8 +49,12 @@ class AjaxScaffoldGenerator < ScaffoldGenerator
49
49
 
50
50
  # Check for class naming collisions.
51
51
  m.class_collisions controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}ControllerTest", "#{controller_class_name}Helper"
52
+ m.class_collisions class_path, class_name, "#{singular_name}Test"
52
53
 
53
- # Controller, helper, views, and test directories.
54
+ # Model, controller, helper, views, and test directories.
55
+ m.directory File.join('app/models', class_path)
56
+ m.directory File.join('test/unit', class_path)
57
+ m.directory File.join('test/fixtures', class_path)
54
58
  m.directory File.join('app/controllers', controller_class_path)
55
59
  m.directory File.join('app/helpers', controller_class_path)
56
60
  m.directory File.join('app/views', controller_class_path, controller_file_name)
@@ -58,9 +62,11 @@ class AjaxScaffoldGenerator < ScaffoldGenerator
58
62
  m.directory File.join('public/images')
59
63
  m.directory File.join('test/functional', controller_class_path)
60
64
 
61
- # Depend on model generator but skip if the model exists.
62
- m.dependency 'model', [singular_name], :collision => :skip, :skip_migration => true
63
-
65
+ # Model class, unit test, and fixtures.
66
+ m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
67
+ m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
68
+ m.template 'fixtures.yml', File.join('test/fixtures', class_path, "#{table_name}.yml")
69
+
64
70
  # Scaffolded forms.
65
71
  m.complex_template 'form.rhtml',
66
72
  File.join('app/views',
@@ -129,10 +135,6 @@ class AjaxScaffoldGenerator < ScaffoldGenerator
129
135
  File.join('app/helpers',
130
136
  controller_class_path,
131
137
  "#{controller_file_name}_helper.rb")
132
-
133
- m.template 'ajax_scaffold_helper.rb',
134
- File.join('app/helpers',
135
- "ajax_scaffold_helper.rb")
136
138
 
137
139
  # Layout and stylesheet.
138
140
  m.template 'layout.rhtml',
@@ -164,19 +166,15 @@ class AjaxScaffoldGenerator < ScaffoldGenerator
164
166
  end
165
167
 
166
168
  def scaffold_rjs_templates
167
- %w( create destroy edit new update )
169
+ %w( create destroy edit new update cancel )
168
170
  end
169
171
 
170
172
  def scaffold_partials
171
173
  %w( form_messages messages column_headings new_edit pagination_links )
172
174
  end
173
-
174
- def scaffold_helpers
175
- %w( helper ajax_scaffold_helper )
176
- end
177
175
 
178
176
  def scaffold_lib
179
- %w( ajax_scaffold_util content_column_patch )
177
+ %w( ajax_scaffold )
180
178
  end
181
179
 
182
180
  def scaffold_images
@@ -1,5 +1,5 @@
1
1
  /*
2
- AjaxScaffoldGenerator version 3.0.0
2
+ AjaxScaffoldGenerator version 3.1.0
3
3
  (c) 2006 Richard White <rrwhite@gmail.com>
4
4
 
5
5
  AjaxScaffoldGenerator is freely distributable under the terms of an MIT-style license.
@@ -16,11 +16,6 @@ margin: 0;
16
16
  padding: 0;
17
17
  }
18
18
 
19
- .ajax-scaffold a {
20
- color: #06c;
21
- text-decoration: none;
22
- }
23
-
24
19
  .ajax-scaffold {
25
20
  margin: 5px 0;
26
21
  }
@@ -29,6 +24,15 @@ margin: 5px 0;
29
24
  width: 100%;
30
25
  }
31
26
 
27
+ .ajax-scaffold a {
28
+ color: #06c;
29
+ text-decoration: none;
30
+ }
31
+
32
+ .ajax-scaffold a:hover {
33
+ background: #ff8;
34
+ }
35
+
32
36
  /* Header Styling
33
37
  ======================== */
34
38
 
@@ -69,26 +73,55 @@ text-align: right;
69
73
  margin-bottom: -3px;
70
74
  }
71
75
 
76
+ /* Header Styling : Nested
77
+ ======================== */
78
+
79
+ .ajax-scaffold .ajax-scaffold {
80
+ margin: 2px 5px;
81
+ }
82
+
83
+ .ajax-scaffold .ajax-scaffold .ajax-scaffold-header h2 {
84
+ font-size: 13px;
85
+ font-weight: bold;
86
+ }
87
+
88
+ .ajax-scaffold .ajax-scaffold .ajax-scaffold-header div.actions a {
89
+ font: bold 11px verdana, sans-serif;
90
+ padding: 0 2px 1px 17px;
91
+ }
92
+
93
+ .ajax-scaffold .ajax-scaffold .ajax-scaffold-header div.actions {
94
+ top: 4px;
95
+ }
96
+
72
97
  /* Table Column Headers
73
98
  ============================= */
74
99
 
75
100
  .ajax-scaffold th {
76
- font-size: 11px;
77
- color: #fff;
78
101
  background: #555;
79
- letter-spacing: 0;
80
- font-family: Arial, sans-serif;
81
102
  text-align: left;
82
103
  }
83
104
 
105
+ .ajax-scaffold th a,
106
+ .ajax-scaffold th p {
107
+ font: bold 11px arial, sans-serif;
108
+ display: block;
109
+ background: #555;
110
+ }
111
+
84
112
  .ajax-scaffold th a {
85
113
  color: #fff;
86
114
  padding: 2px 15px 2px 5px;
87
- display: block;
115
+ }
116
+
117
+ .ajax-scaffold th p {
118
+ color: #eee;
119
+ padding: 2px 5px;
88
120
  }
89
121
 
90
122
  .ajax-scaffold th a:hover {
91
123
  background: #000;
124
+ color: #ff8;
92
125
  }
93
126
 
94
127
  .ajax-scaffold th.sorted {
@@ -115,11 +148,11 @@ background: #333 url(/images/indicator-small.gif) right 50% no-repeat;
115
148
 
116
149
  .ajax-scaffold td {
117
150
  padding: 5px 4px;
118
- border-bottom: solid 1px #C5DBF7;
119
151
  color: #333;
120
152
  font-family: Verdana, sans-serif;
121
153
  font-size: 11px;
122
154
  background-color: #E6F2FF;
155
+ border-bottom: solid 1px #C5DBF7;
123
156
  border-left: solid 1px #C5DBF7;
124
157
  }
125
158
 
@@ -133,18 +166,13 @@ border-left: solid 1px #ddd;
133
166
  }
134
167
 
135
168
  .ajax-scaffold tr td.sorted {
136
- background-color: #ffa;
137
- border-bottom: solid 1px #ccc;
169
+ background-color: #B9DCFF;
170
+ border-bottom: solid 1px #AFD0F5;
138
171
  }
139
172
 
140
173
  .ajax-scaffold tr.even td.sorted {
141
- background-color: #ffd;
142
- border-bottom: solid 1px #ccc;
143
- }
144
-
145
- .ajax-scaffold .update td,
146
- .ajax-scaffold .create td {
147
- padding: 4px;
174
+ background-color: #E6F2FF;
175
+ border-bottom: solid 1px #AFD0F5;
148
176
  }
149
177
 
150
178
  .ajax-scaffold td.empty {
@@ -155,44 +183,28 @@ text-align: center;
155
183
  /* Table Actions (Edit, Delete) Styling
156
184
  ============================= */
157
185
 
158
- .ajax-scaffold td a {
159
- font: bold 11px verdana, sans-serif;
160
- letter-spacing: -1px;
161
- padding: 2px;
162
- line-height: 16px;
163
- }
164
-
165
- .ajax-scaffold td a:hover {
166
- background: #ff8;
167
- }
168
-
169
- .ajax-scaffold .update td,
170
- .ajax-scaffold .create td {
171
- background: #DAFFCD;
172
- }
173
-
174
- .ajax-scaffold .update td,
175
- .ajax-scaffold .create td {
176
- border-left: solid 1px #7FcF00;
177
- border-bottom: solid 1px #7FcF00;
178
- border-right: solid 1px #7FcF00;
179
- }
180
-
181
- .ajax-scaffold .actions {
186
+ .ajax-scaffold td.actions {
182
187
  padding: 0;
183
- width: 95px;
188
+ width: 1%;
184
189
  }
185
190
 
186
- .ajax-scaffold .actions table {
191
+ .ajax-scaffold td.actions table {
187
192
  float: right;
188
193
  width: auto;
189
194
  margin-right: 5px;
190
195
  }
191
196
 
192
- .ajax-scaffold .actions table td {
197
+ .ajax-scaffold td.actions table td {
193
198
  border: none;
194
199
  text-align: right;
195
- padding: 0 0 0 2px;
200
+ padding: 0 2px;
201
+ }
202
+
203
+ .ajax-scaffold td.actions a {
204
+ font: bold 11px verdana, sans-serif;
205
+ letter-spacing: -1px;
206
+ padding: 2px;
207
+ line-height: 16px;
196
208
  }
197
209
 
198
210
  /* ajax-scaffold Footer Styling
@@ -235,7 +247,8 @@ border-right: solid 1px #ccc;
235
247
  /* Messages
236
248
  ========================= */
237
249
 
238
- .ajax-scaffold .messages-container {
250
+ .ajax-scaffold .messages-container,
251
+ .ajax-scaffold .ajax-scaffold .messages-container{
239
252
  padding: 0;
240
253
  margin: 0 7px;
241
254
  border: none;
@@ -356,6 +369,21 @@ margin-bottom: 3px;
356
369
 
357
370
  /* Form Styling
358
371
  ============================== */
372
+
373
+ .ajax-scaffold td.update,
374
+ .ajax-scaffold td.create {
375
+ background: #DAFFCD;
376
+ padding: 4px;
377
+ border: solid 1px #7FcF00;
378
+ border-top: none;
379
+ }
380
+
381
+ .ajax-scaffold .ajax-scaffold td.update,
382
+ .ajax-scaffold .ajax-scaffold td.create {
383
+ background: #ffb;
384
+ border: solid 1px #DDDF37;
385
+ border-top: none;
386
+ }
359
387
 
360
388
  .ajax-scaffold .submit {
361
389
  font-weight: bold;
@@ -389,11 +417,8 @@ letter-spacing: -1px;
389
417
  font: bold 16px arial;
390
418
  }
391
419
 
392
- .ajax-scaffold .update a,
393
- .ajax-scaffold .create a {
394
- font-size: 14px;
395
- font-weight: bold;
396
- font-family: Arial, sans-serif;
420
+ .ajax-scaffold p.form-footer a {
421
+ font: bold 14px arial, sans-serif;
397
422
  letter-spacing: 0;
398
423
  }
399
424
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- AjaxScaffoldGenerator version 3.0.0
2
+ AjaxScaffoldGenerator version 3.1.0
3
3
  (c) 2006 Richard White <rrwhite@gmail.com>
4
4
 
5
5
  AjaxScaffoldGenerator is freely distributable under the terms of an MIT-style license.
@@ -1,5 +1,5 @@
1
1
  class <%= controller_class_name %>Controller < ApplicationController
2
- include AjaxScaffoldUtil
2
+ include AjaxScaffold::Controller
3
3
 
4
4
  after_filter :clear_flashes
5
5
 
@@ -32,15 +32,15 @@ class <%= controller_class_name %>Controller < ApplicationController
32
32
  else
33
33
  # If this is from a client without javascript we want to update the session parameters and then delegate
34
34
  # 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 => "id", :default_sort_direction => "asc"
35
+ update_params :default_scaffold_id => "<%= singular_name %>", :default_sort => nil, :default_sort_direction => "asc"
36
36
  return_to_main
37
37
  end
38
38
  end
39
39
 
40
40
  def component
41
- update_params :default_scaffold_id => "<%= singular_name %>", :default_sort => "id", :default_sort_direction => "asc"
42
-
43
- @sort_by = session[params[:scaffold_id]][:sort] + " " + session[params[:scaffold_id]][:sort_direction]
41
+ update_params :default_scaffold_id => "<%= singular_name %>", :default_sort => nil, :default_sort_direction => "asc"
42
+
43
+ @sort_by = current_sort(params).nil? ? "<%= plural_name %>.id asc" : <%= model_name %>.scaffold_columns_hash[current_sort(params)].sort_sql + " " + current_sort_direction(params)
44
44
  @paginator, @<%= plural_name %> = paginate(:<%= plural_name %>, :order_by => @sort_by, :per_page => default_per_page)
45
45
 
46
46
  render :action => "component", :layout => false
@@ -126,4 +126,12 @@ class <%= controller_class_name %>Controller < ApplicationController
126
126
  # Javascript disabled fallback
127
127
  return_to_main
128
128
  end
129
+
130
+ def cancel
131
+ @successful = true
132
+
133
+ return if request.xhr?
134
+
135
+ return_to_main
136
+ end
129
137
  end
@@ -0,0 +1,5 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+ first:
3
+ id: 1
4
+ another:
5
+ id: 2
@@ -1,8 +1,12 @@
1
1
  module <%= controller_class_name %>Helper
2
- include AjaxScaffoldHelper
2
+ include AjaxScaffold::Helper
3
3
 
4
4
  def num_columns
5
- <%= model_name %>.content_columns.length + 1
5
+ scaffold_columns.length + 1
6
+ end
7
+
8
+ def scaffold_columns
9
+ <%= model_name %>.scaffold_columns
6
10
  end
7
11
 
8
12
  end
@@ -0,0 +1,208 @@
1
+ module AjaxScaffold
2
+
3
+ class ScaffoldColumn
4
+
5
+ attr_reader :name, :eval, :sort_sql, :label
6
+
7
+ # Only options[:name] is required. It will infer the eval and sort values
8
+ # based on the given class.
9
+ def initialize(klass, options)
10
+ @name = options[:name]
11
+ @eval = options[:eval].nil? ? klass.to_s.downcase + "." + @name : options[:eval]
12
+ @label = options[:label].nil? ? Inflector.titleize(@name) : options[:label]
13
+ @sortable = options[:sortable].nil? ? true : options[:sortable]
14
+ @sort_sql = options[:sort_sql].nil? ? Inflector.tableize(klass.to_s) + "." + @name : options[:sort_sql] unless !@sortable
15
+ end
16
+
17
+ def sortable?
18
+ @sortable
19
+ end
20
+
21
+ end
22
+
23
+ module Model
24
+ module ClassMethods
25
+
26
+ def build_scaffold_columns
27
+ scaffold_columns = Array.new
28
+ content_columns.each do |column|
29
+ scaffold_columns << ScaffoldColumn.new(self, { :name => column.name })
30
+ end
31
+ scaffold_columns
32
+ end
33
+
34
+ def build_scaffold_columns_hash
35
+ scaffold_columns_hash = Hash.new
36
+ scaffold_columns.each do |scaffold_column|
37
+ scaffold_columns_hash[scaffold_column.name] = scaffold_column
38
+ end
39
+ scaffold_columns_hash
40
+ end
41
+ end
42
+ end
43
+
44
+ module Common
45
+ def current_sort(params)
46
+ session[params[:scaffold_id]][:sort]
47
+ end
48
+
49
+ def current_sort_direction(params)
50
+ session[params[:scaffold_id]][:sort_direction]
51
+ end
52
+ end
53
+
54
+ module Controller
55
+ include AjaxScaffold::Common
56
+
57
+ def default_per_page
58
+ 25
59
+ end
60
+
61
+ def clear_flashes
62
+ #We want to clear flashes so they don't appear on a page reload
63
+ if request.xhr?
64
+ flash.keys.each do |flash_key|
65
+ flash[flash_key] = nil
66
+ end
67
+ end
68
+ end
69
+
70
+ def store_or_get_from_session(id_key, value_key)
71
+ session[id_key][value_key] = params[value_key] if !params[value_key].nil?
72
+ params[value_key] ||= session[id_key][value_key]
73
+ end
74
+
75
+ def update_params(options)
76
+ @scaffold_id = params[:scaffold_id] ||= options[:default_scaffold_id]
77
+ session[@scaffold_id] ||= {:sort => options[:default_sort], :sort_direction => options[:default_sort_direction], :page => 1}
78
+
79
+ store_or_get_from_session(@scaffold_id, :sort)
80
+ store_or_get_from_session(@scaffold_id, :sort_direction)
81
+ store_or_get_from_session(@scaffold_id, :page)
82
+ end
83
+
84
+ end
85
+
86
+ module Helper
87
+ include AjaxScaffold::Common
88
+
89
+ def format_column(column_value)
90
+ if column_empty?(column_value)
91
+ empty_column_text
92
+ elsif column_value.instance_of? Time
93
+ format_time(column_value)
94
+ elsif column_value.instance_of? Date
95
+ format_date(column_value)
96
+ else
97
+ column_value.to_s
98
+ end
99
+ end
100
+
101
+ def format_time(time)
102
+ time.strftime("%m/%d/%Y %I:%M %p")
103
+ end
104
+
105
+ def format_date(date)
106
+ date.strftime("%m/%d/%Y")
107
+ end
108
+
109
+ def column_empty?(column_value)
110
+ column_value.nil? || (column_value.empty? rescue false)
111
+ end
112
+
113
+ def empty_column_text
114
+ "-"
115
+ end
116
+
117
+ # Generates a temporary id for creating a new element
118
+ def generate_temporary_id
119
+ (Time.now.to_f*1000).to_i.to_s
120
+ end
121
+
122
+ def pagination_ajax_links(paginator, params)
123
+ pagination_links_each(paginator, {}) do |n|
124
+ link_to_remote n,
125
+ { :url => params.merge(:page => n ),
126
+ :loading => "Element.show('#{loading_indicator_id(params.merge(:action => 'pagination'))}');",
127
+ :update => scaffold_content_id(params) },
128
+ { :href => url_for(params.merge(:page => n )) }
129
+ end
130
+ end
131
+
132
+ def column_sort_direction(column_name, params)
133
+ column_name && current_sort_direction(params) == "asc" ? "desc" : "asc"
134
+ end
135
+
136
+ def column_class(column_name, column_value, sort_column)
137
+ class_name = String.new
138
+ class_name += "empty " if column_empty?(column_value)
139
+ class_name += "sorted " if (!sort_column.nil? && column_name == sort_column)
140
+ class_name
141
+ end
142
+
143
+ 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\" />"
146
+ end
147
+
148
+ # The following are a bunch of helper methods to produce the common scaffold view id's
149
+
150
+ def scaffold_content_id(options)
151
+ "#{options[:scaffold_id]}-content"
152
+ end
153
+
154
+ def scaffold_column_header_id(options)
155
+ "#{options[:scaffold_id]}-#{options[:column_name]}"
156
+ end
157
+
158
+ def scaffold_tbody_id(options)
159
+ "#{options[:scaffold_id]}-tbody"
160
+ end
161
+
162
+ def scaffold_messages_id(options)
163
+ "#{options[:scaffold_id]}-messages"
164
+ end
165
+
166
+ def empty_message_id(options)
167
+ "#{options[:scaffold_id]}-empty-message"
168
+ end
169
+
170
+ def element_row_id(options)
171
+ "#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}"
172
+ end
173
+
174
+ def element_cell_id(options)
175
+ "#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-cell"
176
+ end
177
+
178
+ def element_form_id(options)
179
+ "#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-form"
180
+ end
181
+
182
+ def loading_indicator_id(options)
183
+ if options[:id].nil?
184
+ "#{options[:scaffold_id]}-#{options[:action]}-loading-indicator"
185
+ else
186
+ "#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-loading-indicator"
187
+ end
188
+ end
189
+
190
+ def element_messages_id(options)
191
+ "#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-messages"
192
+ end
193
+ end
194
+ end
195
+
196
+ class ActiveRecord::Base
197
+ extend AjaxScaffold::Model::ClassMethods
198
+
199
+ @scaffold_columns = nil
200
+ def self.scaffold_columns
201
+ @scaffold_columns ||= build_scaffold_columns
202
+ end
203
+
204
+ @scaffold_columns_hash = nil
205
+ def self.scaffold_columns_hash
206
+ @scaffold_columns_hash ||= build_scaffold_columns_hash
207
+ end
208
+ end
@@ -0,0 +1,5 @@
1
+ require 'ajax_scaffold'
2
+
3
+ class <%= class_name %> < ActiveRecord::Base
4
+
5
+ end
@@ -1,13 +1,17 @@
1
- <%% current_sort = session[params[:scaffold_id]][:sort] %>
2
- <%% current_sort_direction = session[params[:scaffold_id]][:sort_direction] %>
3
- <%% for column in <%= model_name %>.content_columns %>
4
- <%% sort_direction = current_sort == column.name && current_sort_direction == "asc" ? "desc" : "asc" %>
5
- <%% sort_params = params.merge(:controller => '<%= controller_file_path %>', :action => 'component_update', :sort => column.name, :sort_direction => sort_direction, :page => 1) %>
6
- <th id="<%%= scaffold_column_header_id(sort_params.merge(:column_name => column.name)) %>" <%%= "class=\"sorted #{current_sort_direction}\"" if column.name == current_sort %>>
7
- <%%= link_to_remote column.human_name,
1
+ <%% for scaffold_column in scaffold_columns %>
2
+ <%% column_sort_direction = column_sort_direction(scaffold_column.name, params) %>
3
+ <%% sort_params = params.merge(:controller => '<%= controller_file_path %>', :action => 'component_update', :sort => scaffold_column.name, :sort_direction => column_sort_direction, :page => 1) %>
4
+ <%% column_header_id = scaffold_column_header_id(sort_params.merge(:column_name => scaffold_column.name)) %>
5
+ <th id="<%%= column_header_id %>" <%%= "class=\"sorted #{current_sort_direction(params)}\"" if scaffold_column.name == current_sort(params) %>>
6
+ <%% if scaffold_column.sortable? %>
7
+ <%%= link_to_remote scaffold_column.label,
8
8
  { :url => sort_params,
9
- :loading => "Element.addClassName('#{scaffold_column_header_id(sort_params.merge(:column_name => column.name))}','loading');",
9
+ :loading => "Element.addClassName('#{column_header_id}','loading');",
10
10
  :update => scaffold_content_id(sort_params) },
11
- { :href => url_for(sort_params) } %></th>
11
+ { :href => url_for(sort_params) } %>
12
+ <%% else %>
13
+ <p><%%= scaffold_column.label %></p>
14
+ <%% end %>
15
+ </th>
12
16
  <%% end %>
13
17
  <th></th>
@@ -3,10 +3,10 @@
3
3
  <%% @options = params.merge(:controller => '<%= controller_file_path %>', :action => "view", :id => <%= singular_name %>.id) %>
4
4
 
5
5
  <tr <%%= classAttr %> id="<%%= element_row_id(@options) %>" <%%= "style=\"display: none;\"" if hidden %>>
6
- <%% for column in <%= model_name %>.content_columns %>
7
- <%% column_value = column_value(<%= singular_name %>, column) %>
8
- <td class="<%%= column_class(column.name, column_value, session[params[:scaffold_id]][:sort]) %>" >
9
- <%%= !column_empty?(column_value) ? column_value : "-" %>
6
+ <%% for scaffold_column in scaffold_columns %>
7
+ <%% column_value = eval(scaffold_column.eval) rescue nil %>
8
+ <td class="<%%= column_class(scaffold_column.name, column_value, current_sort(params)) %>" >
9
+ <%%= format_column(column_value) %>
10
10
  </td>
11
11
  <%% end %>
12
12
  <td class="actions">
@@ -2,8 +2,8 @@
2
2
  <table class="ajax-scaffold" cellpadding="0" cellspacing="0">
3
3
  <tbody>
4
4
  <%% end %>
5
- <tr id="<%%= element_row_id(@options) %>" class="<%%= @options[:action] %>" <%%= "style=\"display:none;\"" if request.xhr? %>>
6
- <td id="<%%= element_cell_id(@options) %>" colspan="<%%= num_columns %>">
5
+ <tr id="<%%= element_row_id(@options) %>" <%%= "style=\"display:none;\"" if request.xhr? %>>
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
9
  :loading => "Element.show('#{loading_indicator_id(@options)}');",
@@ -22,17 +22,19 @@
22
22
 
23
23
  <%%= render :partial => 'form' %>
24
24
 
25
- <p>
25
+ <p class="form-footer">
26
26
  <%%= submit_tag Inflector.titleize(@options[:action]), :class => "submit" %>
27
- <%% if request.xhr? %>
28
- <%% on_cancel = "Element.remove('#{element_row_id(@options)}');" %>
29
- <%% on_cancel += "Element.show('#{element_row_id(@view_options)}');" if @options[:action] == "update" %>
30
- <%% on_cancel += "AjaxScaffold.displayMessageIfEmpty('#{scaffold_tbody_id(@options)}','#{empty_message_id(@options)}');" if @options[:action] == "create" %>
31
- <%% end %>
32
- <%%= link_to_function "Cancel", on_cancel,
33
- :href => url_for(:controller => '<%= controller_file_path %>', :action => 'return_to_main') %>
27
+ <%% cancel_params = @options.merge(:controller => '<%= controller_file_path %>', :action => 'cancel', :referring_action => @options[:action]) %>
28
+ <%%= link_to_remote "Cancel",
29
+ { :url => cancel_params,
30
+ :loading => "Element.show('#{loading_indicator_id(@options)}');" },
31
+ { :href => url_for(cancel_params) } %>
34
32
  <%%= loading_indicator_tag @options %>
35
33
  </p>
36
34
  <%%= end_form_tag %>
37
35
  </td>
38
36
  </tr>
37
+ <%% if not request.xhr? %>
38
+ </tbody>
39
+ </table>
40
+ <%% end %>
@@ -0,0 +1,12 @@
1
+ @options = { :scaffold_id => params[:scaffold_id], :action => params[:referring_action], :id => params[:id] }
2
+
3
+ if @successful
4
+ page.remove element_row_id(@options)
5
+ if @options[:action] == "update"
6
+ page.show element_row_id(@options.merge(:action => "view"))
7
+ elsif @options[:action] == "create"
8
+ page << "AjaxScaffold.displayMessageIfEmpty('#{scaffold_tbody_id(@options)}','#{empty_message_id(@options)}');"
9
+ end
10
+ else
11
+ page.hide loading_indicator_id(@options)
12
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
2
+
3
+ class <%= class_name %>Test < Test::Unit::TestCase
4
+ fixtures :<%= table_name %>
5
+
6
+ # Replace this with your real tests.
7
+ def test_truth
8
+ assert true
9
+ end
10
+ end
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.0.4
7
- date: 2006-04-14 00:00:00 -04:00
6
+ version: 3.1.0
7
+ date: 2006-04-18 00:00:00 -04:00
8
8
  summary: Ajax scaffold generator is a rails generator for ajaxified scaffolds
9
9
  require_paths:
10
10
  - lib
@@ -35,11 +35,13 @@ files:
35
35
  - templates/warning.gif
36
36
  - templates/view_list.rhtml
37
37
  - templates/view_component.rhtml
38
+ - templates/unit_test.rb
38
39
  - templates/rjs_update.rjs
39
40
  - templates/rjs_new.rjs
40
41
  - templates/rjs_edit.rjs
41
42
  - templates/rjs_destroy.rjs
42
43
  - templates/rjs_create.rjs
44
+ - templates/rjs_cancel.rjs
43
45
  - templates/rico_corner.js
44
46
  - templates/partial_pagination_links.rhtml
45
47
  - templates/partial_new_edit.rhtml
@@ -47,8 +49,10 @@ files:
47
49
  - templates/partial_item.rhtml
48
50
  - templates/partial_form_messages.rhtml
49
51
  - templates/partial_column_headings.rhtml
52
+ - templates/model.rb
50
53
  - templates/lib_content_column_patch.rb
51
54
  - templates/lib_ajax_scaffold_util.rb
55
+ - templates/lib_ajax_scaffold.rb
52
56
  - templates/layout.rhtml
53
57
  - templates/information.gif
54
58
  - templates/indicator.gif
@@ -57,11 +61,11 @@ files:
57
61
  - templates/functional_test.rb
58
62
  - templates/form_scaffolding.rhtml
59
63
  - templates/form.rhtml
64
+ - templates/fixtures.yml
60
65
  - templates/error.gif
61
66
  - templates/controller.rb
62
67
  - templates/arrow_up.gif
63
68
  - templates/arrow_down.gif
64
- - templates/ajax_scaffold_helper.rb
65
69
  - templates/ajax_scaffold.js
66
70
  - templates/ajax_scaffold.css
67
71
  - templates/add.gif
@@ -1,99 +0,0 @@
1
- module AjaxScaffoldHelper
2
-
3
- def column_value(data_object, column)
4
- column_value = data_object.send(column.name)
5
-
6
- if column_value.instance_of? Time
7
- column_value = format_time(column_value)
8
- elsif column_value.instance_of? Date
9
- column_value = format_date(column_value)
10
- end
11
-
12
- column_value
13
- end
14
-
15
- def format_time(time)
16
- time.strftime("%m/%d/%Y %I:%M %p")
17
- end
18
-
19
- def format_date(date)
20
- date.strftime("%m/%d/%Y")
21
- end
22
-
23
- # Generates a temporary id for creating a new element
24
- def generate_temporary_id
25
- (Time.now.to_f*1000).to_i.to_s
26
- end
27
-
28
- def pagination_ajax_links(paginator, params)
29
- pagination_links_each(paginator, {}) do |n|
30
- link_to_remote n,
31
- { :url => params.merge(:page => n ),
32
- :update => scaffold_content_id(params) },
33
- { :href => url_for(params.merge(:page => n )) }
34
- end
35
- end
36
-
37
- def column_class(column_name, column_value, sort_column)
38
- class_name = String.new
39
- class_name += "empty " if column_empty?(column_value)
40
- class_name += "sorted " if (!sort_column.nil? && column_name == sort_column)
41
- class_name
42
- end
43
-
44
- def column_empty?(column_value)
45
- column_value.nil? || (column_value.empty? rescue false)
46
- end
47
-
48
- def loading_indicator_tag(options)
49
- image_filename = "indicator.gif"
50
- "<img src=\"/images/#{image_filename}\" style=\"display: none;\" id=\"#{loading_indicator_id(options)}\" alt=\"loading indicator\" class=\"loading-indicator\" />"
51
- end
52
-
53
- # The following are a bunch of helper methods to produce the common scaffold view id's
54
-
55
- def scaffold_content_id(options)
56
- "#{options[:scaffold_id]}-content"
57
- end
58
-
59
- def scaffold_column_header_id(options)
60
- "#{options[:scaffold_id]}-#{options[:column_name]}"
61
- end
62
-
63
- def scaffold_tbody_id(options)
64
- "#{options[:scaffold_id]}-tbody"
65
- end
66
-
67
- def scaffold_messages_id(options)
68
- "#{options[:scaffold_id]}-messages"
69
- end
70
-
71
- def empty_message_id(options)
72
- "#{options[:scaffold_id]}-empty-message"
73
- end
74
-
75
- def element_row_id(options)
76
- "#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}"
77
- end
78
-
79
- def element_cell_id(options)
80
- "#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-cell"
81
- end
82
-
83
- def element_form_id(options)
84
- "#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-form"
85
- end
86
-
87
- def loading_indicator_id(options)
88
- if options[:id].nil?
89
- "#{options[:scaffold_id]}-#{options[:action]}-loading-indicator"
90
- else
91
- "#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-loading-indicator"
92
- end
93
- end
94
-
95
- def element_messages_id(options)
96
- "#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-messages"
97
- end
98
-
99
- end