9
9
< script type = "text/javascript " src ="../jquery.indexeddb.js ">
10
10
</ script >
11
11
< link href ="style.css " rel ="stylesheet "/>
12
+ < meta charset ="UTF-8 ">
12
13
</ head >
13
14
< body >
14
15
< div >
@@ -24,23 +25,23 @@ <h2>My Web Store
24
25
< div class = "controls ">
25
26
< h2 > Catalog</ h2 >
26
27
< a href = "javascript:loadFromDB('catalog') "> Load from Local DB</ a >
27
- < a href = "javascript:downloadCatalog(); "> Save from Server TO DB</ a >
28
+ < a href = "javascript:downloadCatalog(); "> Sync to DB</ a >
28
29
</ div >
29
30
< table id = "catalog " width ="400 ">
30
31
< tr >
31
32
< th class = "header key ">
32
33
Id
33
34
</ th >
35
+ < th class = "header actions ">
36
+ Actions
37
+ </ th >
34
38
< th class = "header value action ">
35
39
Object
36
40
< div style ="float:right; width : 200px ">
37
41
< a href = "javascript:loadFromDB('catalog') "> Show all</ a >
38
42
< a href = "javascript:sort('catalog', 'price') "> Sort by Price</ a >
39
43
</ div >
40
44
</ th >
41
- < th class = "header actions ">
42
- Actions
43
- </ th >
44
45
</ tr >
45
46
</ table >
46
47
</ div >
@@ -55,16 +56,16 @@ <h2>Cart</h2>
55
56
< th >
56
57
Id
57
58
</ th >
59
+ < th >
60
+ Actions
61
+ </ th >
58
62
< th >
59
63
Object
60
64
< div class = "action " style ="float:right; width : 200px ">
61
65
< a href = "javascript:loadFromDB('cart') "> Show all</ a >
62
66
< a href = "javascript:sort('cart', 'itemId') "> Sort by ItemId</ a >
63
67
</ div >
64
68
</ th >
65
- < th >
66
- Actions
67
- </ th >
68
69
</ tr >
69
70
</ table >
70
71
</ div >
@@ -80,10 +81,10 @@ <h2>wishlist</h2>
80
81
Id
81
82
</ th >
82
83
< th >
83
- Object
84
+ Actions
84
85
</ th >
85
86
< th >
86
- Actions
87
+ Object
87
88
</ th >
88
89
</ tr >
89
90
</ table >
@@ -122,7 +123,7 @@ <h2>wishlist</h2>
122
123
loadFromDB ( "cart" ) ;
123
124
loadFromDB ( "wishlist" ) ;
124
125
downloadCatalog ( ) ;
125
- } , 100 )
126
+ } , 200 ) ;
126
127
} ) ;
127
128
128
129
function deleteDB ( ) {
@@ -251,24 +252,35 @@ <h2>wishlist</h2>
251
252
var row = document . createElement ( "tr" ) ;
252
253
var html = [ "<tr>" ] ;
253
254
html = html . concat ( [ "<td class = 'key'>" , key , "</td>" ] ) ;
254
- html = html . concat ( [ "<td class = 'value'>" , JSON . stringify ( value ) . replace ( / , / g, ",\n" ) , "</td>" ] ) ;
255
255
html . push ( "<td class = 'action'>" ) ;
256
256
for ( var action in actions [ tableName ] ) {
257
257
html = html . concat ( "<a href = 'javascript:" , actions [ tableName ] [ action ] , "(" , key , ")'>" , action , "</a>" ) ;
258
258
}
259
259
html . push ( "</td>" ) ;
260
+ html = html . concat ( [ "<td class = 'value'>" , renderJSON ( value ) , "</td>" ] ) ;
260
261
html . push ( "</tr>" ) ;
261
262
row . innerHTML = html . join ( "" ) ;
262
263
table . appendChild ( row ) ;
263
264
}
264
265
266
+ function renderJSON ( val ) {
267
+ var result = [ ] ;
268
+ for ( var key in val ) {
269
+ result . push ( "<div class = 'keyval'>" ) ;
270
+ result . push ( "<span class = 'key'>" , key , "</span>" ) ;
271
+ result . push ( "<span class = 'value'>" , JSON . stringify ( val [ key ] ) , "</span>" ) ;
272
+ result . push ( "</div>" )
273
+ }
274
+ return result . join ( "" ) ;
275
+ }
276
+
265
277
function _ ( promise ) {
266
278
promise . then ( function ( a , e ) {
267
279
console . log ( "Action completed" , e . type , a , e ) ;
268
280
} , function ( a , e ) {
269
- console . log ( "Action completed" , e . type , a , e ) ;
281
+ console . log ( "Action completed" , a , e ) ;
270
282
} , function ( a , e ) {
271
- console . log ( "Action completed" , e . type , a , e ) ;
283
+ console . log ( "Action completed" , a , e ) ;
272
284
} )
273
285
}
274
286
</ script >
0 commit comments