Uniformized: @page and @ link in @item
Change parser for page edition.
This commit is contained in:
1 parent
3d97c5bfda
commit
d971a8ecbe
20 files changed
+246
-73
No files matched your search
@@ -13,7 +13,6 @@ class Admin::ItemsController < ApplicationController
|
||||
@item = Item.find(params[:item_id])
|
||||
else
|
||||
@item = Item.first(:conditions => {:parent_id => nil})
|
||||
@page = @item
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,60 +7,60 @@ class Admin::LinksController < ApplicationController
|
||||
before_filter :is_admin?
|
||||
|
||||
def show
|
||||
@link ||= Link.find(params[:id])
|
||||
@item ||= Link.find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
@link = Link.new
|
||||
@link.is_published = true
|
||||
@link.parent_id = Page.find(params[:parent_id]).id rescue nil
|
||||
@item = Link.new
|
||||
@item.is_published = true
|
||||
@item.parent_id = Page.find(params[:parent_id]).id rescue nil
|
||||
end
|
||||
|
||||
def edit
|
||||
@link = Link.find(params[:id])
|
||||
@i18n_variable = @link.i18n_variable
|
||||
@item = Link.find(params[:id])
|
||||
@i18n_variable = @item.i18n_variable
|
||||
end
|
||||
|
||||
def create
|
||||
@link = Link.new(params[:link])
|
||||
@item = Link.new(params[:link])
|
||||
|
||||
if @link.save
|
||||
if @item.save
|
||||
flash.now[:notice] = t('admin.create_success_link')
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
redirect_to admin_link_url(@link)
|
||||
redirect_to admin_link_url(@item)
|
||||
}
|
||||
format.js {}
|
||||
end
|
||||
else
|
||||
flash.now[:error] = t('admin.create_error_link')
|
||||
@i18n_variable = @link.i18n_variable
|
||||
@i18n_variable = @item.i18n_variable
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@link = Link.find(params[:id])
|
||||
@item = Link.find(params[:id])
|
||||
|
||||
if @link.update_attributes(params[:link])
|
||||
if @item.update_attributes(params[:link])
|
||||
flash.now[:notice] = t('admin.update_success_link')
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
redirect_to admin_link_url(@link)
|
||||
redirect_to admin_link_url(@item)
|
||||
}
|
||||
format.js {}
|
||||
end
|
||||
else
|
||||
flash.now[:error] = t('admin.update_error_link')
|
||||
@i18n_variable = @link.i18n_variable
|
||||
@i18n_variable = @item.i18n_variable
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@link = Link.find(params[:id])
|
||||
@link.destroy
|
||||
@link.destroy_i18n_variable
|
||||
@item = Link.find(params[:id])
|
||||
@item.destroy
|
||||
@item.destroy_i18n_variable
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
redirect_to admin_items_url
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
class Admin::PagePartsController < ApplicationController
|
||||
|
||||
layout "content"
|
||||
|
||||
before_filter :authenticate_user!
|
||||
before_filter :is_admin?
|
||||
before_filter :set_current_item
|
||||
|
||||
def show
|
||||
@part = PagePart.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
render 'admin/items/index'
|
||||
}
|
||||
format.js {}
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
|
||||
end
|
||||
|
||||
def edit
|
||||
@part = PagePart.find(params[:id])
|
||||
#@part.content = parse_content(@part.content, {:locale => 'show'})
|
||||
# @part = @part.i18n_variable
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
@part = PagePart.find(params[:id])
|
||||
parse_content(@part.content, {:locale => 'destroy'})
|
||||
if @part.update_attributes(params[:page])
|
||||
@part.content = parse_content(@part.content, {:locale => 'create'})
|
||||
@part.save!
|
||||
flash[:notice] = t('admin.update_success_page')
|
||||
redirect_to admin_items_url( :parent_id => @part.page_id )
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@item = Page.find(params[:id])
|
||||
@item.destroy
|
||||
@item.destroy_i18n_variable
|
||||
|
||||
redirect_to admin_items_url( :parent_id => @item.parent_id )
|
||||
end
|
||||
|
||||
end
|
||||
@@ -8,10 +8,9 @@ class Admin::PagesController < ApplicationController
|
||||
before_filter :set_current_item
|
||||
|
||||
def show
|
||||
@page = Page.find(params[:id])
|
||||
@item = Page.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@item = @page
|
||||
render 'admin/items/index'
|
||||
}
|
||||
format.js {}
|
||||
@@ -19,47 +18,47 @@ class Admin::PagesController < ApplicationController
|
||||
end
|
||||
|
||||
def new
|
||||
@page = Page.new
|
||||
@page.is_published = true
|
||||
@page.parent_id = @parent_item.id rescue nil
|
||||
@item = Page.new
|
||||
@item.is_published = true
|
||||
@item.parent_id = @parent_item.id rescue nil
|
||||
end
|
||||
|
||||
def edit
|
||||
@page = Page.find(params[:id])
|
||||
@page.content = parse_content(@page.content, {:locale => 'show'})
|
||||
@i18n_variable = @page.i18n_variable
|
||||
@item = Page.find(params[:id])
|
||||
@item.content = parse_content(@item.content, {:locale => 'show'})
|
||||
@i18n_variable = @item.i18n_variable
|
||||
end
|
||||
|
||||
def create
|
||||
@page = Page.new(params[:page])
|
||||
@page.content = parse_content(@page.content, {:locale => 'create'})
|
||||
if @page.save
|
||||
@item = Page.new(params[:page])
|
||||
@item.content = parse_content(@item.content, {:locale => 'create'})
|
||||
if @item.save
|
||||
flash[:notice] = t('admin.create_success_page')
|
||||
redirect_to admin_items_url( :parent_id => @page.parent_id )
|
||||
redirect_to admin_items_url( :parent_id => @item.parent_id )
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@page = Page.find(params[:id])
|
||||
parse_content(@page.content, {:locale => 'destroy'})
|
||||
if @page.update_attributes(params[:page])
|
||||
@page.content = parse_content(@page.content, {:locale => 'create'})
|
||||
@page.save!
|
||||
@item = Page.find(params[:id])
|
||||
parse_content(@item.content, {:locale => 'destroy'})
|
||||
if @item.update_attributes(params[:page])
|
||||
@item.content = parse_content(@item.content, {:locale => 'create'})
|
||||
@item.save!
|
||||
flash[:notice] = t('admin.update_success_page')
|
||||
redirect_to admin_items_url( :parent_id => @page.parent_id )
|
||||
redirect_to admin_items_url( :parent_id => @item.parent_id )
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@page = Page.find(params[:id])
|
||||
@page.destroy
|
||||
@page.destroy_i18n_variable
|
||||
@item = Page.find(params[:id])
|
||||
@item.destroy
|
||||
@item.destroy_i18n_variable
|
||||
|
||||
redirect_to admin_items_url( :parent_id => @page.parent_id )
|
||||
redirect_to admin_items_url( :parent_id => @item.parent_id )
|
||||
end
|
||||
|
||||
end
|
||||
@@ -18,8 +18,8 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
# Render the page
|
||||
def render_page
|
||||
if @page
|
||||
render :text => parse_page(@page)
|
||||
if @item
|
||||
render :text => parse_page(@item)
|
||||
else
|
||||
render :text => '404 Not Found'
|
||||
end
|
||||
@@ -53,7 +53,7 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
def set_current_item
|
||||
session[:current_page] = params[:id] || @page.id || @link.id || @item.id rescue nil
|
||||
session[:current_page] = params[:id] || @item.id rescue nil
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,8 +1,8 @@
|
||||
class PagesController < ApplicationController
|
||||
|
||||
def index
|
||||
@page = Page.find_by_name('home')
|
||||
if @page
|
||||
@item = Page.find_by_name('home')
|
||||
if @item
|
||||
render_page
|
||||
else
|
||||
render :text => 'You need a home page'
|
||||
@@ -14,7 +14,7 @@ class PagesController < ApplicationController
|
||||
item = Item.first(:conditions => {:full_name => params[:page_name]})
|
||||
case item._type
|
||||
when 'Page'
|
||||
@page = item
|
||||
@item = item
|
||||
render_page
|
||||
when 'Link'
|
||||
redirect_to "http://#{item[:url]}"
|
||||
|
||||
@@ -4,6 +4,6 @@ switch ("<%= escape_javascript(@item._type)%>") {
|
||||
$('#main').append("<%= escape_javascript(render(:partial => 'admin/links/show')) %>");
|
||||
break;
|
||||
case 'Page':
|
||||
$('#main').append("<%= escape_javascript(render(:partial => 'page')) %>");
|
||||
$('#main').append("<%= escape_javascript(render(:partial => 'admin/pages/show')) %>");
|
||||
break;
|
||||
};
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<%= flash_messages %>
|
||||
|
||||
<%= form_for @link, :url => admin_link_path(@link), :html => { :class => 'form' } do |f| %>
|
||||
<%= form_for @item, :url => admin_link_path(@item), :html => { :class => 'form' } do |f| %>
|
||||
|
||||
<%= render :partial => "admin/links/form", :locals => { :f => f } %>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<%= flash_messages %>
|
||||
|
||||
<%= form_for @link, :url => admin_links_path, :html => { :class => 'form' } do |f| %>
|
||||
<%= form_for @item, :url => admin_links_path, :html => { :class => 'form' } do |f| %>
|
||||
|
||||
<%= render :partial => "admin/links/form", :locals => { :f => f } %>
|
||||
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
<%= flash_messages %>
|
||||
<p>
|
||||
<b><%= t('admin.name') %></b>
|
||||
<%= @link.name %>
|
||||
<%= @item.name %>
|
||||
</p>
|
||||
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<p>
|
||||
<b><%= "#{t('admin.title')} #{locale}" %></b>
|
||||
<%= @link.i18n_variable[locale] if @link.i18n_variable %>
|
||||
<%= @item.i18n_variable[locale] if @item.i18n_variable %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<p>
|
||||
<b><%= t('admin.is_published') %></b>
|
||||
<%= @link.is_published.to_s %>
|
||||
<%= @item.is_published.to_s %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b><%= t('admin.url') %></b>
|
||||
<%= @link.url %>
|
||||
<%= @item.url %>
|
||||
</p>
|
||||
|
||||
<%= link_to t(:edit), edit_admin_link_path(@link) %>
|
||||
<%= link_to t(:edit), edit_admin_link_path(@item) %>
|
||||
@@ -1,4 +1,4 @@
|
||||
<% form_for :link, :url => admin_link_path(@link), :html => { :method => :delete } do |f| %>
|
||||
<% form_for :link, :url => admin_link_path(@item), :html => { :method => :delete } do |f| %>
|
||||
<h2><%= t('sure?') %></h2>
|
||||
<p>
|
||||
<%= submit_tag t(:delete) %>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<h1>EDIT</h1>
|
||||
@@ -0,0 +1,5 @@
|
||||
<% content_for :sidebar do %>
|
||||
<div id='sidebar'><%= render 'admin/items/site_map_left_bar' %></div>
|
||||
<% end -%>
|
||||
|
||||
<%= render 'edit' %>
|
||||
@@ -0,0 +1 @@
|
||||
$('#main').html("<%= escape_javascript(render(:partial => 'edit')) %>");
|
||||
@@ -1 +1,10 @@
|
||||
<%= parse_page(@page).html_safe %>
|
||||
<%= parse_page_edit(@item).html_safe %>
|
||||
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
$("div.editable").live("mouseenter mouseleave",
|
||||
function (event) {
|
||||
$(this).next('.edit_link').toggle();
|
||||
});
|
||||
</script>
|
||||
<% end -%>
|
||||
@@ -1,6 +1,6 @@
|
||||
<h1><%= t('admin.editing_page') %></h1>
|
||||
|
||||
<%= form_for @page, :url => admin_page_path(@page) do |f| %>
|
||||
<%= form_for @item, :url => admin_page_path(@item) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
<%= render :partial => "form", :locals => { :f => f } %>
|
||||
|
||||
|
||||
@@ -18,6 +18,15 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<ul id="nav">
|
||||
<li><%= link_to t('homepage'), root_path %></li>
|
||||
<li><%= link_to t('admin.item'), admin_items_path %></li>
|
||||
<li><%= link_to t('admin.layout'), admin_layouts_path %></li>
|
||||
<li><%= link_to t('admin.asset'), admin_assets_path %></li>
|
||||
<li><%= link_to t('admin.user_info'), admin_user_info_models_path %></li>
|
||||
<li><%= link_to t('admin.user_role'), admin_user_role_models_path %></li>
|
||||
<li><%= link_to t('admin.translation'), admin_translations_path %></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="content" class="content">
|
||||
|
||||
Reference in new issue
Block a user