- No more Home object

- Sitemap on the left side and view of the current page in the main block
This commit is contained in:
chris2tof committed 2011-05-09 18:49:57 +08:00
1 parent 9fdfb140d3
commit d9ba76ebd5
21 files changed
+122 -149

No files matched your search

-50
View File
@@ -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
+6 -3
View File
@@ -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 -1
View File
@@ -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 -1
View File
@@ -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
+21
View File
@@ -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
+10
View File
@@ -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
-10
View File
@@ -1,10 +0,0 @@
class Home < Page
private
# Remove the validation for parent_id
def validates_presence_of_parent_id?
false
end
end
+2 -8
View File
@@ -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
-91
View File
@@ -1,91 +0,0 @@
module Parser
def parser_context(page_content, attributes = {})
Radius::Context.new do |c|
c.define_tag 'content' do |tag|
page_content
end
c.define_tag 'snippet' do |tag|
snippet = Snippet.first(:conditions => {:name => tag.attr['name']})
if snippet
snippet.content
else
t('nothing')
end
end
c.define_tag 'language_bar' do
@site.in_use_locales.map{ |locale|
lang = I18nVariable.first(:conditions => {:key => locale})[locale]
if I18n.locale.to_s.eql?(locale)
lang
else
"<a href='?locale=#{locale}'>#{lang}</a>"
end
}.join(' | ')
end
c.define_tag 'locale' do |tag|
case attributes[:locale]
when 'create'
var = I18nVariable.new(:key => (tag.attr['name'] rescue nil), :document_class => 'Text')
@site.valid_locales.each do |locale|
var[locale] = tag.attr[locale] rescue nil
end
var.save!
res = ''
res << "<r:locale id='#{var.id}' "
res << "name='#{var.key}' " if var.key
@site.valid_locales.each do |locale|
res << "#{locale}='#{var[locale]}' "
end
res << '/>'
when 'show'
var = I18nVariable.find(tag.attr['id'])
res = ''
res << "<r:locale "
res << "name='#{var.key}' " if var.key
@site.valid_locales.each do |locale|
res << "#{locale}='#{var[locale]}' "
end
res << '/>'
when 'destroy'
var = I18nVariable.find(tag.attr['id'])
var.destroy
else
tag.attr[I18n.locale.to_s] rescue nil
end
end
c.define_tag 'css' do |tag|
assets = Asset.any_in(:filename => tag.attr['name'].split(',').map(&:strip))
res = ''
assets.each do |asset|
res << "<link href='#{asset.data.file.url}' rel='stylesheet' type='text/css' /> " if asset.data.file.content_type.eql?('text/css')
end
res
end
c.define_tag 'image' do |tag|
asset = Asset.find(tag.attr['id'])
if asset
res = "<img src=#{asset.data.file.url} "
tag.attr.each do |l|
res << "#{l[0]}='#{l[1]}' "
end
res << '>'
end
end
end
end
def parse_content(page_content, attributes = {})
context = parser_context(page_content, attributes)
parser = Radius::Parser.new(context, :tag_prefix => 'r')
parser.parse(page_content)
end
def parse_page(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
-30
View File
@@ -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>
-10
View File
@@ -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 %>
-11
View File
@@ -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 %>
+26 -17
View File
@@ -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 } %> -->
+9
View File
@@ -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;
};
+1 -6
View File
@@ -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>
+1
View File
@@ -0,0 +1 @@
<%= parse_page(@page).html_safe if @page._type.eql?('Page') %>
@@ -0,0 +1 @@
<%= render_node_and_children(@page) %>
+30
View File
@@ -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>