mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-11 07:26:29 +00:00
c0a464e425
* Add ISO 8601 date format to notification output This is actually supposed to be the only output date format used, per https://www.mediawiki.org/wiki/API:Data_formats#Timestamps , but I'm not doing anything to deprecate the others right now. * Change wgEchoSeenTime to use ISO 8601. mwgrep and extension grep do not show any usages. However, since it is a breaking change, to minimize disruption, I'm also using this opportunity to change 'message' to 'notice'. * Remove wgEchoInitialNotifCount. I was going to also change 'message' to 'notice' here too, but then I saw it was totally unused. (It was read in Echo to populate a JS variable, but then it was unused.) * Make sure the Special:Notifications page aggregation by days is done by local days, even though the timestamp per item is still UTC. This is to make sure the days are displayed correctly in the local timezone. * Change all reverse sorting callbacks to handle comparisons of ISO 8601. Bug: T141413 Change-Id: I20271345c7d350dc3e7f467288e5cdc98e6250cc
218 lines
5.7 KiB
JavaScript
218 lines
5.7 KiB
JavaScript
( function ( mw, $ ) {
|
|
/**
|
|
* 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
|
|
* @cfg {jQuery} [$overlay] A jQuery element functioning as an overlay
|
|
* for popups.
|
|
*/
|
|
mw.echo.ui.BundleNotificationItemWidget = function MwEchoUiBundleNotificationItemWidget( controller, model, config ) {
|
|
config = config || {};
|
|
|
|
// Parent constructor
|
|
mw.echo.ui.BundleNotificationItemWidget.parent.call( this, controller, model, config );
|
|
|
|
this.controller = controller;
|
|
this.model = model;
|
|
|
|
this.toggleMarkAsReadButtons( true );
|
|
|
|
this.listWidget = new mw.echo.ui.SortedListWidget(
|
|
// Sorting callback
|
|
function ( a, b ) {
|
|
// Reverse sorting
|
|
if ( b.getTimestamp() < a.getTimestamp() ) {
|
|
return -1;
|
|
} else if ( b.getTimestamp() > a.getTimestamp() ) {
|
|
return 1;
|
|
}
|
|
|
|
// Fallback on IDs
|
|
return b.getId() - a.getId();
|
|
},
|
|
// Config
|
|
{
|
|
classes: [ 'mw-echo-ui-bundleNotificationItemWidget-group' ],
|
|
timestamp: this.getTimestamp(),
|
|
$overlay: this.$overlay
|
|
}
|
|
);
|
|
|
|
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' );
|
|
|
|
// 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' } );
|
|
|
|
// 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.onPrimaryLinkClick = function () {
|
|
// Log notification click
|
|
|
|
mw.echo.logger.logInteraction(
|
|
mw.echo.Logger.static.actions.notificationClick,
|
|
mw.echo.Logger.static.context.popup,
|
|
this.getModel().getId(),
|
|
this.getModel().getCategory(),
|
|
false,
|
|
// Source of this notification if it is cross-wiki
|
|
this.bundle ? this.getModel().getSource() : ''
|
|
);
|
|
};
|
|
|
|
/**
|
|
* @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 () {
|
|
var widget = this;
|
|
this.getList().addItems( this.model.getList().getItems().map( function ( singleNotifModel ) {
|
|
return new mw.echo.ui.SingleNotificationItemWidget(
|
|
widget.controller,
|
|
singleNotifModel,
|
|
{
|
|
$overlay: widget.$overlay,
|
|
bundle: true
|
|
}
|
|
);
|
|
} ) );
|
|
};
|
|
|
|
/**
|
|
* Update item state when the item model changes.
|
|
*/
|
|
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 () {
|
|
var widget = this;
|
|
|
|
this.toggleExpanded( !this.expanded );
|
|
this.updateExpandButton();
|
|
|
|
if ( !this.expanded ) {
|
|
return;
|
|
}
|
|
|
|
// Log the expand action
|
|
mw.echo.logger.logInteraction(
|
|
mw.echo.Logger.static.actions.notificationBundleExpand,
|
|
mw.echo.Logger.static.context.popup,
|
|
widget.getModel().getId(),
|
|
widget.getModel().getCategory()
|
|
);
|
|
};
|
|
|
|
/**
|
|
* 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 ) {
|
|
this.getList().$element.slideDown();
|
|
} else {
|
|
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'
|
|
);
|
|
};
|
|
|
|
/**
|
|
* 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;
|
|
};
|
|
} )( mediaWiki, jQuery );
|