From 3d2bcdd019781521f1e49d58dabb3ba36deec711 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Thu, 24 May 2012 14:21:57 +0400 Subject: [PATCH] [refs #478] Add js handler to disable frozen platforms and their reps --- app/assets/javascripts/extra/build_list.js | 20 ++++++++++++++++++++ app/models/build_list.rb | 4 ++-- app/views/projects/build_lists/new.html.haml | 5 ++++- config/locales/models/build_list.en.yml | 1 + config/locales/models/build_list.ru.yml | 1 + 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/extra/build_list.js b/app/assets/javascripts/extra/build_list.js index ef50c2b2d..1faee75bb 100644 --- a/app/assets/javascripts/extra/build_list.js +++ b/app/assets/javascripts/extra/build_list.js @@ -45,6 +45,26 @@ $(document).ready(function() { $('.build_bpl_ids').click(function() { return false; }); + + $("select#build_list_update_type").change(function() { + if ( $(this).val() == "bugfix" || $(this).val() == "security" ) { + $("select#build_list_save_to_platform_id option").each(function(i,el) { + $(el).removeAttr("disabled"); + }); + } else { + $("select#build_list_save_to_platform_id option").each(function(i,el) { + if ( $.inArray(parseInt($(el).attr("value")), FROZEN_PLS) == 0 ) { + $(el).attr("disabled", "disabled"); + // If disabled option is selected - select blank repository (it is always first): + if ( $(el).attr("selected") ) { + $( $("select#build_list_save_to_platform_id option")[0] ).attr("selected", "selected"); + } + } + }); + } + }); + $("select#build_list_update_type").trigger('change'); + }); function setPlChecked(pointer, checked) { diff --git a/app/models/build_list.rb b/app/models/build_list.rb index c20b7b9f4..560488ef6 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -17,9 +17,9 @@ class BuildList < ActiveRecord::Base validates_numericality_of :priority, :greater_than_or_equal_to => 0 validates :update_type, :inclusion => UPDATE_TYPES, :unless => Proc.new { |b| b.save_to_platform.released } - validates :update_type, :inclusion => RELEASE_UPDATE_TYPES, + validates :update_type, :inclusion => {:in => RELEASE_UPDATE_TYPES, :message => I18n.t('flash.build_list.frozen_platform')}, :if => Proc.new { |b| b.save_to_platform.released && b.mass_build_id.nil?} - validate lambda { + validate lambda { errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_platform')) if save_to_platform.platform_type == 'main' && save_to_platform_id != build_for_platform_id } diff --git a/app/views/projects/build_lists/new.html.haml b/app/views/projects/build_lists/new.html.haml index 10024025a..4aba04c7d 100644 --- a/app/views/projects/build_lists/new.html.haml +++ b/app/views/projects/build_lists/new.html.haml @@ -11,7 +11,7 @@ .offset25{:style => 'padding-left: 25px'}= render 'include_repos', :platform => pl %section.right %h3= t("activerecord.attributes.build_list.save_to_platform") - .lineForm= f.select :save_to_platform_id, @project.repositories.collect{|r| ["#{r.platform.name}/#{r.name}", r.platform.id]} + .lineForm= f.select :save_to_platform_id, @project.repositories.collect{|r| ["#{r.platform.name}/#{r.name}", r.platform.id]}, :include_blank => true %h3= t("activerecord.attributes.build_list.project_version") - if controller.action_name == 'new' .lineForm= f.select :project_version, @project.versions_for_group_select, :selected => "latest_" + @project.default_branch @@ -34,4 +34,7 @@ %br = f.submit t("layout.projects.build_button") +:javascript + var FROZEN_PLS = [#{ @project.repositories.map { |r| r.id if r.platform.released }.delete_if { |i| i.nil? }.join(", ") }]; + = render 'projects/base/submenu' diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index 9688c14c0..1cf9461f3 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -123,3 +123,4 @@ en: no_arch_or_platform_selected: At least one of architecture of platform must selected wrong_platform: Only the primary platform can be selected for the main repository! can_not_published: Build can only be published with status "Build complete" + frozen_platform: In case of a repository for package storage with frozen platform allowed only bugfix and security updates diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index faebb4372..4acd47807 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -122,3 +122,4 @@ ru: no_arch_or_platform_selected: Выберите хотя бы одну архитектуру и платформу wrong_platform: Для основного репозитория (main) может быть выбран только его же основная платформа! can_not_published: Опубликовать сборку можно только со статусом "Собран" + frozen_platform: В случае выбора репозитория для сохранения пакетов из замороженнной платформы разрешены только bugfix и security обновления