commit 74db519be12e92e518ece4d2b7cadbbe88eea375
Author: cagy <ml.cagy@seznam.cz>
Date:   Tue Sep 1 13:39:02 2020 +0200

    re #8119 - fix values functions bug, js refactoring

diff --git a/src/main/webapp/WEB-INF/templates/assembly.html b/src/main/webapp/WEB-INF/templates/assembly.html
index 6d24b2a3..2a37c813 100644
--- a/src/main/webapp/WEB-INF/templates/assembly.html
+++ b/src/main/webapp/WEB-INF/templates/assembly.html
@@ -92,9 +92,7 @@
                                     </div>
                                 </td>
 
-                                <select class="form-control hidden" th:id="'function-select-' + ${itemStat.index}"
-                                        th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].functions}"
-                                        multiple>
+                                <select class="form-control hidden" th:id="'tmp-function-select-' + ${itemStat.index}" multiple>
                                     <option th:each="function : ${parameterInConfiguration.parameter.functions}"
                                             th:text="${function.name}" th:value="${{function.id}}"></option>
                                 </select>
diff --git a/src/main/webapp/js/assemblyScripts.js b/src/main/webapp/js/assemblyScripts.js
index e92fecf1..ac52ab27 100644
--- a/src/main/webapp/js/assemblyScripts.js
+++ b/src/main/webapp/js/assemblyScripts.js
@@ -4,6 +4,30 @@ let VALUE = 'value';
 
 $(document).ready(function() {
 
+    // init handlers for position buttons
+    initPositionButtons();
+
+    // init actions
+    initParameters();
+
+    // spinner init
+    initSpinnerToButtons();
+
+    // generation init
+    initTableGenerationButtons();
+
+    // sort selected parameters
+    initSelectedParameters();
+
+    // set up tooltips
+    initTooltips();
+
+});
+
+/**
+ * Sets up functionality for position buttons (add/remove elements from position box), headlights
+ */
+function initPositionButtons() {
     // reaction for add/delete parameters from selected fields (row, column, value)
     $('.select-action-button').on('click', function () {
         // if input has headlight class (parameter is already added -> remove)
@@ -38,23 +62,7 @@ $(document).ready(function() {
 
         validateCombination();
     });
-
-    // init actions
-    initParameters();
-
-    // spinner init
-    initSpinnerToButtons();
-
-    // generation init
-    initTableGenerationButtons();
-
-    // sort selected parameters
-    initSelectedParameters();
-
-    // set up tooltips
-    initTooltips();
-
-});
+}
 
 /**
  * Remove value from all selected fields
@@ -90,6 +98,7 @@ function getParameterIndex(button) {
  * @param hiddenValue
  */
 function addParameter(index, parameterName, type, hiddenValue) {
+    // basic set up for mapping element to dao object
     var row = document.createElement('tr');
     row.classList.add(type + '-parameter', 'parameter');
 
@@ -122,14 +131,25 @@ function addParameter(index, parameterName, type, hiddenValue) {
 
     var thirdTdBody;
 
-
+    // for value copy hidden select
     if (type == VALUE)
     {
-        thirdTdBody = $('#function-select-' + index).clone()[0];
+        // get parameter select for functions
+        thirdTdBody = $('#tmp-function-select-' + index).clone()[0];
+
+        // set up id for select
+        thirdTdBody.id = `parametersInConfiguration${index}.functions`;
+
+        // set up name for select
+        thirdTdBody.name = `parametersInConfiguration[${index}].functions`;
+
+        // select first option
         thirdTdBody.selectedIndex = 0;
 
+        // remove hidden class
         $(thirdTdBody).removeClass('hidden');
     }
+    // for row and column add textfield
     else
     {
         var secondTd = document.createElement('td');
@@ -151,8 +171,10 @@ function addParameter(index, parameterName, type, hiddenValue) {
 
     row.appendChild(thirdTd);
 
+    // append element to type wrapper
     $('#' + type + '-wrapper').append($(row));
 
+    // reindex parameters order
     reindexOrder();
 
 }
@@ -225,12 +247,13 @@ function getParameterTitle(context) {
 }
 
 /**
- * Init base actions
+ * Allow sort on parameters
  */
 function initParameters()
 {
     $('.sortable').sortable({
        stop: function () {
+           // after change reindex parameters order
            reindexOrder();
        }
     });
