forked from CmIm/sap-ui5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui5_wunder_app.html
425 lines (357 loc) · 12 KB
/
ui5_wunder_app.html
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
<!DOCTYPE html>
<html>
<head>
<!-- Added charset='utf-8' to handle data in various langauges -->
<meta http-equiv='X-UA-Compatible' content='IE=edge' charset='utf-8' />
<title>Weather Forecast</title>
<!-- Load UI5, select gold reflection theme and the "commons" and "table" control libraries -->
<script id='sap-ui-bootstrap' type='text/javascript'
src='resources/sap-ui-core.js' data-sap-ui-theme='sap_platinum'
data-sap-ui-libs='sap.ui.commons,sap.ui.table'></script>
<script type="text/javascript">
// create a JSONModel, fill in the data and bind the Table to this model
var oModel = new sap.ui.model.json.JSONModel();
// service url for Weather Underground JSON API
var url = 'http://api.wunderground.com/api/Your_Key/conditions/forecast/q/autoip.json?callback=getJSON';
// var url = 'http://api.wunderground.com/api/Your_Key/conditions/forecast/lang:MR/q/autoip.json?callback=getJSON'; //Example URL
// var url = 'http://api.wunderground.com/api/Your_Key/forecast/conditions/lang:MR/q/France/Paris.json?callback=getJSON'; //Example URL
//Ajax Call with Callback function and JSONP data type
$
.ajax({
url : url,
jsonpCallback : 'getJSON',
contentType : "application/json",
dataType : 'jsonp',
success : function(data, textStatus, jqXHR) {
oModel.setData(data);
sap.ui.getCore().setModel(oModel);
// create matrix layout
var oMatrix = new sap.ui.commons.layout.MatrixLayout({
id : 'matrix',
layoutFixed : false,
columns : 3,
});
var oCell = new sap.ui.commons.layout.MatrixLayoutCell({
colSpan : 3
});
var oTV = new sap.ui.commons.TextView(
{
id : 'TV-Head',
text : 'SAPUI5 Application based on Weather Underground JSON API',
design : sap.ui.commons.TextViewDesign.H1
});
oCell.addContent(oTV);
oMatrix.createRow(oCell);
//Create a standard divider
var oCell = new sap.ui.commons.layout.MatrixLayoutCell({
colSpan : 3
});
oCell.addContent(new sap.ui.commons.HorizontalDivider());
oMatrix.createRow(oCell);
//Lable and TextField for City
oLabelCity = new sap.ui.commons.Label({
id : 'L-City',
text : 'City'
});
oTFCity = new sap.ui.commons.TextField({
id : 'TF-City',
tooltip : 'City',
editable : false,
value : '{/current_observation/display_location/full}',
width : '200px'
});
oLabelCity.setLabelFor(oTFCity);
oMatrix.createRow(oLabelCity, oTFCity);
//Lable and TextField for Latitute
oLabelLat = new sap.ui.commons.Label({
id : 'L-Lat',
text : 'Latitude'
});
oTFLat = new sap.ui.commons.TextField(
{
id : 'TF-Lat',
tooltip : 'Latitude',
editable : false,
value : '{/current_observation/display_location/latitude}',
width : '200px'
});
oLabelLat.setLabelFor(oTFLat);
oMatrix.createRow(oLabelLat, oTFLat);
//Lable and TextField for longitude
oLabelLon = new sap.ui.commons.Label({
id : 'L-Lon',
text : 'Longitude'
});
oTFLon = new sap.ui.commons.TextField(
{
id : 'TF-Lon',
tooltip : 'Longitude',
editable : false,
value : '{/current_observation/display_location/longitude}',
width : '200px'
});
oLabelLon.setLabelFor(oTFLon);
oMatrix.createRow(oLabelLon, oTFLon);
//Lable and TextField for Elevation
oLabelElev = new sap.ui.commons.Label({
id : 'L-Elev',
text : 'Elevation'
});
oTFElev = new sap.ui.commons.TextField(
{
id : 'TF-Elev',
tooltip : 'Elevation',
editable : false,
value : '{/current_observation/observation_location/elevation}',
width : '200px'
});
oLabelElev.setLabelFor(oTFElev);
oMatrix.createRow(oLabelElev, oTFElev);
//Create a standard divider
var oCell = new sap.ui.commons.layout.MatrixLayoutCell({
colSpan : 3
});
oCell.addContent(new sap.ui.commons.HorizontalDivider());
oMatrix.createRow(oCell);
//Weather image
var oImageWeather = new sap.ui.commons.Image({
src : '{/current_observation/icon_url}',
alt : '{/current_observation/icon}'
});
//Lable and TextField for weather
oLabelWeather = new sap.ui.commons.Label({
id : 'L-Weather',
text : 'Weather'
});
oTFWeather = new sap.ui.commons.TextField({
id : 'TF-Weather',
tooltip : 'Weather',
editable : false,
value : '{/current_observation/weather}',
width : '200px'
});
oLabelWeather.setLabelFor(oTFWeather);
oMatrix.createRow(oLabelWeather, oTFWeather, oImageWeather);
//Create a standard divider
var oCell = new sap.ui.commons.layout.MatrixLayoutCell({
colSpan : 3
});
oCell.addContent(new sap.ui.commons.HorizontalDivider());
oMatrix.createRow(oCell);
//Lable and TextField for temp_c
oLabelTemp = new sap.ui.commons.Label({
id : 'L-Temp',
text : 'Temperature'
});
var tempstring = oModel
.getProperty("/current_observation/temp_c");
//Append Degree Celsius unit symbol to Temperature reading
var tempinC = tempstring + "\u2103";
oTFTemp = new sap.ui.commons.TextField({
id : 'TF-Temp',
tooltip : 'Temperature',
editable : false,
value : tempinC,
width : '220px'
});
oLabelTemp.setLabelFor(oTFTemp);
oMatrix.createRow(oLabelTemp, oTFTemp);
//Lable and TextField for Obervation Time
oLabelObsTime = new sap.ui.commons.Label({
id : 'L-ObsTime',
text : 'Observation Time'
});
oTFObsTime = new sap.ui.commons.TextField({
id : 'TF-ObsTime',
tooltip : 'Observation Time',
editable : false,
value : '{/current_observation/observation_time}',
width : '220px'
});
oLabelObsTime.setLabelFor(oTFObsTime);
oMatrix.createRow(oLabelObsTime, oTFObsTime);
//Lable and TextField for Local Time
oLabelLclTime = new sap.ui.commons.Label({
id : 'L-LclTime',
text : 'Local Time'
});
oTFLclTime = new sap.ui.commons.TextField({
id : 'TF-LclTime',
tooltip : 'Local Time',
editable : false,
value : '{/current_observation/local_time_rfc822}',
width : '220px'
});
oLabelLclTime.setLabelFor(oTFLclTime);
oMatrix.createRow(oLabelLclTime, oTFLclTime);
//Lable and TextField for relative humidity
oLabelRelHum = new sap.ui.commons.Label({
id : 'L-RelHum',
text : 'Relative Humidity'
});
oTFRelHum = new sap.ui.commons.TextField({
id : 'TF-RelHum',
tooltip : 'Relative Humidity',
editable : false,
value : '{/current_observation/relative_humidity}',
width : '220px'
});
oLabelRelHum.setLabelFor(oTFRelHum);
oMatrix.createRow(oLabelRelHum, oTFRelHum);
//Lable and TextField for Wind
oLabelWind = new sap.ui.commons.Label({
id : 'L-Wind',
text : 'Wind'
});
oTFWind = new sap.ui.commons.TextField({
id : 'TF-Wind',
tooltip : 'Wind',
editable : false,
value : '{/current_observation/wind_string}',
width : '220px'
});
oLabelWind.setLabelFor(oTFWind);
oMatrix.createRow(oLabelWind, oTFWind);
//attach it to some element in the page
oMatrix.placeAt('content');
//Create an instance of the table control
var oTable1 = new sap.ui.table.Table({
title : "Simple Forecast Details",
visibleRowCount : 4,
selectionMode : sap.ui.table.SelectionMode.Single,
navigationMode : sap.ui.table.NavigationMode.Paginator,
});
//Define the columns and the control templates to be used
oTable1.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
text : "Period"
}),
template : new sap.ui.commons.TextView().bindProperty(
"text", "date/weekday"),
width : "10px"
}));
oTable1.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
text : "Image"
}),
template : new sap.ui.commons.Image().bindProperty(
"src", "icon_url"),
width : "10px",
hAlign : "Center"
}));
oTable1.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
text : "High"
}),
template : new sap.ui.commons.TextView().bindProperty(
"text", "high/celsius"),
width : "10px"
}));
oTable1.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
text : "Low"
}),
template : new sap.ui.commons.TextView().bindProperty(
"text", "low/celsius"),
width : "10px"
}));
oTable1.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
text : "Avarage Humidity"
}),
template : new sap.ui.commons.TextView().bindProperty(
"text", "avehumidity"),
width : "10px"
}));
oTable1.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
text : "Max Humidity"
}),
template : new sap.ui.commons.TextView().bindProperty(
"text", "maxhumidity"),
width : "10px"
}));
oTable1.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
text : "Min Humidity"
}),
template : new sap.ui.commons.TextView().bindProperty(
"text", "minhumidity"),
width : "10px"
}));
oTable1.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
text : "Chance of Precipitation"
}),
template : new sap.ui.commons.TextView().bindProperty(
"text", "pop"),
width : "10px"
}));
//Create a model and bind the table rows to this model
var oModel2 = new sap.ui.model.json.JSONModel();
//Get he forecastday array from simpleforecast object
var aSimpleForecast = oModel.getProperty("/forecast/simpleforecast/forecastday");
oModel2.setData({
modelData : aSimpleForecast
});
oTable1.setModel(oModel2);
oTable1.bindRows("/modelData");
oTable1.placeAt('content');
//Create an instance of the table control
var oTable = new sap.ui.table.Table({
title : "Textual Forecast Details",
visibleRowCount : 8,
selectionMode : sap.ui.table.SelectionMode.Single,
navigationMode : sap.ui.table.NavigationMode.Paginator,
});
//Define the columns and the control templates to be used
oTable.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
text : "Period"
}),
template : new sap.ui.commons.TextView().bindProperty(
"text", "title"),
width : "50px"
}));
oTable.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
text : "Image"
}),
template : new sap.ui.commons.Image().bindProperty(
"src", "icon_url"),
width : "75px",
hAlign : "Center"
}));
oTable.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
text : "Forecast"
}),
template : new sap.ui.commons.TextView().bindProperty(
"text", "fcttext_metric"),
width : "300px"
}));
//Create a model and bind the table rows to this model
var oModel1 = new sap.ui.model.json.JSONModel();
//Get the forecastday array table from txt_forecast object
var aData = oModel.getProperty("/forecast/txt_forecast/forecastday");
oModel1.setData({
modelData : aData
});
oTable.setModel(oModel1);
oTable.bindRows("/modelData");
oTable.placeAt('content');
}
});
</script>
</head>
<body class='sapUiBody'>
<div id='content'></div>
<p></p>
<div id="footer">
<div style="float: right; text-align: right;">
<img src="http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png"
border="0" alt=""><br> <span style="padding-top: 20px;">Weather data provided by Weather Underground, Inc.</span>
</div>
</div>
</body>
</html>