-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
73 lines (67 loc) · 3.2 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
<html>
<head>
<script type="text/javascript" src="script/support.js"></script>
<script type="text/javascript" src="script/basic_operations.js"></script>
</head>
<body>
<h1>IndexDBSupported : <span id="indexdb-support"></span></h1>
<h2>Customer</h2>
<div>
<label>First Name : </label><input type="text" id='fname' />
<label>Last Name : </label><input type="text" id='lname' />
<input type="button" value="Add" id="add"/>
</div>
<h2>From DB</h2>
<div>
<table id="value">
</table>
<input type="button" value="Refresh" id="refresh"/>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
var dbName = "custDB";
var ver = 5;
var store = "cust";
db.open(dbName, ver, store, 'lastName' ,[{name: "lastName", contraint: {unique: true}}]);
document.getElementById("indexdb-support").innerHTML = window.isIndexDBSupported ? "Yup" : "Nope";
if (isIndexDBSupported) {
document.getElementById("add").onclick = function (e) {
var c = getCustomer();
db.set(store, c, c.lastName, function () {
db.get(store, c.lastName, function(cust) {
var cEle = createElement('tr');
var firstName = createElement('td', cust.firstName);
var lName = createElement('td', cust.lastName);
cEle.appendChild(firstName);
cEle.appendChild(lName);
document.getElementById("value").appendChild(cEle);
});
});
};
document.getElementById('refresh').onclick = function (e) {
var v = document.getElementById('value');
v.innerHTML = "";
db.getAll(store, function(cust) {
var c = createElement('tr');
var firstName = createElement('td', cust.firstName);
var lName = createElement('td', cust.lastName);
c.appendChild(firstName);
c.appendChild(lName);
v.appendChild(c);
});
};
}
var createElement = function (tag, value) {
var node = document.createElement(tag);
if(value)
node.innerHTML = value;
return node;
}
var getCustomer = function () {
var c = { 'firstName' : document.getElementById('fname').value,'lastName' : document.getElementById('lname').value};
return c;
};
});
</script>
</body>
</html>