blob: c74648e8ebdf4f458ed835a33b4e95f3f4b8927a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
( function ( mw ) {
/**
* View model for a single saved query
*
* @class
* @mixins OO.EventEmitter
*
* @constructor
* @param {string} id Unique identifier
* @param {string} label Saved query label
* @param {Object} data Saved query data
* @param {Object} [config] Configuration options
* @cfg {boolean} [default] This item is the default
*/
mw.rcfilters.dm.SavedQueryItemModel = function MwRcfiltersDmSavedQueriesModel( id, label, data, config ) {
config = config || {};
// Mixin constructor
OO.EventEmitter.call( this );
this.id = id;
this.label = label;
this.data = data;
this.default = !!config.default;
};
/* Initialization */
OO.initClass( mw.rcfilters.dm.SavedQueryItemModel );
OO.mixinClass( mw.rcfilters.dm.SavedQueryItemModel, OO.EventEmitter );
/* Events */
/**
* @event update
*
* Model has been updated
*/
/* Methods */
/**
* Get an object representing the state of this item
*
* @return {Object} Object representing the current data state
* of the object
*/
mw.rcfilters.dm.SavedQueryItemModel.prototype.getState = function () {
return {
data: this.getData(),
label: this.getLabel()
};
};
/**
* Get the query's identifier
*
* @return {string} Query identifier
*/
mw.rcfilters.dm.SavedQueryItemModel.prototype.getID = function () {
return this.id;
};
/**
* Get query label
*
* @return {string} Query label
*/
mw.rcfilters.dm.SavedQueryItemModel.prototype.getLabel = function () {
return this.label;
};
/**
* Update the query label
*
* @param {string} newLabel New label
*/
mw.rcfilters.dm.SavedQueryItemModel.prototype.updateLabel = function ( newLabel ) {
if ( newLabel && this.label !== newLabel ) {
this.label = newLabel;
this.emit( 'update' );
}
};
/**
* Get query data
*
* @return {Object} Object representing parameter and highlight data
*/
mw.rcfilters.dm.SavedQueryItemModel.prototype.getData = function () {
return this.data;
};
/**
* Get the combined data of this item as a flat object of parameters
*
* @return {Object} Combined parameter data
*/
mw.rcfilters.dm.SavedQueryItemModel.prototype.getCombinedData = function () {
return $.extend( true, {}, this.data.params, this.data.highlights );
};
/**
* Check whether this item is the default
*
* @return {boolean} Query is set to be default
*/
mw.rcfilters.dm.SavedQueryItemModel.prototype.isDefault = function () {
return this.default;
};
/**
* Toggle the default state of this query item
*
* @param {boolean} isDefault Query is default
*/
mw.rcfilters.dm.SavedQueryItemModel.prototype.toggleDefault = function ( isDefault ) {
isDefault = isDefault === undefined ? !this.default : isDefault;
if ( this.default !== isDefault ) {
this.default = isDefault;
this.emit( 'update' );
}
};
}( mediaWiki ) );
|