Browse Source

Show list of categories on WebUI download page

adaptive-webui-19844
Thomas Piccirello 6 years ago
parent
commit
7151d6babd
  1. 7
      src/webui/www/private/download.html
  2. 57
      src/webui/www/private/scripts/download.js
  3. 7
      src/webui/www/private/upload.html

7
src/webui/www/private/download.html

@ -60,7 +60,12 @@ @@ -60,7 +60,12 @@
<label for="category">QBT_TR(Category:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
</td>
<td>
<input type="text" id="category" name="category" style="width: 16em;" />
<div class="select-watched-folder-editable">
<select id="categorySelect" onchange="changeCategorySelect(this)">
<option selected value="\other"></option>
</select>
<input name="category" type="text" value="" />
</div>
</td>
</tr>
<tr>

57
src/webui/www/private/scripts/download.js

@ -21,6 +21,28 @@ @@ -21,6 +21,28 @@
* THE SOFTWARE.
*/
var categories = {};
var defaultSavePath = "";
getCategories = function() {
new Request.JSON({
url: 'api/v2/torrents/categories',
noCache: true,
method: 'get',
onSuccess: function(data) {
if (data) {
categories = data;
for (var i in data) {
var category = data[i];
var option = new Element("option");
option.set('value', category.name);
option.set('html', category.name);
$('categorySelect').appendChild(option);
}
}
}
}).send();
};
getPreferences = function() {
new Request.JSON({
@ -32,7 +54,8 @@ getPreferences = function() { @@ -32,7 +54,8 @@ getPreferences = function() {
},
onSuccess: function(pref) {
if (pref) {
$('savepath').setProperty('value', pref.save_path);
defaultSavePath = pref.save_path;
$('savepath').setProperty('value', defaultSavePath);
if (pref.auto_tmm_enabled == 1) {
$('autoTMM').selectedIndex = 1;
$('savepath').disabled = true;
@ -45,15 +68,47 @@ getPreferences = function() { @@ -45,15 +68,47 @@ getPreferences = function() {
}).send();
};
changeCategorySelect = function(item) {
if (item.value == "\\other") {
item.nextElementSibling.hidden = false;
item.nextElementSibling.value = "";
item.nextElementSibling.select();
if ($('autotmm').selectedIndex == 1)
$('savepath').value = defaultSavePath;
}
else {
item.nextElementSibling.hidden = true;
var text = item.options[item.selectedIndex].innerHTML;
item.nextElementSibling.value = text;
if ($('autotmm').selectedIndex == 1) {
var categoryName = item.value;
var category = categories[categoryName];
var savePath = defaultSavePath;
if (category !== undefined)
savePath = (category['savePath'] !== "") ? category['savePath'] : (defaultSavePath + categoryName);
$('savepath').value = savePath;
}
}
};
changeTMM = function(item) {
if (item.selectedIndex == 1) {
$('savepath').disabled = true;
var categorySelect = $('categorySelect');
var categoryName = categorySelect.options[categorySelect.selectedIndex].value;
var category = categories[categoryName];
$('savepath').value = (category === undefined) ? "" : category['savePath'];
}
else {
$('savepath').disabled = false;
$('savepath').value = defaultSavePath;
}
};
$(window).addEventListener("load", function() {
getPreferences();
getCategories();
});

7
src/webui/www/private/upload.html

@ -50,7 +50,12 @@ @@ -50,7 +50,12 @@
<label for="category">QBT_TR(Category:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
</td>
<td>
<input type="text" id="category" name="category" style="width: 16em;" />
<div class="select-watched-folder-editable">
<select id="categorySelect" onchange="changeCategorySelect(this)">
<option selected value="\other"></option>
</select>
<input name="category" type="text" value="" />
</div>
</td>
</tr>
<tr>

Loading…
Cancel
Save