Commit 465e40d3a663944b5aacf3e53a63158a7812f219

Authored by Robert Speicher
1 parent 4247ccd3

Extract ref switcher into a partial

Also moves onchange JS to projects.js.coffee
app/assets/javascripts/projects.js.coffee
... ... @@ -10,11 +10,15 @@ window.Projects = ->
10 10 $('form #project_default_branch').chosen()
11 11 disableButtonIfEmptyField '#project_name', '.project-submit'
12 12  
13   -# Git clone panel switcher
14 13 $ ->
  14 + # Git clone panel switcher
15 15 scope = $ '.project_clone_holder'
16 16 if scope.length > 0
17 17 $('a, button', scope).click ->
18 18 $('a, button', scope).removeClass 'active'
19 19 $(@).addClass 'active'
20 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 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 3 %li{class: "#{'active' if current_page?(project_commits_path(@project)) }"}
8 4 = link_to project_commits_path(@project) do
9 5 Commits
... ... @@ -20,7 +16,6 @@
20 16 Tags
21 17 %span.badge= @project.repo.tag_count
22 18  
23   -
24 19 - if current_page?(project_commits_path(@project)) && current_user.private_token
25 20 %li.right
26 21 %span.rss-icon
... ...
app/views/refs/_head.html.haml
1 1 %ul.nav.nav-tabs
2 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 4 %li{class: "#{'active' if (controller.controller_name == "refs") }"}
8 5 = link_to tree_project_ref_path(@project, @ref) do
9 6 Source
... ...
app/views/shared/_ref_switcher.html.haml 0 → 100644
... ... @@ -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
... ...