/** * QCObjects Framework SDK * ________________ * * Author: Jean Machuca * * Cross Browser Javascript Framework for MVC Patterns * QCObjects is licensed under the MIT License * [LICENSE] (https://github.com/QCObjects/qcobjects-sdk/blob/main/LICENSE.txt) * * Copyright (C) 2015 Jean Machuca, * * Everyone is permitted to copy and distribute verbatim copies of this * license document, but changing it is not allowed. */ "use strict"; import { Package, Component, _DOMCreateElement, New, _super_ } from "qcobjects"; import { Fade, Move } from "./org.qcobjects.effects"; export class NotificationComponent extends Component { cached= false; tplsource= "inline"; shadowed= false; kinds:string[]; template: string; constructor (o:any){ o.name= "notification"; o.body = _DOMCreateElement("div") as HTMLElement; super(o); this.template= `

{{title}} {{message}}

`; this.kinds=["danger", "success", "info", "warning"]; } display(element:HTMLElement) { const _display_ = function (element:HTMLElement){ element.style.display="block"; const appearEffect = New(Move,{ duration:900, apply (element:HTMLElement){ _super_("Fade","apply").call(this,element,0,1); _super_("Move","apply").call(this,element,0,-document.body.clientHeight,0,0); } }); const disappearEffect = New(Move,{ duration:650, apply (element:HTMLElement){ _super_("Fade","apply").call(this,element,1,0); _super_("Move","apply").call(this,element,0,0,0,-document.body.clientHeight); } }); appearEffect.apply(element); setTimeout(function (){ disappearEffect.apply(element); },2000); }; (element as any).subelements("div.notification_background").map((element:HTMLElement):any=> {return (new Fade ({duration:500})).apply(element,0,1);} ); (element as any).subelements("div.notification").map((element:any)=>_display_(element)); setTimeout(function (){ element.remove(); },2200); } static success(message:string) { const c = New(NotificationComponent, { name: "notification", shadowed: true, body: _DOMCreateElement("div"), data: { kind: "success", title: "Success!", message: `${message}...` } }); document.body.append(c); const _componentRoot = (c.shadowed)?(c.shadowRoot.host):(c.body); c.display(_componentRoot); } static danger(message:string) { const c = New(NotificationComponent, { name: "notification", shadowed: true, body: _DOMCreateElement("div"), data: { kind: "danger", title: "Danger!", message: `${message}...` } }); document.body.append(c); const _componentRoot = (c.shadowed)?(c.shadowRoot.host):(c.body); c.display(_componentRoot); } static info(message:string) { const c = New(NotificationComponent, { name: "notification", shadowed: true, body: _DOMCreateElement("div"), data: { kind: "info", title: "Info!", message: `${message}...` } }); document.body.append(c); const _componentRoot = (c.shadowed)?(c.shadowRoot.host):(c.body); c.display(_componentRoot); } static warning(message:string) { const c = New(NotificationComponent, { name: "notification", shadowed: true, body: _DOMCreateElement("div"), data: { kind: "warning", title: "Warning!", message: `${message}...` } }); document.body.append(c); const _componentRoot = (c.shadowed)?(c.shadowRoot.host):(c.body); c.display(_componentRoot); } } Package("org.quickcorp.components.notifications", [ NotificationComponent ]);