complete address field. still have javascript issue for fill back and display address ext fields in modal.

This commit is contained in:
Matthew K. Fu JuYuan 2012-11-16 15:36:08 +08:00
parent 995bdbc86c
commit 3034e53423
7 changed files with 111 additions and 66 deletions

View File

@ -1,11 +1,15 @@
jQuery(document).ready(function($) { jQuery(document).ready(function($) {
// Stuff to do as soon as the DOM is ready. Use $() w/o colliding with other libs; // Stuff to do as soon as the DOM is ready. Use $() w/o colliding with other libs;
var current_textarea = {}; var current_textarea = {};
var parent = null;
var this_modal_window = null;
var lang = <%= VALID_LOCALES.to_s %>; var lang = <%= VALID_LOCALES.to_s %>;
$.each(lang,function(index,value){ $("textarea[func=input_unit]").each(function(){
current_textarea[value] = $("textarea[for="+value+"]").val(); var id = $(this).attr("id");
}); current_textarea[id] = $(this).val();
})
console.log(current_textarea);
// current_textarea['en'] = $("textarea[for=en]").val(); // current_textarea['en'] = $("textarea[for=en]").val();
// current_textarea['zh_tw'] = $("textarea[for=zh_tw]").val(); // current_textarea['zh_tw'] = $("textarea[for=zh_tw]").val();
@ -13,6 +17,9 @@ jQuery(document).ready(function($) {
$("div.controls").on("click","a.edit-btn",function(){ $("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"); 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").removeClass("active in");
$(this).parents(".editMore").find(".modal_tab[for="+choosen_lang+"]").addClass("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"); // $("#tab4").addClass("active in");
// $(".modal-body li").eq(1).addClass("active"); // $(".modal-body li").eq(1).addClass("active");
// break; // break;
});
$.each(lang,function(i,value){ $.each(lang,function(i,value){
// console.log(this_modal_window);
var sa = $(".tab-content input.street_address_"+lang[i]).val(); var sa = parent.find("input.street_address_"+lang[i]).val();
var city = $(".tab-content input.city_"+lang[i]).val(); var city = parent.find("input.city_"+lang[i]).val();
var county = $(".tab-content input.county_"+lang[i]).val(); var county = parent.find("input.county_"+lang[i]).val();
var zip = $(".tab-content input.zip_"+lang[i]).val(); var zip = parent.find("input.zip_"+lang[i]).val();
var country = $(".tab-content input.country_"+lang[i]).val(); var country = parent.find("input.country_"+lang[i]).val();
$(".modal-body").find('#street_address_'+lang[i]).val(sa) this_modal_window.find('.tab-content div[for='+lang[i]+'] textarea[func=street_address]').val(sa);
$(".modal-body").find('#city_'+lang[i]).val(city); this_modal_window.find('.tab-content div[for='+lang[i]+'] input[func=city]').val(city);
$(".modal-body").find('#counties_'+lang[i]).val(county); this_modal_window.find('.tab-content div[for='+lang[i]+'] input[func=county]').val(county);
$(".modal-body").find('#zip_'+lang[i]).val(zip); this_modal_window.find('.tab-content div[for='+lang[i]+'] input[func=zip]').val(zip);
$(".modal-body").find('#country_'+lang[i]).val(country); this_modal_window.find('.tab-content div[for='+lang[i]+'] input[func=country]').val(country);
var verify = sa + city + country +county + zip; var verify = sa + city + country +county + zip;
var combined = ""; var combined = "";
if(verify!="") if(verify!="")
combined = sa + "\n" + city + "\n" + county + "\n" + zip + "\n" + country; combined = sa + "\n" + city + "\n" + county + "\n" + zip + "\n" + country+"\n";
if($(".tab-content textarea[for="+lang[i]+"]").val() != combined){ var Text0 = parent.find("div."+lang[i]+" textarea[func=input_unit]").val();
$(".tab-content").find('#street_address_'+lang[i]).val($(".tab-content textarea[for="+lang[i]+"]").val()); Text1 = Text0.replace(/(\r\n|\n|\r)/gm,"");
$(".modal-body input").val(""); 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"); var lang = $(this).attr("for");
if(current_textarea[lang] != $(this).val()) if(!parent)
$("input.indicator_"+lang).val("true"); parent = $(this).parent().parent();
console.log(current_textarea[id]);
if(current_textarea[id] != $(this).val())
parent.find("input.indicator_"+lang).val("true");
else else
$("input.indicator_"+lang).val("false"); parent.find("input.indicator_"+lang).val("false");
}) })
$(".address-edit").on("hidden",function(){ $(".address-edit").on("hidden",function(){
@ -71,25 +87,24 @@ jQuery(document).ready(function($) {
}) })
$(".bt-save").click(function(){ $(".bt-save").click(function(){
var lang = <%= VALID_LOCALES.to_s %>;
for(i=0;i<2;i++){ for(i=0;i<2;i++){
var sa = $(".tab-content").find('#street_address_'+lang[i]).val(); var sa = this_modal_window.find('.tab-content div[for='+lang[i]+'] textarea[func=street_address]').val();
var city = $(".tab-content").find('#city_'+lang[i]).val(); var city = this_modal_window.find('.tab-content div[for='+lang[i]+'] input[func=city]').val();
var county = $(".tab-content").find('#counties_'+lang[i]).val(); var county = this_modal_window.find('.tab-content div[for='+lang[i]+'] input[func=county]').val();
var zip = $(".tab-content").find('#zip_'+lang[i]).val(); var zip = this_modal_window.find('.tab-content div[for='+lang[i]+'] input[func=zip]').val();
var country = $(".tab-content").find('#country_'+lang[i]).val(); var country = this_modal_window.find('.tab-content div[for='+lang[i]+'] input[func=country]').val();
$(".tab-content input.street_address_"+lang[i]).val(sa); parent.find("input.street_address_"+lang[i]).val(sa);
$(".tab-content input.city_"+lang[i]).val(city); parent.find("input.city_"+lang[i]).val(city);
$(".tab-content input.county_"+lang[i]).val(county); parent.find("input.county_"+lang[i]).val(county);
$(".tab-content input.zip_"+lang[i]).val(zip); parent.find("input.zip_"+lang[i]).val(zip);
$(".tab-content input.country_"+lang[i]).val(country); parent.find("input.country_"+lang[i]).val(country);
var verify = sa + city + country +county + zip; var verify = sa + city + country +county + zip;
var combined = ""; var combined = "";
if(verify!="") if(verify!="")
combined = sa + "\n" + city + "\n" + county + "\n" + zip + "\n" + country; combined = sa + "\n" + city + "\n" + county + "\n" + zip + "\n" + country;
$(".tab-content textarea[for="+lang[i]+"]").val(combined); parent.find("textarea[for="+lang[i]+"]").val(combined);
$("input.indicator_"+lang[i]).val("false"); parent.find("input.indicator_"+lang[i]).val("false");
current_textarea[lang[i]] = combined; current_textarea[parent.find("textarea[for="+lang[i]+"]").attr("id")] = combined;
} }
}) })

View File

@ -20,14 +20,15 @@
$modalNumber+=1; $modalNumber+=1;
var $CloneTarget = $(this).parents(".controls").prev(".multipleInput").children('.controls:last'); var $CloneTarget = $(this).parents(".controls").prev(".multipleInput").children('.controls:last');
$(this).parents(".controls").prev(".multipleInput").append($CloneTarget.clone()); $(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 input').val("");
$(this).parents(".controls").prev(".multipleInput").children('.controls:last').find('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") btn = $(this).parents(".controls").prev(".multipleInput").children('.controls:last').find(".nav.nav-pills li")
$.each(btn,function(i,value){ $.each(btn,function(i,value){
old_link = $(this).children("a").attr("href"); old_link = $(this).children("a").attr("href");
$(this).children("a").attr("href",old_link+".NewInput_"+$modalNumber); $(this).children("a").attr("href",".NewInput_"+$modalNumber);
}); });
removeInput(); removeInput();
checkMultipleInput(); checkMultipleInput();

View File

@ -102,6 +102,7 @@ class Admin::UsersNewInterfaceController < ApplicationController
end end
def update def update
binding.pry
@user = User.find(params[:id]) @user = User.find(params[:id])
@user.update_attributes(params[:user]) @user.update_attributes(params[:user])

View File

@ -34,11 +34,14 @@ module AttributeFieldsHelper
place_holder= @panel_setting["placeholder"][key] rescue '' 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 = 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}") add_ext= @attribute_value.address_ext[key] rescue {}
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+"[address_ext][#{key}][county]",add_ext["county"],:class=>"county_#{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+"[address_ext][#{key}][street_address]",add_ext["street_address"],:class=>"street_address_#{key}")
result << hidden_field_tag(get_basic_field_name_base+"[temp][indicator][#{key}]",nil,:class=>"indicator_#{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
end end
@ -124,7 +127,7 @@ protected
VALID_LOCALES.each.collect do |key| 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 = 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 = [".#{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 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) 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 end.join.html_safe # of VALID_LOCALES.collect for tabs
@ -170,9 +173,11 @@ protected
case self.markup case self.markup
when "text_field" when "text_field"
if can_add_more 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| @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.join("\n").html_safe # of add_more fields
end # of div multipleInput editMore end # of div multipleInput editMore
result = label + multipleInputs + add_more_unt result = label + multipleInputs + add_more_unt
@ -267,7 +272,13 @@ protected
end end
def gen_modal_dialog 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
end end

View File

@ -5,6 +5,8 @@ class AttributeValue
include AttributeValuesHelper include AttributeValuesHelper
field :key field :key
field :address_ext
belongs_to :attribute_field belongs_to :attribute_field
belongs_to :user belongs_to :user
@ -28,7 +30,7 @@ class AttributeValue
else else
self.attribute_field.get_data["cross_lang"] =="true" ? 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 end
when 'select','date','radio_button' when 'select','date','radio_button','address'
self["val"] self["val"]
when 'checkbox' when 'checkbox'
self["val"] self["val"]
@ -46,28 +48,36 @@ class AttributeValue
case self.attribute_field.markup case self.attribute_field.markup
when "text_field" when "text_field"
case self.attribute_field.add_more case self.attribute_field.add_more
when true when true
add_more_index.nil? ? self.value.collect{|t| t[locale]}.join(",") : self.value(add_more_index)[locale] add_more_index.nil? ? self.value.collect{|t| t[locale]}.join(",") : self.value(add_more_index)[locale]
when false when false
self.attribute_field.locale ? self[locale.to_s] : self.value self.attribute_field.locale ? self[locale.to_s] : self.value
end end
when "select" when "select"
markup_values = self.attribute_field.self_defined_markup_options? ? self.attribute_field.markup_value : self.attribute_field.markup_value 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' markup_values[self.value][locale.to_s] rescue 'NoData'
when "text_area" when "text_area"
self.attribute_field.locale ? self[locale.to_s] : self.value self.attribute_field.locale ? self[locale.to_s] : self.value
when "date" when "date"
get_date_by_format get_date_by_format
when "addr"
self.value when "address"
self.value[locale.to_s]
when "radio_button" when "radio_button"
markup_values = self.attribute_field.markup_value markup_values = self.attribute_field.markup_value
markup_values[self.value][locale.to_s] markup_values[self.value][locale.to_s]
when "checkbox" when "checkbox"
markup_values = self.attribute_field.markup_value markup_values = self.attribute_field.markup_value
self.value.collect{|key| markup_values[key][locale.to_s]}.join(",") self.value.collect{|key| markup_values[key][locale.to_s]}.join(",")
when "date_durnation" when "date_durnation"
self.value self.value
else else
self.attribute_field.locale ? self[locale.to_s] : self.value self.attribute_field.locale ? self[locale.to_s] : self.value
end end
@ -83,6 +93,8 @@ def unset_all_lang_values
def data_proc def data_proc
unless self[:temp_data].nil? unless self[:temp_data].nil?
case self.attribute_field.markup case self.attribute_field.markup
when "address"
binding.pry
when 'text_field','text_area' when 'text_field','text_area'
if self.attribute_field.add_more if self.attribute_field.add_more
self["val"] = self["temp_data"] self["val"] = self["temp_data"]

View File

@ -11,10 +11,14 @@
<%= javascript_include_tag "/static/jquery.cycle.all.latest.js" %> <%= javascript_include_tag "/static/jquery.cycle.all.latest.js" %>
<%= javascript_include_tag "inc/modal-preview" %> <%= javascript_include_tag "inc/modal-preview" %>
<%= javascript_include_tag "lib/contenteditable" %> <%= 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 -%> <% 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| %> <%= form_for @user, :url => admin_users_new_interface_index_path, :html => { :multipart => true },:method => :post do |f| %>
<%= f.error_messages %> <%= f.error_messages %>

View File

@ -21,31 +21,32 @@
<div class="control-group"> <div class="control-group">
<label class="control-label" for="street_address"><%= t("address_modal.street_address") %></label> <label class="control-label" for="street_address"><%= t("address_modal.street_address") %></label>
<div class="controls"> <div class="controls">
<%= text_area_tag("#{btn_class}_street_address_#{locale}",nil,:rows=>3,:func=>'street_address') %>
<%= text_area_tag("#{field_name_basic}[temp][address_ext][#{locale}][street_address]",nil,:rows=>3,:func=>'street_address') %>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="city"><%= t("address_modal.city") %></label> <label class="control-label" for="city"><%= t("address_modal.city") %></label>
<div class="controls"> <div class="controls">
<%= text_field_tag("#{btn_class}_city_#{locale}",'',:func=>'city') %> <%= text_field_tag("#{field_name_basic}[temp][address_ext][#{locale}][city]",'',:func=>'city') %>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="counties"><%= t("address_modal.county") %></label> <label class="control-label" for="counties"><%= t("address_modal.county") %></label>
<div class="controls"> <div class="controls">
<%= text_field_tag("#{btn_class}_county_#{locale}",'',:func=>'county') %> <%= text_field_tag("#{field_name_basic}[temp][address_ext][#{locale}][county]",'',:func=>'county') %>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="zip"><%= t("address_modal.zip") %></label> <label class="control-label" for="zip"><%= t("address_modal.zip") %></label>
<div class="controls"> <div class="controls">
<%= text_field_tag("#{btn_class}_zip_#{locale}",nil,:class=>"input-mini",:func=>'zip') %> <%= text_field_tag("#{field_name_basic}[temp][address_ext][#{locale}][zip]",nil,:class=>"input-mini",:func=>'zip') %>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="country"><%= t("address_modal.country") %></label> <label class="control-label" for="country"><%= t("address_modal.country") %></label>
<div class="controls"> <div class="controls">
<%= text_field_tag("#{btn_class}_country_#{locale}",'',:func=>'country') %> <%= text_field_tag("#{field_name_basic}[temp][address_ext][#{locale}][country]",'',:func=>'country') %>
</div> </div>
</div> </div>
</div> </div>