Improve code in items, pages, links
This commit is contained in:
parent
cf4a6c0b35
commit
0b71714d44
|
@ -16,21 +16,6 @@ class Admin::ItemsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
#TODO
|
||||
# Allow to move items down and up different parents
|
||||
# def up
|
||||
# @item = Item.find(params[:id])
|
||||
# @item.move_higher
|
||||
# redirect_to admin_items_url( :parent_name => @item.parent_name )
|
||||
# end
|
||||
#
|
||||
# def down
|
||||
# @item = Item.find(params[:id])
|
||||
# @item.move_lower
|
||||
# redirect_to admin_items_url( :parent_name => @item.parent_name )
|
||||
# end
|
||||
|
||||
protected
|
||||
|
||||
def find_snippets
|
||||
|
|
|
@ -12,13 +12,11 @@ class Admin::LinksController < ApplicationController
|
|||
|
||||
def new
|
||||
@item = Link.new
|
||||
@item.is_published = true
|
||||
@item.parent_id = Page.find(params[:parent_id]).id rescue nil
|
||||
@item.parent = Page.find(params[:parent_id]) rescue nil
|
||||
end
|
||||
|
||||
def edit
|
||||
@item = Link.find(params[:id])
|
||||
@i18n_variable = @item.i18n_variable
|
||||
end
|
||||
|
||||
def create
|
||||
|
@ -34,7 +32,6 @@ class Admin::LinksController < ApplicationController
|
|||
end
|
||||
else
|
||||
flash.now[:error] = t('admin.create_error_link')
|
||||
@i18n_variable = @item.i18n_variable
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
@ -52,7 +49,6 @@ class Admin::LinksController < ApplicationController
|
|||
end
|
||||
else
|
||||
flash.now[:error] = t('admin.update_error_link')
|
||||
@i18n_variable = @item.i18n_variable
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,19 +19,17 @@ class Admin::PagesController < ApplicationController
|
|||
|
||||
def new
|
||||
@item = Page.new
|
||||
@item.parent = Item.find(params[:parent_id]) rescue nil
|
||||
@apps = ModuleApp.all
|
||||
@item.is_published = true
|
||||
@item.parent_id = @parent_item.id rescue nil
|
||||
@designs = Design.all.entries
|
||||
@default_design = Design.first
|
||||
@design = Design.first
|
||||
end
|
||||
|
||||
def edit
|
||||
@item = Page.find(params[:id])
|
||||
@apps = ModuleApp.all
|
||||
@i18n_variable = @item.i18n_variable
|
||||
@designs = Design.all.entries
|
||||
@design = @item.design
|
||||
@design = @item.design ? @item.design : @designs.first
|
||||
@app_frontend_urls = @item.module_app.app_pages if @item.module_app
|
||||
end
|
||||
|
||||
|
@ -47,7 +45,9 @@ class Admin::PagesController < ApplicationController
|
|||
end
|
||||
else
|
||||
flash.now[:error] = t('admin.create_error_page')
|
||||
@i18n_variable = @item.i18n_variable
|
||||
@apps = ModuleApp.all
|
||||
@designs = Design.all.entries
|
||||
@design = Design.first
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,13 +13,16 @@ class PagesController < ApplicationController
|
|||
|
||||
def show
|
||||
#begin
|
||||
item = Item.first(:conditions => {:full_name => params[:page_name]})
|
||||
case item._type
|
||||
@item = Item.first(:conditions => {:full_name => params[:page_name]})
|
||||
if @item.is_published
|
||||
case @item._type
|
||||
when 'Page'
|
||||
@item = item
|
||||
render_page(params[:id])
|
||||
when 'Link'
|
||||
redirect_to "http://#{item[:url]}"
|
||||
redirect_to "http://#{@item[:url]}"
|
||||
end
|
||||
else
|
||||
render :file => "#{Rails.root}/public/404.html", :status => :not_found
|
||||
end
|
||||
#rescue
|
||||
# render :file => "#{Rails.root}/public/404.html", :status => :not_found
|
||||
|
|
|
@ -5,15 +5,13 @@ class Item
|
|||
|
||||
field :name, :index => true
|
||||
field :full_name, :index => true
|
||||
field :parent_id, :index => true
|
||||
field :parent_name
|
||||
field :position, :type => Integer
|
||||
field :is_published, :type => Boolean, :default => true, :index => true
|
||||
field :is_published, :type => Boolean, :default => false, :index => true
|
||||
|
||||
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
|
||||
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 :name, :full_name, :position
|
||||
|
||||
belongs_to :parent, :class_name => "Item"
|
||||
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
|
@ -47,9 +45,6 @@ class Item
|
|||
self.position = (max_page)? max_page + 1 : 1
|
||||
end
|
||||
|
||||
# Set the parent value
|
||||
self.parent_name = Item.first(:conditions => {:id => self.parent_id} ).name rescue nil
|
||||
|
||||
# Build the full_name from the ancestors array
|
||||
full_node = self.ancestors.map{ |a| a.name }.push( self.name )
|
||||
# Remove root node if not root
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
<%= f.error_messages %>
|
||||
<%= f.hidden_field :parent_id %>
|
||||
<%= f.hidden_field :parent, :value => @item.parent.id %>
|
||||
|
||||
<p>
|
||||
<%= f.label :name, "Name" %>
|
||||
<%= f.text_field :name, :class => 'text' %>
|
||||
</p>
|
||||
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<%= f.fields_for :i18n_variable, (@item.new_record? ? @item.build_i18n_variable : @item.i18n_variable) do |f| %>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<p>
|
||||
<%= label_tag "link[title]", "#{t('admin.title')} #{locale}" %>
|
||||
<%= text_field_tag "link[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :class => 'text' %>
|
||||
<%= f.label :locale, "#{t('admin.title')} #{I18nVariable.from_locale(locale)}" %>
|
||||
<%= f.text_field locale %>
|
||||
</p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<p>
|
||||
|
|
|
@ -1,34 +1,27 @@
|
|||
<%= f.error_messages %>
|
||||
<%= f.hidden_field :parent_id %>
|
||||
<%= f.hidden_field :parent, :value => @item.parent.id %>
|
||||
|
||||
<p>
|
||||
<%= f.label :name, t('admin.name') %>
|
||||
<%= f.text_field :name, :class => 'text' %>
|
||||
</p>
|
||||
|
||||
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<%= f.fields_for :i18n_variable, (@item.new_record? ? @item.build_i18n_variable : @item.i18n_variable) do |f| %>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<p>
|
||||
<%= label_tag "page[title]", "#{t('admin.title')} #{locale}" %>
|
||||
<%= text_field_tag "page[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :class => 'text' %>
|
||||
<%= f.label :locale, "#{t('admin.title')} #{I18nVariable.from_locale(locale)}" %>
|
||||
<%= f.text_field locale %>
|
||||
</p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<p>
|
||||
<%= t('admin.design_name') %>
|
||||
<% if @design %>
|
||||
<%= f.collection_select :design_id, @designs, :id, :title, {}, :rel => admin_pages_path %>
|
||||
<% else %>
|
||||
<%= f.select :design_id, @designs.collect { |d| [d.title, d.id] }, {:selected => @default_design.id}, {:rel => admin_pages_path} %>
|
||||
<% end %>
|
||||
<%= f.collection_select :design, @designs, :id, :title, {:selected => @design.id}, {:rel => admin_pages_path} %>
|
||||
</p>
|
||||
<p>
|
||||
<%= t('admin.theme') %>
|
||||
<% if @design %>
|
||||
<%= f.select :theme_id, @design.themes.collect { |t| [t.name.capitalize, t.id] }, :include_blank => true %>
|
||||
<% else %>
|
||||
<%= f.select :theme_id, @default_design.themes.collect { |t| [t.name.capitalize, t.id] }, :include_blank => true %>
|
||||
<% end %>
|
||||
</p>
|
||||
<p>
|
||||
<%= t('admin.module_app') %>
|
||||
|
|
Loading…
Reference in New Issue