2013-03-06 07:16:20 +00:00
|
|
|
class Admin::PagePartsController < OrbitBackendController
|
2011-05-25 06:50:56 +00:00
|
|
|
|
2011-12-05 01:54:41 +00:00
|
|
|
layout "site_editor"
|
2011-05-25 06:50:56 +00:00
|
|
|
|
|
|
|
before_filter :authenticate_user!
|
|
|
|
before_filter :is_admin?
|
|
|
|
before_filter :set_current_item
|
2012-11-15 10:01:49 +00:00
|
|
|
|
|
|
|
helper 'admin/items'
|
2011-05-25 06:50:56 +00:00
|
|
|
|
|
|
|
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])
|
2013-03-22 06:19:10 +00:00
|
|
|
@module_apps = ModuleApp.where(:key.in=>OrbitApp::Module::WidgetUtility.all.keys).order_by(:title, :asc)
|
2013-01-23 10:51:18 +00:00
|
|
|
@module_app = @part.module_app ? @part.module_app : nil
|
2013-01-14 10:49:23 +00:00
|
|
|
@user_choose = @part.widget_path
|
2012-02-16 04:16:27 +00:00
|
|
|
@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
|
2013-01-29 12:33:40 +00:00
|
|
|
|
|
|
|
if @module_app
|
|
|
|
@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? or @module_app.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
unless @module_app.nil?
|
|
|
|
@categories = @module_app.get_categories
|
|
|
|
@tags = @module_app.get_tags
|
|
|
|
end
|
|
|
|
|
2013-01-23 10:51:18 +00:00
|
|
|
@widget_path = @part.widget_path ? @part.widget_path : (@module_app.widgets.keys[0] rescue nil)
|
2012-08-20 09:14:13 +00:00
|
|
|
|
2013-01-23 10:51:18 +00:00
|
|
|
if @module_app && @module_app.widgets.any?{|b| b.class == Array}
|
2012-08-20 09:14:13 +00:00
|
|
|
@widget_style = @module_app.widgets[@widget_path] if !@widget_path.blank? && !@module_app.widgets.blank?
|
|
|
|
end
|
2013-01-24 08:30:02 +00:00
|
|
|
|
2011-05-25 06:50:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2013-02-23 07:19:51 +00:00
|
|
|
|
2011-05-25 06:50:56 +00:00
|
|
|
@part = PagePart.find(params[:id])
|
2013-02-23 09:25:07 +00:00
|
|
|
params[:page_part][:widget_field] = params[:page_part][:widget_field].zip( params[:page_part][:widget_field_type],params[:page_part][:widget_field_is_link] ) if params[:page_part][:widget_field]
|
2013-02-18 07:13:31 +00:00
|
|
|
|
2013-01-29 14:17:00 +00:00
|
|
|
params[:page_part][:widget_field_type] = nil
|
2013-03-07 09:30:49 +00:00
|
|
|
params[:page_part][:widget_field_is_link] = nil
|
2012-12-03 10:52:36 +00:00
|
|
|
|
2013-01-29 14:17:00 +00:00
|
|
|
if params[:page_part][:module_app].blank?
|
|
|
|
params[:page_part][:module_app] = nil
|
|
|
|
end
|
2013-02-06 11:51:53 +00:00
|
|
|
|
2013-03-13 09:53:11 +00:00
|
|
|
if params[:page_part][:tag].nil? || params[:page_part][:tag].include?("nil")
|
2013-02-06 11:51:53 +00:00
|
|
|
params[:page_part][:tag] = []
|
|
|
|
end
|
|
|
|
|
2013-03-13 09:53:11 +00:00
|
|
|
if params[:page_part][:category].nil? || params[:page_part][:category].include?("nil")
|
2013-02-06 11:51:53 +00:00
|
|
|
params[:page_part][:category] = []
|
|
|
|
end
|
|
|
|
|
2013-03-04 11:29:45 +00:00
|
|
|
params[:page_part][:widget_field].each{|t| t[2] = (t[2]=="true" ? true : false )} if !params[:page_part][:widget_field].blank?
|
2013-02-06 11:51:53 +00:00
|
|
|
|
2011-05-25 08:27:17 +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
|
2011-05-25 08:27:17 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
redirect_to admin_page_url( @part.page )
|
|
|
|
}
|
|
|
|
format.js {
|
|
|
|
@item = @part.page
|
|
|
|
}
|
|
|
|
end
|
2011-05-25 06:50:56 +00:00
|
|
|
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
|
|
|
|
|
2013-02-18 07:13:31 +00:00
|
|
|
def reload_widget_field
|
|
|
|
@index = params[:field_seri].to_i
|
|
|
|
@part = PagePart.find params[:id]
|
|
|
|
@choosen_field = params[:widget_field_value]
|
|
|
|
@module_app = @part.module_app
|
2013-02-25 04:49:06 +00:00
|
|
|
@module_app = ModuleApp.find params[:module_app_id] if @module_app.nil?
|
2013-02-18 07:13:31 +00:00
|
|
|
end
|
|
|
|
|
2012-02-16 04:16:27 +00:00
|
|
|
def reload_widgets
|
2013-01-21 08:56:37 +00:00
|
|
|
@part = PagePart.find params[:id]
|
2013-01-23 10:51:18 +00:00
|
|
|
@module_app = ModuleApp.find(params[:module_app_id]) rescue nil
|
2013-01-29 12:33:40 +00:00
|
|
|
@categories =@module_app ? @module_app.get_categories : []
|
|
|
|
@tags =@module_app ? @module_app.get_tags : []
|
|
|
|
@widget_path = @module_app.widgets.keys[0] if (@module_app && @module_app.widgets[0].blank? )
|
2012-08-09 07:25:30 +00:00
|
|
|
@widget_style = @module_app.widgets[@widget_path] if ( !@widget_path.blank? )
|
2012-08-22 10:07:49 +00:00
|
|
|
|
2013-01-29 12:33:40 +00:00
|
|
|
@part.widget_path = @module_app.widgets.first if( @module_app)
|
2012-02-16 04:16:27 +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])
|
2013-01-24 08:30:02 +00:00
|
|
|
|
2013-01-21 08:56:37 +00:00
|
|
|
@part = PagePart.find params[:id]
|
|
|
|
@user_choose =@widget_path= params[:frontend]
|
|
|
|
@widget_style = @module_app.widgets[@widget_path]
|
2013-01-14 10:49:23 +00:00
|
|
|
|
2012-12-03 10:52:36 +00:00
|
|
|
|
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
|
2013-02-23 08:52:37 +00:00
|
|
|
@part = PagePart.find params[:id]
|
|
|
|
@r_tag = params[:type]
|
2012-04-23 18:30:40 +00:00
|
|
|
@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
|
2012-02-16 04:16:27 +00:00
|
|
|
|
2011-05-25 06:50:56 +00:00
|
|
|
end
|