diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 0275d5054..45977fb8f 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -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 diff --git a/app/models/platform.rb b/app/models/platform.rb index 60a1fb558..8ff2f9ed1 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -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 diff --git a/app/views/platforms/_form.html.haml b/app/views/platforms/_form.html.haml index 8c2832d5c..71e3ac2c5 100644 --- a/app/views/platforms/_form.html.haml +++ b/app/views/platforms/_form.html.haml @@ -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 diff --git a/app/views/platforms/show.html.haml b/app/views/platforms/show.html.haml index 28acb9d7a..baf917e62 100644 --- a/app/views/platforms/show.html.haml +++ b/app/views/platforms/show.html.haml @@ -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 diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 943cfb82a..c95d1852b 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -98,6 +98,7 @@ ru: build_all: Собрать все list: Список new: Создать + edit: Редактировать new_header: Новая платформа edit_header: Редактировать list_header: Платформы