Debian Codegraph @

dojox/mobile/tests/test_EdgeToEdgeStoreList-itemMap-updates.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
5 <meta name="viewport"
6 content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/>
7 <meta name="apple-mobile-web-app-capable" content="yes"/>
8 <title>EdgeToEdgeStoreList - updates</title>
9
10 <script type="text/javascript" src="../deviceTheme.js"
11 data-dojo-config="mblThemeFiles: ['base', 'Button']"></script>
12 <script type="text/javascript" src="../../../dojo/dojo.js"
13 data-dojo-config="async: true, parseOnLoad: true"></script>
14
15 <script type="text/javascript">
16 require([
17 "dojo/_base/lang",
18 "dojo/_base/array",
19 "dojo/store/Memory",
20 "dojo/store/Observable",
21 "dijit/registry",
22 "dojox/mobile/parser",
23 "dojox/mobile",
24 "dojox/mobile/compat",
25 "dojox/mobile/EdgeToEdgeStoreList",
26 "dojox/mobile/Button"
27 ], function(lang, array, Memory, Observable, registry){
28 var updateCounter = 0;
29
30 var static_data1 = [
31 { id: 1, text: "Category 1", header: true },
32 { id: 2, text: "Wi-Fi", profile_image_url: "images/i-icon-1.png", moveTo: "wifi" },
33 { id: 3, text: "Brightness & Wallpaper", profile_image_url: "images/i-icon-2.png", moveTo: "bright" },
34 { id: 4, text: "Picture Frame", profile_image_url: "images/i-icon-3.png", moveTo: "picture" },
35 { id: 5, text: "General", profile_image_url: "images/i-icon-4.png", moveTo: "general", "selected": "true" },
36 { id: 6, text: "Mail, Contacts, Calendars", profile_image_url: "images/i-icon-5.png", moveTo: "wifi" },
37 { id: 7, text: "Safari", profile_image_url: "images/i-icon-6.png", moveTo: "bright" },
38 { id: 8, text: "iPod", profile_image_url: "images/i-icon-7.png", moveTo: "picture" },
39 { id: 9, text: "Category 2", header: true },
40 { id: 10, text: "Video", profile_image_url: "images/i-icon-8.png", moveTo: "general" },
41 { id: 11, text: "Photos", profile_image_url: "images/i-icon-9.png", moveTo: "wifi" },
42 { id: 12, text: "Store", profile_image_url: "images/i-icon-10.png", moveTo: "bright" }
43 ];
44
45 var static_data2 = [
46 {id: 1, label: "Apple", moveTo: "dummy"},
47 {id: 2, label: "Banana", moveTo: "dummy"},
48 {id: 3, label: "Cherry", moveTo: "dummy"},
49 {id: 4, label: "Grape", moveTo: "dummy"},
50 {id: 5, label: "Kiwi", moveTo: "dummy"},
51 {id: 6, label: "Lemon", moveTo: "dummy"},
52 {id: 7, label: "Melon", moveTo: "dummy"},
53 {id: 8, label: "Orange", moveTo: "dummy"},
54 {id: 9, label: "Peach", moveTo: "dummy"}
55 ];
56 store1 = Observable(new Memory({data: static_data1}));
57 store2 = Observable(new Memory({data: static_data2}));
58 store1.__counter = store2.__counter = 1;
59 store = store1;
60
61 // switch to the selected store
62 switchTo = function(store){
63 window.store = store;
64 registry.byId("list").setStore(store);
65 };
66 // add a new item
67 add1 = function(){
68 store.add({
69 id: 100 + store.__counter,
70 label: "New Item "+(store.__counter++),
71 icon: "images/i-icon-1.png",
72 moveTo: "dummy"
73 });
74 };
75 // update the text or label of all items
76 var updateSuffix = " update #";
77 var updateUtil = function(str){
78 // Skip the category items (for aesthetic reasons)
79 if(str.indexOf("Category") == 0){
80 return str;
81 }
82 var idx = str.indexOf(updateSuffix);
83 return idx >= 0 ?
84 // already updated: just update the counter
85 str.substring(0, idx) + updateSuffix + updateCounter :
86 // first update: append to str
87 str + updateSuffix + updateCounter;
88 };
89
90 update1 = function(){
91 updateCounter++;
92 array.forEach(store.query({}), function(item, i){
93 // Changes of the data items of the store must only be done
94 // through the API of the store. Hence the cloning.
95 var newItem = lang.clone(item);
96 if(newItem.text){
97 newItem.text = updateUtil(newItem.text);
98 }else{
99 newItem.label = updateUtil(newItem.label)
100 }
101 store.put(newItem);
102 });
103 };
104 // delete the added item
105 delete1 = function(){
106 if(store.__counter > 1){
107 store.remove(100 + (--store.__counter));
108 }
109 };
110 });
111 </script>
112 </head>
113 <body style="visibility:hidden;">
114 <div data-dojo-type="dojox/mobile/View">
115 <h1 data-dojo-type="dojox/mobile/Heading">EdgeToEdgeStoreList</h1>
116 <ul data-dojo-type="dojox/mobile/EdgeToEdgeStoreList" id="list"
117 data-dojo-props='store: store, query: {}, itemMap: {text:"label", profile_image_url: "icon"}'>
118 </ul>
119 <p>Select the data store:<br>
120 <input data-dojo-type="dojox/mobile/Button" type="button" value="Set1"
121 onclick="switchTo(store1)">
122 <input data-dojo-type="dojox/mobile/Button" type="button" value="Set2"
123 onclick="switchTo(store2)">
124 <p>Alter the data store:<br>
125 <input data-dojo-type="dojox/mobile/Button" type="button" value="Add"
126 onclick="add1()">
127 <input data-dojo-type="dojox/mobile/Button" type="button" value="Update"
128 onclick="update1()">
129 <input data-dojo-type="dojox/mobile/Button" type="button" value="Delete"
130 onclick="delete1()">
131 </div>
132 </body>
133 </html>