"
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 << '' if self.markup == 'address'
+ result << '' if self.add_more
result << "
"
- result << "
"
- VALID_LOCALES.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 << "
"
+ if can_muti_lang_input?
+ result << "
"
+ 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 << "
"
+ end
result << "
"
- # @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 << '
'
result << ''
- result << ''+I18n.t("admin.infos.add")+' '
+ result << ''+I18n.t("admin.infos.add")+' '
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 << ''
+ result << '
'
end
end # of loop_time
result << "
"
@@ -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
- locale and LIST[:markups][markup]["ext_support"] && 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 = '
'
- result << '
'
- result << ''
- result << '
'+title+'
'
- result << '
'
- result << '
'
- result << '
One fine body…
'
- result << '
'
- result << ''
- result << '
'
- result.html_safe
+ render_anywhere("shared/attribute_field/address_modal_dialog",{:field_name=>title,:btn_class => "#{get_pairing_tab_class({})}"})
end
end
\ No newline at end of file
diff --git a/app/models/user/attribute_field.rb b/app/models/user/attribute_field.rb
index 3cef5f1d..62281402 100644
--- a/app/models/user/attribute_field.rb
+++ b/app/models/user/attribute_field.rb
@@ -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
diff --git a/app/models/user/attribute_value.rb b/app/models/user/attribute_value.rb
index 7b5d4caf..16ab50f8 100644
--- a/app/models/user/attribute_value.rb
+++ b/app/models/user/attribute_value.rb
@@ -12,35 +12,13 @@ class AttributeValue
before_save :data_proc
# 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,23 +73,52 @@ 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
end
diff --git a/app/views/admin/users_new_interface/_form.html.erb b/app/views/admin/users_new_interface/_form.html.erb
index be54d674..99a8da04 100644
--- a/app/views/admin/users_new_interface/_form.html.erb
+++ b/app/views/admin/users_new_interface/_form.html.erb
@@ -17,53 +17,3 @@
<%= render :partial=>"infos"%>
<%= render :partial=>"roles"%>
-
-<% content_for :page_specific_javascript do -%>
-
-
-<% end -%>
\ No newline at end of file
diff --git a/app/views/admin/users_new_interface/edit.html.erb b/app/views/admin/users_new_interface/edit.html.erb
index 1e169520..faf8bcef 100644
--- a/app/views/admin/users_new_interface/edit.html.erb
+++ b/app/views/admin/users_new_interface/edit.html.erb
@@ -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 -%>
diff --git a/app/views/shared/_address_modal_dialog.html.erb b/app/views/shared/_address_modal_dialog.html.erb
deleted file mode 100644
index 6e241074..00000000
--- a/app/views/shared/_address_modal_dialog.html.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
Modal header
-
-
-
One fine body…
-
-
-
\ No newline at end of file
diff --git a/app/views/shared/attribute_field/_address_modal_dialog.html.erb b/app/views/shared/attribute_field/_address_modal_dialog.html.erb
new file mode 100644
index 00000000..9c51ae27
--- /dev/null
+++ b/app/views/shared/attribute_field/_address_modal_dialog.html.erb
@@ -0,0 +1,61 @@
+