address field. js and style is broken

This commit is contained in:
Matthew K. Fu JuYuan 2012-11-12 10:41:41 +08:00
parent dafe28ffb5
commit 39612b879c
14 changed files with 383 additions and 311 deletions

View File

@ -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;
}
})
});

View File

@ -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;
})
});

View File

@ -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;
}
.language-swich .tab-pane {
margin-bottom: 5px;
margin-right: 10px;
.input-append > .active {
display: inline-block;
}
.input-append .active {
background-color: transparent;
border-color: transparent;
}
.language-swich .tab-pane {
/*margin-bottom: 5px;*/
}

View File

@ -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 {

View File

@ -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 = '<div class="input-append">'.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 << ('<a href="#'+self.key+'-edit" class="btn" type="button" data-toggle="modal"><i class="icon-edit"></i></a>').html_safe
result << '<a href="#" class="btn" type="button"><i class="icon-trash"></i></a>'.html_safe
result << '</div>'.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 << "<div class='multipleInput'>" if self.add_more
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'>"
result << "<div class='tab-content'>"
if can_muti_lang_input?
result << "<div class='tabbable'>"
tab_content_class = add_more ? "tab-content input-append" : "tab-content"
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 << " 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 << '<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.each do |key|
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>"
end
result << "</div>"
# @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 << '<div class="controls">'
result << '<span class="help-block">'
result << '<a href="#"><i class="icon-plus-sign"></i>'+I18n.t("admin.infos.add")+' </a>'
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>"
@ -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
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 = '<div class="modal hide fade" id="address-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none; ">'
result << '<div class="modal-header">'
result << '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>'
result << '<h3 id="myModalLabel">'+title+'</h3>'
result << '</div>'
result << '<div class="modal-body">'
result << '<p>One fine body…</p>'
result << '</div>'
result << '<div class="modal-footer">'
result << '<button class="btn" data-dismiss="modal" aria-hidden="true">'+I18n.t("modal.close")+'</button>'
result << '<button class="btn btn-primary">'+I18n.t("modal.save_and_close")+'</button>'
result << '</div>'
result << '</div>'
result.html_safe
render_anywhere("shared/attribute_field/address_modal_dialog",{:field_name=>title,:btn_class => "#{get_pairing_tab_class({})}"})
end
end

View File

@ -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

View File

@ -13,34 +13,12 @@ class AttributeValue
# 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,22 +73,51 @@ 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

View File

@ -17,53 +17,3 @@
<%= render :partial=>"infos"%>
<%= render :partial=>"roles"%>
<% content_for :page_specific_javascript do -%>
<script>
var CloneTarget ;
var NewNode;
$(document).ready(function(){
function checkMultipleInput() {
$(".multipleInput").each(function(i) {
$(this).find('.tabbable').length==1 ? $(this).addClass("plural") : $(this).removeClass("plural")
});
}
function removeInput(){
$(".removeInput").live('click',function (){
$(this).parents(".tabbable").remove();
checkMultipleInput();
return false;
});
}
checkMultipleInput();
removeInput();
$(".help-block a").live('click',function (){
CloneTarget = $(this).parents(".controls").find(".tabbable:last");
NewNode = CloneTarget.clone();
var index;
NewNode.find("input").each(function(k,v){
index = CloneTarget.parents("div.control-group").find(".list_count").val();
field_name = CloneTarget.parents("div.control-group").find(".field_name").val();
ori_str = $(v).attr("name").replace(field_name,"");
lang = ori_str.match(/\[\D*\]/);
new_field_name = (field_name+"[" + (parseInt(index)+1) + "]" + lang);
$(v).attr("name",new_field_name);
$(v).val("");
})
$(this).parents("div.control-group").find(".list_count").val(parseInt(index)+1)
$(this).parents(".controls").find(".tabbable:last").after(NewNode);
removeInput();
// checkMultipleInput();
return false;
})
});
</script>
</script>
<% end -%>

View File

@ -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 -%>

View File

@ -1,13 +0,0 @@
<div class="modal hide fade" id="address-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none; ">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>

View File

@ -0,0 +1,61 @@
<div class="modal hide fade address-edit <%= btn_class %>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<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>
</div>
<div class="modal-body">
<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%>
<%= link_to t("langs.#{locale}"),".#{btn_class}.address_modal.#{locale}",:data=>{:toggle=>"tab"}%>
<% end %>
<% end %>
</ul>
<div class="tab-content">
<% VALID_LOCALES.each do |locale|%>
<!-- start of lang tab context -->
<% active = (locale == VALID_LOCALES.first ? "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) %>
</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}") %>
</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}") %>
</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") %>
</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}") %>
</div>
</div>
</div>
<!-- end of tab context -->
<% end %>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><%=t("modal.close")%></button>
<button href="" class="btn btn-primary bt-save" data-dismiss="modal" aria-hidden="true"><%=t("modal.save_and_close")%></button>
</div>
</div>

View File

@ -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:

View File

@ -24,11 +24,19 @@ zh_tw:
help: 協助
hide: 隱藏
homepage: 首頁
address_modal:
default_title: 地址
street_address: 街道地址
city: 城市
county: 縣市
zip: 郵遞區號
country: 國家/地區
langs:
zh_tw: 中文
en: 英文
lists:
markups:
address: 地址欄位
text_field: 文字輸入框
select: 下拉選單
date: 日期

View File

@ -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