Admin namespace beendet.

This commit is contained in:
benni 2011-06-10 13:22:15 +02:00
parent 6ddef7267a
commit 172db1d37e
23 changed files with 78 additions and 193 deletions

View file

@ -16,8 +16,4 @@ class Admin::OrdergroupsController < Admin::BaseController
format.js { render :layout => false } # index.js.erb
end
end
def memberships
@group = Ordergroup.find(params[:id])
end
end

View file

@ -14,7 +14,11 @@ class Admin::WorkgroupsController < Admin::BaseController
end
end
def memberships
@group = Workgroup.find(params[:id])
def destroy
@workgroup = Workgroup.find(params[:id])
@workgroup.destroy
redirect_to admin_workgroups_url, :notice => "Arbeitsgruppe wurde gelöscht"
rescue => error
redirect_to admin_workgroups_url, :alert => "Arbeitsgruppe konnte nicht gelöscht werden: #{error}"
end
end

View file

@ -5,9 +5,6 @@ class Group < ActiveRecord::Base
has_many :users, :through => :memberships
validates :name, :presence => true, :length => {:in => 1..25}, :uniqueness => true
validate :last_admin_on_earth, :on => :update
before_destroy :check_last_admin_group
attr_reader :user_tokens
@ -25,28 +22,6 @@ class Group < ActiveRecord::Base
self.user_ids = ids.split(",")
end
protected
# Check before destroy a group, if this is the last group with admin role
def check_last_admin_group
if self.role_admin == true && Group.find_all_by_role_admin(true).size == 1
raise "Die letzte Gruppe mit Admin-Rechten darf nicht gelöscht werden"
end
end
# validates uniqueness of the Group.name. Checks groups and ordergroups
def validate
errors.add(:name, "ist schon vergeben") if (group = Group.find_by_name(name) || group = Ordergroup.find_by_name(name)) && self != group
end
# add validation check on update
# Return an error if this is the last group with admin role and role_admin should set to false
def last_admin_on_earth
if self.role_admin == false && Group.find_all_by_role_admin(true).size == 1 && self == Group.find(:first, :conditions => "role_admin = 1")
errors.add(:role_admin, "Der letzten Gruppe mit Admin-Rechten darf die Admin-Rolle nicht entzogen werden")
end
end
end

View file

@ -12,6 +12,7 @@ class Ordergroup < Group
has_many :orders, :through => :group_orders
validates_numericality_of :account_balance, :message => 'ist keine gültige Zahl'
validate :uniqueness_of_members
after_create :update_stats!
@ -79,6 +80,13 @@ class Ordergroup < Group
end
end
# Make sure, that a user can only be in one ordergroup
def uniqueness_of_members
users.each do |user|
errors.add :user_tokens, "#{user.nick} ist schon in einer anderen Bestellgruppe" if user.groups.where(:type => 'Ordergroup').size > 1
end
end
end
# == Schema Information

View file

@ -15,7 +15,7 @@ class User < ActiveRecord::Base
attr_accessor :password, :setting_attributes
validates_presence_of :nick, :email
validates_presence_of :password_hash, :message => "Password is required."
validates_presence_of :password, :on => :create
validates_length_of :nick, :in => 2..25
validates_uniqueness_of :nick, :case_sensitive => false
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i

View file

@ -6,6 +6,9 @@ class Workgroup < Group
validates_presence_of :task_name, :weekday, :task_required_users,
:if => Proc.new {|workgroup| workgroup.weekly_task }
validate :last_admin_on_earth, :on => :update
before_destroy :check_last_admin_group
def self.weekdays
[["Montag", "1"], ["Dienstag", "2"], ["Mittwoch","3"],["Donnerstag","4"],["Freitag","5"],["Samstag","6"],["Sonntag","0"]]
@ -43,6 +46,23 @@ class Workgroup < Group
}
end
protected
# Check before destroy a group, if this is the last group with admin role
def check_last_admin_group
if role_admin && Workgroup.where(:role_admin => true).size == 1
raise "Die letzte Gruppe mit Admin-Rechten darf nicht gelöscht werden"
end
end
# add validation check on update
# Return an error if this is the last group with admin role and role_admin should set to false
def last_admin_on_earth
if !role_admin && Workgroup.where(:role_admin => true, :id.ne => id).empty?
errors.add(:role_admin, "Der letzten Gruppe mit Admin-Rechten darf die Admin-Rolle nicht entzogen werden")
end
end
end
# == Schema Information

View file

@ -21,7 +21,6 @@
%td= link_to_gmaps ordergroup.contact_address
%td= ordergroup.users.size
%td
= link_to icon(:members), memberships_admin_ordergroup_path(ordergroup)
= link_to icon(:edit), edit_admin_ordergroup_path(ordergroup)
= link_to icon(:delete), [:admin, ordergroup], :confirm => "Willst du #{ordergroup.name} wirklich löschen?",
:method => :delete

View file

@ -1,3 +0,0 @@
= render :partial => 'shared/memberships/members'
%p{ :style => "clear:both" }
= link_to 'Gruppenübersicht', admin_ordergroups_path

View file

@ -5,11 +5,9 @@
.column_content
= render :partial => 'shared/group', :locals => { :group => @ordergroup }
%p
= link_to 'Gruppe bearbeiten', edit_admin_ordergroup_path(@ordergroup)
= link_to 'Gruppe/Mitglieder bearbeiten', edit_admin_ordergroup_path(@ordergroup)
|
= link_to 'Löschen', [:admin, @ordergroup], :confirm => 'Bist Du sicher?', :method => :delete
|
= link_to 'Nachricht senden', :controller => 'messages', :action => 'group', :id => @ordergroup
|
= link_to 'Mitglieder bearbeiten', memberships_admin_ordergroup_path(@ordergroup)
= link_to 'Nachricht senden', new_message_path(:message => {:group_id => @ordergroup.id})
%p{:style => "clear:both"}= link_to "Gruppenübersicht", admin_ordergroups_path

View file

@ -4,7 +4,7 @@
.box_title
%h2 Neue Benutzerin
.column_content#userForm
- simple_form_for([:admin, @user]) do |f|
= 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

View file

@ -1,30 +1,10 @@
- form_for [:admin, @workgroup] do |@form|
- render :layout => 'shared/group_form' do
%div{:style => "float:right;width:40%"}
%h3 Gruppe hat Zugriff auf
%table
%tr
%td
= @form.label :role_admin, "Administration"
%td= @form.check_box :role_admin
%tr
%td
= @form.label :role_finance, "Finanzen"
%td= @form.check_box :role_finance
%tr
%td
= @form.label :role_suppliers, "Lieferantenverwaltung"
%td= @form.check_box :role_suppliers
%tr
%td
= @form.label :role_article_meta, "Artikelverwaltung"
%td= @form.check_box :role_article_meta
%tr
%td
= @form.label :role_orders, "Bestellungsverwaltung"
%td= @form.check_box :role_orders
%br{ :style => "clear:both" }
= submit_tag "Speichern"
|
= link_to "Abbrechen", admin_workgroups_path
= simple_form_for [:admin, @workgroup] do |f|
= render :layout => 'shared/group_form_fields', :locals => {:f => f} do
%h3 Zugriff auf ..
= f.input :role_admin
= f.input :role_finance
= f.input :role_suppliers
= f.input :role_article_meta
= f.input :role_orders
= f.submit
= link_to "oder abbrechen", admin_workgroups_path

View file

@ -19,7 +19,6 @@
%td= workgroup.users.size
%td= format_roles(workgroup)
%td
= link_to icon(:members), memberships_admin_workgroup_path(workgroup)
= link_to icon(:edit), edit_admin_workgroup_path(workgroup)
= link_to icon(:delete), [:admin, workgroup], :confirm => 'Willst du ' + workgroup.name + ' wirklich löschen?',
:method => :delete

View file

@ -1,4 +1,3 @@
- title "Arbeitsgruppe bearbeiten"
.edit_form{:style => "width:50em"}
= render :partial => 'form'

View file

@ -1,3 +0,0 @@
= render :partial => 'shared/memberships/members'
%p{ :style => "clear:both" }
= link_to 'Gruppenübersicht', admin_workgroups_path

View file

@ -1,4 +1,3 @@
- title "Erstelle Arbeitsgruppe"
.edit_form{:style => "width:50em"}
= render :partial => 'form'

View file

@ -6,11 +6,9 @@
= render :partial => 'shared/group', :locals => { :group => @workgroup }
%p
= link_to 'Gruppe bearbeiten', edit_admin_workgroup_path(@workgroup)
= link_to 'Gruppe/Mitglieder bearbeiten', edit_admin_workgroup_path(@workgroup)
|
= link_to 'Löschen', [:admin, @workgroup], :confirm => 'Bist Du sicher?', :method => :delete
|
= link_to 'Nachricht senden', :controller => 'messages', :action => 'group', :id => @workgroup
|
= link_to 'Mitglieder bearbeiten', memberships_admin_workgroup_path(@workgroup)
= link_to 'Nachricht senden', new_message_path(:message => {:group_id => @ordergroup.id})
%p{:style => "clear:both"}= link_to "Gruppenübersicht", admin_workgroups_path

View file

@ -1,41 +1,6 @@
- title "Gruppe bearbeiten"
= simple_form_for [:foodcoop, @workgroup] do |f|
= f.input :name
= f.input :description
= f.input :weekly_task
= f.input :weekday, :as => :select, :collection => Workgroup.weekdays, :input_html => {:class => 'weekly_option'}
= f.input :task_name, :input_html => {:class => 'weekly_option'}
= f.input :task_required_users, :input_html => {:class => 'weekly_option'}
= f.input :task_duration, :input_html => {:class => 'weekly_option'}
= f.input :task_description, :input_html => {:class => 'weekly_option'}
= f.input :user_tokens, :as => :string, :input_html => { 'data-pre' => @workgroup.users.map { |u| u.token_attributes }.to_json }
= render :partial => 'shared/group_form_fields', :locals => {:f => f}
= f.submit
= link_to "oder abbrechen", foodcoop_workgroups_path
- content_for :head do
:javascript
function toggleWeeklyTask() {
$('.weekly_option').each(function() {
if ($("#workgroup_weekly_task").is(':checked')) {
$(this).removeAttr('disabled');
} else {
$(this).attr('disabled', 'disabled');
}
});
}
$(function() {
toggleWeeklyTask();
$('#workgroup_weekly_task').click(function() {
toggleWeeklyTask();
})
$("#workgroup_user_tokens").tokenInput("#{users_path(:format => :json)}", {
crossDomain: false,
prePopulate: $("#workgroup_user_tokens").data("pre")
});
})

View file

@ -7,4 +7,3 @@
%td= h(message.sender_name)
%td= format_time(message.created_at)
%td= link_to('Antworten', new_message_path(:message => {:reply_to => message.id}))

View file

@ -1,63 +0,0 @@
= @form.error_messages
%div{:style => "float:left;width:55%;"}
%p
= @form.label :name
%br/
= @form.text_field :name, :size => 20
%p
= @form.label :description
%br/
= @form.text_field :description, :size => 40
= yield
- if @group.is_a?(Workgroup)
%div{:style => "clear:both"}
%h3
Wöchentliche Jobs definieren?
= @form.check_box :weekly_task, {:onclick => "toggleWeeklyTask();"}
%table
%tr
%td
= @form.label :weekday, "Wochentag:"
%td
= @form.select :weekday, Workgroup.weekdays
%tr
%td
= @form.label :task_name, "Dienstname:"
%td= @form.text_field :task_name, :size => 20
%tr
%td
= @form.label :task_required_users, "Benötigte Verantwortliche:"
%td= @form.text_field :task_required_users, :size => 3
%tr
%td
= @form.label :task_duration, "Vor. Dauer in Stunden"
%td= @form.select :task_duration, options_for_select(1..3, @group.task_duration)
%tr
%td
= @form.label :task_description, "Beschreibung:"
%td= @form.text_area :task_description, :size => "30x10"
%script{ 'type' => "text/javascript"}
:plain
//<![CDATA[
// preset data
function toggleWeeklyTask(){
if ($("workgroup_weekly_task").checked == true) {
$('workgroup_weekday').disabled = false;
$('workgroup_task_name').disabled = false;
$('workgroup_task_required_users').disabled = false;
$('workgroup_task_duration').disabled = false;
$('workgroup_task_description').disabled = false;
} else {
$('workgroup_weekday').disabled = true;
$('workgroup_task_name').disabled = true;
$('workgroup_task_required_users').disabled = true;
$('workgroup_task_duration').disabled = true;
$('workgroup_task_description').disabled = true;
}
}
toggleWeeklyTask();
//]]>

View file

@ -4,7 +4,7 @@
= yield
- if f.object.is_a?(Workgroup)
%h3 Wöchentliche Jobs definieren?
%h3 Wöchentliche Jobs
= f.input :weekly_task
#weekly_task_fields
= f.input :weekday
@ -13,13 +13,17 @@
= f.input :task_duration, :as => :select, :collection => (1..3)
= f.input :task_description
= f.input :user_tokens, :as => :string, :input_html => { 'data-pre' => f.object.users.map { |u| u.token_attributes }.to_json }
- content_for :head do
:javascript
function toggleWeeklyTaskFields() {
if ($('#workgroup_weekly_task').attr('checked') == 'checked') {
if ($('#workgroup_weekly_task').is(':checked')) {
$('#weekly_task_fields div.input').show();
$('#weekly_task_fields input').removeAttr('disabled');
} else {
$('#weekly_task_fields div.input').hide();
$('#weekly_task_fields input').attr('disabled', 'disabled');
}
}
@ -27,5 +31,11 @@
toggleWeeklyTaskFields();
$('#workgroup_weekly_task').click(function() {
toggleWeeklyTaskFields();
})
})
});
$("##{f.object.class.to_s.underscore}_user_tokens").tokenInput("#{users_path(:format => :json)}", {
crossDomain: false,
prePopulate: $("##{f.object.class.to_s.underscore}_user_tokens").data("pre")
});
});

View file

@ -220,6 +220,7 @@ de:
ordergroup: 'Bestellgruppe'
amount: 'Betrag'
phone: "Telefon"
user_tokens: 'Mitglieder'
workgroup:
weekly_task: 'Monatlichen Job definieren?'
weekday: 'Wochentag'
@ -227,7 +228,11 @@ de:
task_required_users: 'Benötige Verantwortliche'
task_duration: 'Vor. Dauer in Stunden'
task_description: 'Beschreibung'
user_tokens: 'Mitglieder'
role_admin: "Administration"
role_finance: "Fianzen"
role_suppliers: "Lieferanten"
role_article_meta: "Artikeldatenbank"
role_orders: "Bestellverwaltung"
ordergroup:
contact_person: "Kontaktperson"
contact_phone: "Telefon"

View file

@ -7,6 +7,7 @@
.simple_form div.input {
margin-bottom: 10px;
clear: both;
}
.simple_form div.boolean, .simple_form input[type='submit'] {

View file

@ -3,7 +3,7 @@ ul.token-input-list {
overflow: hidden;
height: auto !important;
height: 1%;
width: 400px;
width: 300px;
border: 1px solid #999;
cursor: text;
font-size: 12px;
@ -13,7 +13,6 @@ ul.token-input-list {
padding: 0;
background-color: #fff;
list-style-type: none;
clear: left;
}
ul.token-input-list li {