| 1 |
( function () { |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
mw.echo.ui.CrossWikiNotificationItemWidget = function MwEchoUiCrossWikiNotificationItemWidget( controller, model, config ) { |
| 22 |
config = config || {}; |
| 23 |
|
| 24 |
|
| 25 |
mw.echo.ui.CrossWikiNotificationItemWidget.super.call( this, controller, model, config ); |
| 26 |
|
| 27 |
OO.ui.mixin.PendingElement.call( this, config ); |
| 28 |
|
| 29 |
|
| 30 |
this.toggleMarkAsReadButtons( true ); |
| 31 |
|
| 32 |
this.listWidget = new mw.echo.ui.SortedListWidget( |
| 33 |
|
| 34 |
( ( a, b ) => { |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
if ( b.getTimestamp() < a.getTimestamp() ) { |
| 39 |
return -1; |
| 40 |
} else if ( b.getTimestamp() > a.getTimestamp() ) { |
| 41 |
return 1; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
return b.getSource() - a.getSource(); |
| 46 |
} ), |
| 47 |
|
| 48 |
{ |
| 49 |
classes: [ 'mw-echo-ui-crossWikiNotificationItemWidget-group' ], |
| 50 |
timestamp: this.getTimestamp(), |
| 51 |
$overlay: this.$overlay, |
| 52 |
animated: config.animateSorting |
| 53 |
} |
| 54 |
); |
| 55 |
|
| 56 |
this.listWidget.$element |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
.css( 'display', 'none' ); |
| 61 |
this.setPendingElement( this.listWidget.$element ); |
| 62 |
|
| 63 |
this.errorWidget = new mw.echo.ui.PlaceholderItemWidget(); |
| 64 |
this.errorWidget.toggle( false ); |
| 65 |
|
| 66 |
|
| 67 |
this.showTitles = true; |
| 68 |
this.expanded = false; |
| 69 |
this.fetchedOnce = false; |
| 70 |
|
| 71 |
|
| 72 |
this.toggleExpandButton = new OO.ui.ButtonOptionWidget( { |
| 73 |
icon: 'expand', |
| 74 |
framed: false, |
| 75 |
classes: [ 'mw-echo-ui-notificationItemWidget-content-actions-button' ] |
| 76 |
} ); |
| 77 |
this.updateExpandButton(); |
| 78 |
this.actionsButtonSelectWidget.addItems( [ this.toggleExpandButton ] ); |
| 79 |
|
| 80 |
|
| 81 |
this.model.connect( this, { discard: 'onModelDiscard' } ); |
| 82 |
this.toggleExpandButton.connect( this, { click: 'expand' } ); |
| 83 |
this.$content.on( 'click', this.expand.bind( this ) ); |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
this.populateFromModel(); |
| 96 |
this.toggleExpanded( false ); |
| 97 |
this.toggleRead( false ); |
| 98 |
this.toggleTitles( true ); |
| 99 |
this.$element |
| 100 |
.addClass( 'mw-echo-ui-crossWikiNotificationItemWidget' ) |
| 101 |
.append( |
| 102 |
$( '<div>' ) |
| 103 |
.addClass( 'mw-echo-ui-crossWikiNotificationItemWidget-separator' ), |
| 104 |
this.listWidget.$element, |
| 105 |
this.errorWidget.$element |
| 106 |
); |
| 107 |
}; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
OO.inheritClass( mw.echo.ui.CrossWikiNotificationItemWidget, mw.echo.ui.NotificationItemWidget ); |
| 112 |
OO.mixinClass( mw.echo.ui.CrossWikiNotificationItemWidget, OO.ui.mixin.PendingElement ); |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
mw.echo.ui.CrossWikiNotificationItemWidget.prototype.onModelDiscard = function ( groupName ) { |
| 122 |
const list = this.getList(), |
| 123 |
group = list.getItemFromId( groupName ); |
| 124 |
|
| 125 |
list.removeItems( [ group ] ); |
| 126 |
|
| 127 |
if ( list.isEmpty() ) { |
| 128 |
this.controller.removeCrossWikiItem(); |
| 129 |
} |
| 130 |
}; |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
mw.echo.ui.CrossWikiNotificationItemWidget.prototype.markRead = function () { |
| 136 |
|
| 137 |
|
| 138 |
this.controller.markEntireCrossWikiItemAsRead(); |
| 139 |
}; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
mw.echo.ui.CrossWikiNotificationItemWidget.prototype.populateFromModel = function () { |
| 146 |
const groupWidgets = [], |
| 147 |
groups = this.model.getList().getItems(); |
| 148 |
|
| 149 |
for ( let i = 0; i < groups.length; i++ ) { |
| 150 |
|
| 151 |
groupWidgets.push( |
| 152 |
new mw.echo.ui.SubGroupListWidget( |
| 153 |
this.controller, |
| 154 |
groups[ i ], |
| 155 |
{ |
| 156 |
$overlay: this.$overlay, |
| 157 |
showTitle: this.showTitles |
| 158 |
} |
| 159 |
) |
| 160 |
); |
| 161 |
} |
| 162 |
this.getList().addItems( groupWidgets ); |
| 163 |
}; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
mw.echo.ui.CrossWikiNotificationItemWidget.prototype.toggleTitles = function ( show ) { |
| 171 |
const items = this.getList().getItems(); |
| 172 |
|
| 173 |
show = show === undefined ? !this.showTitles : show; |
| 174 |
|
| 175 |
if ( this.showTitles !== show ) { |
| 176 |
this.showTitles = show; |
| 177 |
for ( let i = 0; i < items.length; i++ ) { |
| 178 |
items[ i ].toggleTitle( show ); |
| 179 |
} |
| 180 |
} |
| 181 |
}; |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
mw.echo.ui.CrossWikiNotificationItemWidget.prototype.checkShowTitles = function () { |
| 188 |
this.toggleTitles( this.getList().getItemCount() > 1 ); |
| 189 |
}; |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
mw.echo.ui.CrossWikiNotificationItemWidget.prototype.toggleListDisplay = function ( showList ) { |
| 197 |
this.errorWidget.toggle( !showList ); |
| 198 |
this.listWidget.toggle( showList ); |
| 199 |
}; |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
mw.echo.ui.CrossWikiNotificationItemWidget.prototype.showErrorMessage = function ( label, link ) { |
| 208 |
this.errorWidget.setLabel( label || '' ); |
| 209 |
this.errorWidget.setLink( link || '' ); |
| 210 |
|
| 211 |
this.toggleListDisplay( false ); |
| 212 |
}; |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
mw.echo.ui.CrossWikiNotificationItemWidget.prototype.expand = function () { |
| 219 |
this.toggleExpanded( !this.expanded ); |
| 220 |
this.updateExpandButton(); |
| 221 |
|
| 222 |
if ( !this.expanded ) { |
| 223 |
return; |
| 224 |
} |
| 225 |
|
| 226 |
if ( !this.fetchedOnce ) { |
| 227 |
|
| 228 |
this.pushPending(); |
| 229 |
this.toggleListDisplay( true ); |
| 230 |
|
| 231 |
this.controller.fetchCrossWikiNotifications() |
| 232 |
.catch( |
| 233 |
( result ) => { |
| 234 |
const loginPageTitle = mw.Title.newFromText( 'Special:UserLogin' ); |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
if ( result.errCode === 'notlogin-required' ) { |
| 239 |
|
| 240 |
this.showErrorMessage( |
| 241 |
mw.message( 'echo-notification-popup-loginrequired' ), |
| 242 |
|
| 243 |
loginPageTitle.getUrl() |
| 244 |
); |
| 245 |
} else { |
| 246 |
|
| 247 |
this.showErrorMessage( mw.msg( 'echo-api-failure' ) ); |
| 248 |
} |
| 249 |
} |
| 250 |
) |
| 251 |
.always( this.popPending.bind( this ) ); |
| 252 |
|
| 253 |
|
| 254 |
this.fetchedOnce = true; |
| 255 |
} |
| 256 |
}; |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
mw.echo.ui.CrossWikiNotificationItemWidget.prototype.toggleExpanded = function ( show ) { |
| 264 |
this.expanded = show !== undefined ? !!show : !this.expanded; |
| 265 |
|
| 266 |
this.$element.toggleClass( 'mw-echo-ui-crossWikiNotificationItemWidget-expanded', this.expanded ); |
| 267 |
|
| 268 |
if ( this.expanded ) { |
| 269 |
|
| 270 |
|
| 271 |
this.getList().$element.slideDown(); |
| 272 |
} else { |
| 273 |
|
| 274 |
this.getList().$element.slideUp(); |
| 275 |
} |
| 276 |
}; |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
mw.echo.ui.CrossWikiNotificationItemWidget.prototype.updateExpandButton = function () { |
| 282 |
const type = this.model.getType(); |
| 283 |
|
| 284 |
this.toggleExpandButton.setLabel( |
| 285 |
this.expanded ? |
| 286 |
mw.msg( 'notification-link-text-collapse-all' ) : |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
mw.msg( |
| 291 |
'notification-link-text-expand-' + |
| 292 |
( type === 'message' ? 'notice' : type ) + |
| 293 |
'-count', |
| 294 |
mw.language.convertNumber( this.model.getCount() ) |
| 295 |
) |
| 296 |
); |
| 297 |
this.toggleExpandButton.setIcon( |
| 298 |
this.expanded ? |
| 299 |
'collapse' : |
| 300 |
'expand' |
| 301 |
); |
| 302 |
}; |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
mw.echo.ui.CrossWikiNotificationItemWidget.prototype.getList = function () { |
| 310 |
return this.listWidget; |
| 311 |
}; |
| 312 |
}() ); |