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

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

Added build infrastructure and reorganised code to match it.

Page navigation is now done by the rft/app/Controller class. pages
inherit generally from rft/app/Page, which is a BorderContainer?. The
Page uses normal widget mechanism like templateString, all data-rft-*
are obsolete, use normal data-dojo-* options again in templates.
This is done so the pages of the app can be included in the build.
URLs are linked to pages through registration, which is done in
run.js. The routes are defined in the routes.js file. Page class names
and URLs are now independent.

Reduced includes in index.html to one CSS file and two JS files. Dojo
stylesheets are now included thorugh externals.css.

Dojo 1.8 doesn't require the dotted names in declares anymore. All these
are now removed (redundant with module path and JS filename anyway)
and in templates a module id is used, so iso 'dijit.form.Form' use
'dijit/form/Form' now. This is more consistent with requires in the JS
code and they are picked up by the build system.

Removed any old-style dojo.<function> code and use loaded modules
everywhere.

Lots of whitespace unification.

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