-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComponent.js
More file actions
129 lines (111 loc) · 3.34 KB
/
Component.js
File metadata and controls
129 lines (111 loc) · 3.34 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
jQuery.sap.declare("ns1.Component");
jQuery.sap.require("ns1.MyRouter");
sap.ui.core.UIComponent.extend("ns1.Component", {
metadata: {
name: "atestgithub",
version: "1.0",
includes: [],
dependencies: {
libs: ["sap.m", "sap.ui.layout"],
components: []
},
rootView: "ns1.view.App",
config: {
resourceBundle: "i18n/messageBundle.properties",
serviceConfig: {
name: "ZME_OVERDUE_ITEMS_SRV_01",
serviceUrl: "/sap/opu/odata/sap/ZME_OVERDUE_ITEMS_SRV_01/"
}
},
routing: {
config: {
routerClass: ns1.MyRouter,
viewType: "XML",
viewPath: "ns1.view",
targetAggregation: "detailPages",
clearTarget: false
},
routes: [{
pattern: "",
name: "main",
view: "Master",
targetAggregation: "masterPages",
targetControl: "idAppControl",
subroutes: [{
pattern: "{entity}/:tab:",
name: "detail",
view: "Detail"
}]
}, {
name: "catchallMaster",
view: "Master",
targetAggregation: "masterPages",
targetControl: "idAppControl",
subroutes: [{
pattern: ":all*:",
name: "catchallDetail",
view: "NotFound",
transition: "show"
}]
}]
}
},
init: function() {
sap.ui.core.UIComponent.prototype.init.apply(this, arguments);
var mConfig = this.getMetadata().getConfig();
// Always use absolute paths relative to our own component
// (relative paths will fail if running in the Fiori Launchpad)
var oRootPath = jQuery.sap.getModulePath("ns1");
// Set i18n model
var i18nModel = new sap.ui.model.resource.ResourceModel({
bundleUrl: [oRootPath, mConfig.resourceBundle].join("/")
});
this.setModel(i18nModel, "i18n");
var sServiceUrl = mConfig.serviceConfig.serviceUrl;
//This code is only needed for testing the application when there is no local proxy available
var bIsMocked = jQuery.sap.getUriParameters().get("responderOn") === "true";
// Start the mock server for the domain model
if (bIsMocked) {
this._startMockServer(sServiceUrl);
}
// Create and set domain model to the component
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, {
json: true,
loadMetadataAsync: true
});
oModel.attachMetadataFailed(function() {
this.getEventBus().publish("Component", "MetadataFailed");
}, this);
this.setModel(oModel);
// Set device model
var oDeviceModel = new sap.ui.model.json.JSONModel({
isTouch: sap.ui.Device.support.touch,
isNoTouch: !sap.ui.Device.support.touch,
isPhone: sap.ui.Device.system.phone,
isNoPhone: !sap.ui.Device.system.phone,
listMode: sap.ui.Device.system.phone ? "None" : "SingleSelectMaster",
listItemType: sap.ui.Device.system.phone ? "Active" : "Inactive"
});
oDeviceModel.setDefaultBindingMode("OneWay");
this.setModel(oDeviceModel, "device");
this.getRouter().initialize();
},
_startMockServer: function(sServiceUrl) {
jQuery.sap.require("sap.ui.core.util.MockServer");
var oMockServer = new sap.ui.core.util.MockServer({
rootUri: sServiceUrl
});
var iDelay = +(jQuery.sap.getUriParameters().get("responderDelay") || 0);
sap.ui.core.util.MockServer.config({
autoRespondAfter: iDelay
});
oMockServer.simulate("model/metadata.xml", "model/");
oMockServer.start();
sap.m.MessageToast.show("Running in demo mode with mock data.", {
duration: 4000
});
},
getEventBus: function() {
return sap.ui.getCore().getEventBus();
}
});