diff --git a/app/controllers/panel/users_controller.rb b/app/controllers/panel/users_controller.rb index 1e67c11be..d0fcdf6c6 100644 --- a/app/controllers/panel/users_controller.rb +++ b/app/controllers/panel/users_controller.rb @@ -22,6 +22,7 @@ class Panel::UsersController < ApplicationController def create @user = User.new(params[:user]) if @user.save + flash[:notice] = t('panel.create_success_user') redirect_to :action => :index else render :action => :new @@ -43,6 +44,7 @@ class Panel::UsersController < ApplicationController @user.avatar = params[:file] if params[:file] if @user.update_attributes(params[:user]) + flash[:notice] = t('panel.update_success_user') redirect_to :action => :index else @user_info_models = UserInfoModel.all.entries @@ -52,8 +54,12 @@ class Panel::UsersController < ApplicationController end def destroy - @user = User.find(params[:id]) - @user.destroy + if params[:id].eql?(session['warden.user.user.key'][1].to_s) + flash[:error] = t('panel.cant_delete_self') + else + @user = User.find(params[:id]) + @user.destroy + end redirect_to :action => :index end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cfda53e6a..2e6db4546 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,11 +1,31 @@ module ApplicationHelper + + FLASH_NOTICE_KEYS = [:error, :notice, :warning] def colorize_in_use_locale(locale) @site_in_use_locales.include?(locale)? 'green' : 'red' end + def flash_messages + return unless messages = flash.keys.select{|k| FLASH_NOTICE_KEYS.include?(k)} + formatted_messages = messages.map do |type| + content_tag :div, :class => type.to_s do + message_for_item(flash[type], flash["#{type}_item".to_sym]) + end + end + raw(formatted_messages.join) + end + def link_back link_to t('back'), session[:last_page] end + def message_for_item(message, item = nil) + if item.is_a?(Array) + message % link_to(*item) + else + message % item + end + end + end diff --git a/app/views/admin/items/index.html.erb b/app/views/admin/items/index.html.erb index 5f0f56ed3..40217fcb5 100644 --- a/app/views/admin/items/index.html.erb +++ b/app/views/admin/items/index.html.erb @@ -12,6 +12,8 @@ <% end -%> +<%= flash_messages %> +

<%= t('admin.list_items') %>: <%= show_parent_items_link unless @parent_item.nil? %>

<% if !Layout.exist_one? %> diff --git a/app/views/admin/layouts/index.html.erb b/app/views/admin/layouts/index.html.erb index c7270cb6b..b0634d3aa 100644 --- a/app/views/admin/layouts/index.html.erb +++ b/app/views/admin/layouts/index.html.erb @@ -4,6 +4,8 @@ <% end -%> +<%= flash_messages %> +

<%= t('admin.list_layouts') %>

diff --git a/app/views/panel/users/_form.html.erb b/app/views/panel/users/_form.html.erb index 1034c8c22..86afefe66 100644 --- a/app/views/panel/users/_form.html.erb +++ b/app/views/panel/users/_form.html.erb @@ -32,7 +32,7 @@ <% end %> -<%= hidden_field_tag :active_roles, @user.active_roles.size > 0 %> +<%= hidden_field_tag :active_roles, (@user.active_roles.size > 0 rescue nil ) %> <% if @user_role_models %>
@@ -14,15 +16,16 @@ -<% @users.each do |user| %> - - - - - + + + + - -<% end %> + <%= link_to t(:delete), panel_user_path(user), :confirm => t('sure?'), :method => :delete %> + + + <% end %>
<%= t('panel.action') %>
<%= user.get_roles %><%= user[:name] %><%= user.email %> + <% @users.each do |user| %> +
<%= user.get_roles %><%= user[:name] %><%= user.email %> <%= link_to t(:show), panel_user_path(user) %> | <%= link_to t(:edit), edit_panel_user_path(user) %> | - <%= link_to t(:delete), panel_user_path(user), :method => :delete %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index b659af5ed..5ac19eead 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -97,6 +97,8 @@ en: panel: action: Action + cant_delete_self: You can not delete yourself. + create_success_user: User was successfully created. email: Email home: Home list_users: Users list @@ -105,5 +107,6 @@ en: new_user: New user infos: Information roles: Roles + update_success_user: User was successfully updated. user: User user_panel: User panel diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index f6495949b..b5fb50cb6 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -94,6 +94,8 @@ zh_tw: panel: action: 行動 + cant_delete_self: 您不可以刪除自己。 + create_success_user: 用戶已成功創建。 email: Email home: 首頁 list_users: 使用清單 @@ -102,6 +104,7 @@ zh_tw: new_user: 新增使用 infos: 資料 roles: 角色 + update_success_user: 用戶已成功更新。 user: 用戶 user_panel: 用戶面板 diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css index 01bf8ab06..e6a5601f1 100644 --- a/public/stylesheets/main.css +++ b/public/stylesheets/main.css @@ -9,4 +9,16 @@ ul.list li{ padding:.5em 0; list-style:none; border-bottom:1px solid #ccc; - } \ No newline at end of file + } + +.error{ + color:red; + } + +.notice, .message{ + color:green; + } + +.warning{ + color:orange; + }