PagePart widgets for "system widget"

Delete useless code
This commit is contained in:
chris committed 2013-10-28 16:29:23 +08:00
1 parent 218cb03641
commit a14d69211b
46 files changed
+303 -913

No files matched your search

+62 -126
View File
@@ -1,86 +1,44 @@
class Admin::PagePartsController < OrbitBackendController
include Admin::FrontendWidgetInterface
layout "structure"
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
layout "structure"
open_for_admin
def edit
# @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
@id = params[:id]
@part = PagePart.find(params[:id])
@module_apps = ModuleApp.for_widget_select
@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?
@module_app = @part.module_app || @module_apps.first
@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
@data_count = @module_app.get_registration.get_data_count.to_a rescue []
end
@data_count = @module_app.get_registration.get_data_count.to_a rescue []
@no_orbit_bar = @side_bar = @no_header = true
@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
@html_class = "page-parts"
end
def get_page_setting_json
@@ -103,7 +61,6 @@ class Admin::PagePartsController < OrbitBackendController
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
@@ -132,67 +89,51 @@ class Admin::PagePartsController < OrbitBackendController
end
end
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
end
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
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]
}
end
def update
@part = PagePart.find(params[:id])
clean_tags_and_category_params
# params[:page_part][:widget_field].each{|t| t[2] = (t[2]=="true" ? true : false )} if !params[:page_part][:widget_field].blank?
if @part.update_attributes(params[:page_part])
set_children_sub_menu(@part) if @part.public_r_tag && @part.public_r_tag.eql?('sub_menu')
flash.now[:notice] = t('update.success.content')
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
redirect_to admin_page_url(@part.page, edit: true)
}
end
else
@id = params[:id]
@module_apps = ModuleApp.for_widget_select
@module_app = @part.module_app || @module_apps.first
@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 []
@no_orbit_bar = @side_bar = @no_header = true
@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
@html_class = "page-parts"
render :action => "edit"
end
end
@@ -217,11 +158,6 @@ class Admin::PagePartsController < OrbitBackendController
end
protected
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
def set_children_sub_menu(part)
part.page.children.each do |child|
@@ -1,6 +1,4 @@
class Admin::PagesController < Admin::ItemsController
# helper Admin::PagePartsHelper
# include Admin::FrontendWidgetInterface
def show
@item = Page.find(params[:id])