-
Notifications
You must be signed in to change notification settings - Fork 0
/
Component.js
98 lines (76 loc) · 2.83 KB
/
Component.js
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
jQuery.sap.declare("com.bf.newtrial.Component");
sap.ui.core.UIComponent.extend("com.bf.newtrial.Component", {
metadata: {
name: "NTK New Trial",
version: "1.0",
dependencies: {
libs: ["sap.m"]
},
config: {
serviceConfig: {
baseURL: "http://gblonsup01:8080",
appName: "com.bf.sflight"
}
}
},
init : function() {
sap.ui.core.UIComponent.prototype.init.apply(this, arguments);
// set device model for responsiveness
var deviceModel = new sap.ui.model.json.JSONModel({
isPhone : jQuery.device.is.phone,
isNotPhone : !jQuery.device.is.phone,
listMode : (jQuery.device.is.phone) ? "None" : "SingleSelectMaster",
listItemType : (jQuery.device.is.phone) ? "Active" : "Inactive"
});
deviceModel.setDefaultBindingMode("OneWay");
this.setModel(deviceModel, "device");
},
createRootView: function(sAPPCID) {
var mServiceConfig = this.getMetadata().getConfig().serviceConfig;
var oView = sap.ui.view({
viewName: "com.bf.newtrial.view.Root",
type: sap.ui.core.mvc.ViewType.XML,
viewData: { component: this }
});
// Create the OData model and set against the view
var oModel = new sap.ui.model.odata.ODataModel(
mServiceConfig.baseURL + "/" + mServiceConfig.appName,
true,
"Test",
"Test",
{
'X-SUP-APPCID': sAPPCID
}
);
oView.setModel(oModel);
return oView;
},
createContent: function() {
var mServiceConfig = this.getMetadata().getConfig().serviceConfig;
// First check in local storage
var sAPPCID = localStorage.APPCID;
if (!sAPPCID) {
var oSMPModel = new sap.ui.model.odata.ODataModel(
mServiceConfig.baseURL + "/odata/applications/latest/" + mServiceConfig.appName,
true
);
oSMPModel.create('/Connections', { DeviceType: "Android" }, null,
// Success
jQuery.proxy(function(mResult) {
// Store the APPCID locally
localStorage.APPCID = mResult.ApplicationConnectionId;
// Start the application with the root view
return this.getRootView(sAPPCID);
}, this),
// Error
jQuery.proxy(function(oError) {
jQuery.sap.log.error("Connection creation failed");
jQuery.sap.require("sap.m.MessageBox");
sap.m.MessageBox.alert("OH NOES!");
}, this)
);
} else {
return this.createRootView(sAPPCID);
}
}
});