99 < script type = "text/javascript " src ="../jquery.indexeddb.js ">
1010 </ script >
1111 < link href ="style.css " rel ="stylesheet "/>
12+ < meta charset ="UTF-8 ">
1213 </ head >
1314 < body >
1415 < div >
@@ -24,23 +25,23 @@ <h2>My Web Store
2425 < div class = "controls ">
2526 < h2 > Catalog</ h2 >
2627 < 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 >
2829 </ div >
2930 < table id = "catalog " width ="400 ">
3031 < tr >
3132 < th class = "header key ">
3233 Id
3334 </ th >
35+ < th class = "header actions ">
36+ Actions
37+ </ th >
3438 < th class = "header value action ">
3539 Object
3640 < div style ="float:right; width : 200px ">
3741 < a href = "javascript:loadFromDB('catalog') "> Show all</ a >
3842 < a href = "javascript:sort('catalog', 'price') "> Sort by Price</ a >
3943 </ div >
4044 </ th >
41- < th class = "header actions ">
42- Actions
43- </ th >
4445 </ tr >
4546 </ table >
4647 </ div >
@@ -55,16 +56,16 @@ <h2>Cart</h2>
5556 < th >
5657 Id
5758 </ th >
59+ < th >
60+ Actions
61+ </ th >
5862 < th >
5963 Object
6064 < div class = "action " style ="float:right; width : 200px ">
6165 < a href = "javascript:loadFromDB('cart') "> Show all</ a >
6266 < a href = "javascript:sort('cart', 'itemId') "> Sort by ItemId</ a >
6367 </ div >
6468 </ th >
65- < th >
66- Actions
67- </ th >
6869 </ tr >
6970 </ table >
7071 </ div >
@@ -80,10 +81,10 @@ <h2>wishlist</h2>
8081 Id
8182 </ th >
8283 < th >
83- Object
84+ Actions
8485 </ th >
8586 < th >
86- Actions
87+ Object
8788 </ th >
8889 </ tr >
8990 </ table >
@@ -122,7 +123,7 @@ <h2>wishlist</h2>
122123 loadFromDB ( "cart" ) ;
123124 loadFromDB ( "wishlist" ) ;
124125 downloadCatalog ( ) ;
125- } , 100 )
126+ } , 200 ) ;
126127 } ) ;
127128
128129 function deleteDB ( ) {
@@ -251,24 +252,35 @@ <h2>wishlist</h2>
251252 var row = document . createElement ( "tr" ) ;
252253 var html = [ "<tr>" ] ;
253254 html = html . concat ( [ "<td class = 'key'>" , key , "</td>" ] ) ;
254- html = html . concat ( [ "<td class = 'value'>" , JSON . stringify ( value ) . replace ( / , / g, ",\n" ) , "</td>" ] ) ;
255255 html . push ( "<td class = 'action'>" ) ;
256256 for ( var action in actions [ tableName ] ) {
257257 html = html . concat ( "<a href = 'javascript:" , actions [ tableName ] [ action ] , "(" , key , ")'>" , action , "</a>" ) ;
258258 }
259259 html . push ( "</td>" ) ;
260+ html = html . concat ( [ "<td class = 'value'>" , renderJSON ( value ) , "</td>" ] ) ;
260261 html . push ( "</tr>" ) ;
261262 row . innerHTML = html . join ( "" ) ;
262263 table . appendChild ( row ) ;
263264 }
264265
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+
265277 function _ ( promise ) {
266278 promise . then ( function ( a , e ) {
267279 console . log ( "Action completed" , e . type , a , e ) ;
268280 } , function ( a , e ) {
269- console . log ( "Action completed" , e . type , a , e ) ;
281+ console . log ( "Action completed" , a , e ) ;
270282 } , function ( a , e ) {
271- console . log ( "Action completed" , e . type , a , e ) ;
283+ console . log ( "Action completed" , a , e ) ;
272284 } )
273285 }
274286 </ script >
0 commit comments