diff --git a/src/02/0242b09497911ede8cf11b65a990e8cf.smim.xml b/src/02/024251849e5a1edf9fcf68abc9a5e8c2.smim.xml similarity index 87% rename from src/02/0242b09497911ede8cf11b65a990e8cf.smim.xml rename to src/02/024251849e5a1edf9fcf68abc9a5e8c2.smim.xml index 807ab32..6b34819 100644 --- a/src/02/0242b09497911ede8cf11b65a990e8cf.smim.xml +++ b/src/02/024251849e5a1edf9fcf68abc9a5e8c2.smim.xml @@ -2,7 +2,7 @@ - /SAP/BC/BSP/SAP/ZABAP2UI5 + /SAP/BC/BSP/SAP/Z2UI5 X diff --git a/src/02/package.devc.xml b/src/02/package.devc.xml index f798c04..9bd9bf7 100644 --- a/src/02/package.devc.xml +++ b/src/02/package.devc.xml @@ -3,7 +3,7 @@ - frontend - ui5 app + test diff --git a/src/02/zabap2ui5 5269af785e387a564a40a134e.sicf.xml b/src/02/z2ui5 0ec96042f38e7e75ceadd96a5.sicf.xml similarity index 71% rename from src/02/zabap2ui5 5269af785e387a564a40a134e.sicf.xml rename to src/02/z2ui5 0ec96042f38e7e75ceadd96a5.sicf.xml index c0fc2f0..49fdd78 100644 --- a/src/02/zabap2ui5 5269af785e387a564a40a134e.sicf.xml +++ b/src/02/z2ui5 0ec96042f38e7e75ceadd96a5.sicf.xml @@ -2,13 +2,13 @@ - /sap/bc/bsp/sap/zabap2ui5/ + /sap/bc/ui5_ui5/sap/z2ui5/ - ZABAP2UI5 - zabap2ui5 + Z2UI5 + z2ui5 - ZABAP2UI5 + Z2UI5 E abap2UI5 diff --git a/src/02/zabap2ui5 c18c9f9b4f809552ebde3790e.sicf.xml b/src/02/z2ui5 cc3e0011031e2f3f4be478dc5.sicf.xml similarity index 70% rename from src/02/zabap2ui5 c18c9f9b4f809552ebde3790e.sicf.xml rename to src/02/z2ui5 cc3e0011031e2f3f4be478dc5.sicf.xml index d5d6b7a..3f63ff8 100644 --- a/src/02/zabap2ui5 c18c9f9b4f809552ebde3790e.sicf.xml +++ b/src/02/z2ui5 cc3e0011031e2f3f4be478dc5.sicf.xml @@ -2,13 +2,13 @@ - /sap/bc/ui5_ui5/sap/zabap2ui5/ + /sap/bc/bsp/sap/z2ui5/ - ZABAP2UI5 - zabap2ui5 + Z2UI5 + z2ui5 - ZABAP2UI5 + Z2UI5 E abap2UI5 diff --git a/src/02/zabap2ui5.wapa.manifest.json b/src/02/z2ui5.wapa.cc_-debugtool.fragment.xml similarity index 69% rename from src/02/zabap2ui5.wapa.manifest.json rename to src/02/z2ui5.wapa.cc_-debugtool.fragment.xml index 0226336..47dadaf 100644 --- a/src/02/zabap2ui5.wapa.manifest.json +++ b/src/02/z2ui5.wapa.cc_-debugtool.fragment.xml @@ -1,114 +1,105 @@ -{ - "_version": "1.50.0", - "sap.app": { - "id": "z2ui5", - "type": "application", - "i18n": "i18n/i18n.properties", - "applicationVersion": { - "version": "0.0.2" - }, - "title": "{{appTitle}}", - "description": "{{appDescription}}", - "resources": "resources.json", - "sourceTemplate": { - "id": "@sap/generator-fiori:basic", - "version": "1.10.4", - "toolsId": "45f51711-e1b8-4fc4-bc1b-9e341941c532" - }, - "dataSources": { - "mainService": { - "uri": "/sap/bc/z2ui5/", - "type": "http" - } - } - }, - "sap.ui": { - "technology": "UI5", - "icons": { - "icon": "", - "favIcon": "", - "phone": "", - "phone@2": "", - "tablet": "", - "tablet@2": "" - }, - "deviceTypes": { - "desktop": true, - "tablet": true, - "phone": true - }, -"fullWidth": true - }, - "sap.ui5": { - "flexEnabled": true, - "dependencies": { - "minUI5Version": "1.116.0", - "libs": { - "sap.m": {}, - "sap.ui.core": {}, - "sap.f": {}, - "sap.ui.table": {} - } - }, - "contentDensities": { - "compact": true, - "cozy": true - }, - "services": { - "ShellUIService": { - "factoryName": "sap.ushell.ui5service.ShellUIService" - } - }, - "models": { - "i18n": { - "type": "sap.ui.model.resource.ResourceModel", - "settings": { - "bundleName": "z2ui5.i18n.i18n" - } - } - }, - "resources": { - "css": [ - { - "uri": "css/style.css" - } - ] - }, - "routing": { - "config": { - "routerClass": "sap.m.routing.Router", - "viewType": "XML", - "async": true, - "viewPath": "z2ui5.view", - "controlAggregation": "pages", - "controlId": "viewContainer2", - "clearControlAggregation": false - }, - "routes": [ - { - "name": "RouteView1", - "pattern": ":?query:", - "target": [ - "TargetView1" - ] - } - ], - "targets": { - "TargetView1": { - "viewType": "XML", - "transition": "slide", - "clearControlAggregation": false, - "viewId": "View1", - "viewName": "View1" - } - } - }, - "rootView": { - "viewName": "z2ui5.view.App", - "type": "XML", - "async": true, - "id": "rootView" - } - } -} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/02/z2ui5.wapa.cc_-debugtool.js b/src/02/z2ui5.wapa.cc_-debugtool.js new file mode 100644 index 0000000..c0eb807 --- /dev/null +++ b/src/02/z2ui5.wapa.cc_-debugtool.js @@ -0,0 +1,134 @@ +sap.ui.define(["sap/ui/core/Control", "sap/ui/core/Fragment", "sap/ui/model/json/JSONModel"], (Control, Fragment, JSONModel) => { + "use strict"; + + return Control.extend("z2ui5.cc.DebugTool", { + + prettifyXml: function (sourceXml) { + const xmlDoc = new DOMParser().parseFromString(sourceXml, 'application/xml'); + const sParse = unescape('%3Cxsl%3Astylesheet%20xmlns%3Axsl%3D%22http%3A//www.w3.org/1999/XSL/Transform%22%3E%0A%20%20%3Cxsl%3Astrip-space%20elements%3D%22*%22/%3E%0A%20%20%3Cxsl%3Atemplate%20match%3D%22para%5Bcontent-style%5D%5Bnot%28text%28%+ +29%29%5D%22%3E%0A%20%20%20%20%3Cxsl%3Avalue-of%20select%3D%22normalize-space%28.%29%22/%3E%0A%20%20%3C/xsl%3Atemplate%3E%0A%20%20%3Cxsl%3Atemplate%20match%3D%22node%28%29%7C@*%22%3E%0A%20%20%20%20%3Cxsl%3Acopy%3E%3Cxsl%3Aapply-templates%20select%3D%22nod+ +e%28%29%7C@*%22/%3E%3C/xsl%3Acopy%3E%0A%20%20%3C/xsl%3Atemplate%3E%0A%20%20%3Cxsl%3Aoutput%20indent%3D%22yes%22/%3E%0A%3C/xsl%3Astylesheet%3E'); + const xsltDoc = new DOMParser().parseFromString(sParse, 'application/xml'); + + const xsltProcessor = new XSLTProcessor(); + xsltProcessor.importStylesheet(xsltDoc); + const resultDoc = xsltProcessor.transformToDocument(xmlDoc); + const resultXml = new XMLSerializer().serializeToString(resultDoc); + return resultXml.replace(/>/g, ">"); + }, + + onItemSelect: function (oEvent) { + const selItem = oEvent.getSource().getSelectedKey(); + const oView = z2ui5?.oView; + const oResponse = z2ui5?.oResponse; + const displayEditor = this.displayEditor.bind(this); + + switch (selItem) { + case 'CONFIG': + displayEditor(oEvent, JSON.stringify(z2ui5.oConfig, null, 3), 'json'); + break; + case 'MODEL': + displayEditor(oEvent, JSON.stringify(oView?.getModel()?.getData(), null, 3), 'json'); + break; + case 'VIEW': + const viewContent = oView?.mProperties?.viewContent || z2ui5.responseData.S_FRONT.PARAMS.S_VIEW.XML; + displayEditor(oEvent, this.prettifyXml(viewContent), 'xml', this.prettifyXml(oView?._xContent.outerHTML)); + break; + case 'PLAIN': + displayEditor(oEvent, JSON.stringify(z2ui5.responseData, null, 3), 'json'); + break; + case 'REQUEST': + displayEditor(oEvent, JSON.stringify(z2ui5.oBody, null, 3), 'json'); + break; + case 'POPUP': + displayEditor(oEvent, this.prettifyXml(oResponse?.PARAMS?.S_POPUP?.XML), 'xml'); + break; + case 'POPUP_MODEL': + displayEditor(oEvent, JSON.stringify(z2ui5.oViewPopup.getModel().getData(), null, 3), 'json'); + break; + case 'POPOVER': + displayEditor(oEvent, oResponse?.PARAMS?.S_POPOVER?.XML, 'xml'); + break; + case 'POPOVER_MODEL': + displayEditor(oEvent, JSON.stringify(z2ui5?.oViewPopover?.getModel()?.getData(), null, 3), 'json'); + break; + case 'NEST1': + displayEditor(oEvent, this.prettifyXml(z2ui5?.oViewNest?.mProperties?.viewContent), 'xml', this.prettifyXml(z2ui5?.oViewNest?._xContent.outerHTML)); + break; + case 'NEST1_MODEL': + displayEditor(oEvent, JSON.stringify(z2ui5?.oViewNest?.getModel()?.getData(), null, 3), 'json'); + break; + case 'NEST2': + displayEditor(oEvent, this.prettifyXml(z2ui5?.oViewNest2?.mProperties?.viewContent), 'xml', this.prettifyXml(z2ui5?.oViewNest2?._xContent.outerHTML)); + break; + case 'NEST2_MODEL': + displayEditor(oEvent, JSON.stringify(z2ui5?.oViewNest2?.getModel()?.getData(), null, 3), 'json'); + break; + case 'SOURCE': + const parent = oEvent.getSource().getParent(); + const contentControl = parent.getContent()[2].getItems()[0]; + const url = `${window.location.origin}/sap/bc/adt/oo/classes/${z2ui5.responseData.S_FRONT.APP}/source/main`; + const content = atob('PGlmcmFtZSBpZD0idGVzdCIgc3JjPSInICsgdXJsICsgJyIgaGVpZ2h0PSI4MDBweCIgd2lkdGg9IjEyMDBweCIgLz4=').replace("' + url + '", url); + contentControl.setProperty("content", content); + const modelData = oEvent.getSource().getModel().oData; + modelData.editor_visible = false; + modelData.source_visible = true; + oEvent.getSource().getModel().refresh(); + break; + } + }, + + displayEditor: function (oEvent, content, type, xcontent = "") { + const modelData = oEvent.getSource().getModel().oData; + modelData.editor_visible = true; + modelData.source_visible = false; + modelData.isTemplating = content.includes("xmlns:template"); + modelData.value = content; + modelData.previousValue = content; + modelData.xContent = xcontent; + modelData.type = type; + oEvent.getSource().getModel().refresh(); + }, + + onTemplatingPress: function (oEvent) { + const modelData = oEvent.getSource().getModel().oData; + modelData.value = oEvent.getSource().getPressed() ? modelData.xContent : modelData.previousValue; + oEvent.getSource().getModel().refresh(); + }, + + onClose: function () { + this.oDialog.close(); + }, + + async show() { + if (!this.oDialog) { + this.oDialog = await Fragment.load({ + name: "z2ui5.cc.DebugTool", + controller: this, + }); + } + + const value = JSON.stringify(z2ui5.responseData, null, 3); + const oData = { + type: 'json', + source_visible: false, + editor_visible: true, + value: value, + xContent: '', + previousValue: value, + isTemplating: false, + templatingSource: false, + activeNest1: z2ui5?.oViewNest?.mProperties?.viewContent !== undefined, + activeNest2: z2ui5?.oViewNest2?.mProperties?.viewContent !== undefined, + activePopup: z2ui5?.oResponse?.PARAMS?.S_POPUP?.XML !== undefined, + activePopover: z2ui5?.oResponse?.PARAMS?.S_POPOVER?.XML !== undefined, + }; + const oModel = new JSONModel(oData); + + this.oDialog.addStyleClass('dbg-ltr'); + this.oDialog.setModel(oModel); + this.oDialog.open(); + } + }); +}); + \ No newline at end of file diff --git a/src/02/z2ui5.wapa.cc_-server.js b/src/02/z2ui5.wapa.cc_-server.js new file mode 100644 index 0000000..4fd3bd2 --- /dev/null +++ b/src/02/z2ui5.wapa.cc_-server.js @@ -0,0 +1,147 @@ +sap.ui.define(["sap/ui/core/BusyIndicator","sap/m/MessageBox" +], + function (BusyIndicator, MessageBox) { + "use strict"; + + return { + + endSession: function () { + + if (z2ui5.contextId) { + fetch(z2ui5.oConfig.pathname, { + method: 'HEAD', + keepalive: true, + headers: { + 'sap-terminate': 'session', + 'sap-contextid': z2ui5.contextId, + 'sap-contextid-accept': 'header' + } + }); + delete z2ui5.contextId; + } + + }, + Roundtrip() { + z2ui5.checkTimerActive = false; + z2ui5.checkNestAfter = false; + z2ui5.checkNestAfter2 = false; + let event = (args) => { + if (args != undefined) { + return args[0][0]; + } + }; + + z2ui5.oBody ??= {}; + z2ui5.oBody.S_FRONT = { + ID: z2ui5?.oBody?.ID, + CONFIG: z2ui5.oConfig, + XX: z2ui5?.oBody?.XX, + ORIGIN: window.location.origin, + PATHNAME: window.location.pathname, + SEARCH: (z2ui5.search) ? z2ui5.search : window.location.search, + VIEW: z2ui5.oBody?.VIEWNAME, + EVENT: event(z2ui5.oBody?.ARGUMENTS), + HASH: window.location.hash, + }; + if (z2ui5.oBody?.ARGUMENTS != undefined) { + if (z2ui5.oBody?.ARGUMENTS.length > 0) { + z2ui5.oBody?.ARGUMENTS.shift(); + } + } + z2ui5.oBody.S_FRONT.T_EVENT_ARG = z2ui5.oBody?.ARGUMENTS; + delete z2ui5.oBody.ID; + delete z2ui5.oBody?.VIEWNAME; + delete z2ui5.oBody?.S_FRONT.XX; + delete z2ui5.oBody?.ARGUMENTS; + if (!z2ui5.oBody.S_FRONT.T_EVENT_ARG) { + delete z2ui5.oBody.S_FRONT.T_EVENT_ARG; + } + if (z2ui5.oBody.S_FRONT.T_EVENT_ARG) { + if (z2ui5.oBody.S_FRONT.T_EVENT_ARG.length == 0) { + delete z2ui5.oBody.S_FRONT.T_EVENT_ARG; + } + } + if (z2ui5.oBody.S_FRONT.T_STARTUP_PARAMETERS == undefined) { + delete z2ui5.oBody.S_FRONT.T_STARTUP_PARAMETERS; + } + if (z2ui5.oBody.S_FRONT.SEARCH == '') { + delete z2ui5.oBody.S_FRONT.SEARCH; + } + if (!z2ui5.oBody.XX) { + delete z2ui5.oBody.XX; + } + this.readHttp(); + }, + + async readHttp() { + const response = await fetch(z2ui5.oConfig.pathname, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'sap-contextid-accept': 'header', + 'sap-contextid': z2ui5.contextId + }, + body: JSON.stringify(z2ui5.oBody) + }); + z2ui5.contextId = response.headers.get("sap-contextid"); + if (!response.ok) { + const responseText = await response.text(); + this.responseError(responseText); + } else { + const responseData = await response.json(); + z2ui5.responseData = responseData; + this.responseSuccess({ + ID: responseData.S_FRONT.ID, + PARAMS: responseData.S_FRONT.PARAMS, + OVIEWMODEL: responseData.MODEL, + }); + } + }, + async responseSuccess(response) { + try { + z2ui5.oResponse = response; + if (z2ui5.oResponse.PARAMS?.S_VIEW?.CHECK_DESTROY) { + z2ui5.oController.ViewDestroy(); + } + ; if (z2ui5.oResponse.PARAMS?.S_FOLLOW_UP_ACTION?.CUSTOM_JS) { + setTimeout(() => { + let mParams = z2ui5.oResponse?.PARAMS.S_FOLLOW_UP_ACTION.CUSTOM_JS.split("'"); + let mParamsEF = mParams.filter((val, index) => index % 2) + if (mParamsEF.length) { + z2ui5.oController.eF.apply(undefined, mParamsEF); + } else { + Function("return " + mParams[0])(); + } + }, 100); + }; + z2ui5.oController.showMessage('S_MSG_TOAST', z2ui5.oResponse.PARAMS); + z2ui5.oController.showMessage('S_MSG_BOX', z2ui5.oResponse.PARAMS); + if (z2ui5.oResponse.PARAMS?.S_VIEW?.XML) { + if (z2ui5.oResponse.PARAMS?.S_VIEW?.XML !== '') { + z2ui5.oController.ViewDestroy(); + await z2ui5.oController.displayView(z2ui5.oResponse.PARAMS.S_VIEW.XML, z2ui5.oResponse.OVIEWMODEL); + return; + } + } + z2ui5.oController.updateModelIfRequired('S_VIEW', z2ui5.oView); + z2ui5.oController.updateModelIfRequired('S_VIEW_NEST', z2ui5.oViewNest); + z2ui5.oController.updateModelIfRequired('S_VIEW_NEST2', z2ui5.oViewNest2); + z2ui5.oController.updateModelIfRequired('S_POPUP', z2ui5.oViewPopup); + z2ui5.oController.updateModelIfRequired('S_POPOVER', z2ui5.oViewPopover); + z2ui5.oController.onAfterRendering(); + } catch (e) { + BusyIndicator.hide(); + if (e.message.includes("openui5")) { + if (e.message.includes("script load error")) { + z2ui5.oController.checkSDKcompatibility(e) + } + } else { + MessageBox.error(e.toLocaleString()); + } + } + }, + responseError(response) { + document.write(response); + }, + }; + }); \ No newline at end of file diff --git a/src/02/z2ui5.wapa.component.js b/src/02/z2ui5.wapa.component.js new file mode 100644 index 0000000..d688586 --- /dev/null +++ b/src/02/z2ui5.wapa.component.js @@ -0,0 +1,75 @@ +sap.ui.define(["sap/ui/core/UIComponent", "z2ui5/model/models", + "z2ui5/cc/DebugTool","z2ui5/cc/Server", "sap/base/Log","sap/ui/VersionInfo" +   + ], function (UIComponent, models, DebugTool, Server, Log, VersionInfo) { + return UIComponent.extend("z2ui5.Component", { + metadata: { + manifest: "json" + }, + init: async function () { + + UIComponent.prototype.init.apply(this, arguments); + + this.getRouter().initialize(); + z2ui5.oRouter = this.getRouter(); + this.setModel(models.createDeviceModel(), "device"); + this._oLogger = Log.getLogger("abap2UI5"); + + z2ui5.oConfig = {}; + z2ui5.oConfig.ComponentData = this.getComponentData(); + + try {                                       &nb+ +sp;                                          + +;                                          &+ +nbsp;                                         &nb+ +sp;                                          + +;                           + z2ui5.oLaunchpadService = await this.getService("ShellUIService");                            &nbs+ +p;                                          + +                                          &n+ +bsp;                                         &nbs+ +p;                                          + +                                          &n+ +bsp;                                         &nbs+ +p;                                          + +                                          &n+ +bsp;        + } catch (e) {}   +              + let oVersionInfo = await VersionInfo.load(); + z2ui5.oConfig.UI5VersionInfo = { + version : oVersionInfo.version, + buildTimestamp : oVersionInfo.buildTimestamp, + gav : oVersionInfo.gav, + } + + if (/iPad|iPhone/.test(navigator.platform)) { + window.addEventListener("__pagehide", this.__pagehide.bind(this)); + } else { + window.addEventListener("__beforeunload", this.__beforeunload.bind(this)); + } + + document.addEventListener("keydown", function (zEvent) { + if (zEvent?.key === "F12") { + new z2ui5.cc.DebugTool().show(); + } + }); + }, + + __beforeunload: function () { + window.removeEventListener("__beforeunload", this.__beforeunload.bind(this)); + this.destroy(); + }, + __pagehide: function () { + window.removeEventListener("__pagehide", this.__pagehide.bind(this)); + this.destroy(); + }, + + exit: function () { + Server.endSession(); + if (UIComponent.prototype.exit) + UIComponent.prototype.exit.apply(this, arguments); + }, + }); +}); + \ No newline at end of file diff --git a/src/02/zabap2ui5.wapa.component.js b/src/02/z2ui5.wapa.controller_-app.controller.js similarity index 72% rename from src/02/zabap2ui5.wapa.component.js rename to src/02/z2ui5.wapa.controller_-app.controller.js index 3181929..edba160 100644 --- a/src/02/zabap2ui5.wapa.component.js +++ b/src/02/z2ui5.wapa.controller_-app.controller.js @@ -1,745 +1,780 @@ - sap.z2ui5 = sap.z2ui5 || {} ; if ( typeof z2ui5 == "undefined" ) { var z2ui5 = {}; }; - sap.ui.define([ - "sap/ui/core/UIComponent", - "sap/ui/Device", - "z2ui5/model/models" - ], - function (UIComponent, Device, models) { - return UIComponent.extend("z2ui5.Component", { - metadata: { - manifest: "json" - }, - init: function(){ - - UIComponent.prototype.init.apply(this, arguments); - this.getRouter().initialize(); - this.setModel(models.createDeviceModel(), "device"); - - sap.z2ui5.pathname = sap.z2ui5.pathname || this.getManifestEntry("/sap.app/dataSources/mainService/uri"); - - if (/iPad|iPhone/.test(navigator.platform)){ - window.addEventListener("pagehide", this.__pagehide.bind(this)); - } - else{ - window.addEventListener("beforeunload", this.__beforeunload.bind(this)); - } - - - - - - - -if (!z2ui5.Timer) {sap.ui.define("z2ui5/Timer" , [ - "sap/ui/core/Control" -], (Control) => { - "use strict"; - - return Control.extend("z2ui5.Timer", { - metadata : { - properties: { - delayMS: { - type: "string", - defaultValue: "" - }, - checkActive: { - type: "boolean", - defaultValue: true - }, - checkRepeat: { - type: "boolean", - defaultValue: false - }, - }, - events: { - "finished": { - allowPreventDefault: true, - parameters: {}, - } - } - }, - onAfterRendering() { - }, - delayedCall( oControl){ - - if ( oControl.getProperty("checkActive") == false ){ return; } - setTimeout((oControl) => { - oControl.setProperty( "checkActive", false ) - oControl.fireFinished(); - if ( oControl.getProperty( "checkRepeat" ) ) { oControl.delayedCall( oControl ); } - }, parseInt( oControl.getProperty("delayMS") ), oControl ); - }, - renderer(oRm, oControl) { - oControl.delayedCall( oControl ); +sap.ui.define(["sap/ui/core/mvc/Controller", + "z2ui5/controller/View1.controller", +], function (BaseController, Controller) { + return BaseController.extend("z2ui5.controller.App", { + + onInit: async function () { + + z2ui5.oConfig.pathname = this.getView().getModel().sServiceUrl; + if (z2ui5.oConfig.pathname == '_LOCAL_') {  + z2ui5.oConfig.pathname = window.location.href;  + }; +       + z2ui5.oController = new Controller(); + z2ui5.oController.setApp(this.getView().byId("app")); + + z2ui5.oControllerNest = new Controller(); + z2ui5.oControllerNest2 = new Controller(); + z2ui5.oControllerPopup = new Controller(); + z2ui5.oControllerPopover = new Controller(); + + z2ui5.onBeforeRoundtrip = []; + z2ui5.onAfterRendering = []; + z2ui5.onBeforeEventFrontend = []; + z2ui5.onAfterRoundtrip = []; + + z2ui5.checkNestAfter = false; + + } + }); +}); + + +sap.ui.define("z2ui5/Timer", ["sap/ui/core/Control"], (Control) => { + "use strict"; + + return Control.extend("z2ui5.Timer", { + metadata: { + properties: { + delayMS: { + type: "string", + defaultValue: "" + }, + checkActive: { + type: "boolean", + defaultValue: true + }, + checkRepeat: { + type: "boolean", + defaultValue: false + }, + }, + events: { + "finished": { + allowPreventDefault: true, + parameters: {}, + } + } + }, + onAfterRendering() { }, + delayedCall(oControl) { + + if (oControl.getProperty("checkActive") == false) { + return; + } + setTimeout((oControl) => { + oControl.setProperty("checkActive", false) + oControl.fireFinished(); + if (oControl.getProperty("checkRepeat")) { + oControl.delayedCall(oControl); } - }); -}); }if (!z2ui5.Focus) { sap.ui.define("z2ui5/Focus", [ - "sap/ui/core/Control", -], (Control) => { + } + , parseInt(oControl.getProperty("delayMS")), oControl); + }, + renderer(oRm, oControl) { + oControl.delayedCall(oControl); + } + }); +} +); + +sap.ui.define("z2ui5/Focus", ["sap/ui/core/Control",], (Control) => { "use strict"; return Control.extend("z2ui5.Focus", { - metadata: { - properties: { - setUpdate : { type: "boolean", defaultValue: true }, - focusId: { type: "string" }, - selectionStart: { type: "string", defaultValue: "0" }, - selectionEnd: { type: "string", defaultValue: "0" }, - } - }, - init() { - }, - setFocusId(val) { - try{ - this.setProperty("focusId", val); - var oElement = sap.z2ui5.oView.byId(val); - var oFocus = oElement.getFocusInfo(); - oElement.applyFocusInfo(oFocus); } catch (e) {} - }, - renderer(oRm, oControl) { - if (!oControl.getProperty("setUpdate")){ return; } - oControl.setProperty("setUpdate", false); - setTimeout((oControl) => { - var oElement = sap.z2ui5.oView.byId(oControl.getProperty("focusId")); - var oFocus = oElement.getFocusInfo(); - oFocus.selectionStart = parseInt(oControl.getProperty("selectionStart")); - oFocus.selectionEnd = parseInt(oControl.getProperty("selectionEnd")); - oElement.applyFocusInfo(oFocus); - }, 100, oControl); + metadata: { + properties: { + setUpdate: { + type: "boolean", + defaultValue: true + }, + focusId: { + type: "string" + }, + selectionStart: { + type: "string", + defaultValue: "0" + }, + selectionEnd: { + type: "string", + defaultValue: "0" + }, + } + }, + init() { }, + setFocusId(val) { + try { + this.setProperty("focusId", val); + var oElement = z2ui5.oView.byId(val); + var oFocus = oElement.getFocusInfo(); + oElement.applyFocusInfo(oFocus); + } catch (e) { } + }, + renderer(oRm, oControl) { + if (!oControl.getProperty("setUpdate")) { + return; } + oControl.setProperty("setUpdate", false); + setTimeout((oControl) => { + var oElement = z2ui5.oView.byId(oControl.getProperty("focusId")); + var oFocus = oElement.getFocusInfo(); + oFocus.selectionStart = parseInt(oControl.getProperty("selectionStart")); + oFocus.selectionEnd = parseInt(oControl.getProperty("selectionEnd")); + oElement.applyFocusInfo(oFocus); + } + , 100, oControl); + } }); -}); }if (!z2ui5.Title) { sap.ui.define("z2ui5/Title" , ["sap/ui/core/Control"], (Control)=>{ - "use strict"; - return Control.extend("z2ui5.Title", { - metadata: { - properties: { - title: { - type: "string" - }, - } - }, - setTitle(val) { - this.setProperty("title", val); - document.title = val; - }, - renderer(oRm, oControl) {} - }); - }); }if (!z2ui5.LPTitle) { sap.ui.define("z2ui5/LPTitle" , ["sap/ui/core/Control"], (Control)=>{ - "use strict"; - return Control.extend("z2ui5.LPTitle", { - metadata: { - properties: { - title: { - type: "string" - }, - } - }, - setTitle(val) { - try { - this.setProperty("title", val); - sap.z2ui5.oLaunchpadService.setTitle( val ); - } catch (e) { console.error("Launchpad Service to set Title not found"); } - }, - renderer(oRm, oControl) {} - }); - }); }if (!z2ui5.History) { sap.ui.define("z2ui5/History",["sap/ui/core/Control"], (Control)=>{ - "use strict"; - return Control.extend("z2ui5.History", { - metadata: { - properties: { - search: { - type: "string" - }, - } - }, - setSearch(val) { - this.setProperty("search", val); - history.replaceState(null, null, window.location.pathname + val ); - }, - renderer(oRm, oControl) {} - }); - }); }if (!z2ui5.Scrolling) { sap.ui.define("z2ui5/Scrolling", [ - "sap/ui/core/Control", -], (Control) => { +} +); + +sap.ui.define("z2ui5/Title", ["sap/ui/core/Control"], (Control) => { + "use strict"; + return Control.extend("z2ui5.Title", { + metadata: { + properties: { + title: { + type: "string" + }, + } + }, + setTitle(val) { + this.setProperty("title", val); + document.title = val; + }, + renderer(oRm, oControl) { } + }); +} +); +sap.ui.define("z2ui5/LPTitle", ["sap/ui/core/Control"], (Control) => { + "use strict"; + return Control.extend("z2ui5.LPTitle", { + metadata: { + properties: { + title: { + type: "string" + }, + } + }, + setTitle(val) { + try { + this.setProperty("title", val); + z2ui5.oLaunchpadService.setTitle(val); + } catch (e) { + console.error("Launchpad Service to set Title not found"); + } + }, + renderer(oRm, oControl) { } + }); +} +); +sap.ui.define("z2ui5/History", ["sap/ui/core/Control"], (Control) => { + "use strict"; + return Control.extend("z2ui5.History", { + metadata: { + properties: { + search: { + type: "string" + }, + } + }, + setSearch(val) { + this.setProperty("search", val); + history.replaceState(null, null, window.location.pathname + val); + }, + renderer(oRm, oControl) { } + }); +} +); +sap.ui.define("z2ui5/Scrolling", ["sap/ui/core/Control"], (Control) => { "use strict"; return Control.extend("z2ui5.Scrolling", { - metadata: { - properties: { - setUpdate: { type: "boolean" , defaultValue: true}, - items: { type: "Array" }, - } - }, + metadata: { + properties: { + setUpdate: { + type: "boolean", + defaultValue: true + }, + items: { + type: "Array" + } + } + }, + + setBackend() { + const items = this.getProperty("items"); - setBackend() { - if (this.mProperties.items){ this.mProperties.items.forEach(item => { - try { - item.SCROLLTO = sap.z2ui5.oView.byId(item.ID).getScrollDelegate().getScrollTop(); - } catch (e) { - try { - var ele = '#' + sap.z2ui5.oView.byId(item.ID).getId() + '-inner'; - item.SCROLLTO = $(ele).scrollTop(); - } catch (e) { } - } - }); - } }, - init() { sap.z2ui5.onBeforeRoundtrip.push( this.setBackend.bind(this) ); }, - renderer(oRm, oControl) { - - - if (!oControl.getProperty("setUpdate")){ return; } - - oControl.setProperty("setUpdate", false); - var items = oControl.getProperty("items"); - if(!items){return;}; - - setTimeout( (oControl) => { - var items = oControl.getProperty("items"); - items.forEach(item => { - try { - sap.z2ui5.oView.byId(item.ID).scrollTo(item.SCROLLTO); - } catch { - try { - var ele = '#' + sap.z2ui5.oView.byId(item.ID).getId() + '-inner'; - $(ele).scrollTop(item.SCROLLTO); - } catch { setTimeout( function( item ) { sap.z2ui5.oView.byId(item.ID).scrollTo(item.SCROLLTO); } , 1 , item);} - } - } - ); - - } , 300 , oControl ); + if (items) { + items.forEach(item => { + try { + const scrollDelegate = z2ui5.oView.byId(item.ID).getScrollDelegate(); + item.SCROLLTO = scrollDelegate ? scrollDelegate.getScrollTop() : 0; + } catch { + try { + const element = document.getElementById(`${z2ui5.oView.byId(item.ID).getId()}-inner`); + item.SCROLLTO = element ? element.scrollTop : 0; + } catch {} + } + }); } + }, + + init() { + z2ui5.onBeforeRoundtrip.push(this.setBackend.bind(this)); + }, + + renderer(oRm, oControl) { + if (!oControl.getProperty("setUpdate")) return; + + oControl.setProperty("setUpdate", false); + const items = oControl.getProperty("items"); + if (!items) return; + + setTimeout(() => { + items.forEach(item => { + try { + z2ui5.oView.byId(item.ID).scrollTo(item.SCROLLTO); + } catch { + try { + const element = document.getElementById(`${z2ui5.oView.byId(item.ID).getId()}-inner`); + if (element) element.scrollTop = item.SCROLLTO; + } catch { + setTimeout(() => { + z2ui5.oView.byId(item.ID).scrollTo(item.SCROLLTO); + }, 1); + } + } + }); + }, 100); + } }); -}); } if (!z2ui5.Info) { sap.ui.require([ - "sap/ui/VersionInfo", - "sap/base/util/Version" -], function(VersionInfo, VersionUtil) { - //access the OpenUI5 version at runtime - VersionInfo.load().then(function(oCurrentVersionInfo) { - sap.z2ui5.oCurrentVersionInfo = oCurrentVersionInfo; - }); }); - sap.ui.define("z2ui5/Info",[ - "sap/ui/core/Control" -], (Control ) => { - "use strict"; - - return Control.extend("z2ui5.Info", { - metadata : { - properties: { - ui5_version: { - type: "string" - }, - device_phone: { - type: "string" - }, - device_desktop: { - type: "string" - }, - device_tablet: { - type: "string" - }, - device_combi: { - type: "string" - }, - device_height: { - type: "string" - }, - device_width: { - type: "string" - }, - ui5_gav: { - type: "string" - }, - ui5_theme: { - type: "string" - }, - device_os: { - type: "string" - }, - device_systemtype: { - type: "string" - }, - device_browser: { - type: "string" - }, - }, - events: { - "finished": { - allowPreventDefault: true, - parameters: {}, - } - } - }, - - init () { }, - onAfterRendering() { - }, - onEvent(oControl) { oControl.fireFinished( ); }, - renderer(oRm, oControl) { - oControl.setProperty( "device_phone" , sap.ui.Device.system.phone ); - oControl.setProperty( "device_desktop" , sap.ui.Device.system.desktop ); - oControl.setProperty( "device_tablet" , sap.ui.Device.system.tablet ); - oControl.setProperty( "device_combi" , sap.ui.Device.system.combi ); - oControl.setProperty( "device_height" , sap.ui.Device.resize.height ); - oControl.setProperty( "device_width" , sap.ui.Device.resize.width ); - oControl.setProperty( "ui5_version" , sap.z2ui5.oCurrentVersionInfo.version ); - oControl.setProperty( "ui5_gav" , sap.z2ui5.oCurrentVersionInfo.gav ); - oControl.setProperty( "device_os" , sap.ui.Device.os.name ); - oControl.setProperty( "device_browser" , sap.ui.Device.browser.name ); - setTimeout( oControl.onEvent , 1000 , oControl ); +sap.ui.define("z2ui5/Info", ["sap/ui/core/Control", "sap/ui/VersionInfo", "sap/ui/Device"], (Control, VersionInfo, Device) => { + "use strict"; + return Control.extend("z2ui5.Info", { + metadata: { + properties: { + ui5_version: { + type: "string" + }, + device_phone: { + type: "string" + }, + device_desktop: { + type: "string" + }, + device_tablet: { + type: "string" + }, + device_combi: { + type: "string" + }, + device_height: { + type: "string" + }, + device_width: { + type: "string" + }, + ui5_theme: { + type: "string" + }, + device_os: { + type: "string" + }, + device_systemtype: { + type: "string" + }, + device_browser: { + type: "string" + }, + }, + events: { + "finished": { + allowPreventDefault: true, + parameters: {}, } - }); -}); }if (!z2ui5.Geolocation) { sap.ui.define("z2ui5/Geolocation" , [ - "sap/ui/core/Control" -], (Control) => { - "use strict"; - - return Control.extend("z2ui5.Geolocation", { - metadata : { - properties: { - longitude: { - type: "string", - defaultValue: "" - }, - latitude: { - type: "string", - defaultValue: "" - }, - altitude: { - type: "string", - defaultValue: "" - }, - accuracy: { - type: "string", - defaultValue: "" - }, - altitudeAccuracy: { - type: "string", - defaultValue: "" - }, - speed: { - type: "string", - defaultValue: false - }, - heading: { - type: "string", - defaultValue: false - }, - enableHighAccuracy: { - type: "boolean", - defaultValue: false - }, - timeout: { - type: "string", - defaultValue: "5000" - } - }, - events: { - "finished": { - allowPreventDefault: true, - parameters: {}, - } - } - }, + } + }, - callbackPosition(position){ + init() { }, - var test = position.coords.longitude - this.setProperty("longitude", position.coords.longitude , true); - this.setProperty("latitude", position.coords.latitude , true); - this.setProperty("altitude", position.coords.altitude , true); - this.setProperty("accuracy", position.coords.accuracy , true); - this.setProperty("altitudeAccuracy", position.coords.altitudeAccuracy , true); - this.setProperty("speed", position.coords.speed , true); - this.setProperty("heading", position.coords.heading , true); - this.fireFinished(); - //this.getParent().getParent().getModel().refresh(); + onAfterRendering() { + }, - }, + async renderer(oRm, oControl) { - async init(){ + debugger; + let oDevice = z2ui5.oView.getModel("device").oData; + oControl.setProperty("device_phone", oDevice.system.phone); + oControl.setProperty("device_desktop", oDevice.system.desktop); + oControl.setProperty("device_tablet", oDevice.system.tablet); + oControl.setProperty("device_combi", oDevice.system.combi); + oControl.setProperty("device_height", oDevice.resize.height); + oControl.setProperty("device_width", oDevice.resize.width); + oControl.setProperty("device_os", oDevice.os.name); + oControl.setProperty("device_browser", oDevice.browser.name); + oControl.fireFinished(); - navigator.geolocation.getCurrentPosition(this.callbackPosition.bind(this)); - //navigator.geolocation.watchPosition(this.callbackPosition.bind(this)); + } + }); +} +); - }, +sap.ui.define("z2ui5/Geolocation", ["sap/ui/core/Control"], (Control) => { + "use strict"; - exit () { - //clearWatch + return Control.extend("z2ui5.Geolocation", { + metadata: { + properties: { + longitude: { + type: "string", + defaultValue: "" + }, + latitude: { + type: "string", + defaultValue: "" + }, + altitude: { + type: "string", + defaultValue: "" + }, + accuracy: { + type: "string", + defaultValue: "" + }, + altitudeAccuracy: { + type: "string", + defaultValue: "" }, + speed: { + type: "string", + defaultValue: false + }, + heading: { + type: "string", + defaultValue: false + }, + enableHighAccuracy: { + type: "boolean", + defaultValue: false + }, + timeout: { + type: "string", + defaultValue: "5000" + } + }, + events: { + "finished": { + allowPreventDefault: true, + parameters: {}, + } + } + }, - onAfterRendering() { + callbackPosition(position) { + var test = position.coords.longitude + this.setProperty("longitude", position.coords.longitude, true); + this.setProperty("latitude", position.coords.latitude, true); + this.setProperty("altitude", position.coords.altitude, true); + this.setProperty("accuracy", position.coords.accuracy, true); + this.setProperty("altitudeAccuracy", position.coords.altitudeAccuracy, true); + this.setProperty("speed", position.coords.speed, true); + this.setProperty("heading", position.coords.heading, true); + this.fireFinished(); + //this.getParent().getParent().getModel().refresh(); - }, + }, - renderer(oRm, oControl) { + async init() { - } - }); -}); }if (!z2ui5.FileUploader) { sap.ui.define("z2ui5/FileUploader",[ - "sap/ui/core/Control", - "sap/m/Button", - "sap/ui/unified/FileUploader" - ], function (Control, Button, FileUploader) { - "use strict"; - - return Control.extend("z2ui5.FileUploader", { - - metadata: { - properties: { - value: { - type: "string", - defaultValue: "" - }, - path: { - type: "string", - defaultValue: "" - }, - tooltip: { - type: "string", - defaultValue: "" - }, - fileType: { - type: "string", - defaultValue: "" - }, - placeholder: { - type: "string", - defaultValue: "" - }, - buttonText: { - type: "string", - defaultValue: "" - }, - style: { - type: "string", - defaultValue: "" - }, - uploadButtonText: { - type: "string", - defaultValue: "Upload" - }, - enabled: { - type: "boolean", - defaultValue: true - }, - icon: { - type: "string", - defaultValue: "sap-icon://browse-folder" - }, - iconOnly: { - type: "boolean", - defaultValue: false - }, - buttonOnly: { - type: "boolean", - defaultValue: false - }, - multiple: { - type: "boolean", - defaultValue: false - }, - visible: { - type: "boolean", - defaultValue: true - }, - checkDirectUpload: { - type: "boolean", - defaultValue: false - } - }, - - - aggregations: { - }, - events: { - "upload": { - allowPreventDefault: true, - parameters: {} - } - }, - renderer: null - }, - - renderer: function (oRm, oControl) { - - if (!oControl.getProperty("checkDirectUpload")) { - oControl.oUploadButton = new Button({ - text: oControl.getProperty("uploadButtonText"), - enabled: oControl.getProperty("path") !== "", - press: function (oEvent) { - - this.setProperty("path", this.oFileUploader.getProperty("value")); - - var file = sap.z2ui5.oUpload.oFileUpload.files[0]; - var reader = new FileReader(); - - reader.onload = function (evt) { - var vContent = evt.currentTarget.result; - this.setProperty("value", vContent); - this.fireUpload(); - //this.getView().byId('picture' ).getDomRef().src = vContent; - }.bind(this) - - reader.readAsDataURL(file); - }.bind(oControl) - }); - } - - oControl.oFileUploader = new FileUploader({ - icon: oControl.getProperty("icon"), - iconOnly: oControl.getProperty("iconOnly"), - buttonOnly: oControl.getProperty("buttonOnly"), - buttonText: oControl.getProperty("buttonText"), - style: oControl.getProperty("style"), - fileType: oControl.getProperty("fileType"), - visible: oControl.getProperty("visible"), - uploadOnChange: true, - enabled: oControl.getProperty("enabled"), - value: oControl.getProperty("path"), - placeholder: oControl.getProperty("placeholder"), - change: function (oEvent) { - if (oControl.getProperty("checkDirectUpload")) { - return; - } - - var value = oEvent.getSource().getProperty("value"); - this.setProperty("path", value); - if (value) { - this.oUploadButton.setEnabled(); - } else { - this.oUploadButton.setEnabled(false); - } - this.oUploadButton.rerender(); - sap.z2ui5.oUpload = oEvent.oSource; - }.bind(oControl), - uploadComplete: function (oEvent) { - if (!oControl.getProperty("checkDirectUpload")) { - return; - } - - var value = oEvent.getSource().getProperty("value"); - this.setProperty("path", value); - - var file = oEvent.oSource.oFileUpload.files[0]; - var reader = new FileReader(); - - reader.onload = function (evt) { - var vContent = evt.currentTarget.result; - this.setProperty("value", vContent); - this.fireUpload(); - }.bind(this) - - reader.readAsDataURL(file); - }.bind(oControl) - }); - - var hbox = new sap.m.HBox(); - hbox.addItem(oControl.oFileUploader); - hbox.addItem(oControl.oUploadButton); - oRm.renderControl(hbox); - } - }); - }); }if (!z2ui5.MultiInputExt) { sap.ui.define( "z2ui5/MultiInputExt" , ["sap/ui/core/Control", "sap/m/Token" -], (Control, Token) => { - "use strict"; + navigator.geolocation.getCurrentPosition(this.callbackPosition.bind(this)); + //navigator.geolocation.watchPosition(this.callbackPosition.bind(this)); - return Control.extend("z2ui5.MultiInputExt", { - metadata: { - properties: { - MultiInputId: { type: "String" }, - MultiInputName: { type: "String" }, - addedTokens: { type: "Array" }, - checkInit: { type: "Boolean", defaultValue : false }, - removedTokens: { type: "Array" } - }, - events: { - "change": { - allowPreventDefault: true, - parameters: {} - } - }, - }, + }, - init() { - sap.z2ui5.onAfterRendering.push( this.setControl.bind(this) ); - }, + exit() {//clearWatch + }, - onTokenUpdate(oEvent) { - this.setProperty("addedTokens", []); - this.setProperty("removedTokens", []); + onAfterRendering() { + }, - if (oEvent.mParameters.type == "removed") { - let removedTokens = []; - oEvent.mParameters.removedTokens.forEach((item) => { - removedTokens.push({ KEY: item.getKey(), TEXT: item.getText() }); - }); - this.setProperty("removedTokens", removedTokens); - } else { - let addedTokens = []; - oEvent.mParameters.addedTokens.forEach((item) => { - addedTokens.push({ KEY: item.getKey(), TEXT: item.getText() }); - }); - this.setProperty("addedTokens", addedTokens); - } - this.fireChange(); - }, - renderer(oRm, oControl) { sap.z2ui5.onAfterRendering.push( this.setControl.bind(oControl) ); - }, - setControl(){ - let table = sap.z2ui5.oView.byId( this.getProperty("MultiInputId") ); - if (!table) { - try{ table = sap.ui.getCore( ).byId( - document.getElementsByName(this.getProperty("MultiInputName"))[0].id.replace('-inner', '') - ); -}catch (e){ return; } } - if ( !table ){ return; } - if ( this.getProperty("checkInit") == true ){ return; } - this.setProperty( "checkInit" , true ); - table.attachTokenUpdate(this.onTokenUpdate.bind(this)); - var fnValidator = function (args) { - var text = args.text; - return new Token({ key: text, text: text }); - }; - table.addValidator(fnValidator); }, - renderer(oRM, oControl) { - } + renderer(oRm, oControl) { + } }); -}); }if (!z2ui5.UITableExt) { sap.ui.define("z2ui5/UITableExt" , [ - "sap/ui/core/Control" -], (Control) => { - "use strict"; +} +); - return Control.extend("z2ui5.UITableExt", { - metadata: { - properties: { - tableId: { type: "String" } - } - }, +sap.ui.define("z2ui5/FileUploader", ["sap/ui/core/Control", "sap/m/Button", "sap/ui/unified/FileUploader", "sap/m/HBox"], function (Control, Button, FileUploader, HBox) { + "use strict"; - init() { - sap.z2ui5.onBeforeRoundtrip.push(this.readFilter.bind(this)); - sap.z2ui5.onAfterRoundtrip.push(this.setFilter.bind(this)); - }, + return Control.extend("z2ui5.FileUploader", { - readFilter() { - try { - let id = this.getProperty("tableId"); - let oTable = sap.z2ui5.oView.byId(id); - this.aFilters = oTable.getBinding().aFilters; - } catch (e) { }; + metadata: { + properties: { + value: { + type: "string", + defaultValue: "" + }, + path: { + type: "string", + defaultValue: "" + }, + tooltip: { + type: "string", + defaultValue: "" + }, + fileType: { + type: "string", + defaultValue: "" + }, + placeholder: { + type: "string", + defaultValue: "" + }, + buttonText: { + type: "string", + defaultValue: "" + }, + style: { + type: "string", + defaultValue: "" + }, + uploadButtonText: { + type: "string", + defaultValue: "Upload" + }, + enabled: { + type: "boolean", + defaultValue: true + }, + icon: { + type: "string", + defaultValue: "sap-icon://browse-folder" + }, + iconOnly: { + type: "boolean", + defaultValue: false + }, + buttonOnly: { + type: "boolean", + defaultValue: false + }, + multiple: { + type: "boolean", + defaultValue: false + }, + visible: { + type: "boolean", + defaultValue: true + }, + checkDirectUpload: { + type: "boolean", + defaultValue: false + } }, - setFilter() { - try { - setTimeout( (aFilters) => { let id = this.getProperty("tableId"); - let oTable = sap.z2ui5.oView.byId(id); - oTable.getBinding().filter(aFilters); - } , 100 , this.aFilters); } catch (e) { }; + aggregations: {}, + events: { + "upload": { + allowPreventDefault: true, + parameters: {} + } }, + renderer: null + }, - renderer(oRM, oControl) { - } - }); -}); }if (!z2ui5.Util) { sap.ui.define("z2ui5/Util" , [], ()=>{ - "use strict"; - return { - DateCreateObject: (s) => new Date(s), - DateAbapTimestampToDate: (sTimestamp) => new sap.gantt.misc.Format.abapTimestampToDate(sTimestamp), - DateAbapDateToDateObject: (d) => new Date(d.slice(0, 4), parseInt(d.slice(4, 6)) - 1, d.slice(6, 8)), - DateAbapDateTimeToDateObject: (d, t = '000000') => new Date(d.slice(0, 4), - parseInt(d.slice(4, 6)) - 1, d.slice(6, 8), t.slice(0, 2), t.slice(2, 4), t.slice(4, 6)), - }; - }); sap.ui.require(["z2ui5/Util"], (Util) => { z2ui5.Util = Util; - }); }if (!z2ui5.Favicon) { sap.ui.define("z2ui5/Favicon" , [ "sap/ui/core/Control"], (Control)=>{ - "use strict"; - return Control.extend("z2ui5.Favicon", { - metadata: { - properties: { - favicon: { - type: "string" - }, - } - }, - setFavicon(val) { - this.setProperty("favicon", val); - let headTitle = document.querySelector('head'); - let setFavicon = document.createElement('link'); - setFavicon.setAttribute('rel','shortcut icon'); - setFavicon.setAttribute('href',val); - headTitle.appendChild(setFavicon); - }, - renderer(oRm, oControl) {} - }); - }); }if (!z2ui5.Dirty) { sap.ui.define("z2ui5/Dirty" , ["sap/ui/core/Control"], (Control)=>{ - "use strict"; - return Control.extend("z2ui5.Dirty", { - metadata: { - properties: { - isDirty: { - type: "string" - }, - } - }, - setIsDirty(val) { - // var dirty = !!sap.z2ui5.oResponse.PARAMS?.DIRTY; - if (sap.ushell?.Container) { - sap.ushell.Container.setDirtyFlag(val); - } else { - window.onbeforeunload = function (e) { - if (val) { - e.preventDefault(); - } - } - } - }, - renderer(oRm, oControl) {} - }); - }); } + renderer: function (oRm, oControl) { + if (!oControl.getProperty("checkDirectUpload")) { + oControl.oUploadButton = new Button({ + text: oControl.getProperty("uploadButtonText"), + enabled: oControl.getProperty("path") !== "", + press: function (oEvent) { + this.setProperty("path", this.oFileUploader.getProperty("value")); + var file = z2ui5.oUpload.oFileUpload.files[0]; + var reader = new FileReader(); + reader.onload = function (evt) { + var vContent = evt.currentTarget.result; + this.setProperty("value", vContent); + this.fireUpload(); + //this.getView().byId('picture' ).getDomRef().src = vContent; + } + .bind(this) + reader.readAsDataURL(file); + } + .bind(oControl) + }); + } + oControl.oFileUploader = new FileUploader({ + icon: oControl.getProperty("icon"), + iconOnly: oControl.getProperty("iconOnly"), + buttonOnly: oControl.getProperty("buttonOnly"), + buttonText: oControl.getProperty("buttonText"), + style: oControl.getProperty("style"), + fileType: oControl.getProperty("fileType"), + visible: oControl.getProperty("visible"), + uploadOnChange: true, + enabled: oControl.getProperty("enabled"), + value: oControl.getProperty("path"), + placeholder: oControl.getProperty("placeholder"), + change: function (oEvent) { + if (oControl.getProperty("checkDirectUpload")) { + return; + } + var value = oEvent.getSource().getProperty("value"); + this.setProperty("path", value); + if (value) { + this.oUploadButton.setEnabled(); + } else { + this.oUploadButton.setEnabled(false); + } + this.oUploadButton.rerender(); + z2ui5.oUpload = oEvent.oSource; + } + .bind(oControl), + uploadComplete: function (oEvent) { + if (!oControl.getProperty("checkDirectUpload")) { + return; + } + var value = oEvent.getSource().getProperty("value"); + this.setProperty("path", value); + var file = oEvent.oSource.oFileUpload.files[0]; + var reader = new FileReader(); + reader.onload = function (evt) { + var vContent = evt.currentTarget.result; + this.setProperty("value", vContent); + this.fireUpload(); + } + .bind(this) + reader.readAsDataURL(file); + } + .bind(oControl) + }); + + var hbox = new HBox(); + hbox.addItem(oControl.oFileUploader); + hbox.addItem(oControl.oUploadButton); + oRm.renderControl(hbox); + } + }); +}); +sap.ui.define("z2ui5/MultiInputExt", ["sap/ui/core/Control", "sap/m/Token", "sap/ui/core/Core", "sap/ui/core/Element"], (Control, Token, Core, Element) => { + "use strict"; - }, - __beforeunload: function(){ - window.removeEventListener("__beforeunload", this.__beforeunload.bind(this)); - this.destroy(); //manually call destroy as it is only fired in FLP - }, - __pagehide: function(){ - window.removeEventListener("pagehide", this.__pagehide.bind(this)); - this.destroy(); //manually call destroy as it is only fired in FLP - }, - exit: function(){ - if(sap.z2ui5.contextId){ - fetch(sap.z2ui5.pathname, { - method: 'HEAD', - keepalive: true, - headers: { - 'sap-terminate': 'session', - 'sap-contextid': sap.z2ui5.contextId, - 'sap-contextid-accept': 'header' - } - }); - delete sap.z2ui5.contextId; - } - if(UIComponent.prototype.exit) UIComponent.prototype.exit.apply(this, arguments); - }, - }); + return Control.extend("z2ui5.MultiInputExt", { + metadata: { + properties: { + MultiInputId: { + type: "String" + }, + MultiInputName: { + type: "String" + }, + addedTokens: { + type: "Array" + }, + checkInit: { + type: "Boolean", + defaultValue: false + }, + removedTokens: { + type: "Array" + } + }, + events: { + "change": { + allowPreventDefault: true, + parameters: {} + } + }, + }, + + init() { + z2ui5.onAfterRendering.push(this.setControl.bind(this)); + }, + + onTokenUpdate(oEvent) { + this.setProperty("addedTokens", []); + this.setProperty("removedTokens", []); + + if (oEvent.mParameters.type == "removed") { + let removedTokens = []; + oEvent.mParameters.removedTokens.forEach((item) => { + removedTokens.push({ + KEY: item.getKey(), + TEXT: item.getText() }); + } + ); + this.setProperty("removedTokens", removedTokens); + } else { + let addedTokens = []; + oEvent.mParameters.addedTokens.forEach((item) => { + addedTokens.push({ + KEY: item.getKey(), + TEXT: item.getText() + }); + } + ); + this.setProperty("addedTokens", addedTokens); + } + this.fireChange(); + }, + renderer(oRm, oControl) { + z2ui5.onAfterRendering.push(this.setControl.bind(oControl)); + }, + setControl() { + let table = z2ui5.oView.byId(this.getProperty("MultiInputId")); + if (!table) { + try { + // table = sap.ui.getCore().byId(document.getElementsByName(this.getProperty("MultiInputName"))[0].id.replace('-inner', '')); + table = Core.byId(Element.getElementsByName(this.getProperty("MultiInputName"))[0].id.replace('-inner', '')); + + } catch (e) { + return; + } + } + if (!table) { + return; + } + if (this.getProperty("checkInit") == true) { + return; + } + this.setProperty("checkInit", true); + table.attachTokenUpdate(this.onTokenUpdate.bind(this)); + var fnValidator = function (args) { + var text = args.text; + return new Token({ + key: text, + text: text + }); + }; + table.addValidator(fnValidator); + }, + renderer(oRM, oControl) { } + }); +} +); + +sap.ui.define("z2ui5/UITableExt", ["sap/ui/core/Control"], (Control) => { + "use strict"; + + return Control.extend("z2ui5.UITableExt", { + metadata: { + properties: { + tableId: { + type: "String" + } + } + }, + + init() { + z2ui5.onBeforeRoundtrip.push(this.readFilter.bind(this)); + z2ui5.onAfterRoundtrip.push(this.setFilter.bind(this)); + }, + + readFilter() { + try { + let id = this.getProperty("tableId"); + let oTable = z2ui5.oView.byId(id); + this.aFilters = oTable.getBinding().aFilters; + } catch (e) { } + ; + }, + + setFilter() { + try { + setTimeout((aFilters) => { + let id = this.getProperty("tableId"); + let oTable = z2ui5.oView.byId(id); + oTable.getBinding().filter(aFilters); + } + , 100, this.aFilters); + } catch (e) { } + ; + }, + + renderer(oRM, oControl) { } + }); +} +); +sap.ui.define("z2ui5/Util", [], () => { + "use strict"; + return { + DateCreateObject: (s) => new Date(s), + DateAbapTimestampToDate: (sTimestamp) => new sap.gantt.misc.Format.abapTimestampToDate(sTimestamp), + DateAbapDateToDateObject: (d) => new Date(d.slice(0, 4), parseInt(d.slice(4, 6)) - 1, d.slice(6, 8)), + DateAbapDateTimeToDateObject: (d, t = '000000') => new Date(d.slice(0, 4), parseInt(d.slice(4, 6)) - 1, d.slice(6, 8), t.slice(0, 2), t.slice(2, 4), t.slice(4, 6)), + }; +} +); +sap.ui.require(["z2ui5/Util"], (Util) => { + z2ui5.Util = Util; +} +); + +sap.ui.define("z2ui5/Favicon", ["sap/ui/core/Control"], (Control) => { + "use strict"; + return Control.extend("z2ui5.Favicon", { + metadata: { + properties: { + favicon: { + type: "string" + }, + } + }, + setFavicon(val) { + this.setProperty("favicon", val); + let headTitle = document.querySelector('head'); + let setFavicon = document.createElement('link'); + setFavicon.setAttribute('rel', 'shortcut icon'); + setFavicon.setAttribute('href', val); + headTitle.appendChild(setFavicon); + }, + renderer(oRm, oControl) { } + }); +} +); - \ No newline at end of file +sap.ui.define("z2ui5/Dirty", ["sap/ui/core/Control", "sap/ushell/Container"], (Control, Container) => { + "use strict"; + return Control.extend("z2ui5.Dirty", { + metadata: { + properties: { + isDirty: { + type: "string" + }, + } + }, + setIsDirty(val) { + if (Container) { + Container.setDirtyFlag(val); + } else { + window.onbeforeunload = function (e) { + if (val) { + e.preventDefault(); + } + } + } + }, + renderer(oRm, oControl) { } + }); +} +); \ No newline at end of file diff --git a/src/02/zabap2ui5.wapa.controller_-view1.controller.js b/src/02/z2ui5.wapa.controller_-view1.controller.js similarity index 78% rename from src/02/zabap2ui5.wapa.controller_-view1.controller.js rename to src/02/z2ui5.wapa.controller_-view1.controller.js index 6d1df06..cd778a2 100644 --- a/src/02/zabap2ui5.wapa.controller_-view1.controller.js +++ b/src/02/z2ui5.wapa.controller_-view1.controller.js @@ -1,186 +1,246 @@ - -sap.ui.define(["sap/ui/core/mvc/Controller", "sap/ui/core/mvc/XMLView", "sap/ui/model/json/JSONModel", "sap/ui/core/BusyIndicator", "sap/m/MessageBox", "sap/m/MessageToast", "sap/ui/core/Fragment", "sap/m/BusyDialog", "sap/ui/VersionInfo" ], -function(Controller, XMLView, JSONModel, BusyIndicator, MessageBox, MessageToast, Fragment, mBusyDialog, VersionInfo ) { +sap.ui.define(["sap/ui/core/mvc/Controller", "sap/ui/core/mvc/XMLView", "sap/ui/model/json/JSONModel",  + "sap/ui/core/BusyIndicator", "sap/m/MessageBox", "sap/m/MessageToast", "sap/ui/core/Fragment", "sap/m/BusyDialog", + "sap/ui/VersionInfo", "z2ui5/cc/Server", + ],  + function(Controller, XMLView, JSONModel, BusyIndicator, MessageBox, MessageToast, Fragment, mBusyDialog, VersionInfo,  + Server ) { "use strict"; return Controller.extend("z2ui5.controller.View1", { + + onInit (){ + + z2ui5.oRouter.attachRouteMatched(function(oEvent) { + z2ui5.checkInit = true; + Server.Roundtrip(); + }, this); + + }, async onAfterRendering() { - try{ - if (!sap.z2ui5.oResponse.PARAMS) { - BusyIndicator.hide(); - sap.z2ui5.isBusy = false; + + if (!z2ui5.oResponse){ return; } - const {S_POPUP, S_VIEW_NEST, S_VIEW_NEST2, S_POPOVER} = sap.z2ui5.oResponse.PARAMS; - if (S_POPUP?.CHECK_DESTROY) { - sap.z2ui5.oController.PopupDestroy(); - } - if (S_POPOVER?.CHECK_DESTROY) { - sap.z2ui5.oController.PopoverDestroy(); - } - if (S_POPUP?.XML) { - sap.z2ui5.oController.PopupDestroy(); - await this.displayFragment(S_POPUP.XML, 'oViewPopup'); - } - if (!sap.z2ui5.checkNestAfter) { - if (S_VIEW_NEST?.XML) { - sap.z2ui5.oController.NestViewDestroy(); - await this.displayNestedView(S_VIEW_NEST.XML, 'oViewNest', 'S_VIEW_NEST'); - sap.z2ui5.checkNestAfter = true; + try { + if (!z2ui5.oResponse.PARAMS) { + BusyIndicator.hide(); + z2ui5.isBusy = false; + return; } - } - if (!sap.z2ui5.checkNestAfter2) { - if (S_VIEW_NEST2?.XML) { - sap.z2ui5.oController.NestViewDestroy2(); - await this.displayNestedView2(S_VIEW_NEST2.XML, 'oViewNest2', 'S_VIEW_NEST2'); - sap.z2ui5.checkNestAfter2 = true; + const {S_POPUP, S_VIEW_NEST, S_VIEW_NEST2, S_POPOVER} = z2ui5.oResponse.PARAMS; + if (S_POPUP?.CHECK_DESTROY) { + z2ui5.oController.PopupDestroy(); } - } - if (S_POPOVER?.XML) { - await this.displayPopover(S_POPOVER.XML, 'oViewPopover', S_POPOVER.OPEN_BY_ID); - } - BusyIndicator.hide(); - sap.z2ui5.isBusy = false; - sap.z2ui5.onAfterRendering.forEach(item=>{ - if (item !== undefined) { - item(); + if (S_POPOVER?.CHECK_DESTROY) { + z2ui5.oController.PopoverDestroy(); + } + if (S_POPUP?.XML) { + z2ui5.oController.PopupDestroy(); + await this.displayFragment(S_POPUP.XML, 'oViewPopup'); } + if (!z2ui5.checkNestAfter) { + if (S_VIEW_NEST?.XML) { + z2ui5.oController.NestViewDestroy(); + await this.displayNestedView(S_VIEW_NEST.XML, 'oViewNest', 'S_VIEW_NEST'); + z2ui5.checkNestAfter = true; + } + } + if (!z2ui5.checkNestAfter2) { + if (S_VIEW_NEST2?.XML) { + z2ui5.oController.NestViewDestroy2(); + await this.displayNestedView2(S_VIEW_NEST2.XML, 'oViewNest2', 'S_VIEW_NEST2'); + z2ui5.checkNestAfter2 = true; + } + } + if (S_POPOVER?.XML) { + await this.displayPopover(S_POPOVER.XML, 'oViewPopover', S_POPOVER.OPEN_BY_ID); + } + BusyIndicator.hide(); + z2ui5.isBusy = false; + z2ui5.onAfterRendering.forEach(item => { + if (item !== undefined) { + item(); + } + } + ) + } catch (e) { + BusyIndicator.hide(); + z2ui5.isBusy = false; + MessageBox.error(e.toLocaleString(), { + title: "Unexpected Error Occured - App Terminated", + actions: [], + onClose: () => { + new mBusyDialog({ + text: "Please Restart the App" + }).open(); + } + }) } - ) - }catch(e){BusyIndicator.hide(); sap.z2ui5.isBusy = false; MessageBox.error( e.toLocaleString() , { title : "Unexpected Error Occured - App Terminated" , actions : [ ] , onClose : () => { new mBusyDialog({ text : "Please Restart the App" -}).open(); } } ) } }, - async displayFragment(xml, viewProp) { - let oview_model = new JSONModel(sap.z2ui5.oResponse.OVIEWMODEL); + let oview_model = new JSONModel(z2ui5.oResponse.OVIEWMODEL); const oFragment = await Fragment.load({ definition: xml, - controller: sap.z2ui5.oControllerPopup, + controller: z2ui5.oControllerPopup, id: "popupId" }); - // oview_model.setSizeLimit(sap.z2ui5.JSON_MODEL_LIMIT); oFragment.setModel(oview_model); - sap.z2ui5[viewProp] = oFragment; - sap.z2ui5[viewProp].Fragment = Fragment; - oFragment.open(); + z2ui5[viewProp] = oFragment; + z2ui5[viewProp].Fragment = Fragment; + oFragment.open(); }, async displayPopover(xml, viewProp, openById) { - // let sapUiCore = sap.ui.require('sap/ui/core/Core'); - sap.ui.require(["sap/ui/core/Element"], async function(Element) { - const oFragment = await Fragment.load({ - definition: xml, - controller: sap.z2ui5.oControllerPopover, - id: "popoverId" - }); - let oview_model = new JSONModel(sap.z2ui5.oResponse.OVIEWMODEL); - // oview_model.setSizeLimit(sap.z2ui5.JSON_MODEL_LIMIT); - oFragment.setModel(oview_model); - sap.z2ui5[viewProp] = oFragment; - sap.z2ui5[viewProp].Fragment = Fragment; - let oControl = {}; - if( sap.z2ui5.oView?.byId(openById) ) { - oControl = sap.z2ui5.oView.byId(openById); - } else if ( sap.z2ui5.oViewPopup?.Fragment.byId('popupId',openById) ) { - oControl = sap.z2ui5.oViewPopup.Fragment.byId('popupId',openById); - } else if ( sap.z2ui5.oViewNest?.byId(openById) ) { - oControl = sap.z2ui5.oViewNest.byId(openById); - } else if ( sap.z2ui5.oViewNest2?.byId(openById) ) { - oControl = sap.z2ui5.oViewNest2.byId(openById); - } else { - if(sapUiCore.byId(openById)) { - // oControl = sapUiCore.byId(openById); - oControl = Element.getElementById(openById); + sap.ui.require(["sap/ui/core/Element"], async function(Element) { + const oFragment = await Fragment.load({ + definition: xml, + controller: z2ui5.oControllerPopover, + id: "popoverId" + }); + let oview_model = new JSONModel(z2ui5.oResponse.OVIEWMODEL); + oFragment.setModel(oview_model); + z2ui5[viewProp] = oFragment; + z2ui5[viewProp].Fragment = Fragment; + let oControl = {}; + if (z2ui5.oView?.byId(openById)) { + oControl = z2ui5.oView.byId(openById); + } else if (z2ui5.oViewPopup?.Fragment.byId('popupId', openById)) { + oControl = z2ui5.oViewPopup.Fragment.byId('popupId', openById); + } else if (z2ui5.oViewNest?.byId(openById)) { + oControl = z2ui5.oViewNest.byId(openById); + } else if (z2ui5.oViewNest2?.byId(openById)) { + oControl = z2ui5.oViewNest2.byId(openById); } else { - oControl = null; - }; - } - oFragment.openBy(oControl); - }); }, + if (sapUiCore.byId(openById)) { + // oControl = sapUiCore.byId(openById); + oControl = Element.getElementById(openById); + } else { + oControl = null; + } + ; + } + oFragment.openBy(oControl); + }); + }, async displayNestedView(xml, viewProp, viewNestId) { - let oview_model = new JSONModel(sap.z2ui5.oResponse.OVIEWMODEL); + let oview_model = new JSONModel(z2ui5.oResponse.OVIEWMODEL); const oView = await XMLView.create({ definition: xml, - controller: sap.z2ui5.oControllerNest, - preprocessors: { xml: { models: { template: oview_model } } } + controller: z2ui5.oControllerNest, + preprocessors: { + xml: { + models: { + template: oview_model + } + } + } }); - // oview_model.setSizeLimit(sap.z2ui5.JSON_MODEL_LIMIT); oView.setModel(oview_model); - let oParent = sap.z2ui5.oView.byId(sap.z2ui5.oResponse.PARAMS[viewNestId].ID); + let oParent = z2ui5.oView.byId(z2ui5.oResponse.PARAMS[viewNestId].ID); if (oParent) { try { - oParent[sap.z2ui5.oResponse.PARAMS[viewNestId].METHOD_DESTROY](); + oParent[z2ui5.oResponse.PARAMS[viewNestId].METHOD_DESTROY](); } catch {} - oParent[sap.z2ui5.oResponse.PARAMS[viewNestId].METHOD_INSERT](oView); + oParent[z2ui5.oResponse.PARAMS[viewNestId].METHOD_INSERT](oView); } - sap.z2ui5[viewProp] = oView; + z2ui5[viewProp] = oView; }, async displayNestedView2(xml, viewProp, viewNestId) { - let oview_model = new JSONModel(sap.z2ui5.oResponse.OVIEWMODEL); + let oview_model = new JSONModel(z2ui5.oResponse.OVIEWMODEL); const oView = await XMLView.create({ definition: xml, - controller: sap.z2ui5.oControllerNest2, - preprocessors: { xml: { models: { template: oview_model } } } + controller: z2ui5.oControllerNest2, + preprocessors: { + xml: { + models: { + template: oview_model + } + } + } }); - // oview_model.setSizeLimit(sap.z2ui5.JSON_MODEL_LIMIT); oView.setModel(oview_model); - let oParent = sap.z2ui5.oView.byId(sap.z2ui5.oResponse.PARAMS[viewNestId].ID); + let oParent = z2ui5.oView.byId(z2ui5.oResponse.PARAMS[viewNestId].ID); if (oParent) { try { - oParent[sap.z2ui5.oResponse.PARAMS[viewNestId].METHOD_DESTROY](); + oParent[z2ui5.oResponse.PARAMS[viewNestId].METHOD_DESTROY](); } catch {} - oParent[sap.z2ui5.oResponse.PARAMS[viewNestId].METHOD_INSERT](oView); + oParent[z2ui5.oResponse.PARAMS[viewNestId].METHOD_INSERT](oView); } - sap.z2ui5[viewProp] = oView; + z2ui5[viewProp] = oView; }, PopupDestroy() { - if (!sap.z2ui5.oViewPopup) { + if (!z2ui5.oViewPopup) { return; } - if (sap.z2ui5.oViewPopup.close) { + if (z2ui5.oViewPopup.close) { try { - sap.z2ui5.oViewPopup.close(); + z2ui5.oViewPopup.close(); } catch {} } - sap.z2ui5.oViewPopup.destroy(); + z2ui5.oViewPopup.destroy(); }, PopoverDestroy() { - if (!sap.z2ui5.oViewPopover) { + if (!z2ui5.oViewPopover) { return; } - if (sap.z2ui5.oViewPopover.close) { + if (z2ui5.oViewPopover.close) { try { - sap.z2ui5.oViewPopover.close(); + z2ui5.oViewPopover.close(); } catch {} } - sap.z2ui5.oViewPopover.destroy(); + z2ui5.oViewPopover.destroy(); }, NestViewDestroy() { - if (!sap.z2ui5.oViewNest) { + if (!z2ui5.oViewNest) { return; } - sap.z2ui5.oViewNest.destroy(); + z2ui5.oViewNest.destroy(); }, NestViewDestroy2() { - if (!sap.z2ui5.oViewNest2) { + if (!z2ui5.oViewNest2) { return; } - sap.z2ui5.oViewNest2.destroy(); + z2ui5.oViewNest2.destroy(); }, ViewDestroy() { - if (!sap.z2ui5.oView) { + if (!z2ui5.oView) { return; } - sap.z2ui5.oView.destroy(); + z2ui5.oView.destroy(); }, eF(...args) { - sap.z2ui5.onBeforeEventFrontend.forEach(item => { + + z2ui5.onBeforeEventFrontend.forEach(item => { if (item !== undefined) { item(args); } - } + } ) let oCrossAppNavigator; switch (args[0]) { + case 'SET_SIZE_LIMIT': + switch (args[2]) { + case 'MAIN': + z2ui5.oView.getModel().setSizeLimit(parseInt(args[1])); + z2ui5.oView.getModel().refresh(true); + break; + case 'NEST': + z2ui5.oViewNest.getModel().setSizeLimit(parseInt(args[1])); + z2ui5.oViewNest.getModel().refresh(true); + break; + case 'NEST2': + z2ui5.oViewNest2.getModel().setSizeLimit(parseInt(args[1])); + z2ui5.oViewNest2.getModel().refresh(true); + break; + case 'POPUP': + z2ui5.oPopup.getModel().setSizeLimit(parseInt(args[1])); + z2ui5.oPopup.getModel().refresh(true); + break; + case 'POPOVER': + z2ui5.oPopover.getModel().setSizeLimit(parseInt(args[1])); + z2ui5.oPopover.getModel().refresh(true); + break; + } + break; case 'DOWNLOAD_B64_FILE': var a = document.createElement("a"); a.href = args[1]; @@ -188,10 +248,12 @@ function(Controller, XMLView, JSONModel, BusyIndicator, MessageBox, MessageToast a.click(); break; case 'CROSS_APP_NAV_TO_PREV_APP': + // oCrossAppNavigator = Container.getService("CrossApplicationNavigation"); oCrossAppNavigator = sap.ushell.Container.getService("CrossApplicationNavigation"); oCrossAppNavigator.backToPreviousApp(); break; case 'CROSS_APP_NAV_TO_EXT': + // oCrossAppNavigator = Container.getService("CrossApplicationNavigation"); oCrossAppNavigator = sap.ushell.Container.getService("CrossApplicationNavigation"); const hash = (oCrossAppNavigator.hrefForExternal({ target: args[1], @@ -199,7 +261,8 @@ function(Controller, XMLView, JSONModel, BusyIndicator, MessageBox, MessageToast })) || ""; if (args[3] === 'EXT') { let url = window.location.href.split('#')[0] + hash; - sap.m.URLHelper.redirect(url, true); + //todo + //URLHelper.redirect(url, true); } else { oCrossAppNavigator.toExternal({ target: { @@ -215,268 +278,191 @@ function(Controller, XMLView, JSONModel, BusyIndicator, MessageBox, MessageToast window.open(args[1], '_blank'); break; case 'POPUP_CLOSE': - sap.z2ui5.oController.PopupDestroy(); + z2ui5.oController.PopupDestroy(); break; case 'POPOVER_CLOSE': - sap.z2ui5.oController.PopoverDestroy(); + z2ui5.oController.PopoverDestroy(); break; case 'NAV_CONTAINER_TO': - var navCon = sap.z2ui5.oView.byId(args[1]); - var navConTo = sap.z2ui5.oView.byId(args[2]); + var navCon = z2ui5.oView.byId(args[1]); + var navConTo = z2ui5.oView.byId(args[2]); navCon.to(navConTo); break; case 'NEST_NAV_CONTAINER_TO': - navCon = sap.z2ui5.oViewNest.byId(args[1]); - navConTo = sap.z2ui5.oViewNest.byId(args[2]); + navCon = z2ui5.oViewNest.byId(args[1]); + navConTo = z2ui5.oViewNest.byId(args[2]); navCon.to(navConTo); break; case 'NEST2_NAV_CONTAINER_TO': - navCon = sap.z2ui5.oViewNest2.byId(args[1]); - navConTo = sap.z2ui5.oViewNest2.byId(args[2]); + navCon = z2ui5.oViewNest2.byId(args[1]); + navConTo = z2ui5.oViewNest2.byId(args[2]); navCon.to(navConTo); break; case 'POPUP_NAV_CONTAINER_TO': - navCon = Fragment.byId("popupId",args[1]); - navConTo = Fragment.byId("popupId",args[2]); + navCon = Fragment.byId("popupId", args[1]); + navConTo = Fragment.byId("popupId", args[2]); navCon.to(navConTo); break; } }, eB(...args) { + + // var oRouter = sap.ui.core.UIComponent.getRouterFor(this); + //debugger; + // z2ui5.oRouter.navTo("RouteView2"); + // return; + if (!window.navigator.onLine) { MessageBox.alert('No internet connection! Please reconnect to the server and try again.'); return; } - if (sap.z2ui5.isBusy == true) { - if (!args[0][2]) { - let oBusyDialog = new mBusyDialog(); - oBusyDialog.open(); - setTimeout( (oBusyDialog) => { oBusyDialog.close() } , 100 , oBusyDialog ); + if (z2ui5.isBusy == true) { + if (!args[0][2]) { + let oBusyDialog = new mBusyDialog(); + oBusyDialog.open(); + setTimeout( (oBusyDialog) => { + oBusyDialog.close() + } + , 100, oBusyDialog); return; - } } - sap.z2ui5.isBusy = true; - BusyIndicator.show(); - sap.z2ui5.oBody = {}; - if ( args[0][3] ) { - sap.z2ui5.oBody.XX = sap.z2ui5.oView.getModel().getData().XX; - sap.z2ui5.oBody.VIEWNAME = 'MAIN'; } - else if ( sap.z2ui5.oController == this ) { - sap.z2ui5.oBody.XX = sap.z2ui5.oView.getModel().getData().XX; - sap.z2ui5.oBody.VIEWNAME = 'MAIN'; - }else if - ( sap.z2ui5.oControllerPopup == this ) { - if (sap.z2ui5.oViewPopup){ - sap.z2ui5.oBody.XX = sap.z2ui5.oViewPopup.getModel().getData().XX; - } - sap.z2ui5.oBody.VIEWNAME = 'MAIN'; - }else if ( - sap.z2ui5.oControllerPopover == this ) { - sap.z2ui5.oBody.XX = sap.z2ui5.oViewPopover.getModel().getData().XX; - sap.z2ui5.oBody.VIEWNAME = 'MAIN'; - }else if ( - sap.z2ui5.oControllerNest == this ) { - sap.z2ui5.oBody.XX = sap.z2ui5.oViewNest.getModel().getData().XX; - sap.z2ui5.oBody.VIEWNAME = 'NEST'; - }else if ( - sap.z2ui5.oControllerNest2 == this ) { - sap.z2ui5.oBody.XX = sap.z2ui5.oViewNest2.getModel().getData().XX; - sap.z2ui5.oBody.VIEWNAME = 'NEST2'; + z2ui5.isBusy = true; + BusyIndicator.show(); + z2ui5.oBody = {}; + if (args[0][3]) { + z2ui5.oBody.XX = z2ui5.oView.getModel().getData().XX; + z2ui5.oBody.VIEWNAME = 'MAIN'; + } else if (z2ui5.oController == this) { + z2ui5.oBody.XX = z2ui5.oView.getModel().getData().XX; + z2ui5.oBody.VIEWNAME = 'MAIN'; + } else if (z2ui5.oControllerPopup == this) { + if (z2ui5.oViewPopup) { + z2ui5.oBody.XX = z2ui5.oViewPopup.getModel().getData().XX; } - sap.z2ui5.onBeforeRoundtrip.forEach(item=>{ + z2ui5.oBody.VIEWNAME = 'MAIN'; + } else if (z2ui5.oControllerPopover == this) { + z2ui5.oBody.XX = z2ui5.oViewPopover.getModel().getData().XX; + z2ui5.oBody.VIEWNAME = 'MAIN'; + } else if (z2ui5.oControllerNest == this) { + z2ui5.oBody.XX = z2ui5.oViewNest.getModel().getData().XX; + z2ui5.oBody.VIEWNAME = 'NEST'; + } else if (z2ui5.oControllerNest2 == this) { + z2ui5.oBody.XX = z2ui5.oViewNest2.getModel().getData().XX; + z2ui5.oBody.VIEWNAME = 'NEST2'; + } + z2ui5.onBeforeRoundtrip.forEach(item => { if (item !== undefined) { item(); - }}) + } + } + ) if (args[0][1]) { - sap.z2ui5.oController.ViewDestroy(); + z2ui5.oController.ViewDestroy(); } - sap.z2ui5.oBody.ID = sap.z2ui5.oResponse.ID; - sap.z2ui5.oBody.ARGUMENTS = args; - sap.z2ui5.oBody.ARGUMENTS.forEach( ( item , i ) => { - if ( i == 0 ) { return; } if ( typeof item === 'object' ){ - sap.z2ui5.oBody.ARGUMENTS[ i ] = JSON.stringify( item ); - } - }); - sap.z2ui5.oResponseOld = sap.z2ui5.oResponse; - sap.z2ui5.oController.Roundtrip(); - }, - responseError(response) { - document.write(response); - }, - updateModelIfRequired(paramKey, oView) { - if (sap.z2ui5.oResponse.PARAMS == undefined) { return; } - if (sap.z2ui5.oResponse.PARAMS[paramKey]?.CHECK_UPDATE_MODEL) { - let model = new JSONModel(sap.z2ui5.oResponse.OVIEWMODEL); - // model.setSizeLimit(sap.z2ui5.JSON_MODEL_LIMIT); - if (oView) { oView.setModel(model); } + z2ui5.oBody.ID = z2ui5.oResponse.ID; + z2ui5.oBody.ARGUMENTS = args; + z2ui5.oBody.ARGUMENTS.forEach( (item, i) => { + if (i == 0) { + return; + } + if (typeof item === 'object') { + z2ui5.oBody.ARGUMENTS[i] = JSON.stringify(item); + } } + ); + z2ui5.oResponseOld = z2ui5.oResponse; + Server.Roundtrip(); +             }, - async responseSuccess(response) { - try{ - sap.z2ui5.oResponse = response; - if (sap.z2ui5.oResponse.PARAMS?.S_VIEW?.CHECK_DESTROY) { - sap.z2ui5.oController.ViewDestroy(); - }; - if(sap.z2ui5.oResponse.PARAMS?.S_FOLLOW_UP_ACTION?.CUSTOM_JS) { - setTimeout(() => { - let mParams = sap.z2ui5.oResponse?.PARAMS.S_FOLLOW_UP_ACTION.CUSTOM_JS.split("'"); - let mParamsEF = mParams.filter((val, index) => index % 2) - if(mParamsEF.length) { - sap.z2ui5.oController.eF.apply( undefined , mParamsEF); - } else { - Function("return " + mParams[0])(); - } - },100); - }; - sap.z2ui5.oController.showMessage('S_MSG_TOAST', sap.z2ui5.oResponse.PARAMS); - sap.z2ui5.oController.showMessage('S_MSG_BOX', sap.z2ui5.oResponse.PARAMS); - if (sap.z2ui5.oResponse.PARAMS?.S_VIEW?.XML) { if ( sap.z2ui5.oResponse.PARAMS?.S_VIEW?.XML !== '') { - sap.z2ui5.oController.ViewDestroy(); - await sap.z2ui5.oController.createView(sap.z2ui5.oResponse.PARAMS.S_VIEW.XML, sap.z2ui5.oResponse.OVIEWMODEL); - return; } } - this.updateModelIfRequired('S_VIEW', sap.z2ui5.oView); - this.updateModelIfRequired('S_VIEW_NEST', sap.z2ui5.oViewNest); - this.updateModelIfRequired('S_VIEW_NEST2', sap.z2ui5.oViewNest2); - this.updateModelIfRequired('S_POPUP', sap.z2ui5.oViewPopup); - this.updateModelIfRequired('S_POPOVER', sap.z2ui5.oViewPopover); - sap.z2ui5.oController.onAfterRendering(); - }catch(e){BusyIndicator.hide(); if(e.message.includes("openui5")) { if(e.message.includes("script load error")) { sap.z2ui5.oController.checkSDKcompatibility(e) } } else { - MessageBox.error(e.toLocaleString()); } } + updateModelIfRequired(paramKey, oView) { + if (z2ui5.oResponse.PARAMS == undefined) { + return; + } + if (z2ui5.oResponse.PARAMS[paramKey]?.CHECK_UPDATE_MODEL) { + let model = new JSONModel(z2ui5.oResponse.OVIEWMODEL); + if (oView) { + oView.setModel(model); + } + } }, - async checkSDKcompatibility(err) { - let oCurrentVersionInfo = await VersionInfo.load(); - var ui5_sdk = oCurrentVersionInfo.gav.includes('com.sap.ui5') ? true : false; - if(!ui5_sdk) { - if(err) { - MessageBox.error("openui5 SDK is loaded, module: " + err._modules + " is not availabe in openui5" ); - return; - }; - }; - MessageBox.error(err.toLocaleString()); + async checkSDKcompatibility(err) { + let oCurrentVersionInfo = await VersionInfo.load(); + var ui5_sdk = oCurrentVersionInfo.gav.includes('com.sap.ui5') ? true : false; + if (!ui5_sdk) { + if (err) { + MessageBox.error("openui5 SDK is loaded, module: " + err._modules + " is not availabe in openui5"); + return; + } + ; + } + ;MessageBox.error(err.toLocaleString()); }, showMessage(msgType, params) { - if (params == undefined) { return; } + if (params == undefined) { + return; + } if (params[msgType]?.TEXT !== undefined) { if (msgType === 'S_MSG_TOAST') { - MessageToast.show(params[msgType].TEXT,{duration: params[msgType].DURATION ? parseInt(params[msgType].DURATION) : 3000 , - width: params[msgType].WIDTH ? params[msgType].WIDTH : '15em' , - onClose: params[msgType].ONCLOSE ? params[msgType].ONCLOSE : null , - autoClose: params[msgType].AUTOCLOSE ? true : false , - animationTimingFunction: params[msgType].ANIMATIONTIMINGFUNCTION ? params[msgType].ANIMATIONTIMINGFUNCTION : 'ease' , - animationDuration: params[msgType].ANIMATIONDURATION ? parseInt(params[msgType].ANIMATIONDURATION) : 1000 , - closeonBrowserNavigation: params[msgType].CLOSEONBROWSERNAVIGATION ? true : false - }); - if(params[msgType].CLASS) { - let mtoast = {}; - mtoast = document.getElementsByClassName("sapMMessageToast")[0]; - if(mtoast) { mtoast.classList.add(params[msgType].CLASS); } - }; + MessageToast.show(params[msgType].TEXT, { + duration: params[msgType].DURATION ? parseInt(params[msgType].DURATION) : 3000, + width: params[msgType].WIDTH ? params[msgType].WIDTH : '15em', + onClose: params[msgType].ONCLOSE ? params[msgType].ONCLOSE : null, + autoClose: params[msgType].AUTOCLOSE ? true : false, + animationTimingFunction: params[msgType].ANIMATIONTIMINGFUNCTION ? params[msgType].ANIMATIONTIMINGFUNCTION : 'ease', + animationDuration: params[msgType].ANIMATIONDURATION ? parseInt(params[msgType].ANIMATIONDURATION) : 1000, + closeonBrowserNavigation: params[msgType].CLOSEONBROWSERNAVIGATION ? true : false + }); + if (params[msgType].CLASS) { + let mtoast = {}; + mtoast = document.getElementsByClassName("sapMMessageToast")[0]; + if (mtoast) { + mtoast.classList.add(params[msgType].CLASS); + } + } + ; } else if (msgType === 'S_MSG_BOX') { if (params[msgType].TYPE) { - MessageBox[params[msgType].TYPE](params[msgType].TEXT); + MessageBox[params[msgType].TYPE](params[msgType].TEXT); } else { - MessageBox.show(params[msgType].TEXT,{styleClass:params[msgType].STYLECLASS ? params[msgType].STYLECLASS : '', - title: params[msgType].TITLE ? params[msgType].TITLE : '', - onClose: params[msgType].ONCLOSE ? Function("sAction", "return " + params[msgType].ONCLOSE) : null, - actions: params[msgType].ACTIONS ? params[msgType].ACTIONS : 'OK', - emphasizedAction: params[msgType].EMPHASIZEDACTION ? params[msgType].EMPHASIZEDACTION : 'OK', - initialFocus: params[msgType].INITIALFOCUS ? params[msgType].INITIALFOCUS : null, - textDirection: params[msgType].TEXTDIRECTION ? params[msgType].TEXTDIRECTION : 'Inherit', - icon: params[msgType].ICON ? params[msgType].ICON : 'NONE' , - details: params[msgType].DETAILS ? params[msgType].DETAILS : '', - closeOnNavigation: params[msgType].CLOSEONNAVIGATION ? true : false - } - ) + MessageBox.show(params[msgType].TEXT, { + styleClass: params[msgType].STYLECLASS ? params[msgType].STYLECLASS : '', + title: params[msgType].TITLE ? params[msgType].TITLE : '', + onClose: params[msgType].ONCLOSE ? Function("sAction", "return " + params[msgType].ONCLOSE) : null, + actions: params[msgType].ACTIONS ? params[msgType].ACTIONS : 'OK', + emphasizedAction: params[msgType].EMPHASIZEDACTION ? params[msgType].EMPHASIZEDACTION : 'OK', + initialFocus: params[msgType].INITIALFOCUS ? params[msgType].INITIALFOCUS : null, + textDirection: params[msgType].TEXTDIRECTION ? params[msgType].TEXTDIRECTION : 'Inherit', + icon: params[msgType].ICON ? params[msgType].ICON : 'NONE', + details: params[msgType].DETAILS ? params[msgType].DETAILS : '', + closeOnNavigation: params[msgType].CLOSEONNAVIGATION ? true : false + }) } - } + } } }, - setApp(oApp){ + setApp(oApp) { this._oApp = oApp; }, - async createView(xml, viewModel) { - - let oview_modelTempl = new JSONModel(viewModel); - - sap.z2ui5.oView = await XMLView.create({ + async displayView(xml, viewModel) { + let oview_model = new JSONModel(viewModel); + z2ui5.oView = await XMLView.create({ definition: xml, - // models: oview_model, - controller: sap.z2ui5.oController, + models: oview_model, + controller: z2ui5.oController, id: 'mainView', - preprocessors: { xml: { models: { template: oview_modelTempl } } } - }); - // sap.z2ui5.oView.setModel(sap.z2ui5.oDeviceModel, "device"); - // if (sap.z2ui5.oParent) { - // sap.z2ui5.oParent.removeAllPages(); - // sap.z2ui5.oParent.insertPage(sap.z2ui5.oView); - // } else { - // this._oApp.byId("viewContainer").removeAllPages(); - this._oApp.byId("viewContainer").insertPage(sap.z2ui5.oView); - - let oview_model = new JSONModel(viewModel); - // oview_model.setSizeLimit(sap.z2ui5.JSON_MODEL_LIMIT); - sap.z2ui5.oView.setModel( oview_model ); - // sap.z2ui5.oModelTest = oview_model; - // this._oApp.byId("viewContainer").addItem(sap.z2ui5.oView); - // } - }, - async readHttp() { - - const response = await fetch(sap.z2ui5.pathname, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'sap-contextid-accept': 'header', - 'sap-contextid': sap.z2ui5.contextId - }, - body: JSON.stringify(sap.z2ui5.oBody) + preprocessors: { + xml: { + models: { + template: oview_model + } + } + } }); - sap.z2ui5.contextId = response.headers.get("sap-contextid"); - if (!response.ok) { - const responseText = await response.text(); - sap.z2ui5.oController.responseError(responseText); - } else { - const responseData = await response.json(); - sap.z2ui5.responseData = responseData; - sap.z2ui5.oController.responseSuccess({ - ID : responseData.S_FRONT.ID, - PARAMS : responseData.S_FRONT.PARAMS, - OVIEWMODEL : responseData.MODEL, - }); - } - }, - Roundtrip() { - sap.z2ui5.checkTimerActive = false; - sap.z2ui5.checkNestAfter = false; - sap.z2ui5.checkNestAfter2 = false; - let event = (args) => { if ( args != undefined ) { return args[0][0]; } }; - sap.z2ui5.oBody.S_FRONT = { - ID: sap.z2ui5?.oBody?.ID, - COMPDATA: (sap.z2ui5.ComponentData) ? sap.z2ui5.ComponentData : {} , - XX: sap.z2ui5?.oBody?.XX, - ORIGIN: window.location.origin, - PATHNAME: window.location.pathname, // sap.z2ui5.pathname, - SEARCH: (sap.z2ui5.search) ? sap.z2ui5.search : window.location.search, - VIEW: sap.z2ui5.oBody?.VIEWNAME, - T_STARTUP_PARAMETERS: sap.z2ui5.startupParameters, - EVENT: event(sap.z2ui5.oBody?.ARGUMENTS), - }; - if ( sap.z2ui5.oBody?.ARGUMENTS != undefined ) { if ( sap.z2ui5.oBody?.ARGUMENTS.length > 0 ) { sap.z2ui5.oBody?.ARGUMENTS.shift(); } } - sap.z2ui5.oBody.S_FRONT.T_EVENT_ARG = sap.z2ui5.oBody?.ARGUMENTS; - delete sap.z2ui5.oBody.ID; - delete sap.z2ui5.oBody?.VIEWNAME; - delete sap.z2ui5.oBody?.S_FRONT.XX; - delete sap.z2ui5.oBody?.ARGUMENTS; - if (!sap.z2ui5.oBody.S_FRONT.T_EVENT_ARG) { delete sap.z2ui5.oBody.S_FRONT.T_EVENT_ARG; } - if (sap.z2ui5.oBody.S_FRONT.T_EVENT_ARG) { if (sap.z2ui5.oBody.S_FRONT.T_EVENT_ARG.length == 0 ) { delete sap.z2ui5.oBody.S_FRONT.T_EVENT_ARG; } } - if (sap.z2ui5.oBody.S_FRONT.T_STARTUP_PARAMETERS == undefined) { delete sap.z2ui5.oBody.S_FRONT.T_STARTUP_PARAMETERS; } - if ( sap.z2ui5.oBody.S_FRONT.SEARCH == '' ){ delete sap.z2ui5.oBody.S_FRONT.SEARCH; } - if (!sap.z2ui5.oBody.XX){ delete sap.z2ui5.oBody.XX; } - sap.z2ui5.oController.readHttp(); + z2ui5.oView.setModel(z2ui5.oDeviceModel, "device"); + this._oApp.removeAllPages(); + this._oApp.insertPage(z2ui5.oView); }, }) -}); - - \ No newline at end of file +}); \ No newline at end of file diff --git a/src/02/zabap2ui5.wapa.css_-style.css b/src/02/z2ui5.wapa.css_-style.css similarity index 100% rename from src/02/zabap2ui5.wapa.css_-style.css rename to src/02/z2ui5.wapa.css_-style.css diff --git a/src/02/z2ui5.wapa.i18n_-i18n.properties b/src/02/z2ui5.wapa.i18n_-i18n.properties new file mode 100644 index 0000000..7cb9ff5 --- /dev/null +++ b/src/02/z2ui5.wapa.i18n_-i18n.properties @@ -0,0 +1,5 @@ +# This is the resource bundle for z2ui5 + +#XFLD,24 +flpTitle=abap2UI5 + \ No newline at end of file diff --git a/src/02/zabap2ui5.wapa.index.html b/src/02/z2ui5.wapa.index.html similarity index 95% rename from src/02/zabap2ui5.wapa.index.html rename to src/02/z2ui5.wapa.index.html index 0e362eb..2774d3b 100644 --- a/src/02/zabap2ui5.wapa.index.html +++ b/src/02/z2ui5.wapa.index.html @@ -4,7 +4,7 @@ - abap2UI5 + + + + + + + + + + + \ No newline at end of file diff --git a/src/02/z2ui5.wapa.test_-flpsandbox.js b/src/02/z2ui5.wapa.test_-flpsandbox.js new file mode 100644 index 0000000..5381662 --- /dev/null +++ b/src/02/z2ui5.wapa.test_-flpsandbox.js @@ -0,0 +1,100 @@ +sap.ui.define([ + "sap/base/util/ObjectPath", + "sap/ushell/services/Container" +], function (ObjectPath) { + "use strict"; + + // define ushell config + ObjectPath.set(["sap-ushell-config"], { + defaultRenderer: "fiori2", + bootstrapPlugins: { + "RuntimeAuthoringPlugin": { + component: "sap.ushell.plugins.rta", + config: { + validateAppVersion: false + } + }, + "PersonalizePlugin": { + component: "sap.ushell.plugins.rta-personalize", + config: { + validateAppVersion: false + } + } + }, + renderers: { + fiori2: { + componentData: { + config: { + enableSearch: false, + rootIntent: "Shell-home" + } + } + } + }, + services: { + "LaunchPage": { + "adapter": { + "config": { + "groups": [{ + "tiles": [{ + "tileType": "sap.ushell.ui.tile.StaticTile", + "properties": { + "title": "App Title", + "targetURL": "#z2ui5-display" + } + }] + }] + } + } + }, + "ClientSideTargetResolution": { + "adapter": { + "config": { + "inbounds": { + "z2ui5-display": { + "semanticObject": "z2ui5", + "action": "display", + "description": "An SAP Fiori application.", + "title": "App Title", + "signature": { + "parameters": {} + }, + "resolutionResult": { + "applicationType": "SAPUI5", + "additionalInformation": "SAPUI5.Component=z2ui5", + "url": sap.ui.require.toUrl("z2ui5") + } + } + } + } + } + }, + NavTargetResolution: { + config: { + "enableClientSideTargetResolution": true + } + } + } + }); + + var oFlpSandbox = { + init: function () { + /** + * Initializes the FLP sandbox + * @returns {Promise} a promise that is resolved when the sandbox bootstrap has finshed + */ + + // sandbox is a singleton, so we can start it only once + if (!this._oBootstrapFinished) { + this._oBootstrapFinished = sap.ushell.bootstrap("local"); + this._oBootstrapFinished.then(function () { + sap.ushell.Container.createRenderer().placeAt("content"); + }); + } + + return this._oBootstrapFinished; + } + }; + + return oFlpSandbox; +}); \ No newline at end of file diff --git a/src/02/z2ui5.wapa.test_-initflpsandbox.js b/src/02/z2ui5.wapa.test_-initflpsandbox.js new file mode 100644 index 0000000..fee2fc1 --- /dev/null +++ b/src/02/z2ui5.wapa.test_-initflpsandbox.js @@ -0,0 +1,13 @@ +sap.ui.define([ + "./flpSandbox", + "sap/ui/fl/FakeLrepConnectorLocalStorage", + "sap/m/MessageBox" +], function (flpSandbox, FakeLrepConnectorLocalStorage, MessageBox) { + "use strict"; + + flpSandbox.init().then(function () { + FakeLrepConnectorLocalStorage.enableFakeConnector(); + }, function (oError) { + MessageBox.error(oError.message); + }); +}); \ No newline at end of file diff --git a/src/02/z2ui5.wapa.test_-integration_-alljourneys.js b/src/02/z2ui5.wapa.test_-integration_-alljourneys.js new file mode 100644 index 0000000..2f948f1 --- /dev/null +++ b/src/02/z2ui5.wapa.test_-integration_-alljourneys.js @@ -0,0 +1,14 @@ +sap.ui.define([ + "sap/ui/test/Opa5", + "./arrangements/Startup", + "./NavigationJourney" +], function (Opa5, Startup) { + "use strict"; + + Opa5.extendConfig({ + arrangements: new Startup(), + viewNamespace: "z2ui5.view.", + autoWait: true + }); +}); + \ No newline at end of file diff --git a/src/02/z2ui5.wapa.test_-integration_-arrangements_-startup.js b/src/02/z2ui5.wapa.test_-integration_-arrangements_-startup.js new file mode 100644 index 0000000..6d303b0 --- /dev/null +++ b/src/02/z2ui5.wapa.test_-integration_-arrangements_-startup.js @@ -0,0 +1,26 @@ +sap.ui.define([ + "sap/ui/test/Opa5" +], function (Opa5) { + "use strict"; + + return Opa5.extend("integration.arrangements.Startup", { + + iStartMyApp: function (oOptionsParameter) { + var oOptions = oOptionsParameter || {}; + + // start the app with a minimal delay to make tests fast but still async to discover basic timing issues + oOptions.delay = oOptions.delay || 50; + + // start the app UI component + this.iStartMyUIComponent({ + componentConfig: { + name: "z2ui5", + async: true + }, + hash: oOptions.hash, + autoWait: oOptions.autoWait + }); + } + }); +}); + \ No newline at end of file diff --git a/src/02/zabap2ui5.wapa.model_-models.js b/src/02/z2ui5.wapa.test_-integration_-navigationjourney.js similarity index 73% rename from src/02/zabap2ui5.wapa.model_-models.js rename to src/02/z2ui5.wapa.test_-integration_-navigationjourney.js index 382e936..cae3d6f 100644 --- a/src/02/zabap2ui5.wapa.model_-models.js +++ b/src/02/z2ui5.wapa.test_-integration_-navigationjourney.js @@ -1,23 +1,24 @@ +/*global QUnit*/ + sap.ui.define([ - "sap/ui/model/json/JSONModel", - "sap/ui/Device" -],  - /** - * provide app-view type models (as in the first "V" in MVVC) - *  - * @param {typeof sap.ui.model.json.JSONModel} JSONModel - * @param {typeof sap.ui.Device} Device - *  - * @returns {Function} createDeviceModel() for providing runtime info for the device the UI5 app is running on - */ - function (JSONModel, Device) { - "use strict"; + "sap/ui/test/opaQunit", + "./pages/App", + "./pages/View1" +], function (opaTest) { + "use strict"; + + QUnit.module("Navigation Journey"); + + opaTest("Should see the initial page of the app", function (Given, When, Then) { + // Arrangements + Given.iStartMyApp(); + + // Assertions + Then.onTheAppPage.iShouldSeeTheApp(); + Then.onTheViewPage.iShouldSeeThePageView(); - return { - createDeviceModel: function () { - var oModel = new JSONModel(Device); - oModel.setDefaultBindingMode("OneWay"); - return oModel; - } - }; -}); \ No newline at end of file + //Cleanup + Then.iTeardownMyApp(); + }); +}); + \ No newline at end of file diff --git a/src/02/z2ui5.wapa.test_-integration_-opatests.qunit.html b/src/02/z2ui5.wapa.test_-integration_-opatests.qunit.html new file mode 100644 index 0000000..ebe61eb --- /dev/null +++ b/src/02/z2ui5.wapa.test_-integration_-opatests.qunit.html @@ -0,0 +1,30 @@ + + + + + Integration tests for Basic Template + + + + + + + +
+
+ + + \ No newline at end of file diff --git a/src/02/zabap2ui5.wapa.view_-app.view.xml b/src/02/z2ui5.wapa.test_-integration_-opatests.qunit.js similarity index 71% rename from src/02/zabap2ui5.wapa.view_-app.view.xml rename to src/02/z2ui5.wapa.test_-integration_-opatests.qunit.js index e46ad31..7771669 100644 --- a/src/02/zabap2ui5.wapa.view_-app.view.xml +++ b/src/02/z2ui5.wapa.test_-integration_-opatests.qunit.js @@ -1,7 +1,8 @@ - - - +/* global QUnit */ +sap.ui.require(["z2ui5/test/integration/AllJourneys" +], function () { + QUnit.config.autostart = false; + QUnit.start(); +}); \ No newline at end of file diff --git a/src/02/zabap2ui5.wapa.controller_-app.controller.js b/src/02/z2ui5.wapa.test_-integration_-pages_-app.js similarity index 62% rename from src/02/zabap2ui5.wapa.controller_-app.controller.js rename to src/02/z2ui5.wapa.test_-integration_-pages_-app.js index 1f5cdf0..b349561 100644 --- a/src/02/zabap2ui5.wapa.controller_-app.controller.js +++ b/src/02/z2ui5.wapa.test_-integration_-pages_-app.js @@ -1,37 +1,29 @@ sap.ui.define([ - "sap/ui/core/mvc/Controller", - "sap/ui/core/BusyIndicator", - "z2ui5/controller/View1.controller" - ], function(BaseController, BusyIndicator, Controller){ - return BaseController.extend("z2ui5.controller.App", { - onInit: async function(){ + "sap/ui/test/Opa5" +], function (Opa5) { + "use strict"; + var sViewName = "App"; + + Opa5.createPageObjects({ + onTheAppPage: { - BusyIndicator.show(); + actions: {}, - try { - sap.z2ui5.oLaunchpadService = await this.getOwnerComponent().getService("ShellUIService"); + assertions: { - } catch (e) {} - try { - sap.z2ui5.ComponentData = this.getOwnerComponent().getComponentData(); - sap.z2ui5.startupParameters = this.getOwnerComponent().getComponentData().startupParameters; - } catch (e) {} + iShouldSeeTheApp: function () { + return this.waitFor({ + id: "app", + viewName: sViewName, + success: function () { + Opa5.assert.ok(true, "The " + sViewName + " view is displayed"); + }, + errorMessage: "Did not find the " + sViewName + " view" + }); + } + } + } + }); - sap.z2ui5.oController = new Controller(); - sap.z2ui5.oControllerNest = new Controller(); - sap.z2ui5.oControllerNest2 = new Controller(); - sap.z2ui5.oControllerPopup = new Controller(); - sap.z2ui5.oControllerPopover = new Controller(); - sap.z2ui5.checkNestAfter = false; - sap.z2ui5.oBody = { }; - sap.z2ui5.oController.setApp(this.getView()); - sap.z2ui5.oController.Roundtrip(); - sap.z2ui5.onBeforeRoundtrip = []; - sap.z2ui5.onAfterRendering = []; - sap.z2ui5.onBeforeEventFrontend = []; - sap.z2ui5.onAfterRoundtrip = []; - - - } - }); - }); \ No newline at end of file +}); + \ No newline at end of file diff --git a/src/02/z2ui5.wapa.test_-integration_-pages_-view1.js b/src/02/z2ui5.wapa.test_-integration_-pages_-view1.js new file mode 100644 index 0000000..87edfa2 --- /dev/null +++ b/src/02/z2ui5.wapa.test_-integration_-pages_-view1.js @@ -0,0 +1,29 @@ +sap.ui.define([ + "sap/ui/test/Opa5" +], function (Opa5) { + "use strict"; + var sViewName = "View1"; + + Opa5.createPageObjects({ + onTheViewPage: { + + actions: {}, + + assertions: { + + iShouldSeeThePageView: function () { + return this.waitFor({ + id: "page", + viewName: sViewName, + success: function () { + Opa5.assert.ok(true, "The " + sViewName + " view is displayed"); + }, + errorMessage: "Did not find the " + sViewName + " view" + }); + } + } + } + }); + +}); + \ No newline at end of file diff --git a/src/02/zabap2ui5.wapa.i18n_-i18n.properties b/src/02/z2ui5.wapa.test_-testsuite.qunit.html similarity index 70% rename from src/02/zabap2ui5.wapa.i18n_-i18n.properties rename to src/02/z2ui5.wapa.test_-testsuite.qunit.html index f945779..decf769 100644 --- a/src/02/zabap2ui5.wapa.i18n_-i18n.properties +++ b/src/02/z2ui5.wapa.test_-testsuite.qunit.html @@ -1,11 +1,12 @@ -# This is the resource bundle for z2ui5 - -#Texts for manifest.json - -#XTIT: Application name -appTitle=abap2UI5 - -#YDES: Application description -appDescription=abap2UI5 -#XTIT: Main view title -title=abap2UI5 \ No newline at end of file + + + + + QUnit test suite for z2ui5 + + + + + + + \ No newline at end of file diff --git a/src/02/z2ui5.wapa.test_-testsuite.qunit.js b/src/02/z2ui5.wapa.test_-testsuite.qunit.js new file mode 100644 index 0000000..ad37cde --- /dev/null +++ b/src/02/z2ui5.wapa.test_-testsuite.qunit.js @@ -0,0 +1,15 @@ +/* global window, parent, location */ + +// eslint-disable-next-line fiori-custom/sap-no-global-define +window.suite = function() { + "use strict"; + + // eslint-disable-next-line + var oSuite = new parent.jsUnitTestSuite(), + sContextPath = location.pathname.substring(0, location.pathname.lastIndexOf("/") + 1); + + oSuite.addTestPage(sContextPath + "unit/unitTests.qunit.html"); + oSuite.addTestPage(sContextPath + "integration/opaTests.qunit.html"); + + return oSuite; +}; \ No newline at end of file diff --git a/src/02/z2ui5.wapa.test_-unit_-alltests.js b/src/02/z2ui5.wapa.test_-unit_-alltests.js new file mode 100644 index 0000000..18bdeee --- /dev/null +++ b/src/02/z2ui5.wapa.test_-unit_-alltests.js @@ -0,0 +1,6 @@ +sap.ui.define([ + "z2ui5/test/unit/controller/View1.controller" +], function () { + "use strict"; +}); + \ No newline at end of file diff --git a/src/02/z2ui5.wapa.test_-unit_-controller_-view1.controller.js b/src/02/z2ui5.wapa.test_-unit_-controller_-view1.controller.js new file mode 100644 index 0000000..9772319 --- /dev/null +++ b/src/02/z2ui5.wapa.test_-unit_-controller_-view1.controller.js @@ -0,0 +1,17 @@ +/*global QUnit*/ + +sap.ui.define([ + "z2ui5/controller/View1.controller" +], function (Controller) { + "use strict"; + + QUnit.module("View1 Controller"); + + QUnit.test("I should test the View1 controller", function (assert) { + var oAppController = new Controller(); + oAppController.onInit(); + assert.ok(oAppController); + }); + +}); + \ No newline at end of file diff --git a/src/02/z2ui5.wapa.test_-unit_-unittests.qunit.html b/src/02/z2ui5.wapa.test_-unit_-unittests.qunit.html new file mode 100644 index 0000000..52b7ced --- /dev/null +++ b/src/02/z2ui5.wapa.test_-unit_-unittests.qunit.html @@ -0,0 +1,28 @@ + + + + + Unit tests for z2ui5 + + + + + + + + + +
+
+ + + \ No newline at end of file diff --git a/src/02/z2ui5.wapa.test_-unit_-unittests.qunit.js b/src/02/z2ui5.wapa.test_-unit_-unittests.qunit.js new file mode 100644 index 0000000..3014cdb --- /dev/null +++ b/src/02/z2ui5.wapa.test_-unit_-unittests.qunit.js @@ -0,0 +1,13 @@ +/* global QUnit */ +QUnit.config.autostart = false; + +sap.ui.getCore().attachInit(function () { + "use strict"; + + sap.ui.require([ + "z2ui5/test/unit/AllTests" + ], function () { + QUnit.start(); + }); +}); + \ No newline at end of file diff --git a/src/02/zabap2ui5.wapa.ui556bc4a63f9bb8a077adc9edf2158a3eda5b15cef b/src/02/z2ui5.wapa.ui556bc4a63f9bb8a077adc9edf2158a3eda5b15cef similarity index 80% rename from src/02/zabap2ui5.wapa.ui556bc4a63f9bb8a077adc9edf2158a3eda5b15cef rename to src/02/z2ui5.wapa.ui556bc4a63f9bb8a077adc9edf2158a3eda5b15cef index 4c3051a..8a8f157 100644 --- a/src/02/zabap2ui5.wapa.ui556bc4a63f9bb8a077adc9edf2158a3eda5b15cef +++ b/src/02/z2ui5.wapa.ui556bc4a63f9bb8a077adc9edf2158a3eda5b15cef @@ -41,6 +41,23 @@ }); return libOrCompKeysStringTmp; } + function getComponentUsageNames(compUsages, libOrCompKeysString) { + var libOrCompKeysStringTmp = libOrCompKeysString; + var compNames = Object.keys(compUsages).map(function (compUsageKey) { + return compUsages[compUsageKey].name; + }); + compNames.forEach(function (compName) { + // ignore libs or Components that start with SAPUI5 delivered namespaces + if (!ui5Libs.some(function (substring) { return compName === substring || compName.startsWith(substring + "."); })) { + if (libOrCompKeysStringTmp.length > 0) { + libOrCompKeysStringTmp = libOrCompKeysStringTmp + "," + compName; + } else { + libOrCompKeysStringTmp = compName; + } + } + }); + return libOrCompKeysStringTmp; + } return new Promise(function (resolve, reject) { $.ajax(url) .done(function (manifest) { @@ -60,7 +77,7 @@ manifest["sap.ui5"] && manifest["sap.ui5"].componentUsages ) { - result = getKeys(manifest["sap.ui5"].componentUsages, result); + result = getComponentUsageNames(manifest["sap.ui5"].componentUsages, result); } } resolve(result); @@ -131,6 +148,25 @@ }; })(sap); +function registerSAPFonts() {   + sap.ui.require(["sap/ui/core/IconPool"], function (IconPool) {   + //Fiori Theme font family and URI + var fioriTheme = { + fontFamily: "SAP-icons-TNT", + fontURI: sap.ui.require.toUrl("sap/tnt/themes/base/fonts/") + }; + //Registering to the icon pool + IconPool.registerFont(fioriTheme); + //SAP Business Suite Theme font family and URI + var bSuiteTheme = { + fontFamily: "BusinessSuiteInAppSymbols", + fontURI: sap.ui.require.toUrl("sap/ushell/themes/base/fonts/") + }; + //Registering to the icon pool + IconPool.registerFont(bSuiteTheme); + }); +} + /*eslint-disable fiori-custom/sap-browser-api-warning, fiori-custom/sap-no-dom-access*/ var currentScript = document.getElementById("locate-reuse-libs"); if (!currentScript) { @@ -163,6 +199,7 @@ sap.registerComponentDependencyPaths(manifestUri) if (componentName && componentName.length > 0) { if (useMockserver && useMockserver === "true") { sap.ui.getCore().attachInit(function () { + registerSAPFonts(); sap.ui.require([componentName.replace(/\./g, "/") + "/localService/mockserver"], function (server) { // set up test service for local testing server.init(); @@ -176,6 +213,7 @@ sap.registerComponentDependencyPaths(manifestUri) // setting the app title with the i18n text  sap.ui.getCore().attachInit(function () { + registerSAPFonts(); var sLocale = sap.ui.getCore().getConfiguration().getLanguage(); sap.ui.require(["sap/base/i18n/ResourceBundle"], function (ResourceBundle) { var oResourceBundle = ResourceBundle.create({ @@ -188,8 +226,16 @@ sap.registerComponentDependencyPaths(manifestUri) } } else { sap.ui.getCore().attachInit(function () { - // initialize the ushell sandbox component - sap.ushell.Container.createRenderer().placeAt("content"); + registerSAPFonts(); + try { + // initialize the ushell sandbox component in ui5 v2 + sap.ushell.Container.createRenderer(true).then(function (component) { + component.placeAt("content"); + }); + } catch { + // support older versions of ui5  + sap.ushell.Container.createRenderer().placeAt("content"); + } }); } }); \ No newline at end of file diff --git a/src/02/zabap2ui5.wapa.ui5repositorypathmapping.xml b/src/02/z2ui5.wapa.ui5repositorypathmapping.xml similarity index 95% rename from src/02/zabap2ui5.wapa.ui5repositorypathmapping.xml rename to src/02/z2ui5.wapa.ui5repositorypathmapping.xml index f86ee78..3afec90 100644 --- a/src/02/zabap2ui5.wapa.ui5repositorypathmapping.xml +++ b/src/02/z2ui5.wapa.ui5repositorypathmapping.xml @@ -9,6 +9,30 @@ internal_rep = "B" internal_rep_path = "Component.js" /> + + + + + + + + - - - - + + + + \ No newline at end of file diff --git a/src/02/zabap2ui5.wapa.view_-view1.view.xml b/src/02/z2ui5.wapa.view_-view1.view.xml similarity index 100% rename from src/02/zabap2ui5.wapa.view_-view1.view.xml rename to src/02/z2ui5.wapa.view_-view1.view.xml diff --git a/src/02/z2ui5.wapa.xml b/src/02/z2ui5.wapa.xml new file mode 100644 index 0000000..fee500b --- /dev/null +++ b/src/02/z2ui5.wapa.xml @@ -0,0 +1,360 @@ + + + + + + Z2UI5 + /UI5/CL_UI5_BSP_APPLICATION + Z2UI5 + X + E + E + abap2UI5 + + + + + Z2UI5 + CC/DEBUGTOOL.FRAGMENT.XML + cc/DebugTool.fragment.xml + X + E + A + E + + + + + Z2UI5 + CC/DEBUGTOOL.JS + cc/DebugTool.js + X + E + A + E + + + + + Z2UI5 + CC/SERVER.JS + cc/Server.js + X + E + A + E + + + + + Z2UI5 + COMPONENT.JS + Component.js + X + E + A + E + + + + + Z2UI5 + CONTROLLER/APP.CONTROLLER.JS + controller/App.controller.js + X + E + A + E + + + + + Z2UI5 + CONTROLLER/VIEW1.CONTROLLER.JS + controller/View1.controller.js + X + E + A + E + + + + + Z2UI5 + CSS/STYLE.CSS + css/style.css + X + E + A + E + + + + + Z2UI5 + I18N/I18N.PROPERTIES + i18n/i18n.properties + X + E + A + E + + + + + Z2UI5 + INDEX.HTML + index.html + text/html + X + E + A + E + + + + + Z2UI5 + MANIFEST.JSON + manifest.json + X + E + A + E + + + + + Z2UI5 + MODEL/MODELS.JS + model/models.js + X + E + A + E + + + + + Z2UI5 + TEST/FLPSANDBOX.HTML + test/flpSandbox.html + X + E + A + E + + + + + Z2UI5 + TEST/FLPSANDBOX.JS + test/flpSandbox.js + X + E + A + E + + + + + Z2UI5 + TEST/INITFLPSANDBOX.JS + test/initFlpSandbox.js + X + E + A + E + + + + + Z2UI5 + TEST/INTEGRATION/ALLJOURNEYS.JS + test/integration/AllJourneys.js + X + E + A + E + + + + + Z2UI5 + TEST/INTEGRATION/ARRANGEMENTS/STARTUP.JS + test/integration/arrangements/Startup.js + X + E + A + E + + + + + Z2UI5 + TEST/INTEGRATION/NAVIGATIONJOURNEY.JS + test/integration/NavigationJourney.js + X + E + A + E + + + + + Z2UI5 + TEST/INTEGRATION/OPATESTS.QUNIT.HTML + test/integration/opaTests.qunit.html + X + E + A + E + + + + + Z2UI5 + TEST/INTEGRATION/OPATESTS.QUNIT.JS + test/integration/opaTests.qunit.js + X + E + A + E + + + + + Z2UI5 + TEST/INTEGRATION/PAGES/APP.JS + test/integration/pages/App.js + X + E + A + E + + + + + Z2UI5 + TEST/INTEGRATION/PAGES/VIEW1.JS + test/integration/pages/View1.js + X + E + A + E + + + + + Z2UI5 + TEST/TESTSUITE.QUNIT.HTML + test/testsuite.qunit.html + X + E + A + E + + + + + Z2UI5 + TEST/TESTSUITE.QUNIT.JS + test/testsuite.qunit.js + X + E + A + E + + + + + Z2UI5 + TEST/UNIT/ALLTESTS.JS + test/unit/AllTests.js + X + E + A + E + + + + + Z2UI5 + TEST/UNIT/CONTROLLER/VIEW1.CONTROLLER.JS + test/unit/controller/View1.controller.js + X + E + A + E + + + + + Z2UI5 + TEST/UNIT/UNITTESTS.QUNIT.HTML + test/unit/unitTests.qunit.html + X + E + A + E + + + + + Z2UI5 + TEST/UNIT/UNITTESTS.QUNIT.JS + test/unit/unitTests.qunit.js + X + E + A + E + + + + + Z2UI5 + UI556BC4A63F9BB8A077ADC9EDF2158A3EDA5B15CEF + UI556BC4A63F9BB8A077ADC9EDF2158A3EDA5B15CEF + X + E + A + E + + + + + Z2UI5 + UI5REPOSITORYPATHMAPPING.XML + UI5RepositoryPathMapping.xml + X + E + A + E + + + + + Z2UI5 + VIEW/APP.VIEW.XML + view/App.view.xml + X + E + A + E + + + + + Z2UI5 + VIEW/VIEW1.VIEW.XML + view/View1.view.xml + X + E + A + E + + + + + + diff --git a/src/02/zabap2ui5.wapa.xml b/src/02/zabap2ui5.wapa.xml deleted file mode 100644 index 8fffc31..0000000 --- a/src/02/zabap2ui5.wapa.xml +++ /dev/null @@ -1,162 +0,0 @@ - - - - - - ZABAP2UI5 - /UI5/CL_UI5_BSP_APPLICATION - ZABAP2UI5 - X - E - E - abap2UI5 - - - - - ZABAP2UI5 - COMPONENT.JS - Component.js - X - E - A - E - - - - - ZABAP2UI5 - CONTROLLER/APP.CONTROLLER.JS - controller/App.controller.js - X - E - A - E - - - - - ZABAP2UI5 - CONTROLLER/VIEW1.CONTROLLER.JS - controller/View1.controller.js - X - E - A - E - - - - - ZABAP2UI5 - CSS/STYLE.CSS - css/style.css - X - E - A - E - - - - - ZABAP2UI5 - I18N/I18N.PROPERTIES - i18n/i18n.properties - X - E - A - E - - - - - ZABAP2UI5 - INDEX.HTML - index.html - text/html - X - E - A - E - - - - - ZABAP2UI5 - LOCALSERVICE/METADATA.XML - localService/metadata.xml - X - E - A - E - - - - - ZABAP2UI5 - MANIFEST.JSON - manifest.json - X - E - A - E - - - - - ZABAP2UI5 - MODEL/MODELS.JS - model/models.js - X - E - A - E - - - - - ZABAP2UI5 - UI556BC4A63F9BB8A077ADC9EDF2158A3EDA5B15CEF - UI556BC4A63F9BB8A077ADC9EDF2158A3EDA5B15CEF - X - E - A - E - - - - - ZABAP2UI5 - UI5REPOSITORYPATHMAPPING.XML - UI5RepositoryPathMapping.xml - X - E - A - E - - - - - ZABAP2UI5 - VIEW/APP.VIEW.XML - view/App.view.xml - X - E - A - E - - - - - ZABAP2UI5 - VIEW/VIEW1.VIEW.XML - view/View1.view.xml - X - E - A - E - - - - - -