comindware.core.ui
Version:
Comindware Core UI provides the basic components like editors, lists, dropdowns, popups that we so desperately need while creating Marionette-based single-page applications.
53 lines (46 loc) • 1.65 kB
JavaScript
import NotificationCollectionView from '../views/NotificationCollectionView';
const defaultTimeOfShow = 12000;
export default class ToastNotificationService {
static initialize(options = {}) {
this.notificationCollection = new Backbone.Collection();
options.toastNotificationRegion.show(
new NotificationCollectionView({
collection: this.notificationCollection
})
);
this.notificationTypes = {
INFO: 'Info',
ERROR: 'Error',
SUCCESS: 'Success'
};
Object.assign(this, Backbone.Events);
}
static add(message, type = this.notificationTypes.SUCCESS, options = {}) {
if (!message) {
return;
}
let text = message;
let title = null;
if (_.isObject(message)) {
text = message.text;
title = message.title;
}
const notificationModel = new Backbone.Model({
type,
title,
text,
time: options.time === 0 ? options.time : options.time || defaultTimeOfShow,
showMoreText: options.showMoreText || Localizer.get('CORE.SERVICES.MESSAGE.ERRORS.SHOWDETAILS')
});
if (options.showMore) {
notificationModel.showMore = options.showMore;
}
this.notificationCollection.add(notificationModel, { at: this.notificationCollection.length });
this.trigger('publish:notification', {
message: title || text,
affectedText: title ? text : '',
severity: type || 'Info',
options
});
}
}