source: Dev/branches/rest-dojo-ui/client/rft/ui/Selector.js @ 358

Last change on this file since 358 was 358, checked in by tjcschipper, 13 years ago

Omgevingsbewustzijnde schalingsfunctie

File size: 6.4 KB
Line 
1define([
2    'dojo/_base/declare',
3    'dojo/_base/array',
4    'dijit/registry',
5    'dojo/_base/lang',
6    'dojo/fx',
7    'dijit/_WidgetBase',
8    'dijit/_TemplatedMixin',
9    'dijit/_WidgetsInTemplateMixin',
10    'dijit/_Container',
11    './LineWithActionsWidget',
12    'dojo/text!./templates/Selector.html',
13    'dojo/dom-class'
14    ],function(
15        declare,
16        baseArray,
17        registry,
18        lang,
19        fx,
20        _WidgetBase,
21        _TemplatedMixin,
22        _WidgetsInTemplateMixin,
23        _Container,
24        LineWithActionsWidget,
25        templateString,
26        domClass
27        ){
28        return declare('rft.ui.Selector',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
29            templateString: templateString,
30            title: "ERROR: NULL_TOPIC",
31            baseClass: 'rftSelector',
32            modifiers: 'blue',
33            currentlySelectedId: null,
34            controller: null,   // Use events/pubsub instead of a controller variable? Decoupling!
35
36            postCreate: function() {
37                domClass.add(this.domNode, this.modifiers);
38                domClass.add(this.selectedColorNode, "pending");
39                this.domNode.dataset["topic"] = this.topic;
40
41                new LineWithActionsWidget({
42                    title: this.topic,
43                    modifiers: this.modifiers,
44                    actions: {
45                        "AddToSurvey" : {
46                            callback: lang.hitch(this, this.includeQuestion),
47                            properties: {
48                                blockButton: true,
49                                modifiers: this.modifiers,
50                                icon: "Accept",
51                                label: "Include"
52                            }
53                        }
54                    }
55                },this.titleNode);
56
57                this.selectorLine = new LineWithActionsWidget({
58                    title: 'None',
59                    modifiers: this.modifiers,
60                    actions: {
61                        "ToggleDropdown" : {
62                            callback: lang.hitch(this, this._toggleDropdown()),
63                            properties: {
64                                blockButton: true,
65                                modifiers: this.modifiers,
66                                showLabel: false,
67                                icon: "HalfArrowDown"
68                            }
69                        }
70                    }
71                },this.selectedItemNode);
72            },
73            _toggleDropdown: function() {
74                var node = this.optionsNode;
75                var show = fx.wipeIn({
76                    node: node
77                });
78                var hide = fx.wipeOut({
79                    node: node
80                });
81                hide.play();
82                var folded = true;
83                return function(e) {
84                    if ( folded ) {
85                        var downArrowIcon = dojo.query(".rftBlockButton .rftIconHalfArrowDown", this.selectorLine.buttonsNode)[0];
86                        if (downArrowIcon){
87                            domClass.replace(downArrowIcon, "rftIconHalfArrowUp", "rftIconHalfArrowDown");
88                        }
89                        show.play();
90                        folded = false;
91                    } else {
92                        var upArrowIcon = dojo.query(".rftBlockButton .rftIconHalfArrowUp", this.selectorLine.buttonsNode)[0];
93                        if (upArrowIcon){
94                            domClass.replace(upArrowIcon, "rftIconHalfArrowDown", "rftIconHalfArrowUp");
95                        }
96                        hide.play();
97                        folded = true;
98
99                    }
100                    e.preventDefault();
101                    e.stopPropagation();
102                };
103            },
104            addQuestion: function(questionId) {
105                var question = this.controller.getQuestion(questionId);
106                if (question) {
107                    var w = new LineWithActionsWidget({
108                        title: question.title,
109                        questionId: questionId,
110                        actions: {
111                            "InfoHover" : {
112                                callback: dojo.partial(this.infoFunction, this),
113                                properties: {
114                                    blockButton: false,
115                                    showLabel: false,
116                                    icon: "Inspect"
117                                }
118                            }
119                        }
120                    });
121                    w.placeAt(this.optionsNode);
122                    w.on("click", lang.hitch(this, function(){
123                        this.selectQuestion(questionId);
124                        this._toggleDropdown();
125                    }, questionId));
126
127                }   
128            },
129            infoFunction: function(selector) {
130                var question = selector.controller.getQuestion(this.questionId);
131                console.log(question);
132                alert("Some info here!");
133            },
134            includeQuestion: function() {
135                if (this.currentlySelectedId) {
136                    this.controller.IncludeQuestion(this.currentlySelectedId)
137                } else {
138                    return false;
139                }
140            },
141            selectQuestion: function(questionId) {
142                /* TODO: TEST THOROUGHLY! */
143                var question = this.controller.getQuestion(questionId);
144                if (question) {
145                    this.currentlySelectedId = questionId;
146                    this.selectorLine.questionId = questionId;
147                    this.selectorLine.set("title", question.title);
148                    // Iterate through optionsNode, add "selected" class to currently selected node
149                    baseArray.forEach(this.optionsNode.childNodes, function(node, index){
150                        var line = registry.byNode(node);
151                        if (line) {
152                            if (line.questionId == this.currentlySelectedId) {
153                                domClass.add(line.domNode, "inheritBgColor light");
154                            } else {
155                                domClass.remove(line.domNode, "inheritBgColor light");
156                            }
157                        }
158                    }, this);
159                }
160            }
161        });
162});
Note: See TracBrowser for help on using the repository browser.