summaryrefslogtreecommitdiff
path: root/webapps/qooxdoo-0.6.3-sdk/frontend/demo/source/html/test/List_2.html
blob: d7c51c24fc7e94f09bfb1cd7440b7161115efbb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>qooxdoo &raquo; Demo</title>
  <link type="text/css" rel="stylesheet" href="../../resource/css/layout.css"/>
  <!--[if IE]>
  <link type="text/css" rel="stylesheet" href="../../resource/css/layout_ie.css"/>
  <![endif]-->
  <script type="text/javascript" src="../../script/qx.js"></script>
</head>
<body>
  <script type="text/javascript" src="../../script/layout.js"></script>

  <div id="demoDescription">
    <p>List implementation</p>
    <p>Drag and Drop Handling added</p>
  </div>

  <script type="text/javascript">
    qx.core.Init.getInstance().defineMain(function()
    {
      var doc = qx.ui.core.ClientDocument.getInstance();

      // Create list to drag from


      var sourceList = new qx.ui.form.List();
      sourceList.setWidth(100);
      sourceList.setHeight(250);
      sourceList.setLeft(20);
      sourceList.setTop(48);

      // Set vertical scroll bar to always visible
      sourceList.setOverflow("scrollY");
      // Set selection mode to single explicitly
      // sourceList.getManager().setMultiSelection(false);
      // Set drag selection mode to off
      sourceList.getManager().setDragSelection(false);

      // Add items to source list

      for (var i = 1; i <= 10; i++) 
      {
        var item = new qx.ui.form.ListItem("Item " + i);
        item.addEventListener("dragstart", handleStartDrag);
        sourceList.add(item);
      };

      doc.add(sourceList);



      // Create list to drop to

      var destList = new qx.ui.form.List();
      destList.setWidth(100);
      destList.setHeight(250);
      destList.setLeft(320);
      destList.setTop(48);
      
      // Set vertical scroll bar to always visible
      destList.setOverflow("scrollY");
      // Set selection mode to single explicitly
      // destList.getManager().setMultiSelection(false);
      // Set drag selection mode to off
      destList.getManager().setDragSelection(false);
      
      doc.add(destList);      

      // Define event handlers

      function handleStartDrag(e) 
      {
        e.addData("ListItems", qx.lang.Array.copy(sourceList.getManager().getSelectedItems()));
        e.addAction("move");
        e.startDrag();
      };

      function handleListDrop(e) 
      {
        var type = e.getDropDataTypes()[0];
        var data = e.getData(type);

        // this.debug("Drag&Drop Action: " + e.getAction());
        
        switch(e.getAction())
        {
          case "move":
            sourceList.getManager().setSelectedItems([]);
            sourceList.getManager().setAnchorItem(null);
            sourceList.getManager().setLeadItem(null);
          
            for (var i=0, l=data.length; i<l; i++) {
              destList.add(data[i]);
            };
            
            destList.getManager().setSelectedItems(data);
            break;
        };
      };



      // Set event properties for destination list

      destList.setDropDataTypes(["ListItems"]);
      destList.addEventListener("dragdrop", handleListDrop);
    });
  </script>
</body>
</html>