orbit-basic/app/controllers/admin/page_parts_controller.rb

189 lines
7.5 KiB
Ruby
Raw Normal View History

class Admin::PagePartsController < OrbitBackendController
layout "structure"
open_for_admin
def edit
@id = params[:id]
@part = PagePart.find(params[:id])
2013-04-01 09:06:10 +00:00
@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 []
@pages = Page.where(:module_app_id => @module_app.id)
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
@frontend_styles = @module_app.widgets[@part.widget_path]["style"] rescue nil
@partial = 'custom_widget' if @frontend_styles.present?
end
@partial = 'more_link' unless @partial
end
@data_count = @module_app.get_registration.get_data_count.to_a rescue []
2013-07-29 10:46:38 +00:00
@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
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 = {}
2013-10-29 03:17:02 +00:00
m["main"] = [module_app.label, module_app.id.to_s]
m["sub"] = module_app.widgets.map{|name, data| [t(data["i18n"]), name]} rescue []
if module_app.key == 'member'
m["category"] = RoleStatus.can_display.where(:role_id=> RoleStatus.get_role_data("teacher") ).map{|category| [category.title, category.id.to_s] } rescue ''
m["tags"] = RoleCategory.can_display.where(:role_id=> RoleCategory.get_role_data("teacher") ).map{|category| [category.title, category.id.to_s] } rescue ''
elsif module_app.key == 'member_staff'
m["category"] = RoleStatus.can_display.where(:role_id=> RoleStatus.get_role_data("staff") ).map{|category| [category.title, category.id.to_s] } rescue ''
m["tags"] = RoleCategory.can_display.where(:role_id=> RoleCategory.get_role_data("staff") ).map{|category| [category.title, category.id.to_s] } rescue ''
else
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 ''
end
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
@pages = Page.where(:module_app_id => @module_app.id)
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
@partial = 'more_link' unless @partial
end
2013-04-01 09:06:10 +00:00
end
Merge commit 'fc702a6210d901cd3beea220e72f71a3b7f7d41e' into sidebar_config Conflicts: app/controllers/admin/page_parts_controller.rb app/controllers/default_widget_controller.rb app/uploaders/gprs_uploader.rb app/uploaders/location_uploader.rb app/views/admin/page_parts/_module_widget.html.erb app/views/admin/page_parts/reload_widget_styles.js.erb app/views/admin/page_parts/reload_widgets.js.erb app/views/layouts/_side_bar_content.html.erb config/locales/zh_tw.yml lib/parsers/parser_front_end.rb vendor/built_in_modules/announcement/init.rb vendor/built_in_modules/gprs/app/assets/javascripts/panel/gprs/back_end/locations.js vendor/built_in_modules/gprs/app/assets/stylesheets/panel/gprs/back_end/locations.css vendor/built_in_modules/gprs/app/controllers/panel/gprs/back_end/locations_controller.rb vendor/built_in_modules/gprs/app/views/panel/gprs/back_end/locations/index.html.erb vendor/built_in_modules/gprs/test/functional/panel/gprs/back_end/locations_controller_test.rb vendor/built_in_modules/location/README.rdoc vendor/built_in_modules/location/app/assets/javascripts/panel/gprs/back_end/locations.js vendor/built_in_modules/location/app/assets/javascripts/panel/location/back_end/locations.js vendor/built_in_modules/location/app/assets/stylesheets/panel/gprs/back_end/locations.css vendor/built_in_modules/location/app/assets/stylesheets/panel/location/back_end/locations.css vendor/built_in_modules/location/app/controllers/panel/location/back_end/locations_controller.rb vendor/built_in_modules/location/app/controllers/panel/locations/back_end/locations_controller.rb vendor/built_in_modules/location/app/models/location.rb vendor/built_in_modules/location/app/uploaders/locations_uploader.rb vendor/built_in_modules/location/app/views/panel/location/back_end/locations/index.html.erb vendor/built_in_modules/location/app/views/panel/locations/back_end/locations/_form.html.erb vendor/built_in_modules/location/app/views/panel/locations/back_end/locations/edit.html.erb vendor/built_in_modules/location/app/views/panel/locations/back_end/locations/index.html.erb vendor/built_in_modules/location/app/views/panel/locations/back_end/locations/new.html.erb vendor/built_in_modules/location/config/routes.rb vendor/built_in_modules/location/lib/location.rb vendor/built_in_modules/location/location.gemspec vendor/built_in_modules/location/test/functional/panel/gprs/back_end/locations_controller_test.rb vendor/built_in_modules/location/test/functional/panel/location/back_end/locations_controller_test.rb
2013-01-24 08:30:02 +00:00
def update
@part = PagePart.find(params[:id])
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')
respond_to do |format|
format.js
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
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
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