From 08966ab738f432c7f0fab2467fa371d3ae234a20 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 6 Jun 2013 22:57:36 +0400 Subject: [PATCH] #156: add personal repositories as extra on #new page --- .../javascripts/extra/autocomplete-form.js | 25 ++++++++++-------- app/assets/javascripts/extra/build_list.js | 13 ++++++++++ app/views/platforms/base/_sidebar.html.haml | 1 - app/views/platforms/mass_builds/new.html.haml | 14 ++++++++-- app/views/projects/build_lists/new.html.haml | 15 +++++++++-- app/views/shared/_autocomplete_form.html.haml | 26 +++++++++++++------ 6 files changed, 70 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/extra/autocomplete-form.js b/app/assets/javascripts/extra/autocomplete-form.js index 7a57ed6bf..5de3ae488 100644 --- a/app/assets/javascripts/extra/autocomplete-form.js +++ b/app/assets/javascripts/extra/autocomplete-form.js @@ -9,17 +9,7 @@ $(document).ready(function() { var path = $('#' + field + '_field_path').val(); var label = $('#' + field + '_field_label').val(); - var tr = '' + - '' + - '' + label + '' + - '' + - '' + - '' + - ' ' + - '' + - ''; - - form.find('table tbody').append($(tr)); + addDataToAutocompleteForm(form, path, label, name, subject.val()); form.find('.autocomplete').val(''); return false; }); @@ -41,3 +31,16 @@ $(document).ready(function() { }); }); + +function addDataToAutocompleteForm(form, path, label, name, value) { + var tr = '' + + '' + + '' + label + '' + + '' + + '' + + '' + + ' ' + + '' + + ''; + form.find('table tbody').append($(tr)); +} diff --git a/app/assets/javascripts/extra/build_list.js b/app/assets/javascripts/extra/build_list.js index 7f1b64ae8..e36022bdb 100644 --- a/app/assets/javascripts/extra/build_list.js +++ b/app/assets/javascripts/extra/build_list.js @@ -17,6 +17,7 @@ $(document).ready(function() { if (build_platform.size() == 0) { all_repositories.removeAttr('disabled'); auto_create_container.removeAttr('checked'); + addPersonalPlatformToExtraRepos(selected_option, extra_repos); extra_repos.show(); } else { all_repositories.attr('disabled', 'disabled'); @@ -84,6 +85,18 @@ function updateExtraReposAndBuildLists(save_to_platform_id) { }); } +function addPersonalPlatformToExtraRepos(selected_option, extra_repos) { + var default_value = extra_repos.find('div[label="' + selected_option.text() + '"]'); + if (default_value.length == 0) { return; } + addDataToAutocompleteForm( + extra_repos, + default_value.attr('path'), + default_value.attr('label'), + default_value.attr('name'), + default_value.attr('value') + ); +} + function setBranchSelected(selected_option) { var pl_name = selected_option.text().match(/([\w-.]+)\/[\w-.]+/)[1]; var bl_version_sel = $('#build_list_project_version'); diff --git a/app/views/platforms/base/_sidebar.html.haml b/app/views/platforms/base/_sidebar.html.haml index 691f1934b..ed5ef3e83 100644 --- a/app/views/platforms/base/_sidebar.html.haml +++ b/app/views/platforms/base/_sidebar.html.haml @@ -13,7 +13,6 @@ - if can? :show, @platform %li{:class => (act == :index && contr == :maintainers) ? 'active' : nil} = link_to t("layout.platforms.maintainers"), platform_maintainers_path(@platform) - - if can?(:show, @platform) %li{:class => (contr == :mass_builds) ? 'active' : ''} = link_to t("layout.platforms.mass_build"), platform_mass_builds_path(@platform) - if can? :read, @platform.products.build diff --git a/app/views/platforms/mass_builds/new.html.haml b/app/views/platforms/mass_builds/new.html.haml index 9a3549495..a528d7a26 100644 --- a/app/views/platforms/mass_builds/new.html.haml +++ b/app/views/platforms/mass_builds/new.html.haml @@ -25,8 +25,18 @@ %h3= t('activerecord.attributes.build_list.build_for_platform') = f.collection_select :build_for_platform_id, Platform.main, :id, :name .both - = render 'shared/autocomplete_form', :field => :extra_repositories, :field_class => Repository, :placeholder => 'uxteam_personal', :subject => @mass_build, :autocomplete_path => autocomplete_extra_repositories_autocompletes_path - = render 'shared/autocomplete_form', :field => :extra_build_lists, :field_class => BuildList, :placeholder => '1000000', :subject => @mass_build, :autocomplete_path => autocomplete_extra_build_list_autocompletes_path + = render 'shared/autocomplete_form', + :field => :extra_repositories, + :field_class => Repository, + :placeholder => 'uxteam_personal', + :subject => @mass_build, + :autocomplete_path => autocomplete_extra_repositories_autocompletes_path + = render 'shared/autocomplete_form', + :field => :extra_build_lists, + :field_class => BuildList, + :placeholder => '1000000', + :subject => @mass_build, + :autocomplete_path => autocomplete_extra_build_list_autocompletes_path %h3= t("activerecord.attributes.build_list.preferences") .both = f.check_box :auto_publish diff --git a/app/views/projects/build_lists/new.html.haml b/app/views/projects/build_lists/new.html.haml index ff030d838..bad03ca1c 100644 --- a/app/views/projects/build_lists/new.html.haml +++ b/app/views/projects/build_lists/new.html.haml @@ -21,8 +21,19 @@ %h3= t("activerecord.attributes.build_list.update_type") .lineForm= f.select :update_type, BuildList::UPDATE_TYPES - = render 'shared/autocomplete_form', :field => :extra_repositories, :field_class => Repository, :placeholder => 'uxteam_personal', :subject => @build_list, :autocomplete_path => autocomplete_extra_repositories_autocompletes_path - = render 'shared/autocomplete_form', :field => :extra_build_lists, :field_class => BuildList, :placeholder => '1000000', :subject => @build_list, :autocomplete_path => autocomplete_extra_build_list_autocompletes_path + = render 'shared/autocomplete_form', + :field => :extra_repositories, + :field_class => Repository, + :placeholder => 'uxteam_personal', + :subject => @build_list, + :autocomplete_path => autocomplete_extra_repositories_autocompletes_path, + :default_values => @project.repositories.select{ |r| r.platform.personal? } + = render 'shared/autocomplete_form', + :field => :extra_build_lists, + :field_class => BuildList, + :placeholder => '1000000', + :subject => @build_list, + :autocomplete_path => autocomplete_extra_build_list_autocompletes_path %h3= t("activerecord.attributes.build_list.preferences") - [:auto_publish, :auto_create_container].each do |kind| diff --git a/app/views/shared/_autocomplete_form.html.haml b/app/views/shared/_autocomplete_form.html.haml index d715a22c9..9abe40b05 100644 --- a/app/views/shared/_autocomplete_form.html.haml +++ b/app/views/shared/_autocomplete_form.html.haml @@ -1,11 +1,13 @@ -/ +-# Variables: - - subject - - field - - field_class - - autocomplete_path - - placeholder + subject + field + field_class + autocomplete_path + placeholder + default_values (optional) +- default_values ||= [] - subject_class = subject.class.name.underscore .autocomplete-form{:subject_class => subject_class, :field => field, :path => autocomplete_path, :class => field} %h3= t("activerecord.attributes.build_list.#{field}") @@ -21,6 +23,7 @@ %table.tablesorter{:cellpadding => "0", :cellspacing => "0"} %tbody + - field_name = "#{subject_class}[#{field}][]" - field_class.where(:id => subject.send(field)).each do |extra| %tr - if extra.is_a?(BuildList) @@ -29,5 +32,12 @@ %td= link_to "#{extra.platform.name}/#{extra.name}", [extra.platform, extra] %td.actions - field = extra.is_a?(BuildList) ? 'extra_build_lists' : 'extra_repositories' - = hidden_field_tag "#{subject_class}[#{field}][]", extra.id - %span.delete   \ No newline at end of file + = hidden_field_tag field_name, extra.id + %span.delete   + .default-values + - field_class.where(:id => default_values).each do |extra| + .hidden{:label => "#{extra.platform.name}/#{extra.name}", + :path => url_for([extra.platform, extra]), + :name => field_name, :value => extra.id} + +