2014-10-20 16:48:07 -04:00
|
|
|
class @Labels
|
2014-08-11 14:15:12 -04:00
|
|
|
constructor: ->
|
|
|
|
form = $('.label-form')
|
|
|
|
@setupLabelForm(form)
|
2014-08-11 17:48:54 -04:00
|
|
|
@cleanBinding()
|
|
|
|
@addBinding()
|
2014-08-20 12:11:51 -04:00
|
|
|
@updateColorPreview()
|
2014-08-11 14:15:12 -04:00
|
|
|
|
2014-08-11 17:48:54 -04:00
|
|
|
addBinding: ->
|
|
|
|
$(document).on 'click', '.suggest-colors a', @setSuggestedColor
|
|
|
|
$(document).on 'input', 'input#label_color', @updateColorPreview
|
2014-08-11 14:15:12 -04:00
|
|
|
|
2014-08-11 17:48:54 -04:00
|
|
|
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
|
2014-08-11 14:15:12 -04:00
|
|
|
setupLabelForm: (form) ->
|
2014-08-13 08:22:34 -04:00
|
|
|
disableButtonIfAnyEmptyField form, '.form-control', form.find('.js-save-button')
|
2014-08-11 14:15:12 -04:00
|
|
|
|
2014-08-11 17:48:54 -04:00
|
|
|
# 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()
|
2014-08-13 08:22:34 -04:00
|
|
|
# Notify the form, that color has changed
|
|
|
|
$('.label-form').trigger('keyup')
|
2014-08-11 17:48:54 -04:00
|
|
|
e.preventDefault()
|