diff options
author | Pawel Spychalski (DzikuVx) <pspychalski@gmail.com> | 2020-04-14 12:55:23 +0300 |
---|---|---|
committer | Pawel Spychalski (DzikuVx) <pspychalski@gmail.com> | 2020-04-14 12:55:23 +0300 |
commit | c005214a2be16fbdf5024462267b7509f4234778 (patch) | |
tree | 64f58c8d904c49d67164c815c92209e216183950 /js | |
parent | dd551f5ecb37a1e34007ef9c4450c5a592b06883 (diff) |
Unified LogicConditions selector
Diffstat (limited to 'js')
-rw-r--r-- | js/globalFunction.js | 22 | ||||
-rw-r--r-- | js/gui.js | 22 |
2 files changed, 29 insertions, 15 deletions
diff --git a/js/globalFunction.js b/js/globalFunction.js index 933ba078..be1a22e2 100644 --- a/js/globalFunction.js +++ b/js/globalFunction.js @@ -165,21 +165,13 @@ let GlobalFunction = function (enabled, conditionId, action, operandType, operan self.renderLogicId = function($row) { if (self.getEnabled()) { - - $row.find('.function_cell__logicId').html("<select class='function__logicId' ></select>"); - let $t = $row.find(".function__logicId"); - let count = LOGIC_CONDITIONS.getCount(); - - console.log(self.getConditionId()); - - for (let i = 0; i < count ; i++) { - if (i == self.getConditionId()) { - $t.append('<option value="' + i + '" selected>Logic Condition ' + i + ' </option>'); - } else { - $t.append('<option value="' + i + '">Logic Condition ' + i + ' </option>'); - } - } - $t.change(self.onLogicIdChange); + GUI.renderLogicConditionSelect( + $row.find('.function_cell__logicId'), + LOGIC_CONDITIONS, + self.getConditionId(), + self.onLogicIdChange, + true + ); } else { $row.find('.function_cell__logicId').html(""); } @@ -292,5 +292,27 @@ GUI_control.prototype.renderOperandValue = function ($container, operandMetadata $container.find('.logic_element__operand--value').change(onChange); }; +/** + * @param {jQuery} $container + * @param {LogicConditionsCollection} logicConditions + * @param {int} current + * @param {function} onChange + * @param {boolean} withAlways + */ +GUI_control.prototype.renderLogicConditionSelect = function ($container, logicConditions, current, onChange, withAlways) { + + let $select = $container.append('<select class="mix-rule-condition">').find("select"), + lcCount = logicConditions.getCount(); + + if (withAlways) { + $select.append('<option value="-1">Always</option>') + } + for (let i = 0; i < lcCount ; i++) { + $select.append('<option value="' + i + '">Logic Condition ' + i + ' </option>'); + } + + $select.val(current).change(onChange); +} + // initialize object into GUI variable var GUI = new GUI_control(); |