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

169 lines 7.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BackendUserInterfaceService = void 0; const tslib_1 = require("tslib"); const userinterface_service_1 = require("../lib-core/userinterface-service"); 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 dms_platform_bridge_factory_1 = require("../platform/dms-platform-bridge-factory"); const jquery_1 = tslib_1.__importDefault(require("jquery")); const sweetalert2_1 = tslib_1.__importDefault(require("sweetalert2")); const toast = tslib_1.__importStar(require("./controls/backend-toast")); const css = tslib_1.__importStar(require("./controls/backend-toast-styles.css")); const dms_root_container_1 = require("../ioc/dms-root-container"); /** * Provides user-interface related features like navigation, task launching and others */ let BackendUserInterfaceService = exports.BackendUserInterfaceService = class BackendUserInterfaceService extends userinterface_service_1.UserInterfaceService { constructor(dms, ContextService, ConfigurationService) { const _css = css; super(dms, ContextService, ConfigurationService); } launchTask(taskId, stepId, preserveContext) { return tslib_1.__awaiter(this, void 0, void 0, function* () { 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(); } //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); const appArea = yield this.getApparea(); window.parent.location.assign(`/index.html?app=${this.dms.appCode}${taskId ? `&task=${taskId}` : `&taskId=Home`}${appArea ? `&appArea=${appArea}` : ``}${preserveContext ? '&pc=1' : ''}${stepId ? '#' + stepId : ''}`); }); } /** * shows a default toast message, which stays on screen for 5 seconds and faded away automatically */ showToast(msg) { if (typeof (msg) === 'string') { toast.makeBackendToast({ type: 'info', content: msg, delay: 5000 }); } else { toast.makeBackendToast(msg); } } /** * 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* () { const state = yield this.ConfigurationService.getNavigationState(); (0, jquery_1.default)(`#${state.LastStepId}page-preloader`).show(); // $(`#${state.LastStepId}subcontent`).prop('disabled', true); // $(`#${state.LastStepId}subcontent *`).prop('disabled', true); (0, jquery_1.default)(`#${state.LastStepId}subcontent`).fadeTo('slow', .6); (0, jquery_1.default)(`#${state.LastStepId}subcontent`).append(`<div id="${state.LastStepId}overlay" style="position: absolute;top:0;left:0;width: 100%;height:100%;z-index:9999;opacity:0.8;filter: alpha(opacity = 50)"></div>`); }); } /** * hides the preloader message which was opened with showLoading */ hideLoading() { return tslib_1.__awaiter(this, void 0, void 0, function* () { const state = yield this.ConfigurationService.getNavigationState(); (0, jquery_1.default)(`#${state.LastStepId}page-preloader`).hide(); // $(`#${state.LastStepId}subcontent`).prop('disabled', false); // $(`#${state.LastStepId}subcontent *`).prop('disabled', false); (0, jquery_1.default)(`#${state.LastStepId}overlay`).remove(); (0, jquery_1.default)(`#${state.LastStepId}subcontent`).fadeTo('fast', 1); }); } /** * shows a standard (alert) message on the screen */ showMessage(message) { this.hideLoading(); sweetalert2_1.default.fire({ icon: "info", html: message, confirmButtonText: 'Okay', cancelButtonText: '', showCancelButton: false, showCloseButton: true, //button: "Aww yiss!", }); } showError(err) { //do not call console.... as DMS App for android shows double error window //as it captures console.log('%error'%) //console.warn((err.message ? err.message : err), err.stack) this.hideLoading(); var errMsg = 'unknown error'; if (typeof err === "object" && err.message) { errMsg = err.message; } else if (errMsg != null && typeof err === "object" && err.sqlMessage) { errMsg = err.sqlMessage; } else if (errMsg != null && typeof err === "object" && err.error) { errMsg = err.error; } else if (errMsg != null && typeof err === "object" && err.errorMessge) { errMsg = err.errorMessge; } else if (errMsg != null && typeof err === "object" && err.responseText) { errMsg = err.responseText; try { const o = JSON.parse(err.responseText); if (o.message) errMsg = o.message; } catch (err) { //responseText is just a string } } else if (errMsg != null && typeof err === "object") { errMsg = JSON.stringify(err); } else if (errMsg != null && typeof err === "string") { errMsg = err; } sweetalert2_1.default.fire({ title: "Error", html: errMsg, icon: "error", confirmButtonText: 'Close', cancelButtonText: '', showCancelButton: false, showCloseButton: true }); } confirm(message) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const r = confirm(message); return r; }); } getUserIdentity() { return tslib_1.__awaiter(this, void 0, void 0, function* () { return (0, dms_platform_bridge_factory_1.PlatformBridgeFactory)(this.dms).execute("getUserIdentity", {}); }); } }; exports.BackendUserInterfaceService = BackendUserInterfaceService = tslib_1.__decorate([ (0, injectable_1.Injectable)(), tslib_1.__metadata("design:paramtypes", [application_context_service_1.DmsApplicationService, context_service_1.ContextService, configuration_service_1.ConfigurationService]) ], BackendUserInterfaceService); //# sourceMappingURL=backend-ui-service.js.map