[refs #12] Add platform update options

This commit is contained in:
konstantin.grabar 2011-12-13 17:27:27 +04:00
parent 222033de5e
commit 4a723369a2
5 changed files with 46 additions and 12 deletions

View File

@ -50,6 +50,8 @@ class PlatformsController < ApplicationController
end
def edit
@admin_id = @platform.owner.id
@admin_uname = @platform.owner.uname
end
def create
@ -68,6 +70,26 @@ class PlatformsController < ApplicationController
end
end
def update
@admin_id = params[:admin_id]
@admin_uname = params[:admin_uname]
#@platform.owner = @admin_id.blank? ? get_owner : User.find(@admin_id)
#if @platform.save!
if @platform.update_attributes(
:owner => @admin_id.blank? ? get_owner : User.find(@admin_id),
:description => params[:platform][:description],
:released => params[:platform][:released]
)
#@platform.make_admin_relation(@admin_id)
flash[:notice] = I18n.t("flash.platform.saved")
redirect_to @platform
else
flash[:error] = I18n.t("flash.platform.saved_error")
render :action => :new
end
end
def freeze
@platform.released = true
if @platform.save

View File

@ -24,6 +24,7 @@ class Platform < ActiveRecord::Base
# before_update :check_freezing
after_create lambda { mount_directory_for_rsync unless hidden? }
after_destroy lambda { umount_directory_for_rsync unless hidden? }
after_update :update_owner_relation
scope :by_visibilities, lambda {|v| {:conditions => ['visibility in (?)', v.join(',')]}}
scope :open, where(:visibility => 'open')
@ -130,9 +131,16 @@ class Platform < ActiveRecord::Base
#FileUtils.mkdir_p "#{ Rails.root.join('tmp', 'umount', name) }"
end
def make_admin_relation(user_id)
r = self.relations.build :object_id => user_id, :object_type => 'User', :role => 'admin'
r.save
#def make_admin_relation(user_id)
# r = self.relations.build :object_id => user_id, :object_type => 'User', :role => 'admin'
# r.save
#end
def update_owner_relation
if owner_id_was != owner_id
r = relations.where(:object_id => owner_id_was, :object_type => owner_type_was)[0]
r.update_attributes(:object_id => owner_id, :object_type => owner_type)
end
end
protected

View File

@ -1,20 +1,22 @@
= javascript_include_tag "autocomplete-rails.js"
.group
= f.label :name, :class => :label
= f.text_field :name, :class => 'text_field'
- unless ['edit', 'update'].include? controller.action_name
.group
= f.label :name, :class => :label
= f.text_field :name, :class => 'text_field'
.group
= f.label :description, :class => :label
= f.text_field :description, :class => 'text_field'
.group
= f.label :distrib_type, :class => :label
= f.select :distrib_type, options_for_select(APP_CONFIG['distr_types'])
- unless ['edit', 'update'].include? controller.action_name
.group
= f.label :distrib_type, :class => :label
= f.select :distrib_type, options_for_select(APP_CONFIG['distr_types'])
.group
= f.label :parent, :class => :label
= f.collection_select :parent_platform_id, Platform.all, :id, :description, :include_blank => true
.group
= f.label :parent, :class => :label
= f.collection_select :parent_platform_id, Platform.all, :id, :description, :include_blank => true
.group
= f.label :released, :class => :label

View File

@ -64,6 +64,7 @@
= link_to t("layout.platforms.freeze"), freeze_platform_path(@platform), :confirm => I18n.t("layout.platforms.confirm_freeze"), :method => :post, :class => "button" if can? :freeze, @platform
= link_to "Клонировать", clone_platform_path(@platform), :class => "button" if can? :clone, @platform
= link_to t("layout.platforms.build_all"), build_all_platform_path(@platform), :confirm => I18n.t("layout.confirm"), :method => :post, :class => "button" if can? :build_all, @platform
= link_to t("layout.platforms.edit"), edit_platform_path(@platform), :class => "button" if can? :edit, @platform
%a{ :name => "repositories" }
.block

View File

@ -98,6 +98,7 @@ ru:
build_all: Собрать все
list: Список
new: Создать
edit: Редактировать
new_header: Новая платформа
edit_header: Редактировать
list_header: Платформы