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
|
||||
inherit_resources
|
||||
|
||||
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)
|
||||
@per_page = params[:per_page].to_i
|
||||
else
|
||||
@per_page = 20
|
||||
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 = User.paginate :page => params[:page], :conditions => conditions, :per_page => @per_page, :order => 'nick'
|
||||
@users = @users.paginate(:page => params[:page], :per_page => @per_page)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # listUsers.haml
|
||||
format.js do
|
||||
render :update do |page|
|
||||
page.replace_html 'table', :partial => "users"
|
||||
end
|
||||
end
|
||||
format.html # index.html.haml
|
||||
format.js { render :layout => false } # index.js.erb
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
@user = User.new
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.new(params[:user])
|
||||
if @user.save
|
||||
flash[:notice] = 'Benutzerin wurde erfolgreich angelegt.'
|
||||
redirect_to admin_users_path
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@user = User.find(params[:id])
|
||||
if @user.update_attributes(params[:user])
|
||||
flash[:notice] = 'Änderungen wurden gespeichert.'
|
||||
redirect_to [:admin, @user]
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
user = User.find(params[:id])
|
||||
if user.nick == @current_user.nick
|
||||
# deny destroying logged-in-user
|
||||
flash[:error] = 'Du darfst Dich nicht selbst löschen.'
|
||||
else
|
||||
user.destroy
|
||||
flash[:notice] = 'Benutzer_in wurde gelöscht.'
|
||||
end
|
||||
redirect_to admin_users_path
|
||||
end
|
||||
# def show
|
||||
# @user = User.find(params[:id])
|
||||
# end
|
||||
#
|
||||
# def new
|
||||
# @user = User.new
|
||||
# end
|
||||
#
|
||||
# def create
|
||||
# @user = User.new(params[:user])
|
||||
# if @user.save
|
||||
# flash[:notice] = 'Benutzerin wurde erfolgreich angelegt.'
|
||||
# redirect_to admin_users_path
|
||||
# else
|
||||
# render :action => 'new'
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def edit
|
||||
# @user = User.find(params[:id])
|
||||
# end
|
||||
#
|
||||
# def update
|
||||
# @user = User.find(params[:id])
|
||||
# if @user.update_attributes(params[:user])
|
||||
# flash[:notice] = 'Änderungen wurden gespeichert.'
|
||||
# redirect_to [:admin, @user]
|
||||
# else
|
||||
# render :action => 'edit'
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def destroy
|
||||
# user = User.find(params[:id])
|
||||
# if user.nick == @current_user.nick
|
||||
# # deny destroying logged-in-user
|
||||
# flash[:error] = 'Du darfst Dich nicht selbst löschen.'
|
||||
# else
|
||||
# user.destroy
|
||||
# flash[:notice] = 'Benutzer_in wurde gelöscht.'
|
||||
# end
|
||||
# redirect_to admin_users_path
|
||||
# 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]}%"}))
|
||||
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
|
||||
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
|
||||
@per_page = params[:per_page].to_i
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
%td
|
||||
= pagination_links_remote @users
|
||||
%td{:style => "text-align:right"}
|
||||
- if @total > 20
|
||||
- if @users.size > 20
|
||||
= items_per_page
|
||||
%table.list
|
||||
%thead
|
||||
|
@ -25,7 +25,6 @@
|
|||
%td=h format_roles(user)
|
||||
%td=h format_time(user.last_login)
|
||||
%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(image_tag('b_drop.png', :size => "16x16", :border => "0", :alt => 'Benutzer_in löschen', :title => 'Benutzer_in löschen'), |
|
||||
[:admin, user], |
|
||||
:confirm => 'Willst du ' + user.name + ' wirklich löschen?', :method => :delete) |
|
||||
= link_to icon(:edit), edit_admin_user_path(user)
|
||||
= link_to icon(:delete), [:admin, user], :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
|
||||
%i
|
||||
Hier kannst du Benutzer_innen
|
||||
= link_to 'neu Anlegen', new_admin_user_path
|
||||
, bearbeiten und natürlich auch löschen.
|
||||
#newUser{:style => "display:none;"}
|
||||
.box_title
|
||||
%h2 Neue Benutzerinn
|
||||
.column_content#userForm
|
||||
.left_column{:style => "width:100%"}
|
||||
.box_title
|
||||
%h2 Benutzerinnenübersicht
|
||||
.column_content
|
||||
#user_filter
|
||||
%form{:name=>"sform", :action=>"", :style=>"display:inline;"}
|
||||
%label{:for => 'article_name'} Suche in Name :
|
||||
= text_field_tag("query", params['query'], :size => 10 )
|
||||
|
||||
= observe_field 'query', :frequency => 2, |
|
||||
:before => "Element.show('loader')", |
|
||||
:success => "Element.hide('loader')", |
|
||||
:url => admin_users_path, |
|
||||
:with => 'query', |
|
||||
:method => :get |
|
||||
#table
|
||||
#user_filter{:style => "float:left; margin-right:2em;"}
|
||||
= form_tag admin_users_path, :method => :get, :style=>"display:inline;", :id => 'user_search',
|
||||
:remote => true, 'data-submit-onchange' => true do
|
||||
%label{:for => 'article_name'} Suche nach Name:
|
||||
= text_field_tag :query, params[:query], :size => 10
|
||||
#users
|
||||
= render :partial => "users"
|
||||
%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
|
||||
%h2 Neue Benutzerin
|
||||
.column_content#userForm
|
||||
- form_for([:admin, @user]) do |@form|
|
||||
= render :partial => 'shared/user_form'
|
||||
%p{:style => "clear:both" }
|
||||
= submit_tag "Speichern"
|
||||
|
|
||||
= link_to('Abbrechen', admin_users_path )
|
||||
- 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
|
||||
%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.'
|
||||
labels:
|
||||
password: 'Passwort'
|
||||
password_confirmation: 'Passwort wiederholen'
|
||||
description: 'Beschreibung'
|
||||
title: 'Titel'
|
||||
email: 'E-Mail'
|
||||
|
@ -218,6 +219,7 @@ de:
|
|||
date: 'Datum'
|
||||
ordergroup: 'Bestellgruppe'
|
||||
amount: 'Betrag'
|
||||
phone: "Telefon"
|
||||
workgroup:
|
||||
weekly_task: 'Monatlichen Job definieren?'
|
||||
weekday: 'Wochentag'
|
||||
|
@ -269,6 +271,10 @@ de:
|
|||
supplier: 'Lieferant'
|
||||
delivery:
|
||||
delivered_on: 'Lieferdatum'
|
||||
user:
|
||||
nick: "Benutzername"
|
||||
last_name: "Nachname"
|
||||
|
||||
hints:
|
||||
tax: 'In Prozent, Standard sind 7,0'
|
||||
task:
|
||||
|
|
Loading…
Reference in a new issue