#encoding: utf-8 module AttributeFieldsHelper include ActionView::Helpers::FormTagHelper include ActionView::Helpers::FormOptionsHelper include ActionView::Helpers::DateHelper include ActionView::Helpers::TagHelper include ActionView::Helpers::RenderingHelper include OrbitBasis::RenderAnywhere def block_helper(user,index,disable = false) 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 end def lang_tab(str,lang) content_tag(:div,str,:class=>"tab-pane fade",:id=>(get_field_name_base+"tab_#{lang}")) end def render_address control_group_wrapper do |key,value| 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 '' result = text_area_tag(get_field_name_base + key_field, value,@markup_options.merge(:placeholder=>place_holder)) result << hidden_field_tag(get_basic_field_name_base+"[temp][street_address][#{key}]",nil,:class=>"street_address_#{key}") result << hidden_field_tag(get_basic_field_name_base+"[temp][city][#{key}]",nil,:class=>"city_#{key}") result << hidden_field_tag(get_basic_field_name_base+"[temp][zip][#{key}]",nil,:class=>"zip_#{key}") result << hidden_field_tag(get_basic_field_name_base+"[temp][country][#{key}]",nil,:class=>"country_#{key}") result << hidden_field_tag(get_basic_field_name_base+"[temp][indicator][#{key}]",nil,:class=>"indicator_#{key}") end end def render_checkbox @prefiled_value ||=[] control_group_wrapper do 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")) end.join rescue "" end end def render_date control_group_wrapper{date_select(get_field_name_base,nil,@markup_options.merge(:default=>@prefiled_value),:class=>"input-small")} end def render_date_durnation #Need re-write low priority end def render_radio_button @prefiled_value ||=[] control_group_wrapper do 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 end end def render_select prompt = @panel_setting["initial"][I18n.locale.to_s] rescue nil @markup_options.merge!(:prompt => prompt) unless prompt.nil? 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 "" end def render_text_area control_group_wrapper do |key,value| value = can_muti_lang_input? ? @prefiled_value[key] : @prefiled_value 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)) end end def render_text_field control_group_wrapper do |key,value,add_more_counter| if(add_more) place_holder= @panel_setting["placeholder"][key] text_field_tag(get_field_name_base + (key.nil? ? '' : "[][#{key}]"), value,@markup_options.merge(:placeholder=>place_holder)) else 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)) end end end protected def lang_panel_control_wrapper(&block) result = '