2012-10-12 10:09:02 +00:00
|
|
|
|
#encoding: utf-8
|
2012-10-08 08:58:33 +00:00
|
|
|
|
# require ActionView::Helpers::FormTagHelper
|
|
|
|
|
|
2012-10-09 06:47:16 +00:00
|
|
|
|
module AttributeFieldsHelper
|
2012-10-08 08:58:33 +00:00
|
|
|
|
include ActionView::Helpers::FormTagHelper
|
|
|
|
|
include ActionView::Helpers::FormOptionsHelper
|
|
|
|
|
include ActionView::Helpers::DateHelper
|
|
|
|
|
include ActionView::Helpers::TagHelper
|
2012-10-12 10:09:02 +00:00
|
|
|
|
include ActionView::Helpers::RenderingHelper
|
2012-10-08 08:58:33 +00:00
|
|
|
|
|
2012-10-18 10:36:21 +00:00
|
|
|
|
def block_helper(user,index,disable = false)
|
2012-11-03 21:56:29 +00:00
|
|
|
|
unless self.disabled
|
|
|
|
|
@index = index
|
|
|
|
|
@markup_options = markup_options.merge(:disabled=>disable,:func=>"input_unit")
|
|
|
|
|
@user = user
|
|
|
|
|
@attribute_value = @user.get_value_from_field_id(id)
|
|
|
|
|
@new_attribute = @attribute_value.nil?
|
|
|
|
|
@attribute_value = @attribute_value || @user.attribute_values.build( attribute_field_id: id )
|
|
|
|
|
@prefiled_value = @attribute_value.value
|
|
|
|
|
@panel_setting = self.get_data
|
|
|
|
|
return instance_eval("render_#{markup}") #rescue ""
|
|
|
|
|
|
|
|
|
|
end
|
2012-10-08 08:58:33 +00:00
|
|
|
|
end
|
|
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
|
def lang_tab(str,lang)
|
|
|
|
|
content_tag(:div,str,:class=>"tab-pane fade",:id=>(get_field_name_base+"tab_#{lang}"))
|
2012-10-08 08:58:33 +00:00
|
|
|
|
end
|
|
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
|
def render_address
|
2012-11-03 21:56:29 +00:00
|
|
|
|
#NP
|
2012-10-12 10:09:02 +00:00
|
|
|
|
control_group_wrapper do |key,value|
|
|
|
|
|
result = '<div class="input-append">'.html_safe
|
2012-10-08 08:58:33 +00:00
|
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
|
if(add_more and value.is_a?(Array))
|
|
|
|
|
values = value
|
|
|
|
|
result << values.each_with_index.collect do |value,index|
|
2012-10-18 10:36:21 +00:00
|
|
|
|
text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options)
|
2012-10-12 10:09:02 +00:00
|
|
|
|
end.join.html_safe
|
|
|
|
|
else
|
2012-10-18 10:36:21 +00:00
|
|
|
|
result << text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}]"), value,@markup_options)
|
2012-10-12 10:09:02 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
result << ('<a href="#'+self.key+'-edit" class="btn" type="button" data-toggle="modal"><i class="icon-edit"></i></a>').html_safe
|
|
|
|
|
result << '<a href="#" class="btn" type="button"><i class="icon-trash"></i></a>'.html_safe
|
|
|
|
|
result << '</div>'.html_safe
|
|
|
|
|
result << gen_modal_dialog
|
2012-10-08 08:58:33 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
|
def render_checkbox
|
2012-11-03 21:56:29 +00:00
|
|
|
|
|
2012-10-24 06:46:25 +00:00
|
|
|
|
@prefiled_value ||=[]
|
2012-11-03 21:56:29 +00:00
|
|
|
|
# begin
|
|
|
|
|
# markup_value = eval(self.markup_value)
|
|
|
|
|
# rescue
|
|
|
|
|
# markup_value = self.markup_value
|
|
|
|
|
# ensure
|
|
|
|
|
# markup_value ||= {}
|
|
|
|
|
# end
|
|
|
|
|
|
2012-10-08 08:58:33 +00:00
|
|
|
|
control_group_wrapper do
|
2012-11-03 21:56:29 +00:00
|
|
|
|
a = self[:option_list].collect do |key,value|
|
|
|
|
|
label_tag(key,check_box_tag(get_field_name_base+"[#{key}]", true , (@prefiled_value.include?(key) ? true : false), {})+value[I18n.locale.to_s],@markup_options.merge(:class=>"control-label"))
|
2012-10-12 10:09:02 +00:00
|
|
|
|
end.join rescue ""
|
2012-10-08 08:58:33 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
|
def render_date
|
2012-11-03 21:56:29 +00:00
|
|
|
|
#NP
|
|
|
|
|
control_group_wrapper{date_select(get_field_name_base,nil,@markup_options.merge(:default=>@prefiled_value),:class=>"input-small")}
|
2012-10-08 08:58:33 +00:00
|
|
|
|
end
|
|
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
|
def render_date_durnation #Need re-write low priority
|
2012-11-03 21:56:29 +00:00
|
|
|
|
|
2012-10-08 08:58:33 +00:00
|
|
|
|
end
|
|
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
|
def render_radio_button
|
2012-10-24 06:46:25 +00:00
|
|
|
|
@prefiled_value ||=[]
|
2012-11-03 21:56:29 +00:00
|
|
|
|
# begin
|
|
|
|
|
# markup_value = eval(self.markup_value)
|
|
|
|
|
# rescue
|
|
|
|
|
# markup_value = self.markup_value
|
|
|
|
|
# ensure
|
|
|
|
|
# markup_value ||= {}
|
|
|
|
|
# end
|
2012-10-24 06:46:25 +00:00
|
|
|
|
control_group_wrapper do
|
2012-11-03 21:56:29 +00:00
|
|
|
|
self[:option_list].collect do |key,value|
|
|
|
|
|
label_tag(key,radio_button_tag(get_field_name_base, key , (@prefiled_value.include?(key) ? true : false), {})+value[I18n.locale.to_s],@markup_options.merge(:class=>"control-label"))
|
|
|
|
|
end.join
|
2012-10-08 08:58:33 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
|
def render_select
|
2012-11-03 21:56:29 +00:00
|
|
|
|
|
|
|
|
|
prompt = @panel_setting[:prompt][I18n.locale] rescue nil
|
|
|
|
|
@markup_options.merge!(:prompt => prompt) unless prompt.nil?
|
|
|
|
|
# markup_value = (self.markup_value.is_a?(Hash) ? self.markup_value : eval(self.markup_value) )rescue {}
|
|
|
|
|
# check self[:option_list].collect{|p| [p[1][I18n.locale.to_s],p[0]]}
|
|
|
|
|
control_group_wrapper{select_tag( get_field_name_base,options_for_select(self.option_list.collect{|p| [p[1][I18n.locale.to_s],p[0]]},@prefiled_value),@markup_options)} rescue ""
|
2012-10-08 08:58:33 +00:00
|
|
|
|
end
|
|
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
|
def render_text_area
|
2012-10-18 10:36:21 +00:00
|
|
|
|
control_group_wrapper do |key,value|
|
|
|
|
|
if(add_more and value.is_a?(Hash))
|
|
|
|
|
values = value
|
|
|
|
|
values.each_with_index.collect do |value,index|
|
2012-11-03 21:56:29 +00:00
|
|
|
|
place_holder= @panel_setting["placeholder"][key]
|
|
|
|
|
text_area_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options.merge(:placeholder=>place_holder))
|
2012-10-18 10:36:21 +00:00
|
|
|
|
end.join.html_safe
|
|
|
|
|
else
|
|
|
|
|
value = can_muti_lang_input ? @prefiled_value[key] : @prefiled_value
|
2012-11-03 21:56:29 +00:00
|
|
|
|
key = can_muti_lang_input ? "[#{key}]" : ""
|
|
|
|
|
place_holder= @panel_setting["placeholder"][I18n.locale.to_s] rescue ''
|
|
|
|
|
text_area_tag(get_field_name_base + key, value,@markup_options.merge(:placeholder=>place_holder))
|
2012-10-18 10:36:21 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2012-10-08 08:58:33 +00:00
|
|
|
|
end
|
|
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
|
def render_text_field
|
2012-10-18 10:36:21 +00:00
|
|
|
|
control_group_wrapper do |key,value|
|
2012-11-03 21:56:29 +00:00
|
|
|
|
if(add_more)
|
2012-10-12 10:09:02 +00:00
|
|
|
|
values = value
|
2012-11-03 21:56:29 +00:00
|
|
|
|
result = ""
|
|
|
|
|
unless values.nil?
|
|
|
|
|
result = values.each_with_index.collect do |value,index|
|
|
|
|
|
place_holder= @panel_setting["placeholder"][key]
|
|
|
|
|
text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options.merge(:placeholder=>place_holder))
|
|
|
|
|
end.join.html_safe
|
|
|
|
|
end
|
|
|
|
|
result
|
2012-10-12 10:09:02 +00:00
|
|
|
|
else
|
2012-11-03 21:56:29 +00:00
|
|
|
|
value = (can_muti_lang_input ? @prefiled_value[key] : @prefiled_value) rescue nil
|
|
|
|
|
key_field = can_muti_lang_input ? "[#{key}]" : ""
|
|
|
|
|
place_holder= @panel_setting["placeholder"][key] rescue ''
|
|
|
|
|
text_field_tag(get_field_name_base + key_field, value,@markup_options.merge(:placeholder=>place_holder))
|
2012-10-12 10:09:02 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2012-10-08 08:58:33 +00:00
|
|
|
|
protected
|
2012-10-12 10:09:02 +00:00
|
|
|
|
def lang_panel_control_wrapper(&block)
|
2012-10-18 10:36:21 +00:00
|
|
|
|
result = '<div class="tabbable">'
|
2012-10-12 10:09:02 +00:00
|
|
|
|
result << '<div class="tab-content">'
|
|
|
|
|
result << controls_wrapper{yield}
|
|
|
|
|
result << '</div>'
|
|
|
|
|
result << '</div>'
|
|
|
|
|
result.html_safe
|
|
|
|
|
end
|
2012-10-08 08:58:33 +00:00
|
|
|
|
|
|
|
|
|
def controls_wrapper(&block)
|
|
|
|
|
result = "<div class='controls'>"
|
2012-10-12 10:09:02 +00:00
|
|
|
|
if can_muti_lang_input
|
2012-10-18 10:36:21 +00:00
|
|
|
|
result << "<div class='tabbable'>"
|
2012-10-12 10:09:02 +00:00
|
|
|
|
result << "<div class='tab-content'>"
|
2012-11-03 21:56:29 +00:00
|
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
|
VALID_LOCALES.collect do |key|
|
|
|
|
|
value = @prefiled_value[key.to_s] rescue nil
|
|
|
|
|
div_class = ["tab-pane" ,"fade"].join(" ")
|
|
|
|
|
div_class << (key == I18n.locale.to_s ? " active in" : '')
|
|
|
|
|
result << content_tag(:div,yield(key,value),:class=>div_class,:id=>"tab"+id.to_s+"_#{key}")
|
|
|
|
|
end
|
2012-11-03 21:56:29 +00:00
|
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
|
result << "</div>"
|
2012-10-18 10:36:21 +00:00
|
|
|
|
result << "<ul class='nav nav-pills'>"
|
2012-10-12 10:09:02 +00:00
|
|
|
|
VALID_LOCALES.each do |key|
|
2012-10-29 08:10:07 +00:00
|
|
|
|
result << content_tag(:li,link_to(t(:_locale, :locale => key),"#tab"+id.to_s+"_#{key}",:data=>{:toggle=>"tab"}),:class=>(key == I18n.locale.to_s ? "active" : nil))
|
2012-10-12 10:09:02 +00:00
|
|
|
|
end
|
|
|
|
|
result << "</ul>"
|
|
|
|
|
result << "</div>"
|
|
|
|
|
# @prefiled_value.collect do |key,value|
|
|
|
|
|
# result << yield(key,value)
|
|
|
|
|
# end
|
|
|
|
|
else
|
|
|
|
|
result << yield
|
|
|
|
|
end
|
|
|
|
|
if can_add_more
|
|
|
|
|
result << '<span class="help-block">'
|
|
|
|
|
result << '<a href="#"><i class="icon-plus-sign"></i> Add</a>'
|
|
|
|
|
result << '</span>'
|
|
|
|
|
end
|
2012-10-08 08:58:33 +00:00
|
|
|
|
result << "</div>"
|
|
|
|
|
result.html_safe
|
|
|
|
|
end
|
|
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
|
def control_group_wrapper(&block)
|
|
|
|
|
div_class = can_muti_lang_input ? "control-group language-swich" : "control-group"
|
|
|
|
|
temp = label + controls_wrapper(&block)
|
|
|
|
|
|
|
|
|
|
result = content_tag(:div,temp,:class=>div_class)
|
|
|
|
|
result << end_block
|
|
|
|
|
|
2012-10-08 08:58:33 +00:00
|
|
|
|
result.html_safe
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def end_block
|
|
|
|
|
if @new_attribute
|
2012-11-03 21:56:29 +00:00
|
|
|
|
hidden_field_tag(get_basic_field_name_base+"[attribute_field_id]",id,:for=>"field_#{@index}")
|
2012-10-08 08:58:33 +00:00
|
|
|
|
else
|
2012-11-03 21:56:29 +00:00
|
|
|
|
hidden_field_tag(get_basic_field_name_base+"[id]",@attribute_value.id,:for=>"field_#{@index}")
|
2012-10-08 08:58:33 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2012-11-03 21:56:29 +00:00
|
|
|
|
def get_basic_field_name_base
|
2012-10-08 08:58:33 +00:00
|
|
|
|
if @new_attribute
|
|
|
|
|
"user[new_attribute_values][#{@index}]"
|
|
|
|
|
else
|
|
|
|
|
"user[attribute_values][#{@index}]"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2012-11-03 21:56:29 +00:00
|
|
|
|
def get_field_name_base
|
|
|
|
|
get_basic_field_name_base + "[value]"
|
|
|
|
|
end
|
|
|
|
|
|
2012-10-08 08:58:33 +00:00
|
|
|
|
def label
|
2012-11-03 21:56:29 +00:00
|
|
|
|
label_tag(key,title,:class=>"control-label",:func => "field_label")
|
2012-10-08 08:58:33 +00:00
|
|
|
|
end
|
|
|
|
|
|
2012-10-12 10:09:02 +00:00
|
|
|
|
def can_muti_lang_input
|
2012-11-03 21:56:29 +00:00
|
|
|
|
LIST[:markups][markup]["muti_lang_input_supprt"] #and locale
|
2012-10-12 10:09:02 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def can_add_more
|
|
|
|
|
locale and LIST[:markups][markup]["ext_support"] && add_more
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def render_anywhere(partial, assigns)
|
|
|
|
|
view = ActionView::Base.new(Rails::Configuration.new.view_path, assigns)
|
|
|
|
|
ActionView::Base.helper_modules.each { |helper| view.extend helper }
|
|
|
|
|
view.extend ApplicationHelper
|
|
|
|
|
view.render(:partial => partial)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def gen_modal_dialog
|
|
|
|
|
result = '<div class="modal hide fade" id="address-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none; ">'
|
|
|
|
|
result << '<div class="modal-header">'
|
|
|
|
|
result << '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>'
|
|
|
|
|
result << '<h3 id="myModalLabel">'+title+'</h3>'
|
|
|
|
|
result << '</div>'
|
|
|
|
|
result << '<div class="modal-body">'
|
|
|
|
|
result << '<p>One fine body…</p>'
|
|
|
|
|
result << '</div>'
|
|
|
|
|
result << '<div class="modal-footer">'
|
|
|
|
|
result << '<button class="btn" data-dismiss="modal" aria-hidden="true">'+I18n.t("modal.close")+'</button>'
|
|
|
|
|
result << '<button class="btn btn-primary">'+I18n.t("modal.save_and_close")+'</button>'
|
|
|
|
|
result << '</div>'
|
|
|
|
|
result << '</div>'
|
|
|
|
|
result.html_safe
|
|
|
|
|
end
|
|
|
|
|
|
2012-10-08 08:58:33 +00:00
|
|
|
|
end
|