Orbit/app/controllers/admin/page_parts_controller.rb

150 lines
4.2 KiB
Ruby
Raw Normal View History

class Admin::PagePartsController < ApplicationController
layout "site_editor"
before_filter :authenticate_user!
before_filter :is_admin?
before_filter :set_current_item
helper 'admin/items'
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])
@module_apps = ModuleApp.excludes(widgets: nil).where(enable_frontend: true).order_by(:title, :asc)
@module_app = @part.module_app ? @part.module_app : @module_apps[0]
@r_tag = @part.public_r_tag.blank? ? LIST[:public_r_tags][0] : @part.public_r_tag
2012-04-23 18:30:40 +00:00
@tag_objects = @r_tag.classify.constantize.all rescue nil
2012-12-03 10:52:36 +00:00
@widget_path = @part.widget_path ? @part.widget_path : @module_app.widgets.keys[0]
@widget_style = @module_app.get_widget_style[@widget_path][:style] unless @widget_path.nil?
@categories = @module_app.get_registration.get_categories
@tags = @module_app.get_registration.get_tags
# if @module_app.widgets.any?{|b| b.class == Array}
# @widget_style = @module_app.widgets[@widget_path] if !@widget_path.blank? && !@module_app.widgets.blank?
# end
2012-07-26 08:39:29 +00:00
2012-12-03 10:52:36 +00:00
# case @module_app.key
# when 'announcement'
# @categories = BulletinCategory.all
# @tags = AnnouncementTag.all
# when 'news'
# @categories = NewsBulletinCategory.all
# @tags = NewsTag.all
# when 'web_resource'
# @categories = WebLinkCategory.all
# @tags = WebResourceTag.all
# when 'archive'
# @categories = ArchiveFileCategory.all
# @tags = ArchiveTag.all
# end
end
def create
end
def update
@part = PagePart.find(params[:id])
2012-08-09 07:25:30 +00:00
2012-08-20 09:14:13 +00:00
params[:page_part][:widget_field] = params[:page_part][:widget_field].zip( params[:page_part][:widget_field_type] ) if params[:page_part][:widget_field]
2012-08-09 07:25:30 +00:00
params[:page_part][:widget_field_type] = nil
2012-12-03 10:52:36 +00:00
if @part.update_attributes(params[:page_part])
2012-05-08 20:15:45 +00:00
set_children_sub_menu(@part) if @part.public_r_tag && @part.public_r_tag.eql?('sub_menu')
2012-09-12 11:12:50 +00:00
flash.now[:notice] = t('update.success.content')
2012-07-13 07:36:10 +00:00
if @part.page.name == 'home'
expire_page '/'
else
expire_page page_path(@part.page.name)
end
respond_to do |format|
format.html {
redirect_to admin_page_url( @part.page )
}
format.js {
@item = @part.page
}
end
else
render :action => "edit"
end
end
def destroy
@item = Page.find(params[:id])
@item.destroy
redirect_to admin_items_url( :parent_id => @item.parent_id )
end
def reload_widgets
2012-03-06 08:41:06 +00:00
@categories =[]
@module_app = ModuleApp.find(params[:id])
2012-07-26 08:39:29 +00:00
2012-08-09 07:25:30 +00:00
@widget_path = @module_app.widgets.keys[0] if ( @module_app.widgets[0].blank? )
2012-12-03 10:52:36 +00:00
@widget_style = @module_app.get_widget_style[@widget_path][:style] unless @widget_path.nil?
2012-02-28 14:00:05 +00:00
case @module_app.key
when 'announcement'
@categories = BulletinCategory.all
@tags = AnnouncementTag.all
2012-04-29 22:27:38 +00:00
when 'news'
@categories = NewsBulletinCategory.all
@tags = NewsTag.all
2012-02-28 14:00:05 +00:00
when 'web_resource'
@categories = WebLinkCategory.all
@tags = WebResourceTag.all
2012-08-21 09:37:25 +00:00
when 'archive'
@categories = ArchiveFileCategory.all
@tags = ArchiveTag.all
2012-02-28 14:00:05 +00:00
end
2012-03-06 08:41:06 +00:00
respond_to do |format|
format.js {}
end
end
2012-07-26 08:39:29 +00:00
def reload_widget_styles
@module_app = ModuleApp.find(params[:module_app_id])
2012-12-03 10:52:36 +00:00
style_ary = @module_app.get_widget_style[params[:id]]
@widget_style = style_ary[:style] unless style_ary.nil?
2012-07-26 08:39:29 +00:00
respond_to do |format|
format.js {}
end
end
2012-04-23 18:30:40 +00:00
def reload_r_tag_options
@r_tag = (ModuleApp.find(params[:id]) rescue nil) || params[:id]
@tag_objects = @r_tag.classify.constantize.all rescue nil
respond_to do |format|
format.js {}
end
end
2012-05-08 20:15:45 +00:00
protected
def set_children_sub_menu(part)
part.page.children.each do |child|
child_part = child.page_parts.detect{ |x| x.name.eql?(part.name) } rescue nil
child_part.update_attributes(:kind => part.kind, :public_r_tag => part.public_r_tag, :public_r_tag_object_id => part.public_r_tag_object_id) rescue nil
end
end
end