Merge pull request #56 from finnlabs/feature/extended_wiki_tabs
Feature/extended wiki tabspull/41/head
commit
dbfecfae9c
@ -0,0 +1,62 @@ |
||||
class WikiMenuItemsController < ApplicationController |
||||
def edit |
||||
get_data_from_params(params) |
||||
end |
||||
|
||||
def update |
||||
wiki_menu_setting = params[:wiki_menu_item][:setting] |
||||
parent_wiki_menu_item = params[:parent_wiki_menu_item] |
||||
|
||||
get_data_from_params(params) |
||||
|
||||
if wiki_menu_setting == 'no_item' |
||||
@wiki_menu_item.destroy unless @wiki_menu_item.nil? |
||||
else |
||||
@wiki_menu_item.wiki_id = @page.wiki.id |
||||
@wiki_menu_item.name = params[:wiki_menu_item][:name] |
||||
@wiki_menu_item.title = @page_title |
||||
|
||||
if wiki_menu_setting == 'sub_item' |
||||
@wiki_menu_item.parent_id = parent_wiki_menu_item |
||||
elsif wiki_menu_setting == 'main_item' |
||||
@wiki_menu_item.parent_id = nil |
||||
|
||||
if params[:wiki_menu_item][:new_wiki_page] == "1" |
||||
@wiki_menu_item.new_wiki_page = true |
||||
elsif params[:wiki_menu_item][:new_wiki_page] == "0" |
||||
@wiki_menu_item.new_wiki_page = false |
||||
end |
||||
|
||||
if params[:wiki_menu_item][:index_page] == "1" |
||||
@wiki_menu_item.index_page = true |
||||
elsif params[:wiki_menu_item][:index_page] == "0" |
||||
@wiki_menu_item.index_page = false |
||||
end |
||||
end |
||||
end |
||||
|
||||
if not @wiki_menu_item.errors.size >= 1 and (@wiki_menu_item.destroyed? or @wiki_menu_item.save) |
||||
flash[:notice] = l(:notice_successful_update) |
||||
redirect_back_or_default({ :action => 'edit', :id => @page_title }) |
||||
else |
||||
respond_to do |format| |
||||
format.html { render :action => 'edit', :id => @page_title } |
||||
end |
||||
end |
||||
end |
||||
|
||||
private |
||||
|
||||
def get_data_from_params(params) |
||||
@project = Project.find(params[:project_id]) |
||||
|
||||
@page_title = params[:id] |
||||
@page = WikiPage.find_by_title_and_wiki_id(@page_title, @project.wiki.id) |
||||
|
||||
|
||||
@wiki_menu_item = WikiMenuItem.find_or_initialize_by_wiki_id_and_title(@page.wiki.id, @page_title) |
||||
|
||||
@possible_parent_menu_items = WikiMenuItem.main_items(@page.wiki.id) - [@wiki_menu_item] |
||||
@possible_parent_menu_items.map! {|item| [item.name, item.id]} |
||||
end |
||||
end |
@ -0,0 +1,61 @@ |
||||
class WikiMenuItem < ActiveRecord::Base |
||||
belongs_to :wiki |
||||
belongs_to :parent, :class_name => 'WikiMenuItem' |
||||
has_many :children, :class_name => 'WikiMenuItem', :dependent => :destroy, :foreign_key => :parent_id, :order => 'id ASC' |
||||
|
||||
serialize :options, Hash |
||||
|
||||
named_scope :main_items, lambda { |wiki_id| |
||||
{:conditions => {:wiki_id => wiki_id, :parent_id => nil}, :order => 'id ASC'} |
||||
} |
||||
|
||||
attr_accessible :name, :title |
||||
|
||||
validates_presence_of :title |
||||
validates_format_of :title, :with => /^[^,\.\/\?\;\|\:]*$/ |
||||
validates_uniqueness_of :title, :scope => :wiki_id |
||||
|
||||
validates_presence_of :name |
||||
|
||||
def after_initialize |
||||
self.options ||= Hash.new |
||||
end |
||||
|
||||
def item_class |
||||
title.dasherize |
||||
end |
||||
|
||||
def setting |
||||
if new_record? |
||||
:no_item |
||||
elsif is_main_item? |
||||
:main_item |
||||
else |
||||
:sub_item |
||||
end |
||||
end |
||||
|
||||
def new_wiki_page |
||||
!!options[:new_wiki_page] |
||||
end |
||||
|
||||
def new_wiki_page=(value) |
||||
options[:new_wiki_page] = value |
||||
end |
||||
|
||||
def index_page |
||||
!!options[:index_page] |
||||
end |
||||
|
||||
def index_page=(value) |
||||
options[:index_page] = value |
||||
end |
||||
|
||||
def is_main_item? |
||||
parent_id.nil? |
||||
end |
||||
|
||||
def is_sub_item? |
||||
!parent_id.nil? |
||||
end |
||||
end |
@ -1,19 +0,0 @@ |
||||
<% remote_form_for :wiki, @wiki, |
||||
:url => { :controller => 'wikis', :action => 'edit', :id => @project }, |
||||
:builder => TabularFormBuilder, |
||||
:lang => current_language do |f| %> |
||||
|
||||
<%= error_messages_for 'wiki' %> |
||||
|
||||
<div class="box tabular"> |
||||
<p><%= f.text_field :start_page, :size => 60, :required => true %><br /> |
||||
<em><%= l(:text_unallowed_characters) %>: , . / ? ; : |</em></p> |
||||
</div> |
||||
|
||||
<div class="contextual"> |
||||
<%= link_to(l(:button_delete), {:controller => 'wikis', :action => 'destroy', :id => @project}, |
||||
:class => 'icon icon-del') if @wiki && !@wiki.new_record? %> |
||||
</div> |
||||
|
||||
<%= submit_tag((@wiki.nil? || @wiki.new_record?) ? l(:button_create) : l(:button_save)) %> |
||||
<% end %> |
@ -0,0 +1,44 @@ |
||||
<h2> |
||||
<% if @page.parent %> |
||||
<% breadcrumb_for_page(@page.parent, l("create_new_page")) %> |
||||
<%= l("create_child_page_for", :title => @page.parent.pretty_title) %> |
||||
<% else %> |
||||
<% breadcrumb_paths(l("create_new_page")) %> |
||||
<%= l("create_new_page") %> |
||||
<% end %> |
||||
</h2> |
||||
|
||||
<% form_for :content, @content, :url => wiki_create_path(:project_id => @project), :html => {:method => :post, :multipart => true, :id => 'wiki_form'} do |f| %> |
||||
|
||||
<%= error_messages_for 'page' %> |
||||
|
||||
<% fields_for :page, @page do |page_fields| %> |
||||
<%= page_fields.hidden_field :parent_id %> |
||||
<p><label><%= l(:field_title) %></label><br /><%= page_fields.text_field :title, :size => 120 %></p> |
||||
<% end %> |
||||
|
||||
|
||||
<p><%= f.text_area :text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %></p> |
||||
<p><label><%= l(:field_comments) %></label><br /><%= f.text_field :comments, :size => 120 %></p> |
||||
<p><label><%=l(:label_attachment_plural)%></label><br /><%= render :partial => 'attachments/form' %></p> |
||||
|
||||
<p><%= submit_tag l(:button_save) %> |
||||
<%= link_to_remote l(:label_preview), |
||||
{ :url => wiki_preview_path(:project_id => @project), |
||||
:method => :post, |
||||
:update => 'preview', |
||||
:with => "Form.serialize('wiki_form')", |
||||
:complete => "Element.scrollTo('preview')" |
||||
}, :accesskey => accesskey(:preview) %></p> |
||||
<%= wikitoolbar_for 'content_text' %> |
||||
<% end %> |
||||
|
||||
<div id="preview" class="wiki"></div> |
||||
|
||||
<% content_for :header_tags do %> |
||||
<%= stylesheet_link_tag 'scm' %> |
||||
<%= robot_exclusion_tag %> |
||||
<% end %> |
||||
|
||||
<% html_title @page.pretty_title %> |
||||
|
@ -0,0 +1,46 @@ |
||||
<%= error_messages_for "wiki_menu_item", :object => @wiki_menu_item %> |
||||
|
||||
<% breadcrumb_paths(*@page.ancestors.reverse.collect {|parent| link_to h(parent.pretty_title), {:id => parent.title, :project_id => parent.project}}.push(@page.title)) %> |
||||
|
||||
<h2><%= l(:wiki_menu_item_for, :title => @page_title) %></h2> |
||||
<% form_for :wiki_menu_item, @wiki_menu_item, :html => {:id => 'wiki_menu_item_form', :class => 'wiki_menu_item_form', :method => :put}, :url => wiki_menu_item_path(@project, @page_title) do |form| %> |
||||
<p class="name_of_item"> |
||||
<%= form.label :name, l(:label_menu_item_name), {:id => 'name_of_item'} %> |
||||
<% if @wiki_menu_item.name.nil? %> |
||||
<%= form.text_field :name, :size => 20, :value => @page_title.gsub("_"," ") %> |
||||
<% else %> |
||||
<%= form.text_field :name, :size => 20 %> |
||||
<% end %> |
||||
</p> |
||||
</br> |
||||
<div style="clear: both;"></div> |
||||
<fieldset class="box" id="wiki_menu_item_setting"><legend><%=l(:wiki_menu_item_setting)%></legend> |
||||
<p> |
||||
<%= form.radio_button 'setting', :no_item %> |
||||
<%= form.label 'setting_no_item', l(:label_wiki_dont_show_menu_item) %> |
||||
</p> |
||||
<p class="main_item"> |
||||
<%= form.radio_button 'setting', :main_item %> |
||||
<%= form.label 'setting_main_item', l(:label_wiki_show_menu_item) %> |
||||
</p> |
||||
<p class="wiki_menu_item_optional_links"> |
||||
<%= form.check_box 'new_wiki_page' %> |
||||
<%= form.label 'new_wiki_page', l(:label_wiki_show_new_page_link) %> |
||||
|
||||
</br> |
||||
|
||||
<%= form.check_box 'index_page' %> |
||||
<%= form.label 'index_page', l(:label_wiki_show_index_page_link) %> |
||||
</p> |
||||
<p> |
||||
<% disabled = @possible_parent_menu_items.empty? %> |
||||
<%= form.radio_button 'setting', :sub_item, :disabled => disabled %> |
||||
<%= form.label 'setting_sub_item', l(:label_wiki_show_submenu_item), {:id => 'with-select'} %> |
||||
<%= select_tag "parent_wiki_menu_item", options_for_select(@possible_parent_menu_items), :disabled => disabled %> |
||||
</p> |
||||
</fieldset> |
||||
<p> |
||||
<%= submit_tag l(:button_save), :method => :post %> |
||||
<%= link_to l(:button_cancel), {:controller => 'wiki', :action => 'show', :project_id => @project, :id => @page_title} %> |
||||
</p> |
||||
<% end %> |
@ -0,0 +1,16 @@ |
||||
class CreateWikiMenuItems < ActiveRecord::Migration |
||||
def self.up |
||||
create_table :wiki_menu_items do |t| |
||||
t.column :name, :string |
||||
t.column :title, :string |
||||
t.column :parent_id, :integer |
||||
t.column :options, :text |
||||
|
||||
t.belongs_to :wiki |
||||
end |
||||
end |
||||
|
||||
def self.down |
||||
puts "You cannot safely undo this migration!" |
||||
end |
||||
end |
@ -0,0 +1,18 @@ |
||||
class CreateWikiMenuItemForExistingWikis < ActiveRecord::Migration |
||||
def self.up |
||||
Wiki.all.each do |wiki| |
||||
menu_item = WikiMenuItem.new |
||||
menu_item.name = wiki.start_page |
||||
menu_item.title = wiki.start_page |
||||
menu_item.wiki_id = wiki.id |
||||
menu_item.index_page = true |
||||
menu_item.new_wiki_page = true |
||||
|
||||
menu_item.save! |
||||
end |
||||
end |
||||
|
||||
def self.down |
||||
puts "You cannot safely undo this migration!" |
||||
end |
||||
end |
Loading…
Reference in new issue