| 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</title> |
| 9 |
|
| 10 |
<script type="text/javascript" src="../../../deviceTheme.js" |
| 11 |
data-dojo-config="mblThemeFiles: ['base']"></script> |
| 12 |
<script type="text/javascript" src="../../../../../dojo/dojo.js" |
| 13 |
data-dojo-config="async: true, parseOnLoad: true"></script> |
| 14 |
<script type="text/javascript" src="../TestUtil.js"></script> |
| 15 |
|
| 16 |
<script type="text/javascript"> |
| 17 |
require([ |
| 18 |
"dojo/ready", |
| 19 |
"doh/runner", |
| 20 |
"dojo/query", |
| 21 |
"dojo/_base/lang", |
| 22 |
"dojo/_base/array", |
| 23 |
"dojo/store/Memory", |
| 24 |
"dojo/store/Observable", |
| 25 |
"dijit/registry", |
| 26 |
"dojox/mobile/parser", |
| 27 |
"dojox/mobile", |
| 28 |
"dojox/mobile/compat", |
| 29 |
"dojox/mobile/EdgeToEdgeStoreList" |
| 30 |
], function(ready, runner, query, lang, array, Memory, Observable, registry){ |
| 31 |
var static_data1 = [ |
| 32 |
{ id: 1, text: "Category 1", header: true }, |
| 33 |
{ id: 2, text: "Wi-Fi", profile_image_url: "../../images/i-icon-1.png", moveTo: "wifi" }, |
| 34 |
{ id: 3, text: "Brightness & Wallpaper", profile_image_url: "../../images/i-icon-2.png", moveTo: "bright" }, |
| 35 |
{ id: 4, text: "Picture Frame", profile_image_url: "../../images/i-icon-3.png", moveTo: "picture" }, |
| 36 |
{ id: 5, text: "General", profile_image_url: "../../images/i-icon-4.png", moveTo: "general", "selected": "true" }, |
| 37 |
{ id: 6, text: "Mail, Contacts, Calendars", profile_image_url: "../../images/i-icon-5.png", moveTo: "wifi" }, |
| 38 |
{ id: 7, text: "Safari", profile_image_url: "../../images/i-icon-6.png", moveTo: "bright" }, |
| 39 |
{ id: 8, text: "iPod", profile_image_url: "../../images/i-icon-7.png", moveTo: "picture" }, |
| 40 |
{ id: 9, text: "Category 2", header: true }, |
| 41 |
{ id: 10, text: "Video", profile_image_url: "../../images/i-icon-8.png", moveTo: "general" }, |
| 42 |
{ id: 11, text: "Photos", profile_image_url: "../../images/i-icon-9.png", moveTo: "wifi" }, |
| 43 |
{ id: 12, text: "Store", profile_image_url: "../../images/i-icon-10.png", moveTo: "bright" } |
| 44 |
]; |
| 45 |
|
| 46 |
var static_data2 = [ |
| 47 |
{id: 1, label: "Apple", moveTo: "dummy"}, |
| 48 |
{id: 2, label: "Banana", moveTo: "dummy"}, |
| 49 |
{id: 3, label: "Cherry", moveTo: "dummy"}, |
| 50 |
{id: 4, label: "Grape", moveTo: "dummy"}, |
| 51 |
{id: 5, label: "Kiwi", moveTo: "dummy"}, |
| 52 |
{id: 6, label: "Lemon", moveTo: "dummy"}, |
| 53 |
{id: 7, label: "Melon", moveTo: "dummy"}, |
| 54 |
{id: 8, label: "Orange", moveTo: "dummy"}, |
| 55 |
{id: 9, label: "Peach", moveTo: "dummy"} |
| 56 |
]; |
| 57 |
store1 = Observable(new Memory({data: static_data1})); |
| 58 |
store2 = Observable(new Memory({data: static_data2})); |
| 59 |
store1.__counter = store2.__counter = 1; |
| 60 |
store = store1; |
| 61 |
|
| 62 |
// switch to the selected store |
| 63 |
switchTo = function(store){ |
| 64 |
window.store = store; |
| 65 |
registry.byId("list").setStore(store); |
| 66 |
}; |
| 67 |
// add a new item |
| 68 |
add1 = function(){ |
| 69 |
store.add({ |
| 70 |
id: 100 + store.__counter, |
| 71 |
label: "New Item "+(store.__counter++), |
| 72 |
icon: "images/i-icon-1.png", |
| 73 |
moveTo: "dummy" |
| 74 |
}); |
| 75 |
}; |
| 76 |
// update all items text or label |
| 77 |
update1 = function(){ |
| 78 |
array.forEach(store.query({}), function(item, i){ |
| 79 |
var newItem = lang.clone(item); |
| 80 |
if(newItem.text){ |
| 81 |
newItem.text = newItem.text+"-Updated"; |
| 82 |
}else{ |
| 83 |
newItem.label = newItem.label+"-Updated"; |
| 84 |
} |
| 85 |
store.put(newItem); |
| 86 |
}); |
| 87 |
}; |
| 88 |
// delete the added item |
| 89 |
delete1 = function(){ |
| 90 |
if(store.__counter > 1){ |
| 91 |
store.remove(100 + (--store.__counter)); |
| 92 |
} |
| 93 |
}; |
| 94 |
|
| 95 |
// Tests |
| 96 |
ready(function(){ |
| 97 |
runner.register("dojox.mobile.test.doh.scrollablepane.ScrollablePaneTests", [ |
| 98 |
{ |
| 99 |
name: "Verify that ticket #17093 is fixed", |
| 100 |
timeout: 4000, |
| 101 |
runTest: function(){ |
| 102 |
var referenceValues = lang.clone(static_data1); |
| 103 |
var nodeIndex = 0; |
| 104 |
// Verify what is displayed |
| 105 |
var nodes = query(".mblListItemLabel", "list"); |
| 106 |
runner.assertEqual(referenceValues.length, nodes.length, |
| 107 |
"Before update, number of elements in the list is not the expected one"); |
| 108 |
nodes.forEach(function(node){ |
| 109 |
var text = node.textContent || node.innerText; |
| 110 |
runner.assertEqual(text, referenceValues[nodeIndex].text); |
| 111 |
nodeIndex++; |
| 112 |
}); |
| 113 |
// Click the update button |
| 114 |
fireOnClick(document.getElementById("updateButton")); |
| 115 |
// Verify what is displayed |
| 116 |
var def = new runner.Deferred(); |
| 117 |
setTimeout(def.getTestCallback(function(){ |
| 118 |
nodeIndex = 0; |
| 119 |
var nodes = query(".mblListItemLabel", "list"); |
| 120 |
runner.assertEqual(referenceValues.length, nodes.length, |
| 121 |
"After update, number of elements in the list is not the expected one"); |
| 122 |
nodes.forEach(function(node){ |
| 123 |
var text = node.textContent || node.innerText; |
| 124 |
runner.assertEqual(text, referenceValues[nodeIndex].text + "-Updated"); |
| 125 |
nodeIndex++; |
| 126 |
}); |
| 127 |
}), 2000); |
| 128 |
return def; |
| 129 |
} |
| 130 |
} |
| 131 |
]); |
| 132 |
runner.run(); |
| 133 |
}); |
| 134 |
}); |
| 135 |
</script> |
| 136 |
</head> |
| 137 |
<body style="visibility:hidden;"> |
| 138 |
<div data-dojo-type="dojox/mobile/View"> |
| 139 |
<h1 data-dojo-type="dojox/mobile/Heading">EdgeToEdgeStoreList</h1> |
| 140 |
<ul data-dojo-type="dojox/mobile/EdgeToEdgeStoreList" id="list" |
| 141 |
data-dojo-props='store:store, query:{}, itemMap:{text:"label", profile_image_url:"icon"}'> |
| 142 |
</ul> |
| 143 |
<p>show the different set:<br> |
| 144 |
<input type="button" value="Set1" onclick="switchTo(store1)"> |
| 145 |
<input type="button" value="Set2" onclick="switchTo(store2)"> |
| 146 |
<p>alter the object store:<br> |
| 147 |
<input type="button" value="Add" onclick="add1()"> |
| 148 |
<input type="button" id="updateButton" value="Update" onclick="update1()"> |
| 149 |
<input type="button" value="Delete" onclick="delete1()"> |
| 150 |
</div> |
| 151 |
</body> |
| 152 |
</html> |