Commit e14a246ff4e626033a5ce24a8add88f0f33dfadf
1 parent
c096bbc1
Exists in
master
and in
22 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,6 +41,7 @@ class CmsController < MyProfileController | ||
| 41 | @article = profile.articles.find(params[:id]) | 41 | @article = profile.articles.find(params[:id]) |
| 42 | @parent_id = params[:parent_id] | 42 | @parent_id = params[:parent_id] |
| 43 | @type = params[:type] | 43 | @type = params[:type] |
| 44 | + record_coming_from_public_view | ||
| 44 | if request.post? | 45 | if request.post? |
| 45 | @article.last_changed_by = user | 46 | @article.last_changed_by = user |
| 46 | if @article.update_attributes(params[:article]) | 47 | if @article.update_attributes(params[:article]) |
| @@ -129,12 +130,22 @@ class CmsController < MyProfileController | @@ -129,12 +130,22 @@ class CmsController < MyProfileController | ||
| 129 | protected | 130 | protected |
| 130 | 131 | ||
| 131 | def redirect_back | 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 | redirect_to :action => 'view', :id => @article.parent | 136 | redirect_to :action => 'view', :id => @article.parent |
| 134 | else | 137 | else |
| 135 | redirect_to :action => 'index' | 138 | redirect_to :action => 'index' |
| 136 | end | 139 | end |
| 137 | end | 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 | end | 150 | end |
| 140 | 151 |
app/views/cms/edit.rhtml
| @@ -6,6 +6,8 @@ | @@ -6,6 +6,8 @@ | ||
| 6 | 6 | ||
| 7 | <%= hidden_field_tag('parent_id', @parent_id) if @parent_id %> | 7 | <%= hidden_field_tag('parent_id', @parent_id) if @parent_id %> |
| 8 | 8 | ||
| 9 | + <%= hidden_field_tag('back_to', @back_to) %> | ||
| 10 | + | ||
| 9 | <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %> | 11 | <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %> |
| 10 | 12 | ||
| 11 | <% button_bar do %> | 13 | <% button_bar do %> |
| @@ -31,7 +33,9 @@ | @@ -31,7 +33,9 @@ | ||
| 31 | 33 | ||
| 32 | <% button_bar do %> | 34 | <% button_bar do %> |
| 33 | <%= submit_button :save, _('Save') %> | 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 | <%= button :cancel, _('Cancel'), :action => 'view', :id => @parent_id || @article.parent %> | 39 | <%= button :cancel, _('Cancel'), :action => 'view', :id => @parent_id || @article.parent %> |
| 36 | <% else %> | 40 | <% else %> |
| 37 | <%= button :cancel, _('Cancel'), :action => 'index' %> | 41 | <%= button :cancel, _('Cancel'), :action => 'index' %> |
test/functional/cms_controller_test.rb
| @@ -505,4 +505,28 @@ class CmsControllerTest < Test::Unit::TestCase | @@ -505,4 +505,28 @@ class CmsControllerTest < Test::Unit::TestCase | ||
| 505 | assert_equal [c1, c2], assigns(:categories) | 505 | assert_equal [c1, c2], assigns(:categories) |
| 506 | end | 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 | end | 532 | end |