GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Open Source Ruby on Rails Project Gallery
Homepage: http://www.opensourcerails.com
Clone URL: git://github.com/jcnetdev/opensourcerails.git
Rearranging AJAX Calls to use use custom mime type alias
jcnetdev (author)
Tue Sep 02 18:29:23 -0700 2008
commit  8edef96177dedf07d7eef717902bb5276087865e
tree    17e1baca79a74ad3403fa4d0440338b84fc7776c
parent  1f4d9dde4fe8eb15bfd370286df464896c8ea580
...
7
8
9
10
 
11
12
13
...
19
20
21
22
 
23
24
25
...
7
8
9
 
10
11
12
13
...
19
20
21
 
22
23
24
25
0
@@ -7,7 +7,7 @@ class BookmarksController < Base::ProjectSubpage
0
         flash[:success] = "#{@project.title} is now bookmarked."
0
         redirect_to @project
0
       end
0
- format.js { render_bookmark_control }
0
+ format.ajax { render_bookmark_control }
0
     end
0
   end
0
   
0
@@ -19,7 +19,7 @@ class BookmarksController < Base::ProjectSubpage
0
         flash[:success] = "#{@project.title} is no longer bookmarked."
0
         redirect_to @project
0
       end
0
- format.js { render_bookmark_control }
0
+ format.ajax { render_bookmark_control }
0
     end
0
   end
0
   
...
3
4
5
6
7
8
9
10
11
 
 
 
12
13
14
...
22
23
24
25
26
27
28
29
30
31
 
 
 
 
32
33
34
...
95
96
97
98
 
99
100
101
...
111
112
113
114
 
115
116
117
...
176
177
178
179
 
180
181
182
...
198
199
200
201
 
202
203
204
...
213
214
215
216
 
217
218
219
...
294
295
296
297
 
298
299
300
...
3
4
5
 
 
 
 
 
 
6
7
8
9
10
11
...
19
20
21
 
22
 
 
 
 
 
23
24
25
26
27
28
29
...
90
91
92
 
93
94
95
96
...
106
107
108
 
109
110
111
112
...
171
172
173
 
174
175
176
177
...
193
194
195
 
196
197
198
199
...
208
209
210
 
211
212
213
214
...
289
290
291
 
292
293
294
295
0
@@ -3,12 +3,9 @@ class ProjectsController < ApplicationController
0
     build_gallery(gallery_projects)
0
     @upcoming = Project.upcoming(:limit => AppConfig.project_list_max)
0
     respond_to do |format|
0
- format.html do
0
- if params[:ajax]
0
- render :partial => "projects/parts/grid", :locals => {:projects => @projects}, :layout => false
0
- else
0
- render
0
- end
0
+ format.html
0
+ format.ajax do
0
+ render :partial => "projects/parts/grid.html.haml", :locals => {:projects => @projects}, :layout => false
0
       end
0
       format.atom
0
     end
0
@@ -22,13 +19,11 @@ class ProjectsController < ApplicationController
0
       format.html do
0
         @grid_title = "Upcoming Projects"
0
         @grid_rss = formatted_upcoming_projects_url(:atom)
0
-
0
         @hide_upcoming = true
0
- if params[:ajax]
0
- render :partial => "projects/parts/grid", :locals => {:projects => @projects}, :layout => false
0
- else
0
- render :action => "index"
0
- end
0
+ render :action => "index"
0
+ end
0
+ format.ajax do
0
+ render :partial => "projects/parts/grid.html.haml", :locals => {:projects => @projects}, :layout => false
0
       end
0
       format.atom
0
     end
0
@@ -95,7 +90,7 @@ class ProjectsController < ApplicationController
0
     return unless verify_owner(@project)
0
     
0
     respond_to do |format|
0
- format.js do
0
+ format.ajax do
0
         render :partial => "projects/form.html.haml", :layout => false, :locals => {:ajax => true}
0
       end
0
       format.html
0
@@ -111,7 +106,7 @@ class ProjectsController < ApplicationController
0
     flash[:success] = %("#{@project.title}" has been updated. )
0
     
0
     respond_to do |format|
0
- format.js do
0
+ format.ajax do
0
         render :partial => "projects/parts/ajax_result.html.haml", :locals => {:message => flash[:success]}
0
         flash.discard
0
       end
0
@@ -176,7 +171,7 @@ class ProjectsController < ApplicationController
0
       format.html do
0
         redirect_to @project
0
       end
0
- format.js do
0
+ format.ajax do
0
         render :text => "", :layout => false
0
       end
0
     end
0
@@ -198,7 +193,7 @@ class ProjectsController < ApplicationController
0
         flash.keep
0
         redirect_to @project
0
       end
0
- format.js do
0
+ format.ajax do
0
         render :partial => "projects/parts/about_project.html.haml", :locals => {:project => @project, :hidden => true}, :layout => false
0
       end
0
     end
0
@@ -213,7 +208,7 @@ class ProjectsController < ApplicationController
0
       format.html do
0
         redirect_to root_url
0
       end
0
- format.js do
0
+ format.ajax do
0
         render :partial => "bookmarks/bookmark_list.html.haml", :layout => false, :locals => {:projects => @my_projects}
0
       end
0
     end
0
@@ -294,7 +289,7 @@ class ProjectsController < ApplicationController
0
       # render an output
0
       respond_to do |format|
0
         flash[:error] = "You don't have access to edit this application."
0
- format.js do
0
+ format.ajax do
0
           render :text => flash[:error], :layout => false
0
           flash.discard
0
         end
...
44
45
46
47
48
 
 
 
 
49
50
 
51
52
53
54
55
56
57
58
...
60
61
62
63
64
65
66
67
68
 
69
70
71
72
73
74
75
76
77
78
79
80
 
81
82
83
...
106
107
108
109
110
111
112
113
114
115
116
117
 
 
118
119
120
...
217
218
219
220
 
221
222
223
...
44
45
46
 
 
47
48
49
50
51
 
52
53
54
 
 
 
55
56
57
...
59
60
61
 
 
 
 
 
 
62
63
64
65
66
67
68
 
 
 
 
 
 
69
70
71
72
...
95
96
97
 
 
 
 
 
 
 
 
 
98
99
100
101
102
...
199
200
201
 
202
203
204
205
0
@@ -44,15 +44,14 @@ class UsersController < ApplicationController
0
     respond_to do |format|
0
       format.html do
0
         @grid_title = helpers.pluralize(@user.projects.count, "Bookmarked Project")
0
- if params[:ajax]
0
- render :partial => "projects/parts/grid", :locals => {:projects => @bookmarked_projects}, :layout => false
0
+ end
0
+ format.ajax do
0
+ if params[:show] == "about"
0
+ render :partial => "users/parts/about_user.html.haml", :locals => {:user => @user}, :layout => false
0
         else
0
- render
0
+ render :partial => "projects/parts/grid.html.haml", :locals => {:projects => @bookmarked_projects}, :layout => false
0
         end
0
       end
0
- format.js do
0
- render :partial => "users/parts/about_user", :locals => {:user => @user}, :layout => false
0
- end
0
     end
0
   end
0
   
0
@@ -60,24 +59,14 @@ class UsersController < ApplicationController
0
     @user = find_user
0
     return unless verify_owner(@user)
0
     
0
- respond_to do |format|
0
- format.html
0
- format.js do
0
- render :partial => "users/form", :locals => {:user => @user, :ajax => true}, :layout => false
0
- end
0
- end
0
+ render :partial => "users/form.html.haml", :locals => {:user => @user, :ajax => true}, :layout => false
0
   end
0
   
0
   def edit_password
0
     @user = find_user
0
     return unless verify_owner(@user)
0
 
0
- respond_to do |format|
0
- format.html
0
- format.js do
0
- render :partial => "users/parts/password_form", :locals => {:user => @user, :ajax => true}, :layout => false
0
- end
0
- end
0
+ render :partial => "users/parts/password_form.html.haml", :locals => {:user => @user, :ajax => true}, :layout => false
0
   end
0
   
0
   def update
0
@@ -106,15 +95,8 @@ class UsersController < ApplicationController
0
       flash[:error] = error_msg
0
     end
0
     
0
- respond_to do |format|
0
- format.js do
0
- render :partial => "users/parts/ajax_result.html.haml", :locals => {:message => (flash[:error] || flash[:success])}
0
- flash.discard
0
- end
0
- format.html do
0
- redirect_to @user
0
- end
0
- end
0
+ render :partial => "users/parts/ajax_result.html.haml", :locals => {:message => (flash[:error] || flash[:success])}
0
+ flash.discard
0
   end
0
 
0
   
0
@@ -217,7 +199,7 @@ class UsersController < ApplicationController
0
       # render an output
0
       respond_to do |format|
0
         flash[:error] = "You don't have access to edit this profile."
0
- format.js do
0
+ format.ajax do
0
           render :text => flash[:error], :layout => false
0
           flash.discard
0
         end
...
22
23
24
25
 
26
27
...
22
23
24
 
25
26
27
0
@@ -22,5 +22,5 @@
0
   .actions
0
     = f.submit "Update Information"
0
     or
0
- = link_to "cancel", @project, :class => "cancel"
0
+ = link_to "cancel", formatted_project_url(@project, :ajax), :class => "cancel"
0
     = progress
0
\ No newline at end of file
...
4
5
6
7
 
8
9
10
...
4
5
6
 
7
8
9
10
0
@@ -4,7 +4,7 @@
0
   .reload
0
     #about_project{hide_if(hidden)}
0
       - if true or project.owned_by?(current_or_anon_user)
0
- .top-actions= link_to "Edit...", edit_project_url(project), :class => "edit"
0
+ .top-actions= link_to "Edit...", formatted_edit_project_url(project, :ajax), :class => "edit"
0
 
0
       %h3== #{project.title} Details
0
       .display
...
1
2
3
 
4
...
1
 
2
3
4
0
@@ -1,2 +1,2 @@
0
 = local_assigns[:message]
0
-= link_to "Continue...", details_project_url(@project), :class => "restore"
0
\ No newline at end of file
0
+= link_to "Continue...", formatted_details_project_url(@project, :ajax), :class => "restore"
0
\ No newline at end of file
...
19
20
21
22
 
23
24
...
19
20
21
 
22
23
24
0
@@ -19,5 +19,5 @@
0
   .actions
0
     = f.submit "Update Information"
0
     or
0
- = link_to "cancel", formatted_user_url(user, local_assigns[:ajax] ? :js : :html), :class => "restore"
0
+ = link_to "cancel", user_url(:id => user, :show => "about", :format => local_assigns[:ajax] ? :ajax : :html), :class => "restore"
0
     = progress
0
\ No newline at end of file
...
11
12
13
14
15
16
17
...
32
33
34
35
 
36
37
 
38
39
40
...
11
12
13
 
14
15
16
...
31
32
33
 
34
35
 
36
37
38
39
0
@@ -11,7 +11,6 @@
0
           %strong Name:
0
           =h default(user.name, "[Not Entered]")
0
           
0
-
0
           = br
0
           %strong Email:
0
           =h default(user.email, "[Not Entered]")
0
@@ -32,9 +31,9 @@
0
             = br
0
           
0
           %strong
0
- = link_to "Edit Profile", edit_user_url(user), :class => "edit"
0
+ = link_to "Edit Profile", formatted_edit_user_url(user, :ajax), :class => "edit"
0
             |
0
- = link_to "Change Password", edit_password_user_url(user), :class => "edit"
0
+ = link_to "Change Password", formatted_edit_password_user_url(user, :ajax), :class => "edit"
0
 
0
       .form-container.hidden
0
       = clear
...
1
2
3
 
4
...
1
 
2
3
4
0
@@ -1,2 +1,2 @@
0
 = local_assigns[:message]
0
-= link_to "Continue...", formatted_user_url(@user, :js), :class => "restore"
0
\ No newline at end of file
0
+= link_to "Continue...", user_url(:id => @user, :show => "about", :format => :ajax), :class => "restore"
0
\ No newline at end of file
...
14
15
16
17
 
18
19
...
14
15
16
 
17
18
19
0
@@ -14,5 +14,5 @@
0
   .actions
0
     = f.submit "Change Password"
0
     or
0
- = link_to "cancel", formatted_user_url(user, local_assigns[:ajax] ? :js : :html), :class => "restore"
0
+ = link_to "cancel", user_url(:id => user, :show => "about", :format => :ajax ), :class => "restore"
0
     = progress
0
\ No newline at end of file
...
3
4
5
 
 
...
3
4
5
6
7
0
@@ -3,3 +3,5 @@
0
 # Add new mime types for use in respond_to blocks:
0
 # Mime::Type.register "text/richtext", :rtf
0
 # Mime::Type.register_alias "text/html", :iphone
0
+
0
+Mime::Type.register_alias "text/html", :ajax
...
67
68
69
70
 
71
72
73
...
87
88
89
90
 
91
92
93
...
101
102
103
104
 
105
106
107
...
109
110
111
112
 
113
114
115
...
67
68
69
 
70
71
72
73
...
87
88
89
 
90
91
92
93
...
101
102
103
 
104
105
106
107
...
109
110
111
 
112
113
114
115
0
@@ -67,7 +67,7 @@ $j(document).ready(function() {
0
   
0
   // wire up ajax-forms
0
   $j('form.ajax-form').livequery(function(){
0
- $j(this).ajaxForm({target: $j(this).parents(".form-container")});
0
+ $j(this).ajaxForm({data: {format: "ajax"}, target: $j(this).parents(".form-container")});
0
   }, function(){ });
0
 
0
   $j('form.ajax-form').livequery("submit", function(){
0
@@ -87,7 +87,7 @@ $j(document).ready(function() {
0
 
0
   // update bookmarks
0
   function updateBookmarkPanel() {
0
- $j("#my_bookmarks").load("/bookmarks?format=js");
0
+ $j("#my_bookmarks").load("/bookmarks?format=ajax");
0
   };
0
   
0
   // hook up bookmarking minipanel
0
@@ -101,7 +101,7 @@ $j(document).ready(function() {
0
       if($button.is(".add"))
0
       {
0
         // handle add bookmark ajax call
0
- $j.post($button.attr("href"), "format=js", function(data) {
0
+ $j.post($button.attr("href"), "format=ajax", function(data) {
0
           $button.parents(".bookmark-mini").replaceWith($j(data));
0
           updateBookmarkPanel();
0
         });
0
@@ -109,7 +109,7 @@ $j(document).ready(function() {
0
       else
0
       {
0
         // handle remvoe ajax call
0
- $j.post($button.attr("href"), "format=js&_method=delete", function(data) {
0
+ $j.post($button.attr("href"), "format=ajax&_method=delete", function(data) {
0
           $button.parents(".bookmark-mini").replaceWith($j(data));
0
           updateBookmarkPanel();
0
         });
...
11
12
13
14
 
15
16
17
...
11
12
13
 
14
15
16
17
0
@@ -11,7 +11,7 @@ $j(document).ready(function() {
0
     $this = $j(this);
0
 
0
     $j("#project_info .display").slideUp('slow')
0
- $j("#project_info .form-container").load($this.attr("href")+"?format=js", null, function() {
0
+ $j("#project_info .form-container").load($this.attr("href"), null, function() {
0
       $j(this).slideDown('slow');
0
     });
0
     $this.fadeOut();
...
12
13
14
15
 
16
17
18
...
27
28
29
30
 
31
32
33
...
12
13
14
 
15
16
17
18
...
27
28
29
 
30
31
32
33
0
@@ -12,7 +12,7 @@ $j(document).ready(function() {
0
     $this = $j(this);
0
 
0
     $j("#about_user .display").slideUp('slow')
0
- $j("#about_user .form-container").load($this.attr("href")+"?format=js", null, function() {
0
+ $j("#about_user .form-container").load($this.attr("href"), function() {
0
       $j(this).slideDown('slow');
0
     });
0
     $this.fadeOut();
0
@@ -27,7 +27,7 @@ $j(document).ready(function() {
0
     var reload_url = $this.attr("href");
0
     $reload.find("#about_user").slideUp('slow', function() {
0
       $reload.empty();
0
- $reload.load(reload_url, null, function() {
0
+ $reload.load(reload_url, function() {
0
         $j("#about_user").slideDown('slow');
0
       });
0
     })
...
7
8
9
10
 
11
12
13
...
7
8
9
 
10
11
12
13
0
@@ -7,7 +7,7 @@ $j(document).ready(function() {
0
 
0
   // hook up ajax paging
0
   $j("#project_grid .pagination a").livequery('click', function() {
0
- $j("#project_grid").load($j(this).attr("href")+"&ajax=true");
0
+ $j("#project_grid").load($j(this).attr("href")+"&format=ajax");
0
     return false;
0
   });
0
   

Comments

    No one has commented yet.