c74648e8ebdf4f458ed835a33b4e95f3f4b8927a
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 * @cfg {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 * @return {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 * Get the combined data of this item as a flat object of parameters
97 * @return {Object} Combined parameter data
99 mw
.rcfilters
.dm
.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 mw
.rcfilters
.dm
.SavedQueryItemModel
.prototype.isDefault = function () {
113 * Toggle the default state of this query item
115 * @param {boolean} isDefault Query is default
117 mw
.rcfilters
.dm
.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' );