RCFilters: Allow setting a new query as default
authorStephane Bisson <sbisson@wikimedia.org>
Fri, 28 Jul 2017 19:47:48 +0000 (15:47 -0400)
committerStephane Bisson <sbisson@wikimedia.org>
Fri, 28 Jul 2017 20:55:37 +0000 (16:55 -0400)
When creating a new saved query, there's a checkbox
to set it as default as the same time.

Bug: T171922
Change-Id: Id6da0e79c54bc65d76636bbff64b2ece568c0cd4

languages/i18n/en.json
languages/i18n/qqq.json
resources/Resources.php
resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.SavedQueriesModel.js
resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js
resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.SaveFiltersPopupButtonWidget.less
resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.less
resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.SaveFiltersPopupButtonWidget.js

index 2f09573..b18fa0b 100644 (file)
        "rcfilters-savedqueries-new-name-label": "Name",
        "rcfilters-savedqueries-new-name-placeholder": "Describe the purpose of the filter",
        "rcfilters-savedqueries-apply-label": "Create filter",
+       "rcfilters-savedqueries-apply-and-setdefault-label": "Create default filter",
        "rcfilters-savedqueries-cancel-label": "Cancel",
        "rcfilters-savedqueries-add-new-title": "Save current filter settings",
        "rcfilters-restore-default-filters": "Restore default filters",
index c0d6ad5..5609f75 100644 (file)
        "rcfilters-savedqueries-new-name-label": "Label for the input that holds the name of the new saved filters in [[Special:RecentChanges]]\n{{Identical|Name}}",
        "rcfilters-savedqueries-new-name-placeholder": "Placeholder for the input that holds the name of the new saved filters in [[Special:RecentChanges]]",
        "rcfilters-savedqueries-apply-label": "Label for the button to apply saving a new filter setting in [[Special:RecentChanges]]. This is for a small popup, please try to use a short string.",
+       "rcfilters-savedqueries-apply-and-setdefault-label": "Label for the button to apply saving a new filter setting and set it as default in [[Special:RecentChanges]]. This is for a small popup, please try to use a short string.",
        "rcfilters-savedqueries-cancel-label": "Label for the button to cancel the saving of a new quick link in [[Special:RecentChanges]]\n{{Identical|Cancel}}",
        "rcfilters-savedqueries-add-new-title": "Title for the popup to add new quick link in [[Special:RecentChanges]]. This is for a small popup, please try to use a short string.",
        "rcfilters-restore-default-filters": "Label for the button that resets filters to defaults",
index 64ecc96..cc282e3 100644 (file)
@@ -1853,6 +1853,7 @@ return [
                        'rcfilters-savedqueries-new-name-placeholder',
                        'rcfilters-savedqueries-add-new-title',
                        'rcfilters-savedqueries-apply-label',
+                       'rcfilters-savedqueries-apply-and-setdefault-label',
                        'rcfilters-savedqueries-cancel-label',
                        'rcfilters-restore-default-filters',
                        'rcfilters-clear-all-filters',
index 29134a5..d6dda1e 100644 (file)
         *
         * @param {string} label Label for the new query
         * @param {Object} data Data for the new query
+        * @return {string} ID of the newly added query
         */
        mw.rcfilters.dm.SavedQueriesModel.prototype.addNewQuery = function ( label, data ) {
                var randomID = ( new Date() ).getTime(),
                                normalizedData
                        )
                ] );
+
+               return randomID;
        };
 
        /**
index 2563479..8cee0a8 100644 (file)
         * Save the current model state as a saved query
         *
         * @param {string} [label] Label of the saved query
+        * @param {boolean} [setAsDefault=false] This query should be set as the default
         */
-       mw.rcfilters.Controller.prototype.saveCurrentQuery = function ( label ) {
-               var highlightedItems = {},
+       mw.rcfilters.Controller.prototype.saveCurrentQuery = function ( label, setAsDefault ) {
+               var queryID,
+                       highlightedItems = {},
                        highlightEnabled = this.filtersModel.isHighlightEnabled();
 
                // Prepare highlights
                highlightedItems.highlight = this.filtersModel.isHighlightEnabled();
 
                // Add item
-               this.savedQueriesModel.addNewQuery(
+               queryID = this.savedQueriesModel.addNewQuery(
                        label || mw.msg( 'rcfilters-savedqueries-defaultlabel' ),
                        {
                                filters: this.filtersModel.getSelectedState(),
                        }
                );
 
+               if ( setAsDefault ) {
+                       this.savedQueriesModel.setDefault( queryID );
+               }
+
                // Save item
                this._saveSavedQueries();
        };
index 272909d..ec4954c 100644 (file)
@@ -1,6 +1,7 @@
 .mw-rcfilters-ui-saveFiltersPopupButtonWidget {
        &-popup {
-               &-layout {
+               &-layout,
+               &-options {
                        padding-bottom: 1.5em;
                }
 
index c0f24c6..0bee2f1 100644 (file)
                vertical-align: top;
        }
 }
-
-// Temporary icon classes, until these icons
-// are merged into OOUI properly
-.oo-ui-iconElement-icon.oo-ui-icon-clip {
-       /* @embed */
-       background-image: url( ../images/clip.svg );
-}
-
-.oo-ui-iconElement-icon.oo-ui-icon-unClip {
-       /* @embed */
-       background-image: url( ../images/unClip.svg );
-}
-
-.oo-ui-iconElement-icon.oo-ui-icon-pushPin {
-       /* @embed */
-       background-image: url( ../images/pushPin.svg );
-}
index dfb188d..70a2227 100644 (file)
@@ -14,6 +14,7 @@
         */
        mw.rcfilters.ui.SaveFiltersPopupButtonWidget = function MwRcfiltersUiSaveFiltersPopupButtonWidget( controller, model, config ) {
                var layout,
+                       checkBoxLayout,
                        $popupContent = $( '<div>' );
 
                config = config || {};
                        align: 'top'
                } );
 
+               this.setAsDefaultCheckbox = new OO.ui.CheckboxInputWidget();
+               checkBoxLayout = new OO.ui.FieldLayout( this.setAsDefaultCheckbox, {
+                       label: mw.msg( 'rcfilters-savedqueries-setdefault' ),
+                       align: 'inline'
+               } );
+
                this.applyButton = new OO.ui.ButtonWidget( {
                        label: mw.msg( 'rcfilters-savedqueries-apply-label' ),
                        classes: [ 'mw-rcfilters-ui-saveFiltersPopupButtonWidget-popup-buttons-apply' ],
@@ -61,6 +68,9 @@
                                $( '<div>' )
                                        .addClass( 'mw-rcfilters-ui-saveFiltersPopupButtonWidget-popup-layout' )
                                        .append( layout.$element ),
+                               $( '<div>' )
+                                       .addClass( 'mw-rcfilters-ui-saveFiltersPopupButtonWidget-popup-options' )
+                                       .append( checkBoxLayout.$element ),
                                $( '<div>' )
                                        .addClass( 'mw-rcfilters-ui-saveFiltersPopupButtonWidget-popup-buttons' )
                                        .append(
@@ -80,6 +90,7 @@
                this.input.$input.on( {
                        keyup: this.onInputKeyup.bind( this )
                } );
+               this.setAsDefaultCheckbox.connect( this, { change: 'onSetAsDefaultChange' } );
                this.cancelButton.connect( this, { click: 'onCancelButtonClick' } );
                this.applyButton.connect( this, { click: 'onApplyButtonClick' } );
 
                this.input.focus();
        };
 
+       /**
+        * Respond to "set as default" checkbox change
+        * @param {boolean} checked State of the checkbox
+        */
+       mw.rcfilters.ui.SaveFiltersPopupButtonWidget.prototype.onSetAsDefaultChange = function ( checked ) {
+               var messageKey = checked ?
+                       'rcfilters-savedqueries-apply-and-setdefault-label' :
+                       'rcfilters-savedqueries-apply-label';
+
+               this.applyButton
+                       .setIcon( checked ? 'pushPin' : null )
+                       .setLabel( mw.msg( messageKey ) );
+       };
+
        /**
         * Respond to cancel button click event
         */
                // This condition is more for sanity-check, since the
                // apply button should be disabled if the label is empty
                if ( label ) {
-                       this.controller.saveCurrentQuery( label );
+                       this.controller.saveCurrentQuery( label, this.setAsDefaultCheckbox.isSelected() );
                        this.input.setValue( '' );
+                       this.setAsDefaultCheckbox.setSelected( false );
                        this.popup.toggle( false );
 
                        this.emit( 'saveCurrent' );