Admin/users refactored.
This commit is contained in:
parent
ea6348bc5c
commit
a787b3cf24
10 changed files with 100 additions and 99 deletions
|
@ -1,69 +1,71 @@
|
||||||
class Admin::UsersController < Admin::BaseController
|
class Admin::UsersController < Admin::BaseController
|
||||||
|
inherit_resources
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@users = User.order(:nick.asc)
|
||||||
|
|
||||||
|
# if somebody uses the search field:
|
||||||
|
unless params[:query].blank?
|
||||||
|
@users = @users.where(({:first_name.matches => "%#{params[:query]}%"}) | ({:last_name.matches => "%#{params[:query]}%"}) | ({:nick.matches => "%#{params[:query]}%"}))
|
||||||
|
end
|
||||||
|
|
||||||
|
# sort by nick, thats default
|
||||||
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
|
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
|
||||||
@per_page = params[:per_page].to_i
|
@per_page = params[:per_page].to_i
|
||||||
else
|
else
|
||||||
@per_page = 20
|
@per_page = 20
|
||||||
end
|
end
|
||||||
# if the search field is used
|
|
||||||
conditions = "first_name LIKE '%#{params[:query]}%' OR last_name LIKE '%#{params[:query]}%'" unless params[:query].nil?
|
|
||||||
|
|
||||||
@total = User.count(:conditions => conditions)
|
@users = @users.paginate(:page => params[:page], :per_page => @per_page)
|
||||||
@users = User.paginate :page => params[:page], :conditions => conditions, :per_page => @per_page, :order => 'nick'
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # listUsers.haml
|
format.html # index.html.haml
|
||||||
format.js do
|
format.js { render :layout => false } # index.js.erb
|
||||||
render :update do |page|
|
|
||||||
page.replace_html 'table', :partial => "users"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
# def show
|
||||||
@user = User.find(params[:id])
|
# @user = User.find(params[:id])
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
def new
|
# def new
|
||||||
@user = User.new
|
# @user = User.new
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
def create
|
# def create
|
||||||
@user = User.new(params[:user])
|
# @user = User.new(params[:user])
|
||||||
if @user.save
|
# if @user.save
|
||||||
flash[:notice] = 'Benutzerin wurde erfolgreich angelegt.'
|
# flash[:notice] = 'Benutzerin wurde erfolgreich angelegt.'
|
||||||
redirect_to admin_users_path
|
# redirect_to admin_users_path
|
||||||
else
|
# else
|
||||||
render :action => 'new'
|
# render :action => 'new'
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
def edit
|
# def edit
|
||||||
@user = User.find(params[:id])
|
# @user = User.find(params[:id])
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
def update
|
# def update
|
||||||
@user = User.find(params[:id])
|
# @user = User.find(params[:id])
|
||||||
if @user.update_attributes(params[:user])
|
# if @user.update_attributes(params[:user])
|
||||||
flash[:notice] = 'Änderungen wurden gespeichert.'
|
# flash[:notice] = 'Änderungen wurden gespeichert.'
|
||||||
redirect_to [:admin, @user]
|
# redirect_to [:admin, @user]
|
||||||
else
|
# else
|
||||||
render :action => 'edit'
|
# render :action => 'edit'
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
def destroy
|
# def destroy
|
||||||
user = User.find(params[:id])
|
# user = User.find(params[:id])
|
||||||
if user.nick == @current_user.nick
|
# if user.nick == @current_user.nick
|
||||||
# deny destroying logged-in-user
|
# # deny destroying logged-in-user
|
||||||
flash[:error] = 'Du darfst Dich nicht selbst löschen.'
|
# flash[:error] = 'Du darfst Dich nicht selbst löschen.'
|
||||||
else
|
# else
|
||||||
user.destroy
|
# user.destroy
|
||||||
flash[:notice] = 'Benutzer_in wurde gelöscht.'
|
# flash[:notice] = 'Benutzer_in wurde gelöscht.'
|
||||||
end
|
# end
|
||||||
redirect_to admin_users_path
|
# redirect_to admin_users_path
|
||||||
end
|
# end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,11 +8,6 @@ class Foodcoop::UsersController < ApplicationController
|
||||||
@users = @users.where(({:first_name.matches => "%#{params[:query]}%"}) | ({:last_name.matches => "%#{params[:query]}%"}) | ({:nick.matches => "%#{params[:query]}%"}))
|
@users = @users.where(({:first_name.matches => "%#{params[:query]}%"}) | ({:last_name.matches => "%#{params[:query]}%"}) | ({:nick.matches => "%#{params[:query]}%"}))
|
||||||
end
|
end
|
||||||
|
|
||||||
# sort by ordergroups
|
|
||||||
# if params[:sort_by_ordergroups]
|
|
||||||
# @users = @users.joins(:ordergroup).order(:ordergroup => :name.asc) # Retunr dubbled entries, why?
|
|
||||||
# end
|
|
||||||
|
|
||||||
# sort by nick, thats default
|
# sort by nick, thats default
|
||||||
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
|
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
|
||||||
@per_page = params[:per_page].to_i
|
@per_page = params[:per_page].to_i
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
%td
|
%td
|
||||||
= pagination_links_remote @users
|
= pagination_links_remote @users
|
||||||
%td{:style => "text-align:right"}
|
%td{:style => "text-align:right"}
|
||||||
- if @total > 20
|
- if @users.size > 20
|
||||||
= items_per_page
|
= items_per_page
|
||||||
%table.list
|
%table.list
|
||||||
%thead
|
%thead
|
||||||
|
@ -25,7 +25,6 @@
|
||||||
%td=h format_roles(user)
|
%td=h format_roles(user)
|
||||||
%td=h format_time(user.last_login)
|
%td=h format_time(user.last_login)
|
||||||
%td
|
%td
|
||||||
= link_to(image_tag('b_edit.png', :size => "16x16", :border => "0", :alt => 'Benutzer_in bearbeiten', :title => 'Benutzer_in bearbeiten'), edit_admin_user_path(user))
|
= link_to icon(:edit), edit_admin_user_path(user)
|
||||||
= link_to(image_tag('b_drop.png', :size => "16x16", :border => "0", :alt => 'Benutzer_in löschen', :title => 'Benutzer_in löschen'), |
|
= link_to icon(:delete), [:admin, user], :confirm => "Willst du #{user.name} wirklich löschen?",
|
||||||
[:admin, user], |
|
:method => :delete
|
||||||
:confirm => 'Willst du ' + user.name + ' wirklich löschen?', :method => :delete) |
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
<h1>Benutzerin bearbeiten</h1>
|
|
||||||
<div id="newUser" style="width:65em">
|
|
||||||
<div class="box_title"><h2>Benutzerin bearbeiten</h2></div>
|
|
||||||
<div class="column_content" id="userForm">
|
|
||||||
<% form_for([:admin, @user]) do |@form| %>
|
|
||||||
<%= render :partial => 'shared/user_form' %>
|
|
||||||
<br style="clear:both" />
|
|
||||||
<p>
|
|
||||||
<%= submit_tag 'Speichern' %> | <%= link_to 'Abbrechen', admin_users_path %></p>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
9
app/views/admin/users/edit.html.haml
Normal file
9
app/views/admin/users/edit.html.haml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
%h1 Benutzerin bearbeiten
|
||||||
|
#newUser{:style => "width:65em"}
|
||||||
|
.box_title
|
||||||
|
%h2 Benutzerin bearbeiten
|
||||||
|
#userForm.column_content
|
||||||
|
- simple_form_for([:admin, @user]) do |f|
|
||||||
|
= render :partial => 'shared/user_form_fields', :locals => {:f => f}
|
||||||
|
= f.submit
|
||||||
|
= link_to 'oder abbrechen', admin_users_path
|
|
@ -1,28 +1,18 @@
|
||||||
%h1 Admin/Benutzerinnen
|
- title "Admin/Benutzerinnen"
|
||||||
%p
|
%p
|
||||||
%i
|
%i
|
||||||
Hier kannst du Benutzer_innen
|
Hier kannst du Benutzer_innen
|
||||||
= link_to 'neu Anlegen', new_admin_user_path
|
= link_to 'neu Anlegen', new_admin_user_path
|
||||||
, bearbeiten und natürlich auch löschen.
|
, bearbeiten und natürlich auch löschen.
|
||||||
#newUser{:style => "display:none;"}
|
|
||||||
.box_title
|
|
||||||
%h2 Neue Benutzerinn
|
|
||||||
.column_content#userForm
|
|
||||||
.left_column{:style => "width:100%"}
|
.left_column{:style => "width:100%"}
|
||||||
.box_title
|
.box_title
|
||||||
%h2 Benutzerinnenübersicht
|
%h2 Benutzerinnenübersicht
|
||||||
.column_content
|
.column_content
|
||||||
#user_filter
|
#user_filter{:style => "float:left; margin-right:2em;"}
|
||||||
%form{:name=>"sform", :action=>"", :style=>"display:inline;"}
|
= form_tag admin_users_path, :method => :get, :style=>"display:inline;", :id => 'user_search',
|
||||||
%label{:for => 'article_name'} Suche in Name :
|
:remote => true, 'data-submit-onchange' => true do
|
||||||
= text_field_tag("query", params['query'], :size => 10 )
|
%label{:for => 'article_name'} Suche nach Name:
|
||||||
|
= text_field_tag :query, params[:query], :size => 10
|
||||||
= observe_field 'query', :frequency => 2, |
|
#users
|
||||||
:before => "Element.show('loader')", |
|
|
||||||
:success => "Element.hide('loader')", |
|
|
||||||
:url => admin_users_path, |
|
|
||||||
:with => 'query', |
|
|
||||||
:method => :get |
|
|
||||||
#table
|
|
||||||
= render :partial => "users"
|
= render :partial => "users"
|
||||||
%p= link_to 'Neue Benutzerin', new_admin_user_path
|
%p= link_to 'Neue Benutzerin', new_admin_user_path
|
1
app/views/admin/users/index.js.erb
Normal file
1
app/views/admin/users/index.js.erb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
$('#users').html('<%= escape_javascript(render("users")) %>');
|
|
@ -4,10 +4,8 @@
|
||||||
.box_title
|
.box_title
|
||||||
%h2 Neue Benutzerin
|
%h2 Neue Benutzerin
|
||||||
.column_content#userForm
|
.column_content#userForm
|
||||||
- form_for([:admin, @user]) do |@form|
|
- simple_form_for([:admin, @user]) do |f|
|
||||||
= render :partial => 'shared/user_form'
|
= render :partial => 'shared/user_form_fields', :locals => {:f => f}
|
||||||
%p{:style => "clear:both" }
|
= f.submit
|
||||||
= submit_tag "Speichern"
|
= link_to 'oder abbrechen', admin_users_path
|
||||||
|
|
|
||||||
= link_to('Abbrechen', admin_users_path )
|
|
||||||
%p= link_to 'Benutzerinnenübersicht', admin_users_path
|
%p= link_to 'Benutzerinnenübersicht', admin_users_path
|
13
app/views/shared/_user_form_fields.html.haml
Normal file
13
app/views/shared/_user_form_fields.html.haml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
= f.input :nick
|
||||||
|
= f.input :first_name
|
||||||
|
= f.input :last_name
|
||||||
|
= f.input :email
|
||||||
|
= f.input :phone
|
||||||
|
= f.input :password
|
||||||
|
= f.input :password_confirmation
|
||||||
|
- for setting in User::setting_keys.keys
|
||||||
|
.input.boolean
|
||||||
|
= check_box_tag "user[setting_attributes][#{setting}]",
|
||||||
|
'1', @user.settings[setting] == '1' || @user.settings_default(setting),
|
||||||
|
:class => 'boolean'
|
||||||
|
%label.boolean{:for => "user[setting_attributes][#{setting}]"}= h User::setting_keys[setting]
|
|
@ -211,6 +211,7 @@ de:
|
||||||
# password: 'No special characters, please.'
|
# password: 'No special characters, please.'
|
||||||
labels:
|
labels:
|
||||||
password: 'Passwort'
|
password: 'Passwort'
|
||||||
|
password_confirmation: 'Passwort wiederholen'
|
||||||
description: 'Beschreibung'
|
description: 'Beschreibung'
|
||||||
title: 'Titel'
|
title: 'Titel'
|
||||||
email: 'E-Mail'
|
email: 'E-Mail'
|
||||||
|
@ -218,6 +219,7 @@ de:
|
||||||
date: 'Datum'
|
date: 'Datum'
|
||||||
ordergroup: 'Bestellgruppe'
|
ordergroup: 'Bestellgruppe'
|
||||||
amount: 'Betrag'
|
amount: 'Betrag'
|
||||||
|
phone: "Telefon"
|
||||||
workgroup:
|
workgroup:
|
||||||
weekly_task: 'Monatlichen Job definieren?'
|
weekly_task: 'Monatlichen Job definieren?'
|
||||||
weekday: 'Wochentag'
|
weekday: 'Wochentag'
|
||||||
|
@ -269,6 +271,10 @@ de:
|
||||||
supplier: 'Lieferant'
|
supplier: 'Lieferant'
|
||||||
delivery:
|
delivery:
|
||||||
delivered_on: 'Lieferdatum'
|
delivered_on: 'Lieferdatum'
|
||||||
|
user:
|
||||||
|
nick: "Benutzername"
|
||||||
|
last_name: "Nachname"
|
||||||
|
|
||||||
hints:
|
hints:
|
||||||
tax: 'In Prozent, Standard sind 7,0'
|
tax: 'In Prozent, Standard sind 7,0'
|
||||||
task:
|
task:
|
||||||
|
|
Loading…
Reference in a new issue