diff --git a/app/controllers/platforms/product_build_lists_controller.rb b/app/controllers/platforms/product_build_lists_controller.rb index 9531cd68c..bed67a54b 100644 --- a/app/controllers/platforms/product_build_lists_controller.rb +++ b/app/controllers/platforms/product_build_lists_controller.rb @@ -23,8 +23,11 @@ class Platforms::ProductBuildListsController < Platforms::BaseController end def destroy - @product_build_list.destroy - flash[:notice] = t('flash.product.build_list_delete') + if @product_build_list.destroy + flash[:notice] = t('flash.product_build_list.delete') + else + flash[:error] = t('flash.product_build_list.delete_error') + end redirect_to [@platform, @product] end diff --git a/app/models/product_build_list.rb b/app/models/product_build_list.rb index 774f1d0ca..0a792dfd8 100644 --- a/app/models/product_build_list.rb +++ b/app/models/product_build_list.rb @@ -31,6 +31,7 @@ class ProductBuildList < ActiveRecord::Base scope :recent, order("#{table_name}.updated_at DESC") after_create :xml_rpc_create + before_destroy :can_destroy? after_destroy :xml_delete_iso_container def container_path @@ -49,6 +50,10 @@ class ProductBuildList < ActiveRecord::Base self.class.human_status(status) end + def can_destroy? + [BUILD_COMPLETED, BUILD_FAILED].include? status + end + protected def xml_rpc_create diff --git a/app/views/platforms/product_build_lists/_product_build_list.html.haml b/app/views/platforms/product_build_lists/_product_build_list.html.haml index 47cd0d8a5..8325f843f 100644 --- a/app/views/platforms/product_build_lists/_product_build_list.html.haml +++ b/app/views/platforms/product_build_lists/_product_build_list.html.haml @@ -3,5 +3,6 @@ %td= product_build_list.human_status %td= link_to nil, product_build_list.container_path %td= link_to product_build_list.product.name, platform_product_path(product_build_list.product.platform, product_build_list.product) - %td= link_to image_tag('x.png'), platform_product_product_build_list_path(product_build_list.product.platform, product_build_list.product, product_build_list), :method => :delete, :confirm => t("layout.confirm") if can? :destroy, product_build_list + - pbl = product_build_list + %td= link_to image_tag('x.png'), platform_product_product_build_list_path(pbl.product.platform, pbl.product, pbl), :method => :delete, :confirm => t("layout.confirm") if can?(:destroy, pbl) && pbl.can_destroy? %td= l(product_build_list.updated_at, :format => :long) \ No newline at end of file diff --git a/config/locales/models/product.en.yml b/config/locales/models/product.en.yml index 8a483a667..5a8c5608c 100644 --- a/config/locales/models/product.en.yml +++ b/config/locales/models/product.en.yml @@ -33,7 +33,6 @@ en: save_error: Unable to save product build_started: Product build started destroyed: Product deleted - build_list_delete: Product build list deleted activerecord: models: diff --git a/config/locales/models/product.ru.yml b/config/locales/models/product.ru.yml index 0361b57dc..8969105e9 100644 --- a/config/locales/models/product.ru.yml +++ b/config/locales/models/product.ru.yml @@ -33,7 +33,6 @@ ru: save_error: Не удалось сохранить изменения build_started: Запущена сборка продукта destroyed: Продукт удален - build_list_delete: Сборочный лист продукта удален activerecord: models: diff --git a/config/locales/models/product_build_list.en.yml b/config/locales/models/product_build_list.en.yml index 6f6892274..0eabdae27 100644 --- a/config/locales/models/product_build_list.en.yml +++ b/config/locales/models/product_build_list.en.yml @@ -25,6 +25,10 @@ en: product: Product container_path: Container status: Status - notified_at: Notified at user: User notified_at: Notified at + + flash: + product_build_list: + delete: Product build list deleted + delete_error: Unable to delete product build list \ No newline at end of file diff --git a/config/locales/models/product_build_list.ru.yml b/config/locales/models/product_build_list.ru.yml index c422df74a..73bdd8d60 100644 --- a/config/locales/models/product_build_list.ru.yml +++ b/config/locales/models/product_build_list.ru.yml @@ -28,3 +28,8 @@ ru: user: Пользователь notified_at: Информация получена + flash: + product_build_list: + delete: Сборочный лист продукта удален + delete_error: Не удалось удалить cборочный лист продукта +