"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",
"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",
'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',
*
* @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;
};
/**
* 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();
};
.mw-rcfilters-ui-saveFiltersPopupButtonWidget {
&-popup {
- &-layout {
+ &-layout,
+ &-options {
padding-bottom: 1.5em;
}
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 );
-}
*/
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' ],
$( '<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(
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' );