From 4247ccd3401b81f654f2203f4b71f0257fd9c569 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sun, 16 Sep 2012 11:53:36 -0400 Subject: [PATCH 1/2] Remove unused project/_refs partial --- app/views/projects/_refs.html.haml | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 app/views/projects/_refs.html.haml diff --git a/app/views/projects/_refs.html.haml b/app/views/projects/_refs.html.haml deleted file mode 100644 index dc1f3a28..00000000 --- a/app/views/projects/_refs.html.haml +++ /dev/null @@ -1,3 +0,0 @@ -= form_tag switch_project_refs_path(@project), method: :get, class: "project-refs-form" do - = select_tag "ref", grouped_options_refs, onchange: "this.form.submit();", class: "project-refs-select chosen" - = hidden_field_tag :destination, destination From 465e40d3a663944b5aacf3e53a63158a7812f219 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sun, 16 Sep 2012 12:07:57 -0400 Subject: [PATCH 2/2] Extract ref switcher into a partial Also moves onchange JS to projects.js.coffee --- app/assets/javascripts/projects.js.coffee | 6 +++++- app/views/commits/_head.html.haml | 7 +------ app/views/refs/_head.html.haml | 5 +---- app/views/shared/_ref_switcher.html.haml | 5 +++++ 4 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 app/views/shared/_ref_switcher.html.haml diff --git a/app/assets/javascripts/projects.js.coffee b/app/assets/javascripts/projects.js.coffee index 14738e14..008fa8e9 100644 --- a/app/assets/javascripts/projects.js.coffee +++ b/app/assets/javascripts/projects.js.coffee @@ -10,11 +10,15 @@ window.Projects = -> $('form #project_default_branch').chosen() disableButtonIfEmptyField '#project_name', '.project-submit' -# Git clone panel switcher $ -> + # Git clone panel switcher scope = $ '.project_clone_holder' if scope.length > 0 $('a, button', scope).click -> $('a, button', scope).removeClass 'active' $(@).addClass 'active' $('#project_clone', scope).val $(@).data 'clone' + + # Ref switcher + $('.project-refs-select').on 'change', -> + $(@).parents('form').submit() diff --git a/app/views/commits/_head.html.haml b/app/views/commits/_head.html.haml index 5a09d82a..a8111a72 100644 --- a/app/views/commits/_head.html.haml +++ b/app/views/commits/_head.html.haml @@ -1,9 +1,5 @@ %ul.nav.nav-tabs - %li - = form_tag switch_project_refs_path(@project), method: :get, class: "project-refs-form" do - = select_tag "ref", grouped_options_refs, onchange: "$(this.form).trigger('submit');", class: "project-refs-select chosen" - = hidden_field_tag :destination, "commits" - + %li= render partial: 'shared/ref_switcher', locals: {destination: 'commits'} %li{class: "#{'active' if current_page?(project_commits_path(@project)) }"} = link_to project_commits_path(@project) do Commits @@ -20,7 +16,6 @@ Tags %span.badge= @project.repo.tag_count - - if current_page?(project_commits_path(@project)) && current_user.private_token %li.right %span.rss-icon diff --git a/app/views/refs/_head.html.haml b/app/views/refs/_head.html.haml index 94603f0a..3592f573 100644 --- a/app/views/refs/_head.html.haml +++ b/app/views/refs/_head.html.haml @@ -1,9 +1,6 @@ %ul.nav.nav-tabs %li - = form_tag switch_project_refs_path(@project), method: :get, class: "project-refs-form", remote: true do - = select_tag "ref", grouped_options_refs, onchange: "$(this.form).trigger('submit');", class: "project-refs-select chosen" - = hidden_field_tag :destination, "tree" - = hidden_field_tag :path, params[:path] + = render partial: 'shared/ref_switcher', locals: {destination: 'tree', path: params[:path]} %li{class: "#{'active' if (controller.controller_name == "refs") }"} = link_to tree_project_ref_path(@project, @ref) do Source diff --git a/app/views/shared/_ref_switcher.html.haml b/app/views/shared/_ref_switcher.html.haml new file mode 100644 index 00000000..e0c89522 --- /dev/null +++ b/app/views/shared/_ref_switcher.html.haml @@ -0,0 +1,5 @@ += form_tag switch_project_refs_path(@project), method: :get, class: "project-refs-form" do + = select_tag "ref", grouped_options_refs, class: "project-refs-select chosen" + = hidden_field_tag :destination, destination + - if respond_to?(:path) + = hidden_field_tag :path, path