build: Bump eslint-config-wikimedia from 0.4.0 to 0.5.0
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / dm / mw.rcfilters.dm.SavedQueryItemModel.js
1 ( function ( mw ) {
2 /**
3 * View model for a single saved query
4 *
5 * @class
6 * @mixins OO.EventEmitter
7 *
8 * @constructor
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
14 */
15 mw.rcfilters.dm.SavedQueryItemModel = function MwRcfiltersDmSavedQueriesModel( id, label, data, config ) {
16 config = config || {};
17
18 // Mixin constructor
19 OO.EventEmitter.call( this );
20
21 this.id = id;
22 this.label = label;
23 this.data = data;
24 this.default = !!config.default;
25 };
26
27 /* Initialization */
28
29 OO.initClass( mw.rcfilters.dm.SavedQueryItemModel );
30 OO.mixinClass( mw.rcfilters.dm.SavedQueryItemModel, OO.EventEmitter );
31
32 /* Events */
33
34 /**
35 * @event update
36 *
37 * Model has been updated
38 */
39
40 /* Methods */
41
42 /**
43 * Get an object representing the state of this item
44 *
45 * @return {Object} Object representing the current data state
46 * of the object
47 */
48 mw.rcfilters.dm.SavedQueryItemModel.prototype.getState = function () {
49 return {
50 data: this.getData(),
51 label: this.getLabel()
52 };
53 };
54
55 /**
56 * Get the query's identifier
57 *
58 * @return {string} Query identifier
59 */
60 mw.rcfilters.dm.SavedQueryItemModel.prototype.getID = function () {
61 return this.id;
62 };
63
64 /**
65 * Get query label
66 *
67 * @return {string} Query label
68 */
69 mw.rcfilters.dm.SavedQueryItemModel.prototype.getLabel = function () {
70 return this.label;
71 };
72
73 /**
74 * Update the query label
75 *
76 * @param {string} newLabel New label
77 */
78 mw.rcfilters.dm.SavedQueryItemModel.prototype.updateLabel = function ( newLabel ) {
79 if ( newLabel && this.label !== newLabel ) {
80 this.label = newLabel;
81 this.emit( 'update' );
82 }
83 };
84
85 /**
86 * Get query data
87 *
88 * @return {Object} Object representing parameter and highlight data
89 */
90 mw.rcfilters.dm.SavedQueryItemModel.prototype.getData = function () {
91 return this.data;
92 };
93
94 /**
95 * Check whether this item is the default
96 *
97 * @return {boolean} Query is set to be default
98 */
99 mw.rcfilters.dm.SavedQueryItemModel.prototype.isDefault = function () {
100 return this.default;
101 };
102
103 /**
104 * Toggle the default state of this query item
105 *
106 * @param {boolean} isDefault Query is default
107 */
108 mw.rcfilters.dm.SavedQueryItemModel.prototype.toggleDefault = function ( isDefault ) {
109 isDefault = isDefault === undefined ? !this.default : isDefault;
110
111 if ( this.default !== isDefault ) {
112 this.default = isDefault;
113 this.emit( 'update' );
114 }
115 };
116 }( mediaWiki ) );