Skip to content

Commit

Permalink
Fixed edit publication redirect issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed Mar 29, 2010
1 parent 0f55a7e commit 366252e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 44 deletions.
9 changes: 4 additions & 5 deletions app/controllers/editor/publication_controller.rb
Expand Up @@ -50,19 +50,18 @@ def validate
def edit
@publication = @paragraph.content_publication

@options = EditOptions.new(params[:pub] || @paragraph.data || {})
@options = EditOptions.new(params[:edit] || @paragraph.data || {})
@options.additional_vars(@publication.filter_variables)

return if handle_paragraph_update(@options)

@pages = [['No Return Page', nil ]] + SiteNode.page_options()
end

class EditOptions < HashModel
default_options :return_page => nil, :options => [], :entry_id => nil, :allow_entry_creation => false
attributes :return_page_id => nil, :options => [], :entry_id => nil, :allow_entry_creation => false

page_options :return_page_id

boolean_options :allow_entry_creation
integer_options :return_page,:entry_id
end

def view
Expand Down
30 changes: 6 additions & 24 deletions app/controllers/editor/publication_renderer.rb
Expand Up @@ -171,11 +171,9 @@ def view


def edit

publication = paragraph.content_publication
content_connection,entry_id = page_connection()
options = paragraph.data || {}
pub_options = paragraph_options(:edit) # publication.data || {}
pub_options = paragraph_options(:edit)


if entry_id && entry_id.to_i != 0
Expand All @@ -188,36 +186,20 @@ def edit
render_paragraph :text => ''
return
end

if paragraph.data[:return_page]
redirect_node = SiteNode.find_by_id(paragraph.data[:return_page])
if redirect_node
return_page = redirect_node.node_path
end
end

return_page = '#' unless return_page

return_page = pub_options.return_page_url

if request.post? && params['entry_' + publication.id.to_s]

publication.update_entry(entry,params['entry_' + publication.id.to_s],
{:user => myself, :renderer => self, :controller => controller })

publication.update_entry(entry,params['entry_' + publication.id.to_s],renderer_state)
new_entry = entry.id ? false : true

if entry.save
expire_content(publication.content_model_id)
if publication.update_action_count > 0
if new_entry
publication.run_triggered_actions(entry,'create',myself)
else
publication.run_triggered_actions(entry,'edit',myself)
end
publication.run_triggered_actions(entry,new_entry ? 'create' : 'edit',myself)
end
if return_page
redirect_paragraph redirect_node.node_path
return
end
return redirect_paragraph(return_page) if return_page
end
else
if publication.view_action_count > 0
Expand Down
12 changes: 2 additions & 10 deletions app/views/editor/publication/edit.rhtml
@@ -1,14 +1,6 @@
<div class='cms_form'>
<h3><%= sprintf("%s Options".t,@publication.name) %></h3>

<% tabled_form_for :pub, @options,
:html => { :id => 'edit_entry',
:onsubmit => "cmsEdit.submitParagraphData(this,'#{url_for :action => 'edit'}',#{@paragraph.id},#{@paragraph_index}); return false;"
} do |f| -%>
<%= f.select :return_page, @pages, :label => 'Return Page' %>
<% paragraph_options_form_for "Edit Publication Options", :edit, @options do |f| -%>
<%= f.page_selector :return_page_id %>
<%= f.check_boxes :allow_entry_creation, [ ['Allow creation',true ]], :single => true %>
<% end -%>
<hr/>
<a class='cms_ajax_link' href='javascript:void(0);' onclick="$('edit_entry').onsubmit();"><%= "Update &amp; Close".t %></a>
<a class='cms_ajax_link' href='javascript:void(0);' onclick='cmsEdit.closeBox();'><%= "Cancel".t %></a>
</div>
10 changes: 5 additions & 5 deletions spec/controllers/editor/publication_renderer_spec.rb
Expand Up @@ -125,7 +125,7 @@ def generate_edit_renderer(publication,data = {},page_connection={},options={})
it "should be able to display the edit form on an existing entry" do
@entry = @cm.content_model.create(:string_field => 'This is a test of the emergency broadcast system')

@rnd = generate_edit_renderer(@publication, { :redirect_page => @view_page_node.id }, { :input => [ :entry_id, @entry.id ] })
@rnd = generate_edit_renderer(@publication, { :return_page_id => @view_page_node.id }, { :input => [ :entry_id, @entry.id ] })
@rnd.should_render_feature('form')
renderer_get @rnd
end
Expand All @@ -135,7 +135,7 @@ def generate_edit_renderer(publication,data = {},page_connection={},options={})

@entry = @cm.content_model.create(:string_field => 'This is a test of the emergency broadcast system')

@rnd = generate_edit_renderer(@publication, { :redirect_page => @view_page_node.id }, { :input => [ :entry_id, @entry.id ] }, :site_feature_id => @feature.id)
@rnd = generate_edit_renderer(@publication, { :return_page_id => @view_page_node.id }, { :input => [ :entry_id, @entry.id ] }, :site_feature_id => @feature.id)
@rnd.should_render_feature('form')
renderer_get @rnd

Expand All @@ -147,7 +147,7 @@ def generate_edit_renderer(publication,data = {},page_connection={},options={})
@entry.string_field.should == "This is a test of the emergency broadcast system"

@cm.content_model.count.should == 1
@rnd = generate_edit_renderer(@publication, { :return_page => @view_page_node.id }, { :input => [ :entry_id, @entry.id ] })
@rnd = generate_edit_renderer(@publication, { :return_page_id => @view_page_node.id }, { :input => [ :entry_id, @entry.id ] })

renderer_post @rnd, { "entry_#{@publication.id}" => { :string_field => 'Yay!' } }

Expand All @@ -170,14 +170,14 @@ def generate_edit_renderer(publication,data = {},page_connection={},options={})
end

it "should be display the create form if allowed" do
@rnd = generate_edit_renderer(@publication, { :redirect_page => @view_page_node.id,:allow_entry_creation => true })
@rnd = generate_edit_renderer(@publication, { :return_page_id => @view_page_node.id,:allow_entry_creation => true })

@rnd.should_render_feature('form')
renderer_get @rnd
end

it "should be able to create a new entry if allowed" do
@rnd = generate_edit_renderer(@publication, { :return_page => @view_page_node.id,:allow_entry_creation => true })
@rnd = generate_edit_renderer(@publication, { :return_page_id => @view_page_node.id,:allow_entry_creation => true })

@cm.content_model.count.should == 0

Expand Down

0 comments on commit 366252e

Please sign in to comment.