source: Dev/branches/rest-dojo-ui/client/dojo/dnd/Avatar.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 3.2 KB
Line 
1define(["../main", "./common"], function(dojo) {
2        // module:
3        //              dojo/dnd/Avatar
4        // summary:
5        //              TODOC
6
7
8dojo.declare("dojo.dnd.Avatar", null, {
9        // summary:
10        //              Object that represents transferred DnD items visually
11        // manager: Object
12        //              a DnD manager object
13
14        constructor: function(manager){
15                this.manager = manager;
16                this.construct();
17        },
18
19        // methods
20        construct: function(){
21                // summary:
22                //              constructor function;
23                //              it is separate so it can be (dynamically) overwritten in case of need
24                this.isA11y = dojo.hasClass(dojo.body(),"dijit_a11y");
25                var a = dojo.create("table", {
26                                "class": "dojoDndAvatar",
27                                style: {
28                                        position: "absolute",
29                                        zIndex:   "1999",
30                                        margin:   "0px"
31                                }
32                        }),
33                        source = this.manager.source, node,
34                        b = dojo.create("tbody", null, a),
35                        tr = dojo.create("tr", null, b),
36                        td = dojo.create("td", null, tr),
37                        icon = this.isA11y ? dojo.create("span", {
38                                                id : "a11yIcon",
39                                                innerHTML : this.manager.copy ? '+' : "<"
40                                        }, td) : null,
41                        span = dojo.create("span", {
42                                innerHTML: source.generateText ? this._generateText() : ""
43                        }, td),
44                        k = Math.min(5, this.manager.nodes.length), i = 0;
45                // we have to set the opacity on IE only after the node is live
46                dojo.attr(tr, {
47                        "class": "dojoDndAvatarHeader",
48                        style: {opacity: 0.9}
49                });
50                for(; i < k; ++i){
51                        if(source.creator){
52                                // create an avatar representation of the node
53                                node = source._normalizedCreator(source.getItem(this.manager.nodes[i].id).data, "avatar").node;
54                        }else{
55                                // or just clone the node and hope it works
56                                node = this.manager.nodes[i].cloneNode(true);
57                                if(node.tagName.toLowerCase() == "tr"){
58                                        // insert extra table nodes
59                                        var table = dojo.create("table"),
60                                                tbody = dojo.create("tbody", null, table);
61                                        tbody.appendChild(node);
62                                        node = table;
63                                }
64                        }
65                        node.id = "";
66                        tr = dojo.create("tr", null, b);
67                        td = dojo.create("td", null, tr);
68                        td.appendChild(node);
69                        dojo.attr(tr, {
70                                "class": "dojoDndAvatarItem",
71                                style: {opacity: (9 - i) / 10}
72                        });
73                }
74                this.node = a;
75        },
76        destroy: function(){
77                // summary:
78                //              destructor for the avatar; called to remove all references so it can be garbage-collected
79                dojo.destroy(this.node);
80                this.node = false;
81        },
82        update: function(){
83                // summary:
84                //              updates the avatar to reflect the current DnD state
85                dojo[(this.manager.canDropFlag ? "add" : "remove") + "Class"](this.node, "dojoDndAvatarCanDrop");
86                if (this.isA11y){
87                        var icon = dojo.byId("a11yIcon");
88                        var text = '+';   // assume canDrop && copy
89                        if (this.manager.canDropFlag && !this.manager.copy) {
90                                text = '< '; // canDrop && move
91                        }else if (!this.manager.canDropFlag && !this.manager.copy) {
92                                text = "o"; //!canDrop && move
93                        }else if(!this.manager.canDropFlag){
94                                text = 'x';  // !canDrop && copy
95                        }
96                        icon.innerHTML=text;
97                }
98                // replace text
99                dojo.query(("tr.dojoDndAvatarHeader td span" +(this.isA11y ? " span" : "")), this.node).forEach(
100                        function(node){
101                                node.innerHTML = this._generateText();
102                        }, this);
103        },
104        _generateText: function(){
105                // summary: generates a proper text to reflect copying or moving of items
106                return this.manager.nodes.length.toString();
107        }
108});
109
110return dojo.dnd.Avatar;
111});
Note: See TracBrowser for help on using the repository browser.