2018-11-12 13:56:38 +00:00
|
|
|
( function () {
|
2016-06-07 20:08:16 +00:00
|
|
|
/**
|
|
|
|
* Bundle notification item widget.
|
|
|
|
* This widget is expandable and displays
|
|
|
|
* inner notifications that constitute the bundle.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends mw.echo.ui.NotificationItemWidget
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {mw.echo.Controller} controller Echo notifications controller
|
|
|
|
* @param {mw.echo.dm.BundleNotificationItem} model Notification group model
|
|
|
|
* @param {Object} [config] Configuration object
|
2024-05-27 01:43:21 +00:00
|
|
|
* @param {boolean} [config.animateSorting=false] Animate the sorting of items
|
2016-06-07 20:08:16 +00:00
|
|
|
*/
|
|
|
|
mw.echo.ui.BundleNotificationItemWidget = function MwEchoUiBundleNotificationItemWidget( controller, model, config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
// Parent constructor
|
2018-05-22 14:56:46 +00:00
|
|
|
mw.echo.ui.BundleNotificationItemWidget.super.call( this, controller, model, config );
|
2016-06-07 20:08:16 +00:00
|
|
|
|
|
|
|
this.toggleMarkAsReadButtons( true );
|
|
|
|
|
|
|
|
this.listWidget = new mw.echo.ui.SortedListWidget(
|
|
|
|
// Sorting callback
|
2024-06-03 12:26:18 +00:00
|
|
|
( ( a, b ) => {
|
2016-07-22 18:59:10 +00:00
|
|
|
// Reverse sorting
|
|
|
|
if ( b.getTimestamp() < a.getTimestamp() ) {
|
|
|
|
return -1;
|
|
|
|
} else if ( b.getTimestamp() > a.getTimestamp() ) {
|
|
|
|
return 1;
|
2016-06-07 20:08:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fallback on IDs
|
|
|
|
return b.getId() - a.getId();
|
2024-06-03 12:26:18 +00:00
|
|
|
} ),
|
2016-06-07 20:08:16 +00:00
|
|
|
// Config
|
|
|
|
{
|
|
|
|
classes: [ 'mw-echo-ui-bundleNotificationItemWidget-group' ],
|
|
|
|
timestamp: this.getTimestamp(),
|
Fix fade-in/out animation in sorting
The fade in/out animation is asynchronous. This means that if we are
sorting multiple items one after the other, by the time the item faded
out, it will be reinserted back into the wrong position, breaking the
sorting.
This also broke the promise of OO.SortedEmitterList whereby all its items
are always in order.
The way to fix this was to force a better synchronization with the item
order while we hide and show the item in its new place. To do that,
a new widget is created as a fake clone of the old one, in the original
position of the old one. The original item is then reinserted (while hidden)
to the proper location -- preserving order. The fake clone is then faded
out, and the real item is then faded in.
For this to work properly, the cloned item had to preserve some of the
original item's information, like timestamp, foreigness and id. However,
since both the real item and the fake new clone have the same details,
the clone fakes its ID by adding a fraction to it - promising that the
fallback in case of equal timestamps (which happens on the real and
cloned items) will still resolve with some decision about the placement
of the items rather than (falsely but understandably) decide they are
both the same.
Since this whole animation is somewhat of a hack, the list now has a
configuration parameter to turn the animation on.
The animation is on in the popups, but off in the special page.
Bug: T141419
Change-Id: Ic7c35e5ddefc51bf7fde497eab36414b4dddcd9e
2016-07-29 23:35:29 +00:00
|
|
|
$overlay: this.$overlay,
|
|
|
|
animated: !!config.animateSorting
|
2016-06-07 20:08:16 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.listWidget.$element
|
|
|
|
// We have to manually set the display to 'none' here because
|
|
|
|
// otherwise the 'slideUp' and 'slideDown' jQuery effects don't
|
|
|
|
// work
|
|
|
|
.css( 'display', 'none' );
|
|
|
|
|
2023-12-16 01:49:25 +00:00
|
|
|
// Prevent clicks on the list padding area from activating the primary link
|
2024-06-03 12:26:18 +00:00
|
|
|
this.listWidget.$element.on( 'click', ( e ) => {
|
2023-12-16 01:49:25 +00:00
|
|
|
if ( e.target.closest( 'a' ) === this.$element[ 0 ] ) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2024-06-03 12:26:18 +00:00
|
|
|
} );
|
2023-12-16 01:49:25 +00:00
|
|
|
|
2016-06-07 20:08:16 +00:00
|
|
|
// Initialize closed
|
|
|
|
this.expanded = false;
|
|
|
|
|
|
|
|
// Add "expand" button
|
|
|
|
this.toggleExpandButton = new OO.ui.ButtonOptionWidget( {
|
|
|
|
icon: 'expand',
|
|
|
|
framed: false,
|
|
|
|
classes: [ 'mw-echo-ui-notificationItemWidget-content-actions-button' ]
|
|
|
|
} );
|
|
|
|
this.updateExpandButton();
|
|
|
|
this.actionsButtonSelectWidget.addItems( [ this.toggleExpandButton ], 0 );
|
|
|
|
|
|
|
|
// Events
|
|
|
|
this.toggleExpandButton.connect( this, { click: 'expand' } );
|
|
|
|
|
2016-09-16 22:23:40 +00:00
|
|
|
if ( !this.model.getPrimaryUrl() ) {
|
|
|
|
// If there's no primary link, make sure a click
|
|
|
|
// triggers the 'expand' action
|
|
|
|
this.$content.on( 'click', this.expand.bind( this ) );
|
|
|
|
}
|
|
|
|
|
2016-06-07 20:08:16 +00:00
|
|
|
// Initialization
|
|
|
|
this.populateFromModel();
|
|
|
|
this.toggleExpanded( false );
|
|
|
|
this.toggleRead( false );
|
|
|
|
this.$element
|
|
|
|
.addClass( 'mw-echo-ui-bundleNotificationItemWidget' )
|
|
|
|
.append(
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-bundleNotificationItemWidget-separator' ),
|
|
|
|
this.listWidget.$element
|
|
|
|
);
|
|
|
|
|
|
|
|
// Events
|
|
|
|
this.model.connect( this, { update: 'updateDataFromModel' } );
|
|
|
|
|
|
|
|
// Update read and seen states from the model
|
|
|
|
this.updateDataFromModel();
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
|
|
|
OO.inheritClass( mw.echo.ui.BundleNotificationItemWidget, mw.echo.ui.NotificationItemWidget );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
mw.echo.ui.BundleNotificationItemWidget.prototype.markRead = function ( isRead ) {
|
|
|
|
this.controller.markEntireListModelRead( this.model.getModelName(), isRead );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate the items in this widget according to the data
|
|
|
|
* in the model
|
|
|
|
*/
|
|
|
|
mw.echo.ui.BundleNotificationItemWidget.prototype.populateFromModel = function () {
|
2024-06-03 12:26:18 +00:00
|
|
|
this.getList().addItems( this.model.getList().getItems().map( ( singleNotifModel ) => new mw.echo.ui.SingleNotificationItemWidget(
|
2024-06-03 13:48:16 +00:00
|
|
|
this.controller,
|
2024-06-03 12:26:18 +00:00
|
|
|
singleNotifModel,
|
|
|
|
{
|
2024-06-03 13:48:16 +00:00
|
|
|
$overlay: this.$overlay,
|
2024-06-03 12:26:18 +00:00
|
|
|
bundle: true
|
|
|
|
}
|
|
|
|
) ) );
|
2016-06-07 20:08:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update item state when the item model changes.
|
2024-04-30 14:21:54 +00:00
|
|
|
*
|
|
|
|
* @fires OO.EventEmitter#sortChange
|
2016-06-07 20:08:16 +00:00
|
|
|
*/
|
|
|
|
mw.echo.ui.BundleNotificationItemWidget.prototype.updateDataFromModel = function () {
|
|
|
|
this.toggleRead( this.model.isRead() );
|
|
|
|
this.toggleSeen( this.model.isSeen() );
|
|
|
|
this.emit( 'sortChange' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle the visibility of the notification item list and the placeholder/error widget.
|
|
|
|
*
|
|
|
|
* @param {boolean} showList Show the list
|
|
|
|
*/
|
|
|
|
mw.echo.ui.BundleNotificationItemWidget.prototype.toggleListDisplay = function ( showList ) {
|
|
|
|
this.listWidget.toggle( showList );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expand the group and fetch the list of notifications.
|
|
|
|
* Only fetch the first time we expand.
|
|
|
|
*/
|
|
|
|
mw.echo.ui.BundleNotificationItemWidget.prototype.expand = function () {
|
|
|
|
this.toggleExpanded( !this.expanded );
|
|
|
|
this.updateExpandButton();
|
|
|
|
|
2016-09-07 23:44:03 +00:00
|
|
|
this.$element.toggleClass( 'mw-echo-ui-bundleNotificationItemWidget-expanded', this.expanded );
|
|
|
|
|
2016-06-07 20:08:16 +00:00
|
|
|
if ( !this.expanded ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle the expand/collapsed state of this group widget
|
|
|
|
*
|
|
|
|
* @param {boolean} show Show the widget expanded
|
|
|
|
*/
|
|
|
|
mw.echo.ui.BundleNotificationItemWidget.prototype.toggleExpanded = function ( show ) {
|
|
|
|
this.expanded = show !== undefined ? !!show : !this.expanded;
|
|
|
|
|
|
|
|
if ( show ) {
|
2019-02-06 01:42:53 +00:00
|
|
|
// FIXME: Use CSS transition
|
2019-04-03 22:57:13 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-slide
|
2016-06-07 20:08:16 +00:00
|
|
|
this.getList().$element.slideDown();
|
|
|
|
} else {
|
2019-04-03 22:57:13 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-slide
|
2016-06-07 20:08:16 +00:00
|
|
|
this.getList().$element.slideUp();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the expand button label
|
|
|
|
*/
|
|
|
|
mw.echo.ui.BundleNotificationItemWidget.prototype.updateExpandButton = function () {
|
|
|
|
this.toggleExpandButton.setLabel(
|
|
|
|
this.expanded ?
|
|
|
|
mw.msg( 'notification-link-text-collapse-all' ) :
|
|
|
|
mw.msg( 'notification-link-text-expand-all' )
|
|
|
|
);
|
|
|
|
this.toggleExpandButton.setIcon(
|
|
|
|
this.expanded ?
|
|
|
|
'collapse' :
|
|
|
|
'expand'
|
|
|
|
);
|
2020-07-23 13:44:44 +00:00
|
|
|
// T258706
|
|
|
|
this.toggleExpandButton.setActive( false );
|
2016-06-07 20:08:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the list widget contained in this item
|
|
|
|
*
|
|
|
|
* @return {mw.echo.ui.SortedListWidget} List widget
|
|
|
|
*/
|
|
|
|
mw.echo.ui.BundleNotificationItemWidget.prototype.getList = function () {
|
|
|
|
return this.listWidget;
|
|
|
|
};
|
2018-11-12 13:56:38 +00:00
|
|
|
}() );
|