-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.html
More file actions
192 lines (162 loc) · 6.59 KB
/
hello.html
File metadata and controls
192 lines (162 loc) · 6.59 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Pulsar365 JS Hello World</title>
<script type="text/javascript">
/* *******************************************************************
* The Pulsar365 Javascript Bridge object
* - See window.onload below for how this is initialized
*
* bridge.sendRequest(requestData, // request data (see wiki and example for usage)
* responseCallbackFn // async callback function to receive response data
* )
*
* bridge.addHandler(handlerName, // notification name (see wiki and examples for usage)
* handlerCallbackFn // async callback function to handle notification data
* )
*
* bridge.removeHandler(handlerName) // remove notification handler
* *******************************************************************/
var bridge = undefined;
var docNode = 'window.document';
var platform = 'unknown';
var refObjectId = undefined;
/*
* Helper function to extract URL query variables
*/
function getQueryVariable(variable) {
const query = window.location.search.substring(1);
const vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
const pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
}
/*
* Helper function to pretty-print data as JSON
*/
function stringify(obj) {
return JSON.stringify(obj, null, 4);
}
/*
* Entry point to Pulsar365 Web UI
*/
window.onload = function () {
if ((window.top !== window.self) && window.parent.pulsar) {
// Embedded in iframe?
docNode = 'window.iFrame.contentWindow.document';
bridge = window.parent.pulsar.bridge;
startApp();
}
else if (window.pulsar) {
// Called from another custom HTML?
bridge = window.pulsar.bridge;
startApp();
}
else {
// Launched stand-alone, startApp() on the bridge ready event
document.addEventListener('WebViewJavascriptBridgeReady', function(event) {
bridge = event.bridge;
window.pulsar = {};
pulsar.bridge = event.bridge; // save initial bridge (for propagation to other pages)
startApp();
}, false);
}
};
function startApp() {
// if launched from a record, this is the object Id in question
refObjectId = getQueryVariable('ref_id');
// what environment are we running on?
getPlatform();
// what user are we running on behalf of?
getUserInfo();
// populate inital sync status
getSyncInfo();
}
function getPlatform() {
var request = {};
var obj = {};
request["type"] = 'getPlatform';
request["data"] = obj;
bridge.sendRequest(request, function(responseData) {
console.log('platformInfo: ' + stringify(responseData));
const userInfoBody = document.getElementById("PlatformInfoBody");
if (responseData.type === "getPlatformResponse") {
platformStr = 'Running on the ' + responseData.data + ' platform';
if (refObjectId) {
platformStr += ', launched from record: ' + refObjectId;
}
console.log(platformStr);
userInfoBody.innerHTML = platformStr;
} else {
console.assert(responseData.type == 'error');
var errStr = responseData.data;
console.log('A problem occurred:\n' + errStr);
console.log('Couldnt get platform!');
userInfoBody.innerHTML = stringify(responseData.data);
}
});
}
function getUserInfo() {
var request = {};
var obj = {};
request["type"] = 'userInfo';
request["data"] = obj;
bridge.sendRequest(request, function(responseData) {
console.log('userInfo: ' + stringify(responseData));
const userInfoBody = document.getElementById("UserInfoBody");
if (responseData.type === "userInfoResponse") {
userInfoBody.innerHTML = stringify(responseData.data);
} else {
console.assert(responseData.type == 'error');
const errStr = responseData.data;
console.log('A problem occurred:\n' + errStr);
userInfoBody.innerHTML = stringify(responseData.data);
}
});
}
function getSyncInfo() {
var request = {};
var obj = {};
request["type"] = 'syncInfo';
request["data"] = obj;
bridge.sendRequest(request, function(responseData) {
console.log('syncInfo: ' + stringify(responseData));
const syncInfoBody = document.getElementById("SyncInfoBody");
if (responseData.type === "syncInfoResponse") {
syncInfoBody.innerHTML = stringify(responseData.data);
} else {
console.assert(responseData.type == 'error');
const errStr = responseData.data;
console.log('A problem occurred:\n' + errStr);
syncInfoBody.innerHTML = stringify(responseData.data);
}
});
}
</script>
</head>
<body>
<h1>Pulsar365 JS Hello World</h1>
<div class="container">
<div class="panel-heading">
Platform Info<br/>
</div>
<div class="panel-body" id="PlatformInfoBody"></div>
<hr/>
<div class="panel-heading">
User Info<br/>
</div>
<div class="panel-body" id="UserInfoBody"></div>
<hr/>
<div class="panel-heading">
Sync Info<br/>
</div>
<div class="panel-body" id="SyncInfoBody">(No sync info)</div>
<hr/>
</div>
</body>
</html>