2015-08-13 00:54:16 +00:00
|
|
|
( function ( mw, $ ) {
|
2016-11-18 21:16:43 +00:00
|
|
|
/* global moment:false */
|
2015-08-13 00:54:16 +00:00
|
|
|
/**
|
2016-04-10 13:31:02 +00:00
|
|
|
* A base widget for displaying notification items.
|
2015-08-13 00:54:16 +00:00
|
|
|
*
|
|
|
|
* @class
|
2016-06-03 18:47:13 +00:00
|
|
|
* @abstract
|
2016-04-10 13:31:02 +00:00
|
|
|
* @extends OO.ui.Widget
|
2015-08-13 00:54:16 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2016-04-10 13:31:02 +00:00
|
|
|
* @param {mw.echo.Controller} controller Echo controller
|
2016-03-25 18:52:59 +00:00
|
|
|
* @param {mw.echo.dm.NotificationItem} model Notification item model
|
2016-04-10 13:31:02 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2015-11-21 01:54:12 +00:00
|
|
|
* @cfg {jQuery} [$overlay] A jQuery element functioning as an overlay
|
|
|
|
* for popups.
|
2015-10-16 23:18:25 +00:00
|
|
|
* @cfg {boolean} [bundle=false] This notification item is part of a bundle.
|
2015-08-13 00:54:16 +00:00
|
|
|
*/
|
2016-04-10 13:31:02 +00:00
|
|
|
mw.echo.ui.NotificationItemWidget = function MwEchoUiNotificationItemWidget( controller, model, config ) {
|
2016-03-05 00:57:34 +00:00
|
|
|
var i, secondaryUrls, urlObj, linkButton, $icon, isOutsideMenu, echoMoment,
|
|
|
|
outsideMenuItemCounter = 0,
|
2016-04-10 13:31:02 +00:00
|
|
|
$message = $( '<div>' ).addClass( 'mw-echo-ui-notificationItemWidget-content-message' );
|
2015-10-16 23:18:25 +00:00
|
|
|
|
2015-08-13 00:54:16 +00:00
|
|
|
config = config || {};
|
|
|
|
|
2018-05-22 14:56:46 +00:00
|
|
|
// Parent constructor
|
|
|
|
mw.echo.ui.NotificationItemWidget.super.call( this, $.extend( { data: model.getId() }, config ) );
|
2015-10-16 23:18:25 +00:00
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
this.controller = controller;
|
2015-08-13 00:54:16 +00:00
|
|
|
this.model = model;
|
2016-04-10 13:31:02 +00:00
|
|
|
|
2015-11-21 01:54:12 +00:00
|
|
|
this.$overlay = config.$overlay || this.$element;
|
2015-10-16 23:18:25 +00:00
|
|
|
this.bundle = !!config.bundle;
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2016-02-22 20:32:05 +00:00
|
|
|
this.$content = $( '<div>' ).addClass( 'mw-echo-ui-notificationItemWidget-content' );
|
2015-10-16 23:18:25 +00:00
|
|
|
this.$actions = $( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationItemWidget-content-actions' );
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2016-04-15 20:30:14 +00:00
|
|
|
// Mark as read
|
2016-06-20 20:00:37 +00:00
|
|
|
this.markAsReadButton = new mw.echo.ui.ToggleReadCircleButtonWidget( {
|
2015-08-13 00:54:16 +00:00
|
|
|
framed: false,
|
2016-04-15 20:30:14 +00:00
|
|
|
title: mw.msg( 'echo-notification-markasread-tooltip' ),
|
2016-06-20 20:00:37 +00:00
|
|
|
classes: [ 'mw-echo-ui-notificationItemWidget-markAsReadButton' ],
|
|
|
|
markAsRead: !this.model.isRead()
|
2015-08-13 00:54:16 +00:00
|
|
|
} );
|
|
|
|
|
2015-10-16 23:18:25 +00:00
|
|
|
// Icon
|
|
|
|
if ( this.model.getIconURL() ) {
|
|
|
|
$icon = $( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationItemWidget-icon' )
|
|
|
|
.append( $( '<img>' ).attr( 'src', this.model.getIconURL() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Content
|
|
|
|
$message.append(
|
|
|
|
$( '<div>' )
|
2016-07-19 00:06:48 +00:00
|
|
|
.addClass( 'mw-echo-ui-notificationItemWidget-content-message-header-wrapper' )
|
|
|
|
.append(
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationItemWidget-content-message-header' )
|
|
|
|
.append( this.model.getContentHeader() )
|
|
|
|
)
|
2015-10-16 23:18:25 +00:00
|
|
|
);
|
|
|
|
if ( !this.bundle && this.model.getContentBody() ) {
|
|
|
|
$message.append(
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationItemWidget-content-message-body' )
|
|
|
|
.append( this.model.getContentBody() )
|
2016-02-24 05:09:57 +00:00
|
|
|
// dir=auto has a similar effect to wrapping the content in <bdi>, but
|
|
|
|
// makes text-overflow: ellipsis; behave less strangely
|
|
|
|
.attr( 'dir', 'auto' )
|
2015-10-16 23:18:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actions menu
|
|
|
|
this.actionsButtonSelectWidget = new OO.ui.ButtonSelectWidget( {
|
|
|
|
classes: [ 'mw-echo-ui-notificationItemWidget-content-actions-buttons' ]
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Popup menu
|
|
|
|
this.menuPopupButtonWidget = new mw.echo.ui.ActionMenuPopupWidget( {
|
|
|
|
framed: false,
|
|
|
|
icon: 'ellipsis',
|
|
|
|
$overlay: this.$overlay,
|
|
|
|
menuWidth: 200,
|
2016-04-15 20:30:14 +00:00
|
|
|
title: mw.msg( 'echo-notification-more-options-tooltip' ),
|
2015-10-16 23:18:25 +00:00
|
|
|
classes: [ 'mw-echo-ui-notificationItemWidget-content-actions-menu' ]
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Timestamp
|
2016-02-27 01:19:06 +00:00
|
|
|
// We want to use extra-short timestamp strings; we change the locale
|
|
|
|
// to our echo-defined one and use that instead of the normal moment locale
|
2016-07-22 18:59:10 +00:00
|
|
|
echoMoment = moment.utc( this.model.getTimestamp() );
|
2016-02-27 01:19:06 +00:00
|
|
|
echoMoment.locale( 'echo-shortRelativeTime' );
|
2016-07-22 18:59:10 +00:00
|
|
|
echoMoment.local();
|
2016-02-27 01:19:06 +00:00
|
|
|
|
2015-10-16 23:18:25 +00:00
|
|
|
this.timestampWidget = new OO.ui.LabelWidget( {
|
|
|
|
classes: [ 'mw-echo-ui-notificationItemWidget-content-actions-timestamp' ],
|
2016-02-27 01:19:06 +00:00
|
|
|
// Get the time 'fromNow' without the suffix 'ago'
|
|
|
|
label: echoMoment.fromNow( true )
|
2015-10-16 23:18:25 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Build the actions line
|
2015-12-22 23:16:32 +00:00
|
|
|
if ( this.bundle ) {
|
|
|
|
// In a bundled item, the timestamp should go before the menu
|
|
|
|
this.$actions.append(
|
|
|
|
$( '<div>' )
|
|
|
|
// We are wrapping the actions in a 'row' div so that the
|
|
|
|
// internal pieces are also a table layout
|
|
|
|
.addClass( 'mw-echo-ui-notificationItemWidget-content-actions-row' )
|
|
|
|
.append(
|
|
|
|
this.actionsButtonSelectWidget.$element,
|
|
|
|
this.timestampWidget.$element,
|
|
|
|
this.menuPopupButtonWidget.$element
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.$actions.append(
|
|
|
|
this.actionsButtonSelectWidget.$element,
|
|
|
|
this.menuPopupButtonWidget.$element,
|
|
|
|
this.timestampWidget.$element
|
|
|
|
);
|
|
|
|
}
|
2015-10-16 23:18:25 +00:00
|
|
|
|
|
|
|
// Actions
|
|
|
|
secondaryUrls = this.model.getSecondaryUrls();
|
|
|
|
for ( i = 0; i < secondaryUrls.length; i++ ) {
|
|
|
|
urlObj = secondaryUrls[ i ];
|
|
|
|
|
2016-03-05 00:57:34 +00:00
|
|
|
// Items are placed outside the dotdotdot menu if they are
|
|
|
|
// prioritized explicitly, *except* for items inside a bundle
|
|
|
|
// (where all actions are inside the menu) or there are more than
|
|
|
|
// two prioritized actions (all others go into the menu)
|
2017-09-07 23:11:56 +00:00
|
|
|
isOutsideMenu = !this.bundle && urlObj.prioritized && outsideMenuItemCounter < mw.echo.config.maxPrioritizedActions;
|
2016-01-30 00:27:47 +00:00
|
|
|
|
|
|
|
linkButton = new mw.echo.ui.MenuItemWidget( {
|
2016-08-05 21:44:55 +00:00
|
|
|
type: urlObj.type,
|
|
|
|
actionData: urlObj.data,
|
2016-01-15 02:00:01 +00:00
|
|
|
icon: urlObj.icon || 'next',
|
2015-10-16 23:18:25 +00:00
|
|
|
label: urlObj.label,
|
2016-02-17 17:27:49 +00:00
|
|
|
tooltip: urlObj.tooltip,
|
2016-01-30 00:27:47 +00:00
|
|
|
description: urlObj.description,
|
|
|
|
url: urlObj.url,
|
2016-03-05 00:57:34 +00:00
|
|
|
prioritized: isOutsideMenu
|
2015-10-16 23:18:25 +00:00
|
|
|
} );
|
|
|
|
|
2016-03-05 00:57:34 +00:00
|
|
|
// Limit to 2 items outside the menu
|
|
|
|
if ( isOutsideMenu ) {
|
2015-10-16 23:18:25 +00:00
|
|
|
this.actionsButtonSelectWidget.addItems( [ linkButton ] );
|
2016-03-05 00:57:34 +00:00
|
|
|
outsideMenuItemCounter++;
|
2015-10-16 23:18:25 +00:00
|
|
|
} else {
|
|
|
|
this.menuPopupButtonWidget.getMenu().addItems( [ linkButton ] );
|
|
|
|
}
|
|
|
|
}
|
2016-03-05 00:57:34 +00:00
|
|
|
|
2015-12-22 23:16:32 +00:00
|
|
|
if ( this.bundle ) {
|
|
|
|
// In a bundle, we have table layout, so the icon is
|
|
|
|
// inserted into the content, and the 'mark as read'
|
|
|
|
// button is not floating, and should be at the end
|
2016-02-22 20:32:05 +00:00
|
|
|
this.$content.append(
|
2015-12-22 23:16:32 +00:00
|
|
|
$icon,
|
|
|
|
$message,
|
|
|
|
this.$actions,
|
|
|
|
this.markAsReadButton.$element
|
|
|
|
);
|
2016-02-22 20:32:05 +00:00
|
|
|
this.$element.append( this.$content );
|
2015-12-22 23:16:32 +00:00
|
|
|
} else {
|
2016-02-22 20:32:05 +00:00
|
|
|
this.$content.append(
|
2015-12-22 23:16:32 +00:00
|
|
|
this.markAsReadButton.$element,
|
|
|
|
$message,
|
2016-02-23 01:44:48 +00:00
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationItemWidget-content-table' )
|
|
|
|
.append( this.$actions )
|
2015-12-22 23:16:32 +00:00
|
|
|
);
|
2016-02-22 20:32:05 +00:00
|
|
|
this.$element.append( $icon, this.$content );
|
2015-12-22 23:16:32 +00:00
|
|
|
}
|
|
|
|
|
2016-06-03 18:47:13 +00:00
|
|
|
// Events
|
|
|
|
this.menuPopupButtonWidget.getMenu().connect( this, { choose: 'onPopupButtonWidgetChoose' } );
|
|
|
|
this.markAsReadButton.connect( this, { click: 'onMarkAsReadButtonClick' } );
|
|
|
|
|
2015-08-13 00:54:16 +00:00
|
|
|
this.$element
|
2016-04-10 13:31:02 +00:00
|
|
|
.addClass( 'mw-echo-ui-notificationItemWidget' )
|
2015-10-16 23:18:25 +00:00
|
|
|
.toggleClass( 'mw-echo-ui-notificationItemWidget-initiallyUnseen', !this.model.isSeen() && !this.bundle )
|
2016-05-31 01:08:25 +00:00
|
|
|
.toggleClass( 'mw-echo-ui-notificationItemWidget-bundled', this.bundle );
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
// Wrap the entire item with primary url
|
2015-10-16 23:18:25 +00:00
|
|
|
if ( this.model.getPrimaryUrl() ) {
|
|
|
|
this.$element.contents()
|
|
|
|
.wrapAll(
|
|
|
|
// HACK: Wrap the entire item with a link that takes
|
|
|
|
// the user to the primary url. This is not perfect,
|
|
|
|
// but it makes the behavior native to the browser rather
|
|
|
|
// than us listening to click events and opening new
|
|
|
|
// windows.
|
|
|
|
$( '<a>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationItemWidget-linkWrapper' )
|
|
|
|
.attr( 'href', this.model.getPrimaryUrl() )
|
2016-04-10 13:31:02 +00:00
|
|
|
.on( 'click', this.onPrimaryLinkClick.bind( this ) )
|
2015-10-16 23:18:25 +00:00
|
|
|
);
|
|
|
|
}
|
2015-08-13 00:54:16 +00:00
|
|
|
};
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
OO.inheritClass( mw.echo.ui.NotificationItemWidget, OO.ui.Widget );
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
/**
|
|
|
|
* Respond to primary link click.
|
|
|
|
* Override this in the descendents.
|
|
|
|
*
|
|
|
|
* @return {boolean} true
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.onPrimaryLinkClick = function () {
|
|
|
|
return true;
|
|
|
|
};
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2016-06-03 18:47:13 +00:00
|
|
|
/**
|
2016-08-05 21:44:55 +00:00
|
|
|
* Manage a click on a dynamic secondary link.
|
|
|
|
* We can't know what the link intends us to do in the API, so we trust the 'apiParams'
|
|
|
|
* to tell the controller. When the link is clicked, we will pass the information on
|
|
|
|
* to the controller, which will manage whatever promise and action is needed.
|
|
|
|
*
|
|
|
|
* NOTE: The messages are parsed as HTML. If user-input is expected
|
|
|
|
* please make sure to properly escape it.
|
|
|
|
*
|
|
|
|
* @param {mw.echo.ui.MenuItemWidget} item The selected item
|
2016-11-18 21:16:43 +00:00
|
|
|
* @return {boolean} False to prevent the native event
|
2016-06-03 18:47:13 +00:00
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.onPopupButtonWidgetChoose = function ( item ) {
|
2016-08-05 21:44:55 +00:00
|
|
|
var actionData = item && item.getActionData(),
|
|
|
|
messages = item && item.getConfirmationMessages(),
|
|
|
|
widget = this;
|
2016-06-03 18:47:13 +00:00
|
|
|
|
2016-08-05 21:44:55 +00:00
|
|
|
// Send to controller
|
|
|
|
item.pushPending();
|
|
|
|
this.controller.performDynamicAction( actionData, this.getModel().getSource() )
|
|
|
|
.then( function () {
|
|
|
|
var $title = $( '<p>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationItemWidget-notify-title' )
|
|
|
|
.append( $.parseHTML( messages.title ) ),
|
|
|
|
$description = $( '<p>' )
|
|
|
|
.addClass( 'mw-echo-ui-notificationItemWidget-notify-description' )
|
|
|
|
.append( $.parseHTML( messages.description ) ),
|
|
|
|
$confirmation;
|
|
|
|
|
|
|
|
// Get rid of the button
|
|
|
|
item.disconnect( this );
|
|
|
|
if ( item.isPrioritized() ) {
|
|
|
|
widget.actionsButtonSelectWidget.removeItems( [ item ] );
|
|
|
|
} else {
|
|
|
|
// It's inside the popup menu
|
|
|
|
widget.menuPopupButtonWidget.getMenu().removeItems( [ item ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure to hide either piece if it is empty
|
|
|
|
$title.toggle( !!$title.text() );
|
|
|
|
$description.toggle( !!$description.text() );
|
|
|
|
|
|
|
|
// Display confirmation
|
|
|
|
$confirmation = $( '<div>' )
|
|
|
|
.append( $title, $description );
|
|
|
|
|
|
|
|
// Send to mw.notify
|
|
|
|
mw.notify( $confirmation );
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Prevent the click propagation
|
|
|
|
return false;
|
2016-06-03 18:47:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Respond to mark as read button click
|
2016-11-18 21:16:43 +00:00
|
|
|
*
|
|
|
|
* @return {boolean} False to prevent the native event
|
2016-06-03 18:47:13 +00:00
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.onMarkAsReadButtonClick = function () {
|
2016-06-28 18:25:39 +00:00
|
|
|
// If we're marking read or unread, the notification was already seen.
|
|
|
|
// Remove the animation class
|
|
|
|
this.$element.removeClass( 'mw-echo-ui-notificationItemWidget-initiallyUnseen' );
|
2016-06-20 20:00:37 +00:00
|
|
|
this.markRead( !this.model.isRead() );
|
2016-07-13 18:30:55 +00:00
|
|
|
// Prevent propogation in case there's a link wrapping the content
|
|
|
|
// and the mark as read/unread button
|
|
|
|
return false;
|
2016-06-03 18:47:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark this notification as read
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @abstract
|
|
|
|
* @param {boolean} [isRead=true] Notification is marked as read
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.markRead = null;
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
/**
|
|
|
|
* Get the notification link
|
|
|
|
*
|
|
|
|
* @return {string} Notification link
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.getPrimaryUrl = function () {
|
|
|
|
return this.model.getPrimaryUrl();
|
|
|
|
};
|
2015-10-16 23:18:25 +00:00
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
/**
|
|
|
|
* Get the item id
|
|
|
|
*
|
|
|
|
* @return {number} Notification id
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.getTimestamp = function () {
|
|
|
|
return this.model.getTimestamp();
|
|
|
|
};
|
2015-10-16 23:18:25 +00:00
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
/**
|
|
|
|
* Get the notification Id
|
|
|
|
*
|
|
|
|
* @return {number} Notification id
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.getId = function () {
|
|
|
|
return this.model.getId();
|
|
|
|
};
|
2015-08-13 00:54:16 +00:00
|
|
|
|
|
|
|
/**
|
2016-04-10 13:31:02 +00:00
|
|
|
* Check whether this item is seen.
|
2015-08-13 00:54:16 +00:00
|
|
|
*
|
2016-04-10 13:31:02 +00:00
|
|
|
* @return {boolean} Item is seen
|
2015-08-13 00:54:16 +00:00
|
|
|
*/
|
2016-04-10 13:31:02 +00:00
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.isSeen = function () {
|
|
|
|
return this.model.isSeen();
|
|
|
|
};
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
/**
|
|
|
|
* Check whether this item is read.
|
|
|
|
*
|
|
|
|
* @return {boolean} Item is read
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.isRead = function () {
|
|
|
|
return this.model.isRead();
|
|
|
|
};
|
2015-08-13 00:54:16 +00:00
|
|
|
|
|
|
|
/**
|
2016-04-10 13:31:02 +00:00
|
|
|
* Check whether this item is foreign.
|
|
|
|
*
|
|
|
|
* @return {boolean} Item is foreign
|
2015-08-13 00:54:16 +00:00
|
|
|
*/
|
2016-04-10 13:31:02 +00:00
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.isForeign = function () {
|
|
|
|
return this.model.isForeign();
|
2015-08-13 00:54:16 +00:00
|
|
|
};
|
2015-09-23 00:15:28 +00:00
|
|
|
|
2016-01-21 19:29:21 +00:00
|
|
|
/**
|
2016-06-20 20:00:37 +00:00
|
|
|
* Toggle the function of the 'mark as read' buttons from 'mark as read' to 'mark as unread'
|
|
|
|
* and vice versa.
|
2016-03-04 22:44:22 +00:00
|
|
|
*
|
2016-06-20 20:00:37 +00:00
|
|
|
* @param {boolean} [showMarkAsRead] Show the 'mark as read' buttons
|
2016-03-04 22:44:22 +00:00
|
|
|
* - "false" means that the item is marked as read, whereby we show the user 'mark unread'
|
2016-06-20 20:00:37 +00:00
|
|
|
* buttons.
|
2016-03-04 22:44:22 +00:00
|
|
|
* - "true" means that the item is marked as unread and we show the user 'mark as read'
|
2016-06-20 20:00:37 +00:00
|
|
|
* buttons
|
2016-01-21 19:29:21 +00:00
|
|
|
*/
|
2016-06-20 20:00:37 +00:00
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.toggleMarkAsReadButtons = function ( showMarkAsRead ) {
|
|
|
|
showMarkAsRead = showMarkAsRead !== undefined ? showMarkAsRead : !this.model.isRead();
|
2016-01-21 19:29:21 +00:00
|
|
|
|
2016-06-20 20:00:37 +00:00
|
|
|
this.markAsReadButton.toggleState( showMarkAsRead );
|
2016-01-21 19:29:21 +00:00
|
|
|
this.menuPopupButtonWidget.toggle( !this.menuPopupButtonWidget.getMenu().isEmpty() );
|
|
|
|
};
|
|
|
|
|
2015-08-13 00:54:16 +00:00
|
|
|
/**
|
|
|
|
* Toggle the read state of the widget
|
|
|
|
*
|
|
|
|
* @param {boolean} [read] The current read state. If not given, the state will
|
|
|
|
* become the opposite of its current state.
|
|
|
|
*/
|
2015-11-12 19:37:56 +00:00
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.toggleRead = function ( read ) {
|
2015-08-13 00:54:16 +00:00
|
|
|
this.read = read !== undefined ? read : !this.read;
|
|
|
|
|
2015-11-12 19:37:56 +00:00
|
|
|
this.$element.toggleClass( 'mw-echo-ui-notificationItemWidget-unread', !this.read );
|
2016-01-21 19:29:21 +00:00
|
|
|
this.toggleMarkAsReadButtons( !this.read );
|
2015-08-13 00:54:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle the seen state of the widget
|
|
|
|
*
|
|
|
|
* @param {boolean} [seen] The current seen state. If not given, the state will
|
|
|
|
* become the opposite of its current state.
|
|
|
|
*/
|
2015-11-12 19:37:56 +00:00
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.toggleSeen = function ( seen ) {
|
2015-08-13 00:54:16 +00:00
|
|
|
this.seen = seen !== undefined ? seen : !this.seen;
|
|
|
|
|
|
|
|
this.$element
|
2015-11-12 19:37:56 +00:00
|
|
|
.toggleClass( 'mw-echo-ui-notificationItemWidget-unseen', !this.seen );
|
2015-08-13 00:54:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-04-10 13:31:02 +00:00
|
|
|
* Get the model associated with this widget.
|
2016-11-18 21:16:43 +00:00
|
|
|
*
|
|
|
|
* @return {mw.echo.dm.NotificationItem} Item model
|
2015-08-13 00:54:16 +00:00
|
|
|
*/
|
2015-11-12 19:37:56 +00:00
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.getModel = function () {
|
2015-08-13 00:54:16 +00:00
|
|
|
return this.model;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-04-10 13:31:02 +00:00
|
|
|
* Disconnect events when widget is destroyed.
|
2015-08-13 00:54:16 +00:00
|
|
|
*/
|
2016-04-10 13:31:02 +00:00
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.destroy = function () {
|
|
|
|
this.model.disconnect( this );
|
2015-08-13 00:54:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-04-10 13:31:02 +00:00
|
|
|
* Remove the 'initiallyUnseen' class, which was only used for the
|
|
|
|
* unseen animation when the user has first seen it.
|
2015-08-13 00:54:16 +00:00
|
|
|
*/
|
2016-04-10 13:31:02 +00:00
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.resetInitiallyUnseen = function () {
|
|
|
|
this.$element.removeClass( 'mw-echo-ui-notificationItemWidget-initiallyUnseen' );
|
2015-08-13 00:54:16 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Declares whether this widget is a cloned fake.
|
|
|
|
*
|
|
|
|
* @return {boolean} false
|
|
|
|
*/
|
|
|
|
mw.echo.ui.NotificationItemWidget.prototype.isFake = function () {
|
|
|
|
return false;
|
|
|
|
};
|
2016-11-18 21:16:43 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|