Skip to content

Commit

Permalink
Fix display bugs in WebUI Files tab. Remove <IE9 support
Browse files Browse the repository at this point in the history
Priority select boxes would frequently go blank due to an unexpected priority value. On first load, the torrent-scoped file checkbox's state was inconsistent with the state of the torrent's files.
  • Loading branch information
Piccirello committed Dec 11, 2018
1 parent a44ed9c commit 6601516
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 83 deletions.
2 changes: 1 addition & 1 deletion src/webui/www/private/properties_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<table class="dynamicTable" style="width: 100%">
<thead>
<tr>
<th style="width: 4.5em; border-right: 0"><input type="checkbox" id="tristate_cb" style="display: none;" onclick="javascript:switchCBState()" /><label id="all_files_cb" class="tristate" for="tristate_cb"></label></th>
<th style="width: 4.5em; border-right: 0"><input type="checkbox" id="tristate_cb" onclick="switchCBState()" /></th>
<th>QBT_TR(Name)QBT_TR[CONTEXT=TorrentContentModel]</th>
<th style="width: 150px;">QBT_TR(Size)QBT_TR[CONTEXT=TorrentContentModel]</th>
<th style="width: 90px;">QBT_TR(Progress)QBT_TR[CONTEXT=TorrentContentModel]</th>
Expand Down
145 changes: 63 additions & 82 deletions src/webui/www/private/scripts/prop-files.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,46 @@
var is_seed = true;
var current_hash = "";

if (!(Browser.name == "ie" && Browser.version < 9)) {
$("all_files_cb").removeClass("tristate");
$("all_files_cb").removeClass("partial");
$("all_files_cb").removeClass("checked");
$("tristate_cb").style.display = "inline";
}

var setCBState = function(state) {
if (Browser.name == "ie" && Browser.version < 9) {
if (state == "partial") {
if (!$("all_files_cb").hasClass("partial")) {
$("all_files_cb").removeClass("checked");
$("all_files_cb").addClass("partial");
}
return;
}
if (state == "checked") {
if (!$("all_files_cb").hasClass("checked")) {
$("all_files_cb").removeClass("partial");
$("all_files_cb").addClass("checked");
}
return;
}
$("all_files_cb").removeClass("partial");
$("all_files_cb").removeClass("checked");
$("tristate_cb").state = state;
if (state === "partial") {
$("tristate_cb").indeterminate = true;
}
else {
if (state == "partial") {
$("tristate_cb").indeterminate = true;
}
else if (state == "checked") {
$("tristate_cb").indeterminate = false;
$("tristate_cb").checked = true;
}
else {
$("tristate_cb").indeterminate = false;
$("tristate_cb").checked = false;
}
else if (state === "checked") {
$("tristate_cb").indeterminate = false;
$("tristate_cb").checked = true;
}
else if (state === "unchecked") {
$("tristate_cb").indeterminate = false;
$("tristate_cb").checked = false;
}
};

var switchCBState = function() {
// Uncheck
if ($("all_files_cb").hasClass("partial")) {
$("all_files_cb").removeClass("partial");
if (($("tristate_cb").state === "partial") || ($("tristate_cb").state === "checked")) {
$("tristate_cb").state = "unchecked";
$("tristate_cb").checked = false;
// Uncheck all checkboxes
var indexes = [];
$$('input.DownloadedCB').each(function(item, index) {
item.erase("checked");
indexes.push(index);
});
setFilePriority(indexes, 0);
return;
}
if ($("all_files_cb").hasClass("checked")) {
$("all_files_cb").removeClass("checked");
// Uncheck all checkboxes
else if ($("tristate_cb").state === "unchecked") {
// Check
$("tristate_cb").state = "checked";
$("tristate_cb").checked = true;
// Check all checkboxes
var indexes = [];
$$('input.DownloadedCB').each(function(item, index) {
item.erase("checked");
item.set("checked", "checked");
indexes.push(index);
});
setFilePriority(indexes, 0);
return;
setFilePriority(indexes, FilePriority.Normal);
}
// Check
$("all_files_cb").addClass("checked");
// Check all checkboxes
var indexes = [];
$$('input.DownloadedCB').each(function(item, index) {
item.set("checked", "checked");
indexes.push(index);
});
setFilePriority(indexes, 1);
};

var allCBChecked = function() {
Expand All @@ -97,17 +63,42 @@ var allCBUnchecked = function() {
return true;
};

var FilePriority = {
"Ignored": 0,
"Normal": 1,
"High": 6,
"Maximum": 7,
"Mixed": -1
};

var normalizePriority = function(priority) {
switch (priority) {
case FilePriority.Ignored:
case FilePriority.Normal:
case FilePriority.High:
case FilePriority.Maximum:
case FilePriority.Mixed:
return priority;
default:
return FilePriority.Normal;
}
};

var setFilePriority = function(id, priority) {
if (current_hash === "") return;
var ids = Array.isArray(id) ? id : [id];

clearTimeout(loadTorrentFilesDataTimer);
new Request({
url: 'api/v2/torrents/filePrio',
method: 'post',
data: {
'hash': current_hash,
'id': ids.join('|'),
'priority': priority
},
onComplete: function() {
loadTorrentFilesDataTimer = loadTorrentFilesData.delay(1000);
}
}).send();
// Display or add combobox
Expand Down Expand Up @@ -142,13 +133,11 @@ var createDownloadedCB = function(id, downloaded) {
if (allCBChecked()) {
setCBState("checked");
}
else if (allCBUnchecked()) {
setCBState("unchecked");
}
else {
if (allCBUnchecked()) {
setCBState("unchecked");
}
else {
setCBState("partial");
}
setCBState("partial");
}
});
return CB;
Expand All @@ -166,23 +155,16 @@ var createPriorityCombo = function(id, selected_prio) {
var elem = new Element("option");
elem.set('value', priority.toString());
elem.set('html', html);
if (selected_prio == priority)
elem.setAttribute('selected', 'true');
if (priority == selected_prio)
elem.setAttribute('selected', '');
return elem;
}

var normal = createOptionElement(1, "QBT_TR(Normal)QBT_TR[CONTEXT=PropListDelegate]");
if (selected_prio <= 0)
normal.setAttribute('selected', '');
normal.injectInside(select);

var high = createOptionElement(6, "QBT_TR(High)QBT_TR[CONTEXT=PropListDelegate]");
high.injectInside(select);

var maximum = createOptionElement(7, "QBT_TR(Maximum)QBT_TR[CONTEXT=PropListDelegate]");
maximum.injectInside(select);
createOptionElement(FilePriority.Normal, "QBT_TR(Normal)QBT_TR[CONTEXT=PropListDelegate]").injectInside(select);
createOptionElement(FilePriority.High, "QBT_TR(High)QBT_TR[CONTEXT=PropListDelegate]").injectInside(select);
createOptionElement(FilePriority.Maximum, "QBT_TR(Maximum)QBT_TR[CONTEXT=PropListDelegate]").injectInside(select);

if (is_seed || selected_prio < 1) {
if (is_seed || (selected_prio === FilePriority.Ignored) || (selected_prio === FilePriority.Mixed)) {
select.addClass("invisible");
}
else {
Expand Down Expand Up @@ -231,8 +213,9 @@ var filesDynTable = new Class({
$('pbf_' + id).setValue(row[i].toFloat());
break;
case 4: // download priority
if (!is_seed && row[i] > 0) {
tds[i].getChildren('select').set('value', row[i]);
var priority = normalizePriority(row[i]);
if (!is_seed && (priority > 0)) {
tds[i].getChildren('select').set('value', priority);
if ($('comboPrio' + id).hasClass("invisible"))
$('comboPrio' + id).removeClass("invisible");
}
Expand Down Expand Up @@ -278,7 +261,7 @@ var filesDynTable = new Class({
}));
break;
case 4:
td.adopt(createPriorityCombo(id, row[i]));
td.adopt(createPriorityCombo(id, normalizePriority(row[i])));
break;
default:
td.set('html', row[i]);
Expand Down Expand Up @@ -346,13 +329,11 @@ var loadTorrentFilesData = function() {
if (allCBChecked()) {
setCBState("checked");
}
else if (allCBUnchecked()) {
setCBState("unchecked");
}
else {
if (allCBUnchecked()) {
setCBState("unchecked");
}
else {
setCBState("partial");
}
setCBState("partial");
}
}
else {
Expand Down

0 comments on commit 6601516

Please sign in to comment.