2011-09-14 05:10:51 +00:00
|
|
|
/**
|
|
|
|
* Copyright © Mnemosyne LLC
|
|
|
|
*
|
|
|
|
* This file is licensed under the GPLv2.
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2011-08-16 18:49:26 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-23 22:05:21 +00:00
|
|
|
function FileRow(torrent, depth, name, indices, even)
|
2011-08-16 18:49:26 +00:00
|
|
|
{
|
2011-09-03 04:33:04 +00:00
|
|
|
var fields = {
|
|
|
|
have: 0,
|
2012-09-23 22:05:21 +00:00
|
|
|
indices: [],
|
2011-09-03 04:33:04 +00:00
|
|
|
isWanted: true,
|
2012-09-23 22:05:21 +00:00
|
|
|
priorityLow: false,
|
2012-09-23 22:55:21 +00:00
|
|
|
priorityNormal: false,
|
2012-09-23 22:05:21 +00:00
|
|
|
priorityHigh: false,
|
2011-09-03 04:33:04 +00:00
|
|
|
me: this,
|
|
|
|
size: 0,
|
|
|
|
torrent: null
|
2011-08-16 18:49:26 +00:00
|
|
|
},
|
|
|
|
|
2011-09-03 04:33:04 +00:00
|
|
|
elements = {
|
2011-10-21 02:58:19 +00:00
|
|
|
priority_low_button: null,
|
|
|
|
priority_normal_button: null,
|
|
|
|
priority_high_button: null,
|
2011-09-03 04:33:04 +00:00
|
|
|
progress: null,
|
|
|
|
root: null
|
2011-08-16 18:49:26 +00:00
|
|
|
},
|
2011-09-03 04:33:04 +00:00
|
|
|
|
2012-09-23 22:05:21 +00:00
|
|
|
initialize = function(torrent, depth, name, indices, even) {
|
2011-09-03 04:33:04 +00:00
|
|
|
fields.torrent = torrent;
|
2012-09-23 22:05:21 +00:00
|
|
|
fields.indices = indices;
|
|
|
|
createRow(torrent, depth, name, even);
|
2011-08-28 13:57:25 +00:00
|
|
|
},
|
|
|
|
|
2011-09-03 04:33:04 +00:00
|
|
|
refreshWantedHTML = function()
|
2011-08-28 13:57:25 +00:00
|
|
|
{
|
2011-10-21 02:58:19 +00:00
|
|
|
var e = $(elements.root);
|
|
|
|
e.toggleClass('skip', !fields.isWanted);
|
|
|
|
e.toggleClass('complete', isDone());
|
2012-10-15 04:32:48 +00:00
|
|
|
$(e[0].checkbox).prop('disabled', !isEditable());
|
2011-10-26 15:50:31 +00:00
|
|
|
$(e[0].checkbox).prop('checked', fields.isWanted);
|
2011-08-28 13:57:25 +00:00
|
|
|
},
|
2011-09-03 04:33:04 +00:00
|
|
|
refreshProgressHTML = function()
|
2011-08-28 13:57:25 +00:00
|
|
|
{
|
2011-09-03 04:33:04 +00:00
|
|
|
var pct = 100 * (fields.size ? (fields.have / fields.size) : 1.0),
|
|
|
|
c = [ Transmission.fmt.size(fields.have),
|
2011-08-28 13:57:25 +00:00
|
|
|
' of ',
|
2011-09-03 04:33:04 +00:00
|
|
|
Transmission.fmt.size(fields.size),
|
2011-08-28 13:57:25 +00:00
|
|
|
' (',
|
|
|
|
Transmission.fmt.percentString(pct),
|
|
|
|
'%)' ].join('');
|
2012-07-20 17:37:50 +00:00
|
|
|
setTextContent(elements.progress, c);
|
2011-08-28 13:57:25 +00:00
|
|
|
},
|
2012-09-23 22:05:21 +00:00
|
|
|
refreshImpl = function() {
|
|
|
|
var i,
|
|
|
|
file,
|
|
|
|
have = 0,
|
|
|
|
size = 0,
|
|
|
|
wanted = false,
|
|
|
|
low = false,
|
|
|
|
normal = false,
|
|
|
|
high = false;
|
|
|
|
|
|
|
|
// loop through the file_indices that affect this row
|
|
|
|
for (i=0; i<fields.indices.length; ++i) {
|
|
|
|
file = fields.torrent.getFile (fields.indices[i]);
|
|
|
|
have += file.bytesCompleted;
|
|
|
|
size += file.length;
|
|
|
|
wanted |= file.wanted;
|
|
|
|
switch (file.priority) {
|
|
|
|
case -1: low = true; break;
|
|
|
|
case 0: normal = true; break;
|
|
|
|
case 1: high = true; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((fields.have != have) || (fields.size != size)) {
|
|
|
|
fields.have = have;
|
|
|
|
fields.size = size;
|
2011-09-03 04:33:04 +00:00
|
|
|
refreshProgressHTML();
|
2012-09-23 22:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fields.isWanted !== wanted) {
|
|
|
|
fields.isWanted = wanted;
|
2011-09-03 04:33:04 +00:00
|
|
|
refreshWantedHTML();
|
2011-08-28 13:57:25 +00:00
|
|
|
}
|
2012-09-23 22:05:21 +00:00
|
|
|
|
|
|
|
if (fields.priorityLow !== low) {
|
|
|
|
fields.priorityLow = low;
|
|
|
|
$(elements.priority_low_button).toggleClass('selected', low);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fields.priorityNormal !== normal) {
|
|
|
|
fields.priorityNormal = normal;
|
|
|
|
$(elements.priority_normal_button).toggleClass('selected', normal);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fields.priorityHigh !== high) {
|
|
|
|
fields.priorityHigh = high;
|
|
|
|
$(elements.priority_high_button).toggleClass('selected', high);
|
|
|
|
}
|
2011-08-16 18:49:26 +00:00
|
|
|
},
|
|
|
|
|
2011-09-03 04:33:04 +00:00
|
|
|
isDone = function () {
|
|
|
|
return fields.have >= fields.size;
|
2011-08-28 13:57:25 +00:00
|
|
|
},
|
2012-10-15 04:32:48 +00:00
|
|
|
isEditable = function () {
|
|
|
|
return (fields.torrent.getFileCount()>1) && !isDone();
|
2012-10-29 22:14:46 +00:00
|
|
|
},
|
2011-08-16 18:49:26 +00:00
|
|
|
|
2012-09-23 22:05:21 +00:00
|
|
|
createRow = function(torrent, depth, name, even) {
|
|
|
|
var e, root, box;
|
2011-08-28 13:57:25 +00:00
|
|
|
|
|
|
|
root = document.createElement('li');
|
2012-09-23 22:05:21 +00:00
|
|
|
root.className = 'inspector_torrent_file_list_entry' + (even?'even':'odd');
|
2011-10-21 02:58:19 +00:00
|
|
|
elements.root = root;
|
|
|
|
|
2011-10-26 15:50:31 +00:00
|
|
|
e = document.createElement('input');
|
|
|
|
e.type = 'checkbox';
|
2011-10-21 02:58:19 +00:00
|
|
|
e.className = "file_wanted_control";
|
2011-10-26 15:50:31 +00:00
|
|
|
e.title = 'Download file';
|
|
|
|
$(e).change(function(ev){ fireWantedChanged( $(ev.currentTarget).prop('checked')); });
|
|
|
|
root.checkbox = e;
|
2011-10-21 02:58:19 +00:00
|
|
|
root.appendChild(e);
|
|
|
|
|
|
|
|
e = document.createElement('div');
|
|
|
|
e.className = 'file-priority-radiobox';
|
|
|
|
box = e;
|
|
|
|
|
|
|
|
e = document.createElement('div');
|
|
|
|
e.className = 'low';
|
|
|
|
e.title = 'Low Priority';
|
|
|
|
$(e).click(function(){ firePriorityChanged(-1); });
|
|
|
|
elements.priority_low_button = e;
|
|
|
|
box.appendChild(e);
|
|
|
|
|
|
|
|
e = document.createElement('div');
|
|
|
|
e.className = 'normal';
|
|
|
|
e.title = 'Normal Priority';
|
|
|
|
$(e).click(function(){ firePriorityChanged(0); });
|
|
|
|
elements.priority_normal_button = e;
|
|
|
|
box.appendChild(e);
|
|
|
|
|
|
|
|
e = document.createElement('div');
|
|
|
|
e.title = 'High Priority';
|
|
|
|
e.className = 'high';
|
|
|
|
$(e).click(function(){ firePriorityChanged(1); });
|
|
|
|
elements.priority_high_button = e;
|
|
|
|
box.appendChild(e);
|
|
|
|
|
|
|
|
root.appendChild(box);
|
2011-08-16 18:49:26 +00:00
|
|
|
|
2011-10-21 02:58:19 +00:00
|
|
|
e = document.createElement('div');
|
|
|
|
e.className = "inspector_torrent_file_list_entry_name";
|
2012-07-20 17:37:50 +00:00
|
|
|
setTextContent(e, name);
|
2012-09-23 22:05:21 +00:00
|
|
|
$(e).click(function(){ fireNameClicked(-1); });
|
2011-10-21 02:58:19 +00:00
|
|
|
root.appendChild(e);
|
|
|
|
|
|
|
|
e = document.createElement('div');
|
|
|
|
e.className = "inspector_torrent_file_list_entry_progress";
|
|
|
|
root.appendChild(e);
|
2012-09-23 22:05:21 +00:00
|
|
|
$(e).click(function(){ fireNameClicked(-1); });
|
2011-10-21 02:58:19 +00:00
|
|
|
elements.progress = e;
|
2011-08-16 18:49:26 +00:00
|
|
|
|
2012-09-23 22:05:21 +00:00
|
|
|
$(root).css('margin-left', '' + (depth*16) + 'px');
|
|
|
|
|
|
|
|
refreshImpl();
|
2011-08-16 18:49:26 +00:00
|
|
|
return root;
|
2011-08-28 13:57:25 +00:00
|
|
|
},
|
2011-08-16 18:49:26 +00:00
|
|
|
|
2011-09-03 04:33:04 +00:00
|
|
|
fireWantedChanged = function(do_want) {
|
2012-09-23 22:05:21 +00:00
|
|
|
$(fields.me).trigger('wantedToggled',[ fields.indices, do_want ]);
|
2011-08-28 13:57:25 +00:00
|
|
|
},
|
2011-09-03 04:33:04 +00:00
|
|
|
firePriorityChanged = function(priority) {
|
2012-09-23 22:05:21 +00:00
|
|
|
$(fields.me).trigger('priorityToggled',[ fields.indices, priority ]);
|
|
|
|
},
|
|
|
|
fireNameClicked = function() {
|
|
|
|
$(fields.me).trigger('nameClicked',[ fields.me, fields.indices ]);
|
2011-09-03 04:33:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/***
|
|
|
|
**** PUBLIC
|
|
|
|
***/
|
|
|
|
|
|
|
|
this.getElement = function() {
|
|
|
|
return elements.root;
|
|
|
|
};
|
2012-09-23 22:05:21 +00:00
|
|
|
this.refresh = function() {
|
|
|
|
refreshImpl();
|
2012-08-18 15:04:06 +00:00
|
|
|
};
|
2011-09-03 04:33:04 +00:00
|
|
|
|
2012-09-23 22:05:21 +00:00
|
|
|
initialize(torrent, depth, name, indices, even);
|
2011-08-16 18:49:26 +00:00
|
|
|
};
|