Skip to content

Commit

Permalink
Merge branch 'blog-wizard' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed Mar 4, 2010
2 parents c314d42 + d90c66b commit 2d281de
Show file tree
Hide file tree
Showing 16 changed files with 256 additions and 10 deletions.
3 changes: 2 additions & 1 deletion app/controllers/cms_controller.rb
Expand Up @@ -273,7 +273,8 @@ def cms_page_info(title,section=nil,menu_js = nil) # :nodoc:
# The last page title does not need to exist in cms_admin_paths unless it
# is referenced somewhere else in the controller.
def self.cms_admin_paths(section,pages = {})
pages['Content'] ||= { :controller => '/content' }
pages['Content'] ||= { :controller => '/content' }
pages['Website'] ||= { :controller => '/structure' }
pages['Options'] ||= { :controller => '/options' }
pages['Modules'] ||= { :controller => '/options/modules' }
sing = class << self; self; end
Expand Down
19 changes: 17 additions & 2 deletions app/controllers/structure_controller.rb
Expand Up @@ -4,12 +4,16 @@ class StructureController < CmsController # :nodoc: all

public

permit ['editor_structure','editor_structure_advanced'], :except => [ :index, :element_info ]
permit ['editor_structure','editor_structure_advanced'], :except => [ :index, :element_info, :wizards ]
permit ['editor_website','editor_structure','editor_structure_advanced'], :only => [:index, :element_info]


permit ['editor_structure_advanced'], :only => [:wizards]

helper :application


cms_admin_paths 'website'


def index
session[:structure_view_modifiers] = @display_modifiers= params[:modifiers] ||
Expand Down Expand Up @@ -45,10 +49,21 @@ def index
@active_modules = SiteModule.structure_modules
end

@wizard_list = get_handlers(:structure,:wizard) if myself.has_role?('editor_structure_advanced')

cms_page_info 'Website', 'website',myself.has_role?('editor_structure_advanced') ? 'CMSStructure.popup();' : nil
render :action => 'view', :layout => "manage"
end


def wizards
cms_page_path ['Website'], "Wizards"

@wizard_list = get_handler_info(:structure,:wizard) if myself.has_role?('editor_structure_advanced')
@wizard_list = @wizard_list.select { |info| myself.has_role?(info[:permit]) }

end


def move_node
node_id = params[:node_id]
Expand Down
18 changes: 18 additions & 0 deletions app/models/page_paragraph.rb
Expand Up @@ -169,6 +169,24 @@ def direct_set_page_connections(conns)
def display_module_identifier
self.display_module.gsub("/","_")
end

def add_paragraph_input!(input_name,other_para,conn_type,identifier)
self.connections ||= { }
self.connections[:inputs] ||= { }
self.connections[:inputs][input_name.to_sym] = [ other_para.identity_hash, conn_type.to_sym, identifier.to_sym]

other_para.connections ||= { }
other_para.connections[:outputs] ||= []
other_para.connections[:outputs] << [ identifier.to_sym, self.identity_hash, input_name.to_sym ]
other_para.save
self.save
end

def add_page_input(input_name,conn_type,identifier)
self.connections ||= { }
self.connections[:inputs] ||= { }
self.connections[:inputs][input_name.to_sym] = [ "0", conn_type.to_sym, identifier.to_sym]
end

def page_connection(name)
@page_connections ||= {}
Expand Down
13 changes: 13 additions & 0 deletions app/models/page_revision.rb
Expand Up @@ -241,6 +241,19 @@ def deactivate
self.revision,self.revision_container_type,self.revision_container_id, self.language])
end
end


# Programmatically add a paragraph to a revision
def add_paragraph(renderer_class,name,paragraph_options={ },options={ })

self.page_paragraphs.build(
:zone_idx => options[:zone] || 1,
:display_type => name,
:display_module => renderer_class,
:data => paragraph_options
)
end



end
1 change: 1 addition & 0 deletions app/views/structure/view.rhtml
Expand Up @@ -38,6 +38,7 @@ if @show_archived == 'hide'
p.link 'Hide Archived', :icon => 'show.gif', :url => '?archived=hide'
end
%>
<%= p.link('Wizards',:icon => 'configure.gif',:action => 'wizards') if @wizard_list.length > 0 -%>
<% end -%>
<div class='admin_content'>

Expand Down
8 changes: 8 additions & 0 deletions app/views/structure/wizards.rhtml
@@ -0,0 +1,8 @@

<div class='admin_content'>

<% @wizard_list.each do |wizard| -%>
<h2><%= link_to wizard[:name], wizard[:url] -%></h2>
<%= simple_format(wizard[:description]) -%>
<% end -%>
</div>
4 changes: 2 additions & 2 deletions lib/styled_form_builder_generator.rb
Expand Up @@ -698,7 +698,7 @@ def custom_field(field,options={},&block)
end

generate_styled_fields('form_options',
(field_helpers + %w(label_field label_option_field country_select collection_select select radio_buttons check_box check_boxes grouped_check_boxes grouped_radio_buttons grouped_select ) - %w(radio_button hidden_field))) do
(field_helpers + %w(label_field label_option_field country_select collection_select select radio_buttons check_boxes grouped_check_boxes grouped_radio_buttons grouped_select ) - %w(radio_button hidden_field))) do
field(@options)
end

Expand Down Expand Up @@ -830,7 +830,7 @@ class CmsForm < TabledForm

include WebivaFormElements
generate_styled_fields('form_options',
%w(access_control filemanager_image filemanager_folder filemanager_file price_classes price_range color_field date_field time_zone_select datetime_field upload_image upload_document unsorted_selector content_selector multi_content_selector image_list end_user_selector autocomplete_field ordered_selection_list ordered_array captcha)) do
%w(add_page_selector access_control filemanager_image filemanager_folder filemanager_file price_classes price_range color_field date_field time_zone_select datetime_field upload_image upload_document unsorted_selector content_selector multi_content_selector image_list end_user_selector autocomplete_field ordered_selection_list ordered_array captcha)) do
field(@options)
end

Expand Down
10 changes: 10 additions & 0 deletions lib/webiva_form_elements.rb
Expand Up @@ -1006,4 +1006,14 @@ def access_control(field,message,options={})
def captcha(field, captcha, options={})
captcha.generate(options)
end


def add_page_selector(field,options={ })

self.select_original("#{field}_id",[['--Select Page--'.t,nil]] + SiteNode.page_options) +
" / " +
self.text_field_original("#{field}_subpage",:size => 10, :disabled => !@object.send("#{field}_existing").blank?) +
"<br/>" +
self.check_boxes_original("#{field}_existing", [["Add to an existing page",true]], :single => true, :onclick => " $('#{object_name}_#{field}_subpage').disabled = this.checked")
end
end
12 changes: 9 additions & 3 deletions vendor/modules/blog/app/controllers/blog/admin_controller.rb
Expand Up @@ -11,6 +11,7 @@ class Blog::AdminController < ModuleController

content_model :blogs

register_handler :structure, :wizard, "Blog::WizardController"
register_handler :feed, :rss, "Blog::RssHandler"
register_handler :mail_manager, :generator, "Blog::ManageController"

Expand Down Expand Up @@ -39,12 +40,17 @@ def self.get_blogs_info
def create
cms_page_info [ ["Content",url_for(:controller => '/content') ], "Create a new Blog"], "content"

@blog = Blog::BlogBlog.new(params[:blog])
@blog = Blog::BlogBlog.new(params[:blog] || { :add_to_site => true })

if(request.post? && params[:blog])
if(@blog.save)
redirect_to :controller => '/blog/manage', :path => @blog.id
return
if @blog.add_to_site
redirect_to :controller => '/blog/wizard', :blog_id => @blog.id
return
else
redirect_to :controller => '/blog/manage', :path => @blog.id
return
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion vendor/modules/blog/app/controllers/blog/page_feature.rb
Expand Up @@ -133,7 +133,7 @@ def blog_entry_tags(c,data)
feature :blog_categories, :default_feature => <<-FEATURE
<cms:categories>
<cms:category>
<a <cms:category_href/>><cms:selected> class='selected'</cms:selected>><cms:name/></a><br/>
<cms:category_link selected_class='selected'><cms:name/></cms:category_link><br/>
</cms:category>
</cms:categories>
<br/><br/>
Expand Down
35 changes: 35 additions & 0 deletions vendor/modules/blog/app/controllers/blog/wizard_controller.rb
@@ -0,0 +1,35 @@
# Copyright (C) 2010 Cykod LLC.

class Blog::WizardController < ModuleController

permit 'blog_config'

component_info 'Blog'

cms_admin_paths 'website'

def self.structure_wizard_handler_info
{ :name => "Add a Blog to your Site",
:description => 'This wizard will add an existing blog to a url on your site.',
:permit => "blog_config",
:url => { :controller => '/blog/wizard' }
}
end

def index
cms_page_path ["Website"],"Add a Blog to your site structure"

@blog_wizard = Blog::AddBlogWizard.new(params[:wizard] || { :blog_id => params[:blog_id].to_i})
if request.post?
if !params[:commit]
redirect_to :controller => '/structure', :action => 'wizards'
elsif @blog_wizard.valid?
@blog_wizard.add_to_site!
flash[:notice] = "Added blog to site"
redirect_to :controller => '/structure'
end
end
end


end
91 changes: 91 additions & 0 deletions vendor/modules/blog/app/models/blog/add_blog_wizard.rb
@@ -0,0 +1,91 @@


class Blog::AddBlogWizard < HashModel

attributes :blog_id => nil,
:add_to_id=>nil,
:add_to_subpage => nil,
:add_to_existing => nil,
:detail_page_url => 'view',
:opts => []


validates_format_of :add_to_subpage, :with => /^[a-zA-Z0-9\-_]+$/, :message => 'is an invalid url'
validates_format_of :detail_page_url, :with => /^[a-zA-Z0-9\-_]+$/, :message => 'is an invalid url'
validates_presence_of :add_to_id

validates_presence_of :blog_id
validates_presence_of :detail_page_url

def validate
if self.add_to_existing.blank? && self.add_to_subpage.blank?
self.errors.add(:add_to," must have a subpage selected or add\n to existing must be checked")
end
end

def add_to_site!
nd = SiteNode.find(self.add_to_id)

if self.add_to_existing.blank?
nd = nd.add_subpage(self.add_to_subpage)
end

sub = nd.add_subpage(self.detail_page_url)
sub.save

list_revision = nd.page_revisions[0]
detail_revision = sub.page_revisions[0]

list_para = list_revision.add_paragraph('/blog/page','entry_list',
{
:detail_page => sub.id,
:blog_id => self.blog_id
}
)
list_para.add_page_input(:type,:page_arg_0,:list_type)
list_para.add_page_input(:identifier,:page_arg_1,:list_type_identifier)
list_para.save

detail_para = detail_revision.add_paragraph('/blog/page','entry_detail',
{
:list_page_id => nd.id,
:blog_id => self.blog_id
}
)

detail_para.add_page_input(:input,:page_arg_0,:post_permalink)
detail_para.save

if self.opts.include?('comments')

comments_paragraph = detail_revision.add_paragraph('/feedback/comments','comments',
{
:show => -1,
:allowed_to_post => 'all',
:linked_to_type => 'connection',
:captcha => false,
:order => 'newest'
}
)

comments_paragraph.save
comments_paragraph.add_paragraph_input!(:input,detail_para,:content_id,:content_identifier)
end

if self.opts.include?('categories')
cat_para = list_revision.add_paragraph('/blog/page','categories',
{
:detail_page => sub.id,
:blog_id => self.blog_id,
:list_page_id => nd.id
},
:zone => 3
)
cat_para.save
cat_para.add_paragraph_input!(:input,list_para,:category,:category)
end



end
end
2 changes: 2 additions & 0 deletions vendor/modules/blog/app/models/blog/blog_blog.rb
Expand Up @@ -13,6 +13,8 @@ class Blog::BlogBlog < DomainModel

cached_content # Add cached content support

attr_accessor :add_to_site

include SiteAuthorizationEngine::Target
access_control :edit_permission

Expand Down
3 changes: 2 additions & 1 deletion vendor/modules/blog/app/views/blog/admin/create.rhtml
@@ -1,11 +1,12 @@
<div class='admin_content'>
<% cms_form_for :blog, @blog, :html => { :class => 'admin_form' } do |f| -%>
<% cms_form_for :blog, @blog,:vertical => true, :html => { :class => 'admin_form' } do |f| -%>
<%= f.header 'Blog Information' %>
<%= f.text_field :name, :vertical => true, :required => true %>
<%= f.text_area :description, :vertical => true %>
<%= f.select :content_filter, Blog::BlogBlog.filter_options, :vertical => true %>
<%= f.filemanager_folder :folder_id, :vertical => true %>
<%= f.check_boxes :add_to_site, [["Run the add to site wizard".t,true]],:single => true, :vertical => true -%>
<%= f.submit_tag 'Create Blog', :vertical => true%>
<% end -%>
</div>
15 changes: 15 additions & 0 deletions vendor/modules/blog/app/views/blog/wizard/index.html.erb
@@ -0,0 +1,15 @@
<div class='admin_content'>

<% admin_form_for :wizard, @blog_wizard do |f| -%>
<%= f.select :blog_id, Blog::BlogBlog.select_options_with_nil('Blog'), :label => 'Blog to Add' -%>
<%= f.add_page_selector :add_to -%>
<%= f.text_field :detail_page_url, :label => "Detail Page", :size => 10 -%>
<%= f.check_boxes :opts, [['Add a comments paragraph','comments'],
['Add Categories to list page','categories']],
:label => 'Options', :separator => '<br/>'-%>
<%= f.spacer -%>
<%= f.cancel_submit_buttons 'Cancel', 'Add to Site' -%>
<% end -%>
</div>
30 changes: 30 additions & 0 deletions vendor/modules/blog/spec/models/blog/add_blog_wizard_spec.rb
@@ -0,0 +1,30 @@
# Copyright (C) 2009 Pascal Rettig.

require File.expand_path(File.dirname(__FILE__)) + "/../../../../../../spec/spec_helper"


describe Blog::AddBlogWizard do


reset_domain_tables :blog_blogs, :blog_posts, :blog_post_revisions, :blog_posts_categories, :blog_categories, :content_nodes, :content_types, :site_nodes, :page_paragraphs,:page_revisions

before(:each) do
@blog = Blog::BlogBlog.create(:name => 'Test Blog',:content_filter => 'full_html')
end

it "should add the blog to site" do
root_node = SiteVersion.default.root_node.add_subpage('tester')
wizard = Blog::AddBlogWizard.new(
:blog_id => @blog.id,
:add_to_id => root_node.id,
:add_to_subpage => 'blog',
:detail_page_url => 'myview'
)
wizard.add_to_site!

SiteNode.find_by_node_path('/blog').should_not be_nil
SiteNode.find_by_node_path('/blog/myview').should_not be_nil

end

end

0 comments on commit 2d281de

Please sign in to comment.