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 %>