Commit e14a246ff4e626033a5ce24a8add88f0f33dfadf
1 parent
c096bbc1
Exists in
master
and in
28 other branches
ActionItem593: going back to public view when editing from there
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2351 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
41 additions
and
2 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
... | ... | @@ -41,6 +41,7 @@ class CmsController < MyProfileController |
41 | 41 | @article = profile.articles.find(params[:id]) |
42 | 42 | @parent_id = params[:parent_id] |
43 | 43 | @type = params[:type] |
44 | + record_coming_from_public_view | |
44 | 45 | if request.post? |
45 | 46 | @article.last_changed_by = user |
46 | 47 | if @article.update_attributes(params[:article]) |
... | ... | @@ -129,12 +130,22 @@ class CmsController < MyProfileController |
129 | 130 | protected |
130 | 131 | |
131 | 132 | def redirect_back |
132 | - if @article.parent | |
133 | + if params[:back_to] == 'public_view' | |
134 | + redirect_to @article.url | |
135 | + elsif @article.parent | |
133 | 136 | redirect_to :action => 'view', :id => @article.parent |
134 | 137 | else |
135 | 138 | redirect_to :action => 'index' |
136 | 139 | end |
137 | 140 | end |
138 | 141 | |
142 | + def record_coming_from_public_view | |
143 | + referer = request.referer | |
144 | + if (referer == url_for(@article.url)) || (@article == @profile.home_page && referer == url_for(@profile.url)) | |
145 | + @back_to = 'public_view' | |
146 | + @back_url = @article.url | |
147 | + end | |
148 | + end | |
149 | + | |
139 | 150 | end |
140 | 151 | ... | ... |
app/views/cms/edit.rhtml
... | ... | @@ -6,6 +6,8 @@ |
6 | 6 | |
7 | 7 | <%= hidden_field_tag('parent_id', @parent_id) if @parent_id %> |
8 | 8 | |
9 | + <%= hidden_field_tag('back_to', @back_to) %> | |
10 | + | |
9 | 11 | <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %> |
10 | 12 | |
11 | 13 | <% button_bar do %> |
... | ... | @@ -31,7 +33,9 @@ |
31 | 33 | |
32 | 34 | <% button_bar do %> |
33 | 35 | <%= submit_button :save, _('Save') %> |
34 | - <% if @parent_id || @article.parent %> | |
36 | + <% if @back_url %> | |
37 | + <%= button :cancel, _('Cancel'), @back_url %> | |
38 | + <% elsif @parent_id || @article.parent %> | |
35 | 39 | <%= button :cancel, _('Cancel'), :action => 'view', :id => @parent_id || @article.parent %> |
36 | 40 | <% else %> |
37 | 41 | <%= button :cancel, _('Cancel'), :action => 'index' %> | ... | ... |
test/functional/cms_controller_test.rb
... | ... | @@ -505,4 +505,28 @@ class CmsControllerTest < Test::Unit::TestCase |
505 | 505 | assert_equal [c1, c2], assigns(:categories) |
506 | 506 | end |
507 | 507 | |
508 | + should 'record when coming from public view on edit' do | |
509 | + article = @profile.articles.create!(:name => 'myarticle') | |
510 | + | |
511 | + @request.expects(:referer).returns('http://colivre.net/testinguser/myarticle') | |
512 | + | |
513 | + get :edit, :profile => 'testinguser', :id => article.id | |
514 | + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' } | |
515 | + assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => 'http://colivre.net/testinguser/myarticle' } | |
516 | + end | |
517 | + | |
518 | + should 'detect when comming from home page' do | |
519 | + @request.expects(:referer).returns('http://colivre.net/testinguser') | |
520 | + get :edit, :profile => 'testinguser', :id => @profile.home_page.id | |
521 | + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' } | |
522 | + assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => 'http://colivre.net/testinguser/testingusers-home-page' } | |
523 | + end | |
524 | + | |
525 | + should 'go back to public view when saving coming from there' do | |
526 | + article = @profile.articles.create!(:name => 'myarticle') | |
527 | + | |
528 | + post :edit, :profile => 'testinguser', :id => article.id, :back_to => 'public_view' | |
529 | + assert_redirected_to article.url | |
530 | + end | |
531 | + | |
508 | 532 | end | ... | ... |