| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
const SavedQueryItemModel = function MwRcfiltersDmSavedQueriesModel( id, label, data, config ) { |
| 15 |
config = config || {}; |
| 16 |
|
| 17 |
|
| 18 |
OO.EventEmitter.call( this ); |
| 19 |
|
| 20 |
this.id = id; |
| 21 |
this.label = label; |
| 22 |
this.data = data; |
| 23 |
this.default = !!config.default; |
| 24 |
}; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
OO.initClass( SavedQueryItemModel ); |
| 29 |
OO.mixinClass( SavedQueryItemModel, OO.EventEmitter ); |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
SavedQueryItemModel.prototype.getState = function () { |
| 49 |
return { |
| 50 |
data: this.getData(), |
| 51 |
label: this.getLabel() |
| 52 |
}; |
| 53 |
}; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
SavedQueryItemModel.prototype.getID = function () { |
| 61 |
return this.id; |
| 62 |
}; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
SavedQueryItemModel.prototype.getLabel = function () { |
| 70 |
return this.label; |
| 71 |
}; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
SavedQueryItemModel.prototype.updateLabel = function ( newLabel ) { |
| 79 |
if ( newLabel && this.label !== newLabel ) { |
| 80 |
this.label = newLabel; |
| 81 |
this.emit( 'update' ); |
| 82 |
} |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
SavedQueryItemModel.prototype.getData = function () { |
| 91 |
return this.data; |
| 92 |
}; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
SavedQueryItemModel.prototype.getCombinedData = function () { |
| 100 |
return $.extend( true, {}, this.data.params, this.data.highlights ); |
| 101 |
}; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
SavedQueryItemModel.prototype.isDefault = function () { |
| 109 |
return this.default; |
| 110 |
}; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
SavedQueryItemModel.prototype.toggleDefault = function ( isDefault ) { |
| 118 |
isDefault = isDefault === undefined ? !this.default : isDefault; |
| 119 |
|
| 120 |
if ( this.default !== isDefault ) { |
| 121 |
this.default = isDefault; |
| 122 |
this.emit( 'update' ); |
| 123 |
} |
| 124 |
}; |
| 125 |
|
| 126 |
module.exports = SavedQueryItemModel; |