From 04ad197bcc41a26da2c2a80c5b4ffbfad2c296ee Mon Sep 17 00:00:00 2001
From: Robert Schilling <rschilling@student.tugraz.at>
Date: Wed, 13 Aug 2014 14:22:34 +0200
Subject: [PATCH] Trigger an update of save button if user pressed a preview
 color

---
 app/assets/javascripts/application.js.coffee | 6 +++---
 app/assets/javascripts/labels.js.coffee      | 4 +++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee
index 9c53d3b4cc057..1960479321c2b 100644
--- a/app/assets/javascripts/application.js.coffee
+++ b/app/assets/javascripts/application.js.coffee
@@ -59,18 +59,18 @@ window.rstrip = (val) ->
 # Disable button if text field is empty
 window.disableButtonIfEmptyField = (field_selector, button_selector) ->
   field = $(field_selector)
-  closest_submit = field.closest("form").find(button_selector)
+  closest_submit = field.closest('form').find(button_selector)
 
   closest_submit.disable() if rstrip(field.val()) is ""
 
-  field.on "input", ->
+  field.on 'input', ->
     if rstrip($(@).val()) is ""
       closest_submit.disable()
     else
       closest_submit.enable()
 
 # Disable button if any input field with given selector is empty
-window.disableButtonIfEmptyField = (form, form_selector, button_selector) ->
+window.disableButtonIfAnyEmptyField = (form, form_selector, button_selector) ->
   closest_submit = form.find(button_selector)
   empty = false
   form.find('input').filter(form_selector).each ->
diff --git a/app/assets/javascripts/labels.js.coffee b/app/assets/javascripts/labels.js.coffee
index ce566b5afa30c..8e53d6929df24 100644
--- a/app/assets/javascripts/labels.js.coffee
+++ b/app/assets/javascripts/labels.js.coffee
@@ -16,7 +16,7 @@ class Labels
 
   # 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')
+    disableButtonIfAnyEmptyField form, '.form-control', form.find('.js-save-button')
 
   # Updates the the preview color with the hex-color input
   updateColorPreview: =>
@@ -28,6 +28,8 @@ class Labels
     color = $(e.currentTarget).data('color')
     $('input#label_color').val(color)
     @updateColorPreview()
+    # Notify the form, that color has changed
+    $('.label-form').trigger('keyup')
     e.preventDefault()
 
 @Labels = Labels
-- 
GitLab