2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-03-10 11:35:46 +00:00
|
|
|
class ProjectsController < ApplicationController
|
2012-03-07 21:34:49 +00:00
|
|
|
before_filter :authenticate_user!
|
2011-11-23 15:52:33 +00:00
|
|
|
load_and_authorize_resource
|
2011-03-10 13:38:50 +00:00
|
|
|
|
2011-10-26 21:57:51 +01:00
|
|
|
def index
|
2012-03-07 21:34:49 +00:00
|
|
|
@projects = current_user.projects.paginate(:page => params[:project_page])
|
|
|
|
@projects = @projects.search(params[:query]).search_order if params[:query]
|
2011-03-10 14:20:09 +00:00
|
|
|
end
|
|
|
|
|
2011-10-26 21:57:51 +01:00
|
|
|
def new
|
|
|
|
@project = Project.new
|
2012-02-29 14:45:04 +00:00
|
|
|
@who_owns = :me
|
2011-10-26 21:57:51 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@project = Project.new params[:project]
|
2012-02-27 09:03:28 +00:00
|
|
|
@project.owner = choose_owner
|
2012-02-29 14:45:04 +00:00
|
|
|
@who_owns = (@project.owner_type == 'User' ? :me : :group)
|
2011-10-26 21:57:51 +01:00
|
|
|
|
2011-11-30 12:58:14 +00:00
|
|
|
if @project.save
|
2011-10-26 21:57:51 +01:00
|
|
|
flash[:notice] = t('flash.project.saved')
|
2011-10-27 23:43:44 +01:00
|
|
|
redirect_to @project
|
2011-10-26 21:57:51 +01:00
|
|
|
else
|
|
|
|
flash[:error] = t('flash.project.save_error')
|
2012-03-03 01:05:19 +00:00
|
|
|
flash[:warning] = @project.errors.full_messages.join('. ')
|
2011-10-26 21:57:51 +01:00
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if @project.update_attributes(params[:project])
|
|
|
|
flash[:notice] = t('flash.project.saved')
|
2011-10-27 23:43:44 +01:00
|
|
|
redirect_to @project
|
2011-10-26 21:57:51 +01:00
|
|
|
else
|
2011-11-30 12:58:14 +00:00
|
|
|
@project.save
|
2011-10-26 21:57:51 +01:00
|
|
|
flash[:error] = t('flash.project.save_error')
|
|
|
|
render :action => :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@project.destroy
|
|
|
|
flash[:notice] = t("flash.project.destroyed")
|
2011-10-27 13:49:21 +01:00
|
|
|
redirect_to @project.owner
|
2011-10-26 21:57:51 +01:00
|
|
|
end
|
|
|
|
|
2011-11-23 15:52:33 +00:00
|
|
|
def fork
|
2011-11-29 21:42:58 +00:00
|
|
|
if forked = @project.fork(current_user) and forked.valid?
|
|
|
|
redirect_to forked, :notice => t("flash.project.forked")
|
|
|
|
else
|
|
|
|
flash[:warning] = t("flash.project.fork_error")
|
|
|
|
flash[:error] = forked.errors.full_messages
|
|
|
|
redirect_to @project
|
|
|
|
end
|
2011-11-23 15:52:33 +00:00
|
|
|
end
|
|
|
|
|
2012-02-28 07:59:38 +00:00
|
|
|
def sections
|
|
|
|
if request.post?
|
|
|
|
if @project.update_attributes(params[:project])
|
|
|
|
flash[:notice] = t('flash.project.saved')
|
|
|
|
else
|
|
|
|
@project.save
|
|
|
|
flash[:error] = t('flash.project.save_error')
|
|
|
|
end
|
|
|
|
render :action => :sections
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-07 21:34:49 +00:00
|
|
|
def remove_user
|
|
|
|
@project.relations.by_object(current_user).destroy_all
|
|
|
|
flash[:notice] = t("flash.project.user_removed")
|
|
|
|
redirect_to projects_path
|
|
|
|
end
|
2011-10-17 15:21:29 +01:00
|
|
|
|
2012-03-07 21:34:49 +00:00
|
|
|
protected
|
2012-02-27 09:03:28 +00:00
|
|
|
|
2012-03-07 21:34:49 +00:00
|
|
|
def choose_owner
|
|
|
|
if params[:who_owns] == 'group'
|
|
|
|
Group.find(params[:owner_id])
|
|
|
|
else
|
|
|
|
current_user
|
2012-02-27 09:03:28 +00:00
|
|
|
end
|
2012-03-07 21:34:49 +00:00
|
|
|
end
|
2011-03-10 11:35:46 +00:00
|
|
|
end
|