From 9d583b8c51ac24879cba25a6f9ab0f49e20916e7 Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Tue, 21 Apr 2009 07:17:49 +0000 Subject: [PATCH] completely rework deluge-torrent.js into a self-contained ext class add .build_data to svn:ignore on js add in the first build of deluge-yc.js --- deluge/ui/web/js/deluge-details.js | 6 +- deluge/ui/web/js/deluge-torrents.js | 334 ++++++++++++++++------------ deluge/ui/web/js/deluge-ui.js | 4 +- deluge/ui/web/js/deluge-yc.js | 1 + 4 files changed, 192 insertions(+), 153 deletions(-) create mode 100644 deluge/ui/web/js/deluge-yc.js diff --git a/deluge/ui/web/js/deluge-details.js b/deluge/ui/web/js/deluge-details.js index 3776e1196..5065d7ed3 100644 --- a/deluge/ui/web/js/deluge-details.js +++ b/deluge/ui/web/js/deluge-details.js @@ -40,9 +40,9 @@ Deluge.Details = { }, onRender: function(panel) { - Deluge.Torrents.Grid.on('rowclick', this.onTorrentsClick.bindWithEvent(this)); + Deluge.Torrents.on('rowclick', this.onTorrentsClick.bindWithEvent(this)); - var selModel = Deluge.Torrents.Grid.getSelectionModel(); + var selModel = Deluge.Torrents.getSelectionModel(); selModel.on('selectionchange', function(selModel) { if (!selModel.hasSelection()) { this.clear.delay(10, this); @@ -63,7 +63,7 @@ Deluge.Details = { Deluge.Details.Status = { onRender: function(panel) { this.panel = panel; - this.progressBar = new Deluge.ProgressBar({ + this.progressBar = new Ext.ux.FullProgressBar({ id: 'pbar-status', cls: 'deluge-status-progressbar' }); diff --git a/deluge/ui/web/js/deluge-torrents.js b/deluge/ui/web/js/deluge-torrents.js index 19dcd1a27..e779853a4 100644 --- a/deluge/ui/web/js/deluge-torrents.js +++ b/deluge/ui/web/js/deluge-torrents.js @@ -21,161 +21,199 @@ Copyright: Boston, MA 02110-1301, USA. */ -function queue(value) { - return (value == -1) ? '' : value + 1; -} - -function name(value, p, r) { - return String.format('
{1}
', r.data['state'].toLowerCase(), value); -} - -function torrent_speed(value) { - if (!value) return; - return fspeed(value); -} - -function progress(value, p, r) { - var progress = value.toInt(); - var text = r.data['state'] + ' ' + value.toFixed(2) + '%' - var width = this.style.match(/\w+:\s*(\d+)\w+/)[1].toInt() - 8; - return progressBar(value.toInt(), width, text); -} - -var tpl = '
' + - '
' + - '
' + - '
' + - '
{0}
' + - '
' + - '
' + - '
' + - '
{0}
' + - '
' + - '
' + -'
'; - -function progressBar(progress, width, text) { - var progressWidth = (width / 100.0) * progress; - var barWidth = progressWidth.toInt() - 1; - var textWidth = ((progressWidth.toInt() - 10) > 0 ? progressWidth.toInt() - 10 : 0); - return String.format(tpl, text, width, barWidth, textWidth); -} - -function seeds(value, p, r) { - if (r.data['total_seeds'] > -1) { - return String.format('{0} ({1})', value, r.data['total_seeds']); - } else { - return value; +(function() { + + /* Renderers for the Torrent Grid */ + function queueRenderer(value) { + return (value == -1) ? '' : value + 1; } -} - -function peers(value, p, r) { - if (r.data['total_peers'] > -1) { - return String.format('{0} ({1})', value, r.data['total_peers']); - } else { - return value; + function torrentNameRenderer(value, p, r) { + return String.format('
{1}
', r.data['state'].toLowerCase(), value); } -} - -function avail(value) { - return value.toFixed(3); -} - -function tracker(value) { - return String.format('
{0}
', value); -} - -Deluge.Torrents = { - Store: new Ext.data.SimpleStore({ - fields: [ - {name: 'queue'}, - {name: 'name'}, - {name: 'size', type: 'int'}, - {name: 'state'}, - {name: 'progress', type: 'float'}, - {name: 'seeds', type: 'int'}, - {name: 'total_seeds', type: 'int'}, - {name: 'peers', type: 'int'}, - {name: 'total_peers', type: 'int'}, - {name: 'downspeed', type: 'int'}, - {name: 'upspeed', type: 'int'}, - {name: 'eta', type: 'int'}, - {name: 'ratio', type: 'float'}, - {name: 'avail', type: 'float'}, - {name: 'added', type: 'int'}, - {name: 'tracker'} - ], - id: 16 - }), - - getTorrent: function(rowIndex) { - return this.Grid.store.getAt(rowIndex); - }, - - getSelected: function() { - return this.Grid.getSelectionModel().getSelected(); - }, - - getSelections: function() { - return this.Grid.getSelectionModel().getSelections(); - }, - - onRender: function() { - Deluge.Events.on('torrentRemoved', this.onTorrentRemoved.bindWithEvent(this)); - }, - - onTorrentRemoved: function(torrentIds) { - var selModel = this.Grid.getSelectionModel(); - $each(torrentIds, function(torrentId) { - var record = this.Store.getById(torrentId); - if (selModel.isSelected(record)) { - selModel.deselectRow(this.Store.indexOf(record)); - } - this.Store.remove(record); - - }, this); + function torrentSpeedRenderer(value) { + if (!value) return; + return fspeed(value); } -} -Deluge.Torrents.Store.setDefaultSort('queue'); - -Deluge.Torrents.Grid = new Ext.grid.GridPanel({ - region: 'center', - store: Deluge.Torrents.Store, - cls: 'deluge-torrents', - columns: [ - {id:'queue',header: _('#'), width: 30, sortable: true, renderer: queue, dataIndex: 'queue'}, - {id:'name', header: _('Name'), width: 150, sortable: true, renderer: name, dataIndex: 'name'}, - {header: _('Size'), width: 75, sortable: true, renderer: fsize, dataIndex: 'size'}, - {header: _('Progress'), width: 150, sortable: true, renderer: progress, dataIndex: 'progress'}, - {header: _('Seeders'), width: 60, sortable: true, renderer: seeds, dataIndex: 'seeds'}, - {header: _('Peers'), width: 60, sortable: true, renderer: peers, dataIndex: 'peers'}, - {header: _('Down Speed'), width: 80, sortable: true, renderer: torrent_speed, dataIndex: 'downspeed'}, - {header: _('Up Speed'), width: 80, sortable: true, renderer: torrent_speed, dataIndex: 'upspeed'}, - {header: _('ETA'), width: 60, sortable: true, renderer: ftime, dataIndex: 'eta'}, - {header: _('Ratio'), width: 60, sortable: true, renderer: avail, dataIndex: 'ratio'}, - {header: _('Avail'), width: 60, sortable: true, renderer: avail, dataIndex: 'avail'}, - {header: _('Added'), width: 80, sortable: true, renderer: fdate, dataIndex: 'added'}, - {header: _('Tracker'), width: 120, sortable: true, renderer: tracker, dataIndex: 'tracker'} - ], - stripeRows: true, - autoExpandColumn: 'name', - deferredRender:false, - autoScroll:true, - margins: '5 5 0 0', - listeners: { - 'render': { - fn: Deluge.Torrents.onRender, - scope: Deluge.Torrents - }, - 'rowcontextmenu': { - fn: function(grid, rowIndex, e) { + function torrentProgressRenderer(value, p, r) { + var progress = value.toInt(); + var text = r.data['state'] + ' ' + value.toFixed(2) + '%' + var width = this.style.match(/\w+:\s*(\d+)\w+/)[1].toInt() - 8; + return Deluge.progressBar(value.toInt(), width, text); + } + function seedsRenderer(value, p, r) { + if (r.data['total_seeds'] > -1) { + return String.format('{0} ({1})', value, r.data['total_seeds']); + } else { + return value; + } + } + function peersRenderer(value, p, r) { + if (r.data['total_peers'] > -1) { + return String.format('{0} ({1})', value, r.data['total_peers']); + } else { + return value; + } + } + function availRenderer(value, p, r) { + value.toFixed(3); + } + function trackerRenderer(value, p, r) { + return String.format('
{0}
', value); + } + + Ext.namespace("Ext.deluge"); + Ext.deluge.TorrentGrid = function(config) { + Ext.deluge.TorrentGrid.superclass.constructor.call(this, { + id: 'torrentGrid', + store: new Ext.data.SimpleStore({ + fields: [ + {name: 'queue'}, + {name: 'name'}, + {name: 'size', type: 'int'}, + {name: 'state'}, + {name: 'progress', type: 'float'}, + {name: 'seeds', type: 'int'}, + {name: 'total_seeds', type: 'int'}, + {name: 'peers', type: 'int'}, + {name: 'total_peers', type: 'int'}, + {name: 'downspeed', type: 'int'}, + {name: 'upspeed', type: 'int'}, + {name: 'eta', type: 'int'}, + {name: 'ratio', type: 'float'}, + {name: 'avail', type: 'float'}, + {name: 'added', type: 'int'}, + {name: 'tracker'} + ], + id: 16 + }), + columns: [{ + id:'queue', + header: _('#'), + width: 30, + sortable: true, + renderer: queueRenderer, + dataIndex: 'queue' + }, { + id:'name', + header: _('Name'), + width: 150, + sortable: true, + renderer: torrentNameRenderer, + dataIndex: 'name' + }, { + header: _('Size'), + width: 75, + sortable: true, + renderer: fsize, + dataIndex: 'size' + }, { + header: _('Progress'), + width: 150, + sortable: true, + renderer: torrentProgressRenderer, + dataIndex: 'progress' + }, { + header: _('Seeders'), + width: 60, + sortable: true, + renderer: seedsRenderer, + dataIndex: 'seeds' + }, { + header: _('Peers'), + width: 60, + sortable: true, + renderer: peersRenderer, + dataIndex: 'peers' + }, { + header: _('Down Speed'), + width: 80, + sortable: true, + renderer: torrentSpeedRenderer, + dataIndex: 'downspeed' + }, { + header: _('Up Speed'), + width: 80, + sortable: true, + renderer: torrentSpeedRenderer, + dataIndex: 'upspeed' + }, { + header: _('ETA'), + width: 60, + sortable: true, + renderer: ftime, + dataIndex: 'eta' + }, { + header: _('Ratio'), + width: 60, + sortable: true, + renderer: availRenderer, + dataIndex: 'ratio' + }, { + header: _('Avail'), + width: 60, + sortable: true, + renderer: availRenderer, + dataIndex: 'avail' + }, { + header: _('Added'), + width: 80, + sortable: true, + renderer: fdate, + dataIndex: 'added' + }, { + header: _('Tracker'), + width: 120, + sortable: true, + renderer: trackerRenderer, + dataIndex: 'tracker' + }], + region: 'center', + cls: 'deluge-torrents', + stripeRows: true, + autoExpandColumn: 'name', + deferredRender:false, + autoScroll:true, + margins: '5 5 0 0' + }); + } + + Ext.extend(Ext.deluge.TorrentGrid, Ext.grid.GridPanel, { + initComponent: function() { + Ext.deluge.TorrentGrid.superclass.initComponent.call(this); + Deluge.Events.on('torrentRemoved', this.onTorrentRemoved, this); + this.on('rowcontextmenu', function(grid, rowIndex, e) { e.stopEvent(); var selection = grid.getSelectionModel(); if (!selection.hasSelection()) { selection.selectRow(rowIndex); } Deluge.Menus.Torrent.showAt(e.getPoint()); - } + }); + }, + + getTorrent: function(rowIndex) { + return this.getStore().getAt(rowIndex); + }, + + getSelected: function() { + return this.getSelectionModel().getSelected(); + }, + + getSelections: function() { + return this.getSelectionModel().getSelections(); + }, + + onTorrentRemoved: function(torrentIds) { + var selModel = this.Grid.getSelectionModel(); + $each(torrentIds, function(torrentId) { + var record = this.Store.getById(torrentId); + if (selModel.isSelected(record)) { + selModel.deselectRow(this.Store.indexOf(record)); + } + this.Store.remove(record); + + }, this); } - } -}) + }); + Deluge.Torrents = new Ext.deluge.TorrentGrid(); +})(); \ No newline at end of file diff --git a/deluge/ui/web/js/deluge-ui.js b/deluge/ui/web/js/deluge-ui.js index 3e0257f0d..c3a389799 100644 --- a/deluge/ui/web/js/deluge-ui.js +++ b/deluge/ui/web/js/deluge-ui.js @@ -35,7 +35,7 @@ Deluge.UI = { items: [ Deluge.SideBar.Config, Deluge.Details.Panel, - Deluge.Torrents.Grid + Deluge.Torrents ], bbar: Deluge.StatusBar.Bar }); @@ -105,7 +105,7 @@ Deluge.UI = { id ]); }); - Deluge.Torrents.Store.loadData(torrents); + Deluge.Torrents.getStore().loadData(torrents); Deluge.StatusBar.update(data['stats']); Deluge.SideBar.update(data['filters']); this.errorCount = 0; diff --git a/deluge/ui/web/js/deluge-yc.js b/deluge/ui/web/js/deluge-yc.js new file mode 100644 index 000000000..8bc7cb3b6 --- /dev/null +++ b/deluge/ui/web/js/deluge-yc.js @@ -0,0 +1 @@ +JSON.RPC=new Class({Implements:Options,options:{async:true,methods:[]},initialize:function(b,a){this.setOptions(a);this.url=b;if(this.options.methods.length==0){this._setMethods(this._execute("system.listMethods",{async:false}))}else{this._setMethods(this.options.methods)}},_setMethods:function(b){var a=new Hash();b.forEach(function(f){var e=f.split(".");var c=$pick(a[e[0]],new Hash());var d=function(){var g=this._parseargs(arguments);return this._execute(f,g)}.bind(this);c[e[1]]=d;a[e[0]]=c},this);a.each(function(c,d){this[d]=c},this)},_parseargs:function(c){var f=$A(c),b=f.getLast();if($type(b)=="object"){var a=["async","onRequest","onComplete","onSuccess","onFailure","onException","onCancel"],e=new Hash(b).getKeys(),d=false;a.each(function(g){if(e.contains(g)){d=true}});if(d){f.erase(b)}else{b={}}}else{b={}}b.params=f;return b},_execute:function(c,a){a=$pick(a,{});a.params=$pick(a.params,[]);a.async=$pick(a.async,this.options.async);data=JSON.encode({method:c,params:a.params,id:1});var b=new Request.JSON({url:this.url,async:a.async,onRequest:a.onRequest,onComplete:a.onComplete,onSuccess:function(d){if(a.onSuccess){a.onSuccess(d.result)}},onFailure:a.onFailure,onException:a.onException,onCancel:a.onCancel}).send(data);if(!a.async){return b.response.json.result}}});var Deluge={author:"Damien Churchill ",version:"1.2-dev"};(function(){var a='
{0}
{0}
';Deluge.progressBar=function(c,e,g){var b=(e/100)*c;var d=b.toInt()-1;var f=((b.toInt()-10)>0?b.toInt()-10:0);return String.format(a,g,e,d,f)}})();Deluge.Events={_events:new Hash(),fire:function(){arguments=$A(arguments);var b=arguments.shift();var a=arguments;if(!this._events[b]){return}$each(this._events[b],function(c){c.attempt(a)})},on:function(a,b){var c=$pick(this._events[a],new Array());c.include(b);this._events[a]=c},removeListener:function(a,b){if(!this._events[a]){return}this._events[a].remove(b)}};Deluge.Formatters={date:function(c){function b(d,e){var f=d+"";while(f.length0){return b+"m "+d+"s"}else{return b+"m"}}else{c=c/60}if(c<24){var a=Math.floor(c);var b=Math.round(60*(c-a));if(b>0){return a+"h "+b+"m"}else{return a+"h"}}else{c=c/24}var e=Math.floor(c);var a=Math.round(24*(c-e));if(a>0){return e+"d "+a+"h"}else{return e+"d"}},plain:function(a){return a}};FILE_PRIORITY={0:"Do Not Download",1:"Normal Priority",2:"High Priority",5:"Highest Priority","Do Not Download":0,"Normal Priority":1,"High Priority":2,"Highest Priority":5};FILE_PRIORITY_CSS={0:"x-no-download",1:"x-normal-download",2:"x-high-download",5:"x-highest-download"};var fsize=Deluge.Formatters.size;var fspeed=Deluge.Formatters.speed;var ftime=Deluge.Formatters.timeRemaining;var fdate=Deluge.Formatters.date;var fplain=Deluge.Formatters.plain;Deluge.Keys={Grid:["queue","name","total_size","state","progress","num_seeds","total_seeds","num_peers","total_peers","download_payload_rate","upload_payload_rate","eta","ratio","distributed_copies","is_auto_managed","time_added","tracker_host"],Status:["total_done","total_payload_download","total_uploaded","total_payload_upload","next_announce","tracker_status","num_pieces","piece_length","is_auto_managed","active_time","seeding_time","seed_rank"],Files:["files","file_progress","file_priorities"],Peers:["peers","seeds"],Details:["name","save_path","total_size","num_files","tracker_status","tracker","comment"],Options:["max_download_speed","max_upload_speed","max_connections","max_upload_slots","is_auto_managed","stop_at_ratio","stop_ratio","remove_at_ratio","private","prioritize_first_last"]};Deluge.Keys.Status.extend(Deluge.Keys.Grid);(function(){var a=function(b){Ext.apply(this,{layout:"fit",width:300,height:120,bodyStyle:"padding: 10px 5px;",buttonAlign:"center",closeAction:"hide",closable:false,modal:true,plain:true,resizable:false,title:_("Login"),iconCls:"x-deluge-login-window-icon"});Ext.apply(this,b);a.superclass.constructor.call(this)};Ext.extend(a,Ext.Window,{initComponent:function(){a.superclass.initComponent.call();Deluge.Events.on("logout",this.onLogout);this.on("show",this.onShow,this);this.addButton({text:_("Login"),handler:this.onLogin,scope:this});this.loginForm=this.add({xtype:"form",defaultType:"textfield",id:"loginForm",baseCls:"x-plain",labelWidth:55,items:[{fieldLabel:_("Password"),id:"password",name:"password",inputType:"password",anchor:"100%",listeners:{specialkey:{fn:this.onKey,scope:this}}}]})},onKey:function(c,b){if(b.getKey()==13){this.onLogin()}},onLogin:function(){var b=this.loginForm.items.get("password");Deluge.Client.web.login(b.getValue(),{onSuccess:function(c){if(c==true){this.hide();Deluge.Connections.loginShow();b.setRawValue("");Deluge.Events.fire("login")}else{Ext.MessageBox.show({title:_("Login Failed"),msg:_("You entered an incorrect password"),buttons:Ext.MessageBox.OK,modal:false,fn:function(){b.focus()},icon:Ext.MessageBox.WARNING,iconCls:"x-deluge-icon-warning"})}}.bindWithEvent(this)})},onLogout:function(){this.show()},onShow:function(){var b=this.loginForm.items.get("password");b.focus(false,150)}});Deluge.Login=new a()})();Deluge.Menus={onTorrentAction:function(c,d){var b=Deluge.Torrents.getSelections();var a=new Array();$each(b,function(e){a.include(e.id)});switch(c.id){case"pause":case"resume":Deluge.Client.core[c.id+"_torrent"](a,{onSuccess:function(){Deluge.UI.update()}});break;case"top":case"up":case"down":case"bottom":Deluge.Client.core["queue_"+c.id](a,{onSuccess:function(){Deluge.UI.update()}});break;case"update":Deluge.Client.core.force_reannounce(a,{onSuccess:function(){Deluge.UI.update()}});break;case"remove":Deluge.Events.fire("torrentRemoved",a);Deluge.Client.core.remove_torrent(a,null,{onSuccess:function(){Deluge.UI.update()}});break;case"recheck":Deluge.Client.core.force_recheck(a,{onSuccess:function(){Deluge.UI.update()}});break}}};Deluge.Menus.Torrent=new Ext.menu.Menu({id:"torrentMenu",items:[{id:"pause",text:_("Pause"),icon:"/icons/pause.png",handler:Deluge.Menus.onTorrentAction,scope:Deluge.Menus},{id:"resume",text:_("Resume"),icon:"/icons/start.png",handler:Deluge.Menus.onTorrentAction,scope:Deluge.Menus},"-",{id:"options",text:_("Options"),icon:"/icons/preferences.png",menu:new Ext.menu.Menu({items:[{text:_("D/L Speed Limit"),iconCls:"x-deluge-downloading",menu:new Ext.menu.Menu({items:[{text:_("5 KiB/s")},{text:_("10 KiB/s")},{text:_("30 KiB/s")},{text:_("80 KiB/s")},{text:_("300 KiB/s")},{text:_("Unlimited")}]})},{text:_("U/L Speed Limit"),iconCls:"x-deluge-seeding",menu:new Ext.menu.Menu({items:[{text:_("5 KiB/s")},{text:_("10 KiB/s")},{text:_("30 KiB/s")},{text:_("80 KiB/s")},{text:_("300 KiB/s")},{text:_("Unlimited")}]})},{text:_("Connection Limit"),iconCls:"x-deluge-connections",menu:new Ext.menu.Menu({items:[{text:_("50")},{text:_("100")},{text:_("200")},{text:_("300")},{text:_("500")},{text:_("Unlimited")}]})},{text:_("Upload Slot Limit"),icon:"/icons/upload_slots.png",menu:new Ext.menu.Menu({items:[{text:_("0")},{text:_("1")},{text:_("2")},{text:_("3")},{text:_("5")},{text:_("Unlimited")}]})},{id:"auto_managed",text:_("Auto Managed"),checked:false}]})},"-",{text:_("Queue"),icon:"/icons/queue.png",menu:new Ext.menu.Menu({items:[{id:"top",text:_("Top"),icon:"/icons/top.png",handler:Deluge.Menus.onTorrentAction,scope:Deluge.Menus},{id:"up",text:_("Up"),icon:"/icons/up.png",handler:Deluge.Menus.onTorrentAction,scope:Deluge.Menus},{id:"down",text:_("Down"),icon:"/icons/down.png",handler:Deluge.Menus.onTorrentAction,scope:Deluge.Menus},{id:"bottom",text:_("Bottom"),icon:"/icons/bottom.png",handler:Deluge.Menus.onTorrentAction,scope:Deluge.Menus}]})},"-",{id:"update",text:_("Update Tracker"),icon:"/icons/update.png",handler:Deluge.Menus.onTorrentAction,scope:Deluge.Menus},{edit:"edit_trackers",text:_("Edit Trackers"),icon:"/icons/edit_trackers.png",handler:Deluge.Menus.onTorrentAction,scope:Deluge.Menus},"-",{id:"remove",text:_("Remove Torrent"),icon:"/icons/remove.png",handler:Deluge.Menus.onTorrentAction,scope:Deluge.Menus},"-",{id:"recheck",text:_("Force Recheck"),icon:"/icons/recheck.png",handler:Deluge.Menus.onTorrentAction,scope:Deluge.Menus},{id:"move",text:_("Move Storage"),icon:"/icons/move.png",handler:Deluge.Menus.onTorrentAction,scope:Deluge.Menus}]});Deluge.Menus.Connections=new Ext.menu.Menu({id:"connectionsMenu",items:[{id:"50",text:"50",group:"max_connections_global",checked:false,checkHandler:onLimitChanged},{id:"100",text:"100",group:"max_connections_global",checked:false,checkHandler:onLimitChanged},{id:"200",text:"200",group:"max_connections_global",checked:false,checkHandler:onLimitChanged},{id:"300",text:"300",group:"max_connections_global",checked:false,checkHandler:onLimitChanged},{id:"500",text:"500",group:"max_connections_global",checked:false,checkHandler:onLimitChanged},{id:"-1",text:_("Unlimited"),group:"max_connections_global",checked:false,checkHandler:onLimitChanged},"-",{id:"other",text:_("Other"),group:"max_connections_global",checked:false,checkHandler:onLimitChanged}]});Deluge.Menus.Download=new Ext.menu.Menu({id:"downspeedMenu",items:[{id:"5",text:"5 KiB/s",group:"max_download_speed",checked:false,checkHandler:onLimitChanged},{id:"10",text:"10 KiB/s",group:"max_download_speed",checked:false,checkHandler:onLimitChanged},{id:"30",text:"30 KiB/s",group:"max_download_speed",checked:false,checkHandler:onLimitChanged},{id:"80",text:"80 KiB/s",group:"max_download_speed",checked:false,checkHandler:onLimitChanged},{id:"300",text:"300 KiB/s",group:"max_download_speed",checked:false,checkHandler:onLimitChanged},{id:"-1",text:_("Unlimited"),group:"max_download_speed",checked:false,checkHandler:onLimitChanged},"-",{id:"other",text:_("Other"),group:"max_download_speed",checked:false,checkHandler:onLimitChanged}]});Deluge.Menus.Upload=new Ext.menu.Menu({id:"upspeedMenu",items:[{id:"5",text:"5 KiB/s",group:"max_upload_speed",checked:false,checkHandler:onLimitChanged},{id:"10",text:"10 KiB/s",group:"max_upload_speed",checked:false,checkHandler:onLimitChanged},{id:"30",text:"30 KiB/s",group:"max_upload_speed",checked:false,checkHandler:onLimitChanged},{id:"80",text:"80 KiB/s",group:"max_upload_speed",checked:false,checkHandler:onLimitChanged},{id:"300",text:"300 KiB/s",group:"max_upload_speed",checked:false,checkHandler:onLimitChanged},{id:"-1",text:_("Unlimited"),group:"max_upload_speed",checked:false,checkHandler:onLimitChanged},"-",{id:"other",text:_("Other"),group:"max_upload_speed",checked:false,checkHandler:onLimitChanged}]});Deluge.Menus.FilePriorities=new Ext.menu.Menu({id:"filePrioritiesMenu",items:[{id:"expandAll",text:_("Expand All"),icon:"/icons/expand_all.png"},"-",{id:"no_download",text:_("Do Not Download"),icon:"/icons/no_download.png",filePriority:0},{id:"normal",text:_("Normal Priority"),icon:"/icons/normal.png",filePriority:1},{id:"high",text:_("High Priority"),icon:"/icons/high.png",filePriority:2},{id:"highest",text:_("Highest Priority"),icon:"/icons/highest.png",filePriority:5}]});function onLimitChanged(b,a){if(b.id=="other"){}else{config={};config[b.group]=b.id;Deluge.Client.core.set_config(config,{onSuccess:function(){Deluge.UI.update()}})}}Deluge.ToolBar={connected_buttons:["add","remove","pause","resume","up","down"],onTorrentAdd:function(){Deluge.Add.Window.show()},onConnect:function(){$each(this.connected_buttons,function(a){this.Bar.items.get(a).enable()},this)},onDisconnect:function(){$each(this.connected_buttons,function(a){this.Bar.items.get(a).disable()},this)},onLogin:function(){this.Bar.items.get("logout").enable()},onLogout:function(){this.Bar.items.get("logout").disable();Deluge.Events.fire("logout");Deluge.Login.show()},onConnectionManagerClick:function(a){Deluge.Connections.Window.show()},onPreferencesClick:function(){Deluge.Preferences.show()},onTorrentAction:function(c){var b=Deluge.Torrents.getSelections();var a=new Array();$each(b,function(d){a.include(d.id)});switch(c.id){case"remove":Deluge.Events.fire("torrentRemoved",a);Deluge.Client.core.remove_torrent(a,null,{onSuccess:function(){Deluge.UI.update()}});break;case"pause":case"resume":Deluge.Client.core[c.id+"_torrent"](a,{onSuccess:function(){Deluge.UI.update()}});break;case"up":case"down":Deluge.Client.core["queue_"+c.id](a,{onSuccess:function(){Deluge.UI.update()}});break}},onToolbarRender:function(a){Deluge.Events.on("connect",this.onConnect.bindWithEvent(this));Deluge.Events.on("login",this.onLogin.bindWithEvent(this))}};Deluge.ToolBar.Bar=new Ext.Toolbar({items:[{id:"create",cls:"x-btn-text-icon",disabled:true,text:_("Create"),icon:"/icons/create.png",handler:Deluge.ToolBar.onTorrentAction},{id:"add",cls:"x-btn-text-icon",disabled:true,text:_("Add"),icon:"/icons/add.png",handler:Deluge.ToolBar.onTorrentAdd},{id:"remove",cls:"x-btn-text-icon",disabled:true,text:_("Remove"),icon:"/icons/remove.png",handler:Deluge.ToolBar.onTorrentAction},"|",{id:"pause",cls:"x-btn-text-icon",disabled:true,text:_("Pause"),icon:"/icons/pause.png",handler:Deluge.ToolBar.onTorrentAction},{id:"resume",cls:"x-btn-text-icon",disabled:true,text:_("Resume"),icon:"/icons/start.png",handler:Deluge.ToolBar.onTorrentAction},"|",{id:"up",cls:"x-btn-text-icon",disabled:true,text:_("Up"),icon:"/icons/up.png",handler:Deluge.ToolBar.onTorrentAction},{id:"down",cls:"x-btn-text-icon",disabled:true,text:_("Down"),icon:"/icons/down.png",handler:Deluge.ToolBar.onTorrentAction},"|",{id:"preferences",cls:"x-btn-text-icon",text:_("Preferences"),icon:"/icons/preferences.png",handler:Deluge.ToolBar.onPreferencesClick,scope:Deluge.ToolBar},{id:"connectionman",cls:"x-btn-text-icon",text:_("Connection Manager"),iconCls:"x-deluge-connections",handler:Deluge.ToolBar.onConnectionManagerClick,scope:Deluge.ToolBar},"->",{id:"help",cls:"x-btn-text-icon",disabled:true,icon:"/icons/help.png",text:_("Help"),handler:Deluge.ToolBar.onHelpClick,scope:Deluge.ToolBar},{id:"logout",cls:"x-btn-text-icon",icon:"/icons/logout.png",disabled:true,text:_("Logout"),handler:Deluge.ToolBar.onLogout,scope:Deluge.ToolBar}],listeners:{render:Deluge.ToolBar.onToolbarRender,scope:Deluge.ToolBar}});Deluge.StatusBar={onRender:function(){this.bound={onConnect:this.onConnect.bindWithEvent(this),onDisconnect:this.onDisconnect.bindWithEvent(this)};Deluge.Events.on("connect",this.bound.onConnect);Deluge.Events.on("disconnect",this.bound.onDisconnect)},createButtons:function(){this.Bar.add({id:"statusbar-connections",text:"200 (200)",cls:"x-btn-text-icon",iconCls:"x-deluge-connections",menu:Deluge.Menus.Connections},"-",{id:"statusbar-downspeed",text:"9.8KiB/s (30 KiB/s)",cls:"x-btn-text-icon",iconCls:"x-deluge-downloading",menu:Deluge.Menus.Download},"-",{id:"statusbar-upspeed",text:"9.8KiB/s (30 KiB/s)",cls:"x-btn-text-icon",iconCls:"x-deluge-seeding",menu:Deluge.Menus.Upload},"-",{id:"statusbar-traffic",text:"1.53/2,65 KiB/s",cls:"x-btn-text-icon",iconCls:"x-deluge-traffic"},"-",{id:"statusbar-dht",text:"161",cls:"x-btn-text-icon",iconCls:"x-deluge-dht"});this.created=true},onConnect:function(){this.Bar.setStatus({iconCls:"x-connected",text:""});if(!this.created){this.createButtons()}else{this.Bar.items.each(function(a){a.show();a.enable()})}},onDisconnect:function(){this.Bar.clearStatus({useDefaults:true});this.Bar.items.each(function(a){a.hide();a.disable()})},update:function(b){function d(e){return e+" KiB/s"}var a=function(g,f){var h=this.Bar.items.get("statusbar-"+g);if(f.limit.value==-1){var j=(f.value.formatter)?f.value.formatter(f.value.value):f.value.value}else{var i=(f.value.formatter)?f.value.formatter(f.value.value):f.value.value;var e=(f.limit.formatter)?f.limit.formatter(f.limit.value):f.limit.value;var j=String.format(f.format,i,e)}h.setText(j)}.bind(this);a("connections",{value:{value:b.num_connections},limit:{value:b.max_num_connections},format:"{0} ({1})"});a("downspeed",{value:{value:b.download_rate,formatter:Deluge.Formatters.speed},limit:{value:b.max_download,formatter:d},format:"{0} ({1})"});a("upspeed",{value:{value:b.upload_rate,formatter:Deluge.Formatters.speed},limit:{value:b.max_upload,formatter:d},format:"{0} ({1})"});a("traffic",{value:{value:b.payload_download_rate,formatter:Deluge.Formatters.speed},limit:{value:b.payload_upload_rate,formatter:Deluge.Formatters.speed},format:"{0}/{1}"});this.Bar.items.get("statusbar-dht").setText(b.dht_nodes);function c(g,e){var f=g.items.get(e);if(!f){f=g.items.get("other")}f.setChecked(true)}c(Deluge.Menus.Connections,b.max_num_connections);c(Deluge.Menus.Download,b.max_download);c(Deluge.Menus.Upload,b.max_upload)}};Deluge.StatusBar.Bar=new Ext.StatusBar({id:"deluge-statusbar",defaultIconCls:"x-not-connected",defaultText:_("Not Connected"),listeners:{render:{scope:Deluge.StatusBar,fn:Deluge.StatusBar.onRender}}});Deluge.SideBar={panels:new Hash(),onRender:function(a){this.Bar=a;Deluge.Events.on("disconnect",this.onDisconnect.bindWithEvent(this));this.selected=null},onDisconnect:function(){this.panels.getKeys().each(function(a){this.Bar.remove(a+"-panel")},this);this.panels.empty();this.selected=null},renderer:function(c,e,b){var a=c.toLowerCase().replace(".","_");var d="";if(b.store.id=="tracker_host"){if(c!="Error"){d=String.format("url(/tracker/{0})",c)}else{a=null}}if(d){return String.format('
{0} ({1})
',c,b.data.count,d)}else{if(a){return String.format('
{0} ({1})
',c,b.data.count,a)}else{return String.format('
{0} ({1})
',c,b.data.count)}}},getFilters:function(){var b={};if(!this.selected){return b}if(!this.selected.filter||!this.selected.panel){return b}var a=this.selected.panel.store.id;if(a=="state"&&this.selected.filter=="All"){return b}b[a]=this.selected.filter;return b},update:function(a){a=new Hash(a);a.each(function(b,c){if(this.panels.has(c)){this.updateFilter(c,b)}else{this.createFilter(c,b)}},this);$each(this.panels.getKeys(),function(b){if(!a.has(b)){}})},createFilter:function(d,c){var b=new Ext.data.SimpleStore({id:d,fields:[{name:"filter"},{name:"count"}]});var f=d.replace("_"," ");var e=f.split(" ");f="";e.each(function(g){firstLetter=g.substring(0,1);firstLetter=firstLetter.toUpperCase();g=firstLetter+g.substring(1);f+=g+" "});var a=new Ext.grid.GridPanel({id:d+"-panel",store:b,title:_(f),columns:[{id:"filter",sortable:false,renderer:this.renderer,dataIndex:"filter"}],stripeRows:false,selModel:new Ext.grid.RowSelectionModel({singleSelect:true,listeners:{rowselect:this.onSelect.bindWithEvent(this)}}),hideHeaders:true,autoExpandColumn:"filter",deferredRender:false,autoScroll:true});b.loadData(c);this.Bar.add(a);this.Bar.doLayout();this.panels[d]=a;if(!this.selected){a.getSelectionModel().selectFirstRow();this.selected={row:0,filter:c[0][0],panel:a}}},onSelect:function(b,c,a){if(!this.selected){needsUpdate=true}else{if(this.selected.row!=c){needsUpdate=true}else{needsUpdate=false}}this.selected={row:c,filter:a.get("filter"),panel:this.panels[a.store.id]};if(needsUpdate){Deluge.UI.update()}},updateFilter:function(b,a){this.panels[b].store.loadData(a);if(this.selected&&this.selected.panel==this.panels[b]){this.panels[b].getSelectionModel().selectRow(this.selected.row)}}};Deluge.SideBar.Config={region:"west",id:"sidebar",cls:"deluge-sidebar",title:_("Filters"),layout:"accordion",split:true,width:200,minSize:175,collapsible:true,margins:"5 0 0 5",cmargins:"5 5 0 5",listeners:{render:{scope:Deluge.SideBar,fn:Deluge.SideBar.onRender}}};Deluge.Connections={disconnect:function(){Deluge.Events.fire("disconnect")},loginShow:function(){Deluge.Events.on("logout",function(a){Deluge.Connections.disconnect();Deluge.Connections.Window.hide()});Deluge.Client.web.connected({onSuccess:function(a){if(a){Deluge.Events.fire("connect")}else{Deluge.Connections.Window.show()}}})},onAdd:function(a,b){Deluge.Connections.Add.show()},onAddHost:function(){var d=Deluge.Connections.Add.items.first();var c=d.items.get("host").getValue();var a=d.items.get("port").getValue();var e=d.items.get("username").getValue();var b=d.items.get("_password").getValue();Deluge.Client.web.add_host(c,a,e,b,{onSuccess:function(f){if(!f[0]){Ext.MessageBox.show({title:_("Error"),msg:"Unable to add host: "+f[1],buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.ERROR,iconCls:"x-deluge-icon-error"})}else{Deluge.Connections.runCheck()}Deluge.Connections.Add.hide()}})},onAddWindowHide:function(){var a=Deluge.Connections.Add.items.first();a.items.get("host").reset();a.items.get("port").reset();a.items.get("username").reset();a.items.get("_password").reset()},onClose:function(a){$clear(Deluge.Connections.running);Deluge.Connections.Window.hide()},onConnect:function(b){var a=Deluge.Connections.Grid.getSelectionModel().getSelected();if(!a){return}if(a.get("status")==_("Connected")){Deluge.Client.web.disconnect({onSuccess:function(d){Deluge.Connections.runCheck();Deluge.Events.fire("disconnect")}})}else{var c=a.id;Deluge.Client.web.connect(c,{onSuccess:function(d){Deluge.Client=new JSON.RPC("/json",{methods:d});Deluge.Events.fire("connect")}});$clear(Deluge.Connections.running);Deluge.Connections.Window.hide()}},onGetHosts:function(a){Deluge.Connections.Store.loadData(a);var b=Deluge.Connections.Grid.getSelectionModel();b.selectRow(Deluge.Connections.selectedRow)},onRemove:function(b){var a=Deluge.Connections.Grid.getSelectionModel().getSelected();Deluge.Client.web.remove_host(a.id,{onSuccess:function(c){if(!c){Ext.MessageBox.show({title:_("Error"),msg:c[1],buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.ERROR,iconCls:"x-deluge-icon-error"})}else{Deluge.Connections.Grid.store.remove(a)}}})},onSelect:function(b,d,a){Deluge.Connections.selectedRow=d;var c=Deluge.Connections.Window.buttons[1];if(a.get("status")==_("Connected")){c.setText(_("Disconnect"))}else{c.setText(_("Connect"))}},onShow:function(a){Deluge.Connections.running=Deluge.Connections.runCheck.periodical(2000);Deluge.Connections.runCheck()},onStop:function(b,c){var a=Deluge.Connections.Grid.getSelectionModel().getSelected();Deluge.Client.web.stop_daemon(a.id,{onSuccess:function(d){if(!d[0]){Ext.MessageBox.show({title:_("Error"),msg:d[1],buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.ERROR,iconCls:"x-deluge-icon-error"})}}})},runCheck:function(a){a=$pick(a,Deluge.Connections.onGetHosts);Deluge.Client.web.get_hosts({onSuccess:a})}};Deluge.Connections.Store=new Ext.data.SimpleStore({fields:[{name:"status",mapping:3},{name:"host",mapping:1},{name:"port",mapping:2},{name:"version",mapping:4}],id:0});var renderHost=function(b,c,a){return b+":"+a.data.port};Deluge.Connections.Grid=new Ext.grid.GridPanel({store:Deluge.Connections.Store,columns:[{header:"Status",width:65,sortable:true,renderer:Deluge.Formatters.plain,dataIndex:"status"},{id:"host",header:"Host",width:150,sortable:true,renderer:renderHost,dataIndex:"host"},{header:"Version",width:75,sortable:true,renderer:Deluge.Formatters.plain,dataIndex:"version"}],stripeRows:true,selModel:new Ext.grid.RowSelectionModel({singleSelect:true,listeners:{rowselect:Deluge.Connections.onSelect}}),autoExpandColumn:"host",deferredRender:false,autoScroll:true,margins:"0 0 0 0",bbar:new Ext.Toolbar({items:[{id:"add",cls:"x-btn-text-icon",text:_("Add"),icon:"/icons/add.png",handler:Deluge.Connections.onAdd},{id:"remove",cls:"x-btn-text-icon",text:_("Remove"),icon:"/icons/remove.png",handler:Deluge.Connections.onRemove},"->",{id:"stop",cls:"x-btn-text-icon",text:_("Stop Daemon"),icon:"/icons/error.png",handler:Deluge.Connections.onStop}]})});Deluge.Connections.Add=new Ext.Window({layout:"fit",width:300,height:195,bodyStyle:"padding: 10px 5px;",buttonAlign:"right",closeAction:"hide",closable:true,plain:true,title:_("Add Connection"),iconCls:"x-deluge-add-window-icon",items:[new Ext.form.FormPanel({defaultType:"textfield",id:"connectionAddForm",baseCls:"x-plain",labelWidth:55,items:[{fieldLabel:_("Host"),id:"host",name:"host",anchor:"100%",listeners:{}},{fieldLabel:_("Port"),id:"port",xtype:"uxspinner",ctCls:"x-form-uxspinner",name:"port",strategy:Ext.ux.form.Spinner.NumberStrategy(),value:"58846",anchor:"50%",listeners:{}},{fieldLabel:_("Username"),id:"username",name:"username",anchor:"100%",listeners:{}},{fieldLabel:_("Password"),anchor:"100%",id:"_password",name:"_password",inputType:"password"}]})],buttons:[{text:_("Close"),handler:function(){Deluge.Connections.Add.hide()}},{text:_("Add"),handler:Deluge.Connections.onAddHost}],listeners:{hide:Deluge.Connections.onAddWindowHide}});Deluge.Connections.Window=new Ext.Window({layout:"fit",width:300,height:220,bodyStyle:"padding: 10px 5px;",buttonAlign:"right",closeAction:"hide",closable:true,plain:true,title:_("Connection Manager"),iconCls:"x-deluge-connect-window-icon",items:[Deluge.Connections.Grid],buttons:[{text:_("Close"),handler:Deluge.Connections.onClose},{text:_("Connect"),handler:Deluge.Connections.onConnect}],listeners:{hide:Deluge.Connections.onClose,show:Deluge.Connections.onShow}});(function(){function f(i){return(i==-1)?"":i+1}function b(j,k,i){return String.format('
{1}
',i.data.state.toLowerCase(),j)}function h(i){if(!i){return}return fspeed(i)}function c(l,m,k){var i=l.toInt();var n=k.data.state+" "+l.toFixed(2)+"%";var j=this.style.match(/\w+:\s*(\d+)\w+/)[1].toInt()-8;return Deluge.progressBar(l.toInt(),j,n)}function e(j,k,i){if(i.data.total_seeds>-1){return String.format("{0} ({1})",j,i.data.total_seeds)}else{return j}}function g(j,k,i){if(i.data.total_peers>-1){return String.format("{0} ({1})",j,i.data.total_peers)}else{return j}}function d(j,k,i){j.toFixed(3)}function a(j,k,i){return String.format('
{0}
',j)}Ext.namespace("Ext.deluge");Ext.deluge.TorrentGrid=function(i){Ext.deluge.TorrentGrid.superclass.constructor.call(this,{id:"torrentGrid",store:new Ext.data.SimpleStore({fields:[{name:"queue"},{name:"name"},{name:"size",type:"int"},{name:"state"},{name:"progress",type:"float"},{name:"seeds",type:"int"},{name:"total_seeds",type:"int"},{name:"peers",type:"int"},{name:"total_peers",type:"int"},{name:"downspeed",type:"int"},{name:"upspeed",type:"int"},{name:"eta",type:"int"},{name:"ratio",type:"float"},{name:"avail",type:"float"},{name:"added",type:"int"},{name:"tracker"}],id:16}),columns:[{id:"queue",header:_("#"),width:30,sortable:true,renderer:f,dataIndex:"queue"},{id:"name",header:_("Name"),width:150,sortable:true,renderer:b,dataIndex:"name"},{header:_("Size"),width:75,sortable:true,renderer:fsize,dataIndex:"size"},{header:_("Progress"),width:150,sortable:true,renderer:c,dataIndex:"progress"},{header:_("Seeders"),width:60,sortable:true,renderer:e,dataIndex:"seeds"},{header:_("Peers"),width:60,sortable:true,renderer:g,dataIndex:"peers"},{header:_("Down Speed"),width:80,sortable:true,renderer:h,dataIndex:"downspeed"},{header:_("Up Speed"),width:80,sortable:true,renderer:h,dataIndex:"upspeed"},{header:_("ETA"),width:60,sortable:true,renderer:ftime,dataIndex:"eta"},{header:_("Ratio"),width:60,sortable:true,renderer:d,dataIndex:"ratio"},{header:_("Avail"),width:60,sortable:true,renderer:d,dataIndex:"avail"},{header:_("Added"),width:80,sortable:true,renderer:fdate,dataIndex:"added"},{header:_("Tracker"),width:120,sortable:true,renderer:a,dataIndex:"tracker"}],region:"center",cls:"deluge-torrents",stripeRows:true,autoExpandColumn:"name",deferredRender:false,autoScroll:true,margins:"5 5 0 0"})};Ext.extend(Ext.deluge.TorrentGrid,Ext.grid.GridPanel,{initComponent:function(){Ext.deluge.TorrentGrid.superclass.initComponent.call(this);Deluge.Events.on("torrentRemoved",this.onTorrentRemoved,this);this.on("rowcontextmenu",function(i,l,k){k.stopEvent();var j=i.getSelectionModel();if(!j.hasSelection()){j.selectRow(l)}Deluge.Menus.Torrent.showAt(k.getPoint())})},getTorrent:function(i){return this.getStore().getAt(i)},getSelected:function(){return this.getSelectionModel().getSelected()},getSelections:function(){return this.getSelectionModel().getSelections()},onTorrentRemoved:function(j){var i=this.Grid.getSelectionModel();$each(j,function(l){var k=this.Store.getById(l);if(i.isSelected(k)){i.deselectRow(this.Store.indexOf(k))}this.Store.remove(k)},this)}});Deluge.Torrents=new Ext.deluge.TorrentGrid()})();Deluge.Details={clear:function(){this.Panel.items.each(function(a){if(a.clear){a.clear()}})},update:function(a){var b=Deluge.Torrents.getSelected();if(!b){return}a=a||this.Panel.getActiveTab();if(a.update){a.update(b.id)}},onRender:function(a){Deluge.Torrents.on("rowclick",this.onTorrentsClick.bindWithEvent(this));var b=Deluge.Torrents.getSelectionModel();b.on("selectionchange",function(c){if(!c.hasSelection()){this.clear.delay(10,this)}}.bindWithEvent(this));Deluge.Events.on("disconnect",this.clear.bind(this))},onTabChange:function(a,b){this.update(b)},onTorrentsClick:function(a,c,b){this.update()}};Deluge.Details.Status={onRender:function(a){this.panel=a;this.progressBar=new Ext.ux.FullProgressBar({id:"pbar-status",cls:"deluge-status-progressbar"});this.panel.add(this.progressBar);this.panel.add({id:"status-details",cls:"deluge-status",border:false,listeners:{render:Deluge.Details.Status.onStatusRender}});this.panel.update=this.update.bind(this);this.panel.clear=this.clear.bind(this)},onStatusRender:function(a){this.status=a;this.status.load({url:"/render/tab_status.html",text:_("Loading")+"..."})},onRequestComplete:function(a){seeders=a.total_seeds>-1?a.num_seeds+" ("+a.total_seeds+")":a.num_seeds;peers=a.total_peers>-1?a.num_peers+" ("+a.total_peers+")":a.num_peers;var b={downloaded:fsize(a.total_done)+" ("+fsize(a.total_payload_download)+")",uploaded:fsize(a.total_uploaded)+" ("+fsize(a.total_payload_upload)+")",share:a.ratio.toFixed(3),announce:ftime(a.next_announce),tracker_status:a.tracker_status,downspeed:fspeed(a.download_payload_rate),upspeed:fspeed(a.upload_payload_rate),eta:ftime(a.eta),pieces:a.num_pieces+" ("+fsize(a.piece_length)+")",seeders:seeders,peers:peers,avail:a.distributed_copies.toFixed(3),active_time:ftime(a.active_time),seeding_time:ftime(a.seeding_time),seed_rank:a.seed_rank,auto_managed:"False",time_added:fdate(a.time_added)};if(a.is_auto_managed){b.auto_managed="True"}this.fields.each(function(e,d){e.set("text",b[d])},this);var c=a.state+" "+a.progress.toFixed(2)+"%";this.progressBar.updateProgress(a.progress,c)},getFields:function(){var a=this.panel.items.get("status-details");this.fields=new Hash();$(a.body.dom).getElements("dd").each(function(b){this.fields[b.getProperty("class")]=b},this)},update:function(a){if(!this.fields){this.getFields()}Deluge.Client.core.get_torrent_status(a,Deluge.Keys.Status,{onSuccess:this.onRequestComplete.bind(this)})},clear:function(){if(!this.fields){return}this.progressBar.updateProgress(0," ");this.fields.each(function(b,a){b.set("text","")},this)}};Deluge.Details.Details={onRender:function(a){this.panel=a;a.load({url:"/render/tab_details.html",text:_("Loading")+"...",callback:this.onLoaded.bindWithEvent(this)});this.doUpdate=false;this.panel.update=this.update.bind(this);this.panel.clear=this.clear.bind(this)},onLoaded:function(){this.getFields();this.doUpdate=true;if(Deluge.Details.Panel.getActiveTab()==this.panel){Deluge.Details.update(this.panel)}},onRequestComplete:function(c,a){var b={torrent_name:c.name,hash:a,path:c.save_path,size:fsize(c.total_size),files:c.num_files,status:c.tracker_status,tracker:c.tracker,comment:c.comment};this.fields.each(function(e,d){e.set("text",b[d])},this)},getFields:function(){this.fields=new Hash();$(this.panel.body.dom.firstChild).getElements("dd").each(function(a){this.fields[a.getProperty("class")]=a},this)},update:function(a){if(!this.doUpdate){return}if(!this.fields){this.getFields()}Deluge.Client.core.get_torrent_status(a,Deluge.Keys.Details,{onSuccess:this.onRequestComplete.bindWithEvent(this,a)})},clear:function(){if(!this.fields){return}this.fields.each(function(b,a){b.set("text","")},this)}};Deluge.Details.Files={onRender:function(a){this.panel=a;this.panel.clear=this.clear.bind(this);this.panel.update=this.update.bind(this);new Ext.tree.TreeSorter(this.panel,{folderSort:true});Deluge.Menus.FilePriorities.on("itemclick",this.onItemClick.bindWithEvent(this))},onContextMenu:function(b,c){c.stopEvent();var a=this.panel.getSelectionModel();if(a.getSelectedNodes().length<2){a.clearSelections();b.select()}Deluge.Menus.FilePriorities.showAt(c.getPoint())},onItemClick:function(f,d){switch(f.id){case"expandAll":this.panel.expandAll();break;default:var c=new Hash();function a(e){if(!$defined(e.attributes.fileIndex)){return}c[e.attributes.fileIndex]=e.attributes.priority}this.panel.getRootNode().cascade(a);var b=this.panel.getSelectionModel().getSelectedNodes();$each(b,function(e){if(!$defined(e.attributes.fileIndex)){return}c[e.attributes.fileIndex]=f.filePriority});priorities=new Array(c.getLength());c.each(function(g,e){priorities[e]=g});Deluge.Client.core.set_torrent_file_priorities(this.torrentId,priorities,{onSuccess:function(){$each(b,function(e){e.setColumnValue(3,f.filePriority)})}.bind(this)});break}},onRequestComplete:function(d,c){if(this.torrentId!=c){this.clear();this.torrentId=c}function b(f,e){$each(f,function(h,g){var i=e.findChild("id",g);if($type(h)=="object"){if(!i){i=new Ext.tree.TreeNode({id:g,text:g});e.appendChild(i)}b(h,i)}else{if(!i){i=new Ext.tree.ColumnTreeNode({id:g,filename:g,text:g,fileIndex:h[0],size:h[1],progress:h[2],priority:h[3],leaf:true,iconCls:"x-deluge-file",uiProvider:Ext.tree.ColumnNodeUI});e.appendChild(i)}i.setColumnValue(1,h[1]);i.setColumnValue(2,h[2]);i.setColumnValue(3,h[3])}})}var a=this.panel.getRootNode();b(d,a);a.firstChild.expand()},clear:function(){var a=this.panel.getRootNode();if(!a.hasChildNodes()){return}a.cascade(function(c){var b=c.parentNode;if(!b){return}if(!b.ownerTree){return}b.removeChild(c)})},update:function(a){Deluge.Client.web.get_torrent_files(a,{onSuccess:this.onRequestComplete.bindWithEvent(this,a)})}};Deluge.Details.Peers={onRender:function(a){this.panel=a;this.panel.update=this.update.bind(this);this.panel.clear=this.clear.bind(this)},onRequestComplete:function(b){var a=new Array();b.peers.each(function(c){a.include([c.country,c.ip,c.client,c.progress,c.down_speed,c.up_speed,c.seed])},this);this.Store.loadData(a)},clear:function(){this.Store.loadData([])},update:function(a){Deluge.Client.core.get_torrent_status(a,Deluge.Keys.Peers,{onSuccess:this.onRequestComplete.bindWithEvent(this,a)})}};Deluge.Details.Options={onRender:function(a){a.layout=new Ext.layout.FormLayout();a.layout.setContainer(a);a.doLayout();this.form=a.getForm()},onRequestComplete:function(a){},clear:function(){this.form.findField("max_download_speed").setValue(0);this.form.findField("max_upload_speed").setValue(0);this.form.findField("max_connections").setValue(0);this.form.findField("max_upload_slots").setValue(0);this.form.findField("stop_ratio").setValue(0);this.form.findField("is_auto_managed").setValue(false);this.form.findField("stop_at_ratio").setValue(false);this.form.findField("remove_at_ratio").setValue(false);this.form.findField("private").setValue(false);this.form.findField("prioritize_first_last").setValue(false)},update:function(a){Deluge.Client.core.get_torrent_status(a,Deluge.Keys.Options,{onSuccess:this.onRequestComplete.bindWithEvent(this,a)})},reset:function(){if(this.torrentId){delete this.changed[this.torrentId]}}};function flag(a){return String.format('',a)}function peer_address(c,d,b){var a=(b.data.seed==1024)?"x-deluge-seed":"x-deluge-peer";return String.format('
{1}
',a,c)}function file_progress(b){var a=b*100;return progressBar(a,this.width-50,a.toFixed(2)+"%")}function peer_progress(c){var a=(c*100).toInt();var b=this.style.match(/\w+:\s*(\d+)\w+/)[1].toInt()-8;return progressBar(a,b,a+"%")}FILE_PRIORITY_CSS={0:"x-no-download",1:"x-normal-download",2:"x-high-download",5:"x-highest-download"};function priority_renderer(a){return String.format('
{1}
',FILE_PRIORITY_CSS[a],_(FILE_PRIORITY[a]))}function sort_address(c){var a=c.match(/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\:(\d+)/);var b=0;var d=[a[1],a[2],a[3],a[4]];$each(d,function(f,e){f=parseInt(f);b=b|f<<((3-e)*8);alert("Total: "+b+"\nPart: "+f+"\nIndex: "+e+"\nCalc: "+(f<<((3-e)*8)))});return b}Deluge.Details.Peers.Store=new Ext.data.SimpleStore({fields:[{name:"country"},{name:"address",sortType:sort_address},{name:"client"},{name:"progress",type:"float"},{name:"downspeed",type:"int"},{name:"upspeed",type:"int"},{name:"seed",type:"int"}],id:0});Deluge.Details.Panel=new Ext.TabPanel({region:"south",split:true,height:220,minSize:100,collapsible:true,margins:"0 5 5 5",activeTab:0,items:[{id:"status",title:_("Status"),listeners:{render:{fn:Deluge.Details.Status.onRender,scope:Deluge.Details.Status}}},{id:"details",title:_("Details"),cls:"deluge-status",listeners:{render:{fn:Deluge.Details.Details.onRender,scope:Deluge.Details.Details}}},new Ext.tree.ColumnTree({id:"files",title:_("Files"),rootVisible:false,autoScroll:true,selModel:new Ext.tree.MultiSelectionModel(),columns:[{header:_("Filename"),width:330,dataIndex:"filename"},{header:_("Size"),width:150,dataIndex:"size",renderer:fsize},{header:_("Progress"),width:150,dataIndex:"progress",renderer:file_progress},{header:_("Priority"),width:150,dataIndex:"priority",renderer:priority_renderer}],root:new Ext.tree.TreeNode({text:"Files"}),listeners:{render:{fn:Deluge.Details.Files.onRender,scope:Deluge.Details.Files},contextmenu:{fn:Deluge.Details.Files.onContextMenu,scope:Deluge.Details.Files}}}),new Ext.grid.GridPanel({id:"peers",title:_("Peers"),cls:"x-deluge-peers",store:Deluge.Details.Peers.Store,columns:[{header:" ",width:30,sortable:true,renderer:flag,dataIndex:"country"},{header:"Address",width:125,sortable:true,renderer:peer_address,dataIndex:"address"},{header:"Client",width:125,sortable:true,renderer:Deluge.Formatters.plain,dataIndex:"client"},{header:"Progress",width:150,sortable:true,renderer:peer_progress,dataIndex:"progress"},{header:"Down Speed",width:100,sortable:true,renderer:fspeed,dataIndex:"downspeed"},{header:"Up Speed",width:100,sortable:true,renderer:fspeed,dataIndex:"upspeed"}],stripeRows:true,deferredRender:false,autoScroll:true,margins:"0 0 0 0",listeners:{render:{fn:Deluge.Details.Peers.onRender,scope:Deluge.Details.Peers}}}),new Ext.form.FormPanel({id:"options",title:_("Options"),frame:true,autoScroll:true,deferredRender:false,items:[{layout:"column",defaults:{border:false},items:[{bodyStyle:"padding-left: 5px; padding-right:5px;",width:300,items:[{xtype:"fieldset",title:_("Bandwidth"),layout:"table",layoutConfig:{columns:3},autoHeight:true,labelWidth:150,defaultType:"uxspinner",items:[{xtype:"label",text:_("Max Download Speed"),forId:"max_download_speed",cls:"x-deluge-options-label"},{id:"max_download_speed",width:100,value:-1,strategy:new Ext.ux.form.Spinner.NumberStrategy({minValue:-1,maxValue:99999,incrementValue:1})},{xtype:"label",text:"KiB/s",style:"margin-left: 10px;"},{xtype:"label",text:_("Max Upload Speed"),forId:"max_upload_speed",cls:"x-deluge-options-label"},{id:"max_upload_speed",width:100,value:-1,strategy:new Ext.ux.form.Spinner.NumberStrategy({minValue:-1,maxValue:99999,incrementValue:1})},{xtype:"label",text:"KiB/s",style:"margin-left: 10px;"},{xtype:"label",text:_("Max Connections"),forId:"max_connections",cls:"x-deluge-options-label"},{id:"max_connections",colspan:2,width:100,value:-1,strategy:new Ext.ux.form.Spinner.NumberStrategy({minValue:-1,maxValue:99999,incrementValue:1})},{xtype:"label",text:_("Max Upload Slots"),forId:"max_upload_slots",cls:"x-deluge-options-label"},{id:"max_upload_slots",colspan:2,width:100,value:-1,strategy:new Ext.ux.form.Spinner.NumberStrategy({minValue:-1,maxValue:99999,incrementValue:1})}]}]},{bodyStyle:"padding-left: 5px; padding-right:5px;",width:200,items:[{xtype:"fieldset",title:_("Queue"),autoHeight:true,labelWidth:1,defaultType:"checkbox",items:[{fieldLabel:"",labelSeparator:"",boxLabel:_("Auto Managed"),id:"is_auto_managed"},{fieldLabel:"",labelSeparator:"",boxLabel:_("Stop seed at ratio"),id:"stop_at_ratio"},{fieldLabel:"",labelSeparator:"",boxLabel:_("Remove at ratio"),id:"remove_at_ratio"},{fieldLabel:"",labelSeparator:"",boxLabel:_("Move Completed"),id:"move_completed"}]}]},{bodyStyle:"padding-left:5px;",width:200,items:[{xtype:"fieldset",title:_("General"),autoHeight:true,defaultType:"checkbox",labelWidth:1,items:[{fieldLabel:"",labelSeparator:"",boxLabel:_("Private"),id:"private"},{fieldLabel:"",labelSeparator:"",boxLabel:_("Prioritize First/Last"),id:"prioritize_first_last"}]},{layout:"column",items:[{items:[{id:"edit_trackers",xtype:"button",text:_("Edit Trackers"),cls:"x-btn-text-icon",iconCls:"x-deluge-edit-trackers",width:100}]},{items:[{id:"apply",xtype:"button",text:_("Apply"),style:"margin-left: 10px",width:100}]}]}]}]}],listeners:{render:{fn:Deluge.Details.Options.onRender,scope:Deluge.Details.Options}}})],listeners:{render:{fn:Deluge.Details.onRender,scope:Deluge.Details},tabchange:{fn:Deluge.Details.onTabChange,scope:Deluge.Details}}});Deluge.Add={torrents:new Hash(),clear:function(){this.clearFiles();this.Store.loadData([]);this.torrents.empty()},clearFiles:function(){var a=this.Files.getRootNode();if(!a.hasChildNodes()){return}a.cascade(function(b){if(!b.parentNode||!b.getOwnerTree()){return}b.remove()})},getDefaults:function(){var a=["add_paused","compact_allocation","download_location","max_connections_per_torrent","max_download_speed_per_torrent","max_upload_slots_per_torrent","max_upload_speed_per_torrent","prioritize_first_last_pieces"];Deluge.Client.core.get_config_values(a,{onSuccess:function(b){this.defaults=b;$each(b,function(e,d){var f=this.form.findField(d);if(!f){return}f.setValue(e)},this);var c=this.form.findField("compact_allocation");if(b.compact_allocation){c.items.get("compact_allocation_true").setValue(true);c.items.get("compact_allocation_false").setValue(false)}else{c.items.get("compact_allocation_false").setValue(true);c.items.get("compact_allocation_true").setValue(false)}}.bindWithEvent(this)})},onAdd:function(){torrents=new Array();this.torrents.each(function(b,a){torrents.include({path:b.filename,options:{}})});Deluge.Client.web.add_torrents(torrents,{onSuccess:function(a){}});this.clear();this.Window.hide()},onFile:function(){this.File.Window.show()},onOptionsRender:function(a){a.layout=new Ext.layout.FormLayout();a.layout.setContainer(a);a.doLayout();this.form=a.getForm();this.getDefaults()},onRender:function(a){new Ext.tree.TreeSorter(this.Files,{folderSort:true})},onSelect:function(e,f,c){var d=Deluge.Add.torrents[c.id];function b(h,g){$each(h,function(j,i){if($type(j)=="object"){var k=new Ext.tree.TreeNode({text:i});b(j,k);g.appendChild(k)}else{g.appendChild(new Ext.tree.TreeNode({filename:i,text:i,size:fsize(j[0]),leaf:true,checked:j[1],iconCls:"x-deluge-file",uiProvider:Ext.tree.ColumnNodeUI}))}})}this.clearFiles();var a=this.Files.getRootNode();b(d.files_tree,a);a.firstChild.expand()},onTorrentAdded:function(b,a){if(!b){Ext.MessageBox.show({title:_("Error"),msg:_("Not a valid torrent"),buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.ERROR,iconCls:"x-deluge-icon-error"});return}b.filename=a;this.Store.loadData([[b.info_hash,b.name]],true);this.torrents[b.info_hash]=b},onUrl:function(a,b){this.Url.Window.show()},onRemove:function(){var a=this.Grid.getSelectionModel();if(!a.hasSelection()){return}var b=a.getSelected();delete this.torrents[b.id];this.Store.remove(b);this.clearFiles()}};Deluge.Add.Files=new Ext.tree.ColumnTree({id:"files",layout:"fit",rootVisible:false,autoScroll:true,height:170,border:false,animate:false,columns:[{header:_("Filename"),width:275,dataIndex:"filename"},{header:_("Size"),width:80,dataIndex:"size"}],root:new Ext.tree.AsyncTreeNode({text:"Files"})});Deluge.Add.Store=new Ext.data.SimpleStore({fields:[{name:"torrent",mapping:1}],id:0});Deluge.Add.Grid=new Ext.grid.GridPanel({store:Deluge.Add.Store,region:"center",columns:[{id:"torrent",width:150,sortable:true,renderer:Deluge.Formatters.plain,dataIndex:"torrent"}],stripeRows:true,selModel:new Ext.grid.RowSelectionModel({singleSelect:true,listeners:{rowselect:{fn:Deluge.Add.onSelect,scope:Deluge.Add}}}),hideHeaders:true,autoExpandColumn:"torrent",deferredRender:false,autoScroll:true,margins:"5 5 5 5",bbar:new Ext.Toolbar({items:[{id:"file",cls:"x-btn-text-icon",iconCls:"x-deluge-add-file",text:_("File"),handler:Deluge.Add.onFile,scope:Deluge.Add},{id:"url",cls:"x-btn-text-icon",text:_("Url"),icon:"/icons/add_url.png",handler:Deluge.Add.onUrl,scope:Deluge.Add},{id:"infohash",cls:"x-btn-text-icon",text:_("Infohash"),icon:"/icons/add_magnet.png",disabled:true},"->",{id:"remove",cls:"x-btn-text-icon",text:_("Remove"),icon:"/icons/remove.png",handler:Deluge.Add.onRemove,scope:Deluge.Add}]})});Deluge.Add.Options=new Ext.TabPanel({region:"south",margins:"5 5 5 5",activeTab:0,height:220,items:[{id:"addFilesTab",title:_("Files"),items:[Deluge.Add.Files]},{id:"addOptionsTab",title:_("Options"),layout:"fit",items:[new Ext.form.FormPanel({id:"addOptionsForm",bodyStyle:"padding: 5px;",border:false,items:[{xtype:"fieldset",style:"padding: 0px; padding-top: 5px;",title:_("Download Location"),border:false,autoHeight:true,border:false,labelWidth:1,items:[{layout:"column",border:false,items:[{xtype:"textfield",id:"download_location",fieldLabel:"",labelSeparator:"",width:330},{border:false,style:"padding-left: 5px;",items:[{xtype:"button",text:_("Browse")+"...",disabled:true}]}]}]},{layout:"column",border:false,defaults:{border:false},items:[{xtype:"fieldset",bodyStyle:"margin-left: 5px; margin-right:5px;",title:_("Allocation"),autoHeight:true,border:false,labelWidth:1,width:100,items:[new Ext.form.RadioGroup({id:"compact_allocation",name:"compact_allocation",columns:1,labelSeparator:"",items:[{boxLabel:_("Full"),inputValue:"false",id:"compact_allocation_false",name:"compact_allocation",checked:true},{boxLabel:_("Compact"),inputValue:"true",id:"compact_allocation_true",name:"compact_allocation"}]})]},{xtype:"fieldset",title:_("Bandwidth"),layout:"form",autoHeight:true,defaultType:"uxspinner",labelWidth:100,items:[{id:"max_download_speed_per_torrent",fieldLabel:_("Max Down Speed"),width:60,value:-1,strategy:new Ext.ux.form.Spinner.NumberStrategy({minValue:-1,maxValue:99999,incrementValue:1})},{id:"max_upload_speed_per_torrent",fieldLabel:_("Max Up Speed"),width:60,value:-1,strategy:new Ext.ux.form.Spinner.NumberStrategy({minValue:-1,maxValue:99999,incrementValue:1})},{id:"max_connections_per_torrent",fieldLabel:_("Max Connections"),width:60,value:-1,strategy:new Ext.ux.form.Spinner.NumberStrategy({minValue:-1,maxValue:99999,incrementValue:1})},{id:"max_upload_slots_per_torrent",fieldLabel:_("Max Upload Slots"),colspan:2,width:60,value:-1,strategy:new Ext.ux.form.Spinner.NumberStrategy({minValue:-1,maxValue:99999,incrementValue:1})}]},{xtype:"fieldset",title:_("General"),autoHeight:true,border:false,labelWidth:10,defaultType:"checkbox",items:[{fieldLabel:"",labelSeparator:"",boxLabel:_("Add In Paused State"),id:"add_paused"},{fieldLabel:"",labelSeparator:"",boxLabel:_("Prioritize First/Last Piece"),id:"prioritize_first_last_pieces"},{xtype:"button",text:_("Apply to All"),style:"margin-left: 20px; margin-top: 5px;"},{xtype:"button",text:_("Revert to Defaults"),style:"margin-left: 20px; margin-top: 5px;"}]}]}],listeners:{render:{fn:Deluge.Add.onOptionsRender,scope:Deluge.Add}}})]}]});Deluge.Add.File={onAdd:function(){if(this.form.getForm().isValid()){this.form.getForm().submit({url:"/upload",waitMsg:_("Uploading your torrent..."),success:this.onUploadSuccess.bindWithEvent(this)})}},onUploadSuccess:function(c,b){this.Window.hide();var a=b.result.toString();this.form.items.get("torrentFile").setValue("");Deluge.Client.web.get_torrent_info(a,{onSuccess:Deluge.Add.onTorrentAdded.bindWithEvent(Deluge.Add,a)})}};Deluge.Add.File.form=new Ext.form.FormPanel({fileUpload:true,id:"fileAddForm",baseCls:"x-plain",labelWidth:55,autoHeight:true,items:[{xtype:"fileuploadfield",id:"torrentFile",emptyText:_("Select a torrent"),fieldLabel:_("File"),name:"file",buttonCfg:{text:_("Browse")+"..."}}]});Deluge.Add.File.Window=new Ext.Window({layout:"fit",width:350,height:115,bodyStyle:"padding: 10px 5px;",buttonAlign:"center",closeAction:"hide",modal:true,plain:true,title:_("Add from File"),iconCls:"x-deluge-add-file",items:Deluge.Add.File.form,buttons:[{text:_("Add"),handler:Deluge.Add.File.onAdd,scope:Deluge.Add.File}]});Deluge.Add.Url={onAdd:function(c,b){if(c.id=="url"&&b.getKey()!=b.ENTER){return}var c=this.form.items.get("url");var a=c.getValue();Deluge.Client.web.download_torrent_from_url(a,{onSuccess:this.onDownload.bindWithEvent(this)});this.Window.hide()},onDownload:function(a){this.form.items.get("url").setValue("");Deluge.Client.web.get_torrent_info(a,{onSuccess:Deluge.Add.onTorrentAdded.bindWithEvent(Deluge.Add,a)})}};Deluge.Add.Url.form=new Ext.form.FormPanel({defaultType:"textfield",id:"urlAddForm",baseCls:"x-plain",labelWidth:55,items:[{fieldLabel:_("Url"),id:"url",name:"url",inputType:"url",anchor:"100%",listeners:{specialkey:{fn:Deluge.Add.Url.onAdd,scope:Deluge.Add.Url}}}]});Deluge.Add.Url.Window=new Ext.Window({layout:"fit",width:350,height:115,bodyStyle:"padding: 10px 5px;",buttonAlign:"center",closeAction:"hide",modal:true,plain:true,title:_("Add from Url"),iconCls:"x-deluge-add-url-window-icon",items:Deluge.Add.Url.form,buttons:[{text:_("Add"),handler:Deluge.Add.Url.onAdd,scope:Deluge.Add.Url}]});Deluge.Add.Window=new Ext.Window({layout:"border",width:470,height:450,bodyStyle:"padding: 10px 5px;",buttonAlign:"right",closeAction:"hide",closable:true,plain:true,title:_("Add Torrents"),iconCls:"x-deluge-add-window-icon",items:[Deluge.Add.Grid,Deluge.Add.Options],buttons:[{text:_("Cancel"),handler:function(){Deluge.Add.clear();Deluge.Add.Window.hide()}},{text:_("Add"),handler:Deluge.Add.onAdd,scope:Deluge.Add}],listeners:{render:{fn:Deluge.Add.onRender,scope:Deluge.Add}}});(function(){PreferencesWindow=function(a){Ext.apply(this,a);this.layout="border";this.width=485;this.height=500;this.buttonAlign="right";this.closeAction="hide";this.closable=true;this.iconCls="x-deluge-preferences";this.plain=true;this.resizable=false;this.title=_("Preferences");this.buttons=[{text:_("Close"),handler:this.onCloseButtonClick,scope:this},{text:_("Apply")},{text:_("Ok")}];this.currentPage=false;this.items=[{xtype:"grid",region:"west",title:_("Categories"),store:new Ext.data.SimpleStore({fields:[{name:"name",mapping:0}]}),columns:[{id:"name",renderer:fplain,dataIndex:"name"}],sm:new Ext.grid.RowSelectionModel({singleSelect:true,listeners:{rowselect:{fn:this.onPageSelect,scope:this}}}),hideHeaders:true,autoExpandColumn:"name",deferredRender:false,autoScroll:true,margins:"5 0 5 5",cmargins:"5 0 5 5",width:120,collapsible:true},{region:"center",title:" ",layout:"fit",height:400,margins:"5 5 5 5",cmargins:"5 5 5 5"}];PreferencesWindow.superclass.constructor.call(this)};Ext.extend(PreferencesWindow,Ext.Window,{initComponent:function(){PreferencesWindow.superclass.initComponent.call(this);this.categoriesGrid=this.items.get(0);this.configPanel=this.items.get(1);this.pages={};this.on("show",this.onShow.bindWithEvent(this))},onCloseButtonClick:function(){this.hide()},addPage:function(b,c){var a=this.categoriesGrid.getStore();a.loadData([[b]],true);c.bodyStyle="margin: 5px";this.pages[b]=this.configPanel.add(c);this.pages[b].hide()},onPageSelect:function(a,d,c){if(this.currentPage){this.currentPage.hide()}var b=c.get("name");this.pages[b].show();this.configPanel.setTitle(b);this.currentPage=this.pages[b];this.configPanel.doLayout()},onShow:function(){if(!this.categoriesGrid.getSelectionModel().hasSelection()){this.categoriesGrid.getSelectionModel().selectFirstRow()}}});Deluge.Preferences=new PreferencesWindow();Deluge.Preferences.addPage(_("Downloads"),{border:false,xtype:"form",layout:"form",items:[{xtype:"fieldset",border:false,title:_("Folders"),labelWidth:140,defaultType:"textfield",autoHeight:true,items:[{name:"download_location",fieldLabel:_("Download to"),width:125},{name:"move_completed",fieldLabel:_("Move completed to"),width:125},{name:"copy_torrent_files",fieldLabel:_("Copy of .torrent files to"),width:125}]},{xtype:"fieldset",border:false,title:_("Allocation"),autoHeight:true,labelWidth:1,defaultType:"radio",items:[{name:"compact_allocation",labelSeparator:"",boxLabel:_("Compact")},{name:"compact_allocation",labelSeparator:"",boxLabel:_("Full")}]},{xtype:"fieldset",border:false,title:_("Options"),autoHeight:true,labelWidth:1,defaultType:"checkbox",items:[{name:"prioritize_first_last",labelSeparator:"",boxLabel:_("Prioritize first and last pieces of torrent")},{name:"add_paused",labelSeparator:"",boxLabel:_("Add torrents in Paused state")}]}]});Deluge.Preferences.addPage(_("Bandwidth"),{border:false,xtype:"form",layout:"form",labelWidth:10,items:[{xtype:"fieldset",border:false,title:_("Global Bandwidth Usage"),autoHeight:true,labelWidth:200,style:"margin-bottom: 0px; padding-bottom: 0px;",defaultType:"uxspinner",items:[{name:"max_connections",fieldLabel:_("Maximum Connections"),width:60,value:-1},{name:"max_upload_slots",fieldLabel:_("Maximum Upload Slots"),width:60,value:-1},{name:"max_download_speed",fieldLabel:_("Maximum Download Speed (KiB/s)"),width:60,value:-1},{name:"max_upload_speed",fieldLabel:_("Maximum Upload Speed (KiB/s)"),width:60,value:-1},{name:"max_half_open_connections",fieldLabel:_("Maximum Half-Open Connections"),width:60,value:-1},{name:"max_connections_per_second",fieldLabel:_("Maximum Connection Attempts per Second"),width:60,value:-1}]},{xtype:"fieldset",border:false,title:"",autoHeight:true,style:"padding-top: 0px; margin-top: 0px; margin-bottom: 0px;",items:[{xtype:"checkbox",name:"ignore_local",fieldLabel:"",labelSeparator:"",boxLabel:_("Ignore limits on local network"),value:-1},{xtype:"checkbox",name:"limit_ip_overhead",fieldLabel:"",labelSeparator:"",boxLabel:_("Rate limit IP overhead"),value:-1}]},{xtype:"fieldset",border:false,title:_("Per Torrent Bandwidth Usage"),autoHeight:true,labelWidth:200,defaultType:"uxspinner",items:[{name:"max_connections_per_torrent",fieldLabel:_("Maximum Connections"),width:60,value:-1},{name:"max_upload_slots_per_torrent",fieldLabel:_("Maximum Upload Slots"),width:60,value:-1},{name:"max_download_speed_per_torrent",fieldLabel:_("Maximum Download Speed (KiB/s)"),width:60,value:-1},{name:"max_upload_speed_per_torrent",fieldLabel:_("Maximum Upload Speed (KiB/s)"),width:60,value:-1}]}]});Deluge.Preferences.addPage(_("Interface"),{border:false,xtype:"form",layout:"form",items:[{xtype:"fieldset",border:false,title:_("Window"),autoHeight:true,labelWidth:1,items:[{xtype:"checkbox",fieldLabel:"",labelSeparator:"",boxLabel:_("Show session speed in titlebar"),id:"show_session_speed"}]},{xtype:"fieldset",border:false,title:_("Sidebar"),autoHeight:true,labelWidth:1,items:[{xtype:"checkbox",fieldLabel:"",labelSeparator:"",boxLabel:_("Hide filters with zero torrents"),id:"hide_sidebar_zero"}]},{xtype:"fieldset",border:false,title:_("Password"),autoHeight:true,defaultType:"textfield",items:[{fieldLabel:"New Password",inputType:"password",id:"new_password"},{inputType:"password",fieldLabel:"Confirm Password",id:"confirm_password"}]}]});Deluge.Preferences.addPage(_("Daemon"),{border:false,xtype:"form",layout:"form",items:[{xtype:"fieldset",border:false,title:_("Port"),autoHeight:true,defaultType:"uxspinner",items:[{fieldLabel:_("Daemon port"),id:"daemon_port"}]},{xtype:"fieldset",border:false,title:_("Connections"),autoHeight:true,labelWidth:1,defaultType:"checkbox",items:[{fieldLabel:"",labelSeparator:"",boxLabel:_("Allow Remote Connections"),id:"allow_remote"}]},{xtype:"fieldset",border:false,title:_("Other"),autoHeight:true,labelWidth:1,defaultType:"checkbox",items:[{fieldLabel:"",labelSeparator:"",height:40,boxLabel:_("Periodically check the website for new releases"),id:"new_releases"}]}]})})();Deluge.UI={initialize:function(){this.errorCount=0;Ext.state.Manager.setProvider(new Ext.state.CookieProvider());this.MainPanel=new Ext.Panel({id:"mainPanel",iconCls:"x-deluge-main-panel",title:"Deluge",layout:"border",tbar:Deluge.ToolBar.Bar,items:[Deluge.SideBar.Config,Deluge.Details.Panel,Deluge.Torrents],bbar:Deluge.StatusBar.Bar});this.Viewport=new Ext.Viewport({layout:"fit",items:[this.MainPanel]});Deluge.Login.show();Deluge.Events.on("connect",this.onConnect.bindWithEvent(this));Deluge.Events.on("disconnect",this.onDisconnect.bindWithEvent(this));Deluge.Client=new JSON.RPC("/json")},update:function(){var a=Deluge.SideBar.getFilters();Deluge.Client.web.update_ui(Deluge.Keys.Grid,a,{onSuccess:this.onUpdate.bindWithEvent(this),onFailure:this.onUpdateError.bindWithEvent(this)});Deluge.Details.update();Deluge.Client.web.connected({onSuccess:this.onConnectedCheck.bindWithEvent(this)})},onConnectedCheck:function(a){if(!a){Deluge.Events.fire("disconnect")}},onUpdateError:function(a){if(this.errorCount==2){Ext.MessageBox.show({title:"Lost Connection",msg:"The connection to the webserver has been lost!",buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.ERROR})}this.errorCount++},onUpdate:function(b){var a=new Array();$each(b.torrents,function(c,d){a.include([c.queue,c.name,c.total_size,c.state,c.progress,c.num_seeds,c.total_seeds,c.num_peers,c.total_peers,c.download_payload_rate,c.upload_payload_rate,c.eta,c.ratio,c.distributed_copies,c.time_added,c.tracker_host,d])});Deluge.Torrents.getStore().loadData(a);Deluge.StatusBar.update(b.stats);Deluge.SideBar.update(b.filters);this.errorCount=0},onConnect:function(){if(!this.running){this.running=this.update.periodical(2000,this);this.update()}},onDisconnect:function(){this.stop();this.notify("Disconnected","Deluge has disconnected from the daemon")},stop:function(){if(this.running){$clear(this.running);this.running=false;Deluge.Torrents.Store.loadData([])}}};document.addEvent("domready",function(a){Deluge.UI.initialize()}); \ No newline at end of file