2013-03-06 07:16:20 +00:00
|
|
|
class Admin::PagePartsController < OrbitBackendController
|
2013-04-01 09:06:10 +00:00
|
|
|
include Admin::FrontendWidgetInterface
|
2013-07-02 08:46:44 +00:00
|
|
|
layout "structure"
|
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 edit
|
2013-10-28 03:37:56 +00:00
|
|
|
# @part = PagePart.find(params[:id])
|
|
|
|
# @r_tag = @part.public_r_tag.blank? ? LIST[:public_r_tags][0] : @part.public_r_tag
|
|
|
|
# @tag_objects = @r_tag.classify.constantize.all rescue nil
|
|
|
|
# if @r_tag.eql?('tag_cloud')
|
|
|
|
# @tag_objects = ModuleApp.where(has_tag: true)
|
|
|
|
# else
|
|
|
|
# @tag_objects = @r_tag.classify.constantize.all rescue nil
|
|
|
|
# end
|
|
|
|
|
|
|
|
# @module_apps = ModuleApp.for_widget_select
|
|
|
|
# @categories = nil
|
|
|
|
# @tags = nil
|
|
|
|
# @page_frontend_data_counts = nil
|
|
|
|
# # @frontend_styles = nil
|
|
|
|
|
|
|
|
# @selected={
|
|
|
|
# :module_app=> @part.module_app ? @part.module_app : nil,
|
|
|
|
# :app_frontend_url=> @part.widget_path || "default_widget", #@module_apps.first
|
|
|
|
# :category=>nil, #fetch by method: get_categories_and_tags
|
|
|
|
# :tag=>nil, #fetch by method: get_categories_and_tags
|
|
|
|
# :page_frontend_data_count=>nil,
|
|
|
|
# :frontend_style => nil,
|
|
|
|
# :widget_path=> nil
|
|
|
|
# }
|
|
|
|
|
|
|
|
# @selected[:widget_path] = @part.widget_path ? @part.widget_path : (@selected[:module_app].widgets.keys[0] rescue nil)
|
|
|
|
# get_categories_and_tags
|
|
|
|
# get_frontend_data_count
|
|
|
|
# @app_frontend_urls = get_app_frontend_urls
|
|
|
|
# @no_orbit_bar = @side_bar = @no_header = true
|
|
|
|
|
2013-01-29 12:33:40 +00:00
|
|
|
|
2013-10-28 03:37:56 +00:00
|
|
|
|
|
|
|
@id = params[:id]
|
|
|
|
@part = PagePart.find(params[:id])
|
2013-04-01 09:06:10 +00:00
|
|
|
@module_apps = ModuleApp.for_widget_select
|
2013-10-28 03:37:56 +00:00
|
|
|
@module_app = @part.module_app
|
|
|
|
if @module_app
|
|
|
|
@module_app_categories = @module_app.categories
|
|
|
|
@module_app_tags = @module_app.tags
|
|
|
|
@widget_paths = ModuleApp.find(@module_app.id).widgets.map{|name, data| [t(data["i18n"]), name]} rescue []
|
|
|
|
if @part.widget_path.present?
|
|
|
|
if @part.widget_path.eql?("default_widget")
|
|
|
|
@checked_style = @part.widget_style
|
|
|
|
@enabled_styles = @module_app.get_default_widget["enabled_styles"]
|
|
|
|
@widget_fields = @module_app.widget_fields.collect do |widget_field|
|
|
|
|
label = I18n.t("#{@module_app.key}.default_widget.#{widget_field[0]}")
|
|
|
|
[label, widget_field[0], class: widget_field[2]]
|
|
|
|
end
|
|
|
|
@class_options = LIST[:widget_field_type].collect{|widget_field| [widget_field.humanize, widget_field]}
|
|
|
|
@partial = 'default_widget'
|
|
|
|
else
|
|
|
|
@frontend_styles = @module_app.widgets[params[:val]]["style"] rescue nil
|
|
|
|
@partial = 'custom_widget' if @frontend_styles.present?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@data_count = @module_app.get_registration.get_data_count.to_a rescue []
|
|
|
|
end
|
2013-07-29 10:46:38 +00:00
|
|
|
@no_orbit_bar = @side_bar = @no_header = true
|
2013-10-28 03:37:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_page_setting_json
|
|
|
|
begin
|
|
|
|
part = PagePart.find(params[:id])
|
|
|
|
m = {}
|
|
|
|
m["main"] = part.module_app_id.to_s
|
|
|
|
m["sub"] = part.widget_path
|
|
|
|
m["category"] = part.category.present? ? [0, part.category.map{|c| c.to_s}] : [1]
|
|
|
|
m["tags"] = part.tag.present? ? [0, part.tag.map{|c| c.to_s}] : [1]
|
|
|
|
m["count"] = part.widget_data_count
|
|
|
|
render json: JSON.pretty_generate({module: m})
|
|
|
|
rescue
|
|
|
|
render :json => {error: ''}, status: 422
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_page_module_json
|
|
|
|
modules = ModuleApp.for_widget_select.inject([]) do |module_apps, module_app|
|
|
|
|
m = {}
|
|
|
|
m["main"] = [module_app.title, module_app.id.to_s]
|
|
|
|
m["sub"] = module_app.widgets.map{|name, data| [t(data["i18n"]), name]} rescue []
|
|
|
|
m["sub"] << [I18n.t('default_widget.default_widget'),'default_widget'] if module_app.has_default_widget?
|
|
|
|
m["category"] = module_app.categories.map{|category| [category.title, category.id.to_s] } rescue ''
|
|
|
|
m["tags"] = module_app.tags.map{|tag| [tag.name, tag.id.to_s] } rescue ''
|
|
|
|
m["count"] = module_app.get_registration.get_data_count.to_a
|
|
|
|
module_apps << m
|
|
|
|
end
|
|
|
|
render json: JSON.pretty_generate({module: modules})
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_display_style
|
|
|
|
@part = PagePart.find(params[:id]) rescue nil
|
|
|
|
@module_app = ModuleApp.find(params[:module_id]) rescue nil
|
|
|
|
if @module_app
|
|
|
|
if params[:val].eql?("default_widget")
|
|
|
|
@checked_style = @part.widget_path.present? ? @part.widget_style : nil if @part && @part.widget_path.eql?("default_widget")
|
|
|
|
@enabled_styles = @module_app.get_default_widget["enabled_styles"]
|
|
|
|
@widget_fields = @module_app.widget_fields.collect do |widget_field|
|
|
|
|
label = I18n.t("#{@module_app.key}.default_widget.#{widget_field[0]}")
|
|
|
|
[label, widget_field[0], class: widget_field[2]]
|
|
|
|
end
|
|
|
|
@class_options = LIST[:widget_field_type].collect{|widget_field| [widget_field.humanize, widget_field]}
|
|
|
|
@partial = 'default_widget'
|
|
|
|
else
|
|
|
|
@frontend_styles = @module_app.widgets[params[:val]]["style"] rescue nil
|
|
|
|
@partial = 'custom_widget' if @frontend_styles.present?
|
|
|
|
end
|
|
|
|
end
|
2013-04-01 09:06:10 +00:00
|
|
|
end
|
2013-01-24 08:30:02 +00:00
|
|
|
|
2013-04-01 09:06:10 +00:00
|
|
|
def reload_widgets
|
|
|
|
@part = PagePart.find params[:id]
|
|
|
|
@selected={
|
|
|
|
:module_app=> ModuleApp.find(params["module_app_id"])
|
|
|
|
}
|
|
|
|
get_categories_and_tags
|
|
|
|
get_frontend_data_count
|
|
|
|
@selected[:app_frontend_url] = @selected[:module_app].has_default_widget? ? 'default_widget' : @selected[:module_app].widget_options.first.name
|
2011-05-25 06:50:56 +00:00
|
|
|
end
|
|
|
|
|
2013-04-01 09:06:10 +00:00
|
|
|
|
|
|
|
def reload_widget_styles
|
|
|
|
@part = PagePart.find(params[:id])
|
|
|
|
@selected={
|
|
|
|
:module_app=> ModuleApp.find(params["module_app_id"]),
|
|
|
|
:app_frontend_url=> params["frontend"], #@module_apps.first
|
|
|
|
:category=>nil, #fetch by method: get_categories_and_tags
|
|
|
|
:tag=>nil, #fetch by method: get_categories_and_tags
|
|
|
|
:page_frontend_data_count=>nil,
|
|
|
|
:frontend_style => nil,
|
|
|
|
:widget_path=> nil
|
|
|
|
}
|
|
|
|
get_categories_and_tags
|
|
|
|
get_frontend_data_count
|
|
|
|
end
|
2011-05-25 06:50:56 +00:00
|
|
|
|
2013-04-01 09:06:10 +00:00
|
|
|
def reload_widget_field
|
|
|
|
@index = params[:field_seri].to_i
|
|
|
|
@part = PagePart.find(params[:id])
|
|
|
|
@selected = {
|
|
|
|
:module_app=> ModuleApp.find(params["module_app_id"]),
|
|
|
|
:default_widget_field=>params[:widget_field_value]
|
|
|
|
}
|
2011-05-25 06:50:56 +00:00
|
|
|
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-03-28 10:29:24 +00:00
|
|
|
|
2012-12-03 10:52:36 +00:00
|
|
|
|
2013-04-01 09:06:10 +00:00
|
|
|
clean_tags_and_category_params
|
2013-02-06 11:51:53 +00:00
|
|
|
|
2013-03-28 10:29:24 +00:00
|
|
|
# params[:page_part][:widget_field].each{|t| t[2] = (t[2]=="true" ? true : false )} if !params[:page_part][:widget_field].blank?
|
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
|
|
|
|
|
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]
|
2013-05-24 10:42:01 +00:00
|
|
|
if params[:type].eql?('tag_cloud')
|
|
|
|
@tag_objects = ModuleApp.where(has_tag: true)
|
|
|
|
else
|
|
|
|
@tag_objects = @r_tag.classify.constantize.all rescue nil
|
|
|
|
end
|
2012-04-23 18:30:40 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.js {}
|
|
|
|
end
|
|
|
|
end
|
2012-05-08 20:15:45 +00:00
|
|
|
|
|
|
|
protected
|
2013-04-01 09:06:10 +00:00
|
|
|
def get_app_frontend_urls
|
|
|
|
@selected[:module_app] ? @selected[:module_app].widgets.collect{|k,v| [I18n.t(v["i18n"]),k]} : []
|
|
|
|
# has_old_value = @selected[:module_app].app_pages[@selected[:app_frontend_url]]
|
|
|
|
# @frontend_styles = has_old_value ? has_old_value["style"] : (@selected[:module_app].app_pages.first[1]["style"] rescue nil)
|
|
|
|
end
|
2012-05-08 20:15:45 +00:00
|
|
|
|
|
|
|
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
|