- No more Home object
- Sitemap on the left side and view of the current page in the main block
This commit is contained in:
parent
9fdfb140d3
commit
d9ba76ebd5
|
@ -1,50 +0,0 @@
|
|||
class Admin::HomesController < ApplicationController
|
||||
|
||||
layout "admin"
|
||||
before_filter :authenticate_user!
|
||||
before_filter :is_admin?
|
||||
|
||||
def show
|
||||
#TODO
|
||||
end
|
||||
|
||||
def new
|
||||
@home = Home.new
|
||||
@home.is_published = true
|
||||
@home.parent_id = nil
|
||||
end
|
||||
|
||||
def edit
|
||||
@home = Home.find(params[:id])
|
||||
@i18n_variable = @home.i18n_variable
|
||||
end
|
||||
|
||||
def create
|
||||
@home = Home.new(params[:home])
|
||||
|
||||
if @home.save
|
||||
flash[:notice] = t('admin.create_success_home')
|
||||
redirect_to admin_items_url
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@home = Home.find(params[:id])
|
||||
if @home.update_attributes(params[:home])
|
||||
flash[:notice] = t('admin.update_success_home')
|
||||
redirect_to admin_items_url
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@home = Home.find(params[:id])
|
||||
@home.destroy
|
||||
|
||||
redirect_to admin_items_url
|
||||
end
|
||||
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
class Admin::ItemsController < ApplicationController
|
||||
|
||||
layout "admin"
|
||||
layout "content"
|
||||
|
||||
before_filter :authenticate_user!
|
||||
before_filter :find_parent_item
|
||||
|
@ -8,8 +8,11 @@ class Admin::ItemsController < ApplicationController
|
|||
before_filter :is_admin?
|
||||
|
||||
def index
|
||||
@items = Item.where(:parent_id => @parent_item.id).entries rescue []
|
||||
@items = Item.where(:_type => 'Home').entries unless (!@items.empty? || @parent_item)
|
||||
if params[:item_id]
|
||||
@page = Item.find(params[:item_id])
|
||||
else
|
||||
@page = Item.first(:conditions => {:parent_id => nil})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class Admin::PagesController < ApplicationController
|
||||
|
||||
layout "admin"
|
||||
layout "content"
|
||||
before_filter :authenticate_user!
|
||||
before_filter :find_parent_item
|
||||
before_filter :is_admin?
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class PagesController < ApplicationController
|
||||
|
||||
def index
|
||||
@page = Home.find_by_name('home')
|
||||
@page = Page.find_by_name('home')
|
||||
if @page
|
||||
render_page
|
||||
else
|
||||
|
|
|
@ -48,5 +48,26 @@ module ApplicationHelper
|
|||
message % item
|
||||
end
|
||||
end
|
||||
|
||||
def render_node_and_children(node, current_name = 'home')
|
||||
ret = ''
|
||||
if node
|
||||
ret << "<li>"
|
||||
ret << (link_to node.name, admin_items_path(:item_id => node.id), :remote => true, :class => (current_name.eql?(node.name) ? 'sidebar_no_link' : 'sidebar_link'))
|
||||
ret << render_children(node) if node.children.size > 0
|
||||
ret << "</li>"
|
||||
end
|
||||
ret.html_safe
|
||||
end
|
||||
|
||||
def render_children(parent)
|
||||
ret = ''
|
||||
ret << "<ul>"
|
||||
parent.children.each do |child|
|
||||
ret << render_node_and_children(child)
|
||||
end
|
||||
ret << "</ul>"
|
||||
ret
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class Component
|
||||
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :key
|
||||
field :document_class, :type => String
|
||||
field :parent_id, :type => BSON::ObjectId, :index => true
|
||||
|
||||
end
|
|
@ -1,10 +0,0 @@
|
|||
class Home < Page
|
||||
|
||||
private
|
||||
|
||||
# Remove the validation for parent_id
|
||||
def validates_presence_of_parent_id?
|
||||
false
|
||||
end
|
||||
|
||||
end
|
|
@ -15,10 +15,9 @@ class Item
|
|||
validates :name, :exclusion => { :in => LIST[:forbidden_item_names] }
|
||||
validates_uniqueness_of :name, :scope => :parent_id
|
||||
validates_presence_of :name, :full_name, :position, :is_published
|
||||
validates_presence_of :parent_id, :if => :validates_presence_of_parent_id?
|
||||
|
||||
referenced_in :parent, :class_name => "Item"
|
||||
references_many :children, :class_name => "Item"
|
||||
belongs_to :parent, :class_name => "Item"
|
||||
has_many :children, :class_name => "Item", :as => 'parent'
|
||||
|
||||
before_validation :setup_default_value
|
||||
|
||||
|
@ -59,11 +58,6 @@ class Item
|
|||
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
|
||||
end
|
||||
|
||||
# Check if the page is home
|
||||
def is_home?
|
||||
self.name.eql?('home') && (self.parent_id.nil? || self.parent_id.empty?)
|
||||
end
|
||||
|
||||
# Build the url from the array of ancestors
|
||||
def url
|
||||
urls = ancestors.map{ |a| a.name } << self.name
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
<%= f.hidden_field :parent_id %>
|
||||
|
||||
<p>
|
||||
<%= f.label :name, t('admin.name') %>
|
||||
<%= f.text_field :name, :class => 'text', :value => 'home', :disabled => true %>
|
||||
<%= f.hidden_field :name, :value => 'home' %>
|
||||
</p>
|
||||
|
||||
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<p>
|
||||
<%= label_tag "home[title]", "#{t('admin.title')} #{locale}" %>
|
||||
<%= text_field_tag "home[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :class => 'text' %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<p>
|
||||
<%= f.label :layout_id, t('admin.layout_name') %>
|
||||
<%= f.select :layout_id, Layout.all.map{ |l| [l.description, l.id] } %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label "content", t('admin.content') %>
|
||||
<%= f.text_area "content", :size => '100x30' %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label :is_published, "#{t('admin.is_published')} ?" %>
|
||||
<%= f.radio_button :is_published, true %>Yes <%= f.radio_button :is_published, false %> No
|
||||
</p>
|
|
@ -1,10 +0,0 @@
|
|||
<h1><%= t('admin.editing_home') %></h1>
|
||||
|
||||
<%= form_for @home, :url => admin_home_path(@home) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
<%= render :partial => "form", :locals => { :f => f } %>
|
||||
|
||||
<p>
|
||||
<%= f.submit t('update') %> <%= link_back %>
|
||||
</p>
|
||||
<% end %>
|
|
@ -1,11 +0,0 @@
|
|||
<h1><%= t('admin.new_home') %></h1>
|
||||
|
||||
<%= form_for :home, :url => admin_homes_path do |f| %>
|
||||
<%= f.error_messages %>
|
||||
<%= render :partial => "form", :locals => { :f => f } %>
|
||||
|
||||
<p>
|
||||
<%= f.submit t('create') %> <%= link_back %>
|
||||
</p>
|
||||
|
||||
<% end %>
|
|
@ -1,27 +1,36 @@
|
|||
<% content_for :secondary do %>
|
||||
<ul class="list">
|
||||
<% if (@items.empty? && !@parent_item ) || (!@items.empty? && @items[0].is_home?) %>
|
||||
<li><%= t('admin.new_page') %></li>
|
||||
<li><%= t('admin.new_link') %></li>
|
||||
<li><%= t('admin.new_snippet') %></li>
|
||||
<% else %>
|
||||
<li><%= link_to t('admin.new_page'), new_admin_page_path( :parent_id => @parent_item.id ), :class => 'button positive' %></li>
|
||||
<li><%= link_to t('admin.new_link'), new_admin_link_path( :parent_id => @parent_item.id ) %>
|
||||
<li><%= link_to t('admin.new_snippet'), new_admin_snippet_path( :parent_id => @parent_item.id ), :class => 'button positive' %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% content_for :sidebar do %>
|
||||
<div id='sidebar'><%= render 'layouts/site_map_left_bar' %></div>
|
||||
<% end -%>
|
||||
|
||||
<%= flash_messages %>
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
$('a.sidebar_link').live( "click", function(){
|
||||
$(this).removeClass('sidebar_link');
|
||||
$('.sidebar_no_link').addClass('sidebar_link');
|
||||
$('.sidebar_no_link').removeClass('sidebar_no_link');
|
||||
$(this).addClass('sidebar_no_link');
|
||||
});
|
||||
</script>
|
||||
<% end -%>
|
||||
|
||||
<% content_for :page_specific_css do %>
|
||||
<style type="text/css">
|
||||
.sidebar_no_link {
|
||||
pointer-events: none;
|
||||
cursor: default;
|
||||
}
|
||||
</style>
|
||||
<% end %>
|
||||
|
||||
<%= render 'layouts/page' %>
|
||||
|
||||
<!-- <%= flash_messages %>
|
||||
|
||||
<h1><%= t('admin.list_items') %>: <%= show_parent_items_link unless @parent_item.nil? %></h1>
|
||||
|
||||
<% if !Layout.exist_one? %>
|
||||
<div style='color:red'><%= t('admin.no_layout') %>: <%= link_to t('create').downcase, new_admin_layout_path %></div>
|
||||
<br/>
|
||||
<% elsif (@items.empty? && !@parent_item ) %>
|
||||
<div style='color:red'><%= t('admin.no_home_page') %>: <%= link_to t('create').downcase, new_admin_home_path(:parent_id => nil) %></div>
|
||||
<br/>
|
||||
<% else %>
|
||||
<table>
|
||||
<tr>
|
||||
|
@ -43,4 +52,4 @@
|
|||
</table>
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => "snippets", :locals => { :snippets => @snippets } %>
|
||||
<%= render :partial => "snippets", :locals => { :snippets => @snippets } %> -->
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
$('#main').empty();
|
||||
switch ("<%= escape_javascript(@page._type)%>") {
|
||||
case 'Link':
|
||||
$('#main').append("TODO: page to edit the link");
|
||||
break;
|
||||
case 'Page':
|
||||
$('#main').append("<%= escape_javascript(render(:partial => 'layouts/page')) %>");
|
||||
break;
|
||||
};
|
|
@ -2,12 +2,7 @@
|
|||
|
||||
<p>
|
||||
<%= f.label :name, t('admin.name') %>
|
||||
<% if @page.parent_id.nil? %>
|
||||
<%= f.text_field :name, :class => 'text', :value => 'home', :disabled => true %>
|
||||
<%= f.hidden_field :name, :value => 'home' %>
|
||||
<% else %>
|
||||
<%= f.text_field :name, :class => 'text' %>
|
||||
<% end %>
|
||||
<%= f.text_field :name, :class => 'text' %>
|
||||
</p>
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<%= parse_page(@page).html_safe if @page._type.eql?('Page') %>
|
|
@ -0,0 +1 @@
|
|||
<%= render_node_and_children(@page) %>
|
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<title><%= @title %></title>
|
||||
<link rel="shortcut icon" href="/favicon.ico">
|
||||
<%= yield :page_specific_link %>
|
||||
<%= stylesheet_link_tag "easy", "main", "devise", "content", :media => "screen, projection" %>
|
||||
<%= stylesheet_link_tag "easyprint", :media => "print" %>
|
||||
<%= javascript_include_tag "jquery", "jquery-ui", "rails", "easy", "application", :cache => 'all' %>
|
||||
<%= yield :page_specific_javascript %>
|
||||
<!--[if IE]>
|
||||
<%= stylesheet_link_tag "ie", :media => "screen, projection" %>
|
||||
<![endif]-->
|
||||
<%= yield :page_specific_css %>
|
||||
<%= csrf_meta_tag %>
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
</div>
|
||||
|
||||
<div id="content" class="content">
|
||||
<div id="sidebar" style='float: left;'><%= yield :sidebar %></div>
|
||||
<div id="main" style='float: left;'><%= yield %></div>
|
||||
</div>
|
||||
|
||||
<div id="footer">
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -24,6 +24,7 @@ module PrototypeR4
|
|||
|
||||
# Custom directories with classes and modules you want to be autoloadable.
|
||||
# config.autoload_paths += %W(#{config.root}/extras)
|
||||
config.autoload_paths = %W(#{config.root}/lib)
|
||||
|
||||
# Only load the plugins named here, in the order given (default is alphabetical).
|
||||
# :all can be used as a placeholder for all plugins not explicitly named.
|
||||
|
|
|
@ -82,10 +82,16 @@ module Parser
|
|||
end
|
||||
|
||||
def parse_page(page)
|
||||
layout_content = (page.layout)? page.layout.content : "<r:content />"
|
||||
if page._type == 'Page'
|
||||
layout_content = (page.layout)? page.layout.content : "<r:content />"
|
||||
context = parser_context(page.content)
|
||||
parser = Radius::Parser.new(context, :tag_prefix => 'r')
|
||||
parser.parse(parser.parse(layout_content))
|
||||
end
|
||||
end
|
||||
|
||||
def self.included(base)
|
||||
base.send :helper_method, :parse_page if base.respond_to? :helper_method
|
||||
end
|
||||
|
||||
end
|
|
@ -47,7 +47,7 @@ namespace :dev do
|
|||
|
||||
layout = Layout.create!( :name => 'root', :description => 'root', :content => File.open("#{RAILS_ROOT}/lib/template/root.layout").read )
|
||||
|
||||
home = Home.create!( :i18n_variable_id => var_10.id, :layout_id => layout.id, :name => 'home', :is_published => true, :content => File.open("#{RAILS_ROOT}/lib/template/root.home").read )
|
||||
home = Page.create!( :i18n_variable_id => var_10.id, :layout_id => layout.id, :name => 'home', :is_published => true, :content => File.open("#{RAILS_ROOT}/lib/template/root.home").read )
|
||||
|
||||
Page.create!( :i18n_variable_id => var_11.id, :layout_id => layout.id, :name => 'about', :is_published => true, :parent_id => home.id, :content => File.open("#{RAILS_ROOT}/lib/template/about.page").read )
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
html{
|
||||
height:100%;
|
||||
width:100%;
|
||||
}
|
Reference in New Issue