diff --git a/client-side-js/dragAndDrop.js b/client-side-js/dragAndDrop.js new file mode 100644 index 00000000..9c8da48e --- /dev/null +++ b/client-side-js/dragAndDrop.js @@ -0,0 +1,18 @@ +async function clientSide_dragAndDrop(sourceWebElem, destWebElem) { + return await browser.executeAsync( + (sourceWebElem, destWebElem, done) => { + window.bridge.waitForUI5(window.wdi5.waitForUI5Options).then(() => { + const oSourceControl = window.wdi5.getUI5CtlForWebObj(sourceWebElem) + const oDestControl = window.wdi5.getUI5CtlForWebObj(destWebElem) + window.wdi5.simulateDragDrop(oSourceControl, oDestControl) + }) + done(["success"]) + }, + sourceWebElem, + destWebElem + ) +} + +module.exports = { + clientSide_dragAndDrop +} diff --git a/client-side-js/injectUI5.js b/client-side-js/injectUI5.js index 1c9e6d5a..7492c765 100644 --- a/client-side-js/injectUI5.js +++ b/client-side-js/injectUI5.js @@ -354,6 +354,14 @@ async function clientSide_injectUI5(config, waitForUI5Timeout, browserInstance) } } + window.wdi5.simulateDragDrop = (oSourceControl, oDestinationControl, sAggregationName = "items") => { + const oDrag = new Drag() + oDrag.executeOn(oSourceControl) + const oDrop = new Drop({ + aggregationName: sAggregationName + }) + oDrop.executeOn(oDestinationControl) + } window.wdi5.errorHandling = (done, error) => { window.wdi5.Log.error("[browser wdi5] ERR: ", error) done({ status: 1, message: error.toString() }) diff --git a/examples/ui5-js-app/webapp/controller/Other.controller.js b/examples/ui5-js-app/webapp/controller/Other.controller.js index 1726af5f..b015ec9c 100644 --- a/examples/ui5-js-app/webapp/controller/Other.controller.js +++ b/examples/ui5-js-app/webapp/controller/Other.controller.js @@ -1,27 +1,37 @@ sap.ui.define( - ['test/Sample/controller/BaseController', 'sap/m/MessageToast', 'sap/m/StandardListItem'], + ["test/Sample/controller/BaseController", "sap/m/MessageToast", "sap/m/StandardListItem"], function (Controller, MessageToast, StandardListItem) { - 'use strict'; + "use strict" - return Controller.extend('test.Sample.controller.Other', { + return Controller.extend("test.Sample.controller.Other", { onInit: function () {}, onItemPress(oEvent) { - this.getView().byId('idTextFieldClickResult').setText(oEvent.getParameter('listItem').data('key')); + this.getView().byId("idTextFieldClickResult").setText(oEvent.getParameter("listItem").data("key")) - MessageToast.show(oEvent.getParameter('listItem').data('key')); + MessageToast.show(oEvent.getParameter("listItem").data("key")) + }, + + onDragDrop: function (oEvent) { + const oDraggedItem = oEvent.getParameter("draggedControl") + const oDroppedItem = oEvent.getParameter("droppedControl") + const oPeopleList = this.getView().byId("PeopleList") + const iDroppedItemIndex = oPeopleList.indexOfItem(oDroppedItem) + + list.removeItem(oDraggedItem) + list.insertItem(oDraggedItem, iDroppedItemIndex) }, onAddLineItem(oEvent) { this.getView() - .byId('PeopleList') + .byId("PeopleList") .addItem( new StandardListItem({ - title: 'FirstName LastName', - type: 'Navigation' + title: "FirstName LastName", + type: "Navigation" }) - ); + ) } - }); + }) } -); +) diff --git a/examples/ui5-js-app/webapp/index.html b/examples/ui5-js-app/webapp/index.html index 673c6dcc..76830ad8 100644 --- a/examples/ui5-js-app/webapp/index.html +++ b/examples/ui5-js-app/webapp/index.html @@ -1,24 +1,29 @@ +
+ + +