From 0e94c31ca2c93273bb908b51d083e57c03878c14 Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Sat, 21 Mar 2009 11:15:17 +0000 Subject: [PATCH] turn the port field into a spinner --- deluge/ui/web/css/Spinner.css | 54 +++++ deluge/ui/web/images/LICENSE | 15 +- deluge/ui/web/images/spinner-split.gif | Bin 0 -> 49 bytes deluge/ui/web/images/spinner.gif | Bin 0 -> 3186 bytes deluge/ui/web/index.html | 4 + deluge/ui/web/js/Spinner.js | 302 +++++++++++++++++++++++++ deluge/ui/web/js/SpinnerStrategy.js | 172 ++++++++++++++ deluge/ui/web/js/deluge-connections.js | 37 ++- 8 files changed, 560 insertions(+), 24 deletions(-) create mode 100644 deluge/ui/web/css/Spinner.css create mode 100644 deluge/ui/web/images/spinner-split.gif create mode 100644 deluge/ui/web/images/spinner.gif create mode 100644 deluge/ui/web/js/Spinner.js create mode 100644 deluge/ui/web/js/SpinnerStrategy.js diff --git a/deluge/ui/web/css/Spinner.css b/deluge/ui/web/css/Spinner.css new file mode 100644 index 000000000..1f32c1887 --- /dev/null +++ b/deluge/ui/web/css/Spinner.css @@ -0,0 +1,54 @@ +.x-form-spinner-proxy{ + /*background-color:#ff00cc;*/ +} +.x-form-field-wrap .x-form-spinner-trigger { + background: transparent url(/images/spinner.gif) no-repeat 0 0; +} + +.x-form-field-wrap .x-form-spinner-overup{ + background-position:-17px 0; +} +.x-form-field-wrap .x-form-spinner-clickup{ + background-position:-34px 0; +} +.x-form-field-wrap .x-form-spinner-overdown{ + background-position:-51px 0; +} +.x-form-field-wrap .x-form-spinner-clickdown{ + background-position:-68px 0; +} + + +.x-trigger-wrap-focus .x-form-spinner-trigger{ + background-position:-85px 0; +} +.x-trigger-wrap-focus .x-form-spinner-overup{ + background-position:-102px 0; +} +.x-trigger-wrap-focus .x-form-spinner-clickup{ + background-position:-119px 0; +} +.x-trigger-wrap-focus .x-form-spinner-overdown{ + background-position:-136px 0; +} +.x-trigger-wrap-focus .x-form-spinner-clickdown{ + background-position:-153px 0; +} +.x-trigger-wrap-focus .x-form-trigger{ + border-bottom: 1px solid #7eadd9; +} + +.x-form-field-wrap .x-form-spinner-splitter { + line-height:1px; + font-size:1px; + background:transparent url(/images/spinner-split.gif) no-repeat 0 0; + position:absolute; + cursor: n-resize; +} +.x-trigger-wrap-focus .x-form-spinner-splitter{ + background-position:-14px 0; +} + +.x-form-uxspinner .x-form-field-wrap { + height: 24px; +} \ No newline at end of file diff --git a/deluge/ui/web/images/LICENSE b/deluge/ui/web/images/LICENSE index c6cd56804..6b7f3f660 100644 --- a/deluge/ui/web/images/LICENSE +++ b/deluge/ui/web/images/LICENSE @@ -1,14 +1 @@ -icons in this folder are copied from the kde oxygen set - -http://www.oxygen-icons.org/?page_id=4 - -LICENCE: -Oxygen icon theme is dual licensed. -You may copy it under the Creative Common Attribution-ShareAlike 3.0 License -or the GNU Library General Public License. - -ICONS NOT UNDER THIS LICENCE: -*none yet -*add them here if needed. - - +The spinner.gif and spinner-split.gif are part of the Spinner plugin for Extjs, under the BSD license. diff --git a/deluge/ui/web/images/spinner-split.gif b/deluge/ui/web/images/spinner-split.gif new file mode 100644 index 0000000000000000000000000000000000000000..72811461bb31f3b7b04ca7f9a383b55ad799b9e5 GIT binary patch literal 49 zcmZ?wbhEHblwn|En8?5|>)8J_D`x)x|DS<@K?jH#K;jHcTvPg2O27TzFlUMwgEatx C0}smp literal 0 HcmV?d00001 diff --git a/deluge/ui/web/images/spinner.gif b/deluge/ui/web/images/spinner.gif new file mode 100644 index 0000000000000000000000000000000000000000..4e72f53d09fe7b105bf33fe75b61370e034e60d8 GIT binary patch literal 3186 zcmV-&42|Rwu<@f*A>HpT&*1XW^@%Q?+)#f!* zjrsikyx8c@;P=$j)ad#D&ENFk^#8!p>FxXfu+Zf6^z^{g>$TP9`u_hlRE_-p|JCF1 z`~3dp@%i!b@wUt4w8`S#-QE2C{@U8w^Y{Dz|NqnB>h|{b{QUgM-S*Ss^6>ER?(XjQ z_xI}h|MmI$(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YfvSH%WH8;0% z&O@`)3-VyQ)~hWSIm@3Na(>s@&i>wWZC^}s3Yc8bCrbIs(Y=a^Z@kGJ_qeZV?sC_b z{NzC|x5`%z^LN)A<~QGVsCUkDpF^G8GnhIW_dxct2cQKCXh8tVzK1EYo$O~%``XLy z_P57f?QH)z%m+XM1vFiYc?f(SZeZ;H;gtIZfp_-a`~LTtdzJ5gkN3-A{&>bqKI?WK zumS-7V!;o-@V7a9;tNf5yQ3ZNd0%?vBhPQI0zUABM}XmHfcVi<-Vcy(dcU{5d9HUJ z_Mq2;=tuu{xKm;7bgx74_Yi>NzrF5ucYf+`4_YM*;P$TwQwT<%vtiku$2R;J0PkX_io9KTie)Ex^{M&<7{p;s>+t+>G=Xn2De(Q&G zi1mI7_|dal<8o(FtzP=EF}eqQx~;zxZc z2!fMGeJYrM4d`DD7=I*af}@Aef2pv69LRz(7=Qve10@)Nwg-bQxO;Xc05fQVgg1mE zICjgod=?mm$w!4f$bu|rgRqwXL|A}Wn1v{ah3EH$Avl9(sD*>ag-=L&=w^i(NQUA! zf@#==UI>R+$9`sLXIgjzYPg1On0kL$g@M?19Y}^~D2GL8hc9S{V`zwYn1>FCh-;{W zs4$3xsE8pbiHP`pjtGegc!- + + + + diff --git a/deluge/ui/web/js/Spinner.js b/deluge/ui/web/js/Spinner.js new file mode 100644 index 000000000..9568d1ae9 --- /dev/null +++ b/deluge/ui/web/js/Spinner.js @@ -0,0 +1,302 @@ +/** + * Copyright (c) 2008, Steven Chim + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * * The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * Ext.ux.form.Spinner Class + * + * @author Steven Chim + * @version Spinner.js 2008-08-27 v0.35 + * + * @class Ext.ux.form.Spinner + * @extends Ext.form.TriggerField + */ + +Ext.namespace("Ext.ux.form"); + +Ext.ux.form.Spinner = function(config){ + Ext.ux.form.Spinner.superclass.constructor.call(this, config); + this.addEvents({ + 'spin' : true, + 'spinup' : true, + 'spindown' : true + }); +} + +Ext.extend(Ext.ux.form.Spinner, Ext.form.TriggerField, { + triggerClass : 'x-form-spinner-trigger', + splitterClass : 'x-form-spinner-splitter', + + alternateKey : Ext.EventObject.shiftKey, + strategy : undefined, + + //private + onRender : function(ct, position){ + Ext.ux.form.Spinner.superclass.onRender.call(this, ct, position); + + this.splitter = this.wrap.createChild({tag:'div', cls:this.splitterClass, style:'width:13px; height:2px;'}); + this.splitter.show().setRight( (Ext.isIE) ? 1 : 2 ); + this.splitter.show().setTop(10); + + this.proxy = this.trigger.createProxy('', this.splitter, true); + this.proxy.addClass("x-form-spinner-proxy"); + this.proxy.setStyle('left','0px'); + this.proxy.setSize(14, 1); + this.proxy.hide(); + this.dd = new Ext.dd.DDProxy(this.splitter.dom.id, "SpinnerDrag", {dragElId: this.proxy.id}); + + this.initSpinner(); + }, + + //private + initTrigger : function(){ + this.trigger.addClassOnOver('x-form-trigger-over'); + this.trigger.addClassOnClick('x-form-trigger-click'); + }, + + //private + initSpinner : function(){ + this.keyNav = new Ext.KeyNav(this.el, { + "up" : function(e){ + e.preventDefault(); + this.onSpinUp(); + }, + + "down" : function(e){ + e.preventDefault(); + this.onSpinDown(); + }, + + "pageUp" : function(e){ + e.preventDefault(); + this.onSpinUpAlternate(); + }, + + "pageDown" : function(e){ + e.preventDefault(); + this.onSpinDownAlternate(); + }, + + scope : this + }); + + this.repeater = new Ext.util.ClickRepeater(this.trigger); + this.repeater.on("click", this.onTriggerClick, this, {preventDefault:true}); + this.trigger.on("mouseover", this.onMouseOver, this, {preventDefault:true}); + this.trigger.on("mouseout", this.onMouseOut, this, {preventDefault:true}); + this.trigger.on("mousemove", this.onMouseMove, this, {preventDefault:true}); + this.trigger.on("mousedown", this.onMouseDown, this, {preventDefault:true}); + this.trigger.on("mouseup", this.onMouseUp, this, {preventDefault:true}); + this.wrap.on("mousewheel", this.handleMouseWheel, this); + + this.dd.setXConstraint(0, 0, 10) + this.dd.setYConstraint(1500, 1500, 10); + this.dd.endDrag = this.endDrag.createDelegate(this); + this.dd.startDrag = this.startDrag.createDelegate(this); + this.dd.onDrag = this.onDrag.createDelegate(this); + + /* + jsakalos suggestion + http://extjs.com/forum/showthread.php?p=121850#post121850 */ + if('object' == typeof this.strategy && this.strategy.xtype) { + switch(this.strategy.xtype) { + case 'number': + this.strategy = new Ext.ux.form.Spinner.NumberStrategy(this.strategy); + break; + + case 'date': + this.strategy = new Ext.ux.form.Spinner.DateStrategy(this.strategy); + break; + + case 'time': + this.strategy = new Ext.ux.form.Spinner.TimeStrategy(this.strategy); + break; + + default: + delete(this.strategy); + break; + } + delete(this.strategy.xtype); + } + + if(this.strategy == undefined){ + this.strategy = new Ext.ux.form.Spinner.NumberStrategy(); + } + }, + + //private + onMouseOver : function(){ + if(this.disabled){ + return; + } + var middle = this.getMiddle(); + this.__tmphcls = (Ext.EventObject.getPageY() < middle) ? 'x-form-spinner-overup' : 'x-form-spinner-overdown'; + this.trigger.addClass(this.__tmphcls); + }, + + //private + onMouseOut : function(){ + this.trigger.removeClass(this.__tmphcls); + }, + + //private + onMouseMove : function(){ + if(this.disabled){ + return; + } + var middle = this.getMiddle(); + if( ((Ext.EventObject.getPageY() > middle) && this.__tmphcls == "x-form-spinner-overup") || + ((Ext.EventObject.getPageY() < middle) && this.__tmphcls == "x-form-spinner-overdown")){ + } + }, + + //private + onMouseDown : function(){ + if(this.disabled){ + return; + } + var middle = this.getMiddle(); + this.__tmpccls = (Ext.EventObject.getPageY() < middle) ? 'x-form-spinner-clickup' : 'x-form-spinner-clickdown'; + this.trigger.addClass(this.__tmpccls); + }, + + //private + onMouseUp : function(){ + this.trigger.removeClass(this.__tmpccls); + }, + + //private + onTriggerClick : function(){ + if(this.disabled || this.getEl().dom.readOnly){ + return; + } + var middle = this.getMiddle(); + var ud = (Ext.EventObject.getPageY() < middle) ? 'Up' : 'Down'; + this['onSpin'+ud](); + }, + + //private + getMiddle : function(){ + var t = this.trigger.getTop(); + var h = this.trigger.getHeight(); + var middle = t + (h/2); + return middle; + }, + + //private + //checks if control is allowed to spin + isSpinnable : function(){ + if(this.disabled || this.getEl().dom.readOnly){ + Ext.EventObject.preventDefault(); //prevent scrolling when disabled/readonly + return false; + } + return true; + }, + + handleMouseWheel : function(e){ + //disable scrolling when not focused + if(this.wrap.hasClass('x-trigger-wrap-focus') == false){ + return; + } + + var delta = e.getWheelDelta(); + if(delta > 0){ + this.onSpinUp(); + e.stopEvent(); + } else if(delta < 0){ + this.onSpinDown(); + e.stopEvent(); + } + }, + + //private + startDrag : function(){ + this.proxy.show(); + this._previousY = Ext.fly(this.dd.getDragEl()).getTop(); + }, + + //private + endDrag : function(){ + this.proxy.hide(); + }, + + //private + onDrag : function(){ + if(this.disabled){ + return; + } + var y = Ext.fly(this.dd.getDragEl()).getTop(); + var ud = ''; + + if(this._previousY > y){ud = 'Up';} //up + if(this._previousY < y){ud = 'Down';} //down + + if(ud != ''){ + this['onSpin'+ud](); + } + + this._previousY = y; + }, + + //private + onSpinUp : function(){ + if(this.isSpinnable() == false) { + return; + } + if(Ext.EventObject.shiftKey == true){ + this.onSpinUpAlternate(); + return; + }else{ + this.strategy.onSpinUp(this); + } + this.fireEvent("spin", this); + this.fireEvent("spinup", this); + }, + + //private + onSpinDown : function(){ + if(this.isSpinnable() == false) { + return; + } + if(Ext.EventObject.shiftKey == true){ + this.onSpinDownAlternate(); + return; + }else{ + this.strategy.onSpinDown(this); + } + this.fireEvent("spin", this); + this.fireEvent("spindown", this); + }, + + //private + onSpinUpAlternate : function(){ + if(this.isSpinnable() == false) { + return; + } + this.strategy.onSpinUpAlternate(this); + this.fireEvent("spin", this); + this.fireEvent("spinup", this); + }, + + //private + onSpinDownAlternate : function(){ + if(this.isSpinnable() == false) { + return; + } + this.strategy.onSpinDownAlternate(this); + this.fireEvent("spin", this); + this.fireEvent("spindown", this); + } + +}); + +Ext.reg('uxspinner', Ext.ux.form.Spinner); diff --git a/deluge/ui/web/js/SpinnerStrategy.js b/deluge/ui/web/js/SpinnerStrategy.js new file mode 100644 index 000000000..ad0e5a81c --- /dev/null +++ b/deluge/ui/web/js/SpinnerStrategy.js @@ -0,0 +1,172 @@ +/** + * Copyright (c) 2008, Steven Chim + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * * The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/*** + * Abstract Strategy + */ +Ext.ux.form.Spinner.Strategy = function(config){ + Ext.apply(this, config); +}; + +Ext.extend(Ext.ux.form.Spinner.Strategy, Ext.util.Observable, { + defaultValue : 0, + minValue : undefined, + maxValue : undefined, + incrementValue : 1, + alternateIncrementValue : 5, + validationTask : new Ext.util.DelayedTask(), + + onSpinUp : function(field){ + this.spin(field, false, false); + }, + + onSpinDown : function(field){ + this.spin(field, true, false); + }, + + onSpinUpAlternate : function(field){ + this.spin(field, false, true); + }, + + onSpinDownAlternate : function(field){ + this.spin(field, true, true); + }, + + spin : function(field, down, alternate){ + this.validationTask.delay(500, function(){field.validate()}); + //extend + }, + + fixBoundries : function(value){ + return value; + //overwrite + } + +}); + +/*** + * Concrete Strategy: Numbers + */ +Ext.ux.form.Spinner.NumberStrategy = function(config){ + Ext.ux.form.Spinner.NumberStrategy.superclass.constructor.call(this, config); +}; + +Ext.extend(Ext.ux.form.Spinner.NumberStrategy, Ext.ux.form.Spinner.Strategy, { + + allowDecimals : true, + decimalPrecision : 2, + + spin : function(field, down, alternate){ + Ext.ux.form.Spinner.NumberStrategy.superclass.spin.call(this, field, down, alternate); + + var v = parseFloat(field.getValue()); + var incr = (alternate == true) ? this.alternateIncrementValue : this.incrementValue; + + (down == true) ? v -= incr : v += incr ; + v = (isNaN(v)) ? this.defaultValue : v; + v = this.fixBoundries(v); + field.setRawValue(v); + }, + + fixBoundries : function(value){ + var v = value; + + if(this.minValue != undefined && v < this.minValue){ + v = this.minValue; + } + if(this.maxValue != undefined && v > this.maxValue){ + v = this.maxValue; + } + + return this.fixPrecision(v); + }, + + // private + fixPrecision : function(value){ + var nan = isNaN(value); + if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){ + return nan ? '' : value; + } + return parseFloat(parseFloat(value).toFixed(this.decimalPrecision)); + } +}); + + +/*** + * Concrete Strategy: Date + */ +Ext.ux.form.Spinner.DateStrategy = function(config){ + Ext.ux.form.Spinner.DateStrategy.superclass.constructor.call(this, config); +}; + +Ext.extend(Ext.ux.form.Spinner.DateStrategy, Ext.ux.form.Spinner.Strategy, { + defaultValue : new Date(), + format : "Y-m-d", + incrementValue : 1, + incrementConstant : Date.DAY, + alternateIncrementValue : 1, + alternateIncrementConstant : Date.MONTH, + + spin : function(field, down, alternate){ + Ext.ux.form.Spinner.DateStrategy.superclass.spin.call(this); + + var v = field.getRawValue(); + + v = Date.parseDate(v, this.format); + var dir = (down == true) ? -1 : 1 ; + var incr = (alternate == true) ? this.alternateIncrementValue : this.incrementValue; + var dtconst = (alternate == true) ? this.alternateIncrementConstant : this.incrementConstant; + + if(typeof this.defaultValue == 'string'){ + this.defaultValue = Date.parseDate(this.defaultValue, this.format); + } + + v = (v) ? v.add(dtconst, dir*incr) : this.defaultValue; + + v = this.fixBoundries(v); + field.setRawValue(Ext.util.Format.date(v,this.format)); + }, + + //private + fixBoundries : function(date){ + var dt = date; + var min = (typeof this.minValue == 'string') ? Date.parseDate(this.minValue, this.format) : this.minValue ; + var max = (typeof this.maxValue == 'string') ? Date.parseDate(this.maxValue, this.format) : this.maxValue ; + + if(this.minValue != undefined && dt < min){ + dt = min; + } + if(this.maxValue != undefined && dt > max){ + dt = max; + } + + return dt; + } + +}); + + +/*** + * Concrete Strategy: Time + */ +Ext.ux.form.Spinner.TimeStrategy = function(config){ + Ext.ux.form.Spinner.TimeStrategy.superclass.constructor.call(this, config); +}; + +Ext.extend(Ext.ux.form.Spinner.TimeStrategy, Ext.ux.form.Spinner.DateStrategy, { + format : "H:i", + incrementValue : 1, + incrementConstant : Date.MINUTE, + alternateIncrementValue : 1, + alternateIncrementConstant : Date.HOUR +}); diff --git a/deluge/ui/web/js/deluge-connections.js b/deluge/ui/web/js/deluge-connections.js index 28ffd4168..830b943ae 100644 --- a/deluge/ui/web/js/deluge-connections.js +++ b/deluge/ui/web/js/deluge-connections.js @@ -73,6 +73,15 @@ Deluge.Connections = { }); }, + onAddWindowHide: function() { + // Tidy up the form to ensure all the values are default. + var form = Deluge.Connections.Add.items.first(); + form.items.get('host').reset(); + form.items.get('port').reset(); + form.items.get('username').reset(); + form.items.get('password').reset(); + }, + onClose: function(e) { $clear(Deluge.Connections.running); Deluge.Connections.Window.hide(); @@ -213,7 +222,7 @@ Deluge.Connections.Grid = new Ext.grid.GridPanel({ Deluge.Connections.Add = new Ext.Window({ layout: 'fit', width: 300, - height: 220, + height: 195, bodyStyle: 'padding: 10px 5px;', buttonAlign: 'right', closeAction: 'hide', @@ -235,11 +244,14 @@ Deluge.Connections.Add = new Ext.Window({ },{ fieldLabel: _('Port'), id: 'port', + xtype: 'uxspinner', + ctCls: 'x-form-uxspinner', name: 'port', + strategy: Ext.ux.form.Spinner.NumberStrategy(), value: '58846', - anchor: '100%', + anchor: '50%', listeners: {} - },{ + }, { fieldLabel: _('Username'), id: 'username', name: 'username', @@ -247,25 +259,30 @@ Deluge.Connections.Add = new Ext.Window({ listeners: {} },{ fieldLabel: _('Password'), - id: 'password', - name: 'password', - inputType: 'password', anchor: '100%', - listeners: {} + id: '_password', + name: '_password', + inputType: 'password' }] })], buttons: [{ - text: _('Close') + 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: 200, + height: 220, bodyStyle: 'padding: 10px 5px;', buttonAlign: 'right', closeAction: 'hide',