From 7901de7b31852dc54e37cc87363de1a81d0bf91b Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Mon, 15 Oct 2012 13:54:29 +0800 Subject: [PATCH] can add member --- .../admin/users_new_interface_controller.rb | 10 ++++++- app/models/user/attribute_field.rb | 2 +- app/models/user/user.rb | 4 ++- .../admin/users_new_interface/_form.html.erb | 2 +- .../admin/users_new_interface/_role.html.erb | 12 +++++++++ .../admin/users_new_interface/_roles.html.erb | 1 + .../users_new_interface/_user_basic.html.erb | 26 +++++++++++++++++++ .../admin/users_new_interface/new.html.erb | 26 +++++++++++++++++++ .../admin/users_new_interface/show.html.erb | 3 +-- config/locales/devise.zh_tw.yml | 1 + config/locales/zh_tw.yml | 5 ++++ 11 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 app/views/admin/users_new_interface/_role.html.erb create mode 100644 app/views/admin/users_new_interface/_roles.html.erb create mode 100644 app/views/admin/users_new_interface/_user_basic.html.erb create mode 100644 app/views/admin/users_new_interface/new.html.erb diff --git a/app/controllers/admin/users_new_interface_controller.rb b/app/controllers/admin/users_new_interface_controller.rb index d4fb76876..932663ace 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 d7b21414c..79d0b4d80 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 59032224a..0de352907 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 c9816391e..99a8da048 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 000000000..4f3c461a3 --- /dev/null +++ b/app/views/admin/users_new_interface/_role.html.erb @@ -0,0 +1,12 @@ +
+

<%= role.title %>

+
+ + <% role.attribute_fields.each do |af|%> + <%= af.block_helper(@user,@form_index)%> + <% @form_index = @form_index +1 %> + <% end %> + + +
+
\ No newline at end of file diff --git a/app/views/admin/users_new_interface/_roles.html.erb b/app/views/admin/users_new_interface/_roles.html.erb new file mode 100644 index 000000000..794935e9d --- /dev/null +++ b/app/views/admin/users_new_interface/_roles.html.erb @@ -0,0 +1 @@ +<%=render :partial=>"role",:collection=>Role.all%> \ No newline at end of file diff --git a/app/views/admin/users_new_interface/_user_basic.html.erb b/app/views/admin/users_new_interface/_user_basic.html.erb new file mode 100644 index 000000000..3ce900b70 --- /dev/null +++ b/app/views/admin/users_new_interface/_user_basic.html.erb @@ -0,0 +1,26 @@ + <%#= devise_error_messages! %> + +
+

<%=t('admin.user_new_interface.sys_basic_form')%>

+
+
+ <%= f.label t('admin.user_new_interface.email'),:class=>"control-label" %>
+
+ <%= f.email_field :email %> +
+
+
+ <%= f.label t('admin.user_new_interface.password'),:class=>"control-label" %> +
+ <%= f.password_field :password %> +
+
+
+ <%= f.label t('admin.user_new_interface.password_confirmation'),:class=>"control-label" %> +
+
+ <%= f.password_field :password_confirmation %> +
+
+
+
\ No newline at end of file diff --git a/app/views/admin/users_new_interface/new.html.erb b/app/views/admin/users_new_interface/new.html.erb new file mode 100644 index 000000000..68420f499 --- /dev/null +++ b/app/views/admin/users_new_interface/new.html.erb @@ -0,0 +1,26 @@ +<% content_for :page_specific_css do -%> + <%= stylesheet_link_tag "member" %> + <%= stylesheet_link_tag "site-map" %> + <%= stylesheet_link_tag "isotope" %> +<% end -%> +<% content_for :page_specific_javascript do -%> + <%= javascript_include_tag "/static/jquery.cycle.all.latest.js" %> + <%= javascript_include_tag "inc/modal-preview" %> + <%= javascript_include_tag "lib/contenteditable" %> +<% end -%> + + +<%= content_tag :div,:class=>"user-role site-map" do%> + <%= form_for @user, :url => admin_users_new_interface_index_path, :html => { :multipart => true },:method => :post do |f| %> + + <%= f.error_messages %> + <%= render :partial => 'user_basic', :locals => {:f => f}%> + <%= render :partial => 'form', :locals => { :f => f } %> +
+ <%#= link_back %> + <%#= link_to t('update'), "#", :onclick=>"$('#edit_user_#{@user.id}').submit()" %> + <%= f.submit%> +
+ <% end -%> + +<% end -%> \ No newline at end of file diff --git a/app/views/admin/users_new_interface/show.html.erb b/app/views/admin/users_new_interface/show.html.erb index 0299c34fc..e2840e15a 100644 --- a/app/views/admin/users_new_interface/show.html.erb +++ b/app/views/admin/users_new_interface/show.html.erb @@ -34,8 +34,7 @@

<%= @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"%>
diff --git a/config/locales/devise.zh_tw.yml b/config/locales/devise.zh_tw.yml index 4cb8c3170..d825f92e0 100644 --- a/config/locales/devise.zh_tw.yml +++ b/config/locales/devise.zh_tw.yml @@ -30,6 +30,7 @@ zh_tw: signed_up: '您已經成功的登錄,確認信件已送至您的 Email 信箱。' updated: '您已經成功的更新帳號資訊。' destroyed: '再會!您的帳號已被取消。有緣再會。' + email_not_unique: '已被註冊' unlocks: send_instructions: '您將在幾分鐘後收到一封電子郵件,內有將帳號解除鎖定的步驟說明。' unlocked: '您的帳號已被解鎖,現在您已成功登入。' diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index ff07a5f65..3fa4029fd 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -311,6 +311,11 @@ zh_tw: upload_design: 上傳設計 url: URL user: 用戶 + user_new_interface: + sys_basic_form: 系統基本資料表 + password: 密碼 + password_confirmation: 確認密碼 + email: 使用者帳號信箱 user_role: auth: all_member: 所有會員