Skip to content

Commit fdfb96e

Browse files
1 parent c2a0868 commit fdfb96e

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

app/webapp/controller/App.controller.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,27 +1189,27 @@ sap.ui.define("z2ui5/Dirty", ["sap/ui/core/Control"], (Control) => {
11891189
}
11901190
},
11911191
setIsDirty(val) {
1192-
1193-
sap.ui.require([ "sap/ushell/Container" ], async (Container) => {
11941192

1195-
if (Container) {
1196-
Container.setDirtyFlag(val);
1197-
} else {
1198-
window.onbeforeunload = function (e) {
1199-
if (val) {
1200-
e.preventDefault();
1201-
}
1202-
}
1203-
}
1204-
1205-
}, () => {
1206-
// Fallback if ushell is not available (OpenUI5)
1193+
const fallback = () => {
12071194
window.onbeforeunload = function (e) {
12081195
if (val) {
12091196
e.preventDefault();
12101197
}
12111198
}
1212-
});
1199+
}
1200+
1201+
// Container can be loaded (only available in SAPUI5, not in OpenUI5) and we are in Fiori Launchpad?
1202+
// Yes: We can use the containers ability to prevent data loss
1203+
// No: We fallback to window.onbeforeunload event
1204+
sap.ui.require([ "sap/ushell/Container" ], async (Container) => {
1205+
1206+
if (Container && z2ui5.oLaunchpadService) {
1207+
Container.setDirtyFlag(val);
1208+
} else {
1209+
fallback();
1210+
}
1211+
1212+
}, fallback);
12131213

12141214
},
12151215
renderer(oRm, oControl) { }

0 commit comments

Comments
 (0)