3 * View model for a single saved query
6 * @mixins OO.EventEmitter
9 * @param {string} id Unique identifier
10 * @param {string} label Saved query label
11 * @param {Object} data Saved query data
12 * @param {Object} [config] Configuration options
13 * @param {boolean} [default] This item is the default
15 mw
.rcfilters
.dm
.SavedQueryItemModel
= function MwRcfiltersDmSavedQueriesModel( id
, label
, data
, config
) {
16 config
= config
|| {};
19 OO
.EventEmitter
.call( this );
24 this.default = !!config
.default;
29 OO
.initClass( mw
.rcfilters
.dm
.SavedQueryItemModel
);
30 OO
.mixinClass( mw
.rcfilters
.dm
.SavedQueryItemModel
, OO
.EventEmitter
);
37 * Model has been updated
43 * Get an object representing the state of this item
45 * @returns {Object} Object representing the current data state
48 mw
.rcfilters
.dm
.SavedQueryItemModel
.prototype.getState = function () {
51 label
: this.getLabel()
56 * Get the query's identifier
58 * @return {string} Query identifier
60 mw
.rcfilters
.dm
.SavedQueryItemModel
.prototype.getID = function () {
67 * @return {string} Query label
69 mw
.rcfilters
.dm
.SavedQueryItemModel
.prototype.getLabel = function () {
74 * Update the query label
76 * @param {string} newLabel New label
78 mw
.rcfilters
.dm
.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 mw
.rcfilters
.dm
.SavedQueryItemModel
.prototype.getData = function () {
95 * Check whether this item is the default
97 * @return {boolean} Query is set to be default
99 mw
.rcfilters
.dm
.SavedQueryItemModel
.prototype.isDefault = function () {
104 * Toggle the default state of this query item
106 * @param {boolean} isDefault Query is default
108 mw
.rcfilters
.dm
.SavedQueryItemModel
.prototype.toggleDefault = function ( isDefault
) {
109 isDefault
= isDefault
=== undefined ? !this.default : isDefault
;
111 if ( this.default !== isDefault
) {
112 this.default = isDefault
;
113 this.emit( 'update' );