address field and text field convert

This commit is contained in:
Matthew K. Fu JuYuan 2012-11-15 17:23:39 +08:00 committed by chris
parent a85e5fcc0d
commit 17988f2fb2
10 changed files with 217 additions and 116 deletions

View File

@ -0,0 +1,33 @@
function checkSwitch() {
$(".groups").each(function() {
$(this).find('.form-horizontal > .hide').length < $(this).find('.form-horizontal > div').length ? $(this).removeClass("disabled") : $(this).addClass("disabled")
});
// $(".groups").addClass('disabled').has('.groups > .form-horizontal > div:not(.hide)').removeClass('disabled');
}
$(document).ready(function(){
checkSwitch();
$('.onoff').click(function () {
if($(this).parents("h4").length==1) {
$(this).parents(".map-block").toggleClass("disabled");
$(this).parents(".map-block").find(".form-horizontal").toggleClass("hide");
if($(this).parents(".map-block").hasClass("disabled")){
$(this).text("OFF");
}else{
$(this).text("ON");
}
}
if($(this).parents("legend").length==1) {
$(this).toggleClass("disabled");
$(this).parents("legend").next("div").toggleClass("hide");
if($(this).parents("legend").next("div").hasClass("hide")){
$(this).text("OFF");
}else{
$(this).text("ON");
}
checkSwitch();
}
return false;
});
});

View File

@ -0,0 +1,15 @@
$(document).ready(function(){
$(".status select").each(function (i) {
$(this).change(function () {
$(".status option:selected").eq(i).each(function () {
if($(this).attr("value")=="alumna") {
$(this).parents(".status").nextAll(".graduated").removeClass("hide");
$(this).parents(".status").nextAll(".graduated").find("select").removeAttr("disabled");
}else{
$(this).parents(".status").nextAll(".graduated").addClass("hide");
$(this).parents(".status").nextAll(".graduated").find("select").attr({disabled:''});
}
});
})
})
});

View File

@ -1,21 +1,38 @@
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();
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(){
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++){
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();
@ -36,8 +53,8 @@ jQuery(document).ready(function($) {
$(".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())
@ -54,7 +71,7 @@ jQuery(document).ready(function($) {
})
$(".bt-save").click(function(){
var lang = ["en","zh_tw"];
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();

View File

@ -1,3 +1,5 @@
// var $CloneTarget ;
function checkMultipleInput() {
$(".multipleInput").each(function() {
$(this).children('.controls').length==1 ? $(this).addClass("plural") : $(this).removeClass("plural")
@ -18,7 +20,15 @@
$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("");
// $(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)
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);
});
removeInput();
checkMultipleInput();
return false;

View File

@ -8,6 +8,8 @@ class ApplicationController < ActionController::Base
helper :admin
before_filter :set_locale, :set_site
helper_attr :site_valid_locales
def set_current_user
User.current = current_or_guest_user
end

View File

@ -5,7 +5,9 @@ module AttributeFieldsHelper
include ActionView::Helpers::DateHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::RenderingHelper
include ActionView::Context
include OrbitBasis::RenderAnywhere
def block_helper(user,index,disable = false)
unless self.disabled
@index = index
@ -30,7 +32,7 @@ module AttributeFieldsHelper
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 = 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}")
@ -54,7 +56,7 @@ module AttributeFieldsHelper
end
def render_date_durnation #Need re-write low priority
end
def render_radio_button
@ -82,100 +84,131 @@ module AttributeFieldsHelper
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
control_group_wrapper do |key,value|
add_more_blank = can_add_more ? "[]" : ""
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
text_field_tag([get_field_name_base,add_more_blank,key_field].join, value,@markup_options.merge(:placeholder=>place_holder))
end
end
protected
def lang_panel_control_wrapper(&block)
result = '<div class="tabbable">'
result << '<div class="tab-content">'
result << controls_wrapper{yield}
result << '</div>'
result << '</div>'
result.html_safe
def lang_panel_tabbable_wrapper(add_more_params,&block)
add_more_counter = ''
content_tag :div,:class=>"tabbable" do
tmp = content_tag :div,:class=> (add_more || self.markup=='address') ? "tab-content input-append" : "tab-content" do
buff = VALID_LOCALES.collect do |key|
value = @prefiled_value[key] rescue nil
div_class_ary = ["tab-pane" ,"fade",key,get_pairing_tab_class({})]
if can_add_more
add_more_value = add_more_params[0][:value]
add_more_counter = add_more_params[0][:counter]
value = add_more_value[key] rescue nil
div_class_ary << "add_more_item_#{add_more_counter}"
end
div_class = div_class_ary.join(" ")
div_class << (key == I18n.locale.to_s ? " active in" : '')
content_tag(:div,yield(key,value),:class=>div_class)
end# of VALID_LOCALES.collect for tabed input
buff << link_to((content_tag :i,'',:class=>'icon-edit'),"##{get_pairing_tab_class({})}_m_window",:class=>'btn edit-btn',:type=>'button',:data=>{:toggle=>"modal"}) if self.markup == 'address'
buff << link_to((content_tag :i,'',:class=>'icon-trash'),"#") if self.add_more
# buff << '<a href="#" class="btn removeInput" type="button"><i class="icon-trash"></i></a>' if self.add_more
buff.join("\n").html_safe
end
tmp << content_tag(:ul,:class=> 'nav nav-pills') do
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 = 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
end # of content ul
end
end
def controls_wrapper(&block)
loop_time = self.add_more ? @attribute_value.add_more_counter : 1
result = ''
multi_and_edit_more_class = (self.markup == 'address' ? "multipleInput" : "multipleInput editMore" )
result << "<div class='#{multi_and_edit_more_class}'>" if self.add_more
result << "<div class='controls'>"
loop_time.times do |loop_counter|
if can_muti_lang_input?
result << "<div class='tabbable'>"
tab_content_class = add_more ? "tab-content input-append" : "tab-content"
def controls_wrapper(*add_more_params,&block)
content_tag :div,:class=>'controls' do
result = ''
add_more_counter = ""
result << "<div class= '#{tab_content_class}'>"
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 << " #{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 << '<a href=".address-edit.' + get_pairing_tab_class({}) + ' " class="btn edit-btn" type="button" data-toggle="modal"><i class="icon-edit"></i></a>' if self.markup == 'address'
result << '<a href="#" class="btn removeInput" type="button"><i class="icon-trash"></i></a>' if self.add_more
result << "</div>"
if can_muti_lang_input?
result << "<ul class='nav nav-pills'>"
VALID_LOCALES.reverse.each do |key|
link_entry = self.add_more ? "#{add_more_tab(:tab_btn,loop_counter,key)}" : "#tab"+id.to_s+"_#{key}"
result << content_tag(:li,link_to(I18n.t("langs."+key),link_entry,:data=>{:toggle=>"tab"}),:class=>(key == I18n.locale.to_s ? "active" : nil))
end # of VALID_LOCALES.collect for tabs
result << "</ul>"
if can_add_more
add_more_counter = add_more_params[0][:counter]
add_more_value = add_more_params[0][:value]
end
result << "</div>"
if can_muti_lang_input?
result << lang_panel_tabbable_wrapper(add_more_params,&block)
result << gen_modal_dialog if self.markup == "address"
else
value = case can_add_more
when true
add_more_params[0]
else
@prefiled_value
end
result << yield
result << yield(nil,value)
end
if can_add_more and (loop_counter == loop_time-1)
temp_field_name = get_basic_field_name_base + '[temp]'
result << '<div class="controls">'
result << '<span class="help-block">'
result << '<a href="#" class="addinput"><i class="icon-plus-sign"></i>'+I18n.t("admin.infos.add")+' </a>'
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 << '</span>'
result << '</div>'
end
end # of loop_time
result << "</div>"
result << "</div>" if self.add_more
result.html_safe
result.html_safe
end # of controls div
end # of def controls_wrapper(&block)
def control_group_wrapper(&block)
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
result =""
case self.markup
when "text_field"
if can_add_more
multipleInputs = content_tag :div,:class=>"multipleInput editMore" do
@attribute_value.add_more_counter.times.collect do |t|
controls_wrapper(:value=>@prefiled_value[t],:counter=>t,&block)
end.join("\n").html_safe # of add_more fields
end # of div multipleInput editMore
result = label + multipleInputs + add_more_unt
# result = label + 一堆的輸入框(要用 multipleInput editMore 包起來) + add_more btn + hidden_fields
else
temp = label + controls_wrapper(&block)
result = content_tag(:div,temp,:class=>div_class)
end
when "address"
address = content_tag :div,:class=>"multipleInput editMore" do
controls_wrapper(&block)
end # of div multipleInput editMore
result = label + address
else
temp = label + controls_wrapper(&block)
result = content_tag(:div,temp,:class=>div_class)
end
result << end_block
result.html_safe
end
def add_more_unt
temp_field_name = get_basic_field_name_base + '[temp]'
add_more = content_tag :div,:class=> 'controls' do
content_tag :span,:class=> 'help-block' do
content = link_to (content_tag :i,I18n.t("admin.infos.add"),:class=>"icon-plus-sign"),"#",:class=>'addinput'
content << hidden_field_tag("#{temp_field_name}[count]",@attribute_value.add_more_counter ,:class=>"list_count")
content << hidden_field_tag("#{temp_field_name}[count]",get_basic_field_name_base,:class=>"field_name")
content
end # of span
end # of div
end
def end_block
if @new_attribute
hidden_field_tag(get_basic_field_name_base+"[attribute_field_id]",id,:for=>"field_#{@index}")
@ -233,10 +266,8 @@ protected
end
end
def gen_modal_dialog
render_anywhere("shared/attribute_field/address_modal_dialog",{:field_name=>title,:btn_class => "#{get_pairing_tab_class({})}"})
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({})}"})
end
end

View File

@ -149,7 +149,7 @@ protected
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} }
av["val"] = av["val"].collect{|t| {default_locale => t} } #unless av["val"].nil?
else
av[default_locale] = av["val"]
av.unset("val")

View File

@ -42,14 +42,6 @@
var NewNode;
$(document).ready(function(){
// function mas(){
// $('.site-map').masonry({
// itemSelector: '.map-block',
// columnWidth: 450,
// isAnimated: true
// });
// }
function checkSwitch() {
$(".groups").addClass('disabled').has('.groups > .form-horizontal > div:not(.hide)').removeClass('disabled');
}

View File

@ -13,7 +13,8 @@
<%= 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 -%>

View File

@ -1,4 +1,4 @@
<div class="modal hide fade address-edit <%= btn_class %>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal hide fade address-edit <%= btn_class %>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id=<%= html_id%>>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel"><%= (field_name rescue nil) || t("address_modal.default_title") %></h3>
@ -7,8 +7,8 @@
<div class="tabbable">
<ul class="nav nav-tabs">
<% VALID_LOCALES.each do |locale|%>
<% active = (locale == VALID_LOCALES.first ? "active" : nil ) %>
<%= content_tag :i,:class=>active do%>
<% active = (locale == I18n.locale.to_s ? ["active"] : [] ) %>
<%= content_tag :li,:class=>active.push("modal_tab","address_tab").join(' '),:for=>locale do%>
<%= link_to t("langs.#{locale}"),".#{btn_class}.address_modal.#{locale}",:data=>{:toggle=>"tab"}%>
<% end %>
<% end %>
@ -16,36 +16,36 @@
<div class="tab-content">
<% VALID_LOCALES.each do |locale|%>
<!-- start of lang tab context -->
<% active = (locale == VALID_LOCALES.first ? "active" : "" ) %>
<% active = (locale == I18n.locale.to_s ? "active" : "" ) %>
<div class="tab-pane <%= active %> fade in <%= "#{btn_class} address_modal #{locale}" %>" for="<%= locale %>">
<div class="control-group">
<label class="control-label" for="street_address"><%= t("address_modal.street_address") %></label>
<div class="controls">
<%= text_area_tag("#{btn_class}_street_address_#{locale}",nil,:rows=>3) %>
<%= text_area_tag("#{btn_class}_street_address_#{locale}",nil,:rows=>3,:func=>'street_address') %>
</div>
</div>
<div class="control-group">
<label class="control-label" for="city"><%= t("address_modal.city") %></label>
<div class="controls">
<%= text_field_tag("#{btn_class}_city_#{locale}") %>
<%= text_field_tag("#{btn_class}_city_#{locale}",'',:func=>'city') %>
</div>
</div>
<div class="control-group">
<label class="control-label" for="counties"><%= t("address_modal.county") %></label>
<div class="controls">
<%= text_field_tag("#{btn_class}_county_#{locale}") %>
<%= text_field_tag("#{btn_class}_county_#{locale}",'',:func=>'county') %>
</div>
</div>
<div class="control-group">
<label class="control-label" for="zip"><%= t("address_modal.zip") %></label>
<div class="controls">
<%= text_field_tag("#{btn_class}_zip_#{locale}",nil,:class=>"input-mini") %>
<%= text_field_tag("#{btn_class}_zip_#{locale}",nil,:class=>"input-mini",:func=>'zip') %>
</div>
</div>
<div class="control-group">
<label class="control-label" for="country"><%= t("address_modal.country") %></label>
<div class="controls">
<%= text_field_tag("#{btn_class}_country_#{locale}") %>
<%= text_field_tag("#{btn_class}_country_#{locale}",'',:func=>'country') %>
</div>
</div>
</div>