Debian Codegraph @

dijit/tests/tree/robot/Tree_dnd.js

raw symbols SCIP
1 /*
2 * Helper functions for Tree_dnd.html and Tree_dnd_multiParent.html tests
3 */
4
5 define([
6 "doh/runner", "dojo/robotx",
7 "dojo/_base/array", "dojo/dnd/autoscroll", "dojo/dom", "dojo/dom-geometry", "dojo/query", "dojo/_base/window",
8 "dijit/tests/helpers"
9 ], function(doh, robot, array, autoscroll, dom, domGeom, query, win, helpers){
10
11 var exports = {
12 setup: function setup(){
13 doh.register("setup screen", function(){
14 // Hide boilerplate text so it's easier to drag on small screen
15 query("h1,h2,p", robot.doc).style("display", "none");
16
17 // Disable auto-scrolling because otherwise the viewport scrolls as robot.mouseMoveAt()
18 // moves the mouse, literally making the the drop target a moving target
19 // (and mouseMoveAt() doesn't take this possibility into account).
20 autoscroll.autoScrollNodes = function(){};
21
22 // Scroll viewport to (try to) make sure that both tree and drag-source
23 // are simultaneously in view.
24 var scroll = domGeom.position(dom.byId("1001", robot.doc)).y;
25 win.body(robot.doc).parentNode.scrollTop = scroll; // works on FF
26 win.body(robot.doc).scrollTop = scroll; // works on safari
27 });
28
29 // Wait for trees to load
30 doh.register("wait for load", {
31 name: "wait for load",
32 timeout: 10000,
33 runTest: helpers.waitForLoad
34 });
35 doh.register("setup vars", function(){
36 registry = robot.window.require("dijit/registry");
37 });
38 },
39
40 findTreeNode: function findTreeNode(/*String*/ treeId, /*String*/ label){
41 // summary:
42 // Find the TreeNode with the specified label in the given tree.
43 // Assumes that there's only one TreeNode w/that label (i.e. it
44 // breaks if certain items have multiple parents and appear in the
45 // tree multiple times)
46 var nodes = query(".dijitTreeLabel", dom.byId(treeId, robot.doc));
47 for(var i=0; i<nodes.length; i++){
48 if(helpers.innerText(nodes[i]) == label){
49 return registry.getEnclosingWidget(nodes[i]); // TreeNode
50 }
51 }
52 return null;
53 },
54
55 findTreeNodeByPath: function findTreeNodeByPath(/*String*/ treeId, /*String[] */ path){
56 // summary:
57 // Find the TreeNode with the specified path (like ["Fruits", "Apple"] in a tree like:
58 // | * Foods
59 // | * Vegetables
60 // | * Fruits
61 // | * Orange
62 // | * Apple
63 // Path shouldn't include the root node.
64
65 var tree = registry.byId(treeId);
66 for(var i=0, node=tree.rootNode; i<path.length; i++){
67 var pathElem = path[i], matchingChildNode;
68 for(var j=0, children=node.getChildren(); j < children.length; j++){
69 if(children[j].label == pathElem){
70 matchingChildNode = children[j];
71 break;
72 }
73 }
74 if(!matchingChildNode){
75 return null;
76 }
77 node = matchingChildNode;
78 }
79 return node;
80 },
81
82 getChildrenOfItem: function getChildrenOfItem(/*String*/ name){
83 // summary:
84 // Return the children of the data store item w/the specified name
85 // Note that test_Tree_Dnd.html splits the children up into the "children"
86 // and "items" attributes.
87
88 // Get the parent item
89 // Note that the ItemFileWriteStore's callback will happen immediately.
90 var myStore = robot.window.myStore,
91 parentItem;
92 myStore.fetch({
93 query: {name: name},
94 onItem: function(item){ parentItem = item; }
95 });
96
97 // Get the children, which are stored in two separate attributes,
98 // categories (like 'Fruits') and items (ie, leaf nodes) (like 'Apple')
99 return {
100 categories: myStore.getValues(parentItem, 'children'),
101 items: myStore.getValues(parentItem, 'items')
102 };
103 },
104
105 mapItemsToNames: function mapItemsToNames(ary){
106 // summary:
107 // Convert an array of items into an array of names
108 var myStore = robot.window.myStore;
109 return array.map(ary, function(item){
110 return myStore.getValue(item, "name");
111 });
112 },
113
114 getNamesOfChildrenOfItem: function getNamesOfChildrenOfItem(/*String*/ name){
115 // summary:
116 // Return the names of the (items that are) children of the item w/the specified name
117
118 // Get the parent item (according to
119 var obj = exports.getChildrenOfItem(name);
120 return {
121 categories: exports.mapItemsToNames(obj.categories),
122 items: exports.mapItemsToNames(obj.items)
123 };
124 }
125 };
126
127 return exports;
128 });
129
130