diff --git a/app/controllers/admin/users_new_interface_controller.rb b/app/controllers/admin/users_new_interface_controller.rb index d4fb7687..932663ac 100644 --- a/app/controllers/admin/users_new_interface_controller.rb +++ b/app/controllers/admin/users_new_interface_controller.rb @@ -75,16 +75,24 @@ class Admin::UsersNewInterfaceController < ApplicationController def new @user = User.new + @form_index = 0 get_info_and_roles end def create puts params.to_yaml - @user = User.new(params[:user]) + attribute_valuesp_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values' + attribute_values = params[:user].delete(attribute_valuesp_key) + # binding.pry + @user = User.new(params["user"]) + attribute_values.to_hash.each{|key,value| + @user.attribute_values.build(value) + } if @user.save flash[:notice] = t('admin.create_success_user') redirect_to :action => :index else + @form_index = 0 render :action => :new end end diff --git a/app/models/user/attribute_field.rb b/app/models/user/attribute_field.rb index d7b21414..79d0b4d8 100644 --- a/app/models/user/attribute_field.rb +++ b/app/models/user/attribute_field.rb @@ -2,7 +2,7 @@ class AttributeField include Mongoid::Document include Mongoid::Timestamps - include AttributeFieldHelper + include ::AttributeFieldsHelper field :key field :markup diff --git a/app/models/user/user.rb b/app/models/user/user.rb index 59032224..0de35290 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -10,7 +10,7 @@ class User field :admin, :type => Boolean, :default => true field :active_role field :nccu_ldap_uid - + field :email # field :cache_dept # has_one :cache_dept, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy field :cache_dept,type: Hash @@ -37,6 +37,8 @@ class User before_save :check_status_record scope :remote_account, where(:nccu_id.ne => nil) + validates_uniqueness_of :email,:message=> I18n.t("devise.registrations.email_not_unique") + def set_sub_role(sub_role_id,status_id) self.sub_roles << SubRole.find(sub_role_id) diff --git a/app/views/admin/users_new_interface/_form.html.erb b/app/views/admin/users_new_interface/_form.html.erb index c9816391..99a8da04 100644 --- a/app/views/admin/users_new_interface/_form.html.erb +++ b/app/views/admin/users_new_interface/_form.html.erb @@ -16,4 +16,4 @@ <%= render :partial=>"infos"%> - +<%= render :partial=>"roles"%> diff --git a/app/views/admin/users_new_interface/_role.html.erb b/app/views/admin/users_new_interface/_role.html.erb new file mode 100644 index 00000000..4f3c461a --- /dev/null +++ b/app/views/admin/users_new_interface/_role.html.erb @@ -0,0 +1,12 @@ +
<%= @user.email %>
- <%= link_to "TempEdit".html_safe,temp_edit_admin_users_new_interface_path(@user),:class=>"btn btn-small"%> - + <%= link_to "#{t('admin.edit')}".html_safe,edit_admin_users_new_interface_path(@user),:class=>"btn btn-small"%>