-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathBaseController.js
More file actions
61 lines (52 loc) · 1.95 KB
/
BaseController.js
File metadata and controls
61 lines (52 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/core/UIComponent",
"sap/ui/core/Fragment",
"sap/ui/core/routing/History"
], function (Controller, UIComponent, Fragment, History) {
"use strict";
return Controller.extend("ui5.challenge.controller.BaseController", {
navTo: function (psTarget, pmParameters, pbReplace) {
this.getRouter().navTo(psTarget, pmParameters, pbReplace);
},
getRouter: function () {
return UIComponent.getRouterFor(this);
},
onNavBack: function () {
var oHistory = History.getInstance();
var sPreviousHash = oHistory.getPreviousHash();
if (sPreviousHash !== undefined) {
window.history.go(-1);
} else {
var oRouter = this.getOwnerComponent().getRouter();
oRouter.navTo("overview", {}, true);
}
},
onPress: function () {
},
loadFragment: function (sFragmentName, oController, sId) {
if (!this._aFragments) {
this._aFragments = {};
}
return new Promise(function(resolve, reject) {
if (!this._aFragments[sFragmentName]) {
var sName = this.getOwnerComponent().getMetadata().getComponentName() + ".fragment." + sFragmentName;
Fragment.load({
id: sId,
name: sName,
controller: oController
}).then(function(oFragment) {
this._aFragments[sFragmentName] = oFragment;
this.getView().addDependent(oFragment);
resolve(this._aFragments[sFragmentName]);
}.bind(this));
}else {
resolve(this._aFragments[sFragmentName]);
}
}.bind(this));
},
getFragment: function (sFragmentName) {
return this._aFragments[sFragmentName];
}
});
});