This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/helpers/admin/page_parts_helper.rb

153 lines
4.8 KiB
Ruby

module Admin::PagePartsHelper
def support_link
url_method = @module_app.get_default_widget[:url_method]
unless url_method.nil?
res = "Link:"
res << select_tag( "page_part[widget_field_is_link][]", options_for_select([["NotLink",false],["Link1",url_method]]))
res.html_safe
end
end
def get_widget_field_rel(local_item=nil)
local_item = @part if local_item.nil? && @part
local_item = @page if local_item.nil? && @page
case local_item
when Page
admin_pages_path
when PagePart
admin_page_parts_path
end
end
def link_to_field_switch(i,object_name,field_name,local_item=nil,prefill_value=nil) #link_to_field is for showing
local_item = @part if local_item.nil? && @part
local_item = @page if local_item.nil? && @page
res = ''
choosen_value = prefill_value || (local_item[:widget_field][i][0] rescue nil)
if choosen_value
choosen_field_is_link = (@module_app.widget_fields.select{|t| t[0].to_s==choosen_value}.first)[2]==:link
else
choosen_field_is_link = false
end
if choosen_field_is_link
value = case local_item
when Page
local_item[:frontend_field][i][2] rescue false
when PagePart
local_item[:widget_field][i][2] rescue false
end
res = label_tag '' do
check_box_tag("#{object_name}[#{field_name}_is_link][]", "true", value) + I18n.t("default_widget.field_is_link")
end
else # choosen_field_not_link
res = hidden_field_tag "#{object_name}[#{field_name}_is_link][]", 'false'
end # of if choosen_field_is_link
end
def widget_field_options(i,local_item=nil)
local_item = @part if local_item.nil? && @part
local_item = @page if local_item.nil? && @page
options = @module_app.widget_fields.collect do |widget_field|
label = I18n.t("#{@module_app.key}.default_widget.#{widget_field[0]}")
[label, widget_field[0]]
end
case local_item
when Page
options_for_select(options, (local_item[:frontend_field][i][0] if (local_item && !local_item[:frontend_field].blank? && !local_item[:frontend_field][i].blank?)) )
when PagePart
options_for_select(options, (local_item[:widget_field][i][0] if (local_item && !local_item[:widget_field].blank? && !local_item[:widget_field][i].blank?)) )
end
end
def widget_fiield_type_options(i,local_item=nil)
options = LIST[:widget_field_type].collect{|widget_field| [widget_field.humanize, widget_field]}
local_item = @part if local_item.nil? && @part
local_item = @page if local_item.nil? && @page
case local_item
when Page
options_for_select(options, (local_item[:frontend_field][i][1] if (local_item && !local_item[:frontend_field].blank? && !local_item[:frontend_field][i].blank?)) )
when PagePart
options_for_select(options, (local_item[:widget_field][i][1] if (local_item && !local_item[:widget_field].blank? && !local_item[:widget_field][i].blank?)) )
end
end
def tag_checked_value(part,radio_value)
if radio_value.blank?
(part.nil? || part[:tag].blank?) ? true : false
else
part and (part[:tag].include?(radio_value.to_s)) ? true : false
end
end
def category_checked_value(part,radio_value)
if radio_value.blank?
(part.nil? || part[:category].blank?) ? true : false
else
part and (part[:category].include?(radio_value.to_s)) ? true : false
end
end
def style_checked_value(part,radio_value)
case part
when Page
if part.frontend_style.nil? && radio_value == "typeA"
true
else
(part.frontend_style == radio_value) ? true : false
end
when PagePart
if part.widget_style.nil? && radio_value == "typeA"
true
else
(part.widget_style == radio_value) ? true : false
end
when nil
false
end
end
def nil_checkbox_button(part,tag_or_cate)
field_name = case part
when PagePart
'page_part'
when Page
'page'
end
content_tag :label,:class=>"radio inline" do
op = check_box_tag("#{field_name}[#{tag_or_cate}][]", 'nil' , eval("#{tag_or_cate}_checked_value(part,'')"),:class=>'select_all')
op << I18n.t("default_widget.no_value")
end
end
def nil_radio_button(part,tag_or_cate)
field_name = case part
when PagePart
'page_part'
when Page
'page'
end
content_tag :label,:class=>"radio inline" do
op = radio_button(field_name, tag_or_cate, '' , :checked => eval("#{tag_or_cate}_checked_value(part,'')"))
op << I18n.t("default_widget.no_value")
end
end
def show_default_widget_setting_panel
@module_app && @module_app.has_default_widget? && (!@user_choose.nil? && @user_choose== 'default_widget') #&& @part.widget_path == 'default_widget'
end
def show_custom_widget_setting_panel
true
end
end