[closed #20] Changed adding collaborators to project

Changed collaborators page of project:
  *  Added form to input group and/or project nickname.
  *  In tables show only projects/groups that already added to project
This commit is contained in:
George Vinogradov 2011-12-12 03:42:13 +04:00
parent 5e3711505c
commit 55ebb648f5
6 changed files with 68 additions and 4 deletions

View File

@ -82,6 +82,41 @@ class CollaboratorsController < ApplicationController
def destroy
end
def add
# TODO: Here is used Chelyabinsk method to display Flash messages.
member = User.find_by_uname(params['member_uname']) if params['member_uname'] && !params['member_uname'].empty?
group = Group.find_by_uname(params['group_uname']) if params['group_uname'] && !params['group_uname'].empty?
flash[:notice], flash[:error], flash[:warning] = [], [], []
[member, group].compact.each do |mem|
if mem and @project.relations.exists?(:object_id => mem.id, :object_type => mem.class.to_s)
flash[:warning] << [t('flash.collaborators.member_already_added'), mem.uname]
end
unless @project.relations.exists?(:object_id => mem.id, :object_type => mem.class.to_s)
rel = @project.relations.build(:role => 'reader')
rel.object = mem
if rel.save
flash[:notice] << [t('flash.collaborators.successfully_added'), mem.uname]
else
flash[:notice] << [t('flash.collaborators.error_in_adding'), mem.uname]
end
end
end
[:notice, :warning, :error].each do |k|
if flash[k].size > 0
flash[k] = flash[k].map{|i| (i.is_a? Array) ? sprintf(i.first, i.last) : i}.join('; ')
else
flash[k] = nil
end
end
flash.delete_if{|k, v| v.nil?}
redirect_to(edit_project_collaborators_path(@project))
end
protected
def find_project
@ -89,10 +124,10 @@ class CollaboratorsController < ApplicationController
end
def find_users
@users = User.all
@users = @project.collaborators#User.all
end
def find_groups
@groups = Group.all
@groups = @project.groups#Group.all
end
end

View File

@ -8,6 +8,7 @@ class GroupsController < ApplicationController
before_filter :find_group, :only => [:show, :edit, :update, :destroy]
load_and_authorize_resource
autocomplete :group, :uname
def index
puts parent.inspect

View File

@ -4,6 +4,7 @@ class UsersController < ApplicationController
before_filter :find_user, :only => [:show, :edit, :update, :destroy]
load_and_authorize_resource
autocomplete :user, :uname
def index
@users = User.paginate(:page => params[:user_page])

View File

@ -5,6 +5,23 @@
%li.active= link_to t("layout.collaborators.edit"), edit_project_collaborators_path(@project)
.content
.inner
= form_tag add_project_collaborators_path(@project) do
= javascript_include_tag 'autocomplete-rails.js'
.group
%h2.title= t("layout.collaborators.add")
= label_tag "member_uname", t("layout.collaborators.input_username")
= autocomplete_field_tag 'member_uname', params[:member_uname], autocomplete_user_uname_users_path
&nbsp;
= t('layout.or')
&nbsp;
= label_tag "group_uname", t("layout.collaborators.input_groupname")
= autocomplete_field_tag 'group_uname', params[:group_uname], autocomplete_group_uname_groups_path
%br
.group.navform.wat-cf
%button.button{:type => "submit"}
= image_tag("web-app-theme/icons/tick.png", :alt => t("layout.add"))
= t("layout.add")
= form_tag project_collaborators_path(@project) do
%h2.title= t("layout.users.list_header")
%table.table
@ -31,8 +48,8 @@
%tr
%th.first ID
%th= t("activerecord.attributes.group.name")
%th= t("activerecord.attributes.group.roles")
%th= t("activerecord.attributes.group.uname")
%th.last= t("layout.collaborators.add")
- @groups.each do |group|
%tr{:class => cycle("odd", "even")}
%td

View File

@ -222,6 +222,8 @@ ru:
edit_roles: Редактировать роли
roles_header: Роли для
add_role: Добавить/Удалить роль
input_username: Введите псевдоним пользователя
input_groupname: Введите псевдоним группы
members:
back_to_group: Вернуться к группе
@ -327,6 +329,10 @@ ru:
collaborators:
successfully_changed: Список коллабораторов успешно изменен
error_in_changing: Ошибка изменения списка коллабораторов
member_already_added: Участник %s уже добавлен
group_already_added: Группа уже добавлена
successfully_added: Участник %s успешно добавлен
error_in_adding: Ошибка при добавлении участника %s
members:
successfully_changed: Список участников успешно изменен

View File

@ -8,6 +8,7 @@ Rosa::Application.routes.draw do
resources :users do
resources :groups, :only => [:new, :create, :index]
get :autocomplete_user_uname, :on => :collection
end
resources :event_logs, :only => :index
@ -78,10 +79,11 @@ Rosa::Application.routes.draw do
end
end
resources :collaborators, :only => [:index, :edit, :update] do
resources :collaborators, :only => [:index, :edit, :update, :add] do
collection do
get :edit
post :update
post :add
end
member do
post :update
@ -108,6 +110,8 @@ Rosa::Application.routes.draw do
end
resources :groups do
get :autocomplete_group_uname, :on => :collection
resources :members, :only => [:index, :edit, :update] do
collection do
get :edit