mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 12:53:13 +03:00
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
|
var when = require('when'),
|
||
|
_ = require('underscore'),
|
||
|
// Holds the persistent notifications
|
||
|
notificationsStore = [],
|
||
|
notifications;
|
||
|
|
||
|
// ## Notifications
|
||
|
notifications = {
|
||
|
|
||
|
browse: function browse() {
|
||
|
return when(notificationsStore);
|
||
|
},
|
||
|
|
||
|
// #### Destroy
|
||
|
|
||
|
// **takes:** an identifier object ({id: id})
|
||
|
destroy: function destroy(i) {
|
||
|
notificationsStore = _.reject(notificationsStore, function (element) {
|
||
|
return element.id === i.id;
|
||
|
});
|
||
|
// **returns:** a promise for remaining notifications as a json object
|
||
|
return when(notificationsStore);
|
||
|
},
|
||
|
|
||
|
destroyAll: function destroyAll() {
|
||
|
notificationsStore = [];
|
||
|
return when(notificationsStore);
|
||
|
},
|
||
|
|
||
|
// #### Add
|
||
|
|
||
|
// **takes:** a notification object of the form
|
||
|
// ```
|
||
|
// msg = {
|
||
|
// type: 'error', // this can be 'error', 'success', 'warn' and 'info'
|
||
|
// message: 'This is an error', // A string. Should fit in one line.
|
||
|
// status: 'persistent', // or 'passive'
|
||
|
// id: 'auniqueid' // A unique ID
|
||
|
// };
|
||
|
// ```
|
||
|
add: function add(notification) {
|
||
|
// **returns:** a promise for all notifications as a json object
|
||
|
return when(notificationsStore.push(notification));
|
||
|
}
|
||
|
};
|
||
|
|
||
|
module.exports = notifications;
|