1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-16 09:40:13 +00:00

224 lines
10 KiB
JavaScript
Raw Normal View History

2014-12-20 20:29:17 +03:00
/*
Script: Parametrics.js
Initializes the GUI property sliders.
Copyright:
Copyright (c) 2007-2008 Greg Houston, <http://greghoustondesign.com/>.
License:
MIT-style license.
Requires:
Core.js, Window.js
*/
MochaUI.extend({
2015-02-01 12:08:45 -05:00
addUpLimitSlider: function(hashes) {
2014-12-20 20:29:17 +03:00
if ($('uplimitSliderarea')) {
var windowOptions = MochaUI.Windows.windowOptions;
var sliderFirst = true;
// Get global upload limit
var maximum = 500;
var req = new Request({
url: 'command/getGlobalUpLimit',
method: 'post',
data: {},
onSuccess: function(data) {
if (data) {
var tmp = data.toInt();
if (tmp > 0) {
maximum = tmp / 1024.
}
else {
2015-02-01 12:08:45 -05:00
if (hashes[0] == "global")
2014-12-20 20:29:17 +03:00
maximum = 10000;
else
maximum = 1000;
}
}
2015-02-01 12:08:45 -05:00
// Get torrents upload limit
2014-12-20 20:29:17 +03:00
// And create slider
2015-02-01 12:08:45 -05:00
if (hashes[0] == 'global') {
2014-12-20 20:29:17 +03:00
var up_limit = maximum;
if (up_limit < 0) up_limit = 0;
maximum = 10000;
var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), {
steps: maximum,
offset: 0,
initialStep: up_limit.round(),
onChange: function(pos) {
if (pos > 0) {
$('uplimitUpdatevalue').value = pos;
$('upLimitUnit').style.visibility = "visible";
}
else {
$('uplimitUpdatevalue').value = '∞';
$('upLimitUnit').style.visibility = "hidden";
}
}.bind(this)
});
// Set default value
if (up_limit == 0) {
$('uplimitUpdatevalue').value = '∞';
$('upLimitUnit').style.visibility = "hidden";
}
else {
$('uplimitUpdatevalue').value = up_limit.round();
$('upLimitUnit').style.visibility = "visible";
}
}
else {
2015-02-01 12:08:45 -05:00
var req = new Request.JSON({
url: 'command/getTorrentsUpLimit',
noCache : true,
2014-12-20 20:29:17 +03:00
method: 'post',
data: {
2015-02-01 12:08:45 -05:00
hashes: hashes.join('|')
2014-12-20 20:29:17 +03:00
},
onSuccess: function(data) {
if (data) {
2015-02-01 12:08:45 -05:00
var up_limit = data[hashes[0]];
for(var key in data)
if (up_limit != data[key]) {
up_limit = 0;
break;
}
2014-12-20 20:29:17 +03:00
if (up_limit < 0) up_limit = 0;
var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), {
steps: maximum,
offset: 0,
initialStep: (up_limit / 1024.).round(),
onChange: function(pos) {
if (pos > 0) {
$('uplimitUpdatevalue').value = pos;
$('upLimitUnit').style.visibility = "visible";
}
else {
$('uplimitUpdatevalue').value = '∞';
$('upLimitUnit').style.visibility = "hidden";
}
}.bind(this)
});
// Set default value
if (up_limit == 0) {
$('uplimitUpdatevalue').value = '∞';
$('upLimitUnit').style.visibility = "hidden";
}
else {
$('uplimitUpdatevalue').value = (up_limit / 1024.).round();
$('upLimitUnit').style.visibility = "visible";
}
}
}
}).send();
}
}
}).send();
}
},
2015-02-01 12:45:37 -05:00
addDlLimitSlider: function(hashes) {
2014-12-20 20:29:17 +03:00
if ($('dllimitSliderarea')) {
var windowOptions = MochaUI.Windows.windowOptions;
var sliderFirst = true;
// Get global upload limit
var maximum = 500;
var req = new Request({
url: 'command/getGlobalDlLimit',
method: 'post',
data: {},
onSuccess: function(data) {
if (data) {
var tmp = data.toInt();
if (tmp > 0) {
maximum = tmp / 1024.
}
else {
2015-02-01 12:45:37 -05:00
if (hashes[0] == "global")
2014-12-20 20:29:17 +03:00
maximum = 10000;
else
maximum = 1000;
}
}
2015-02-01 12:45:37 -05:00
// Get torrents download limit
2014-12-20 20:29:17 +03:00
// And create slider
2015-02-01 12:45:37 -05:00
if (hashes[0] == 'global') {
2014-12-20 20:29:17 +03:00
var dl_limit = maximum;
if (dl_limit < 0) dl_limit = 0;
maximum = 10000;
var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), {
steps: maximum,
offset: 0,
initialStep: dl_limit.round(),
onChange: function(pos) {
if (pos > 0) {
$('dllimitUpdatevalue').value = pos;
$('dlLimitUnit').style.visibility = "visible";
}
else {
$('dllimitUpdatevalue').value = '∞';
$('dlLimitUnit').style.visibility = "hidden";
}
}.bind(this)
});
// Set default value
if (dl_limit == 0) {
$('dllimitUpdatevalue').value = '∞';
$('dlLimitUnit').style.visibility = "hidden";
}
else {
$('dllimitUpdatevalue').value = dl_limit.round();
$('dlLimitUnit').style.visibility = "visible";
}
}
else {
2015-02-01 12:45:37 -05:00
var req = new Request.JSON({
url: 'command/getTorrentsDlLimit',
noCache : true,
2014-12-20 20:29:17 +03:00
method: 'post',
data: {
2015-02-01 12:45:37 -05:00
hashes: hashes.join('|')
2014-12-20 20:29:17 +03:00
},
onSuccess: function(data) {
if (data) {
2015-02-01 12:45:37 -05:00
var dl_limit = data[hashes[0]];
for(var key in data)
if (dl_limit != data[key]) {
dl_limit = 0;
break;
}
2014-12-20 20:29:17 +03:00
if (dl_limit < 0) dl_limit = 0;
var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), {
steps: maximum,
offset: 0,
initialStep: (dl_limit / 1024.).round(),
onChange: function(pos) {
if (pos > 0) {
$('dllimitUpdatevalue').value = pos;
$('dlLimitUnit').style.visibility = "visible";
}
else {
$('dllimitUpdatevalue').value = '∞';
$('dlLimitUnit').style.visibility = "hidden";
}
}.bind(this)
});
// Set default value
if (dl_limit == 0) {
$('dllimitUpdatevalue').value = '∞';
$('dlLimitUnit').style.visibility = "hidden";
}
else {
$('dllimitUpdatevalue').value = (dl_limit / 1024.).round();
$('dlLimitUnit').style.visibility = "visible";
}
}
}
}).send();
}
}
}).send();
}
}
});