From 2db6464949e65df55396640dda598ffcdd27420c Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sun, 13 Nov 2016 15:02:17 +0800 Subject: webui: Store config validity; Check before start task * "updateFormConfigStatus()": Store the configuration validity as a custom data attribute. * Check the current configuration validity before start the task on the server. --- fg21sim/webui/static/js/configs.js | 16 ++++++++++------ fg21sim/webui/static/js/websocket.js | 10 +++++++--- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'fg21sim/webui/static') diff --git a/fg21sim/webui/static/js/configs.js b/fg21sim/webui/static/js/configs.js index d05892b..4e635ae 100644 --- a/fg21sim/webui/static/js/configs.js +++ b/fg21sim/webui/static/js/configs.js @@ -262,28 +262,32 @@ var setFormConfigs = function (data, errors) { /** * Update the configuration form status indicator: "#conf-status" + * Also store the validity status in a custom data attribute. */ var updateFormConfigStatus = function () { + var target = $("#conf-status"); var recheck_icon = $("#conf-recheck"); var invalid = $("#conf-form").find("input[name]:invalid"); if (invalid.length) { // Exists invalid configurations console.warn("Found", invalid.length, "invalid configurations!"); recheck_icon.show(); - $("#conf-status").removeClass("label-default label-success") + target.removeClass("label-default label-success") .addClass("label-warning"); - $("#conf-status .icon").removeClass("fa-question-circle fa-check-circle") + target.find(".icon").removeClass("fa-question-circle fa-check-circle") .addClass("fa-warning"); - $("#conf-status .text").text("Invalid!"); + target.find(".text").text("Invalid!"); + target.data("validity", false); } else { // All valid // console.info("Great, all configurations are valid :)"); recheck_icon.hide(); - $("#conf-status").removeClass("label-default label-warning") + target.removeClass("label-default label-warning") .addClass("label-success"); - $("#conf-status .icon").removeClass("fa-question-circle fa-warning") + target.find(".icon").removeClass("fa-question-circle fa-warning") .addClass("fa-check-circle"); - $("#conf-status .text").text("Valid :)"); + target.find(".text").text("Valid :)"); + target.data("validity", true); } }; diff --git a/fg21sim/webui/static/js/websocket.js b/fg21sim/webui/static/js/websocket.js index fdca619..26d7fce 100644 --- a/fg21sim/webui/static/js/websocket.js +++ b/fg21sim/webui/static/js/websocket.js @@ -227,9 +227,13 @@ $(document).ready(function () { // Start the task on the server $("#task-start").on("click", function () { - updateTaskStatus({running: true, finished: false}); - startServerTask(g_ws); - getServerTaskStatus(g_ws); + if ($("#conf-status").data("validity")) { + updateTaskStatus({running: true, finished: false}); + startServerTask(g_ws); + getServerTaskStatus(g_ws); + } else { + console.error("Exist invalid configuration values!"); + } }); /* Logging messages controls */ -- cgit v1.2.2