| 1 |
( function () { |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
mw.echo.ui.DatedNotificationsWidget = function MwEchoUiDatedNotificationsListWidget( controller, modelManager, config ) { |
| 17 |
config = config || {}; |
| 18 |
|
| 19 |
|
| 20 |
mw.echo.ui.DatedNotificationsWidget.super.call( this, config ); |
| 21 |
|
| 22 |
OO.ui.mixin.PendingElement.call( this, config ); |
| 23 |
|
| 24 |
this.manager = modelManager; |
| 25 |
this.controller = controller; |
| 26 |
this.models = {}; |
| 27 |
|
| 28 |
this.$overlay = config.$overlay || this.$element; |
| 29 |
this.animateSorting = !!config.animateSorting; |
| 30 |
|
| 31 |
this.listWidget = new mw.echo.ui.SortedListWidget( |
| 32 |
|
| 33 |
( ( a, b ) => { |
| 34 |
|
| 35 |
if ( b.getTimestamp() < a.getTimestamp() ) { |
| 36 |
return -1; |
| 37 |
} else if ( b.getTimestamp() > a.getTimestamp() ) { |
| 38 |
return 1; |
| 39 |
} |
| 40 |
} ), |
| 41 |
|
| 42 |
{ |
| 43 |
classes: [ 'mw-echo-ui-datedNotificationsWidget-group' ], |
| 44 |
$overlay: this.$overlay, |
| 45 |
animated: false |
| 46 |
} |
| 47 |
); |
| 48 |
|
| 49 |
|
| 50 |
this.manager.connect( this, { |
| 51 |
update: 'populateFromModel', |
| 52 |
discard: 'onManagerDiscardModel' |
| 53 |
} ); |
| 54 |
|
| 55 |
this.$element |
| 56 |
.addClass( 'mw-echo-ui-datedNotificationsWidget' ) |
| 57 |
.append( this.listWidget.$element ); |
| 58 |
|
| 59 |
|
| 60 |
this.populateFromModel(); |
| 61 |
}; |
| 62 |
|
| 63 |
|
| 64 |
OO.inheritClass( mw.echo.ui.DatedNotificationsWidget, OO.ui.Widget ); |
| 65 |
OO.mixinClass( mw.echo.ui.DatedNotificationsWidget, OO.ui.mixin.PendingElement ); |
| 66 |
|
| 67 |
mw.echo.ui.DatedNotificationsWidget.prototype.onManagerDiscardModel = function ( modelId ) { |
| 68 |
const model = this.models[ modelId ], |
| 69 |
list = this.getList(); |
| 70 |
|
| 71 |
if ( model ) { |
| 72 |
const group = list.getItemFromId( model.getName() ); |
| 73 |
list.removeItems( [ group ] ); |
| 74 |
} |
| 75 |
}; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
mw.echo.ui.DatedNotificationsWidget.prototype.onModelRemoveSource = function ( source ) { |
| 82 |
const list = this.getList(), |
| 83 |
group = list.getItemFromId( source ); |
| 84 |
|
| 85 |
list.removeItems( [ group ] ); |
| 86 |
}; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
mw.echo.ui.DatedNotificationsWidget.prototype.populateFromModel = function ( models ) { |
| 96 |
const groupWidgets = []; |
| 97 |
|
| 98 |
|
| 99 |
for ( const modelId in this.models ) { |
| 100 |
this.detachModel( modelId ); |
| 101 |
} |
| 102 |
|
| 103 |
for ( const model in models ) { |
| 104 |
|
| 105 |
const subgroupWidget = new mw.echo.ui.DatedSubGroupListWidget( |
| 106 |
this.controller, |
| 107 |
models[ model ], |
| 108 |
{ |
| 109 |
showTitle: true, |
| 110 |
showMarkAllRead: true, |
| 111 |
$overlay: this.$overlay, |
| 112 |
animated: this.animateSorting |
| 113 |
} |
| 114 |
); |
| 115 |
this.attachModel( model, models[ model ] ); |
| 116 |
|
| 117 |
subgroupWidget.resetItemsFromModel(); |
| 118 |
groupWidgets.push( subgroupWidget ); |
| 119 |
} |
| 120 |
|
| 121 |
this.getList().getItems().forEach( ( widget ) => { |
| 122 |
|
| 123 |
widget.destroy(); |
| 124 |
} ); |
| 125 |
|
| 126 |
|
| 127 |
this.getList().clearItems(); |
| 128 |
this.getList().addItems( groupWidgets ); |
| 129 |
}; |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
mw.echo.ui.DatedNotificationsWidget.prototype.attachModel = function ( modelId, model ) { |
| 138 |
this.models[ modelId ] = model; |
| 139 |
}; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
mw.echo.ui.DatedNotificationsWidget.prototype.detachModel = function ( modelId ) { |
| 147 |
this.models[ modelId ].disconnect( this ); |
| 148 |
delete this.models[ modelId ]; |
| 149 |
}; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
mw.echo.ui.DatedNotificationsWidget.prototype.getList = function () { |
| 157 |
return this.listWidget; |
| 158 |
}; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
mw.echo.ui.DatedNotificationsWidget.prototype.getAllNotificationCount = function () { |
| 166 |
const groups = this.getList().getItems(); |
| 167 |
|
| 168 |
let count = 0; |
| 169 |
for ( let i = 0; i < groups.length; i++ ) { |
| 170 |
count += groups[ i ].getListWidget().getItemCount(); |
| 171 |
} |
| 172 |
|
| 173 |
return count; |
| 174 |
}; |
| 175 |
|
| 176 |
}() ); |