WebUI: Allow to control the alternative speed limits

setGlobalDownloadLimit and setGlobalUploadLimit will now modify the
alternative speed limits if they are currently enabled and the regular
speed limits otherwise.

Add also two new commands to toggle the state of the alternative speed
limits and get their current state.

Closes #2203.
This commit is contained in:
Gabriele 2014-12-14 10:00:00 +01:00
parent 25e8cad16c
commit c53b19d6c1
4 changed files with 63 additions and 3 deletions

View file

@ -27,6 +27,7 @@ myTable = new dynamicTable();
var updatePropertiesPanel = function(){};
var updateTransferInfo = function(){};
var updateTransferList = function(){};
var alternativeSpeedsLimit = false;
var stateToImg = function (state) {
if (state == "pausedUP" || state == "pausedDL") {
@ -278,6 +279,40 @@ window.addEvent('load', function () {
// Start fetching data now
loadTransferInfo();
var updateAltSpeedIcon = function(enabled) {
if (enabled)
$('alternativeSpeedLimits').src = "images/slow.png";
else
$('alternativeSpeedLimits').src = "images/slow_off.png"
}
// Determine whether the alternative speed limits are enabled or not
new Request({url: 'command/alternativeSpeedLimitsEnabled',
method: 'get',
onSuccess : function (isEnabled) {
alternativeSpeedsLimit = !!isEnabled;
if (alternativeSpeedsLimit)
$('alternativeSpeedLimits').src = "images/slow.png"
}
}).send();
$('alternativeSpeedLimits').addEvent('click', function() {
// Change icon immediately to give some feedback
updateAltSpeedIcon(!alternativeSpeedsLimit);
new Request({url: 'command/toggleAlternativeSpeedLimits',
method: 'post',
onComplete: function() {
alternativeSpeedsLimit = !alternativeSpeedsLimit;
updateTransferInfo();
},
onFailure: function() {
// Restore icon in case of failure
updateAltSpeedIcon(alternativeSpeedsLimit)
}
}).send();
});
$('DlInfos').addEvent('click', globalDownloadLimitFN);
$('UpInfos').addEvent('click', globalUploadLimitFN);