-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
277 lines (262 loc) · 11 KB
/
index.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
<!doctype html>
<!--[if lt IE 7]>
<html class="no-js lt-ie9 lt-ie8 lt-ie7" lang=""> <![endif]-->
<!--[if IE 7]>
<html class="no-js lt-ie9 lt-ie8" lang=""> <![endif]-->
<!--[if IE 8]>
<html class="no-js lt-ie9" lang=""> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" lang=""> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/kendo/styles/kendo.common.min.css">
<link rel="stylesheet" href="css/kendo/styles/kendo.bootstrap.min.css">
<link rel="stylesheet" href="css/kendo/styles/kendo.bootstrap.mobile.min.css">
<style>
body {
padding-top: 50px;
padding-bottom: 20px;
}
</style>
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/main.css">
<script src="js/vendor/modernizr-2.8.3-respond-1.4.2.min.js"></script>
</head>
<body>
<!--[if lt IE 8]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade
your browser</a> to improve your experience.</p>
<![endif]-->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Kendo test</a>
</div>
</div>
</nav>
<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
<div class="container">
<h1>Name Loader Demo</h1>
<p>This is a simple Kendo UI example project using static HTML, hitting a web service to generate random user
profiles and dropping them into a grid. For fun, it supports querying multiple regions at once even though the underlying API does not (it combines results). It also pulls the supported regions from the API's github source instead of using a hardcoded list, so (theoretically) as the project is improved the list will stay up to date.</p>
</div>
</div>
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">Options</div>
<div class="panel-body">
<form id="namesForm" class="form-horizontal">
<div class="form-group">
<label for="inputMale" class="col-sm-2 control-label">Male Names</label>
<div class="col-sm-10">
<input type="checkbox" id="inputMale" checked="checked"/>
</div>
</div>
<div class="form-group">
<label for="inputFemale" class="col-sm-2 control-label">Female Names</label>
<div class="col-sm-10">
<input type="checkbox" id="inputFemale" checked="checked"/>
</div>
</div>
<div class="form-group">
<label for="numResults" class="col-sm-2 control-label">Number of Results</label>
<div class="col-sm-10">
<input id="numResults"/>
</div>
</div>
<div class="form-group">
<label for="nameRange" class="col-sm-2 control-label">Min/Max Name Size</label>
<div class="col-sm-10">
<div id="nameRange">
<input id="nameRangeBegin"/>
<input id="nameRangeEnd"/>
</div>
</div>
</div>
<div class="form-group">
<label for="nameRegions" class="col-sm-2 control-label">Name Regions</label>
<div class="col-sm-10">
<select id="nameRegions" multiple="multiple" required validationMessage="Select At Least One Region" data-placeholder="Select Countries (start typing...)" >
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Get Some Names!</button>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div id="grid"></div>
</div>
</div>
<hr>
<footer>
<p>© Mark Gunlogson 2016</p>
</footer>
</div> <!-- /container -->
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<script src="js/vendor/bootstrap.min.js"></script>
<script src="/node_modules/setasap/setAsap.min.js"></script>
<script src="/node_modules/whatwg-fetch/fetch.js"></script>
<script src="js/vendor/kendo/kendo.all.min.js"></script>
<script src="js/main.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.2/lodash.js"
integrity="sha256-jMc5qmlrXS+V1z21mzYUtTpsqdYU4BLe8gzd/UBPo24="
crossorigin="anonymous"></script>
<script>
'use strict';
//Kendo UI components
$(document).ready(function () {
var supportedRegions = [];
var actualGridResults = [];
var switchInstance = $("#inputMale").kendoMobileSwitch();
var switchInstance2 = $("#inputFemale").kendoMobileSwitch();
$("#grid").kendoGrid({
dataSource: {
data: actualGridResults,
schema: {
model: {
fields: {
name: {type: "string"},
surname: {type: "string"},
gender: {type: "string"},
region: {type: "string"}
}
}
},
pageSize: 100
},
height: 550,
groupable: true,
sortable: true,
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
});
$("#nameRange").kendoRangeSlider({
min: 5,
max: 30,
orientation: "horizontal",
smallStep: 5,
largeStep: 10,
tickPlacement: "BOTH"
});
$("#numResults").kendoSlider({
max: 500,
min: 50,
orientation: "horizontal",
smallStep: 50,
largeStep: 100
});
$("#nameRegions").kendoMultiSelect({
animation: false,
dataSource: supportedRegions
});
//get list of available name regions for multi-select
fetch('https://raw.githubusercontent.com/thm/uinames/master/names.json').then(function (response) {
if (response.ok) {
response.json().then(function (json) {
json.forEach(function (element) {
supportedRegions.push(element.region);
})
//refresh datasource
$("#nameRegions").data('kendoMultiSelect').refresh();
});
} else {
console.log('Region request failed');
}
});
var validator = $("#namesForm").kendoValidator().data("kendoValidator"),
status = $(".status");
$("#namesForm").submit(function (event) {
event.preventDefault();
if (validator.validate()) {
status.text("")
.removeClass("invalid")
.addClass("valid");
//make fetch call to API and dump into grid widget
//build query(ies)
var query = {
male: $("#inputMale").data("kendoMobileSwitch").check(),
female: $("#inputFemale").data("kendoMobileSwitch").check(),
count: $("#numResults").val(),
shortestName: $("#nameRangeBegin").val(),
longestName: $("#nameRangeEnd").val(),
nameRegions: $("#nameRegions").val(),
};
//get the data from api
var datar = getNamesFromApi(query);
//dump to grid
} else {
status.text("Oops! There is invalid data in the form.")
.removeClass("valid")
.addClass("invalid");
}
});
function getNamesFromApi(options) {
//ignore request if female and male are both unselected....
if ((!options.male) && (!options.female)) {
$("#grid").data('kendoGrid').dataSource.data([]);
return;
}
//make a query for each region chosen, throw them in promise array
var requestPromiseAry = [];
options.nameRegions.forEach(function (theRegion) {
//generate param string
var params = {
amount: options.count,
minlen: options.shortestName,
maxlen: options.longestName,
region: theRegion
};
//don't add the param if they want male and female(api uses blank instead)
if (!(options.male && options.female)) {
params.gender = options.male ? "male" : "female";
}
var paramStr = jQuery.param(params);
var myInit = { method: 'GET',
mode: 'cors',
cache: 'default' };
requestPromiseAry.push(fetch("http://uinames.com/api/?" + paramStr,myInit).then(function (response){return response.json()}));
})
//now we have a bunch of async api requests flying around. Use a promise to resolve everything.
Promise.all(requestPromiseAry).then(function (dataArr) {
var resultsAry = [];
dataArr.forEach(function (data) {
//combine the results into a single array
resultsAry=resultsAry.concat(data);
});
//use lodash to sample random subset with an actual correct count...
actualGridResults=_.sampleSize(resultsAry,options.count);
//refresh grid data
$("#grid").data('kendoGrid').dataSource.data(actualGridResults);
});
}
});
</script>
</body>
</html>