Merge "RCFilters: Trim spaces in saved query names"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 30 Jun 2017 22:20:48 +0000 (22:20 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 30 Jun 2017 22:20:48 +0000 (22:20 +0000)
resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.SaveFiltersPopupButtonWidget.js
resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.SavedLinksListItemWidget.js

index 62f7aee..dfb188d 100644 (file)
         * @param {string} value Input value
         */
        mw.rcfilters.ui.SaveFiltersPopupButtonWidget.prototype.onInputChange = function ( value ) {
+               value = value.trim();
+
                this.applyButton.setDisabled( !value );
        };
 
         * Apply and add the new quick link
         */
        mw.rcfilters.ui.SaveFiltersPopupButtonWidget.prototype.apply = function () {
-               var label = this.input.getValue();
+               var label = this.input.getValue().trim();
 
                // This condition is more for sanity-check, since the
                // apply button should be disabled if the label is empty
index 7ce9b6a..b6b20ee 100644 (file)
                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 )
                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
         *
         * 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
         *