This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/assets/javascripts/inc/input_module.js.erb

98 lines
3.9 KiB
Plaintext

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 lang = <%= VALID_LOCALES.to_s %>;
$.each(lang,function(index,value){
current_textarea[value] = $("textarea[for="+value+"]").val();
});
// current_textarea['en'] = $("textarea[for=en]").val();
// current_textarea['zh_tw'] = $("textarea[for=zh_tw]").val();
$("div.controls").on("click","a.edit-btn",function(){
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");
$(this).parents(".editMore").find(".modal-body li").removeClass("active");
$(this).parents(".editMore").find(".modal-body li[for="+choosen_lang+"]").addClass("active");
// 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;
});
$.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);
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 = <%= 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 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;
}
})
});