Commit 7e76610d0a521af73459ffc2ba7b3956ab9da34c

Authored by Robert Speicher
1 parent c1ff89fa

Update the projects js file to coffeescript; refactor the clone panel switcher

app/assets/javascripts/projects.js.coffee
1 -function Projects() {  
2 - $("#project_name").live("change", function(){  
3 - var slug = slugify($(this).val());  
4 - $("#project_code").val(slug);  
5 - $("#project_path").val(slug);  
6 - }); 1 +window.Projects = ->
  2 + $("#project_name").live "change", ->
  3 + slug = slugify($(this).val())
  4 + $("#project_code").val(slug)
  5 + $("#project_path").val(slug)
7 6
8 - $('.new_project, .edit_project').live('ajax:before', function() {  
9 - $('.project_new_holder, .project_edit_holder').hide();  
10 - $('.save-project-loader').show();  
11 - }); 7 + $(".new_project, .edit_project").live "ajax:before", ->
  8 + $(".project_new_holder, .project_edit_holder").hide()
  9 + $(".save-project-loader").show()
12 10
13 - $('form #project_default_branch').chosen(); 11 + $("form #project_default_branch").chosen()
  12 + disableButtonIfEmtpyField "#project_name", ".project-submit"
14 13
15 - disableButtonIfEmtpyField("#project_name", ".project-submit")  
16 -}  
17 -  
18 -function initGitCloneSwitcher() {  
19 - var link_sel = ".project_clone_holder button";  
20 - $(link_sel).bind("click", function(e) {  
21 - $(link_sel).removeClass("active");  
22 - $(this).addClass("active");  
23 - $("#project_clone").val($(this).attr("data-clone"));  
24 - })  
25 -} 14 +# Git clone panel switcher
  15 +$ ->
  16 + scope = $('.project_clone_holder')
  17 + if scope.length > 0
  18 + $('a, button', scope).click ->
  19 + $('a, button', scope).removeClass('active')
  20 + $(this).addClass('active')
  21 + $('#project_clone', scope).val($(this).data('clone'))
app/views/projects/empty.html.haml
@@ -36,16 +36,3 @@ @@ -36,16 +36,3 @@
36 - if can? current_user, :admin_project, @project 36 - if can? current_user, :admin_project, @project
37 .prepend-top-20 37 .prepend-top-20
38 = link_to 'Remove project', @project, confirm: 'Are you sure?', method: :delete, class: "btn danger right" 38 = link_to 'Remove project', @project, confirm: 'Are you sure?', method: :delete, class: "btn danger right"
39 -  
40 -  
41 -  
42 -:javascript  
43 - $(function(){  
44 - var link_sel = ".project_clone_holder a";  
45 - $(link_sel).bind("click", function() {  
46 - $(link_sel).removeClass("active");  
47 - $(this).addClass("active");  
48 - $("#project_clone").val($(this).attr("data-clone"));  
49 - })  
50 - })  
51 -  
app/views/projects/show.html.haml
@@ -2,8 +2,3 @@ @@ -2,8 +2,3 @@
2 = render 'clone_panel' 2 = render 'clone_panel'
3 = render "events/event_last_push", event: @last_push 3 = render "events/event_last_push", event: @last_push
4 .content_list= render @events 4 .content_list= render @events
5 -  
6 -:javascript  
7 - $(function(){  
8 - initGitCloneSwitcher();  
9 - })  
app/views/refs/_head.html.haml
@@ -12,8 +12,3 @@ @@ -12,8 +12,3 @@
12 %button{class: "btn small active", :"data-clone" => @project.ssh_url_to_repo} SSH 12 %button{class: "btn small active", :"data-clone" => @project.ssh_url_to_repo} SSH
13 %button{class: "btn small", :"data-clone" => @project.http_url_to_repo} HTTP 13 %button{class: "btn small", :"data-clone" => @project.http_url_to_repo} HTTP
14 = text_field_tag :project_clone, @project.url_to_repo, class: "one_click_select span5" 14 = text_field_tag :project_clone, @project.url_to_repo, class: "one_click_select span5"
15 -  
16 -:javascript  
17 - $(function(){  
18 - initGitCloneSwitcher();  
19 - })