UNPKG

@web-atoms/core-docs

Version:
95 lines 3.72 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports", "../services/NavigationService", "./AtomViewModel"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AtomWindowViewModel = void 0; const NavigationService_1 = require("../services/NavigationService"); const AtomViewModel_1 = require("./AtomViewModel"); /** * This view model should be used with WindowService to create and open window. * * This view model has `close` and `cancel` methods. `close` method will * close the window and will resolve the given result in promise. `cancel` * will reject the given promise. * * @example * * @Inject windowService: NavigationService * var result = await * windowService.openPage( * ModuleFiles.views.NewWindow, * { * title: "Edit Object", * data: { * id: 4 * } * }); * * * * class NewTaskWindowViewModel extends AtomWindowViewModel{ * * .... * save(){ * * // close and send result * this.close(task); * * } * .... * * } * * @export * @class AtomWindowViewModel * @extends {AtomViewModel} */ class AtomWindowViewModel extends AtomViewModel_1.AtomViewModel { /** * This will broadcast `atom-window-close:windowName`. * WindowService will close the window on receipt of such message and * it will resolve the promise with given result. * * this.close(someResult); * * @param {*} [result] * @memberof AtomWindowViewModel */ close(result) { this.app.broadcast(`atom-window-close:${this.windowName}`, result); } /** * This will return true if this view model is safe to cancel and close */ cancel() { return __awaiter(this, void 0, void 0, function* () { if (this.closeWarning) { const navigationService = this.app.resolve(NavigationService_1.NavigationService); if (!(yield navigationService.confirm(this.closeWarning, "Are you sure?"))) { return false; } } this.app.broadcast(`atom-window-cancel:${this.windowName}`, "cancelled"); return true; }); } } exports.AtomWindowViewModel = AtomWindowViewModel; }); //# sourceMappingURL=AtomWindowViewModel.js.map