Debian Codegraph @

extensions/Echo/modules/ui/mw.echo.ui.DatedSubGroupListWidget.js

raw symbols SCIP
1 ( function () {
2 /* global moment:false */
3 /**
4 * A sub group widget that displays notifications divided by dates.
5 *
6 * @class
7 * @extends mw.echo.ui.SubGroupListWidget
8 *
9 * @constructor
10 * @param {mw.echo.Controller} controller Notifications controller
11 * @param {mw.echo.dm.SortedList} listModel Notifications list model for this source
12 * @param {Object} [config] Configuration object
13 */
14 mw.echo.ui.DatedSubGroupListWidget = function MwEchoUiDatedSubGroupListWidget( controller, listModel, config ) {
15 const now = moment(),
16 $primaryDate = $( '<span>' )
17 .addClass( 'mw-echo-ui-datedSubGroupListWidget-title-primary' ),
18 $secondaryDate = $( '<span>' )
19 .addClass( 'mw-echo-ui-datedSubGroupListWidget-title-secondary' ),
20 $title = $( '<h2>' )
21 .addClass( 'mw-echo-ui-datedSubGroupListWidget-title' )
22 .append( $primaryDate, $secondaryDate );
23
24 // Parent constructor
25 mw.echo.ui.DatedSubGroupListWidget.super.call( this, controller, listModel, Object.assign( {
26 // Since this widget is defined as a dated list, we sort
27 // its items according to timestamp without consideration
28 // of read state or foreignness.
29 sortingCallback: function ( a, b ) {
30 // Reverse sorting
31 if ( b.getTimestamp() < a.getTimestamp() ) {
32 return -1;
33 } else if ( b.getTimestamp() > a.getTimestamp() ) {
34 return 1;
35 }
36
37 // Fallback on IDs
38 return b.getId() - a.getId();
39 }
40 }, config ) );
41
42 // Round all dates to the day they're in, as if they all happened at 00:00h
43 const stringTimestamp = moment.utc( this.model.getTimestamp() ).local().format( 'YYYY-MM-DD' );
44 const momentTimestamp = moment( stringTimestamp );
45 const diff = now.diff( momentTimestamp, 'weeks' );
46 const fullDate = momentTimestamp.format( 'LL' );
47
48 $primaryDate.text( fullDate );
49 if ( diff === 0 ) {
50 $secondaryDate.text( fullDate );
51 momentTimestamp.locale( 'echo-shortRelativeTime' );
52 $primaryDate.text( momentTimestamp.calendar() );
53 }
54
55 this.title.setLabel( $title );
56
57 this.$element
58 .addClass( 'mw-echo-ui-datedSubGroupListWidget' );
59 };
60
61 /* Initialization */
62
63 OO.inheritClass( mw.echo.ui.DatedSubGroupListWidget, mw.echo.ui.SubGroupListWidget );
64 }() );