Ignore:
Timestamp:
04/27/2009 08:48:39 PM (16 years ago)
Author:
Damien Churchill <damoc@gmail.com>
Branches:
2.0.x, develop, extjs4-port, master
Children:
b88542f
Parents:
2ac545d
Message:

add torrents to be added to the grid before their info has been
retrieved with a url or filename in place of the torrent name

File:
1 edited

Legend:

Unmodified
Added
Removed
  • deluge/ui/web/js/Deluge.Add.js

    r2ac545d r8582915  
    6363                        folderSort: true
    6464                });
     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                });
    6589        },
    6690       
     
    90114        ]
    91115        Deluge.Client.core.get_config_values(keys, {
    92             onSuccess: function(config) {
     116            success: function(config) {
    93117                                this.defaults = config;
    94                                 $each(config, function(value, key) {
     118                                for (var key in config) {
    95119                                        var field = this.form.findField(key);
    96120                                        if (!field) return;
    97                                         field.setValue(value);
    98                                 }, this);
     121                                        field.setValue(config[key]);
     122                                }
    99123                                var field = this.form.findField('compact_allocation');
    100124                                if (config['compact_allocation']) {
     
    105129                                        field.items.get('compact_allocation_true').setValue(false);
    106130                                }
    107                         }.bindWithEvent(this)
     131                        },
     132                        scope: this
    108133        });
    109134        }
     
    117142                        'add'
    118143                );
     144        },
     145       
     146        createTorrentId: function() {
     147                return new Date().getTime();
    119148        }
    120149});
     
    146175                this.addButton(_('Add'), this.onAdd, this);
    147176               
     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               
    148185                this.grid = this.add({
    149186                        xtype: 'grid',
    150187                        region: 'center',
    151188                        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                                ],
    153193                                id: 0
    154194                        }),
     
    157197                                        width: 150,
    158198                                        sortable: true,
    159                                         renderer: fplain,
    160                                         dataIndex: 'torrent'
     199                                        renderer: torrentRenderer,
     200                                        dataIndex: 'text'
    161201                        }],     
    162202                        stripeRows: true,
     
    250290                delete this.torrents[torrent.id];
    251291                this.grid.getStore().remove(torrent);
    252                 this.clearFiles();
     292                this.options.clear();
    253293        },
    254294       
    255295        onSelect: function(selModel, rowIndex, record) {
    256                 var torrentInfo = this.torrents[record.id];
     296                var torrentInfo = this.torrents[record.get('info_hash')];
    257297               
    258298                function walk(files, parent) {
     
    300340        },
    301341       
    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) {
    306348                if (!info) {
    307349                        Ext.MessageBox.show({
     
    315357                        return;
    316358                }
    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();
    318364                this.torrents[info['info_hash']] = info;
    319365        },
     
    324370});
    325371Deluge.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: true
    343                 });
    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: file
    354                                         });
    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 reasons
    361                                                 size: fsize(item[0]),
    362                                                 leaf: true,
    363                                                 checked: item[1],
    364                                                 iconCls: 'x-deluge-file',
    365                                                 uiProvider: Ext.tree.ColumnNodeUI
    366                                         }));   
    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: 330
    444                                         }, {
    445                                                 border: false,
    446                                                 style: 'padding-left: 5px;',
    447                                                 items: [{
    448                                                         xtype: 'button',
    449                                                         text: _('Browse') + '...',
    450                                                         disabled: true
    451                                                 }]
    452                                         }]
    453                                 }]
    454                         }, {
    455                                 layout: 'column',
    456                                 border: false,
    457                                 defaults: {
    458                                         border: false
    459                                 },
    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: true
    479                                                 },{
    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: 1
    502                                                 })
    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: 1
    512                                                 })
    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: 1
    522                                                 })
    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: 1
    533                                                 })
    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.Add
    567                                 }
    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.File
    628     }]
    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.