2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-03-09 19:27:51 +00:00
|
|
|
class PlatformsController < ApplicationController
|
2011-11-16 18:45:01 +00:00
|
|
|
|
2012-04-01 16:19:54 +01:00
|
|
|
before_filter :authenticate_user!
|
2011-11-24 21:46:19 +00:00
|
|
|
load_and_authorize_resource
|
2012-04-01 16:19:54 +01:00
|
|
|
|
2011-12-01 09:29:04 +00:00
|
|
|
autocomplete :user, :uname
|
2011-10-28 18:55:40 +01:00
|
|
|
|
2011-11-30 14:48:16 +00:00
|
|
|
def build_all
|
2012-02-23 18:32:56 +00:00
|
|
|
@platform.delay.build_all(current_user)
|
2011-11-30 14:48:16 +00:00
|
|
|
|
|
|
|
redirect_to(platform_path(@platform), :notice => t("flash.platform.build_all_success"))
|
|
|
|
end
|
|
|
|
|
2011-03-09 19:27:51 +00:00
|
|
|
def index
|
2012-03-20 16:24:18 +00:00
|
|
|
@platforms = @platforms.accessible_by(current_ability, :related).paginate(:page => params[:page], :per_page => 20)
|
2011-10-27 12:02:25 +01:00
|
|
|
end
|
|
|
|
|
2011-03-09 19:27:51 +00:00
|
|
|
def show
|
2012-04-01 16:19:54 +01:00
|
|
|
|
2011-03-09 19:27:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2011-12-12 15:37:28 +00:00
|
|
|
@admin_uname = current_user.uname
|
|
|
|
@admin_id = current_user.id
|
2011-03-09 19:27:51 +00:00
|
|
|
end
|
2012-03-11 23:08:50 +00:00
|
|
|
|
2011-10-25 14:07:19 +01:00
|
|
|
def edit
|
2011-12-13 13:27:27 +00:00
|
|
|
@admin_id = @platform.owner.id
|
|
|
|
@admin_uname = @platform.owner.uname
|
2011-10-25 14:07:19 +01:00
|
|
|
end
|
2011-03-09 19:27:51 +00:00
|
|
|
|
|
|
|
def create
|
2011-12-12 14:10:39 +00:00
|
|
|
@admin_id = params[:admin_id]
|
2011-12-12 15:37:28 +00:00
|
|
|
@admin_uname = params[:admin_uname]
|
2012-04-01 16:19:54 +01:00
|
|
|
# FIXME: do not allow manipulate owner model, only platforms onwer_id and onwer_type
|
2011-12-12 15:37:28 +00:00
|
|
|
@platform.owner = @admin_id.blank? ? get_owner : User.find(@admin_id)
|
2011-10-17 15:27:07 +01:00
|
|
|
|
2011-12-13 21:48:25 +00:00
|
|
|
if @platform.save
|
2012-03-15 22:56:12 +00:00
|
|
|
flash[:notice] = I18n.t("flash.platform.created")
|
2011-12-13 13:27:27 +00:00
|
|
|
redirect_to @platform
|
|
|
|
else
|
2012-03-15 22:56:12 +00:00
|
|
|
flash[:error] = I18n.t("flash.platform.create_error")
|
2012-04-01 16:19:54 +01:00
|
|
|
flash[:warning] = @platform.errors.full_messages.join('. ')
|
2011-12-13 13:27:27 +00:00
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@admin_id = params[:admin_id]
|
|
|
|
@admin_uname = params[:admin_uname]
|
|
|
|
|
|
|
|
if @platform.update_attributes(
|
|
|
|
:owner => @admin_id.blank? ? get_owner : User.find(@admin_id),
|
|
|
|
:description => params[:platform][:description],
|
2012-04-20 19:55:40 +01:00
|
|
|
:released => (params[:platform][:released] || @platform.released)
|
2011-12-13 13:27:27 +00:00
|
|
|
)
|
|
|
|
flash[:notice] = I18n.t("flash.platform.saved")
|
2011-10-17 15:27:07 +01:00
|
|
|
redirect_to @platform
|
|
|
|
else
|
2011-12-28 02:57:42 +00:00
|
|
|
flash[:error] = I18n.t("flash.platform.save_error")
|
2012-04-01 16:19:54 +01:00
|
|
|
flash[:warning] = @platform.errors.full_messages.join('. ')
|
|
|
|
render :action => :edit
|
2011-10-17 15:27:07 +01:00
|
|
|
end
|
2011-03-09 19:27:51 +00:00
|
|
|
end
|
|
|
|
|
2011-05-30 10:04:32 +01:00
|
|
|
def clone
|
2012-02-21 21:27:11 +00:00
|
|
|
@cloned = Platform.new
|
|
|
|
@cloned.name = @platform.name + "_clone"
|
|
|
|
@cloned.description = @platform.description + "_clone"
|
|
|
|
end
|
|
|
|
|
|
|
|
def make_clone
|
2012-02-22 20:24:29 +00:00
|
|
|
@cloned = @platform.full_clone params[:platform].merge(:owner => current_user)
|
|
|
|
if @cloned.persisted?
|
2012-02-21 21:27:11 +00:00
|
|
|
flash[:notice] = I18n.t("flash.platform.clone_success")
|
|
|
|
redirect_to @cloned
|
2011-05-30 10:04:32 +01:00
|
|
|
else
|
2012-02-21 21:27:11 +00:00
|
|
|
flash[:error] = @cloned.errors.full_messages.join('. ')
|
|
|
|
render 'clone'
|
2011-05-30 10:04:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-09 19:27:51 +00:00
|
|
|
def destroy
|
2012-02-22 12:35:40 +00:00
|
|
|
@platform.delay.destroy if @platform
|
2011-03-31 03:00:21 +01:00
|
|
|
|
|
|
|
flash[:notice] = t("flash.platform.destroyed")
|
2012-03-15 22:56:12 +00:00
|
|
|
redirect_to platforms_path
|
2011-03-09 19:27:51 +00:00
|
|
|
end
|
2012-03-20 16:24:18 +00:00
|
|
|
|
|
|
|
def members
|
|
|
|
@members = @platform.members.order('name')
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_members
|
|
|
|
all_user_ids = params['user_remove'].inject([]) {|a, (k, v)| a << k if v.first == '1'; a}
|
|
|
|
all_user_ids.each do |uid|
|
2012-04-26 02:38:33 +01:00
|
|
|
Relation.by_target(@platform).where(:actor_id => uid, :actor_type => 'User').each{|r| r.destroy}
|
2012-03-20 16:24:18 +00:00
|
|
|
end
|
|
|
|
redirect_to members_platform_path(@platform)
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_member
|
|
|
|
u = User.find(params[:member_id])
|
2012-04-26 02:38:33 +01:00
|
|
|
Relation.by_actor(u).by_target(@platform).each{|r| r.destroy}
|
2012-03-20 16:24:18 +00:00
|
|
|
|
|
|
|
redirect_to members_platform_path(@platform)
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_member
|
|
|
|
if params[:member_id].present?
|
|
|
|
member = User.find(params[:member_id])
|
2012-04-26 02:38:33 +01:00
|
|
|
if @platform.relations.exists?(:actor_id => member.id, :actor_type => member.class.to_s) or @platform.owner == member
|
2012-03-20 16:24:18 +00:00
|
|
|
flash[:warning] = t('flash.platform.members.already_added', :name => member.uname)
|
|
|
|
else
|
|
|
|
rel = @platform.relations.build(:role => 'admin')
|
2012-04-26 02:38:33 +01:00
|
|
|
rel.actor = member
|
2012-03-20 16:24:18 +00:00
|
|
|
if rel.save
|
|
|
|
flash[:notice] = t('flash.platform.members.successfully_added', :name => member.uname)
|
|
|
|
else
|
|
|
|
flash[:error] = t('flash.platform.members.error_in_adding', :name => member.uname)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
redirect_to members_platform_url(@platform)
|
|
|
|
end
|
|
|
|
|
2011-03-09 19:27:51 +00:00
|
|
|
end
|