From a85e5fcc0db7e8e380cb6e4808423af06f74f1f6 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Mon, 12 Nov 2012 10:41:41 +0800 Subject: [PATCH] address field. js and style is broken --- app/assets/javascripts/inc/input_module.js | 80 ++++++++ .../javascripts/inc/ploy_input_field.js | 26 +++ app/assets/stylesheets/member.css | 15 +- app/assets/stylesheets/site-map.css | 2 +- app/helpers/attribute_fields_helper.rb | 142 +++++--------- app/models/user/attribute_field.rb | 183 ++++++++---------- app/models/user/attribute_value.rb | 98 +++++----- .../admin/users_new_interface/_form.html.erb | 50 ----- .../admin/users_new_interface/edit.html.erb | 3 + .../shared/_address_modal_dialog.html.erb | 13 -- .../_address_modal_dialog.html.erb | 61 ++++++ config/list.yml | 6 +- config/locales/zh_tw.yml | 11 ++ lib/orbit_basis.rb | 7 + 14 files changed, 386 insertions(+), 311 deletions(-) create mode 100644 app/assets/javascripts/inc/input_module.js create mode 100644 app/assets/javascripts/inc/ploy_input_field.js delete mode 100644 app/views/shared/_address_modal_dialog.html.erb create mode 100644 app/views/shared/attribute_field/_address_modal_dialog.html.erb diff --git a/app/assets/javascripts/inc/input_module.js b/app/assets/javascripts/inc/input_module.js new file mode 100644 index 00000000..869a2098 --- /dev/null +++ b/app/assets/javascripts/inc/input_module.js @@ -0,0 +1,80 @@ +jQuery(document).ready(function($) { + // Stuff to do as soon as the DOM is ready. Use $() w/o colliding with other libs; + var current_textarea = {}; + current_textarea['en'] = $("textarea[for=en]").val(); + current_textarea['zh_tw'] = $("textarea[for=zh_tw]").val(); + $("div.controls").on("click","a.edit-btn",function(){ + switch($(this).parent().parent().find("ul li.active a").attr("href")){ + case ".tab1": + $("#tab3").addClass("active in"); + $(".modal-body li").eq(0).addClass("active"); + break; + case ".tab2": + $("#tab4").addClass("active in"); + $(".modal-body li").eq(1).addClass("active"); + break; + } + var lang = ["en","zh_tw"]; + for(i=0;i<2;i++){ + + var sa = $(".tab-content input.street_address_"+lang[i]).val(); + var city = $(".tab-content input.city_"+lang[i]).val(); + var county = $(".tab-content input.county_"+lang[i]).val(); + var zip = $(".tab-content input.zip_"+lang[i]).val(); + var country = $(".tab-content input.country_"+lang[i]).val(); + $(".modal-body").find('#street_address_'+lang[i]).val(sa) + $(".modal-body").find('#city_'+lang[i]).val(city); + $(".modal-body").find('#counties_'+lang[i]).val(county); + $(".modal-body").find('#zip_'+lang[i]).val(zip); + $(".modal-body").find('#country_'+lang[i]).val(country); + var verify = sa + city + country +county + zip; + var combined = ""; + if(verify!="") + combined = sa + "\n" + city + "\n" + county + "\n" + zip + "\n" + country; + + if($(".tab-content textarea[for="+lang[i]+"]").val() != combined){ + $(".tab-content").find('#street_address_'+lang[i]).val($(".tab-content textarea[for="+lang[i]+"]").val()); + $(".modal-body input").val(""); + } + } + }) + $("textarea.dummy").change(function(){ + var lang = $(this).attr("for"); + if(current_textarea[lang] != $(this).val()) + $("input.indicator_"+lang).val("true"); + else + $("input.indicator_"+lang).val("false"); + }) + + $(".address-edit").on("hidden",function(){ + $("#tab3").removeClass("active in"); + $("#tab4").removeClass("active in"); + $(".modal-body li").removeClass("active"); + $(".modal-body input, .modal-body textarea").val(""); + + }) + $(".bt-save").click(function(){ + var lang = ["en","zh_tw"]; + for(i=0;i<2;i++){ + var sa = $(".tab-content").find('#street_address_'+lang[i]).val(); + var city = $(".tab-content").find('#city_'+lang[i]).val(); + var county = $(".tab-content").find('#counties_'+lang[i]).val(); + var zip = $(".tab-content").find('#zip_'+lang[i]).val(); + var country = $(".tab-content").find('#country_'+lang[i]).val(); + $(".tab-content input.street_address_"+lang[i]).val(sa); + $(".tab-content input.city_"+lang[i]).val(city); + $(".tab-content input.county_"+lang[i]).val(county); + $(".tab-content input.zip_"+lang[i]).val(zip); + $(".tab-content input.country_"+lang[i]).val(country); + var verify = sa + city + country +county + zip; + var combined = ""; + if(verify!="") + combined = sa + "\n" + city + "\n" + county + "\n" + zip + "\n" + country; + $(".tab-content textarea[for="+lang[i]+"]").val(combined); + $("input.indicator_"+lang[i]).val("false"); + current_textarea[lang[i]] = combined; + } + + }) + +}); diff --git a/app/assets/javascripts/inc/ploy_input_field.js b/app/assets/javascripts/inc/ploy_input_field.js new file mode 100644 index 00000000..a4bb01f5 --- /dev/null +++ b/app/assets/javascripts/inc/ploy_input_field.js @@ -0,0 +1,26 @@ + function checkMultipleInput() { + $(".multipleInput").each(function() { + $(this).children('.controls').length==1 ? $(this).addClass("plural") : $(this).removeClass("plural") + }); + } + function removeInput(){ + $(".removeInput").click(function (){ + $(this).parents(".controls").remove(); + checkMultipleInput(); + return false; + }); + } + $(document).ready(function(){ + var $modalNumber = 0; + checkMultipleInput(); + removeInput(); + $(".addinput").click(function (){ + $modalNumber+=1; + var $CloneTarget = $(this).parents(".controls").prev(".multipleInput").children('.controls:last'); + $(this).parents(".controls").prev(".multipleInput").append($CloneTarget.clone()); + $(this).parents(".controls").prev(".multipleInput").children('.controls:last input').val(""); + removeInput(); + checkMultipleInput(); + return false; + }) + }); \ No newline at end of file diff --git a/app/assets/stylesheets/member.css b/app/assets/stylesheets/member.css index add8774a..031b271c 100644 --- a/app/assets/stylesheets/member.css +++ b/app/assets/stylesheets/member.css @@ -280,7 +280,7 @@ margin-top: 8px; } .nav-tabs li a { - padding-right: 32px; + /*padding-right: 32px;*/ } .user-role { @@ -314,7 +314,8 @@ float: left; } .role-block .nav-pills { - margin-bottom: 0;g + margin-bottom: 0; + margin-left: 10px; } .role-block .nav-pills > li > a { margin-top: 0; @@ -345,7 +346,13 @@ -moz-border-radius: 0 3px 3px 0; border-radius: 0 3px 3px 0; } +.input-append > .active { + display: inline-block; +} +.input-append .active { + background-color: transparent; + border-color: transparent; +} .language-swich .tab-pane { - margin-bottom: 5px; - margin-right: 10px; + /*margin-bottom: 5px;*/ } \ No newline at end of file diff --git a/app/assets/stylesheets/site-map.css b/app/assets/stylesheets/site-map.css index 53e94c1f..c7a95b45 100644 --- a/app/assets/stylesheets/site-map.css +++ b/app/assets/stylesheets/site-map.css @@ -111,7 +111,7 @@ .role-block .form-horizontal .controls { margin-left: 120px; } -.role-block .form-horizontal .controls>.input-append { +.role-block .form-horizontal .controls .input-append { margin-bottom: 10px; } .role-block .form-horizontal legend .onoff { diff --git a/app/helpers/attribute_fields_helper.rb b/app/helpers/attribute_fields_helper.rb index a1d68b56..5b7343fa 100644 --- a/app/helpers/attribute_fields_helper.rb +++ b/app/helpers/attribute_fields_helper.rb @@ -5,7 +5,7 @@ module AttributeFieldsHelper 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 @@ -26,37 +26,22 @@ module AttributeFieldsHelper end def render_address - #NP control_group_wrapper do |key,value| - result = '
'.html_safe + 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)) - if(add_more and value.is_a?(Array)) - values = value - result << values.each_with_index.collect do |value,index| - text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options) - end.join.html_safe - else - result << text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}]"), value,@markup_options) - end - - result << ('').html_safe - result << ''.html_safe - result << '
'.html_safe - result << gen_modal_dialog + 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 ||=[] - # @prefiled_value = @prefiled_value.keys unless @prefiled_value ==[] - # begin - # markup_value = eval(self.markup_value) - # rescue - # markup_value = self.markup_value - # ensure - # markup_value ||= {} - # end - 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")) @@ -65,7 +50,6 @@ module AttributeFieldsHelper end def render_date - #NP control_group_wrapper{date_select(get_field_name_base,nil,@markup_options.merge(:default=>@prefiled_value),:class=>"input-small")} end @@ -75,13 +59,6 @@ module AttributeFieldsHelper def render_radio_button @prefiled_value ||=[] - # begin - # markup_value = eval(self.markup_value) - # rescue - # markup_value = self.markup_value - # ensure - # markup_value ||= {} - # end 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")) @@ -92,25 +69,15 @@ module AttributeFieldsHelper def render_select prompt = @panel_setting["initial"][I18n.locale.to_s] 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 "" end def render_text_area control_group_wrapper do |key,value| - # if(add_more and value.is_a?(Hash)) - # values = value - # values.each_with_index.collect do |value,index| - # 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)) - # end.join.html_safe - # else - value = can_muti_lang_input ? @prefiled_value[key] : @prefiled_value - key = can_muti_lang_input ? "[#{key}]" : "" + 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 end @@ -118,10 +85,10 @@ module AttributeFieldsHelper 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)) + link_to( (content_tag :i,'',:class=>"icon-trash"),'#',:class=> "btn removeInput") + 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}]" : "" + 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 @@ -141,50 +108,58 @@ protected def controls_wrapper(&block) loop_time = self.add_more ? @attribute_value.add_more_counter : 1 result = '' - result << "
" if self.add_more + multi_and_edit_more_class = (self.markup == 'address' ? "multipleInput" : "multipleInput editMore" ) + result << "
" if self.add_more result << "
" loop_time.times do |loop_counter| - if can_muti_lang_input + + if can_muti_lang_input? result << "
" - - result << "
" + tab_content_class = add_more ? "tab-content input-append" : "tab-content" + + result << "
" 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" : '') if self.add_more - div_class << " input-append #{add_more_tab(:input_field,loop_counter,key)}" - # binding.pry + div_class << " #{add_more_tab(:input_field,loop_counter,key)}" add_more_field_value = @prefiled_value[loop_counter][key] rescue '' result << content_tag(:div,yield(key,add_more_field_value,loop_counter),:class=>div_class)#,:id=>"tab"+id.to_s+"_#{key}_#{loop_counter}" else result << content_tag(:div,yield(key,value),:class=>div_class,:id=>"tab"+id.to_s+"_#{key}") end end # of VALID_LOCALES.collect for tabed input + + result << '' if self.markup == 'address' + result << '' if self.add_more result << "
" - result << "" + if can_muti_lang_input? + result << "" + end result << "
" - # @prefiled_value.collect do |key,value| - # result << yield(key,value) - # end + result << gen_modal_dialog if self.markup == "address" else + result << yield end if can_add_more and (loop_counter == loop_time-1) temp_field_name = get_basic_field_name_base + '[temp]' + result << '
' result << '' - result << ''+I18n.t("admin.infos.add")+' ' + result << ''+I18n.t("admin.infos.add")+' ' result << hidden_field_tag("#{temp_field_name}[count]",loop_time,:class=>"list_count") result << hidden_field_tag("#{temp_field_name}[count]",get_basic_field_name_base,:class=>"field_name") result << '' + result << '
' end end # of loop_time result << "
" @@ -193,9 +168,8 @@ protected end # of def controls_wrapper(&block) def control_group_wrapper(&block) - div_class = can_muti_lang_input ? "control-group language-swich" : "control-group" + 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 @@ -243,36 +217,26 @@ protected label_tag(key,title,:class=>"control-label",:func => "field_label") end - def can_muti_lang_input - LIST[:markups][markup]["muti_lang_input_supprt"] #and locale + def can_muti_lang_input? + if self.markup == "address" + return true + else + LIST[:markups][markup]["muti_lang_input_supprt"] and !(get_data["cross_lang"] == "true") + end end def can_add_more - locale and LIST[:markups][markup]["ext_support"] && add_more + if self.markup == "address" + return false + else + locale and LIST[:markups][markup]["ext_support"] && add_more + end 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 = '' - result.html_safe + render_anywhere("shared/attribute_field/address_modal_dialog",{:field_name=>title,:btn_class => "#{get_pairing_tab_class({})}"}) end end \ No newline at end of file diff --git a/app/models/user/attribute_field.rb b/app/models/user/attribute_field.rb index 3cef5f1d..62281402 100644 --- a/app/models/user/attribute_field.rb +++ b/app/models/user/attribute_field.rb @@ -1,5 +1,4 @@ class AttributeField - include Mongoid::Document include Mongoid::Timestamps include ::AttributeFieldsHelper @@ -8,8 +7,6 @@ class AttributeField field :markup ,:default=>"text_field" field :option_list ,:type => Hash,:default => {} field :markup_options,:type => Hash - # field :locale, :type => Boolean, :default => true - # field :list_options, :type => Array field :built_in, :type => Boolean, :default => false field :disabled, :type => Boolean, :default => false field :to_delete,:type=> Boolean,:default => false @@ -18,18 +15,11 @@ class AttributeField field :typeC,:type=> Hash,:default=>{:claendar=>"west_claendar",:format=>"format3"} field :typeD,:type=> Hash,:default=>{:cross_lang=>false} field :typeE,:type=> Hash,:default=>{} - - - #field :title, localize: true - field :title, localize: true - belongs_to :attribute - # belongs_to :role has_many :attribute_values,:autosave => true, :dependent => :destroy before_save :check_option_list - # validates_uniqueness_of :key def markup_value get_data["option_list"] @@ -52,12 +42,6 @@ class AttributeField (self.attribute.role.method(self[:key].pluralize.to_sym) && self.attribute.role.method(self[:key].pluralize+"_for_"+markup)) rescue false end - # def markup_value=(var) - # if !self_defined_markup_options? - # self[:markup_value] = (eval(var) rescue {}) - # end - # end - def option_list if self_defined_markup_options? #Class need to have corresponding field and value agent @@ -71,8 +55,6 @@ class AttributeField end end - - def markup_options=(var) self[:markup_options] = (eval(var) rescue {}) end @@ -99,92 +81,18 @@ class AttributeField end - # def title_translations - # if locale - # return self.locale_title_translations - # else - # return self[:neutral_title] #Hash[VALID_LOCALES.map{|d| [d,neutral_title]}] - # end - # end - - # def title_translations=(var) - # if locale - # self.locale_title_translations = var - # end - # end - - # def title - # if locale - # return self.locale_title - # else - # return self.neutral_title - # end - # end - - # def check_title - # if locale - # self.locale_title_translations = self[:temp_title] - # else - # self.neutral_title = self[:temp_title] - # end - # self.unset("temp_title") - # end - - # def title=(var) - # self["temp_title"] = var - # end - - # # Convert the string list_options into an array - # def select_list_options=(var) - # self.list_options = var.gsub(' ', '').split(',') - # end - - # # Convert the array list_options into a string - # def select_list_options - # self.list_options.to_a.join(', ') - # end - - def add_more_convert(opt) - case opt - when :to_add_more - self.attribute_values.each do |av| - VALID_LOCALES.each do |loc| - splited_str = av[loc].split(",") rescue [] - av["val"] = [] if av["val"].nil? - splited_str.each_with_index{|value,index| av["val"][index] = av["val"][index].nil? ? {loc=>value} : av["val"][index].merge(loc=>value) } - # av[loc] = Hash[splited_str.each_with_index.map{|t,index| [index.to_s,t]}] rescue {"0"=>av[loc].to_s} - end - av.save - end #of self.attribute_values.each - when :to_no_add_more - self.attribute_values.each do |av| - VALID_LOCALES.each do |loc| - if av["val"].kind_of? Array - av[loc] = av["val"].collect{|t| t[loc]}.join(",") - else - av[loc] = av["val"] - end - # av[loc] = av["val"].invert.keys.join(",") rescue av["val"] - # av.save(:validate => false) - end - av.unset("val") - av.save - end #of self.attribute_values.each - end - end def typeA=(var) - if self["typeA"]["add_more"] != var["add_more"] - case var["add_more"] - when "true" #from no-add_more to add_more - add_more_convert(:to_add_more) - else #from add_more to no-add_more - add_more_convert(:to_no_add_more) - end # of case - end # of if + check_add_more_convert(var) + check_cross_lang_convert(var,"typeA") self["typeA"] = var end + def typeD=(var) + check_cross_lang_convert(var,"typeD") + self["typeD"] = var + end + def is_built_in? self.built_in end @@ -195,7 +103,82 @@ class AttributeField protected def check_option_list - self[:option_list] = self[panel]["option_list"] + self[:option_list] = self[panel]["option_list"] rescue nil + end + + def add_more_convert(opt) + case opt + when :to_add_more + self.attribute_values.each do |av| + VALID_LOCALES.each do |loc| + splited_str = av[loc].split(",") rescue [] + av["val"] = [] if av["val"].nil? + splited_str.each_with_index{|value,index| av["val"][index] = av["val"][index].nil? ? {loc=>value} : av["val"][index].merge(loc=>value) } + end + av.unset_all_lang_values + av.save + end #of self.attribute_values.each + when :to_no_add_more + self.attribute_values.each do |av| + VALID_LOCALES.each do |loc| + if av["val"].kind_of? Array + av[loc] = av["val"].collect{|t| t[loc]}.join(",") + else + av[loc] = av["val"] + end + end + av.unset("val") + av.save + end #of self.attribute_values.each + end + end + + def cross_lang_convert(opt) + case opt + when :to_cross_lang + self.attribute_values.each do |av| + if add_more + av["val"] = av["val"].collect{|t| t.invert.keys.join(",")} + else + av["val"] = VALID_LOCALES.collect{|t| av[t]}.join(",") + av.unset_all_lang_values + end + av.save + end #of self.attribute_values.each + when :to_no_cross_lang + default_locale = I18n.default_locale.to_s + self.attribute_values.each do |av| + if add_more + av["val"] = av["val"].collect{|t| {default_locale => t} } + else + av[default_locale] = av["val"] + av.unset("val") + end + av.save + end #of self.attribute_values.each + end + end + + def check_add_more_convert(var) + if self["typeA"]["add_more"] != var["add_more"] + case var["add_more"] + when "true" #from no-add_more to add_more + add_more_convert(:to_add_more) + else #from add_more to no-add_more + add_more_convert(:to_no_add_more) + end # of case + end # of if + end + + def check_cross_lang_convert(var,field) + if self[field]["cross_lang"] != var["cross_lang"] + case var["cross_lang"] + when "true" #from no-add_more to add_more + cross_lang_convert(:to_cross_lang) + else #from add_more to no-add_more + cross_lang_convert(:to_no_cross_lang) + end # of case + end # of if end end diff --git a/app/models/user/attribute_value.rb b/app/models/user/attribute_value.rb index 7b5d4caf..16ab50f8 100644 --- a/app/models/user/attribute_value.rb +++ b/app/models/user/attribute_value.rb @@ -12,35 +12,13 @@ class AttributeValue before_save :data_proc # NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"] + def add_more_counter index_max = self["val"].count rescue 0 index_max == 0 ? 1 : index_max end - def data_proc - unless self[:temp_data].nil? - case self.attribute_field.markup - when 'text_field','text_area' - if self.attribute_field.add_more - self["val"] = self["temp_data"] - else # if not add_more - self[:temp_data].each{|key,val| - self[key] = val - } if(!self.attribute_field.get_data[:cross_lang]) - self["val"] = self[:temp_data] if(self.attribute_field.get_data[:cross_lang]) - end # of self.attribute_field.add_more - - when 'select','date','radio_button' - self["val"] = self[:temp_data] - when 'checkbox' - self["val"] = self[:temp_data].keys - end #end of case self.attribute_field.markup - end # of self[:temp_data].nil? - self.unset('temp_data') - self.unset('temp') - end #of data_proc - def value(index = nil) result = case self.attribute_field.markup when 'text_field','text_area' @@ -48,7 +26,7 @@ class AttributeValue index.nil? ? self["val"] : self["val"][index] # self.attribute_field.get_data[:cross_lang] ? Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}] : self["val"] #if !self.attribute_field.get_data[:cross_lang] else - self.attribute_field.get_data[:cross_lang] ? self["val"] : Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}] + self.attribute_field.get_data["cross_lang"] =="true" ? self["val"] : Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}] end when 'select','date','radio_button' self["val"] @@ -62,17 +40,6 @@ class AttributeValue self[:temp_data] = value end - def check_key - self.key = attribute_field.key - end - - def method_missing(*field) - if field.size < 1 - self[field[0]] - else - self[(field[0].to_s.delete "=")] = field[1] - end - end def get_value_by_locale(locale,add_more_index=nil) @@ -106,23 +73,52 @@ class AttributeValue end end - # def get_values - # unless ['select','checkbox','radio_button'].include?(self.attribute_field.markup ) - # if self.attribute_field.locale && LIST[:markups][self.attribute_field.markup]["muti_lang_input_supprt"] - # return Hash[VALID_LOCALES.collect{|lang| [lang,get_value_by_locale(lang.to_sym)]}] - # else - # return get_value_by_locale("") - # end - # else - # if self.attribute_field.markup == "select" - # self[:value] - # else - # self[:value].keys rescue self[:value] - # end - # end - # end - protected + +protected +def unset_all_lang_values + VALID_LOCALES.each{|t| self.unset t} + end + + def data_proc + unless self[:temp_data].nil? + case self.attribute_field.markup + when 'text_field','text_area' + if self.attribute_field.add_more + self["val"] = self["temp_data"] + else # if not add_more + if self.attribute_field.can_muti_lang_input? + self[:temp_data].each do |key,val| + self[key] = val + end if(!self.attribute_field.get_data[:cross_lang]) + else + self["val"] = self[:temp_data] + end + end # of self.attribute_field.add_more + + when 'select','date','radio_button' + self["val"] = self[:temp_data] + when 'checkbox' + self["val"] = self[:temp_data].keys + end #end of case self.attribute_field.markup + end # of self[:temp_data].nil? + self.unset('temp_data') + self.unset('temp') + end #of data_proc + + def check_key + self.key = attribute_field.key + end + + def method_missing(*field) + if field.size < 1 + self[field[0]] + else + self[(field[0].to_s.delete "=")] = field[1] + end + end + + def get_date Date.new(self[:val]["(1i)"].to_i,self[:val]["(2i)"].to_i,self[:val]["(3i)"].to_i) rescue nil end diff --git a/app/views/admin/users_new_interface/_form.html.erb b/app/views/admin/users_new_interface/_form.html.erb index 48f06c84..76f304fa 100644 --- a/app/views/admin/users_new_interface/_form.html.erb +++ b/app/views/admin/users_new_interface/_form.html.erb @@ -17,53 +17,3 @@ <%= render :partial=>"infos"%> <%= render :partial=>"roles"%> - -<% content_for :page_specific_javascript do -%> - - -<% end -%> \ No newline at end of file diff --git a/app/views/admin/users_new_interface/edit.html.erb b/app/views/admin/users_new_interface/edit.html.erb index 1e169520..faf8bcef 100644 --- a/app/views/admin/users_new_interface/edit.html.erb +++ b/app/views/admin/users_new_interface/edit.html.erb @@ -11,6 +11,9 @@ <%= javascript_include_tag "/static/jquery.cycle.all.latest.js" %> <%= javascript_include_tag "inc/modal-preview" %> <%= javascript_include_tag "lib/contenteditable" %> + <%= javascript_include_tag "inc/ploy_input_field" %> + <%= javascript_include_tag "inc/input_module" %> + <% end -%> diff --git a/app/views/shared/_address_modal_dialog.html.erb b/app/views/shared/_address_modal_dialog.html.erb deleted file mode 100644 index 6e241074..00000000 --- a/app/views/shared/_address_modal_dialog.html.erb +++ /dev/null @@ -1,13 +0,0 @@ - \ No newline at end of file diff --git a/app/views/shared/attribute_field/_address_modal_dialog.html.erb b/app/views/shared/attribute_field/_address_modal_dialog.html.erb new file mode 100644 index 00000000..9c51ae27 --- /dev/null +++ b/app/views/shared/attribute_field/_address_modal_dialog.html.erb @@ -0,0 +1,61 @@ + \ No newline at end of file diff --git a/config/list.yml b/config/list.yml index ebfff364..bae7a90d 100644 --- a/config/list.yml +++ b/config/list.yml @@ -33,9 +33,9 @@ markups: # date_durnation: # muti_lang_input_supprt: false # ext_support: false - # address: - # muti_lang_input_supprt: true - # ext_support: true + address: + muti_lang_input_supprt: true + ext_support: true public_r_tags: diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index a1dee0a1..1573323b 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -158,8 +158,19 @@ zh_tw: user: 使用者列表 list_: 列表 list_lower: 列表 + address_modal: + default_title: 地址 + street_address: 街道地址 + city: 城市 + county: 縣市 + zip: 郵遞區號 + country: 國家/地區 + langs: + zh_tw: 中文 + en: 英文 lists: markups: + address: 地址欄位 text_field: 文字輸入框 select: 下拉選單 date: 日期 diff --git a/lib/orbit_basis.rb b/lib/orbit_basis.rb index 3e0ec976..0ab3939f 100644 --- a/lib/orbit_basis.rb +++ b/lib/orbit_basis.rb @@ -1,4 +1,11 @@ module OrbitBasis + module RenderAnywhere + def render_anywhere(partial,opts) + view = ActionView::Base.new(Orbit::Application.config.paths["app/views"].first) + view.extend ApplicationHelper + view.render(:partial => partial,:locals=>opts) + end + end module BaseModel extend ActiveSupport::Concern