Core.UI = Core.UI || {}; Core.UI.Notification = class extends _core { /** * Instantiate notification. * @param {string} html */ constructor(data) { super(); if (!data.selector) { data.selector = '.notification.button'; } this.data = data; } /** * Display this button in the notification list. */ render() { if (!this.data.html) { return; } if (!this.getButton().exists()) { Core.UI.Notifications.getContainer().prepend(this.data.html); } if (!this.getButton().exists()) { return; } this.getButton().attr('data-html', this.data.properties.popup_html); this.getButton().removeClass(this.getButton().attr('data-color')); this.getButton().attr('data-color', this.data.properties.color); this.getButton().addClass(this.getButton().attr('data-color')); this.getButton().attr('data-action', this.data.properties.action); if (this.data.properties.status) { this.getButton() .transition('set looping') .transition(this.data.properties.status); } else { this.getButton().transition('remove looping'); } this.bind(); } /** * * @returns jQuery */ getButton() { if (!this.$button) { this.$button = Core.UI.Notifications.getContainer().find(this.data.selector + '[data-id="' + this.data.properties.id + '"]'); } return this.$button; } /** * Bind user interaction. */ bind() { this.getButton() .off('click') .rebind( 'click', () => this.clicked() ); this.getButton().popup({ position: 'bottom right', onShow: function() { let $popup = $(this); $popup.addClass('flowing'); Core.UI.Bind.get($popup); } }); } /** * Process user click/tap. */ clicked() { if (this.data.properties.action) { let uri = this.data.properties.action.split(':'); switch (uri[0]) { case 'url': window.open(uri[1]); break; case 'uri': Server.call( uri[1], { func: this.action }, function (data) { location.reload(); }, null, null ); break; case 'page': let parameters = this.data.properties.action_parameters; if (_.isObject(parameters)) { parameters = JSON.stringify(parameters); } eval(`${uri[1]}.open(${parameters})`); break; case 'modal': eval(`new ${uri[1]}(${this.data.properties.action_parameters})`); break; } } else { switch (this.data.properties.action) { case 'refresh': location.reload(); break; case 'logout': Core.User.logout(); break; } } } };