diff options
-rw-r--r-- | app/assets/javascripts/labels.js.coffee | 31 | ||||
-rw-r--r-- | app/views/projects/labels/_form.html.haml | 16 |
2 files changed, 23 insertions, 24 deletions
diff --git a/app/assets/javascripts/labels.js.coffee b/app/assets/javascripts/labels.js.coffee index e6ab3f9ee12..ce566b5afa3 100644 --- a/app/assets/javascripts/labels.js.coffee +++ b/app/assets/javascripts/labels.js.coffee @@ -1,18 +1,33 @@ class Labels constructor: -> - # find the form form = $('.label-form') @setupLabelForm(form) + @cleanBinding() + @addBinding() + @updateColorPreview - ### - General note form setup. + addBinding: -> + $(document).on 'click', '.suggest-colors a', @setSuggestedColor + $(document).on 'input', 'input#label_color', @updateColorPreview - deactivates the submit button when text is empty - hides the preview button when text is empty - setup GFM auto complete - show the form - ### + cleanBinding: -> + $(document).off 'click', '.suggest-colors a' + $(document).off 'input', 'input#label_color' + + # Initializes the form to disable the save button if no color or title is entered setupLabelForm: (form) -> disableButtonIfEmptyField form, '.form-control', form.find('.js-save-button') + # Updates the the preview color with the hex-color input + updateColorPreview: => + previewColor = $('input#label_color').val() + $('div.label-color-preview').css('background-color', previewColor) + + # Updates the preview color with a click on a suggested color + setSuggestedColor: (e) => + color = $(e.currentTarget).data('color') + $('input#label_color').val(color) + @updateColorPreview() + e.preventDefault() + @Labels = Labels diff --git a/app/views/projects/labels/_form.html.haml b/app/views/projects/labels/_form.html.haml index be7fddc65e7..72a01e1c271 100644 --- a/app/views/projects/labels/_form.html.haml +++ b/app/views/projects/labels/_form.html.haml @@ -31,19 +31,3 @@ = f.submit 'Save', class: 'btn btn-save js-save-button' = link_to "Cancel", project_labels_path(@project), class: 'btn btn-cancel' - -:coffeescript - updateColorPreview = -> - previewColor = $('input#label_color').val() - $('div.label-color-preview').css('background-color', previewColor) - - $('.suggest-colors a').on 'click', (e) -> - color = $(this).data("color") - $('input#label_color').val(color) - updateColorPreview() - e.preventDefault() - - $('input#label_color').on 'input', -> - updateColorPreview() - - updateColorPreview() |