~ubuntu-branches/ubuntu/lucid/ktorrent/lucid

« back to all changes in this revision

Viewing changes to plugins/webinterface/www/common/torrent_details.js

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2009-02-16 18:37:14 UTC
  • mfrom: (1.1.25 upstream) (0.4.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090216183714-52tf47jrnmk4xkmp
Tags: 3.2+dfsg.1-2ubuntu1
* Merge with Debian, remaining changes: (LP: #296433)
  - Use Kubuntu's kde4.mk
  - Build-depend on libboost-serialization1.35-dev since unversioned -dev is
    in universe
  - Change plasma-applet-ktorrent to plasma-widget-ktorrent since we're
    supposed to call them widgets for the users

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
var current_torrent = 0;
 
2
 
 
3
function show_torrent_details(tor)
 
4
{
 
5
        update_torrent_details(tor);
 
6
        show_div("torrent_details");
 
7
}
 
8
 
 
9
function update_torrent_details(tor)
 
10
{
 
11
        current_torrent = tor;
 
12
        fetch_xml("/data/torrent/files.xml?torrent=" + tor,update_torrent_details_table,show_error);
 
13
}
 
14
 
 
15
function update_torrent_details_table(xmldoc)
 
16
{
 
17
        // Make sure errors are cleared
 
18
        clear_error();
 
19
        
 
20
        var newtable = document.createElement('table');
 
21
        newtable.setAttribute('id', 'torrent_details_table');
 
22
        newtable.className='list_table';
 
23
        
 
24
        var files = xmldoc.getElementsByTagName('file');
 
25
        var i = 0;
 
26
        while (files[i]) 
 
27
        {
 
28
                file_row(files[i], newtable, i);
 
29
                i++;
 
30
        }
 
31
        
 
32
        file_header(newtable.insertRow(0));
 
33
 
 
34
        var oldtable = document.getElementById('torrent_details_table');
 
35
        oldtable.parentNode.replaceChild(newtable, oldtable);
 
36
}
 
37
 
 
38
function file_row(element,table,i)
 
39
{
 
40
        var row = table.insertRow(i);
 
41
        var actions = row.insertCell(0);
 
42
        var file = row.insertCell(1);
 
43
        var priority = row.insertCell(2);
 
44
        var size = row.insertCell(3);
 
45
        var perc = row.insertCell(4);
 
46
        
 
47
        row.setAttribute('class',(i % 2 == 0) ? 'even' : 'odd');
 
48
        
 
49
        var file_status = element.getElementsByTagName('priority')[0].firstChild.data;
 
50
        var command = '';
 
51
        command = (file_status==20 || file_status==10) ? '' : "file_stop=" + current_torrent + "-" +i;
 
52
        actions.appendChild(create_priority_button("Only Seed","/only_seed.png",command));
 
53
        
 
54
        command = (file_status==30) ? '' : "file_lp=" + current_torrent + "-" +i;
 
55
        actions.appendChild(create_priority_button("Low Priority","/low_priority.png",command));
 
56
        
 
57
        command = (file_status==40) ? '' : "file_np=" + current_torrent + "-" +i;
 
58
        actions.appendChild(create_priority_button("Normal Priority","/normal_priority.png",command));
 
59
        
 
60
        command = (file_status==50) ? '' : "file_hp=" + current_torrent + "-" +i;
 
61
        actions.appendChild(create_priority_button("High Priority","/high_priority.png",command));
 
62
        
 
63
        actions.setAttribute("align","center");
 
64
        file.appendChild(get_text(element,"path"));
 
65
        size.appendChild(get_text(element,"size"));
 
66
        priority.appendChild(priority_node(element));
 
67
        var el = get_text(element,"percentage");
 
68
        el.appendData(" %");
 
69
        perc.appendChild(el);
 
70
}
 
71
 
 
72
function file_header(row)
 
73
{
 
74
        headers = new Array("Actions","File","Priority","Size","Complete");
 
75
        for (var i in headers) 
 
76
        {
 
77
                var header =  document.createElement("th");
 
78
                header.appendChild(document.createTextNode(headers[i]));
 
79
                row.appendChild(header);
 
80
        }
 
81
        return row;
 
82
}
 
83
 
 
84
 
 
85
function priority_node(element)
 
86
{
 
87
        var prio = element.getElementsByTagName('priority')[0].firstChild.data;
 
88
        switch (prio)
 
89
        {
 
90
        case '50': return document.createTextNode('Download First');
 
91
        case '40': return document.createTextNode('Download Normally');
 
92
        case '30': return document.createTextNode('Download Last');
 
93
        case '20': return document.createTextNode('Only Seed');
 
94
        case '10': return document.createTextNode('Do Not Download');
 
95
        default: return document.createTextNode('Unknown');
 
96
        }
 
97
}
 
98
 
 
99
function create_priority_button(button_name, image_src, command) 
 
100
{
 
101
        var image = document.createElement("img");
 
102
        image.setAttribute("src", image_src);
 
103
        image.setAttribute("alt", button_name);
 
104
        image.setAttribute("title", button_name);
 
105
 
 
106
        if (command != '')
 
107
        {
 
108
                var a = document.createElement("a");
 
109
                a.setAttribute("href", "javascript:do_action(\"" + command + "\"); update_torrent_details(current_torrent);");
 
110
                a.appendChild(image);
 
111
                return a;
 
112
        }
 
113
        else
 
114
                return image;
 
115
}