app/views/script/index.erb in tailog-0.6.5 vs app/views/script/index.erb in tailog-0.6.6
- old
+ new
@@ -43,21 +43,25 @@
$("#mode").change(function() {
editor.setOption("mode", ModeMap[$(this).val()]);
});
var $content = $("#content"),
- $script = $("#script");
+ $script = $("#script"),
+ $submitButton = $("#submit-button"),
+ $broadcastButton = $("#broadcast-button"),
+ $buttons = $("#submit-button, #broadcast-button");
- $("#submit-button").click(function(event) {
+ $submitButton.click(function(event) {
event.preventDefault();
editor.save();
$script.ajaxSubmit({
beforeSend: function() {
$content
.html("<hr/>")
.append('<span class="text-info">Loading...</span>');
+ $buttons.attr("disabled", true);
},
error: function() {
$content
.html("<hr/>")
.append('<span class="text-danger">Oops! Something went wrong, please try again later!</span>');
@@ -70,31 +74,53 @@
.append('<span class="text-info">' + data.server_hostname + " - " + data.process_uuid + "</span>")
.append(ansi_up.ansi_to_html(data.content));
} catch (error) {
console.error(error);
}
+ },
+ complete: function() {
+ $buttons.attr("disabled", false);
}
});
});
- $("#broadcast-button").click(function(event) {
+ var ajaxInterval = null;
+ $broadcastButton.click(function(event) {
event.preventDefault();
editor.save();
+ function onComplete() {
+ $submitButton.attr("disabled", false);
+ $broadcastButton.text("Broadcast");
+ clearInterval(ajaxInterval);
+ ajaxInterval = null;
+ }
+
+ if (ajaxInterval) {
+ onComplete();
+ $(".progress-bar")
+ .removeClass("progress-bar-info active")
+ .addClass("progress-bar-danger");
+ return;
+ }
+
$content
.html("<hr/>")
- .append('<div class="progress"><div class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar" style="width: 0%"><span class="progress-bar-indicator">0 / 1 Requests, 0 Instances (0%)</span></div></div>');
+ .append('<div class="progress"><div class="progress-bar progress-bar-info progress-bar-striped active" role="progressbar" style="width: 0%"><span class="progress-bar-indicator">0 / 1 Requests, 0 Instances (0%)</span></div></div>');
+ $submitButton.attr("disabled", true);
+ $broadcastButton.text("Stop broadcasting!");
+
var $progressBar = $(".progress-bar"),
$indicator = $(".progress-bar-indicator");
var MaxCurrent = 10;
var discovered = [],
totalEstimate = 1,
currentTries = 0,
concurrent = 0;
- var ajaxInterval = setInterval(function() {
+ ajaxInterval = setInterval(function() {
if (currentTries < totalEstimate) {
if (concurrent < MaxCurrent) {
$script.ajaxSubmit({
data: {
broadcast: true,
@@ -134,10 +160,13 @@
concurrent -= 1;
}
});
}
} else if (concurrent === 0) {
- clearInterval(ajaxInterval);
+ onComplete();
+ $progressBar
+ .removeClass("progress-bar-info active")
+ .addClass("progress-bar-success");
}
}, 100);
});
</script>