ajax_scaffold_generator 2.2.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/ajax_scaffold_generator.rb +97 -22
- data/templates/{style.css → ajax_scaffold.css} +451 -364
- data/templates/ajax_scaffold.js +126 -0
- data/templates/ajax_scaffold_helper.rb +95 -0
- data/templates/arrow_down.gif +0 -0
- data/templates/arrow_up.gif +0 -0
- data/templates/controller.rb +93 -42
- data/templates/error.gif +0 -0
- data/templates/form_scaffolding.rhtml +1 -1
- data/templates/helper.rb +2 -6
- data/templates/indicator.gif +0 -0
- data/templates/information.gif +0 -0
- data/templates/layout.rhtml +2 -1
- data/templates/lib_ajax_scaffold_util.rb +26 -0
- data/templates/lib_content_column_patch.rb +10 -0
- data/templates/partial_column_headings.rhtml +12 -0
- data/templates/partial_form_messages.rhtml +5 -0
- data/templates/partial_item.rhtml +30 -21
- data/templates/partial_messages.rhtml +10 -0
- data/templates/partial_new_edit.rhtml +38 -0
- data/templates/partial_pagination_links.rhtml +14 -0
- data/templates/rjs_create.rjs +17 -0
- data/templates/rjs_destroy.rjs +10 -0
- data/templates/rjs_edit.rjs +16 -0
- data/templates/rjs_new.rjs +14 -0
- data/templates/rjs_update.rjs +17 -0
- data/templates/view_component.rhtml +51 -0
- data/templates/view_list.rhtml +1 -59
- data/templates/warning.gif +0 -0
- metadata +22 -8
- data/templates/partial_form_errors.rhtml +0 -9
- data/templates/script.js +0 -423
- data/templates/view_edit.rhtml +0 -36
- data/templates/view_index.rhtml +0 -1
- data/templates/view_new.rhtml +0 -33
@@ -0,0 +1,12 @@
|
|
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
|
+
<th <%%= "class=\"sorted #{current_sort_direction}\"" if column.name == current_sort %>>
|
5
|
+
<%% sort_direction = current_sort == column.name && current_sort_direction == "asc" ? "desc" : "asc" %>
|
6
|
+
<%% sort_params = params.merge(:controller => '<%= controller_name %>', :action => 'component_update', :sort => column.name, :sort_direction => sort_direction, :page => 1) %>
|
7
|
+
<%%= link_to_remote column.human_name,
|
8
|
+
{ :url => sort_params,
|
9
|
+
:update => scaffold_content_id(sort_params) },
|
10
|
+
{ :href => url_for(sort_params) } %></th>
|
11
|
+
<%% end %>
|
12
|
+
<th></th>
|
@@ -1,27 +1,36 @@
|
|
1
1
|
<%% # The following is used when the browser doesn't have javascript enabled %>
|
2
2
|
<%% classAttr = cycle("", "class=\"even\"") %>
|
3
|
-
|
3
|
+
<%% @options = params.merge(:controller => '<%= controller_name %>', :action => "view", :id => <%= singular_name %>.id) %>
|
4
|
+
|
5
|
+
<tr <%%= classAttr %> id="<%%= element_row_id(@options) %>" <%%= "style=\"display: none;\"" if hidden %>>
|
4
6
|
<%% for column in <%= model_name %>.content_columns %>
|
5
|
-
|
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 : "-" %>
|
10
|
+
</td>
|
6
11
|
<%% end %>
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
{ :
|
17
|
-
|
18
|
-
{ :
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
12
|
+
<td class="actions">
|
13
|
+
<table cellpadding="0" cellspacing="0">
|
14
|
+
<tr>
|
15
|
+
<td class="indicator-container">
|
16
|
+
<%%= loading_indicator_tag(@options) %>
|
17
|
+
</td>
|
18
|
+
<td>
|
19
|
+
<%% edit_options = @options.merge(:action => 'edit') %>
|
20
|
+
<%%= link_to_remote "Edit",
|
21
|
+
{ :url => edit_options,
|
22
|
+
:loading => "Element.show('#{loading_indicator_id(@options)}');" },
|
23
|
+
{ :href => url_for(edit_options) } %>
|
24
|
+
</td>
|
25
|
+
<td>
|
26
|
+
<%% delete_options = @options.merge(:action => 'destroy') %>
|
27
|
+
<%%= link_to_remote "Delete",
|
28
|
+
{ :url => delete_options,
|
29
|
+
:confirm => 'Are you sure?',
|
30
|
+
:loading => "Element.show('#{loading_indicator_id(@options)}');" },
|
31
|
+
{ :href => url_for( delete_options ) } %>
|
32
|
+
</td>
|
33
|
+
</tr>
|
34
|
+
</table>
|
26
35
|
</td>
|
27
36
|
</tr>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%% for name in [:info, :warning, :error] %>
|
2
|
+
<%% if @flash[name] %>
|
3
|
+
<p class="<%%= "#{name}-message message" %>" >
|
4
|
+
<%%= @flash[name] %>
|
5
|
+
<%% if request.xhr? %>
|
6
|
+
<a href="#" onclick="Element.remove(this.parentNode); return false;">Close</a>
|
7
|
+
<%% end %>
|
8
|
+
</p>
|
9
|
+
<%% end %>
|
10
|
+
<%% end %>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<%% if not request.xhr? %>
|
2
|
+
<table class="ajax-scaffold" cellpadding="0" cellspacing="0">
|
3
|
+
<tbody>
|
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 %>">
|
7
|
+
|
8
|
+
<%%= form_remote_tag :url => @options.merge(:controller => '<%= controller_name %>'),
|
9
|
+
:loading => "Element.show('#{loading_indicator_id(@options)}');",
|
10
|
+
:html => { :href => url_for(@options.merge(:controller => '<%= controller_name %>')),
|
11
|
+
:id => element_form_id(@options) } %>
|
12
|
+
|
13
|
+
<%%= hidden_field_tag "scaffold_id", @options[:scaffold_id] %>
|
14
|
+
|
15
|
+
<h4><%%= Inflector.titleize(@options[:action]) %> <%= Inflector.titleize(singular_name) %></h4>
|
16
|
+
|
17
|
+
<%% if request.xhr? %>
|
18
|
+
<div id="<%%= element_messages_id(@options) %>" class="messages-container"></div>
|
19
|
+
<%% else %>
|
20
|
+
<%%= render :partial => 'form_messages' %>
|
21
|
+
<%% end %>
|
22
|
+
|
23
|
+
<%%= render :partial => 'form' %>
|
24
|
+
|
25
|
+
<p>
|
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_name %>', :action => 'return_to_main') %>
|
34
|
+
<%%= loading_indicator_tag @options %>
|
35
|
+
</p>
|
36
|
+
<%%= end_form_tag %>
|
37
|
+
</td>
|
38
|
+
</tr>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%% pagination_params = params.merge(:controller => '<%= controller_name %>', :action => 'component_update') %>
|
2
|
+
<%%= link_to_remote('Previous',
|
3
|
+
{ :url => pagination_params.merge(:page => paginator.current.previous),
|
4
|
+
:update => scaffold_content_id(pagination_params) },
|
5
|
+
{ :href => url_for(pagination_params.merge(:page => paginator.current.previous)),
|
6
|
+
:class => "previous"}) if @paginator.current.previous %>
|
7
|
+
<span class="page-numbers">
|
8
|
+
<%%= pagination_ajax_links @paginator, pagination_params %>
|
9
|
+
</span>
|
10
|
+
<%%= link_to_remote('Next',
|
11
|
+
{ :url => pagination_params.merge(:page => paginator.current.next),
|
12
|
+
:update => scaffold_content_id(pagination_params) },
|
13
|
+
{ :href => url_for(pagination_params.merge(:page => paginator.current.next)),
|
14
|
+
:class => "next"}) if @paginator.current.next %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
@options = { :scaffold_id => params[:scaffold_id], :action => "view", :id => @<%= singular_name %>.id }
|
2
|
+
@create_options = @options.merge(:action => "create", :id => params[:id])
|
3
|
+
|
4
|
+
if @successful
|
5
|
+
page.insert_html :bottom, scaffold_tbody_id(@options), :partial => '<%= singular_name %>', :locals => { :hidden => true }
|
6
|
+
page << "new TableRow.MoveAfter('#{element_row_id(@create_options)}', '#{element_row_id(@options)}');"
|
7
|
+
page.remove element_row_id(@create_options)
|
8
|
+
page.show element_row_id(@options)
|
9
|
+
page << "AjaxScaffold.stripe('#{scaffold_tbody_id(@options)}');"
|
10
|
+
page << "AjaxScaffold.removeSortClasses('#{@options[:scaffold_id]}');"
|
11
|
+
page.replace_html scaffold_messages_id(@options), :partial => 'messages'
|
12
|
+
else
|
13
|
+
page.replace_html element_messages_id(@create_options), :partial => 'form_messages'
|
14
|
+
page.hide loading_indicator_id(@create_options)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
@options = { :scaffold_id => params[:scaffold_id], :action => "view", :id => params[:id] }
|
2
|
+
|
3
|
+
if @successful
|
4
|
+
page.remove element_row_id(@options)
|
5
|
+
page << "AjaxScaffold.displayMessageIfEmpty('#{scaffold_tbody_id(@options)}','#{empty_message_id(@options)}');"
|
6
|
+
page << "AjaxScaffold.stripe('#{scaffold_tbody_id(@options)}');"
|
7
|
+
end
|
8
|
+
|
9
|
+
page.replace_html scaffold_messages_id(@options), :partial => 'messages'
|
10
|
+
page.hide loading_indicator_id(@options)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
@options = { :scaffold_id => params[:scaffold_id], :action => "update", :id => params[:id] }
|
2
|
+
@view_options = @options.merge(:action => "view")
|
3
|
+
|
4
|
+
if @successful
|
5
|
+
page.hide element_row_id(@view_options)
|
6
|
+
page.insert_html :bottom, scaffold_tbody_id(@options), :partial => 'new_edit'
|
7
|
+
page << "new TableRow.MoveAfter('#{element_row_id(@view_options)}', '#{element_row_id(@options)}');"
|
8
|
+
page.show element_row_id(@options)
|
9
|
+
page << "Form.focusFirstElement('#{element_form_id(@options)}');"
|
10
|
+
page.visual_effect :highlight, element_cell_id(@options)
|
11
|
+
page.replace_html element_messages_id(@options), :partial => 'form_messages'
|
12
|
+
else
|
13
|
+
page.replace_html scaffold_messages_id(@options), :partial => 'messages'
|
14
|
+
end
|
15
|
+
|
16
|
+
page.hide loading_indicator_id(@view_options)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
@options = { :scaffold_id => params[:scaffold_id], :action => "create", :id => generate_temporary_id }
|
2
|
+
@new_options = @options.merge(:action => "new", :id => nil)
|
3
|
+
|
4
|
+
if @successful
|
5
|
+
page.insert_html :top, scaffold_tbody_id(@options), :partial => 'new_edit'
|
6
|
+
page.show element_row_id(@options)
|
7
|
+
page << "Form.focusFirstElement('#{element_form_id(@options)}');"
|
8
|
+
page.visual_effect :highlight, element_cell_id(@options)
|
9
|
+
page.replace_html element_messages_id(@options), :partial => 'form_messages'
|
10
|
+
else
|
11
|
+
page.replace_html scaffold_messages_id(@options), :partial => 'messages'
|
12
|
+
end
|
13
|
+
|
14
|
+
page.hide loading_indicator_id(@new_options), empty_message_id(@options)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
@options = { :scaffold_id => params[:scaffold_id], :action => "view", :id => params[:id] }
|
2
|
+
@update_options = @options.merge(:action => "update")
|
3
|
+
|
4
|
+
if @successful
|
5
|
+
page.remove element_row_id(@options)
|
6
|
+
page.insert_html :bottom, scaffold_tbody_id(@options), :partial => '<%= singular_name %>', :locals => { :hidden => true }
|
7
|
+
page << "new TableRow.MoveAfter('#{element_row_id(@update_options)}', '#{element_row_id(@options)}');"
|
8
|
+
page.remove element_row_id(@update_options)
|
9
|
+
page.show element_row_id(@options)
|
10
|
+
page << "AjaxScaffold.stripe('#{scaffold_tbody_id(@options)}');"
|
11
|
+
page << "AjaxScaffold.removeSortClasses('#{@options[:scaffold_id]}');"
|
12
|
+
page.replace_html scaffold_messages_id(@options), :partial => 'messages'
|
13
|
+
else
|
14
|
+
page.replace_html element_messages_id(@update_options), :partial => 'form_messages'
|
15
|
+
page.hide loading_indicator_id(@update_options)
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
<%% if not request.xhr? %>
|
2
|
+
<div id="<%%= params[:scaffold_id] %>" class="ajax-scaffold">
|
3
|
+
<div id="<%%= scaffold_content_id(params) %>">
|
4
|
+
<%% end %>
|
5
|
+
<div class="ajax-scaffold-header">
|
6
|
+
<div class="actions">
|
7
|
+
<%% new_params = params.merge(:controller => '<%= controller_name %>', :action => 'new') %>
|
8
|
+
<%%= loading_indicator_tag(new_params) %>
|
9
|
+
<%%= link_to_remote "Create New",
|
10
|
+
{ :url => new_params,
|
11
|
+
:loading => "Element.show('#{loading_indicator_id(new_params)}');" },
|
12
|
+
{ :href => url_for(new_params),
|
13
|
+
:class => "create" } %>
|
14
|
+
</div>
|
15
|
+
<h2><%= Inflector.titleize(plural_name) %></h2>
|
16
|
+
</div>
|
17
|
+
<table cellpadding="0" cellspacing="0">
|
18
|
+
<thead>
|
19
|
+
<tr>
|
20
|
+
<%%= render :partial => 'column_headings' %>
|
21
|
+
</tr>
|
22
|
+
</thead>
|
23
|
+
<tbody>
|
24
|
+
<tr>
|
25
|
+
<td colspan="<%%= num_columns %>" class="messages-container">
|
26
|
+
<div id="<%%= scaffold_messages_id(params) %>">
|
27
|
+
<%%= render :partial => 'messages' %>
|
28
|
+
</div>
|
29
|
+
<p id="<%%= empty_message_id(params) %>" class="empty-message" <%%= " style=\"display:none;\" " if !@<%= plural_name %>.empty? %>>
|
30
|
+
No Entries
|
31
|
+
</p>
|
32
|
+
</td>
|
33
|
+
</tr>
|
34
|
+
</tbody>
|
35
|
+
<tbody id="<%%= scaffold_tbody_id(params) %>">
|
36
|
+
<%% if !@<%= plural_name %>.empty? %>
|
37
|
+
<%%= render :partial => '<%= singular_name %>', :collection => @<%= plural_name %>, :locals => { :hidden => false } %>
|
38
|
+
<%% end %>
|
39
|
+
</tbody>
|
40
|
+
</table>
|
41
|
+
<div class="ajax-scaffold-footer">
|
42
|
+
<%%= render :partial => 'pagination_links', :locals => { :paginator => @paginator } %>
|
43
|
+
</div>
|
44
|
+
<%% if not request.xhr? %>
|
45
|
+
</div>
|
46
|
+
</div>
|
47
|
+
|
48
|
+
<script type="text/javascript">
|
49
|
+
Rico.Corner.round('<%%= params[:scaffold_id] %>', {color: '#005CB8', bgColor: '#fff', compact: true});
|
50
|
+
</script>
|
51
|
+
<%% end %>
|
data/templates/view_list.rhtml
CHANGED
@@ -1,59 +1 @@
|
|
1
|
-
|
2
|
-
<div id="<%= singular_name %>-list-header" class="ajax-scaffold-header">
|
3
|
-
<h2><%= Inflector.titleize(plural_name) %></h2>
|
4
|
-
|
5
|
-
<div class="actions">
|
6
|
-
<%%= loading_indicator_tag '<%= singular_name %>', "new" %>
|
7
|
-
<%%= link_to_remote "Create New",
|
8
|
-
{ :url => { :controller => '<%= controller_file_name %>', :action => 'new' },
|
9
|
-
:loading => "AjaxScaffold.newOnLoading(request,'<%= singular_name %>');",
|
10
|
-
:success => "AjaxScaffold.newOnSuccess(request,'<%= singular_name %>');",
|
11
|
-
:failure => "AjaxScaffold.newOnFailure(request,'<%= singular_name %>');" },
|
12
|
-
{ :href => url_for(:controller => '<%= controller_file_name %>', :action => 'new'),
|
13
|
-
:class => "create" } %>
|
14
|
-
|
15
|
-
</div>
|
16
|
-
|
17
|
-
</div>
|
18
|
-
<table id="<%= singular_name %>-list" class="ajax-scaffold" cellpadding="0" cellspacing="0">
|
19
|
-
<thead>
|
20
|
-
<tr class="header">
|
21
|
-
<%% for column in <%= model_name %>.content_columns %>
|
22
|
-
<th><%%= column.human_name %></th>
|
23
|
-
<%% end %>
|
24
|
-
<th></th>
|
25
|
-
</tr>
|
26
|
-
</thead>
|
27
|
-
<tbody>
|
28
|
-
<tr id="<%= singular_name %>-error-message" class="error-message" style="display:none;">
|
29
|
-
<td colspan="<%%= num_columns - 1 %>">
|
30
|
-
<p>An error has occurred</p>
|
31
|
-
</td>
|
32
|
-
<td class="actions">
|
33
|
-
<%%= link_to_function "Close", "AjaxScaffold.hideError('<%= singular_name %>');" %>
|
34
|
-
</td>
|
35
|
-
</tr>
|
36
|
-
<tr id="<%= singular_name %>-empty-message" class="empty-message" <%%= " style=\"display:none;\" " if !@<%= plural_name %>.empty? %>>
|
37
|
-
<td colspan="<%%= num_columns %>">No Entries</td>
|
38
|
-
</tr>
|
39
|
-
</tbody>
|
40
|
-
<tbody id="<%= singular_name %>-list-body">
|
41
|
-
<%% if !@<%= plural_name %>.empty? %>
|
42
|
-
<%%= render :partial => '<%= singular_name %>', :collection => @<%= plural_name %>, :locals => { :hidden => false } %>
|
43
|
-
<%% else %>
|
44
|
-
<%% # Do not remove the following TR, it is needed to load up the even row color when enableHighlighting is turned on and the list is empty %>
|
45
|
-
<tr class="even ignore" style="display: none;">
|
46
|
-
<td colspan="<%%= num_columns %>"></td>
|
47
|
-
</tr>
|
48
|
-
<%% end %>
|
49
|
-
</tbody>
|
50
|
-
</table>
|
51
|
-
</div>
|
52
|
-
|
53
|
-
<script type="text/javascript">
|
54
|
-
TableBodyUtil.enableHighlighting(AjaxScaffold.getTableBodyElement('<%= singular_name %>'));
|
55
|
-
<%% if !@<%= plural_name %>.empty? %>
|
56
|
-
TableBodyUtil.paintStripes(AjaxScaffold.getTableBodyElement('<%= singular_name %>'));
|
57
|
-
<%% end %>
|
58
|
-
Rico.Corner.round('<%= singular_name %>-list-wrapper', {color: '#005CB8', bgColor: '#fff', compact: true});
|
59
|
-
</script>
|
1
|
+
<%%= render_component :controller => '<%= controller_name %>', :action => 'component', :params => params %>
|
Binary file
|
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:
|
7
|
-
date: 2006-
|
6
|
+
version: 3.0.0
|
7
|
+
date: 2006-04-12 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
|
@@ -32,16 +32,25 @@ files:
|
|
32
32
|
- MIT-LICENSE
|
33
33
|
- ajax_scaffold_generator.rb
|
34
34
|
- templates/
|
35
|
-
- templates/
|
35
|
+
- templates/warning.gif
|
36
36
|
- templates/view_list.rhtml
|
37
|
-
- templates/
|
38
|
-
- templates/
|
39
|
-
- templates/
|
40
|
-
- templates/
|
37
|
+
- templates/view_component.rhtml
|
38
|
+
- templates/rjs_update.rjs
|
39
|
+
- templates/rjs_new.rjs
|
40
|
+
- templates/rjs_edit.rjs
|
41
|
+
- templates/rjs_destroy.rjs
|
42
|
+
- templates/rjs_create.rjs
|
41
43
|
- templates/rico_corner.js
|
44
|
+
- templates/partial_pagination_links.rhtml
|
45
|
+
- templates/partial_new_edit.rhtml
|
46
|
+
- templates/partial_messages.rhtml
|
42
47
|
- templates/partial_item.rhtml
|
43
|
-
- templates/
|
48
|
+
- templates/partial_form_messages.rhtml
|
49
|
+
- templates/partial_column_headings.rhtml
|
50
|
+
- templates/lib_content_column_patch.rb
|
51
|
+
- templates/lib_ajax_scaffold_util.rb
|
44
52
|
- templates/layout.rhtml
|
53
|
+
- templates/information.gif
|
45
54
|
- templates/indicator.gif
|
46
55
|
- templates/helper.rb
|
47
56
|
- templates/functional_test.rb
|
@@ -49,6 +58,11 @@ files:
|
|
49
58
|
- templates/form.rhtml
|
50
59
|
- templates/error.gif
|
51
60
|
- templates/controller.rb
|
61
|
+
- templates/arrow_up.gif
|
62
|
+
- templates/arrow_down.gif
|
63
|
+
- templates/ajax_scaffold_helper.rb
|
64
|
+
- templates/ajax_scaffold.js
|
65
|
+
- templates/ajax_scaffold.css
|
52
66
|
- templates/add.gif
|
53
67
|
test_files: []
|
54
68
|
rdoc_options: []
|
@@ -1,9 +0,0 @@
|
|
1
|
-
<%% unless @<%= singular_name %>.nil? %>
|
2
|
-
<%%= error_messages_for '<%= singular_name %>' %>
|
3
|
-
<%% end -%>
|
4
|
-
|
5
|
-
<%% for name in [:notice, :warning, :error, :message] %>
|
6
|
-
<%% if @flash[name] %>
|
7
|
-
<%%= "<div class=\"#{name}\">#{@flash[name]}</div>" %>
|
8
|
-
<%% end %>
|
9
|
-
<%% end %>
|
data/templates/script.js
DELETED
@@ -1,423 +0,0 @@
|
|
1
|
-
// The following is a cross browser way to move around <tr> elements in a <table> or <tbody>
|
2
|
-
|
3
|
-
var Abstract = new Object();
|
4
|
-
Abstract.Table = function() {};
|
5
|
-
Abstract.Table.prototype = {
|
6
|
-
tagTest: function(element, tagName) {
|
7
|
-
return $(element).tagName.toLowerCase() == tagName.toLowerCase();
|
8
|
-
}
|
9
|
-
};
|
10
|
-
|
11
|
-
Abstract.TableRow = function() {};
|
12
|
-
Abstract.TableRow.prototype = Object.extend(new Abstract.Table(), {
|
13
|
-
initialize: function(targetTableRow, sourceTableRow) {
|
14
|
-
try {
|
15
|
-
var sourceTableRow = $(sourceTableRow);
|
16
|
-
var targetTableRow = $(targetTableRow);
|
17
|
-
|
18
|
-
if (targetTableRow == null || !this.tagTest(targetTableRow,'tr')
|
19
|
-
|| sourceTableRow == null || !this.tagTest(sourceTableRow,'tr')) {
|
20
|
-
throw("TableRow: both parameters must be a <tr> tag.");
|
21
|
-
}
|
22
|
-
|
23
|
-
var tableOrTbody = this.findParentTableOrTbody(targetTableRow);
|
24
|
-
|
25
|
-
var newRow = tableOrTbody.insertRow(this.getNewRowIndex(targetTableRow) - this.getRowOffset(tableOrTbody));
|
26
|
-
newRow.parentNode.replaceChild(sourceTableRow, newRow);
|
27
|
-
|
28
|
-
} catch (e) {
|
29
|
-
alert(e);
|
30
|
-
}
|
31
|
-
},
|
32
|
-
getRowOffset: function(tableOrTbody) {
|
33
|
-
//If we are inserting into a tablebody we would need figure out the rowIndex of the first
|
34
|
-
// row in that tbody and subtract that offset from the new row index
|
35
|
-
var rowOffset = 0;
|
36
|
-
if (this.tagTest(tableOrTbody,'tbody')) {
|
37
|
-
rowOffset = tableOrTbody.rows[0].rowIndex;
|
38
|
-
}
|
39
|
-
return rowOffset;
|
40
|
-
},
|
41
|
-
findParentTableOrTbody: function(element) {
|
42
|
-
var element = $(element);
|
43
|
-
// Completely arbitrary value
|
44
|
-
var maxSearchDepth = 3;
|
45
|
-
var currentSearchDepth = 1;
|
46
|
-
var current = element;
|
47
|
-
while (currentSearchDepth <= maxSearchDepth) {
|
48
|
-
current = current.parentNode;
|
49
|
-
if (this.tagTest(current, 'tbody') || this.tagTest(current, 'table')) {
|
50
|
-
return current;
|
51
|
-
}
|
52
|
-
currentSearchDepth++;
|
53
|
-
}
|
54
|
-
}
|
55
|
-
});
|
56
|
-
|
57
|
-
var TableRow = new Object();
|
58
|
-
|
59
|
-
TableRow.MoveBefore = Class.create();
|
60
|
-
TableRow.MoveBefore.prototype = Object.extend(new Abstract.TableRow(), {
|
61
|
-
getNewRowIndex: function(target) {
|
62
|
-
return target.rowIndex;
|
63
|
-
}
|
64
|
-
});
|
65
|
-
|
66
|
-
TableRow.MoveAfter = Class.create();
|
67
|
-
TableRow.MoveAfter.prototype = Object.extend(new Abstract.TableRow(), {
|
68
|
-
getNewRowIndex: function(target) {
|
69
|
-
return target.rowIndex+1;
|
70
|
-
}
|
71
|
-
});
|
72
|
-
|
73
|
-
//Since scriptaculous doesn't support tables and causes and error applying effects to rows in IE 6.0 and Safari we need this wrapper
|
74
|
-
|
75
|
-
Abstract.TableEffect = function() {};
|
76
|
-
Abstract.TableEffect.prototype = Object.extend(new Abstract.Table(), {
|
77
|
-
callEffect: function(target, command) {
|
78
|
-
var target = $(target);
|
79
|
-
if (this.tagTest(target,'tr')) {
|
80
|
-
var length = target.cells.length;
|
81
|
-
for (var i = 0; i < length; i++) {
|
82
|
-
eval("new " + command + "(target.cells[i]);");
|
83
|
-
}
|
84
|
-
} else {
|
85
|
-
eval("new " + command + "(targetElement);");
|
86
|
-
}
|
87
|
-
}
|
88
|
-
});
|
89
|
-
|
90
|
-
var TableEffect = new Object();
|
91
|
-
|
92
|
-
TableEffect.Fade = Class.create();
|
93
|
-
TableEffect.Fade.prototype = Object.extend(new Abstract.TableEffect(), {
|
94
|
-
initialize: function(target) {
|
95
|
-
this.callEffect(target, 'Effect.Fade');
|
96
|
-
}
|
97
|
-
});
|
98
|
-
|
99
|
-
TableEffect.Highlight = Class.create();
|
100
|
-
TableEffect.Highlight.prototype = Object.extend(new Abstract.TableEffect(), {
|
101
|
-
initialize: function(target) {
|
102
|
-
this.callEffect(target, 'Effect.Highlight');
|
103
|
-
}
|
104
|
-
});
|
105
|
-
|
106
|
-
//The following is a utility to paint beautiful stripes on our table rows, a lot of logic for setting the colors explicitly on each element
|
107
|
-
// if hightlighting is going to overwrite out CSS styles otherwise.
|
108
|
-
|
109
|
-
var TableBodyUtil = {
|
110
|
-
enableHighlighting: function(tableBody) {
|
111
|
-
this.getColorStore(tableBody).highlighting = true;
|
112
|
-
},
|
113
|
-
disableHighlighting: function(tableBody) {
|
114
|
-
this.getColorStore(tableBody).highlighting = false;
|
115
|
-
},
|
116
|
-
highlightingEnabled: function(tableBody) {
|
117
|
-
var returnValue = true;
|
118
|
-
if (this.getColorStore(tableBody).highlighting != null) {
|
119
|
-
returnValue = this.getColorStore(tableBody).highlighting;
|
120
|
-
}
|
121
|
-
return returnValue;
|
122
|
-
},
|
123
|
-
// We are going to proxy all highlighting through this so that we can uniformly allow/block it (and subsequently paintStripes depending on this)
|
124
|
-
highlight: function(target, tableBody) {
|
125
|
-
if (this.highlightingEnabled(tableBody)) {
|
126
|
-
new TableEffect.Highlight(target);
|
127
|
-
}
|
128
|
-
},
|
129
|
-
getColorStore: function(tableBody) {
|
130
|
-
var uniqueId = tableBody.id;
|
131
|
-
|
132
|
-
if (this.tables == null) {
|
133
|
-
this.tables = new Object();
|
134
|
-
}
|
135
|
-
|
136
|
-
if (this.tables[String(uniqueId)] == null) {
|
137
|
-
this.tables[String(uniqueId)] = new Object();
|
138
|
-
}
|
139
|
-
|
140
|
-
return this.tables[String(uniqueId)];
|
141
|
-
},
|
142
|
-
paintStripes: function(tableBody) {
|
143
|
-
var even = false;
|
144
|
-
var tableBody = tableBody;
|
145
|
-
var tableRows = tableBody.getElementsByTagName("tr");
|
146
|
-
var length = tableBody.rows.length;
|
147
|
-
|
148
|
-
var colorStore = this.getColorStore(tableBody);
|
149
|
-
|
150
|
-
for (var i = 0; i < length; i++) {
|
151
|
-
var tableRow = tableBody.rows[i];
|
152
|
-
//Make sure to skip rows that are create or edit rows or messages
|
153
|
-
if (!Element.hasClassName(tableRow, "edit")
|
154
|
-
&& !Element.hasClassName(tableRow, "create")
|
155
|
-
&& !Element.hasClassName(tableRow, "deleted")
|
156
|
-
&& !Element.hasClassName(tableRow, "message")) {
|
157
|
-
|
158
|
-
if (even) {
|
159
|
-
Element.addClassName(tableRow, "even");
|
160
|
-
if (this.highlightingEnabled(tableBody)) {
|
161
|
-
//If we don't already know what the color is supposed to be we'll poll it from the styles and then save that to apply later
|
162
|
-
if (!colorStore.evenColor) {
|
163
|
-
colorStore.evenColor = this.getCellBackgroundColor(tableRow);
|
164
|
-
// Safari won't pick up the style of the color if the row is not displayed so we are going to hide and then show
|
165
|
-
// the dummy row if thats what this is.
|
166
|
-
if (colorStore.evenColor == null) {
|
167
|
-
Element.show(tableRow);
|
168
|
-
colorStore.evenColor = this.getCellBackgroundColor(tableRow);
|
169
|
-
Element.hide(tableRow);
|
170
|
-
}
|
171
|
-
}
|
172
|
-
this.setCellBackgroundColor(tableRow, colorStore.evenColor);
|
173
|
-
}
|
174
|
-
} else {
|
175
|
-
Element.removeClassName(tableRow, "even");
|
176
|
-
|
177
|
-
if (this.highlightingEnabled(tableBody)) {
|
178
|
-
if (!colorStore.oddColor) {
|
179
|
-
colorStore.oddColor = this.getCellBackgroundColor(tableRow);
|
180
|
-
}
|
181
|
-
this.setCellBackgroundColor(tableRow, colorStore.oddColor);
|
182
|
-
}
|
183
|
-
}
|
184
|
-
even = !even;
|
185
|
-
}
|
186
|
-
}
|
187
|
-
},
|
188
|
-
getCellBackgroundColor: function(tableRow) {
|
189
|
-
var tableCell = tableRow.getElementsByTagName("td")[0];
|
190
|
-
return Element.getStyle(tableCell, 'background-color');
|
191
|
-
},
|
192
|
-
setCellBackgroundColor: function(tableRow, color) {
|
193
|
-
var length = tableRow.cells.length;
|
194
|
-
for (var i = 0; i < length; i++) {
|
195
|
-
try {
|
196
|
-
tableRow.cells[i].style.backgroundColor = color;
|
197
|
-
} catch (e) {
|
198
|
-
alert(e);
|
199
|
-
}
|
200
|
-
}
|
201
|
-
},
|
202
|
-
countRows: function(tableBody) {
|
203
|
-
var tableBody = tableBody;
|
204
|
-
var length = tableBody.rows.length;
|
205
|
-
|
206
|
-
var validRows = 0;
|
207
|
-
|
208
|
-
for (var i = 0; i < length; i++) {
|
209
|
-
var tableRow = tableBody.rows[i];
|
210
|
-
//Make sure to skip rows that are deleted or message
|
211
|
-
if (!Element.hasClassName(tableRow, "deleted")
|
212
|
-
&& !Element.hasClassName(tableRow, "message")
|
213
|
-
&& !Element.hasClassName(tableRow, "ignore")) {
|
214
|
-
validRows++;
|
215
|
-
}
|
216
|
-
}
|
217
|
-
return validRows;
|
218
|
-
}
|
219
|
-
}
|
220
|
-
|
221
|
-
var AjaxScaffold = {
|
222
|
-
newOnLoading: function(request, type) {
|
223
|
-
Element.show(this.getNewIndicator(type));
|
224
|
-
},
|
225
|
-
newOnFailure: function(request, type) {
|
226
|
-
this.showError(type, request.responseText);
|
227
|
-
Element.hide(this.getNewIndicator(type));
|
228
|
-
},
|
229
|
-
newOnSuccess: function(request, type) {
|
230
|
-
var createForm = request.responseText;
|
231
|
-
|
232
|
-
var id = this.getId(request,type);
|
233
|
-
|
234
|
-
new Insertion.Top(this.getTableBodyElement(type), createForm);
|
235
|
-
|
236
|
-
Element.hide(this.getEmptyMessageElement(type));
|
237
|
-
Element.hide(this.getNewIndicator(type));
|
238
|
-
|
239
|
-
var createElement = this.getCreateElement(type, id);
|
240
|
-
Element.show(createElement);
|
241
|
-
TableBodyUtil.highlight(createElement,this.getTableBodyElement(type));
|
242
|
-
Form.focusFirstElement(this.getFormElement('create',type,id));
|
243
|
-
},
|
244
|
-
|
245
|
-
|
246
|
-
createOnLoading: function(request,type,id) {
|
247
|
-
Element.show(this.getIndicator('create',type,id));
|
248
|
-
},
|
249
|
-
createOnFailure: function(request,type,id) {
|
250
|
-
var errorElement = this.getFormErrorElement('create',type,id)
|
251
|
-
var errorMessages = request.responseText;
|
252
|
-
errorElement.innerHTML = errorMessages;
|
253
|
-
Element.show(errorElement);
|
254
|
-
Element.hide(this.getIndicator('create',type,id));
|
255
|
-
},
|
256
|
-
createOnSuccess: function(request,type,id) {
|
257
|
-
var createElement = this.getCreateElement(type,id);
|
258
|
-
|
259
|
-
var view = request.responseText;
|
260
|
-
var viewId = this.getId(request,type);
|
261
|
-
|
262
|
-
// TODO : Convert this into TableRow.InsertAfter
|
263
|
-
new Insertion.Bottom(this.getTableBodyElement(type), view);
|
264
|
-
var viewElement = this.getViewElement(type,viewId);
|
265
|
-
new TableRow.MoveAfter(createElement, viewElement);
|
266
|
-
|
267
|
-
Element.remove(createElement);
|
268
|
-
Element.show(viewElement);
|
269
|
-
|
270
|
-
TableBodyUtil.paintStripes(this.getTableBodyElement(type));
|
271
|
-
TableBodyUtil.highlight(viewElement,this.getTableBodyElement(type));
|
272
|
-
},
|
273
|
-
createOnCancel: function(type,id) {
|
274
|
-
var createElement = this.getCreateElement(type,id);
|
275
|
-
Element.remove(createElement);
|
276
|
-
if (TableBodyUtil.countRows(this.getTableBodyElement(type)) == 0) {
|
277
|
-
Element.show(this.getEmptyMessageElement(type));
|
278
|
-
}
|
279
|
-
},
|
280
|
-
|
281
|
-
|
282
|
-
deleteOnLoading: function(type,id) {
|
283
|
-
|
284
|
-
},
|
285
|
-
deleteOnFailure: function(type,id) {
|
286
|
-
this.showError(type, request.responseText);
|
287
|
-
},
|
288
|
-
deleteOnSuccess: function(type,id) {
|
289
|
-
var viewElement = this.getViewElement(type,id);
|
290
|
-
|
291
|
-
new TableEffect.Fade(viewElement);
|
292
|
-
//We cannot set a timeout to remove this element from the DOM b/c once fade is complete
|
293
|
-
// get by ID no longer works on this element. So we'll set a class so that it isn't picked up in a re striping
|
294
|
-
Element.addClassName(viewElement, 'deleted');
|
295
|
-
|
296
|
-
if (TableBodyUtil.countRows(this.getTableBodyElement(type)) == 0) {
|
297
|
-
Element.show(this.getEmptyMessageElement(type));
|
298
|
-
} else {
|
299
|
-
TableBodyUtil.paintStripes(this.getTableBodyElement(type));
|
300
|
-
}
|
301
|
-
},
|
302
|
-
|
303
|
-
|
304
|
-
editOnLoading: function(request,type,id) {
|
305
|
-
Element.show(this.getIndicator('edit',type,id));
|
306
|
-
},
|
307
|
-
editOnFailure: function(request,type,id) {
|
308
|
-
this.showError(type, request.responseText);
|
309
|
-
Element.hide(this.getIndicator('edit',type,id));
|
310
|
-
},
|
311
|
-
editOnSuccess: function(request,type,id) {
|
312
|
-
var viewElement = this.getViewElement(type,id);
|
313
|
-
|
314
|
-
//Ajax.Update with Insertion.top does not work when being used as a component with other scaffolds on the screen
|
315
|
-
// the only safe way it seems it to always insert new elements at the bottom and then move them into the appropriate location
|
316
|
-
var editForm = request.responseText;
|
317
|
-
|
318
|
-
// TODO : Convert this into TableRow.InsertAfter
|
319
|
-
new Insertion.Bottom(this.getTableBodyElement(type), editForm);
|
320
|
-
var editElement = this.getEditElement(type,id);
|
321
|
-
new TableRow.MoveAfter(viewElement, editElement);
|
322
|
-
|
323
|
-
var formElement = this.getFormElement('edit',type,id);
|
324
|
-
|
325
|
-
Element.hide(viewElement);
|
326
|
-
Element.hide(this.getIndicator('edit',type,id));
|
327
|
-
Element.show(editElement);
|
328
|
-
|
329
|
-
new TableEffect.Highlight(editElement);
|
330
|
-
Form.focusFirstElement(formElement);
|
331
|
-
},
|
332
|
-
|
333
|
-
|
334
|
-
updateOnLoading: function(request,type,id) {
|
335
|
-
Element.show(this.getIndicator('update',type,id));
|
336
|
-
},
|
337
|
-
updateOnFailure: function(request,type,id) {
|
338
|
-
var errorElement = this.getFormErrorElement('update',type,id)
|
339
|
-
var errorMessages = request.responseText;
|
340
|
-
errorElement.innerHTML = errorMessages;
|
341
|
-
Element.show(errorElement);
|
342
|
-
Element.hide(this.getIndicator('update',type,id));
|
343
|
-
},
|
344
|
-
updateOnSuccess: function(request,type,id) {
|
345
|
-
var editElement = this.getEditElement(type,id);
|
346
|
-
var formElement = this.getFormElement(type,id);
|
347
|
-
var viewElement = this.getViewElement(type,id);
|
348
|
-
|
349
|
-
Element.remove(viewElement);
|
350
|
-
|
351
|
-
var view = request.responseText;
|
352
|
-
|
353
|
-
// TODO : Convert this into a TableRow.InsertBefore
|
354
|
-
new Insertion.Bottom(this.getTableBodyElement(type), view);
|
355
|
-
var viewElement = this.getViewElement(type,id);
|
356
|
-
new TableRow.MoveBefore(editElement, viewElement);
|
357
|
-
|
358
|
-
Element.remove(editElement);
|
359
|
-
Element.show(viewElement);
|
360
|
-
|
361
|
-
TableBodyUtil.paintStripes(this.getTableBodyElement(type));
|
362
|
-
TableBodyUtil.highlight(viewElement,this.getTableBodyElement(type));
|
363
|
-
},
|
364
|
-
updateOnCancel: function(type,id) {
|
365
|
-
var viewElement = this.getViewElement(type,id);
|
366
|
-
var editElement = this.getEditElement(type,id);
|
367
|
-
|
368
|
-
Element.show(viewElement);
|
369
|
-
Element.remove(editElement);
|
370
|
-
},
|
371
|
-
|
372
|
-
|
373
|
-
showError: function(type,html) {
|
374
|
-
var errorElement = this.getErrorMessageElement(type);
|
375
|
-
var errorMessageElement = errorElement.getElementsByTagName("p")[0];
|
376
|
-
errorMessageElement.innerHTML = html;
|
377
|
-
Element.show(errorElement);
|
378
|
-
TableBodyUtil.highlight(errorElement,this.getTableBodyElement(type));
|
379
|
-
},
|
380
|
-
hideError: function(type) {
|
381
|
-
var errorElement = this.getErrorMessageElement(type);
|
382
|
-
Element.hide(errorElement);
|
383
|
-
},
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
getNewIndicator: function(type) {
|
388
|
-
return $(type + "-new-loading-indicator");
|
389
|
-
},
|
390
|
-
getIndicator: function(scope, type,id) {
|
391
|
-
return $(type + '-' + scope + '-' + id + "-loading-indicator");
|
392
|
-
},
|
393
|
-
getFormErrorElement: function(scope,type,id) {
|
394
|
-
return $(scope + '-' + type + '-' + id + '-errors')
|
395
|
-
},
|
396
|
-
getId: function(request, type) {
|
397
|
-
return request.getResponseHeader(type + '-id');
|
398
|
-
},
|
399
|
-
getCreateElementId: function(type,id) {
|
400
|
-
return 'create-' + type + '-' + id;
|
401
|
-
},
|
402
|
-
getCreateElement: function(type,id) {
|
403
|
-
return $('create-' + type + '-' + id);
|
404
|
-
},
|
405
|
-
getViewElement: function(type,id) {
|
406
|
-
return $('view-' + type + '-' + id);
|
407
|
-
},
|
408
|
-
getEditElement: function(type,id) {
|
409
|
-
return $('edit-' + type + '-' + id);
|
410
|
-
},
|
411
|
-
getFormElement: function(scope,type,id) {
|
412
|
-
return $(scope+'-'+type + '-' + id + '-form');
|
413
|
-
},
|
414
|
-
getEmptyMessageElement: function(type) {
|
415
|
-
return $(type + '-empty-message');
|
416
|
-
},
|
417
|
-
getErrorMessageElement: function(type) {
|
418
|
-
return $(type + '-error-message');
|
419
|
-
},
|
420
|
-
getTableBodyElement: function(type) {
|
421
|
-
return $(type + '-list-body');
|
422
|
-
}
|
423
|
-
}
|