add new member with role interface. add more not usable.

role management new attribute is ok. delete is ok.
This commit is contained in:
Matthew K. Fu JuYuan authored and chris committed 2012-11-04 20:42:58 +08:00
1 parent fe0e49c3e9
commit beb843f75b
25 files changed
+1159 -512

No files matched your search

+19 -9
View File
@@ -287,36 +287,42 @@
padding: 0 20px 0 150px !important;
margin: 20px 0 0;
}
.user-role .user-info {
.role-block .user-info {
top: 23px;
margin-left: -135px;
width: 100px;
border-right: none;
box-shadow: none;
}
.user-role .map-block h4 .gender {
.role-block .map-block h4 .gender {
top: -1px;
bottom: auto;
left: -1px;
right: auto;
border-radius: 4px 0 0 0;
}
.user-role .teacher h4 .gender {
.role-block .teacher h4 .gender {
border-color: #186AB6 transparent transparent #186AB6;
}
.user-role .student h4 .gender {
.role-block .student h4 .gender {
border-color: #F38C08 transparent transparent #F38C08;
}
.user-role .staff h4 .gender {
.role-block .staff h4 .gender {
border-color: #139E2F transparent transparent #139E2F;
}
.user-role .tab-content, .user-role .nav-pills {
.role-block .tab-content, .role-block .nav-pills {
float: left;
}
.user-role .nav-pills {
margin-left: 10px;
.role-block .nav-pills {
margin-bottom: 0;g
}
.plural .input-append input, .plural .input-append select, .plural .input-append .uneditable-input {
.role-block .nav-pills > li > a {
margin-top: 0;
}
/*.role-block .control-group .inline {
float:
}*/
.plural .input-append input, .plural .input-append select, .plural .input-append .uneditable-input, .unRadius input {
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
@@ -338,4 +344,8 @@
-webkit-border-radius: 0 3px 3px 0;
-moz-border-radius: 0 3px 3px 0;
border-radius: 0 3px 3px 0;
}
.language-swich .tab-pane {
margin-bottom: 5px;
margin-right: 10px;
}
+35 -12
View File
@@ -81,37 +81,60 @@
background-color: #5EB92B;
font-size: 9px;
padding: 0px 10px;
border-radius: 8px;
line-height: 16px;
height: 15px;
border-radius: 11px;
line-height: 20px;
height: 19px;
color: #FFF;
width: 38px;
width: 40px;
border: none;
box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.5), 0 0 5px rgba(13, 75, 23, 0.5) inset;
margin-top: 2px;
margin-top: 1px;
}
/* for mamber role */
.user-role .form-horizontal {
.role-block .form-horizontal {
padding: 20px 10px 10px;
background-color: #FFF;
margin-bottom: 0;
border-radius: 0 0 4px 4px;
}
.user-role .form-horizontal .control-label {
.role-block [class*="type"] {
background-color: #F1F1F1;
padding: 20px 0 10px;
border-radius: 5px;
margin: -25px 0 40px;
/*box-shadow: 0px 1px 3px rgba(100,100,100,.4)*/
}
.role-block .form-horizontal .control-label {
width: 100px;
}
.user-role .form-horizontal .controls {
.role-block .form-horizontal .controls {
margin-left: 120px;
}
.user-role .form-horizontal .controls>.input-append {
.role-block .form-horizontal .controls>.input-append {
margin-bottom: 10px;
}
.user-role .map-block {
.role-block .form-horizontal legend .onoff {
margin-top: 4px;
}
.role-block .form-horizontal legend .btn-danger {
margin-right: 20px;
}
.role-block .form-horizontal legend>.clear {
margin-right: 150px;
min-width: 350px;
}
.role-block .map-block {
min-width: 440px;
}
.user-role .map-block legend {
.role-block .map-block .form-actions {
margin: 0;
padding: 10px 20px;
}
.role-block .map-block legend {
font-size: 18px;
line-height: 25px;
}
.role-block .map-block legend .nav {
font-size: 12px;
}
+8 -7
View File
@@ -1,10 +1,11 @@
class Admin::InfosController < ApplicationController
layout "admin"
layout "new_admin"
before_filter :authenticate_user!
before_filter :is_admin?
before_filter :set_attribute, :only => [:index, :show, :new, :edit]
helper Admin::AttributeValuesViewHelper
def index
@attributes = Info.all.entries
render :template => 'admin/attributes/index'
@@ -32,8 +33,8 @@ class Admin::InfosController < ApplicationController
def update
@attribute = Info.find(params[:id])
# binding.pry
@attribute.update_attributes(params[:info])
@attribute.attribute_fields.each{|t| t.destroy if t["to_delete"] == true}
respond_to do |format|
format.html { redirect_to :action => :index }
format.js { render 'admin/attributes/toggle_enable' }
@@ -47,10 +48,10 @@ class Admin::InfosController < ApplicationController
end
def add_attribute_field
@attribute = Info.find(params[:id]) rescue nil
if !@attribute
@attribute = Info.new
end
attribute = Info.find(params[:info_id]) rescue nil
@attribute_field_counter = attribute.attribute_fields.count
@attribute_field = attribute.attribute_fields.build
@attribute_field.save
end
protected
@@ -75,7 +75,6 @@ class Admin::UsersNewInterfaceController < ApplicationController
end
def create
binding.pry
puts params.to_yaml
# attribute_values_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values'
# attribute_values = params[:user].delete(attribute_values_key)
@@ -84,6 +83,7 @@ class Admin::UsersNewInterfaceController < ApplicationController
# @user.attribute_values.build(value)
# }
# @user.rebuild_sub_roles_from_attribute_values!(attribute_values)
binding.pry
if @user.save
flash[:notice] = t('admin.create_success_user')
redirect_to :action => :index
@@ -0,0 +1,16 @@
module Admin::AttributeValuesViewHelper
OPT = [
["YYYY / MM / DD hh : mm","format1"],
["YYYY / MM / DD","format2"],
["YYYY / MM","format3"],
["YYYY","format4"]
]
def show_type_panel(attribute_field,type)
markup = attribute_field.markup
LIST[:markups][markup]["panel"] == type ? type : [type,'hide'].join(" ")
end
def name_to_id(str)
str.gsub(/\]/,'').gsub(/\[/,"_")
end
end
+72 -37
View File
@@ -9,14 +9,18 @@ module AttributeFieldsHelper
include ActionView::Helpers::RenderingHelper
def block_helper(user,index,disable = false)
@index = index
@markup_options = markup_options.merge(:disabled=>disable)
@user = user
@attribute_value = @user.get_value_from_field_id(id)
@new_attribute = @attribute_value.nil?
@attribute_value = @attribute_value || @user.attribute_values.build(attribute_field_id: id)
@prefiled_value = @attribute_value.get_values
return instance_eval("render_#{markup}") #rescue ""
unless self.disabled
@index = index
@markup_options = markup_options.merge(:disabled=>disable,:func=>"input_unit")
@user = user
@attribute_value = @user.get_value_from_field_id(id)
@new_attribute = @attribute_value.nil?
@attribute_value = @attribute_value || @user.attribute_values.build( attribute_field_id: id )
@prefiled_value = @attribute_value.value
@panel_setting = self.get_data
return instance_eval("render_#{markup}") #rescue ""
end
end
def lang_tab(str,lang)
@@ -24,6 +28,7 @@ module AttributeFieldsHelper
end
def render_address
#NP
control_group_wrapper do |key,value|
result = '<div class="input-append">'.html_safe
@@ -44,36 +49,55 @@ module AttributeFieldsHelper
end
def render_checkbox
@prefiled_value ||=[]
markup_value = eval(self.markup_value) rescue {}
# begin
# markup_value = eval(self.markup_value)
# rescue
# markup_value = self.markup_value
# ensure
# markup_value ||= {}
# end
control_group_wrapper do
markup_value.collect do |key,value|
label_tag(key,check_box_tag(get_field_name_base+"[value][#{key}]", value[I18n.locale.to_s], (@prefiled_value.include?(key) ? true : false), {})+value[I18n.locale.to_s],@markup_options.merge(:class=>"control-label"))
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"))
end.join rescue ""
end
end
def render_date
control_group_wrapper{date_select(get_field_name_base+"[value]",nil,@markup_options.merge(:default=>@prefiled_value),:class=>"input-small")}
#NP
control_group_wrapper{date_select(get_field_name_base,nil,@markup_options.merge(:default=>@prefiled_value),:class=>"input-small")}
end
def render_date_durnation #Need re-write low priority
end
def render_radio_button
@prefiled_value ||=[]
markup_value = eval(self.markup_value) rescue {}
# begin
# markup_value = eval(self.markup_value)
# rescue
# markup_value = self.markup_value
# ensure
# markup_value ||= {}
# end
control_group_wrapper do
markup_value.collect do |key,value|
label_tag(key,radio_button_tag(get_field_name_base+"[value][#{key}]", value[I18n.locale.to_s], (@prefiled_value.include?(key) ? true : false), {})+value[I18n.locale.to_s],@markup_options.merge(:class=>"control-label"))
end.join rescue ""
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"))
end.join
end
end
def render_select
markup_value = (self.markup_value.is_a?(Hash) ? self.markup_value : eval(self.markup_value) )rescue {}
control_group_wrapper{select_tag( get_field_name_base+"[value]",options_for_select(markup_value.collect{|p| [p[1][I18n.locale.to_s],p[0]]},@prefiled_value),@markup_options)} rescue ""
prompt = @panel_setting[:prompt][I18n.locale] 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
@@ -81,28 +105,35 @@ module AttributeFieldsHelper
if(add_more and value.is_a?(Hash))
values = value
values.each_with_index.collect do |value,index|
text_area_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options)
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]"
text_area_tag(get_field_name_base + key, value,@markup_options)
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
def render_text_field
control_group_wrapper do |key,value|
if(add_more and value.is_a?(Hash))
if(add_more)
values = value
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
result = ""
unless values.nil?
result = values.each_with_index.collect do |value,index|
place_holder= @panel_setting["placeholder"][key]
text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options.merge(:placeholder=>place_holder))
end.join.html_safe
end
result
else
value = can_muti_lang_input ? @prefiled_value[key] : @prefiled_value
key = can_muti_lang_input ? "[#{key}]" : "[value]"
text_field_tag(get_field_name_base + key, value,@markup_options)
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
end
end
@@ -121,12 +152,14 @@ protected
if can_muti_lang_input
result << "<div class='tabbable'>"
result << "<div class='tab-content'>"
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" : '')
result << content_tag(:div,yield(key,value),:class=>div_class,:id=>"tab"+id.to_s+"_#{key}")
end
result << "</div>"
result << "<ul class='nav nav-pills'>"
VALID_LOCALES.each do |key|
@@ -161,15 +194,13 @@ protected
def end_block
if @new_attribute
hidden_field_tag(get_field_name_base+"[attribute_field_id]",id,:for=>"field_#{@index}")
hidden_field_tag(get_basic_field_name_base+"[attribute_field_id]",id,:for=>"field_#{@index}")
else
hidden_field_tag(get_field_name_base+"[id]",@attribute_value.id,:for=>"field_#{@index}")
hidden_field_tag(get_basic_field_name_base+"[id]",@attribute_value.id,:for=>"field_#{@index}")
end
end
def get_field_name_base
# "user[#{self.attribute._type.downcase.pluralize}][#{self.attribute._id.to_s}][attribute_values][#{attribute_value.id}]"
# binding.pry if @attribute_value[:key] == 'status'
def get_basic_field_name_base
if @new_attribute
"user[new_attribute_values][#{@index}]"
else
@@ -177,12 +208,16 @@ protected
end
end
def get_field_name_base
get_basic_field_name_base + "[value]"
end
def label
label_tag(key,title,:class=>"control-label")
label_tag(key,title,:class=>"control-label",:func => "field_label")
end
def can_muti_lang_input
locale and LIST[:markups][markup]["muti_lang_input_supprt"]
LIST[:markups][markup]["muti_lang_input_supprt"] #and locale
end
def can_add_more
+1
View File
@@ -11,6 +11,7 @@ class Attribute
has_many :attribute_fields, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :attribute_fields, :allow_destroy => true
def is_built_in?
self.built_in
end
+66 -36
View File
@@ -5,26 +5,38 @@ class AttributeField
include ::AttributeFieldsHelper
field :key
field :markup
field :markup_value ,:type => Hash
field :markup ,:default=>"text_field"
field :option_list ,:type => Hash,:default => {}
field :markup_options,:type => Hash
field :locale, :type => Boolean, :default => true
# 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 :add_more,:type => Boolean, :default => false
field :to_delete,:type=> Boolean,:default => false
field :typeA,:type=> Hash,:default=>{}
field :typeB,:type=> Hash,:default=>{}
field :typeC,:type=> Hash,:default=>{:claendar=>"west_claendar"}
field :typeD,:type=> Hash,:default=>{}
field :typeE,:type=> Hash,:default=>{}
#field :title, localize: true
field :locale_title, localize: true
field :neutral_title
field :neutral_for
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 add_more
(get_data["add_more"] == "true" ? true : false) rescue false
end
def locale
(get_data["locale"] == "true" ? true : false) rescue false
end
def self_defined_markup_options?
(self.attribute.role.method(self[:key].pluralize.to_sym) && self.attribute.role.method(self[:key].pluralize+"_for_"+markup)) rescue false
@@ -36,16 +48,16 @@ class AttributeField
end
end
def markup_value
def option_list
if self_defined_markup_options?
#Class need to have corresponding field and value agent
# Ex: For "status" the class must have field called "statuses" for the relation and "statuses_for_select" for the select function
method = self.attribute.role.method(self[:key].pluralize+"_for_"+markup)
return (method.call rescue {})
elsif self[:markup_value].nil? || (self[:markup_value].empty?)
elsif self[:option_list].nil? || (self[:option_list].empty?)
return {}
else
return self[:markup_value]
return self[:option_list]
end
end
@@ -68,36 +80,49 @@ class AttributeField
self.attribute.role
end
def title_translations
if locale
return locale_title_translations
else
return Hash[VALID_LOCALES.map{|d| [d,neutral_title]}]
end
def panel
panel = LIST[:markups][self[:markup]]["panel"]
end
def title_translations=(var)
if locale
self.locale_title_translations = var
end
def get_data
self[panel]
end
def title
if locale
return self.locale_title
else
return self.neutral_title
end
end
def title=(var)
# binding.pry
if locale
self.locale_title = var
else
self.neutral_title = var
end
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)
@@ -117,4 +142,9 @@ class AttributeField
self.disabled
end
protected
def check_option_list
self[:option_list] = self[panel]["option_list"]
end
end
+73 -27
View File
@@ -10,11 +10,56 @@ class AttributeValue
belongs_to :user
before_save :check_key
before_save :data_proc
# NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"]
def data_proc
# binding.pry
# binding.pry if self.attribute_field.markup == 'radio_button'
if self.attribute_field.locale
case self.attribute_field.markup
when 'text_field','text_area'
# binding.pry
self[:temp_data].each{|key,val|
self[key] = val
} unless self[:temp_data].nil?
when 'select','date','radio_button'
self["val"] = self[:temp_data]
when 'checkbox'
self["val"] = self[:temp_data].keys rescue {}
end #end of case
else # if not locale
case self.attribute_field.markup
when 'text_field','text_area'
self["val"] = self[:temp_data]
when 'select','date','radio_button'
self["val"] = self[:temp_data]
when 'checkbox'
self["val"] = self[:temp_data].keys rescue {}
end #end of case
end
self.unset('temp_data')
end
def value
result=""
if self.attribute_field.locale && (self.attribute_field.markup == "text_field" || self.attribute_field.markup == "text_area")
result= Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}]
else
result = self["val"]
end
result
end
def value=(value)
#save everything to temp_data waiting for futher process
# binding
self[:temp_data] = value
end
def check_key
binding.pry if attribute_field.nil?
self.key = attribute_field.key
end
@@ -27,45 +72,46 @@ class AttributeValue
end
def get_value_by_locale(locale)
case self.attribute_field.markup
when "text_field"
self.attribute_field.locale ? self[locale] : self[:value]
self.attribute_field.locale ? self.value[locale.to_s] : self.value
when "select"
markup_values = self.attribute_field.self_defined_markup_options? ? self.attribute_field.markup_value : eval(self.attribute_field.markup_value)
markup_values[self[:value]][locale.to_s] rescue 'NoData'
markup_values[self.value][locale.to_s] rescue 'NoData'
when "text_area"
self.attribute_field.locale ? self[locale] : self[:value]
self.attribute_field.locale ? self.value[locale.to_s] : self.value
when "date"
Date.new(self[:value]["(1i)"].to_i,self[:value]["(2i)"].to_i,self[:value]["(3i)"].to_i) rescue nil
Date.new(self[:val]["(1i)"].to_i,self[:val]["(2i)"].to_i,self[:val]["(3i)"].to_i) rescue nil
when "addr"
self[:value]
self.value
when "radio_button"
markup_values = eval(self.attribute_field.markup_value)
markup_values[self[:value].first[0]][locale.to_s]
when "checkbox"
markup_values[self.value][locale.to_s]
when "checkbox"
markup_values = eval(self.attribute_field.markup_value)
self[:value].keys.collect{|key| markup_values[key][locale.to_s] }.join(",")
self.value.collect{|key| markup_values[key][locale.to_s] }.join(",")
when "date_durnation"
self[:value]
self.value
else
self.attribute_field.locale ? self[locale] : self[:value]
self.attribute_field.locale ? self.value[locale.to_s] : self.value
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
# 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
end
+2 -1
View File
@@ -38,7 +38,8 @@ class User
before_save :save_roles
scope :remote_account, where(:nccu_id.ne => nil)
validates_uniqueness_of :email,:message=> I18n.t("devise.registrations.email_not_unique")
# validates_uniqueness_of :email,:message=> I18n.t("devise.registrations.email_not_unique")
# def new_attribute_values=(vars)
# binding.pry
# end
+137 -12
View File
@@ -1,14 +1,139 @@
<% content_for :secondary do %>
<%= render 'admin/users/side_bar' %>
<%= form_for @attribute,:url => admin_info_path(@attribute) ,:class=> "form-horizontal" do |f| %>
<div class="site-map role-block">
<div class="map-block back">
<h4><span><%= t("admin.info")%></span></h4>
<div class="form-horizontal">
<div class="clear">
<div class="control-group pull-left">
<label class="control-label" for="key"><%= t("admin.key") %></label>
<div class="controls">
<% if @attribute.new_record? %>
<%= f.text_field :key,:placeholder=>"Key" %>
<% else %>
<div><%= @attribute.key%></div>
<% 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]"}%>
</div>
</div>
</div>
<div class="map-block back attributes">
<h4><span><%= t("admin.attributes")%></span></h4>
<%= render :partial=>"attribute_field",:collection=>@attribute.attribute_fields%>
</div>
</div>
<div class="form-actions form-fixed pagination-right">
<%= link_to content_tag(:i,t("admin.infos.add_attribute_field"),:class=>"icon-plus icon-white"),admin_info_add_attribute_field_path(@attribute),:class=>"btn btn-primary",:remote => true%>
<%= f.submit t("admin.infos.save"),:class=>"btn btn-primary"%>
</div>
<% end %>
<% content_for :page_specific_css do -%>
<%= stylesheet_link_tag "member" %>
<%= stylesheet_link_tag "site-map" %>
<% end %>
<div id="profile">
<%= form_for @attribute, :url => eval("admin_#{@attribute_type}_path(@attribute)") do |f| %>
<%= f.error_messages %>
<%= render :partial => "admin/#{@attribute_type}s/form", :locals => { :f => f, :is_new => false } %>
<div class='button_bar'>
<%= link_back %>
<%= link_to t('update'), "#", :onclick=>"$('#edit_#{@attribute_type}_#{@attribute.id}').submit()" %>
</div>
<% end %>
</div>
<% content_for :page_specific_javascript do -%>
<script>
var CloneTarget ;
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');
}
function checkMultipleInput() {
$(".multipleInput").each(function() {
$(this).find('.controls').length==1 ? $(this).addClass("plural") : $(this).removeClass("plural")
});
}
function removeInput(){
$(".removeInput").live('click',function (){
$(this).parents(".controls").remove();
checkMultipleInput();
return false;
});
}
checkSwitch();
checkMultipleInput();
removeInput();
$(".remove_attribute").live('click',function(){
$(this).siblings(".attribute_field_to_delete").val("true");
$(this).parents(".form-horizontal").fadeOut("slow", function () { $(this).hide(); });
});
$(".help-block a").live('click',function (){
CloneTarget = $(this).parents(".controls").prev(".multipleInput").find('.controls: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);
})
$(this).parents("div.control-group").find(".list_count").val(parseInt(index)+1)
$(this).parents(".controls").prev(".multipleInput").append(NewNode);
$(this).parents(".controls").prev(".multipleInput").find('.controls:last input').val("");
removeInput();
checkMultipleInput();
return false;
})
$(".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:''});
}
});
})
})
$('.onoff').live('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");
$(this).siblings(".attribute_field_disabled").val("true");
}else{
$(this).text("ON");
$(this).siblings(".attribute_field_disabled").val("false");
}
checkSwitch();
}
return false;
});
$(".dataType").change(function () {
$(this).parents("legend").next("div").find("div[class^='type']").addClass("hide");
$(this).parents("legend").next("div").find("."+$(this).find("option:selected").attr("ref")).removeClass("hide");
})
});
</script>
<% end -%>
+100 -3
View File
@@ -1,3 +1,100 @@
<%= f.fields_for :attribute_fields, attribute_field do |f| %>
<%= render :partial => 'admin/attributes/attribute_field', :object => attribute_field, :locals => {:f => f} %>
<% end %>
<div class="form-horizontal">
<legend>
<button class="onoff pull-right <%= attribute_field.disabled ? 'disabled' : ''%>">ON</button>
<%= hidden_field "info[attribute_fields][#{attribute_field_counter}]","disabled",:value=>attribute_field.disabled,:class=>"attribute_field_disabled"%>
<%= hidden_field "info[attribute_fields][#{attribute_field_counter}]","to_delete",:value=>false,:class=>"attribute_field_to_delete"%>
<a class="btn btn-small pull-right btn-danger remove_attribute" href="#"><i class="icon-trash icon-large"></i> <%= t("delete")%></a>
<div class="clear">
<div class="control-group pull-left">
<label class="control-label" for="key"><%= t("admin.key") %></label>
<div class="multipleInput">
<div class="controls">
<%= text_field "info[attribute_fields][#{attribute_field_counter}]","key",:value=>attribute_field.key%>
</div>
</div>
</div>
<%= render :partial=>"placeholder_block",:locals=>{:values=>attribute_field.title_translations,:class_ext=>"pull-left",:label_ext=>t("admin.infos.name"),:field_name=>"info[attribute_fields][#{attribute_field_counter}][title_translations]"}%>
<div class="control-group pull-left">
<label class="control-label" for=""><%= t("admin.infos.type")%></label>
<div class="controls">
<%#= select_tag "info[attribute_fields][#{attribute_field_counter}][markup]" do %>
<select class="dataType" name=<%= "info[attribute_fields][#{attribute_field_counter}][markup]"%>>
<%LIST[:markups].each do |key,val|%>
<option value="<%= key %>" <%= attribute_field.markup == key ? 'selected="selected"' : '' %> ref="<%=val["panel"]%>"><%=t("lists.markups."+key)%></option >
<% end %>
</select>
</div>
</div>
</div>
</legend>
<div class="<%= attribute_field.disabled ? 'hide' : ''%>">
<%= content_tag :div,:class=>show_type_panel(attribute_field,"typeA") do%>
<div class="control-group">
<label class="control-label"><%= t("admin.infos.options")%></label>
<div class="controls">
<label class="checkbox inline">
<%= check_box_tag("info[attribute_fields][#{attribute_field_counter}][typeA][multilingual]","true",attribute_field["typeA"]["multilingual"]) %>
<%= t("admin.infos.multilingual")%>
</label>
<label class="checkbox inline">
<%= check_box_tag("info[attribute_fields][#{attribute_field_counter}][typeA][add_more]","true",attribute_field["typeA"]["add_more"]) %>
<%= t("admin.infos.add_more")%>
</label>
</div>
</div>
<%= render :partial=> "placeholder_block",:locals=>{:values=>attribute_field["typeA"]["placeholder"],:field_name=>"info[attribute_fields][#{attribute_field_counter}][typeA][placeholder]"}%>
<% end %>
<%= content_tag :div,:class=>show_type_panel(attribute_field,"typeB") do %>
<%= render :partial=> "placeholder_block",:locals=>{:label_ext=>t("admin.infos.initial"),:values=>attribute_field["typeB"]["initial"],:field_name=>"info[attribute_fields][#{attribute_field_counter}][typeB][initial]"}%>
<%= render :partial=>"list_block",:locals=>{:values=>attribute_field["option_list"],:field_name=> "info[attribute_fields][#{attribute_field_counter}][typeB][option_list]"} %>
<% end %>
<%= content_tag :div,:class=>show_type_panel(attribute_field,"typeC") do %>
<div class="control-group">
<label class="control-label"><%= t("admin.infos.date.format")%></label>
<div class="controls">
<%= select "info[attribute_fields][#{attribute_field_counter}][typeC]","format",Admin::AttributeValuesViewHelper::OPT,:class=>"dataType",:selected=>attribute_field["typeC"]["format"] %>
</div>
</div>
<div class="control-group">
<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")%>
</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")%>
</label>
</div>
</div>
<div class="control-group">
<label class="control-label"><%= t("admin.infos.date.claendar")%></label>
<div class="controls">
<label class="radio inline">
<%= radio_button("info[attribute_fields][#{attribute_field_counter}][typeC]", "claendar", "west_claendar",:checked =>(attribute_field["typeC"]["claendar"]== "west_claendar" ? true : false)) %><%= t("admin.infos.date.west_claendar")%>
</label>
<label class="radio inline">
<%= radio_button("info[attribute_fields][#{attribute_field_counter}][typeC]", "claendar", "tw_claendar",:checked =>(attribute_field["typeC"]["claendar"]== "tw_claendar" ? true : false)) %><%= t("admin.infos.date.tw_claendar")%>
</label>
</div>
</div>
<% end %>
<%= content_tag :div,:class=>show_type_panel(attribute_field,"typeD") do%>
<div class="control-group">
<label class="control-label"><%= t("admin.infos.options")%></label>
<div class="controls">
<label class="checkbox inline">
<%= check_box_tag("info[attribute_fields][#{attribute_field_counter}][typeD][multilingual]","true",attribute_field["typeD"]["multilingual"]) %>
<%= t("admin.infos.multilingual")%>
</label>
</div>
</div>
<%= render :partial=> "placeholder_block",:locals=>{:field_name=>"info[attribute_fields][#{attribute_field_counter}][typeD][placeholder]",:values=>attribute_field["typeD"]["placeholder"]} %>
<% end %>
<%= content_tag :div,:class=>show_type_panel(attribute_field,"typeE") do%>
<%= render :partial=>"list_block",:locals=>{:field_name=>"info[attribute_fields][#{attribute_field_counter}][typeE][option_list]",:values=>attribute_field["option_list"]}%>
<% end %>
</div>
<%= hidden_field "info[attribute_fields][#{attribute_field_counter}]","id",:value=>attribute_field.id%>
</div>
@@ -0,0 +1,45 @@
<% temp_field_name = field_name.gsub /\[\D*\]$/,'[temp]'%>
<div class="control-group">
<%= hidden_field_tag "#{temp_field_name}[count]",((values.keys.collect{|t| t.to_i}.max rescue nil) || 0 ),:class=>"list_count"%>
<%= hidden_field_tag "#{temp_field_name}[name]",field_name,:class=>"field_name"%>
<label class="control-label" ><%= t("admin.infos.list")%></label>
<div class="multipleInput">
<%if values.blank? %>
<div class="controls">
<% @site_valid_locales.each do |locale| %>
<% last = (locale == @site_valid_locales.last ? true : false) %>
<% p_value = value[locale.to_s] rescue nil%>
<%= content_tag :div,:class=>"input-append #{"unRadius" if last }" do%>
<%= text_field("#{field_name}[0]", locale,:placeholder=>t("langs.#{locale}")) %>
<% if last %>
<a href="#" class="btn removeInput" type="button"><i class="icon-trash"></i></a>
<% end %>
<% end %>
<% end %>
</div>
<%else%>
<%values.each do |index,value|%>
<div class="controls">
<% @site_valid_locales.each do |locale| %>
<% last = (locale == @site_valid_locales.last ? true : false) %>
<% p_value = value[locale.to_s] rescue nil%>
<%= content_tag :div,:class=>"input-append #{"unRadius" if last }" do%>
<%= text_field("#{field_name}[#{index}]", locale,:value=>p_value,:placeholder=>t("langs.#{locale}")) %>
<% if last %>
<a href="#" class="btn removeInput" type="button"><i class="icon-trash"></i></a>
<% end %>
<% end %>
<% end %>
</div>
<% end %>
<% end %>
</div>
<div class="controls">
<span class="help-block">
<a href="#"><i class="icon-plus-sign"></i><%= t("admin.infos.add") %></a>
</span>
</div>
</div>
@@ -0,0 +1,25 @@
<% values ||=[]%>
<%= content_tag :div,:class=>"control-group language-swich #{class_ext rescue "" }" do%>
<label class="control-label" for=""><%= (defined? label_ext) ? label_ext : t("admin.infos.placeholder") %></label>
<div class="controls">
<div class="tabbable">
<div class="tab-content">
<% @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}")) %>
<% end %>
<% end %>
</div>
<ul class="nav nav-pills ">
<% @site_valid_locales.each do |locale| %>
<% active = (locale == @site_valid_locales.first ? "active" : "'") %>
<%=content_tag :li,:class=>active do %>
<%= link_to t("langs.#{locale}"),"##{name_to_id(field_name)}_#{locale}",:data=>{:toggle=>"tab"}%>
<% end %>
<% end %>
</ul>
</div>
</div>
<% end %>
@@ -0,0 +1,6 @@
$(".attributes").append('<%= escape_javascript(render :partial=>"attribute_field",:locals=>{:attribute_field=>@attribute_field,:attribute_field_counter=>@attribute_field_counter} )%>');
$(".dataType").change(function () {
$(this).parents("legend").next("div").find("div[class^='type']").addClass("hide");
$(this).parents("legend").next("div").find("."+$(this).find("option:selected").attr("ref")).removeClass("hide");
})
@@ -14,7 +14,7 @@
<% end -%>
<%= content_tag :div,:class=>"user-role site-map" do%>
<%= content_tag :div,:class=>"user-role site-map role-block" do%>
<%= form_for @user, :url => admin_users_new_interface_path(@user), :html => { :multipart => true } do |f| %>
<%= f.error_messages %>