| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-type" content="text/html; charset=utf-8"/> |
| 5 | <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/> |
| 6 | <meta name="apple-mobile-web-app-capable" content="yes"/> |
| 7 | <title>RoundRectDataList</title> |
| 8 | |
| 9 | <script type="text/javascript" src="../deviceTheme.js" data-dojo-config="mblThemeFiles: ['base']"></script> |
| 10 | <script type="text/javascript" src="../../../dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: true"></script> |
| 11 | |
| 12 | <script type="text/javascript"> |
| 13 | require([ |
| 14 | "dojo/_base/lang", |
| 15 | "dojo/data/ItemFileWriteStore", |
| 16 | "dijit/registry", |
| 17 | "dojox/mobile/parser", |
| 18 | "dojox/mobile", |
| 19 | "dojox/mobile/compat", |
| 20 | "dojox/mobile/RoundRectDataList" |
| 21 | ], function(lang, ItemFileWriteStore, registry){ |
| 22 | var static_data = { |
| 23 | items: [ |
| 24 | {label: "Apple", moveTo: "dummy"}, |
| 25 | {label: "Banana", moveTo: "dummy"}, |
| 26 | {label: "Cherry", moveTo: "dummy"}, |
| 27 | {label: "Grape", moveTo: "dummy"}, |
| 28 | {label: "Kiwi", moveTo: "dummy"}, |
| 29 | {label: "Lemon", moveTo: "dummy"}, |
| 30 | {label: "Melon", moveTo: "dummy"}, |
| 31 | {label: "Orange", moveTo: "dummy"}, |
| 32 | {label: "Peach", moveTo: "dummy"} |
| 33 | ] |
| 34 | }; |
| 35 | store1 = new ItemFileWriteStore({url: "data/settings.json", clearOnClose: true}); |
| 36 | store2 = new ItemFileWriteStore({data: lang.clone(static_data), clearOnClose: true}); |
| 37 | store = store1; |
| 38 | var newItems = [[],[]]; |
| 39 | |
| 40 | // switch to the selected store |
| 41 | switchTo = function(store){ |
| 42 | window.store = store; |
| 43 | registry.byId("list").setStore(store); |
| 44 | }; |
| 45 | // add a new item |
| 46 | add1 = function(){ |
| 47 | var item = store.newItem({label: "New Item", moveTo: "dummy"}); |
| 48 | newItems[(store == store1) ? 1 : 0].push(item); |
| 49 | }; |
| 50 | // delete the added item |
| 51 | delete1 = function(){ |
| 52 | var item = newItems[(store == store1) ? 1 : 0].pop(); |
| 53 | if(item){ |
| 54 | store.deleteItem(item); |
| 55 | } |
| 56 | }; |
| 57 | reload1 = function(){ |
| 58 | store.save({onComplete: function(){console.log("Saved");}, onError: function(e){console.log(e);}}); |
| 59 | if(store === store2){ |
| 60 | store.data = lang.clone(static_data); |
| 61 | } |
| 62 | store.close(); |
| 63 | }; |
| 64 | }); |
| 65 | </script> |
| 66 | </head> |
| 67 | <body style="visibility:hidden;"> |
| 68 | <div data-dojo-type="dojox.mobile.View"> |
| 69 | <h1 data-dojo-type="dojox.mobile.Heading">RoundRectDataList</h1> |
| 70 | <ul data-dojo-type="dojox.mobile.RoundRectDataList" id="list" data-dojo-props='store:store, query:{label: "*"}'></ul> |
| 71 | <p>show the different set:<br> |
| 72 | <input type="button" value="Set1" onclick="switchTo(store1)"> |
| 73 | <input type="button" value="Set2" onclick="switchTo(store2)"> |
| 74 | <p>alter the object store:<br> |
| 75 | <input type="button" value="Add" onclick="add1()"> |
| 76 | <input type="button" value="Delete" onclick="delete1()"> |
| 77 | <input type="button" value="Reload" onclick="reload1()"> |
| 78 | </div> |
| 79 | </body> |
| 80 | </html> |