# require ActionView::Helpers::FormTagHelper module AttributeFieldsHelper include ActionView::Helpers::FormTagHelper include ActionView::Helpers::FormOptionsHelper include ActionView::Helpers::DateHelper include ActionView::Helpers::TagHelper def block_helper(user,index) @index = index @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.get_values return instance_eval("render_#{markup}") #rescue "" end def render_text_area result = "" result << label if self.locale? @prefiled_value.each do |key,value| result << controls_wrapper{text_area_tag("#{get_field_name_base}[#{key.to_s}]", value, {})} end else value = @prefiled_value result << controls_wrapper{text_area_tag(get_field_name_base, value, {})} end result << end_block result.html_safe end def render_radio_button result = "" result << label markup_value.each do |key,value| result << controls_wrapper{label_tag(key,radio_button_tag(get_field_name_base+"[#{key}]", value[I18n.locale.to_s], (@prefiled_value==value ? true : false), {})+value[I18n.locale.to_s],:class=>"control-label")} end result << end_block result.html_safe end def render_checkbox # label+ "" + end_block # check_box_tag(name, value = "1", checked = false, options = {}) result = "" result << label markup_value.each do |key,value| result << controls_wrapper{label_tag(key,check_box_tag(get_field_name_base+"[#{key}]", value[I18n.locale.to_s], (@prefiled_value==value ? true : false), {})+value[I18n.locale.to_s],:class=>"control-label")} end result << end_block result.html_safe end def render_date_durnation control_group_wrapper do if @new_attribute @prefiled_value = {} end label+controls_wrapper{date_select(get_field_name_base+"[value][from]",@prefiled_value["from"]) +date_select(get_field_name_base+"[value][end]",@prefiled_value["end"])} + end_block end end def render_text_field_ext result = "" result << label if self.locale? @prefiled_value.each do |key,value| result << controls_wrapper{text_field_tag("#{get_field_name_base}[#{key.to_s}]", value, {})} end else value = @prefiled_value result << controls_wrapper{text_field_tag(get_field_name_base, value, {})} end result << end_block result.html_safe end def render_date label+controls_wrapper{date_select(get_field_name_base+"[value]",@prefiled_value)} + end_block end def render_select label+controls_wrapper{select_tag( get_field_name_base+"[value]",options_for_select(markup_value.collect{|p| [p[1][I18n.locale.to_s],p[0]]},@prefiled_value))} + end_block end def render_text_field result = "" result << label if self.locale? @prefiled_value.each do |key,value| result << controls_wrapper{text_field_tag("#{get_field_name_base}[#{key.to_s}]", value, {})} end else value = @prefiled_value result << controls_wrapper{text_field_tag(get_field_name_base, value, {})} end result << end_block result.html_safe end def render_email label+controls_wrapper{email_field_tag(get_field_name_base, value, {})}+ end_block end def render_addr label+controls_wrapper{text_field_tag(get_field_name_base, value, {})} + end_block end protected def controls_wrapper(&block) result = "