Changeset 12832
- Timestamp:
- Sep 3, 2011, 4:33:04 AM (12 years ago)
- Location:
- trunk/web/javascript
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/javascript/file-row.js
r12791 r12832 7 7 function FileRow(torrent, i) 8 8 { 9 this.initialize(torrent, i); 10 } 11 12 FileRow.prototype = 13 { 14 initialize: function(torrent, i) 15 { 16 this._torrent = torrent; 17 this._index = i; 18 this.createRow(torrent, i); 9 var fields = { 10 have: 0, 11 index: 0, 12 isDirty: false, 13 isWanted: true, 14 priority: 0, 15 me: this, 16 size: 0, 17 torrent: null 19 18 }, 20 19 21 getTorrent: function() 22 { 23 return this._torrent; 24 }, 25 getIndex: function() 26 { 27 return this._index; 20 elements = { 21 priority_control: null, 22 progress: null, 23 root: null 28 24 }, 29 25 30 readAttributes: function(file) 31 { 32 if (file.index !== undefined && file.index !== this._index) { 33 this._index = file.index; 34 this._dirty = true; 26 initialize = function(torrent, i) { 27 fields.torrent = torrent; 28 fields.index = i; 29 createRow(torrent, i); 30 }, 31 32 readAttributes = function(file) { 33 if (fields.have !== file.bytesCompleted) { 34 fields.have = file.bytesCompleted; 35 fields.isDirty = true; 35 36 } 36 if (fi le.bytesCompleted !== undefined && file.bytesCompleted !== this._done) {37 this._done = file.bytesCompleted;38 this._dirty = true;37 if (fields.size !== file.length) { 38 fields.size = file.length; 39 fields.isDirty = true; 39 40 } 40 if (fi le.length !== undefined && file.length !== this._size) {41 this._size = file.length;42 this._dirty = true;41 if (fields.priority !== file.priority) { 42 fields.priority = file.priority; 43 fields.isDirty = true; 43 44 } 44 if (file.priority !== undefined && file.priority !== this._prio) { 45 this._prio = file.priority; 46 this._dirty = true; 47 } 48 if (file.wanted !== undefined && file.wanted !== this._wanted) { 49 this._wanted = file.wanted; 50 this._dirty = true; 45 if (fields.isWanted !== file.wanted) { 46 fields.isWanted = file.wanted; 47 fields.isDirty = true; 51 48 } 52 49 }, 53 50 54 refreshWantedHTML :function()51 refreshWantedHTML = function() 55 52 { 56 var e = this.getElement(),53 var e = elements.root, 57 54 c = [ e.classNameConst ]; 58 55 59 if (! this._wanted) { c.push('skip'); }60 if ( this.isDone()) { c.push('complete'); }56 if (!fields.isWanted) { c.push('skip'); } 57 if (isDone()) { c.push('complete'); } 61 58 e.className = c.join(' '); 62 59 }, 63 refreshPriorityHTML :function()60 refreshPriorityHTML = function() 64 61 { 65 var e = this._priority_control,62 var e = elements.priority_control, 66 63 c = [ e.classNameConst ]; 67 64 68 switch( this._prio) {65 switch(fields.priority) { 69 66 case -1 : c.push('low'); break; 70 67 case 1 : c.push('high'); break; … … 73 70 e.className = c.join(' '); 74 71 }, 75 refreshProgressHTML :function()72 refreshProgressHTML = function() 76 73 { 77 var pct = 100 * ( this._size ? (this._done / this._size) : 1.0),78 c = [ Transmission.fmt.size( this._done),74 var pct = 100 * (fields.size ? (fields.have / fields.size) : 1.0), 75 c = [ Transmission.fmt.size(fields.have), 79 76 ' of ', 80 Transmission.fmt.size( this._size),77 Transmission.fmt.size(fields.size), 81 78 ' (', 82 79 Transmission.fmt.percentString(pct), 83 80 '%)' ].join(''); 84 setInnerHTML( this._progress[0], c);81 setInnerHTML(elements.progress, c); 85 82 }, 86 refreshHTML :function() {87 if ( this._dirty) {88 this._dirty = false;89 this.refreshProgressHTML();90 this.refreshWantedHTML();91 this.refreshPriorityHTML();83 refreshHTML = function() { 84 if (fields.isDirty) { 85 fields.isDirty = false; 86 refreshProgressHTML(); 87 refreshWantedHTML(); 88 refreshPriorityHTML(); 92 89 } 93 90 }, 94 refresh: function() 95 { 96 var i = this.getIndex(), 97 t = this.getTorrent(); 98 this.readAttributes(t.getFile(i)); 99 this.refreshHTML(); 91 refresh = function() { 92 readAttributes(fields.torrent.getFile(fields.index)); 93 refreshHTML(); 100 94 }, 101 95 102 isDone: function () { 103 return this._done >= this._size; 104 }, 105 isEditable: function () { 106 return (this.getTorrent().getFileCount()>1) && !this.isDone(); 96 isDone = function () { 97 return fields.have >= fields.size; 107 98 }, 108 99 109 createRow: function(torrent, i) 110 { 111 var me = this, 112 file = torrent.getFile(i), 100 createRow = function(torrent, i) { 101 var file = torrent.getFile(i), 113 102 name, root, wanted_div, pri_div, file_div, prog_div; 114 103 115 104 root = document.createElement('li'); 116 root.id = 't' + this._torrent.getId() + 'f' + this._index;105 root.id = 't' + fields.torrent.getId() + 'f' + fields.index; 117 106 root.classNameConst = 'inspector_torrent_file_list_entry ' + ((i%2)?'odd':'even'); 118 107 root.className = root.classNameConst; … … 120 109 wanted_div = document.createElement('div'); 121 110 wanted_div.className = "file_wanted_control"; 122 $(wanted_div). bind('click',function(){ me.fireWantedChanged(!me._wanted); });111 $(wanted_div).click(function(){ fireWantedChanged(!fields.isWanted); }); 123 112 124 113 pri_div = document.createElement('div'); … … 133 122 e = e.offsetParent; 134 123 } 124 // ugh. 135 125 if (isMobileDevice) { 136 126 if (x < 8) prio = -1; … … 142 132 else prio = 1; 143 133 } 144 me.firePriorityChanged(prio);134 firePriorityChanged(prio); 145 135 }); 146 136 … … 160 150 root.appendChild(prog_div); 161 151 162 this._element = root;163 this._priority_control = pri_div;164 this._progress = $(prog_div);152 elements.root = root; 153 elements.priority_control = pri_div; 154 elements.progress = prog_div; 165 155 166 this.refresh();156 refresh(); 167 157 return root; 168 158 }, 169 159 170 getElement: function() 171 { 172 return this._element; 160 fireWantedChanged = function(do_want) { 161 $(fields.me).trigger('wantedToggled',[ fields.me, do_want ]); 173 162 }, 163 firePriorityChanged = function(priority) { 164 $(fields.me).trigger('priorityToggled',[ fields.me, priority ]); 165 }; 174 166 175 fireWantedChanged: function(do_want) 176 { 177 $(this).trigger('wantedToggled',[ this, do_want ]); 178 }, 179 firePriorityChanged: function(priority) 180 { 181 $(this).trigger('priorityToggled',[ this, priority ]); 182 } 167 /*** 168 **** PUBLIC 169 ***/ 170 171 this.getElement = function() { 172 return elements.root; 173 }; 174 this.getIndex = function() { 175 return fields.index; 176 }; 177 this.isEditable = function () { 178 return (fields.torrent.getFileCount()>1) && !isDone(); 179 }; 180 181 initialize(torrent, i); 183 182 }; -
trunk/web/javascript/inspector.js
r12829 r12832 202 202 filesDeselectAllClicked = function() { filesAllClicked(false); }, 203 203 filesAllClicked = function(s) { 204 var t = data.file_torrent; 205 if (t) 206 toggleFilesWantedDisplay(t, s); 207 }, 208 209 changeFileCommand = function(command, rows) { 210 data.controller.changeFileCommand(command, rows); 211 }, 212 213 toggleFilesWantedDisplay = function(torrent, wanted) { 214 var i, row, rows=[]; 204 var i, row, rows=[], t=data.file_torrent; 205 if (!t) 206 return; 215 207 for (i=0; row=data.file_rows[i]; ++i) 216 if (row.isEditable() && (t orrent.getFile(i).wanted !== wanted))208 if (row.isEditable() && (t.getFile(i).wanted !== s)) 217 209 rows.push(row); 218 210 if (rows.length > 0) 219 changeFileCommand(wanted?'files-wanted':'files-unwanted', rows); 211 changeFileCommand(rows, s?'files-wanted':'files-unwanted'); 212 }, 213 214 changeFileCommand = function(rows, command) { 215 var torrentId = data.file_torrent.getId(); 216 var rowIndices = $.map(rows.slice(0),function (row) {return row.getIndex();}); 217 data.controller.changeFileCommand(torrentId, rowIndices, command); 220 218 }, 221 219 222 220 onFileWantedToggled = function(row, want) { 223 changeFileCommand( want ? 'files-wanted' : 'files-unwanted', [row]);221 changeFileCommand([row], want?'files-wanted':'files-unwanted'); 224 222 }, 225 223 … … 231 229 default: command = 'priority-normal'; break; 232 230 } 233 changeFileCommand( command, [ row ]);231 changeFileCommand([row], command); 234 232 }, 235 233 -
trunk/web/javascript/remote.js
r12828 r12832 147 147 }, 148 148 149 changeFileCommand: function(command, rows) { 150 var remote = this; 151 var torrent_ids = [ rows[0].getTorrent().getId() ]; 152 var files = []; 153 for (var i=0, row; row=rows[i]; ++i) 154 files.push(row.getIndex()); 155 var o = { 156 method: 'torrent-set', 157 arguments: { ids: torrent_ids } 158 }; 159 o.arguments[command] = files; 160 this.sendRequest(o, function() { 149 changeFileCommand: function(torrentId, fileIndices, command) { 150 var remote = this, 151 args = { ids: [torrentId] }; 152 args[command] = fileIndices; 153 this.sendRequest({ 154 arguments: args, 155 method: 'torrent-set' 156 }, function() { 161 157 remote._controller.refreshTorrents(torrent_ids); 162 158 }); -
trunk/web/javascript/transmission.js
r12829 r12832 1263 1263 this.refreshTorrents, this); 1264 1264 }, 1265 changeFileCommand: function( command, rows) {1266 this.remote.changeFileCommand( command, rows);1265 changeFileCommand: function(torrentId, rowIndices, command) { 1266 this.remote.changeFileCommand(torrentId, rowIndices, command); 1267 1267 }, 1268 1268
Note: See TracChangeset
for help on using the changeset viewer.