UNPKG

@web-atoms/core

Version:
113 lines (112 loc) 4.13 kB
System.register(["tslib", "../../core/types", "../../core/XNode", "../../services/NavigationService", "../styles/AtomPageLinkStyle", "./AtomControl"], function (_export, _context) { "use strict"; var __awaiter, CancelToken, XNode, NavigationService, AtomPageLinkStyle, AtomControl, AtomPageLink; _export("AtomPageLink", void 0); return { setters: [function (_tslib) { __awaiter = _tslib.__awaiter; }, function (_coreTypes) { CancelToken = _coreTypes.CancelToken; }, function (_coreXNode) { XNode = _coreXNode.default; }, function (_servicesNavigationService) { NavigationService = _servicesNavigationService.NavigationService; }, function (_stylesAtomPageLinkStyle) { AtomPageLinkStyle = _stylesAtomPageLinkStyle.default; }, function (_AtomControl) { AtomControl = _AtomControl.AtomControl; }], execute: function () { _export("AtomPageLink", AtomPageLink = class AtomPageLink extends AtomControl { constructor(app, e) { super(app, e || document.createElement("span")); } preCreate() { this.page = null; this.parameters = null; this.isOpen = false; this.options = null; this.modal = false; this.toggle = true; this.defaultControlStyle = AtomPageLinkStyle; super.preCreate(); this.bindEvent(this.element, "click", () => { if (this.modal) { return this.openPopup(); } return this.app.runAsync(() => this.openPopup()); }); this.bind(this.element, "styleClass", [["this", "isOpen"]], false, v => ({ [this.controlStyle.name]: 1, "is-open": v, "atom-page-link": 1 }), this); this.registerDisposable({ dispose: () => { const ct = this.cancelToken; if (ct) { ct.cancel(); } } }); } openPopup() { return __awaiter(this, void 0, void 0, function* () { if (this.cancelToken) { if (this.toggle) { this.cancelToken.cancel(); this.cancelToken = null; this.isOpen = false; return; } else { this.cancelToken.dispose(); } } this.cancelToken = new CancelToken(); let o = null; try { const navigationService = this.app.resolve(NavigationService); const pt = this.page; if (!pt) { console.error("No popup template specified in PopupButton"); return; } this.isOpen = true; o = this.options ? Object.assign(Object.assign({}, this.options), { cancelToken: this.cancelToken }) : { cancelToken: this.cancelToken }; o.onInit = view => { view.setLocalValue(view.element, "styleClass", `${this.controlStyle.name} page`); }; const getParametersEvent = new CustomEvent("getParameters", { detail: {} }); this.element.dispatchEvent(getParametersEvent); const p = getParametersEvent.detail.parameters || this.parameters; const result = yield navigationService.openPage(pt, p, o); this.element.dispatchEvent(new CustomEvent("result", { detail: result })); } catch (e) { if (this.element) { this.element.dispatchEvent(new CustomEvent("error", { detail: e })); } } finally { this.cancelToken = null; this.isOpen = false; if (o) { o.onInit = null; } } }); } }); AtomPageLink.page = XNode.prepare("page", true, true); } }; }); //# sourceMappingURL=AtomPageLink.js.map