diff --git a/app/assets/javascripts/inc/input_module.js.erb b/app/assets/javascripts/inc/input_module.js.erb index 944d935a..5ac7b056 100644 --- a/app/assets/javascripts/inc/input_module.js.erb +++ b/app/assets/javascripts/inc/input_module.js.erb @@ -1,18 +1,25 @@ jQuery(document).ready(function($) { // Stuff to do as soon as the DOM is ready. Use $() w/o colliding with other libs; var current_textarea = {}; + var parent = null; + var this_modal_window = null; var lang = <%= VALID_LOCALES.to_s %>; - $.each(lang,function(index,value){ - current_textarea[value] = $("textarea[for="+value+"]").val(); - }); +$("textarea[func=input_unit]").each(function(){ + var id = $(this).attr("id"); + current_textarea[id] = $(this).val(); +}) +console.log(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(){ + parent = $(this).parent(); + this_modal_window = $(this).parent().parent().parent().parent().find(".modal"); + choosen_lang = $(this).parent().parent().find("ul li.active").attr("for"); $(this).parents(".editMore").find(".modal_tab").removeClass("active in"); $(this).parents(".editMore").find(".modal_tab[for="+choosen_lang+"]").addClass("active in"); @@ -29,38 +36,47 @@ jQuery(document).ready(function($) { // $("#tab4").addClass("active in"); // $(".modal-body li").eq(1).addClass("active"); // break; - }); - + $.each(lang,function(i,value){ - - 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); + // console.log(this_modal_window); + var sa = parent.find("input.street_address_"+lang[i]).val(); + var city = parent.find("input.city_"+lang[i]).val(); + var county = parent.find("input.county_"+lang[i]).val(); + var zip = parent.find("input.zip_"+lang[i]).val(); + var country = parent.find("input.country_"+lang[i]).val(); + this_modal_window.find('.tab-content div[for='+lang[i]+'] textarea[func=street_address]').val(sa); + this_modal_window.find('.tab-content div[for='+lang[i]+'] input[func=city]').val(city); + this_modal_window.find('.tab-content div[for='+lang[i]+'] input[func=county]').val(county); + this_modal_window.find('.tab-content div[for='+lang[i]+'] input[func=zip]').val(zip); + this_modal_window.find('.tab-content div[for='+lang[i]+'] input[func=country]').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(""); + combined = sa + "\n" + city + "\n" + county + "\n" + zip + "\n" + country+"\n"; + + var Text0 = parent.find("div."+lang[i]+" textarea[func=input_unit]").val(); + Text1 = Text0.replace(/(\r\n|\n|\r)/gm,""); + var Text2 = combined; + Text2 = Text2.replace(/(\r\n|\n|\r)/gm,""); + + if(Text1 != Text2){ + this_modal_window.find('.tab-content div[for='+lang[i]+'] textarea[func=street_address]').val(Text0); + this_modal_window.find("input").val(""); } }); - - $("textarea.dummy").change(function(){ + }); + $("textarea[func=input_unit]").change(function(){ + var id = $(this).attr("id"); var lang = $(this).attr("for"); - if(current_textarea[lang] != $(this).val()) - $("input.indicator_"+lang).val("true"); + if(!parent) + parent = $(this).parent().parent(); + console.log(current_textarea[id]); + if(current_textarea[id] != $(this).val()) + parent.find("input.indicator_"+lang).val("true"); else - $("input.indicator_"+lang).val("false"); + parent.find("input.indicator_"+lang).val("false"); }) $(".address-edit").on("hidden",function(){ @@ -71,25 +87,24 @@ jQuery(document).ready(function($) { }) $(".bt-save").click(function(){ - var lang = <%= VALID_LOCALES.to_s %>; 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 sa = this_modal_window.find('.tab-content div[for='+lang[i]+'] textarea[func=street_address]').val(); + var city = this_modal_window.find('.tab-content div[for='+lang[i]+'] input[func=city]').val(); + var county = this_modal_window.find('.tab-content div[for='+lang[i]+'] input[func=county]').val(); + var zip = this_modal_window.find('.tab-content div[for='+lang[i]+'] input[func=zip]').val(); + var country = this_modal_window.find('.tab-content div[for='+lang[i]+'] input[func=country]').val(); + parent.find("input.street_address_"+lang[i]).val(sa); + parent.find("input.city_"+lang[i]).val(city); + parent.find("input.county_"+lang[i]).val(county); + parent.find("input.zip_"+lang[i]).val(zip); + parent.find("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; + parent.find("textarea[for="+lang[i]+"]").val(combined); + parent.find("input.indicator_"+lang[i]).val("false"); + current_textarea[parent.find("textarea[for="+lang[i]+"]").attr("id")] = combined; } }) diff --git a/app/assets/javascripts/inc/ploy_input_field.js b/app/assets/javascripts/inc/ploy_input_field.js index d3369114..3799c64c 100644 --- a/app/assets/javascripts/inc/ploy_input_field.js +++ b/app/assets/javascripts/inc/ploy_input_field.js @@ -20,14 +20,15 @@ $modalNumber+=1; var $CloneTarget = $(this).parents(".controls").prev(".multipleInput").children('.controls:last'); $(this).parents(".controls").prev(".multipleInput").append($CloneTarget.clone()); - + class_to_be_removed = $(this).parents(".controls").prev(".multipleInput").attr("ext_class") // $(this).parents(".controls").prev(".multipleInput").children('.controls:last input').val(""); $(this).parents(".controls").prev(".multipleInput").children('.controls:last').find('input').val('') - $(this).parents(".controls").prev(".multipleInput").children('.controls:last').find('.tab-pane').addClass("NewInput_"+$modalNumber) + + $(this).parents(".controls").prev(".multipleInput").children('.controls:last').find('.tab-pane').removeClass(class_to_be_removed).addClass("NewInput_"+$modalNumber) btn = $(this).parents(".controls").prev(".multipleInput").children('.controls:last').find(".nav.nav-pills li") $.each(btn,function(i,value){ old_link = $(this).children("a").attr("href"); - $(this).children("a").attr("href",old_link+".NewInput_"+$modalNumber); + $(this).children("a").attr("href",".NewInput_"+$modalNumber); }); removeInput(); checkMultipleInput(); diff --git a/app/controllers/admin/users_new_interface_controller.rb b/app/controllers/admin/users_new_interface_controller.rb index 8c5ec93a..01f44016 100644 --- a/app/controllers/admin/users_new_interface_controller.rb +++ b/app/controllers/admin/users_new_interface_controller.rb @@ -102,6 +102,7 @@ class Admin::UsersNewInterfaceController < ApplicationController end def update + binding.pry @user = User.find(params[:id]) @user.update_attributes(params[:user]) diff --git a/app/helpers/attribute_fields_helper.rb b/app/helpers/attribute_fields_helper.rb index f7763c36..ded899ad 100644 --- a/app/helpers/attribute_fields_helper.rb +++ b/app/helpers/attribute_fields_helper.rb @@ -34,11 +34,14 @@ module AttributeFieldsHelper place_holder= @panel_setting["placeholder"][key] rescue '' result = text_area_tag(get_field_name_base + key_field, value,@markup_options.merge({:placeholder=>place_holder,:for=>key})) - 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}") + add_ext= @attribute_value.address_ext[key] rescue {} + + result << hidden_field_tag(get_basic_field_name_base+"[address_ext][#{key}][county]",add_ext["county"],:class=>"county_#{key}") + result << hidden_field_tag(get_basic_field_name_base+"[address_ext][#{key}][street_address]",add_ext["street_address"],:class=>"street_address_#{key}") + result << hidden_field_tag(get_basic_field_name_base+"[address_ext][#{key}][city]",add_ext["city"],:class=>"city_#{key}") + result << hidden_field_tag(get_basic_field_name_base+"[address_ext][#{key}][zip]",add_ext["zip"],:class=>"zip_#{key}") + result << hidden_field_tag(get_basic_field_name_base+"[address_ext][#{key}][country]",add_ext["country"],:class=>"country_#{key}") + result << hidden_field_tag(get_basic_field_name_base+"[address_ext][#{key}][indicator]",add_ext["indicator"],:class=>"indicator_#{key}") end end @@ -124,7 +127,7 @@ protected VALID_LOCALES.each.collect do |key| # link_entry = self.add_more ? "#{add_more_tab(:tab_btn,loop_counter,key)}" : "#tab"+id.to_s+"_#{key}" link_entry_ary = [".#{get_pairing_tab_class({})}",".#{key}"] - link_entry_ary << ".add_more_item_#{add_more_counter}" if can_add_more + # link_entry_ary << ".add_more_item_#{add_more_counter}" if can_add_more link_entry = link_entry_ary.join content_tag(:li,link_to(I18n.t("langs."+key),link_entry,:data=>{:toggle=>"tab"}),:class=>(key == I18n.locale.to_s ? "active" : nil),:for=>key) end.join.html_safe # of VALID_LOCALES.collect for tabs @@ -170,9 +173,11 @@ protected case self.markup when "text_field" if can_add_more - multipleInputs = content_tag :div,:class=>"multipleInput editMore" do + multipleInput_ary = %w{multipleInput editMore} + add_more_seri = "add_more_group_#{id}" + multipleInputs = content_tag :div,:class=> multipleInput_ary.join(' ') ,:ext_class=>get_pairing_tab_class({}) do @attribute_value.add_more_counter.times.collect do |t| - controls_wrapper(:value=>@prefiled_value[t],:counter=>t,&block) + controls_wrapper(:value=>(@prefiled_value[t] rescue nil),:counter=>t,&block) end.join("\n").html_safe # of add_more fields end # of div multipleInput editMore result = label + multipleInputs + add_more_unt @@ -267,7 +272,13 @@ protected end def gen_modal_dialog - render_anywhere("shared/attribute_field/address_modal_dialog",{:field_name=>title,:html_id=>"#{get_pairing_tab_class({})}_m_window",:btn_class => "#{get_pairing_tab_class({})}"}) + render_anywhere("shared/attribute_field/address_modal_dialog",{ + :field_name=>title, + :html_id=>"#{get_pairing_tab_class({})}_m_window", + :btn_class => "#{get_pairing_tab_class({})}", + :field_name_basic => get_basic_field_name_base + } + ) end end \ No newline at end of file diff --git a/app/models/user/attribute_value.rb b/app/models/user/attribute_value.rb index 16ab50f8..e335451a 100644 --- a/app/models/user/attribute_value.rb +++ b/app/models/user/attribute_value.rb @@ -5,6 +5,8 @@ class AttributeValue include AttributeValuesHelper field :key + field :address_ext + belongs_to :attribute_field belongs_to :user @@ -28,7 +30,7 @@ class AttributeValue else 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' + when 'select','date','radio_button','address' self["val"] when 'checkbox' self["val"] @@ -46,28 +48,36 @@ class AttributeValue case self.attribute_field.markup when "text_field" case self.attribute_field.add_more - when true - add_more_index.nil? ? self.value.collect{|t| t[locale]}.join(",") : self.value(add_more_index)[locale] - when false - self.attribute_field.locale ? self[locale.to_s] : self.value + when true + add_more_index.nil? ? self.value.collect{|t| t[locale]}.join(",") : self.value(add_more_index)[locale] + when false + self.attribute_field.locale ? self[locale.to_s] : self.value end + when "select" markup_values = self.attribute_field.self_defined_markup_options? ? self.attribute_field.markup_value : self.attribute_field.markup_value markup_values[self.value][locale.to_s] rescue 'NoData' + when "text_area" self.attribute_field.locale ? self[locale.to_s] : self.value + when "date" get_date_by_format - when "addr" - self.value + + when "address" + self.value[locale.to_s] + when "radio_button" markup_values = self.attribute_field.markup_value markup_values[self.value][locale.to_s] + when "checkbox" markup_values = self.attribute_field.markup_value self.value.collect{|key| markup_values[key][locale.to_s]}.join(",") + when "date_durnation" self.value + else self.attribute_field.locale ? self[locale.to_s] : self.value end @@ -83,6 +93,8 @@ def unset_all_lang_values def data_proc unless self[:temp_data].nil? case self.attribute_field.markup + when "address" + binding.pry when 'text_field','text_area' if self.attribute_field.add_more self["val"] = self["temp_data"] diff --git a/app/views/admin/users_new_interface/new.html.erb b/app/views/admin/users_new_interface/new.html.erb index 3e9bfc77..108e9a08 100644 --- a/app/views/admin/users_new_interface/new.html.erb +++ b/app/views/admin/users_new_interface/new.html.erb @@ -11,10 +11,14 @@ <%= 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" %> + <%= javascript_include_tag "inc/attribute_panel_select" %> + <%= javascript_include_tag "inc/attribute_onoff" %> <% end -%> -<%= content_tag :div,:class=>"user-role site-map" do%> +<%= content_tag :div,:class=>"user-role site-map role-block" do%> <%= form_for @user, :url => admin_users_new_interface_index_path, :html => { :multipart => true },:method => :post do |f| %> <%= f.error_messages %> diff --git a/app/views/shared/attribute_field/_address_modal_dialog.html.erb b/app/views/shared/attribute_field/_address_modal_dialog.html.erb index 482b774d..31063d43 100644 --- a/app/views/shared/attribute_field/_address_modal_dialog.html.erb +++ b/app/views/shared/attribute_field/_address_modal_dialog.html.erb @@ -21,31 +21,32 @@