summaryrefslogtreecommitdiff
path: root/swat/apps/qooxdoo-examples/example/RpcTreeFullControl_1.html
blob: 84c36576a4162419bda286158d7f128fa034d503 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<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>
    Shows a tree which listens for tree events.  This script communicates via
    JSON-RPC to a backend server.  Each time a new tree node is opened, the
    children are requested from the server.  See the server-side functions
    at backend/php/services/qooxdoo/fs.php.
  </div>

<script type="text/javascript">
qx.core.Init.getInstance().defineMain(
    function()
    {
        var addChildren = function(parent, children)
        {
            var t;
            var trs;
            var child;

            for (i = 0; i < children.length; i++)
            {
                child = children[i];

                trs = qx.ui.treefullcontrol.TreeRowStructure.getInstance().newRow();

                // Here's our indentation and tree-lines
                trs.addIndent();

                // If not a file or directory, change the icon
                var bIsDirectory = ((child.mode & 0040000) != 0);
                var bIsFile = ((child.mode & 0100000) != 0);
                if (! bIsDirectory && ! bIsFile)
                {
                    trs.addIcon("icon/16/desktop.png",
                                "icon/16/dictionary.png");
                }
                else
                {
                    trs.addIcon();
                }

                // The label
                trs.addLabel(child.name);

                // All else should be right justified
                obj = new qx.ui.basic.HorizontalSpacer;
                trs.addObject(obj, true);

                // Add the permissions
                mode = "";
                mode = ((child.mode & 0001) ? "x" : "-") + mode;
                mode = ((child.mode & 0002) ? "w" : "-") + mode;
                mode = ((child.mode & 0004) ? "r" : "-") + mode;
                mode = ((child.mode & 0010) ? "x" : "-") + mode;
                mode = ((child.mode & 0020) ? "w" : "-") + mode;
                mode = ((child.mode & 0040) ? "r" : "-") + mode;
                mode = ((child.mode & 0100) ? "x" : "-") + mode;
                mode = ((child.mode & 0200) ? "w" : "-") + mode;
                mode = ((child.mode & 0400) ? "r" : "-") + mode;
                obj = new qx.ui.basic.Label(mode);
                obj.setWidth(80);
                obj.setStyleProperty("fontFamily", "monospace");
                trs.addObject(obj, true);

                // Add a file size, date and mode
                obj = new qx.ui.basic.Label(child.size + "");
                obj.setWidth(50);
                obj.setStyleProperty("fontFamily", "monospace");
                trs.addObject(obj, true);

                var d = new Date();
                d.setTime(child.mtime * 1000);
                obj = new qx.ui.basic.Label(d.toString().slice(0,33));
                obj.setWidth(200);
                obj.setStyleProperty("fontFamily", "monospace");
                trs.addObject(obj, true);

                if (bIsDirectory)
                {
                    t = new qx.ui.treefullcontrol.TreeFolder(trs);
                }
                else
                {
                    t = new qx.ui.treefullcontrol.TreeFile(trs);
                }
                parent.add(t);
            }
        }

        /*
         * Reset the default of always showing the plus/minus symbol.  The
         * default is 'false'.  We want to always display it for each folder
         * (and then stop displaying it if we determine upon open that there
         * are no contents).
         */
        var constructor = qx.OO.classes["qx.ui.treefullcontrol.TreeFolder"];
        qx.Proto = constructor.prototype;
        qx.OO.changeProperty({
              name : "alwaysShowPlusMinusSymbol",
              type : qx.constant.Type.BOOLEAN,
              defaultValue : true });

        var rpc = new qx.io.remote.Rpc();
        rpc.setTimeout(10000);
        rpc.setUrl("/services/");
        rpc.setServiceName("qooxdoo.fs");
        rpc.setCrossDomain(false);

        var mycall = null;

        var trs = qx.ui.treefullcontrol.TreeRowStructure.getInstance().standard("Root");
        var t = new qx.ui.treefullcontrol.Tree(trs);

        with(t)
        {
            setBackgroundColor(255);
            setBorder(qx.renderer.border.BorderPresets.getInstance().inset);
            setOverflow("scrollY");

            setHeight(null);
            setTop(48);
            setLeft(20);
            setWidth(700);
            setBottom(48);

            setHideNode(true);          // hide the root node
            setUseTreeLines(true);      // display tree lines
        };

        /*
         * All subtrees will use this root node's event listeners.  Create an
         * event listener for an open while empty.
         */
        t.addEventListener(
            qx.constant.Event.TREEOPENWHILEEMPTY,
            function(e)
            {
                var parent = e.getData();
                var hierarchy = parent.getHierarchy(new Array());

                parent.debug("Requesting children...");

                // Strip off the root node
                hierarchy.shift();

                mycall = rpc.callAsync(
                    function(result, ex, id)
                    {
                        mycall = null;
                        if (ex == null) {
                            parent.debug("Children obtained.  Rendering...");
                            addChildren(parent, result);
                            parent.debug("Rendering complete.");
                        } else {
                            alert("Async(" + id + ") exception: " + ex);
                        }
                    },
                    "readDirEntries",
                    hierarchy,
                    true);
            });

        qx.ui.core.ClientDocument.getInstance().add(t);

        var trs = qx.ui.treefullcontrol.TreeRowStructure.getInstance().standard("Sandbox");
        var tf = new qx.ui.treefullcontrol.TreeFolder(trs);
        t.add(tf);
    });
/*
 * Local Variables:
 * mode: java
 * End:
 */
</script>

</body>
</html>