From beb843f75b90e3df9c0e7182000af8938045b77a Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Sun, 4 Nov 2012 05:56:29 +0800 Subject: [PATCH] add new member with role interface. add more not usable. role management new attribute is ok. delete is ok. --- app/assets/stylesheets/member.css | 28 +- app/assets/stylesheets/site-map.css | 47 ++- app/controllers/admin/infos_controller.rb | 15 +- .../admin/users_new_interface_controller.rb | 2 +- .../admin/attribute_values_view_helper.rb | 16 + app/helpers/attribute_fields_helper.rb | 109 ++++-- app/models/user/attribute.rb | 1 + app/models/user/attribute_field.rb | 102 +++-- app/models/user/attribute_value.rb | 100 +++-- app/models/user/user.rb | 3 +- app/views/admin/attributes/edit.html.erb | 149 ++++++- .../admin/infos/_attribute_field.html.erb | 103 ++++- app/views/admin/infos/_list_block.html.erb | 45 +++ .../admin/infos/_placeholder_block.html.erb | 25 ++ .../admin/infos/add_attribute_field.js.erb | 6 + .../admin/users_new_interface/edit.html.erb | 2 +- config/list.yml | 6 + config/locales/en.yml | 8 + config/locales/zh_tw.yml | 32 +- spec/helpers/attribute_fields_helper_spec.rb | 78 ++++ spec/models/app_auth_basic.rb | 368 +++++++++--------- spec/models/app_auth_spec.rb | 140 +++---- spec/models/attribute_value_spec.rb | 63 +++ spec/models/role_spec.rb | 222 +++++------ spec/spec_helper.rb | 1 + 25 files changed, 1159 insertions(+), 512 deletions(-) create mode 100644 app/helpers/admin/attribute_values_view_helper.rb create mode 100644 app/views/admin/infos/_list_block.html.erb create mode 100644 app/views/admin/infos/_placeholder_block.html.erb create mode 100644 app/views/admin/infos/add_attribute_field.js.erb create mode 100644 spec/helpers/attribute_fields_helper_spec.rb create mode 100644 spec/models/attribute_value_spec.rb diff --git a/app/assets/stylesheets/member.css b/app/assets/stylesheets/member.css index 436a9b6a..add8774a 100644 --- a/app/assets/stylesheets/member.css +++ b/app/assets/stylesheets/member.css @@ -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; } \ No newline at end of file diff --git a/app/assets/stylesheets/site-map.css b/app/assets/stylesheets/site-map.css index d7d3cda6..53e94c1f 100644 --- a/app/assets/stylesheets/site-map.css +++ b/app/assets/stylesheets/site-map.css @@ -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; +} diff --git a/app/controllers/admin/infos_controller.rb b/app/controllers/admin/infos_controller.rb index 5ffa6a06..cec5c5f4 100644 --- a/app/controllers/admin/infos_controller.rb +++ b/app/controllers/admin/infos_controller.rb @@ -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 diff --git a/app/controllers/admin/users_new_interface_controller.rb b/app/controllers/admin/users_new_interface_controller.rb index 0609fef0..1d5833d8 100644 --- a/app/controllers/admin/users_new_interface_controller.rb +++ b/app/controllers/admin/users_new_interface_controller.rb @@ -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 diff --git a/app/helpers/admin/attribute_values_view_helper.rb b/app/helpers/admin/attribute_values_view_helper.rb new file mode 100644 index 00000000..9a724c96 --- /dev/null +++ b/app/helpers/admin/attribute_values_view_helper.rb @@ -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 \ No newline at end of file diff --git a/app/helpers/attribute_fields_helper.rb b/app/helpers/attribute_fields_helper.rb index 5e0cf290..323d26a3 100644 --- a/app/helpers/attribute_fields_helper.rb +++ b/app/helpers/attribute_fields_helper.rb @@ -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 = '
'.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 << "
" result << "
" + 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 << "
" result << "