UNPKG

dynamicsmobile

Version:

Allows development of off-line mobile and web business apps over the Dynamics Mobile platform. More info on https://www.dynamicsmobile.com

152 lines 6.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MobileUserInterfaceService = void 0; const tslib_1 = require("tslib"); const injectable_1 = require("../ioc/injectable"); const application_context_service_1 = require("../lib-core/application-context-service"); const configuration_service_1 = require("../lib-core/configuration-service"); const context_service_1 = require("../lib-core/context-service"); const userinterface_service_1 = require("../lib-core/userinterface-service"); const device_service_1 = require("../lib-core/device-service"); const dms_root_container_1 = require("../ioc/dms-root-container"); const bundle_1 = require("framework7/bundle"); const $ = bundle_1.Dom7; /** * Provides user-interface related features like navigation, task launching and others */ let MobileUserInterfaceService = exports.MobileUserInterfaceService = class MobileUserInterfaceService extends userinterface_service_1.UserInterfaceService { constructor(dms, ContextService, ConfigurationService) { super(dms, ContextService, ConfigurationService); } /** * shows a default toast message, which stays on screen for 5 seconds and faded away automatically */ showToast(msg) { if (!msg) return; if (typeof msg === 'string') { if (this.dms && this.dms.app && this.dms.app.toast) this.dms.app.toast.create({ text: msg, closeTimeout: 5000, }).open(); } else { if (this.dms && this.dms.app && this.dms.app.toast) this.dms.app.toast.create({ position: !msg.toastOrSnack || msg.toastOrSnack == 'toast' ? 'bottom' : 'top', text: msg.content, icon: msg.icon, cssClass: msg.cssClass, closeButtonText: msg.closeButtonText ? msg.closeButtonText : 'X', closeButton: msg.dismissible == true ? true : false, closeTimeout: msg.delay ? msg.delay : 4000, }).open(); } } /** * opens a preloader on the screen, which blocks the UI - e.g. the user must wait until hideLoading is called */ showLoading() { return tslib_1.__awaiter(this, void 0, void 0, function* () { // if (globals && globals.dms && globals.dms.app && globals.dms.app.preloader) // globals.dms.app.preloader.show(); if (this.dms && this.dms.app && this.dms.app.preloader) this.dms.app.preloader.show(); }); } /** *hides the preloader message which was opened with showLoading **/ hideLoading() { return tslib_1.__awaiter(this, void 0, void 0, function* () { // if (globals && globals.dms && globals.dms.app && globals.dms.app.preloader) // globals.dms.app.preloader.hide(); if (this.dms && this.dms.app && this.dms.app.preloader) this.dms.app.preloader.hide(); }); } /** * shows a standard (alert) message on the screen */ showMessage(message) { if (this.dms && this.dms.app && this.dms.app.dialog) { this.hideLoading().then(() => { this.dms.app.dialog.alert(message, 'Dynamics Mobile'); }); } else { throw new Error(message); } } confirm(message) { return tslib_1.__awaiter(this, void 0, void 0, function* () { yield this.hideLoading(); return new Promise((resolve, reject) => { this.dms.app.dialog.confirm(message, () => { resolve(true); }, () => { resolve(false); }); }); }); } /** * starts a new task by given task id * The task must be defined in the /Task folder of the app */ launchTask(_taskId, _stepId, preserveContext) { return tslib_1.__awaiter(this, void 0, void 0, function* () { let taskId = _taskId; let stepId = _stepId; if (taskId == 'Home') { stepId = null; taskId = yield this.getHomeTaskId(); } var allowed = yield this.isTaskAllowed(taskId); if (!allowed) { var msg = `Task ${taskId} is blocked by the system administrator!`; if (!this.supressUIAlertsOnError) { this.showError(msg); } throw new Error(msg); } var state = { LastTaskId: taskId, LastStepId: stepId }; yield this.ConfigurationService.setNavigationState(state); if (!preserveContext) { this.ContextService.clear(); } //$('body').addClass('dms-preload'); //call the event before the context //to allow the dev to put data in the context //before persisting of context this.dms.eventEmitter.emit('dms:beforetask', { taskId: taskId, stepId: stepId }); //persist context between the task boundaries const p = dms_root_container_1.RootDIContainer.inject(context_service_1.ContextPersister); yield p.save(this.ContextService, this.dms); //launch the task const info = yield dms_root_container_1.RootDIContainer.inject(device_service_1.DeviceService).getInfo(); if (!info.isDevice) { //emulator in web browser let url = `${taskId}.html${window.location.search}`; if (preserveContext && url.indexOf('pc=') < 0) { url = url.indexOf('?') > 0 ? url + '&pc=1' : url + '?pc=1'; } window.location.assign(url); } else { //physical mobile device window.location.assign(`${taskId}.html${preserveContext ? '?pc=1' : ''}`); } //if (globals && globals.dms && globals.dms.eventEmitter) // globals.dms.eventEmitter.emit('launchtask', { taskId: taskId, stepId: stepId, preserveContext: preserveContext }); }); } }; exports.MobileUserInterfaceService = MobileUserInterfaceService = tslib_1.__decorate([ (0, injectable_1.Injectable)({ singleton: true }), tslib_1.__metadata("design:paramtypes", [application_context_service_1.DmsApplicationService, context_service_1.ContextService, configuration_service_1.ConfigurationService]) ], MobileUserInterfaceService); //# sourceMappingURL=mobile-ui-service.js.map