Commit b5442eb5643b10a0e6539b1081ccf048d555d38a

Authored by Dmitriy Zaporozhets
2 parents 7c7e9b13 465e40d3

Merge pull request #1479 from tsigo/ref_switch

Extract ref switcher into a partial
app/assets/javascripts/projects.js.coffee
@@ -10,11 +10,15 @@ window.Projects = -> @@ -10,11 +10,15 @@ window.Projects = ->
10 $('form #project_default_branch').chosen() 10 $('form #project_default_branch').chosen()
11 disableButtonIfEmptyField '#project_name', '.project-submit' 11 disableButtonIfEmptyField '#project_name', '.project-submit'
12 12
13 -# Git clone panel switcher  
14 $ -> 13 $ ->
  14 + # Git clone panel switcher
15 scope = $ '.project_clone_holder' 15 scope = $ '.project_clone_holder'
16 if scope.length > 0 16 if scope.length > 0
17 $('a, button', scope).click -> 17 $('a, button', scope).click ->
18 $('a, button', scope).removeClass 'active' 18 $('a, button', scope).removeClass 'active'
19 $(@).addClass 'active' 19 $(@).addClass 'active'
20 $('#project_clone', scope).val $(@).data 'clone' 20 $('#project_clone', scope).val $(@).data 'clone'
  21 +
  22 + # Ref switcher
  23 + $('.project-refs-select').on 'change', ->
  24 + $(@).parents('form').submit()
app/views/commits/_head.html.haml
1 %ul.nav.nav-tabs 1 %ul.nav.nav-tabs
2 - %li  
3 - = form_tag switch_project_refs_path(@project), method: :get, class: "project-refs-form" do  
4 - = select_tag "ref", grouped_options_refs, onchange: "$(this.form).trigger('submit');", class: "project-refs-select chosen"  
5 - = hidden_field_tag :destination, "commits"  
6 - 2 + %li= render partial: 'shared/ref_switcher', locals: {destination: 'commits'}
7 %li{class: "#{'active' if current_page?(project_commits_path(@project)) }"} 3 %li{class: "#{'active' if current_page?(project_commits_path(@project)) }"}
8 = link_to project_commits_path(@project) do 4 = link_to project_commits_path(@project) do
9 Commits 5 Commits
@@ -20,7 +16,6 @@ @@ -20,7 +16,6 @@
20 Tags 16 Tags
21 %span.badge= @project.repo.tag_count 17 %span.badge= @project.repo.tag_count
22 18
23 -  
24 - if current_page?(project_commits_path(@project)) && current_user.private_token 19 - if current_page?(project_commits_path(@project)) && current_user.private_token
25 %li.right 20 %li.right
26 %span.rss-icon 21 %span.rss-icon
app/views/projects/_refs.html.haml
@@ -1,3 +0,0 @@ @@ -1,3 +0,0 @@
1 -= form_tag switch_project_refs_path(@project), method: :get, class: "project-refs-form" do  
2 - = select_tag "ref", grouped_options_refs, onchange: "this.form.submit();", class: "project-refs-select chosen"  
3 - = hidden_field_tag :destination, destination  
app/views/refs/_head.html.haml
1 %ul.nav.nav-tabs 1 %ul.nav.nav-tabs
2 %li 2 %li
3 - = form_tag switch_project_refs_path(@project), method: :get, class: "project-refs-form", remote: true do  
4 - = select_tag "ref", grouped_options_refs, onchange: "$(this.form).trigger('submit');", class: "project-refs-select chosen"  
5 - = hidden_field_tag :destination, "tree"  
6 - = hidden_field_tag :path, params[:path] 3 + = render partial: 'shared/ref_switcher', locals: {destination: 'tree', path: params[:path]}
7 %li{class: "#{'active' if (controller.controller_name == "refs") }"} 4 %li{class: "#{'active' if (controller.controller_name == "refs") }"}
8 = link_to tree_project_ref_path(@project, @ref) do 5 = link_to tree_project_ref_path(@project, @ref) do
9 Source 6 Source
app/views/shared/_ref_switcher.html.haml 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 += form_tag switch_project_refs_path(@project), method: :get, class: "project-refs-form" do
  2 + = select_tag "ref", grouped_options_refs, class: "project-refs-select chosen"
  3 + = hidden_field_tag :destination, destination
  4 + - if respond_to?(:path)
  5 + = hidden_field_tag :path, path