disable data transform when switching attribute field type. new member stable

This commit is contained in:
Matthew K. Fu JuYuan 2012-11-22 17:49:44 +08:00 committed by chris
parent edf38644c9
commit 77386f0284
12 changed files with 174 additions and 95 deletions

View File

@ -13,8 +13,10 @@ $(document).ready(function(){
$(this).parents(".map-block").find(".form-horizontal").toggleClass("hide");
if($(this).parents(".map-block").hasClass("disabled")){
$(this).text("OFF");
$(this).siblings(".subrole_disable_field").val("true");
}else{
$(this).text("ON");
$(this).siblings(".subrole_disable_field").val("false");
}
}
if($(this).parents("legend").length==1) {
@ -22,8 +24,10 @@ $(document).ready(function(){
$(this).parents("legend").next("div").toggleClass("hide");
if($(this).parents("legend").next("div").hasClass("hide")){
$(this).text("OFF");
$(this).siblings(".subrole_disable_field").val("true");
}else{
$(this).text("ON");
$(this).siblings(".subrole_disable_field").val("false");
}
checkSwitch();
}

View File

@ -6,6 +6,7 @@ class Admin::UsersNewInterfaceController < OrbitBackendController
before_filter :force_order_for_visitor,:only=>[:index,:show]
before_filter :force_order_for_user,:except => [:index,:show]
before_filter :set_attribute,:except => [:index,:show]
def index
get_tags

View File

@ -55,7 +55,19 @@ module AttributeFieldsHelper
end
def render_date
control_group_wrapper{date_select(get_field_name_base,nil,@markup_options.merge(:default=>@prefiled_value),:class=>"input-small")}
if date_is_range?
fill_from = @attribute_value.get_date(:from) rescue nil
fill_to = @attribute_value.get_date(:to) rescue nil
control_group_wrapper do
buf = date_select(get_field_name_base+'[from]',nil,@markup_options.merge(:default=>fill_from),:class=>"input-small")
buf << ' ~ '
buf << date_select(get_field_name_base+'[to]',nil,@markup_options.merge(:default=>fill_to),:class=>"input-small")
buf
end
else
@prefiled_value = @attribute_value.get_date
control_group_wrapper{date_select(get_field_name_base,nil,@markup_options.merge(:default=>@prefiled_value),:class=>"input-small")}
end
end
def render_date_durnation #Need re-write low priority
@ -66,7 +78,7 @@ module AttributeFieldsHelper
@prefiled_value ||=[]
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"))
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=>" radio inline"))
end.join
end
end
@ -87,13 +99,23 @@ module AttributeFieldsHelper
end
def render_text_field
control_group_wrapper do |key,value|
a = 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,add_more_blank,key_field].join, value,@markup_options.merge(:placeholder=>place_holder))
end
end
def date_is_range?
is_range = "false"
data = get_data
if !data.nil?
is_range = data['is_range'] if data.has_key? "is_range"
end
is_range == "true"
end
protected
def lang_panel_tabbable_wrapper(add_more_params,&block)
@ -117,17 +139,15 @@ protected
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 << link_to((content_tag :i,'',:class=>'icon-trash'),"#",:class=>"btn removeInput") 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
buff.join('').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_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
@ -151,16 +171,18 @@ protected
if can_muti_lang_input?
result << lang_panel_tabbable_wrapper(add_more_params,&block)
result << gen_modal_dialog if self.markup == "address"
else
else #cross lang field
value = case can_add_more
when true
add_more_params[0]
else
@prefiled_value
case can_add_more
when true
value = add_more_params[0][:value]
result << content_tag(:div,:class=>"input-append"){yield(nil,value) + link_to((content_tag :i,'',:class=>'icon-trash'),"#",:class=>"btn removeInput") }
else
value = @prefiled_value
result << yield(nil,value)
end
result << yield(nil,value)
end
result.html_safe
@ -173,12 +195,12 @@ protected
case self.markup
when "text_field"
if can_add_more
multipleInput_ary = %w{multipleInput editMore}
multipleInput_ary = %w{multipleInput}
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|
controls_wrapper(:value=>(@prefiled_value[t] rescue nil),:counter=>t,&block)
end.join("\n").html_safe # of add_more fields
end.join('').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
@ -267,7 +289,7 @@ protected
if self.markup == "address"
return false
else
locale and LIST[:markups][markup]["ext_support"] && add_more
add_more
end
end

View File

@ -1,6 +1,14 @@
module AttributeValuesHelper
def show_west_calender
date = get_date
def show_west_calender(from_to=nil)
case from_to
when :to
date = get_date(:to)
when :from
date = get_date(:from)
when nil
date = get_date
end
case self.attribute_field["typeC"]["format"]
when 'format1' # Y/M/D h:m
date.strftime("%Y/%m/%d %H:%M")
@ -13,9 +21,16 @@ module AttributeValuesHelper
end # of case west cal format
end
def show_minguo_calendar
def show_minguo_calendar(from_to=nil)
get_minguo
date = get_date
case from_to
when :to
date = get_date(:to)
when :from
date = get_date(:from)
when nil
date = get_date
end
year_str = ""
unless date.year == 1912
m_year = (date.year - 1912).abs.to_s + I18n.t("admin.infos.date.minguo_calendar.year")
@ -52,17 +67,17 @@ module AttributeValuesHelper
end # of case
end
def get_date_by_format
def get_date_by_format(from_to = nil)
case I18n.locale
when :zh_tw
case
when self.attribute_field["typeC"]["claendar"] == "west_claendar"
show_west_calender
show_west_calender(from_to)
when self.attribute_field["typeC"]["claendar"] == "tw_claendar"
show_minguo_calendar
show_minguo_calendar(from_to)
end #case self.attribute_field["typeC"]["claendar"]
when :en
show_west_calender
show_west_calender(from_to)
end
end
end

View File

@ -30,12 +30,7 @@ class AttributeField
end
def locale
default = true
if get_data["locale"].nil?
return default
else
(get_data["locale"] == "true" ? true : false) rescue default
end
get_data["cross_lang"] == "true" ? false : true
end
def self_defined_markup_options?
@ -107,56 +102,63 @@ protected
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
# 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?
# old_data = av["val"]
# av["val"] = []
# splited_str.each_with_index do |value,index|
# av["val"][index] = {loc=>value}
# end
# av["val"] << old_data
# 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|
# binding.pry
# 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} } #unless av["val"].nil?
else
av[default_locale] = av["val"]
av.unset("val")
end
av.save
end #of self.attribute_values.each
end
# 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} } #unless av["val"].nil?
# 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)

View File

@ -49,7 +49,12 @@ class AttributeValue
when "text_field"
case self.attribute_field.add_more
when true
add_more_index.nil? ? self.value.collect{|t| t[locale]}.join(",") : self.value(add_more_index)[locale]
if self.attribute_field.locale
add_more_index.nil? ? self.value.collect{|t| t[locale]}.join(",") : self.value(add_more_index)[locale]
else
add_more_index.nil? ? self.value.join(",") : self.value(add_more_index)
end
when false
self.attribute_field.locale ? self[locale.to_s] : self.value
end
@ -62,7 +67,11 @@ class AttributeValue
self.attribute_field.locale ? self[locale.to_s] : self.value
when "date"
get_date_by_format
if self.attribute_field.date_is_range?
get_date_by_format(:from) + ' ~ ' + get_date_by_format(:to)
else
get_date_by_format
end
when "address"
self.value[locale.to_s]
@ -83,6 +92,18 @@ class AttributeValue
end
end
def get_date(item = nil)
case item
when :from
data = self[:val]["from"]
when :to
data = self[:val]["to"]
when nil
data = self[:val]
end
Date.new(data["(1i)"].to_i,data["(2i)"].to_i,data["(3i)"].to_i) rescue nil
end
protected
@ -130,9 +151,4 @@ def unset_all_lang_values
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
end

View File

@ -14,7 +14,7 @@
<% end %>
</div>
</div>
<%= render :partial=>"placeholder_block",:locals=>{:value=>@attribute.title_translations,:class_ext=>"pull-left",:label_ext=>t("admin.infos.item_name"),:field_name=>"info[title_translations]"}%>
<%= render :partial=>"placeholder_block",:locals=>{:values=>@attribute.title_translations,:class_ext=>"pull-left",:label_ext=>t("admin.infos.item_name"),:field_name=>"info[title_translations]"}%>
</div>
</div>

View File

@ -66,10 +66,10 @@
<label class="control-label"><%= t("admin.infos.date.range")%></label>
<div class="controls">
<label class="radio inline">
<%= radio_button("info[attribute_fields][#{attribute_field_counter}][typeC]", "is_range", "false",:checked => (attribute_field["typeC"]["is_range"]== "false" ? true : false)) %><%= t("admin.infos.not_range")%>
<%= radio_button("info[attribute_fields][#{attribute_field_counter}][typeC]", "is_range", "false",:checked => (!attribute_field.date_is_range? ? true : false)) %><%= t("admin.infos.not_range")%>
</label>
<label class="radio inline">
<%= radio_button("info[attribute_fields][#{attribute_field_counter}][typeC]", "is_range", "true",:checked => (attribute_field["typeC"]["is_range"]== "true" ? true : false)) %><%= t("admin.infos.is_range")%>
<%= radio_button("info[attribute_fields][#{attribute_field_counter}][typeC]", "is_range", "true",:checked => (attribute_field.date_is_range? ? true : false)) %><%= t("admin.infos.is_range")%>
</label>
</div>
</div>

View File

@ -7,8 +7,8 @@
<% @site_valid_locales.each do |locale| %>
<% active = (locale == @site_valid_locales.first ? "active in" : "'") %>
<%= content_tag :div,:class=>"tab-pane fade #{active}",:id=>"#{name_to_id(field_name)}_#{locale}" do%>
<% value = values[locale.to_s] rescue nil%>
<%= text_field(field_name, locale,:value=>value,:placeholder=>t("langs.#{locale}")) %>
<% locale_value = values[locale.to_s] rescue nil%>
<%= text_field(field_name, locale,:value=>locale_value,:placeholder=>t("langs.#{locale}")) %>
<% end %>
<% end %>
</div>

View File

@ -6,10 +6,10 @@
<% role.sub_roles.each do |sub_role| %>
<% sub_role_disable = @user.sub_roles.include?(sub_role) ? false : true %>
<%= hidden_field_tag("user[disable_sub_role][id][#{sub_role.id}]",sub_role_disable,:for=>@form_index,:class=>"subrole_disable_field",:value=>sub_role_disable)%>
<%#= hidden_field_tag("[user][new_attribute_values][sub_role][disable][#{sub_role.id}]",sub_role_disable)%>
<legend>
<button for=<%=@form_index%> class="onoff pull-right <%= sub_role_disable ? 'disabled' : '' %> ">ON</button><%= sub_role.title %>
<%= hidden_field_tag("user[disable_sub_role][id][#{sub_role.id}]",sub_role_disable,:for=>@form_index,:class=>"subrole_disable_field",:value=>sub_role_disable)%>
</legend>
<div class="controls-block <%= sub_role_disable ? 'hide' : '' %>" >
<% sub_role.attribute_fields.each do |af|%>

View File

@ -3,8 +3,8 @@
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('users_new_interface')) do -%>
<%= content_tag :li, link_to((t('admin.new_admin.side_bar.all_user') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, admin_users_new_interface_index_path), :class => active_for_action('users_new_interface', 'index') %>
<%= content_tag :li, link_to((t('admin.new_admin.side_bar.add_user') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, new_admin_users_new_interface_path), :class => active_for_action('users_new_interface', 'new') %>
<%= content_tag :li, link_to((t('admin.new_admin.side_bar.user_roles') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, ), :class => active_for_action('users_new_interfacexx', 'index') %>
<%= content_tag :li, link_to((t('admin.new_admin.side_bar.user_info') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, ), :class => active_for_action('users_new_interfacexx', 'index') %>
<%= content_tag :li, link_to((t('admin.new_admin.side_bar.user_roles') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe,admin_infos_path ), :class => active_for_action('users_new_interfacexx', 'index') %>
<%= content_tag :li, link_to((t('admin.new_admin.side_bar.user_info') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, admin_roles_path), :class => active_for_action('users_new_interfacexx', 'index') %>
<% end -%>
<% end -%>

View File

@ -2,7 +2,26 @@
require 'resque_scheduler/tasks'
namespace :data_migration do
task :migrate_user_infos_from_1121 => :environment do
AttributeField.all.each do |af|
if af.has_attribute?('locale')
af.title_translations = case af[:locale]
when true
af[:locale_title]
when false
{af[:neutral_for] => af[:neutral_title]}
end
af.unset("locale")
af.unset("locale_title")
af.unset("neutral_for")
af.unset("neutral_title")
af.save
end
end
end
task :add_order_to_announcement_tag_0703 => :environment do
AnnouncementTag.first({conditions:{ key: 'students' }}).update_attributes(:order=>1)
AnnouncementTag.first({conditions:{ key: 'alumni' }}).update_attributes(:order=>2)