2009-01-15 12:14:01 +01:00
|
|
|
class HomeController < ApplicationController
|
2009-01-15 20:10:50 +01:00
|
|
|
helper :messages
|
2009-01-15 12:14:01 +01:00
|
|
|
|
|
|
|
def index
|
2009-01-29 01:57:51 +01:00
|
|
|
@currentOrders = Order.open
|
2009-02-01 20:56:23 +01:00
|
|
|
@ordergroup = @current_user.ordergroup
|
2009-01-15 12:14:01 +01:00
|
|
|
# unaccepted tasks
|
|
|
|
@unaccepted_tasks = @current_user.unaccepted_tasks
|
|
|
|
# task in next week
|
|
|
|
@next_tasks = @current_user.next_tasks
|
2009-04-20 13:54:39 +02:00
|
|
|
@messages = Message.public.all :order => 'created_at DESC', :limit => 5
|
2009-01-15 12:14:01 +01:00
|
|
|
# count tasks with no responsible person
|
|
|
|
# tasks for groups the current user is not a member are ignored
|
|
|
|
tasks = Task.find(:all, :conditions => ["assigned = ? and done = ?", false, false])
|
|
|
|
@unassigned_tasks_number = 0
|
|
|
|
for task in tasks
|
2009-02-06 20:51:14 +01:00
|
|
|
(@unassigned_tasks_number += 1) unless task.workgroup && !current_user.member_of?(task.workgroup)
|
2009-01-15 12:14:01 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def profile
|
|
|
|
@user = @current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_profile
|
|
|
|
@user = @current_user
|
|
|
|
if @user.update_attributes(params[:user])
|
|
|
|
flash[:notice] = 'Änderungen wurden gespeichert.'
|
|
|
|
redirect_to :action => 'profile'
|
|
|
|
else
|
|
|
|
render :action => 'profile'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def ordergroup
|
|
|
|
@user = @current_user
|
2009-02-01 20:56:23 +01:00
|
|
|
@ordergroup = @user.ordergroup
|
2009-01-15 12:14:01 +01:00
|
|
|
|
2009-08-04 13:05:37 +02:00
|
|
|
unless @ordergroup.nil?
|
|
|
|
@ordergroup_column_names = ["Description", "Actual Size", "Balance", "Updated"]
|
|
|
|
@ordergroup_columns = ["description", "account_balance", "account_updated"]
|
2009-01-15 12:14:01 +01:00
|
|
|
|
2009-08-04 13:05:37 +02:00
|
|
|
#listing the financial transactions with ajax...
|
|
|
|
|
|
|
|
if params['sort']
|
|
|
|
sort = case params['sort']
|
|
|
|
when "date" then "created_on"
|
|
|
|
when "note" then "note"
|
|
|
|
when "amount" then "amount"
|
|
|
|
when "date_reverse" then "created_on DESC"
|
|
|
|
when "note_reverse" then "note DESC"
|
|
|
|
when "amount_reverse" then "amount DESC"
|
|
|
|
end
|
2009-01-15 12:14:01 +01:00
|
|
|
else
|
|
|
|
sort = "created_on DESC"
|
|
|
|
end
|
|
|
|
|
2009-08-04 13:05:37 +02:00
|
|
|
# or if somebody uses the search field:
|
|
|
|
conditions = ["note LIKE ?", "%#{params[:query]}%"] unless params[:query].nil?
|
2009-01-15 12:14:01 +01:00
|
|
|
|
2009-08-04 13:05:37 +02:00
|
|
|
@total = @ordergroup.financial_transactions.count(:conditions => conditions)
|
|
|
|
@financial_transactions = @ordergroup.financial_transactions.paginate(:page => params[:page],
|
|
|
|
:per_page => 10,
|
|
|
|
:conditions => conditions,
|
|
|
|
:order => sort)
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # myOrdergroup.haml
|
|
|
|
format.js { render :partial => "finance/transactions/list" }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
flash[:error] = "Leider bist Du kein Mitglied einer Bestellgruppe"
|
|
|
|
redirect_to root_path
|
2009-01-15 12:14:01 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-04 13:05:37 +02:00
|
|
|
# cancel personal memberships direct from the myProfile-page
|
2009-01-15 12:14:01 +01:00
|
|
|
def cancel_membership
|
|
|
|
membership = Membership.find(params[:membership_id])
|
|
|
|
if membership.user == current_user
|
|
|
|
membership.destroy
|
|
|
|
flash[:notice] = "Du bist jetzt kein Mitglied der Gruppe #{@group.name} mehr."
|
|
|
|
else
|
|
|
|
flash[:error] = "Ein Problem ist aufgetreten."
|
|
|
|
end
|
|
|
|
redirect_to my_profile_path
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|