dynamicsmobile
Version:
Allows development of off-line mobile and web business apps over the Dynamics Mobile platform. More info on https://www.dynamicsmobile.com
239 lines • 13.1 kB
JavaScript
"use strict";
//do not import framework7 css here, it will be imported in every app separately
//as it need to support rtl/ltr and other customizations
//import 'framework7/css/bundle'
Object.defineProperty(exports, "__esModule", { value: true });
exports.MobileDmsTask = void 0;
const tslib_1 = require("tslib");
require("./mobile-app-styles.css");
const dms_root_container_1 = require("../ioc/dms-root-container");
const bundle_1 = tslib_1.__importDefault(require("framework7/bundle"));
const dom7_1 = tslib_1.__importDefault(require("dom7"));
const $ = dom7_1.default;
const task_1 = require("../lib-core/task");
const application_context_service_1 = require("../lib-core/application-context-service");
const mobile_context_service_1 = require("./mobile-context-service");
const context_service_1 = require("../lib-core/context-service");
const mobile_device_service_1 = require("./mobile-device-service");
const mobile_print_service_1 = require("./mobile-print-service");
const print_service_1 = require("../lib-core/print-service");
const configuration_service_1 = require("../lib-core/configuration-service");
const mobile_ui_service_1 = require("./mobile-ui-service");
const device_service_1 = require("../lib-core/device-service");
const mobile_configuration_service_1 = require("./mobile-configuration-service");
const files_service_base_1 = require("../lib-core/files-service-base");
const userinterface_service_1 = require("../lib-core/userinterface-service");
const decorators_service_1 = require("../lib-core/decorators-service");
const mobile_applicationcontext_service_1 = require("./mobile-applicationcontext-service");
const mobile_file_service_1 = require("./mobile-file-service");
const mobile_docseries_service_1 = require("./mobile-docseries-service");
const sql_query_service_1 = require("../lib-core/sql-query-service");
const mobile_sqlquery_service_1 = require("./mobile-sqlquery-service");
const mobile_syncpacket_service_1 = require("./mobile-syncpacket-service");
const syncpacket_service_1 = require("../lib-core/syncpacket-service");
const docseries_service_1 = require("../lib-core/docseries-service");
const mobile_notification_service_1 = require("./mobile-notification-service");
const notification_service_1 = require("../lib-core/notification-service");
const keyvalue_service_1 = require("../lib-core/keyvalue-service");
const mobile_keyvalue_service_1 = require("./mobile-keyvalue-service");
//import '../images/dynamicsmobile-logo.png';
class MobileDmsTask extends task_1.DmsTask {
constructor() {
super(...arguments);
this.navigaitonStack = [];
}
setupInjectableServices() {
this.domManager = $;
this.dms = new mobile_applicationcontext_service_1.MobileDmsApplicationService(this._appCode, "1.0", this._taskId);
dms_root_container_1.RootDIContainer.addProvider({ provide: application_context_service_1.DmsApplicationService, useValue: this.dms });
dms_root_container_1.RootDIContainer.addProvider({ provide: context_service_1.ContextService, useClass: mobile_context_service_1.MobileContextService, singleton: true });
dms_root_container_1.RootDIContainer.addProvider({ provide: print_service_1.PrintService, useClass: mobile_print_service_1.MobilePrintService, singleton: true });
dms_root_container_1.RootDIContainer.addProvider({ provide: device_service_1.DeviceService, useClass: mobile_device_service_1.MobileDeviceService, singleton: true });
dms_root_container_1.RootDIContainer.addProvider({ provide: configuration_service_1.ConfigurationService, useClass: mobile_configuration_service_1.MobileConfigurationService, singleton: true });
dms_root_container_1.RootDIContainer.addProvider({ provide: files_service_base_1.FileService, useClass: mobile_file_service_1.MobileFileService, singleton: true });
dms_root_container_1.RootDIContainer.addProvider({ provide: userinterface_service_1.UserInterfaceService, useClass: mobile_ui_service_1.MobileUserInterfaceService, singleton: true });
dms_root_container_1.RootDIContainer.addProvider({ provide: sql_query_service_1.SqlQueryService, useClass: mobile_sqlquery_service_1.MobileSqlQueryService, singleton: true });
dms_root_container_1.RootDIContainer.addProvider({ provide: syncpacket_service_1.SyncPacketService, useClass: mobile_syncpacket_service_1.MobileSyncPacketService, singleton: true });
dms_root_container_1.RootDIContainer.addProvider({ provide: docseries_service_1.DocumentSeriesService, useClass: mobile_docseries_service_1.MobileDocumentSeriesService, singleton: true });
dms_root_container_1.RootDIContainer.addProvider({ provide: decorators_service_1.DecoratorsManager, useClass: decorators_service_1.DecoratorsManager, singleton: true });
dms_root_container_1.RootDIContainer.addProvider({ provide: notification_service_1.NotificationService, useClass: mobile_notification_service_1.MobileNotificationService, singleton: true });
dms_root_container_1.RootDIContainer.addProvider({ provide: context_service_1.ContextPersister, useClass: context_service_1.ContextPersister, singleton: true });
dms_root_container_1.RootDIContainer.addProvider({ provide: keyvalue_service_1.KeyValueService, useClass: mobile_keyvalue_service_1.MobileKeyValueService, singleton: true });
}
initializeUIFramework({ theme, allTaskRoutes }) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
var me = this;
this.dms.app = new bundle_1.default({
// App Name
name: 'Dynamics Mobile',
theme: theme,
// Enable swipe panel
panel: {
swipe: true
},
on: {
init: function () {
me.showViewOverlay();
},
pageInit: (page) => {
page.view.router.params.stackPages = true;
page.view.router.params.pushState = false;
},
pageReinit: function (page) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield me.doCreateView(page, me.dms);
});
},
},
routes: allTaskRoutes
});
this.dms.app.request = {
promise: (options, responseType) => tslib_1.__awaiter(this, void 0, void 0, function* () {
if (options.data) {
//fetch uses body instead of data
options.body = options.data;
}
const response = yield fetch(options.url, options);
let r;
if (response && response.status === 200) {
switch (responseType) {
case 'text':
r = yield response.text();
break;
case 'json':
r = yield response.json();
break;
case 'array':
r = yield response.arrayBuffer();
break;
case 'blob':
r = yield response.blob();
break;
case 'form':
r = yield response.formData();
break;
default:
r = yield response.text();
break;
}
}
else {
throw new Error(response && response.text ? yield response.text() : 'API Request failed');
}
return { data: r };
})
};
if (!this.dms.app.data) {
this.dms.app.data = {};
}
this.dms.app.methods = {
onBackKeyDown: function () {
let leftp = null;
let rightp = null;
if (navigator.dmsapp.panel) {
leftp = navigator.dmsapp.panel.left && navigator.dmsapp.panel.left.opened;
rightp = navigator.dmsapp.panel.right && navigator.dmsapp.panel.right.opened;
}
if (leftp || rightp) {
if (navigator.dmsapp.panel)
navigator.dmsapp.panel.close();
return false;
}
else if (me.domManager('.modal-in').length > 0) {
if (navigator.dmsapp.dialog)
navigator.dmsapp.dialog.close();
if (navigator.dmsapp.popup)
navigator.dmsapp.popup.close();
return false;
}
else {
dms_root_container_1.RootDIContainer.inject(userinterface_service_1.UserInterfaceService).navigate('prior');
return false;
}
}
};
if (!this.dms.app.request.promise) {
this.dms.app.request.promise = this.dms.app.request;
}
navigator["dmsapp"] = this.dms.app;
//we are in the correct task, time to activate the view
this.mainView = this.dms.app.views.create('.view-main');
});
}
internalNavigate(routeObect) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (this._isTestMode) {
return;
}
let isValid = true;
let _ro = JSON.parse(JSON.stringify(routeObect));
if (routeObect.pageName == '$back') {
if (this.navigaitonStack.length > 0) {
_ro = this.navigaitonStack.pop();
}
else {
_ro.pageName = 'HomeStep';
_ro.name = 'Home';
_ro.path = '/HomeStep/';
_ro.validate = false;
_ro.preserveContext = false;
_ro.routeId = 'prior';
}
}
const currentViewInstance = this.dms.app.data["_currentViewInstance"];
if (currentViewInstance) {
isValid = yield this.validateView(currentViewInstance, _ro);
}
if (isValid) {
if (this._taskId != 'LoginSuccess' && this._taskId != 'Index') {
yield dms_root_container_1.RootDIContainer.inject(configuration_service_1.ConfigurationService).setNavigationState({
LastTaskId: this._taskId,
LastStepId: _ro.pageName
});
}
if (_ro.pageName.indexOf('Home') > -1 || _ro.pageName.indexOf('HomeStep') > -1) {
this.navigaitonStack = [];
}
else {
if (currentViewInstance && routeObect.pageName != '$back' && routeObect.lastStepId != 'HomeStep') {
this.navigaitonStack.push({
pageName: _ro.lastStepId,
name: currentViewInstance.className,
path: `/${_ro.lastStepId}/`,
validate: false,
preserveContext: true,
routeId: 'prior'
});
}
}
this.mainView.router.navigate(_ro.path);
}
});
}
findRoute(stepId, routeId) {
const current = this.dms.app.views.current ? this.dms.app.views.current : this.dms.app.views[0];
let stepName = stepId && stepId.name ? stepId.name : stepId;
if (!stepName) {
stepName = current.router && current.router.currentPageEl ? current.router.currentPageEl.id : '';
}
if (!stepName) {
return null;
}
const name = `${stepName}${routeId ? routeId : ''}`;
const rt = current.router.routes.find(r => r.name == name);
return rt;
}
run(isTestMode) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.internalRun(isTestMode);
const cfg = dms_root_container_1.RootDIContainer.inject(configuration_service_1.ConfigurationService);
const syncCompleted = yield cfg.getSetting('$$dmsdatasyncompleted');
if (syncCompleted == 'true') {
yield cfg.setSetting('$$dmsdatasyncompleted', undefined);
this.dms.eventEmitter.emit('dms:aftersync');
}
});
}
}
exports.MobileDmsTask = MobileDmsTask;
//# sourceMappingURL=mobile-task.js.map