2015-08-13 00:54:16 +00:00
|
|
|
( function ( mw, $ ) {
|
|
|
|
/**
|
2016-04-10 13:31:02 +00:00
|
|
|
* Notification item data structure.
|
2015-08-13 00:54:16 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @mixins OO.EventEmitter
|
2016-04-10 13:31:02 +00:00
|
|
|
* @mixins OO.SortedEmitterList
|
2015-08-13 00:54:16 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {number} id Notification id,
|
|
|
|
* @param {Object} [config] Configuration object
|
2015-10-16 23:18:25 +00:00
|
|
|
* @cfg {string} [iconUrl] A URL for the given icon.
|
|
|
|
* @cfg {string} [iconType] A string noting the icon type.
|
|
|
|
* @cfg {Object} [content] The message object defining the text for the header and,
|
|
|
|
* optionally, the body of the notification.
|
|
|
|
* @cfg {string} [content.header=''] The header text of the notification
|
|
|
|
* @cfg {string} [content.body=''] The body text of the notification
|
2015-08-13 00:54:16 +00:00
|
|
|
* @cfg {string} [category] The category of this notification. The category identifies
|
|
|
|
* where the notification originates from.
|
2016-04-10 13:31:02 +00:00
|
|
|
* @cfg {string} [type='message'] The notification type 'message' or 'alert'
|
2015-08-13 00:54:16 +00:00
|
|
|
* @cfg {boolean} [read=false] State the read state of the option
|
|
|
|
* @cfg {boolean} [seen=false] State the seen state of the option
|
|
|
|
* @cfg {string} [timestamp] Notification timestamp in Mediawiki timestamp format
|
|
|
|
* @cfg {string} [primaryUrl] Notification primary link in raw url format
|
2015-11-25 04:07:54 +00:00
|
|
|
* @cfg {boolean} [foreign=false] This notification is from a foreign source
|
2016-05-19 20:55:21 +00:00
|
|
|
* @cfg {boolean} [bundled=false] This notification is part of a bundle
|
2015-11-25 04:07:54 +00:00
|
|
|
* @cfg {string} [source] The source this notification is coming from, if it is foreign
|
2015-10-16 23:18:25 +00:00
|
|
|
* @cfg {Object[]} [secondaryUrls] An array of objects defining the secondary URLs
|
|
|
|
* for this notification. The secondary URLs are expected to have this structure:
|
|
|
|
* {
|
|
|
|
* "iconType": "userAvatar", // A symbolic name for the icon.
|
|
|
|
* // Will render as oo-ui-icon-* class.
|
|
|
|
* "label": "", // The label for the link
|
|
|
|
* "prioritized": true/false, // Prioritized links are outside of the popup
|
|
|
|
* // menu, whenever possible.
|
|
|
|
* "url": "..." // The url for the secondary link
|
|
|
|
* }
|
2015-08-13 00:54:16 +00:00
|
|
|
*/
|
2016-04-10 13:31:02 +00:00
|
|
|
mw.echo.dm.NotificationItem = function MwEchoDmNotificationItem( id, config ) {
|
2015-08-13 00:54:16 +00:00
|
|
|
var date = new Date(),
|
|
|
|
normalizeNumber = function ( number ) {
|
|
|
|
return ( number < 10 ? '0' : '' ) + String( number );
|
|
|
|
},
|
|
|
|
fallbackMWDate = date.getUTCFullYear() +
|
|
|
|
normalizeNumber( date.getMonth() ) +
|
|
|
|
normalizeNumber( date.getUTCDate() ) +
|
|
|
|
normalizeNumber( date.getUTCHours() ) +
|
|
|
|
normalizeNumber( date.getUTCMinutes() ) +
|
|
|
|
normalizeNumber( date.getUTCSeconds() );
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
config = config || {};
|
|
|
|
|
2015-08-13 00:54:16 +00:00
|
|
|
// Mixin constructor
|
|
|
|
OO.EventEmitter.call( this );
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
// Properties
|
|
|
|
this.id = id;
|
2015-10-16 23:18:25 +00:00
|
|
|
this.content = $.extend( { header: '', body: '' }, config.content );
|
2015-08-13 00:54:16 +00:00
|
|
|
this.category = config.category || '';
|
2016-04-10 13:31:02 +00:00
|
|
|
this.type = config.type || 'message';
|
2015-11-25 04:07:54 +00:00
|
|
|
this.foreign = !!config.foreign;
|
2016-05-19 20:55:21 +00:00
|
|
|
this.bundled = !!config.bundled;
|
2015-12-23 18:33:59 +00:00
|
|
|
this.source = config.source || '';
|
2015-10-16 23:18:25 +00:00
|
|
|
this.iconType = config.iconType;
|
|
|
|
this.iconURL = config.iconURL;
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2015-10-16 23:18:25 +00:00
|
|
|
this.read = !!config.read;
|
|
|
|
this.seen = !!config.seen;
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2015-10-28 20:47:54 +00:00
|
|
|
this.timestamp = config.timestamp || fallbackMWDate;
|
2015-08-13 00:54:16 +00:00
|
|
|
this.setPrimaryUrl( config.primaryUrl );
|
2015-10-16 23:18:25 +00:00
|
|
|
this.setSecondaryUrls( config.secondaryUrls );
|
2015-08-13 00:54:16 +00:00
|
|
|
};
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
/* Initialization */
|
2015-08-13 00:54:16 +00:00
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
OO.initClass( mw.echo.dm.NotificationItem );
|
2015-08-13 00:54:16 +00:00
|
|
|
OO.mixinClass( mw.echo.dm.NotificationItem, OO.EventEmitter );
|
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
2016-04-10 13:31:02 +00:00
|
|
|
* @event update
|
2015-08-13 00:54:16 +00:00
|
|
|
*
|
2016-04-10 13:31:02 +00:00
|
|
|
* Item details have changed or were updated
|
2015-08-13 00:54:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get NotificationItem id
|
2016-03-07 13:29:15 +00:00
|
|
|
*
|
2015-08-13 00:54:16 +00:00
|
|
|
* @return {string} NotificationItem Id
|
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.getId = function () {
|
|
|
|
return this.id;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-10-16 23:18:25 +00:00
|
|
|
* Get NotificationItem content header
|
2016-03-07 13:29:15 +00:00
|
|
|
*
|
2015-10-16 23:18:25 +00:00
|
|
|
* @return {string} NotificationItem content
|
2015-08-13 00:54:16 +00:00
|
|
|
*/
|
2015-10-16 23:18:25 +00:00
|
|
|
mw.echo.dm.NotificationItem.prototype.getContentHeader = function () {
|
|
|
|
return this.content.header;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get NotificationItem content body
|
2016-03-07 13:29:15 +00:00
|
|
|
*
|
2015-10-16 23:18:25 +00:00
|
|
|
* @return {string} NotificationItem content body
|
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.getContentBody = function () {
|
|
|
|
return this.content.body;
|
2015-08-13 00:54:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get NotificationItem category
|
2016-03-07 13:29:15 +00:00
|
|
|
*
|
2015-08-13 00:54:16 +00:00
|
|
|
* @return {string} NotificationItem category
|
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.getCategory = function () {
|
|
|
|
return this.category;
|
|
|
|
};
|
2016-04-10 13:31:02 +00:00
|
|
|
|
2015-09-29 00:07:37 +00:00
|
|
|
/**
|
|
|
|
* Get NotificationItem type
|
2016-03-07 13:29:15 +00:00
|
|
|
*
|
2015-09-29 00:07:37 +00:00
|
|
|
* @return {string} NotificationItem type
|
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.getType = function () {
|
|
|
|
return this.type;
|
|
|
|
};
|
2015-08-13 00:54:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether this notification item is read
|
2016-03-07 13:29:15 +00:00
|
|
|
*
|
2015-08-13 00:54:16 +00:00
|
|
|
* @return {boolean} Notification item is read
|
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.isRead = function () {
|
|
|
|
return this.read;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether this notification item is seen
|
2016-03-07 13:29:15 +00:00
|
|
|
*
|
2015-08-13 00:54:16 +00:00
|
|
|
* @return {boolean} Notification item is seen
|
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.isSeen = function () {
|
|
|
|
return this.seen;
|
|
|
|
};
|
|
|
|
|
2015-10-16 23:18:25 +00:00
|
|
|
/**
|
2015-11-25 04:07:54 +00:00
|
|
|
* Check whether this notification item is foreign
|
2016-03-07 13:29:15 +00:00
|
|
|
*
|
2015-11-25 04:07:54 +00:00
|
|
|
* @return {boolean} Notification item is foreign
|
2015-10-16 23:18:25 +00:00
|
|
|
*/
|
2015-11-25 04:07:54 +00:00
|
|
|
mw.echo.dm.NotificationItem.prototype.isForeign = function () {
|
|
|
|
return this.foreign;
|
2015-10-16 23:18:25 +00:00
|
|
|
};
|
|
|
|
|
2016-05-19 20:55:21 +00:00
|
|
|
/**
|
|
|
|
* Check whether this notification item is part of a bundle
|
|
|
|
*
|
|
|
|
* @return {boolean} Notification item is part of a bundle
|
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.isBundled = function () {
|
|
|
|
return this.bundled;
|
|
|
|
};
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
/**
|
|
|
|
* Set this notification item as foreign
|
|
|
|
*
|
|
|
|
* @param {boolean} isForeign Notification item is foreign
|
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.setForeign = function ( isForeign ) {
|
|
|
|
this.foreign = isForeign;
|
|
|
|
};
|
|
|
|
|
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.
|
2016-04-10 13:31:02 +00:00
|
|
|
* @fires update
|
2015-08-13 00:54:16 +00:00
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.toggleRead = function ( read ) {
|
|
|
|
read = read !== undefined ? read : !this.read;
|
|
|
|
if ( this.read !== read ) {
|
|
|
|
this.read = read;
|
2016-04-10 13:31:02 +00:00
|
|
|
this.emit( 'update' );
|
2015-10-28 20:47:54 +00:00
|
|
|
this.emit( 'sortChange' );
|
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.
|
2016-04-10 13:31:02 +00:00
|
|
|
* @fires update
|
2015-08-13 00:54:16 +00:00
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.toggleSeen = function ( seen ) {
|
|
|
|
seen = seen !== undefined ? seen : !this.seen;
|
|
|
|
if ( this.seen !== seen ) {
|
|
|
|
this.seen = seen;
|
2016-04-10 13:31:02 +00:00
|
|
|
this.emit( 'update' );
|
2015-08-13 00:54:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the notification timestamp
|
|
|
|
*
|
|
|
|
* @return {number} Notification timestamp in Mediawiki timestamp format
|
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.getTimestamp = function () {
|
|
|
|
return this.timestamp;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the notification link
|
|
|
|
*
|
|
|
|
* @param {string} link Notification url
|
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.setPrimaryUrl = function ( link ) {
|
|
|
|
this.primaryUrl = link;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the notification link
|
|
|
|
*
|
|
|
|
* @return {string} Notification url
|
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.getPrimaryUrl = function () {
|
|
|
|
return this.primaryUrl;
|
|
|
|
};
|
|
|
|
|
2015-10-16 23:18:25 +00:00
|
|
|
/**
|
|
|
|
* Get the notification icon URL
|
|
|
|
*
|
|
|
|
* @return {string} Notification icon URL
|
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.getIconURL = function () {
|
|
|
|
return this.iconURL;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the notification icon type
|
|
|
|
*
|
|
|
|
* @return {string} Notification icon type
|
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.getIconType = function () {
|
|
|
|
return this.iconType;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the notification's secondary links
|
|
|
|
* See constructor documentation for the structure of these links objects.
|
|
|
|
*
|
|
|
|
* @param {Object[]} links Secondary url definitions
|
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.setSecondaryUrls = function ( links ) {
|
|
|
|
this.secondaryUrls = links || [];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the notification's secondary links
|
|
|
|
*
|
|
|
|
* @return {Object[]} Secondary url definitions
|
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.getSecondaryUrls = function () {
|
|
|
|
return this.secondaryUrls;
|
|
|
|
};
|
2015-12-23 18:33:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the notification's source
|
|
|
|
*
|
|
|
|
* @return {string} Notification source
|
|
|
|
*/
|
|
|
|
mw.echo.dm.NotificationItem.prototype.getSource = function () {
|
|
|
|
return this.source;
|
|
|
|
};
|
2016-04-10 13:31:02 +00:00
|
|
|
} )( mediaWiki, jQuery );
|