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

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

Seperated question browser in TabbedQuestionBrowser? widget.
Made configuring Selector actions more flexible (both for top actions and item actions).
Fixed lowercase/uppercase problem in SurveyListView?.
Fixed whitespace and toolyip in LineWithActionsWidget?.
Added question browser to questions page. Removed the old dialog that was there and redirect to questionEditor page.

File size: 6.6 KB
Line 
1define([
2    'dojo/_base/declare',
3    'dojo/_base/array',
4    'dijit/registry',
5    'dojo/_base/lang',
6    'dojo/_base/event',
7    'dojo/fx',
8    'dijit/_WidgetBase',
9    'dijit/_TemplatedMixin',
10    'dijit/_WidgetsInTemplateMixin',
11    'dijit/_Container',
12    './LineWithActionsWidget',
13    'dojo/text!./templates/Selector.html',
14    'dojo/dom-class',
15    ],function(
16        declare,
17        baseArray,
18        registry,
19        lang,
20        event,
21        fx,
22        _WidgetBase,
23        _TemplatedMixin,
24        _WidgetsInTemplateMixin,
25        _Container,
26        LineWithActionsWidget,
27        templateString,
28        domClass
29        ){
30        return declare('rft.ui.Selector',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
31            templateString: templateString,
32            baseClass: 'rftSelector',
33            modifiers: 'blue',
34
35            title: "",
36            selectedActions: null,
37            itemActions: null,
38            // main selector action: Object
39            //    title:
40            //    description:
41            //    icon:
42
43            _folded: true,
44            _titleLine: null,
45            _selectorLine: null,
46            _selectedItem: null,
47
48            startup: function() {
49                domClass.add(this.domNode, this.modifiers);
50                domClass.add(this.selectedColorNode, "pending");
51
52                this._createTitleLine();
53                this._createSelectorLine();
54
55                fx.wipeOut({
56                    node: this.optionsNode
57                }).play();
58            },
59            _createTitleLine: function() {
60                var actions = {};
61                var action = null;
62                if ( this.selectedActions !== null ) {
63                    for (var actionName in this.selectedActions) {
64                        action = this.selectedActions[actionName];
65                        actions[actionName] = {
66                            callback: action.callback &&
67                                    lang.hitch(this,this._onSelectedAction,
68                                            action.callback),
69                            properties: {
70                                 blockButton: true,
71                                 modifiers: this.modifiers,
72                                 label: action.title || actionName,
73                                 icon: action.icon,
74                                 tooltip: action.description
75                             }
76
77                        };
78                    }
79                }
80
81                this._titleLine = new LineWithActionsWidget({
82                    title: this.title,
83                    modifiers: this.modifiers,
84                    actions: actions
85                },this.titleNode);
86                this._titleLine.startup();
87            },
88            _createSelectorLine: function() {
89                this._selectorLine = new LineWithActionsWidget({
90                    title: 'None',
91                    modifiers: this.modifiers,
92                    actions: {
93                        "Toggle dropdown" : {
94                            callback: lang.hitch(this, this.onToggle),
95                            properties: {
96                                blockButton: true,
97                                modifiers: this.modifiers,
98                                showLabel: false,
99                                icon: "HalfArrowDown"
100                            }
101                        }
102                    }
103                },this.selectedItemNode);
104                this._selectorLine.startup();
105                this._selectorLine.on('click',lang.hitch(this, this.onToggle));
106            },
107            _onSelect: function(item, widget) {
108                this._selectedItem = item;
109                this.onToggle();
110                this._selectorLine.set("title", item.title);
111                baseArray.forEach(this.optionsNode.childNodes, function(node){
112                    var line = registry.byNode(node);
113                    if (line) {
114                        if (line === widget) {
115                            domClass.add(line.domNode, "inheritBgColor light");
116                        } else {
117                            domClass.remove(line.domNode, "inheritBgColor light");
118                        }
119                    }
120                }, this);
121                this.onSelect(item);
122            },
123            _onSelectedAction: function(callback) {
124                if (this._selectedItem && callback) {
125                    callback(this._selectedItem);
126                }
127            },
128
129            onToggle: function(evt) {
130                if (this._folded) {
131                    var downArrowIcon = dojo.query(".rftBlockButton .rftIconHalfArrowDown", this._selectorLine.buttonsNode)[0];
132                    if (downArrowIcon){
133                        domClass.replace(downArrowIcon, "rftIconHalfArrowUp", "rftIconHalfArrowDown");
134                    }
135                    fx.wipeIn({
136                        node: this.optionsNode
137                    }).play();
138                    this._folded = false;
139                } else {
140                    var upArrowIcon = dojo.query(".rftBlockButton .rftIconHalfArrowUp", this._selectorLine.buttonsNode)[0];
141                    if (upArrowIcon){
142                        domClass.replace(upArrowIcon, "rftIconHalfArrowDown", "rftIconHalfArrowUp");
143                    }
144                    fx.wipeOut({
145                        node: this.optionsNode
146                    }).play();
147                    this._folded = true;
148                }
149                evt && event.stop(evt);
150                return false;
151            },
152
153            addItem: function(item) {
154                var actions = {};
155                var action;
156                if (this.itemActions) {
157                    for (var actionName in this.itemActions) {
158                        action = this.itemActions[actionName];
159                        actions[actionName] = {
160                            callback: function(){action.callback && action.callback(item);},
161                            properties: {
162                                blockButton: false,
163                                showLabel: false,
164                                icon: action.icon,
165                                tooltip: action.description
166                            }
167                        }
168                    }
169                }
170                var w = new LineWithActionsWidget({
171                    title: item.title,
172                    actions: actions
173                }).placeAt(this.optionsNode);
174                w.startup();
175                w.on("click", lang.hitch(this, this._onSelect, item, w));
176            },
177
178            onSelect: function(item) {}
179        });
180});
Note: See TracBrowser for help on using the repository browser.