Commit 6085b6a7 authored by Robert Schilling's avatar Robert Schilling

Move label coffeescript from view to class

parent 0b5e0e4c
class Labels class Labels
constructor: -> constructor: ->
# find the form
form = $('.label-form') form = $('.label-form')
@setupLabelForm(form) @setupLabelForm(form)
@cleanBinding()
@addBinding()
@updateColorPreview
### addBinding: ->
General note form setup. $(document).on 'click', '.suggest-colors a', @setSuggestedColor
$(document).on 'input', 'input#label_color', @updateColorPreview
deactivates the submit button when text is empty cleanBinding: ->
hides the preview button when text is empty $(document).off 'click', '.suggest-colors a'
setup GFM auto complete $(document).off 'input', 'input#label_color'
show the form
### # Initializes the form to disable the save button if no color or title is entered
setupLabelForm: (form) -> setupLabelForm: (form) ->
disableButtonIfEmptyField form, '.form-control', form.find('.js-save-button') 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 @Labels = Labels
...@@ -31,19 +31,3 @@ ...@@ -31,19 +31,3 @@
= f.submit 'Save', class: 'btn btn-save js-save-button' = f.submit 'Save', class: 'btn btn-save js-save-button'
= link_to "Cancel", project_labels_path(@project), class: 'btn btn-cancel' = 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()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment