2 * View model for a single saved query.
4 * @class mw.rcfilters.dm.SavedQueryItemModel
6 * @mixes OO.EventEmitter
8 * @param {string} id Unique identifier
9 * @param {string} label Saved query label
10 * @param {Object} data Saved query data
11 * @param {Object} [config] Configuration options
12 * @param {boolean} [config.default] This item is the default
14 const SavedQueryItemModel = function MwRcfiltersDmSavedQueriesModel( id, label, data, config ) {
15 config = config || {};
18 OO.EventEmitter.call( this );
23 this.default = !!config.default;
28 OO.initClass( SavedQueryItemModel );
29 OO.mixinClass( SavedQueryItemModel, OO.EventEmitter );
34 * Model has been updated.
43 * Get an object representing the state of this item
45 * @return {Object} Object representing the current data state
48 SavedQueryItemModel.prototype.getState = function () {
51 label: this.getLabel()
56 * Get the query's identifier
58 * @return {string} Query identifier
60 SavedQueryItemModel.prototype.getID = function () {
67 * @return {string} Query label
69 SavedQueryItemModel.prototype.getLabel = function () {
74 * Update the query label
76 * @param {string} newLabel New label
78 SavedQueryItemModel.prototype.updateLabel = function ( newLabel ) {
79 if ( newLabel && this.label !== newLabel ) {
80 this.label = newLabel;
81 this.emit( 'update' );
88 * @return {Object} Object representing parameter and highlight data
90 SavedQueryItemModel.prototype.getData = function () {
95 * Get the combined data of this item as a flat object of parameters
97 * @return {Object} Combined parameter data
99 SavedQueryItemModel.prototype.getCombinedData = function () {
100 return $.extend( true, {}, this.data.params, this.data.highlights );
104 * Check whether this item is the default
106 * @return {boolean} Query is set to be default
108 SavedQueryItemModel.prototype.isDefault = function () {
113 * Toggle the default state of this query item
115 * @param {boolean} isDefault Query is default
117 SavedQueryItemModel.prototype.toggleDefault = function ( isDefault ) {
118 isDefault = isDefault === undefined ? !this.default : isDefault;
120 if ( this.default !== isDefault ) {
121 this.default = isDefault;
122 this.emit( 'update' );
126 module.exports = SavedQueryItemModel;