| 1 |
( function () { |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
mw.echo.ui.NotificationsInboxWidget = function MwEchoUiNotificationsInboxWidget( controller, manager, config ) { |
| 18 |
config = config || {}; |
| 19 |
|
| 20 |
|
| 21 |
mw.echo.ui.NotificationsInboxWidget.super.call( this, config ); |
| 22 |
|
| 23 |
OO.ui.mixin.PendingElement.call( this, config ); |
| 24 |
|
| 25 |
this.controller = controller; |
| 26 |
this.manager = manager; |
| 27 |
|
| 28 |
this.$overlay = config.$overlay || this.$element; |
| 29 |
this.limit = config.limit || 25; |
| 30 |
|
| 31 |
this.error = false; |
| 32 |
|
| 33 |
|
| 34 |
this.noticeMessageWidget = new OO.ui.LabelWidget( { |
| 35 |
classes: [ 'mw-echo-ui-notificationsInboxWidget-notice' ] |
| 36 |
} ); |
| 37 |
|
| 38 |
|
| 39 |
this.datedListWidget = new mw.echo.ui.DatedNotificationsWidget( |
| 40 |
this.controller, |
| 41 |
this.manager, |
| 42 |
{ |
| 43 |
$overlay: this.$overlay, |
| 44 |
animateSorting: false |
| 45 |
} |
| 46 |
); |
| 47 |
this.setPendingElement( this.datedListWidget.$element ); |
| 48 |
|
| 49 |
|
| 50 |
this.topPaginationWidget = new mw.echo.ui.PaginationWidget( |
| 51 |
this.manager.getPaginationModel(), |
| 52 |
{ |
| 53 |
itemsPerPage: this.limit |
| 54 |
} |
| 55 |
); |
| 56 |
this.bottomPaginationWidget = new mw.echo.ui.PaginationWidget( |
| 57 |
this.manager.getPaginationModel(), |
| 58 |
{ |
| 59 |
itemsPerPage: this.limit |
| 60 |
} |
| 61 |
); |
| 62 |
|
| 63 |
|
| 64 |
this.settingsMenu = new mw.echo.ui.SpecialHelpMenuWidget( |
| 65 |
this.manager, |
| 66 |
{ |
| 67 |
framed: true, |
| 68 |
prefLink: config.prefLink, |
| 69 |
$overlay: this.$overlay |
| 70 |
} |
| 71 |
); |
| 72 |
|
| 73 |
|
| 74 |
this.readStateSelectWidget = new mw.echo.ui.ReadStateButtonSelectWidget(); |
| 75 |
|
| 76 |
|
| 77 |
this.xwikiUnreadWidget = new mw.echo.ui.CrossWikiUnreadFilterWidget( |
| 78 |
this.controller, |
| 79 |
this.manager.getFiltersModel() |
| 80 |
); |
| 81 |
|
| 82 |
|
| 83 |
this.readStateSelectWidget.connect( this, { filter: 'onReadStateFilter' } ); |
| 84 |
this.xwikiUnreadWidget.connect( this, { filter: 'onSourcePageFilter' } ); |
| 85 |
this.manager.connect( this, { |
| 86 |
modelItemUpdate: 'updatePaginationLabels', |
| 87 |
localCountChange: 'updatePaginationLabels' |
| 88 |
} ); |
| 89 |
this.manager.getFiltersModel().connect( this, { update: 'updateReadStateSelectWidget' } ); |
| 90 |
this.manager.getPaginationModel().connect( this, { update: 'updatePaginationLabels' } ); |
| 91 |
this.topPaginationWidget.connect( this, { change: 'populateNotifications' } ); |
| 92 |
this.bottomPaginationWidget.connect( this, { change: 'populateNotifications' } ); |
| 93 |
this.settingsMenu.connect( this, { markAllRead: 'onSettingsMarkAllRead' } ); |
| 94 |
|
| 95 |
this.topPaginationWidget.setDisabled( true ); |
| 96 |
this.bottomPaginationWidget.setDisabled( true ); |
| 97 |
|
| 98 |
this.$topToolbar = |
| 99 |
$( '<div>' ) |
| 100 |
.addClass( 'mw-echo-ui-notificationsInboxWidget-main-toolbar-top' ) |
| 101 |
.append( |
| 102 |
$( '<div>' ) |
| 103 |
.addClass( 'mw-echo-ui-notificationsInboxWidget-row' ) |
| 104 |
.append( |
| 105 |
$( '<div>' ) |
| 106 |
.addClass( 'mw-echo-ui-notificationsInboxWidget-cell-placeholder' ) |
| 107 |
.append( |
| 108 |
$( '<div>' ) |
| 109 |
.addClass( 'mw-echo-ui-notificationsInboxWidget-main-toolbar-readState' ) |
| 110 |
.addClass( 'mw-echo-ui-notificationsInboxWidget-cell' ) |
| 111 |
.append( this.readStateSelectWidget.$element ) |
| 112 |
), |
| 113 |
$( '<div>' ) |
| 114 |
.addClass( 'mw-echo-ui-notificationsInboxWidget-main-toolbar-pagination' ) |
| 115 |
.addClass( 'mw-echo-ui-notificationsInboxWidget-cell' ) |
| 116 |
.append( this.topPaginationWidget.$element ), |
| 117 |
mw.user.isTemp() ? '' : $( '<div>' ) |
| 118 |
.addClass( 'mw-echo-ui-notificationsInboxWidget-main-toolbar-settings' ) |
| 119 |
.addClass( 'mw-echo-ui-notificationsInboxWidget-cell' ) |
| 120 |
.append( this.settingsMenu.$element ) |
| 121 |
) |
| 122 |
); |
| 123 |
|
| 124 |
this.$toolbarWrapper = |
| 125 |
$( '<div>' ) |
| 126 |
.addClass( 'mw-echo-ui-notificationsInboxWidget-toolbarWrapper' ) |
| 127 |
.append( this.$topToolbar ); |
| 128 |
|
| 129 |
const $sidebar = $( '<div>' ) |
| 130 |
.addClass( 'mw-echo-ui-notificationsInboxWidget-sidebar' ) |
| 131 |
.append( this.xwikiUnreadWidget.$element ); |
| 132 |
|
| 133 |
const $main = $( '<div>' ) |
| 134 |
.addClass( 'mw-echo-ui-notificationsInboxWidget-main' ) |
| 135 |
.append( |
| 136 |
this.$toolbarWrapper, |
| 137 |
this.noticeMessageWidget.$element, |
| 138 |
this.datedListWidget.$element |
| 139 |
); |
| 140 |
|
| 141 |
this.$element |
| 142 |
.addClass( 'mw-echo-ui-notificationsInboxWidget' ) |
| 143 |
.append( |
| 144 |
$( '<div>' ) |
| 145 |
.addClass( 'mw-echo-ui-notificationsInboxWidget-row' ) |
| 146 |
.append( |
| 147 |
$sidebar |
| 148 |
.addClass( 'mw-echo-ui-notificationsInboxWidget-cell' ), |
| 149 |
$main |
| 150 |
.addClass( 'mw-echo-ui-notificationsInboxWidget-cell' ) |
| 151 |
) |
| 152 |
); |
| 153 |
|
| 154 |
this.updateReadStateSelectWidget(); |
| 155 |
this.xwikiUnreadWidget.populateSources(); |
| 156 |
this.populateNotifications(); |
| 157 |
|
| 158 |
}; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
OO.inheritClass( mw.echo.ui.NotificationsInboxWidget, OO.ui.Widget ); |
| 163 |
OO.mixinClass( mw.echo.ui.NotificationsInboxWidget, OO.ui.mixin.PendingElement ); |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
mw.echo.ui.NotificationsInboxWidget.prototype.updateReadStateSelectWidget = function () { |
| 171 |
this.readStateSelectWidget |
| 172 |
.findItemFromData( this.manager.getFiltersModel().getReadState() ) |
| 173 |
.setSelected( true ); |
| 174 |
}; |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
mw.echo.ui.NotificationsInboxWidget.prototype.updatePaginationLabels = function () { |
| 180 |
this.resetMessageLabel(); |
| 181 |
|
| 182 |
this.topPaginationWidget.updateLabel(); |
| 183 |
this.bottomPaginationWidget.updateLabel(); |
| 184 |
}; |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
mw.echo.ui.NotificationsInboxWidget.prototype.onSettingsMarkAllRead = function () { |
| 190 |
this.pushPending(); |
| 191 |
this.controller.markAllRead() |
| 192 |
.always( this.popPending.bind( this ) ); |
| 193 |
}; |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
mw.echo.ui.NotificationsInboxWidget.prototype.onSourcePageFilter = function ( source, page ) { |
| 202 |
this.controller.setFilter( 'sourcePage', source, page ); |
| 203 |
this.populateNotifications(); |
| 204 |
}; |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
mw.echo.ui.NotificationsInboxWidget.prototype.onReadStateFilter = function ( readState ) { |
| 212 |
this.controller.setFilter( 'readState', readState ); |
| 213 |
this.populateNotifications(); |
| 214 |
}; |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
mw.echo.ui.NotificationsInboxWidget.prototype.populateNotifications = function ( direction ) { |
| 225 |
let fetchPromise; |
| 226 |
if ( direction === 'prev' ) { |
| 227 |
fetchPromise = this.controller.fetchPrevPageByDate(); |
| 228 |
} else if ( direction === 'next' ) { |
| 229 |
fetchPromise = this.controller.fetchNextPageByDate(); |
| 230 |
} else { |
| 231 |
fetchPromise = this.controller.fetchFirstPageByDate(); |
| 232 |
} |
| 233 |
|
| 234 |
this.pushPending(); |
| 235 |
this.error = false; |
| 236 |
return fetchPromise |
| 237 |
.then( |
| 238 |
|
| 239 |
() => { |
| 240 |
|
| 241 |
mw.hook( 'ext.echo.special.onInitialize' ).fire( this.controller.manager.getTypeString(), this.controller ); |
| 242 |
|
| 243 |
this.popPending(); |
| 244 |
|
| 245 |
this.controller.updateSeenTime(); |
| 246 |
}, |
| 247 |
|
| 248 |
( errObj ) => { |
| 249 |
let msg; |
| 250 |
if ( errObj.errCode === 'notlogin-required' ) { |
| 251 |
|
| 252 |
msg = mw.msg( 'echo-notification-loginrequired' ); |
| 253 |
} else { |
| 254 |
|
| 255 |
msg = mw.msg( 'echo-api-failure' ); |
| 256 |
} |
| 257 |
this.error = true; |
| 258 |
this.noticeMessageWidget.setLabel( msg ); |
| 259 |
this.displayMessage( true ); |
| 260 |
} |
| 261 |
) |
| 262 |
.always( this.popPending.bind( this ) ); |
| 263 |
}; |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
mw.echo.ui.NotificationsInboxWidget.prototype.pushPending = function () { |
| 269 |
this.noticeMessageWidget.toggle( false ); |
| 270 |
this.topPaginationWidget.setDisabled( true ); |
| 271 |
this.bottomPaginationWidget.setDisabled( true ); |
| 272 |
|
| 273 |
|
| 274 |
OO.ui.mixin.PendingElement.prototype.pushPending.call( this ); |
| 275 |
}; |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
mw.echo.ui.NotificationsInboxWidget.prototype.popPending = function () { |
| 281 |
if ( !this.error ) { |
| 282 |
this.resetMessageLabel(); |
| 283 |
} |
| 284 |
|
| 285 |
this.topPaginationWidget.setDisabled( false ); |
| 286 |
this.bottomPaginationWidget.setDisabled( false ); |
| 287 |
|
| 288 |
|
| 289 |
OO.ui.mixin.PendingElement.prototype.popPending.call( this ); |
| 290 |
}; |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
mw.echo.ui.NotificationsInboxWidget.prototype.resetMessageLabel = function () { |
| 297 |
const count = this.manager.getPaginationModel().getCurrentPageItemCount(); |
| 298 |
|
| 299 |
if ( count === 0 ) { |
| 300 |
const label = this.manager.getFiltersModel().getReadState() === 'all' ? |
| 301 |
mw.msg( 'echo-notification-placeholder' ) : |
| 302 |
mw.msg( 'echo-notification-placeholder-filters' ); |
| 303 |
|
| 304 |
this.noticeMessageWidget.setLabel( label ); |
| 305 |
} |
| 306 |
|
| 307 |
this.displayMessage( count === 0 ); |
| 308 |
}; |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
mw.echo.ui.NotificationsInboxWidget.prototype.displayMessage = function ( displayMessage ) { |
| 317 |
this.noticeMessageWidget.toggle( displayMessage ); |
| 318 |
this.datedListWidget.toggle( !displayMessage ); |
| 319 |
}; |
| 320 |
|
| 321 |
}() ); |