X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.rcfilters%2Fui%2Fmw.rcfilters.ui.SavedLinksListItemWidget.js;h=b6b20eeb1aed32e2e412e3f7b018ba30d2a955bd;hb=68e16c26dd58afdf58a97f18f3cc76ed3b0ad9ee;hp=7ce9b6afff9dce61e550dc96e2af13130880472a;hpb=137c5993e1412ab5b12dfdd2223b206c06205fd8;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.SavedLinksListItemWidget.js b/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.SavedLinksListItemWidget.js index 7ce9b6afff..b6b20eeb1a 100644 --- a/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.SavedLinksListItemWidget.js +++ b/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.SavedLinksListItemWidget.js @@ -81,8 +81,11 @@ this.menu.connect( this, { choose: 'onMenuChoose' } ); - this.saveButton.connect( this, { click: 'onSaveButtonClick' } ); - this.editInput.connect( this, { enter: 'onEditInputEnter' } ); + this.saveButton.connect( this, { click: 'save' } ); + this.editInput.connect( this, { + change: 'onInputChange', + enter: 'save' + } ); this.editInput.$input.on( { blur: this.onInputBlur.bind( this ), keyup: this.onInputKeyup.bind( this ) @@ -204,22 +207,6 @@ this.menu.toggle( false ); }; - /** - * Respond to save button click - */ - mw.rcfilters.ui.SavedLinksListItemWidget.prototype.onSaveButtonClick = function () { - this.emit( 'edit', this.editInput.getValue() ); - this.toggleEdit( false ); - }; - - /** - * Respond to input enter event - */ - mw.rcfilters.ui.SavedLinksListItemWidget.prototype.onEditInputEnter = function () { - this.emit( 'edit', this.editInput.getValue() ); - this.toggleEdit( false ); - }; - /** * Respond to input keyup event, this is the way to intercept 'escape' key * @@ -239,10 +226,39 @@ * Respond to blur event on the input */ mw.rcfilters.ui.SavedLinksListItemWidget.prototype.onInputBlur = function () { - this.emit( 'edit', this.editInput.getValue() ); + this.save(); + + // Whether the save succeeded or not, the input-blur event + // means we need to cancel editing mode this.toggleEdit( false ); }; + /** + * Respond to input change event + * + * @param {string} value Input value + */ + mw.rcfilters.ui.SavedLinksListItemWidget.prototype.onInputChange = function ( value ) { + value = value.trim(); + + this.saveButton.setDisabled( !value ); + }; + + /** + * Save the name of the query + * + * @param {string} [value] The value to save + * @fires edit + */ + mw.rcfilters.ui.SavedLinksListItemWidget.prototype.save = function () { + var value = this.editInput.getValue().trim(); + + if ( value ) { + this.emit( 'edit', value ); + this.toggleEdit( false ); + } + }; + /** * Toggle edit mode on this widget *