Changeset 8582915
- Timestamp:
- 04/27/2009 08:48:39 PM (16 years ago)
- Branches:
- 2.0.x, develop, extjs4-port, master
- Children:
- b88542f
- Parents:
- 2ac545d
- Location:
- deluge/ui/web/js
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
deluge/ui/web/js/Deluge.Add.File.js
r2ac545d r8582915 66 66 onAdd: function(field, e) { 67 67 if (this.form.getForm().isValid()) { 68 this.torrentId = this.createTorrentId(); 68 69 this.form.getForm().submit({ 69 70 url: '/upload', … … 72 73 scope: this 73 74 }); 75 var name = this.form.getForm().findField('torrentFile').value; 76 this.fireEvent('beforeadd', this.torrentId, name); 74 77 } 75 this.fireEvent('beforeadd', null); 78 }, 79 80 onGotInfo: function(info, obj, response, request) { 81 info['filename'] = request.options.filename; 82 this.fireEvent('add', this.torrentId, info); 76 83 }, 77 84 … … 85 92 filename: filename 86 93 }); 87 },88 89 onGotInfo: function(info, obj, response, request) {90 info['filename'] = request.options.filename;91 this.fireEvent('add', info);92 94 } 93 95 }); -
deluge/ui/web/js/Deluge.Add.Url.js
r2ac545d r8582915 71 71 var field = this.form.items.get('url'); 72 72 var url = field.getValue(); 73 var torrentId = this.createTorrentId(); 73 74 74 75 Deluge.Client.web.download_torrent_from_url(url, { 75 76 success: this.onDownload, 76 scope: this 77 scope: this, 78 torrentId: torrentId 77 79 }); 78 80 this.hide(); 79 this.fireEvent('beforeadd', url);81 this.fireEvent('beforeadd', torrentId, url); 80 82 }, 81 83 82 onDownload: function(filename ) {84 onDownload: function(filename, obj, resp, req) { 83 85 this.form.items.get('url').setValue(''); 84 86 Deluge.Client.web.get_torrent_info(filename, { 85 87 success: this.onGotInfo, 86 88 scope: this, 87 filename: filename 89 filename: filename, 90 torrentId: req.options.torrentId 88 91 }); 89 92 }, … … 91 94 onGotInfo: function(info, obj, response, request) { 92 95 info['filename'] = request.options.filename; 93 this.fireEvent('add', info);96 this.fireEvent('add', request.options.torrentId, info); 94 97 } 95 98 }); -
deluge/ui/web/js/Deluge.Add.js
r2ac545d r8582915 63 63 folderSort: true 64 64 }); 65 66 this.form = this.add({ 67 xtype: 'form', 68 labelWidth: 1, 69 frame: false, 70 title: _('Options'), 71 bodyStyle: 'padding: 5px;', 72 border: false, 73 74 75 items: [{ 76 xtype: 'fieldset', 77 title: _('Download Location'), 78 border: false, 79 defaultType: 'textfield', 80 labelWidth: 1, 81 items: [{ 82 fieldLabel: '', 83 labelSeperator: '', 84 name: 'download_location', 85 width: 330 86 }] 87 }] 88 }); 65 89 }, 66 90 … … 90 114 ] 91 115 Deluge.Client.core.get_config_values(keys, { 92 onSuccess: function(config) {116 success: function(config) { 93 117 this.defaults = config; 94 $each(config, function(value, key) {118 for (var key in config) { 95 119 var field = this.form.findField(key); 96 120 if (!field) return; 97 field.setValue( value);98 } , this);121 field.setValue(config[key]); 122 } 99 123 var field = this.form.findField('compact_allocation'); 100 124 if (config['compact_allocation']) { … … 105 129 field.items.get('compact_allocation_true').setValue(false); 106 130 } 107 }.bindWithEvent(this) 131 }, 132 scope: this 108 133 }); 109 134 } … … 117 142 'add' 118 143 ); 144 }, 145 146 createTorrentId: function() { 147 return new Date().getTime(); 119 148 } 120 149 }); … … 146 175 this.addButton(_('Add'), this.onAdd, this); 147 176 177 function torrentRenderer(value, p, r) { 178 if (r.data['infohash']) { 179 return String.format('<div class="x-add-torrent-name">{0}</div>', value); 180 } else { 181 return String.format('<div class="x-add-torrent-name-loading">{0}</div>', value); 182 } 183 } 184 148 185 this.grid = this.add({ 149 186 xtype: 'grid', 150 187 region: 'center', 151 188 store: new Ext.data.SimpleStore({ 152 fields: [{name: 'torrent', mapping: 1}], 189 fields: [ 190 {name: 'info_hash', mapping: 1}, 191 {name: 'text', mapping: 2} 192 ], 153 193 id: 0 154 194 }), … … 157 197 width: 150, 158 198 sortable: true, 159 renderer: fplain,160 dataIndex: 't orrent'199 renderer: torrentRenderer, 200 dataIndex: 'text' 161 201 }], 162 202 stripeRows: true, … … 250 290 delete this.torrents[torrent.id]; 251 291 this.grid.getStore().remove(torrent); 252 this. clearFiles();292 this.options.clear(); 253 293 }, 254 294 255 295 onSelect: function(selModel, rowIndex, record) { 256 var torrentInfo = this.torrents[record. id];296 var torrentInfo = this.torrents[record.get('info_hash')]; 257 297 258 298 function walk(files, parent) { … … 300 340 }, 301 341 302 onTorrentBeforeAdd: function(temptext) { 303 }, 304 305 onTorrentAdd: function(info) { 342 onTorrentBeforeAdd: function(torrentId, text) { 343 var store = this.grid.getStore(); 344 store.loadData([[torrentId, null, text]], true); 345 }, 346 347 onTorrentAdd: function(torrentId, info) { 306 348 if (!info) { 307 349 Ext.MessageBox.show({ … … 315 357 return; 316 358 } 317 this.grid.getStore().loadData([[info['info_hash'], info['name']]], true); 359 360 var r = this.grid.getStore().getById(torrentId); 361 r.set('info_hash', info['info_hash']); 362 r.set('text', info['name']); 363 this.grid.getStore().commitChanges(); 318 364 this.torrents[info['info_hash']] = info; 319 365 }, … … 324 370 }); 325 371 Deluge.Add = new Ext.deluge.add.AddWindow(); 326 327 /*Deluge.Add = {328 onFile: function() {329 this.File.Window.show();330 },331 332 onOptionsRender: function(panel) {333 panel.layout = new Ext.layout.FormLayout();334 panel.layout.setContainer(panel);335 panel.doLayout();336 this.form = panel.getForm();337 this.getDefaults();338 },339 340 onRender: function(window) {341 new Ext.tree.TreeSorter(this.Files, {342 folderSort: true343 });344 },345 346 onSelect: function(selModel, rowIndex, record) {347 var torrentInfo = Deluge.Add.torrents[record.id];348 349 function walk(files, parent) {350 $each(files, function(item, file) {351 if ($type(item) == 'object') {352 var child = new Ext.tree.TreeNode({353 text: file354 });355 walk(item, child);356 parent.appendChild(child);357 } else {358 parent.appendChild(new Ext.tree.TreeNode({359 filename: file,360 text: file, // this needs to be here for sorting reasons361 size: fsize(item[0]),362 leaf: true,363 checked: item[1],364 iconCls: 'x-deluge-file',365 uiProvider: Ext.tree.ColumnNodeUI366 }));367 }368 });369 }370 371 this.clearFiles();372 373 var root = this.Files.getRootNode();374 walk(torrentInfo['files_tree'], root);375 root.firstChild.expand();376 },377 378 onTorrentAdded: function(info, filename) {379 if (!info) {380 Ext.MessageBox.show({381 title: _('Error'),382 msg: _('Not a valid torrent'),383 buttons: Ext.MessageBox.OK,384 modal: false,385 icon: Ext.MessageBox.ERROR,386 iconCls: 'x-deluge-icon-error'387 });388 return;389 }390 info['filename'] = filename;391 this.Store.loadData([[info['info_hash'], info['name']]], true);392 this.torrents[info['info_hash']] = info;393 },394 395 onUrl: function(button, event) {396 this.Url.Window.show();397 },398 399 onRemove: function() {400 var selection = this.Grid.getSelectionModel();401 if (!selection.hasSelection()) return;402 var torrent = selection.getSelected();403 404 delete this.torrents[torrent.id];405 this.Store.remove(torrent);406 this.clearFiles();407 }408 }409 410 Deluge.Add.Options = new Ext.TabPanel({411 region: 'south',412 margins: '5 5 5 5',413 activeTab: 0,414 height: 220,415 items: [{416 id: 'addFilesTab',417 title: _('Files'),418 items: [Deluge.Add.Files]419 },{420 id: 'addOptionsTab',421 title: _('Options'),422 layout: 'fit',423 items: [new Ext.form.FormPanel({424 id: 'addOptionsForm',425 bodyStyle: 'padding: 5px;',426 border: false,427 items: [{428 xtype: 'fieldset',429 style: 'padding: 0px; padding-top: 5px;',430 title: _('Download Location'),431 border: false,432 autoHeight: true,433 border: false,434 labelWidth: 1,435 items: [{436 layout: 'column',437 border: false,438 items: [{439 xtype: 'textfield',440 id: 'download_location',441 fieldLabel: '',442 labelSeparator: '',443 width: 330444 }, {445 border: false,446 style: 'padding-left: 5px;',447 items: [{448 xtype: 'button',449 text: _('Browse') + '...',450 disabled: true451 }]452 }]453 }]454 }, {455 layout: 'column',456 border: false,457 defaults: {458 border: false459 },460 items: [{461 xtype: 'fieldset',462 bodyStyle: 'margin-left: 5px; margin-right:5px;',463 title: _('Allocation'),464 autoHeight: true,465 border: false,466 labelWidth: 1,467 width: 100,468 items: [new Ext.form.RadioGroup({469 id: 'compact_allocation',470 name: 'compact_allocation',471 columns: 1,472 labelSeparator: '',473 items: [{474 boxLabel: _('Full'),475 inputValue: 'false',476 id: 'compact_allocation_false',477 name: 'compact_allocation',478 checked: true479 },{480 boxLabel: _('Compact'),481 inputValue: 'true',482 id: 'compact_allocation_true',483 name: 'compact_allocation'484 }]485 })]486 }, {487 xtype: 'fieldset',488 title: _('Bandwidth'),489 layout: 'form',490 autoHeight: true,491 defaultType: 'uxspinner',492 labelWidth: 100,493 items: [{494 id: 'max_download_speed_per_torrent',495 fieldLabel: _('Max Down Speed'),496 width: 60,497 value: -1,498 strategy: new Ext.ux.form.Spinner.NumberStrategy({499 minValue: -1,500 maxValue: 99999,501 incrementValue: 1502 })503 }, {504 id: 'max_upload_speed_per_torrent',505 fieldLabel: _('Max Up Speed'),506 width: 60,507 value: -1,508 strategy: new Ext.ux.form.Spinner.NumberStrategy({509 minValue: -1,510 maxValue: 99999,511 incrementValue: 1512 })513 }, {514 id: 'max_connections_per_torrent',515 fieldLabel: _('Max Connections'),516 width: 60,517 value: -1,518 strategy: new Ext.ux.form.Spinner.NumberStrategy({519 minValue: -1,520 maxValue: 99999,521 incrementValue: 1522 })523 }, {524 id: 'max_upload_slots_per_torrent',525 fieldLabel: _('Max Upload Slots'),526 colspan: 2,527 width: 60,528 value: -1,529 strategy: new Ext.ux.form.Spinner.NumberStrategy({530 minValue: -1,531 maxValue: 99999,532 incrementValue: 1533 })534 }]535 }, {536 xtype: 'fieldset',537 title: _('General'),538 autoHeight: true,539 border: false,540 labelWidth: 10,541 defaultType: 'checkbox',542 items: [{543 fieldLabel: '',544 labelSeparator: '',545 boxLabel: _('Add In Paused State'),546 id: 'add_paused'547 }, {548 fieldLabel: '',549 labelSeparator: '',550 boxLabel: _('Prioritize First/Last Piece'),551 id: 'prioritize_first_last_pieces'552 }, {553 xtype: 'button',554 text: _('Apply to All'),555 style: 'margin-left: 20px; margin-top: 5px;'556 }, {557 xtype: 'button',558 text: _('Revert to Defaults'),559 style: 'margin-left: 20px; margin-top: 5px;'560 }]561 }]562 }],563 listeners: {564 'render': {565 fn: Deluge.Add.onOptionsRender,566 scope: Deluge.Add567 }568 }569 })]570 }]571 });572 573 Deluge.Add.File = {574 onAdd: function() {575 if (this.form.getForm().isValid()) {576 this.form.getForm().submit({577 url: '/upload',578 waitMsg: _('Uploading your torrent...'),579 success: this.onUploadSuccess.bindWithEvent(this)580 });581 }582 },583 584 onUploadSuccess: function(fp, upload) {585 this.Window.hide();586 var filename = upload.result.toString();587 this.form.items.get('torrentFile').setValue('');588 Deluge.Client.web.get_torrent_info(filename, {589 onSuccess: Deluge.Add.onTorrentAdded.bindWithEvent(Deluge.Add, filename)590 });591 }592 }593 594 Deluge.Add.File.form = new Ext.form.FormPanel({595 fileUpload: true,596 id: 'fileAddForm',597 baseCls: 'x-plain',598 labelWidth: 55,599 autoHeight: true,600 items: [{601 xtype: 'fileuploadfield',602 id: 'torrentFile',603 emptyText: _('Select a torrent'),604 fieldLabel: _('File'),605 name: 'file',606 buttonCfg: {607 text: _('Browse') + '...'608 }609 }]610 });611 612 Deluge.Add.File.Window = new Ext.Window({613 layout: 'fit',614 width: 350,615 height: 115,616 bodyStyle: 'padding: 10px 5px;',617 buttonAlign: 'center',618 closeAction: 'hide',619 modal: true,620 plain: true,621 title: _('Add from File'),622 iconCls: 'x-deluge-add-file',623 items: Deluge.Add.File.form,624 buttons: [{625 text: _('Add'),626 handler: Deluge.Add.File.onAdd,627 scope: Deluge.Add.File628 }]629 });630 631 Deluge.Add.Url = {632 onAdd: function(field, e) {633 if (field.id == 'url' && e.getKey() != e.ENTER) return;634 635 var field = this.form.items.get('url');636 var url = field.getValue();637 638 Deluge.Client.web.download_torrent_from_url(url, {639 onSuccess: this.onDownload.bindWithEvent(this)640 });641 this.Window.hide();642 },643 644 onDownload: function(filename) {645 this.form.items.get('url').setValue('');646 Deluge.Client.web.get_torrent_info(filename, {647 onSuccess: Deluge.Add.onTorrentAdded.bindWithEvent(Deluge.Add, filename)648 });649 }650 }651 652 Deluge.Add.Url.form = ;653 */
Note:
See TracChangeset
for help on using the changeset viewer.