Commit 8c1b83cffe934ded9886a85a74447c0dae6c908e
Exists in
master
and in
4 other branches
Merge pull request #1391 from NARKOZ/refactoring
Refactoring
Showing
13 changed files
with
174 additions
and
201 deletions
Show diff stats
app/assets/javascripts/admin.js
| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | -$(document).ready(function(){ | |
| 2 | - $('input#user_force_random_password').on('change', function(elem) { | |
| 3 | - var elems = $('#user_password, #user_password_confirmation'); | |
| 4 | - | |
| 5 | - if ($(this).attr('checked')) { | |
| 6 | - elems.val('').attr('disabled', true); | |
| 7 | - } else { | |
| 8 | - elems.removeAttr('disabled'); | |
| 9 | - } | |
| 10 | - }); | |
| 11 | -}); |
app/assets/javascripts/application.js
| ... | ... | @@ -17,134 +17,3 @@ |
| 17 | 17 | //= require raphael |
| 18 | 18 | //= require branch-graph |
| 19 | 19 | //= require_tree . |
| 20 | - | |
| 21 | -$(document).ready(function(){ | |
| 22 | - | |
| 23 | - $(".one_click_select").live("click", function(){ | |
| 24 | - $(this).select(); | |
| 25 | - }); | |
| 26 | - | |
| 27 | - $('body').on('ajax:complete, ajax:beforeSend, submit', 'form', function(e){ | |
| 28 | - var buttons = $('[type="submit"]', this); | |
| 29 | - switch( e.type ){ | |
| 30 | - case 'ajax:beforeSend': | |
| 31 | - case 'submit': | |
| 32 | - buttons.attr('disabled', 'disabled'); | |
| 33 | - break; | |
| 34 | - case ' ajax:complete': | |
| 35 | - default: | |
| 36 | - buttons.removeAttr('disabled'); | |
| 37 | - break; | |
| 38 | - } | |
| 39 | - }) | |
| 40 | - | |
| 41 | - $(".account-box").mouseenter(showMenu); | |
| 42 | - $(".account-box").mouseleave(resetMenu); | |
| 43 | - | |
| 44 | - $("#projects-list .project").live('click', function(e){ | |
| 45 | - if(e.target.nodeName != "A" && e.target.nodeName != "INPUT") { | |
| 46 | - location.href = $(this).attr("url"); | |
| 47 | - e.stopPropagation(); | |
| 48 | - return false; | |
| 49 | - } | |
| 50 | - }); | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * Focus search field by pressing 's' key | |
| 54 | - */ | |
| 55 | - $(document).keypress(function(e) { | |
| 56 | - if( $(e.target).is(":input") ) return; | |
| 57 | - switch(e.which) { | |
| 58 | - case 115: focusSearch(); | |
| 59 | - e.preventDefault(); | |
| 60 | - } | |
| 61 | - }); | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * Commit show suppressed diff | |
| 65 | - * | |
| 66 | - */ | |
| 67 | - $(".supp_diff_link").bind("click", function() { | |
| 68 | - showDiff(this); | |
| 69 | - }); | |
| 70 | - | |
| 71 | - /** | |
| 72 | - * Note markdown preview | |
| 73 | - * | |
| 74 | - */ | |
| 75 | - $(document).on('click', '#preview-link', function(e) { | |
| 76 | - $('#preview-note').text('Loading...'); | |
| 77 | - | |
| 78 | - var previewLinkText = ($(this).text() == 'Preview' ? 'Edit' : 'Preview'); | |
| 79 | - $(this).text(previewLinkText); | |
| 80 | - | |
| 81 | - var note = $('#note_note').val(); | |
| 82 | - if (note.trim().length === 0) { note = 'Nothing to preview'; } | |
| 83 | - $.post($(this).attr('href'), {note: note}, function(data) { | |
| 84 | - $('#preview-note').html(data); | |
| 85 | - }); | |
| 86 | - | |
| 87 | - $('#preview-note, #note_note').toggle(); | |
| 88 | - e.preventDefault(); | |
| 89 | - }); | |
| 90 | -}); | |
| 91 | - | |
| 92 | -function focusSearch() { | |
| 93 | - $("#search").focus(); | |
| 94 | -} | |
| 95 | - | |
| 96 | -function updatePage(data){ | |
| 97 | - $.ajax({type: "GET", url: location.href, data: data, dataType: "script"}); | |
| 98 | -} | |
| 99 | - | |
| 100 | -function showMenu() { | |
| 101 | - $(this).toggleClass('hover'); | |
| 102 | -} | |
| 103 | - | |
| 104 | -function resetMenu() { | |
| 105 | - $(this).removeClass("hover"); | |
| 106 | -} | |
| 107 | - | |
| 108 | -function slugify(text) { | |
| 109 | - return text.replace(/[^-a-zA-Z0-9]+/g, '_').toLowerCase(); | |
| 110 | -} | |
| 111 | - | |
| 112 | -function showDiff(link) { | |
| 113 | - $(link).next('table').show(); | |
| 114 | - $(link).remove(); | |
| 115 | -} | |
| 116 | - | |
| 117 | -(function($){ | |
| 118 | - var _chosen = $.fn.chosen; | |
| 119 | - $.fn.extend({ | |
| 120 | - chosen: function(options) { | |
| 121 | - var default_options = {'search_contains' : 'true'}; | |
| 122 | - $.extend(default_options, options); | |
| 123 | - return _chosen.apply(this, [default_options]); | |
| 124 | - }}) | |
| 125 | -})(jQuery); | |
| 126 | - | |
| 127 | - | |
| 128 | -function ajaxGet(url) { | |
| 129 | - $.ajax({type: "GET", url: url, dataType: "script"}); | |
| 130 | -} | |
| 131 | - | |
| 132 | -/** | |
| 133 | - * Disable button if text field is empty | |
| 134 | - */ | |
| 135 | -function disableButtonIfEmtpyField(field_selector, button_selector) { | |
| 136 | - field = $(field_selector); | |
| 137 | - if(field.val() == "") { | |
| 138 | - field.closest("form").find(button_selector).attr("disabled", "disabled").addClass("disabled"); | |
| 139 | - } | |
| 140 | - | |
| 141 | - field.on('keyup', function(){ | |
| 142 | - var field = $(this); | |
| 143 | - var closest_submit = field.closest("form").find(button_selector); | |
| 144 | - if(field.val() == "") { | |
| 145 | - closest_submit.attr("disabled", "disabled").addClass("disabled"); | |
| 146 | - } else { | |
| 147 | - closest_submit.removeAttr("disabled").removeClass("disabled"); | |
| 148 | - } | |
| 149 | - }) | |
| 150 | -} | ... | ... |
app/assets/javascripts/graph.js
| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | -function initGraphNav() { | |
| 2 | - $(".graph svg").css("position", "relative"); | |
| 3 | - $("body").bind("keyup", function(e) { | |
| 4 | - if(e.keyCode == 37) { // left | |
| 5 | - $(".graph svg").animate({ left: "+=400" }); | |
| 6 | - } else if(e.keyCode == 39) { // right | |
| 7 | - $(".graph svg").animate({ left: "-=400" }); | |
| 8 | - } | |
| 9 | - }); | |
| 10 | -} |
| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | +initGraphNav = -> | |
| 2 | + $('.graph svg').css 'position', 'relative' | |
| 3 | + | |
| 4 | + $('body').bind 'keyup', (e) -> | |
| 5 | + if e.keyCode is 37 # left | |
| 6 | + $('.graph svg').animate left: '+=400' | |
| 7 | + else if e.keyCode is 39 # right | |
| 8 | + $('.graph svg').animate left: '-=400' | |
| 9 | + | |
| 10 | +window.initGraphNav = initGraphNav | ... | ... |
app/assets/javascripts/loader.js
| ... | ... | @@ -0,0 +1,130 @@ |
| 1 | +$(document).ready(function(){ | |
| 2 | + | |
| 3 | + $(".one_click_select").live("click", function(){ | |
| 4 | + $(this).select(); | |
| 5 | + }); | |
| 6 | + | |
| 7 | + $('body').on('ajax:complete, ajax:beforeSend, submit', 'form', function(e){ | |
| 8 | + var buttons = $('[type="submit"]', this); | |
| 9 | + switch( e.type ){ | |
| 10 | + case 'ajax:beforeSend': | |
| 11 | + case 'submit': | |
| 12 | + buttons.attr('disabled', 'disabled'); | |
| 13 | + break; | |
| 14 | + case ' ajax:complete': | |
| 15 | + default: | |
| 16 | + buttons.removeAttr('disabled'); | |
| 17 | + break; | |
| 18 | + } | |
| 19 | + }) | |
| 20 | + | |
| 21 | + $(".account-box").mouseenter(showMenu); | |
| 22 | + $(".account-box").mouseleave(resetMenu); | |
| 23 | + | |
| 24 | + $("#projects-list .project").live('click', function(e){ | |
| 25 | + if(e.target.nodeName != "A" && e.target.nodeName != "INPUT") { | |
| 26 | + location.href = $(this).attr("url"); | |
| 27 | + e.stopPropagation(); | |
| 28 | + return false; | |
| 29 | + } | |
| 30 | + }); | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * Focus search field by pressing 's' key | |
| 34 | + */ | |
| 35 | + $(document).keypress(function(e) { | |
| 36 | + if( $(e.target).is(":input") ) return; | |
| 37 | + switch(e.which) { | |
| 38 | + case 115: focusSearch(); | |
| 39 | + e.preventDefault(); | |
| 40 | + } | |
| 41 | + }); | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * Commit show suppressed diff | |
| 45 | + * | |
| 46 | + */ | |
| 47 | + $(".supp_diff_link").bind("click", function() { | |
| 48 | + showDiff(this); | |
| 49 | + }); | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * Note markdown preview | |
| 53 | + * | |
| 54 | + */ | |
| 55 | + $(document).on('click', '#preview-link', function(e) { | |
| 56 | + $('#preview-note').text('Loading...'); | |
| 57 | + | |
| 58 | + var previewLinkText = ($(this).text() == 'Preview' ? 'Edit' : 'Preview'); | |
| 59 | + $(this).text(previewLinkText); | |
| 60 | + | |
| 61 | + var note = $('#note_note').val(); | |
| 62 | + if (note.trim().length === 0) { note = 'Nothing to preview'; } | |
| 63 | + $.post($(this).attr('href'), {note: note}, function(data) { | |
| 64 | + $('#preview-note').html(data); | |
| 65 | + }); | |
| 66 | + | |
| 67 | + $('#preview-note, #note_note').toggle(); | |
| 68 | + e.preventDefault(); | |
| 69 | + }); | |
| 70 | +}); | |
| 71 | + | |
| 72 | +function focusSearch() { | |
| 73 | + $("#search").focus(); | |
| 74 | +} | |
| 75 | + | |
| 76 | +function updatePage(data){ | |
| 77 | + $.ajax({type: "GET", url: location.href, data: data, dataType: "script"}); | |
| 78 | +} | |
| 79 | + | |
| 80 | +function showMenu() { | |
| 81 | + $(this).toggleClass('hover'); | |
| 82 | +} | |
| 83 | + | |
| 84 | +function resetMenu() { | |
| 85 | + $(this).removeClass("hover"); | |
| 86 | +} | |
| 87 | + | |
| 88 | +function slugify(text) { | |
| 89 | + return text.replace(/[^-a-zA-Z0-9]+/g, '_').toLowerCase(); | |
| 90 | +} | |
| 91 | + | |
| 92 | +function showDiff(link) { | |
| 93 | + $(link).next('table').show(); | |
| 94 | + $(link).remove(); | |
| 95 | +} | |
| 96 | + | |
| 97 | +(function($){ | |
| 98 | + var _chosen = $.fn.chosen; | |
| 99 | + $.fn.extend({ | |
| 100 | + chosen: function(options) { | |
| 101 | + var default_options = {'search_contains' : 'true'}; | |
| 102 | + $.extend(default_options, options); | |
| 103 | + return _chosen.apply(this, [default_options]); | |
| 104 | + }}) | |
| 105 | +})(jQuery); | |
| 106 | + | |
| 107 | + | |
| 108 | +function ajaxGet(url) { | |
| 109 | + $.ajax({type: "GET", url: url, dataType: "script"}); | |
| 110 | +} | |
| 111 | + | |
| 112 | +/** | |
| 113 | + * Disable button if text field is empty | |
| 114 | + */ | |
| 115 | +function disableButtonIfEmtpyField(field_selector, button_selector) { | |
| 116 | + field = $(field_selector); | |
| 117 | + if(field.val() == "") { | |
| 118 | + field.closest("form").find(button_selector).attr("disabled", "disabled").addClass("disabled"); | |
| 119 | + } | |
| 120 | + | |
| 121 | + field.on('keyup', function(){ | |
| 122 | + var field = $(this); | |
| 123 | + var closest_submit = field.closest("form").find(button_selector); | |
| 124 | + if(field.val() == "") { | |
| 125 | + closest_submit.attr("disabled", "disabled").addClass("disabled"); | |
| 126 | + } else { | |
| 127 | + closest_submit.removeAttr("disabled").removeClass("disabled"); | |
| 128 | + } | |
| 129 | + }) | |
| 130 | +} | ... | ... |
app/assets/javascripts/projects.js.coffee
| 1 | 1 | window.Projects = -> |
| 2 | - $("#project_name").live "change", -> | |
| 3 | - slug = slugify($(this).val()) | |
| 4 | - $("#project_code").val(slug) | |
| 5 | - $("#project_path").val(slug) | |
| 2 | + $('#project_name').on 'change', -> | |
| 3 | + slug = slugify $(@).val() | |
| 4 | + $('#project_code').val slug | |
| 6 | 5 | |
| 7 | - $(".new_project, .edit_project").live "ajax:before", -> | |
| 8 | - $(".project_new_holder, .project_edit_holder").hide() | |
| 9 | - $(".save-project-loader").show() | |
| 6 | + $('.new_project, .edit_project').on 'ajax:before', -> | |
| 7 | + $('.project_new_holder, .project_edit_holder').hide() | |
| 8 | + $('.save-project-loader').show() | |
| 10 | 9 | |
| 11 | - $("form #project_default_branch").chosen() | |
| 12 | - disableButtonIfEmtpyField "#project_name", ".project-submit" | |
| 10 | + $('form #project_default_branch').chosen() | |
| 11 | + disableButtonIfEmtpyField '#project_name', '.project-submit' | |
| 13 | 12 | |
| 14 | 13 | # Git clone panel switcher |
| 15 | 14 | $ -> |
| 16 | - scope = $('.project_clone_holder') | |
| 15 | + scope = $ '.project_clone_holder' | |
| 17 | 16 | if scope.length > 0 |
| 18 | 17 | $('a, button', scope).click -> |
| 19 | - $('a, button', scope).removeClass('active') | |
| 20 | - $(this).addClass('active') | |
| 21 | - $('#project_clone', scope).val($(this).data('clone')) | |
| 18 | + $('a, button', scope).removeClass 'active' | |
| 19 | + $(@).addClass 'active' | |
| 20 | + $('#project_clone', scope).val $(@).data 'clone' | ... | ... |
app/assets/javascripts/snippets.js
app/assets/javascripts/team.js
app/controllers/commits_controller.rb
| ... | ... | @@ -64,19 +64,14 @@ class CommitsController < ApplicationController |
| 64 | 64 | @commit.to_patch, |
| 65 | 65 | type: "text/plain", |
| 66 | 66 | disposition: 'attachment', |
| 67 | - filename: (@commit.id.to_s + ".patch") | |
| 67 | + filename: "#{@commit.id.patch}" | |
| 68 | 68 | ) |
| 69 | 69 | end |
| 70 | 70 | |
| 71 | 71 | protected |
| 72 | 72 | |
| 73 | 73 | def load_refs |
| 74 | - if params[:ref].blank? | |
| 75 | - @branch = params[:branch].blank? ? nil : params[:branch] | |
| 76 | - @tag = params[:tag].blank? ? nil : params[:tag] | |
| 77 | - @ref = @branch || @tag || @project.try(:default_branch) || 'master' | |
| 78 | - else | |
| 79 | - @ref = params[:ref] | |
| 80 | - end | |
| 74 | + @ref ||= params[:ref].presence || params[:branch].presence || params[:tag].presence | |
| 75 | + @ref ||= @ref || @project.try(:default_branch) || 'master' | |
| 81 | 76 | end |
| 82 | 77 | end | ... | ... |