source: Dev/branches/rest-dojo-ui/client/rft/ui/LineWithActionsWidget.js @ 405

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

Guarded widget startup() functions.

File size: 3.3 KB
Line 
1define(['dojo/_base/declare',
2        'dojo/_base/lang',
3        'dojo/on',
4        'dojo/dom',
5        'dojo/_base/event',
6        'dojo/dom-class',
7        'dijit/form/Button',
8        'dijit/_WidgetBase',
9        'dijit/_TemplatedMixin',
10        'dijit/_WidgetsInTemplateMixin',
11        'dojo/text!./templates/LineWithActionsWidget.html'
12        ],
13        function(declare,lang,on,dom,event,domClass,Button,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,templateString){
14                return declare('rft.ui.LineWithActionsWidget',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin],{
15                        templateString: templateString,
16                        baseClass: 'rftLineWithButtons',
17                        title: '',
18                        selectable: false,
19                        userObject: null,
20
21                        actions: null,
22                        postCreate: function() {
23                                dom.setSelectable(this.domNode, false); // Text selection, has nothing to do with object selection!
24                                on(this.domNode,'click',lang.hitch(this,'_onClick'));
25                        },
26                        startup: function() {
27                if ( this._started ){ return; }
28                                this.inherited(arguments);
29                                this._setupActions();
30                                domClass.add(this.domNode, "inheritBgColor bg");
31                                this.refresh();
32                        },
33                        _setupActions: function() {
34                if ( this.actions === null ) {
35                    return;
36                }
37                                for (var action in this.actions) {
38                                        var properties;
39                                        if (this.actions[action].properties.blockButton == true) {
40                                                properties = lang.mixin({
41                                                        baseClass: 'rftBlockButton',
42                            "class": "inheritBgColor light",
43                                                        label: "Default",
44                                                        iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon,
45                                                        title: this.actions[action].properties.tooltip,
46                            onClick: lang.hitch(this, function(action, e){
47                                action.callback && action.callback(e);
48                                event.stop(e);
49                                return false;
50                            }, this.actions[action])
51                                                }, this.actions[action].properties);
52                        new Button(properties).placeAt(this.buttonsNode);
53                    } else {
54                        properties = lang.mixin({
55                            baseClass: 'rftInlineButton',
56                            label: "Default",
57                            showLabel: false,
58                            iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon,
59                            title: this.actions[action].properties.tooltip,
60                            onClick: lang.hitch(this, function(action, e){
61                                action.callback && action.callback(e);
62                                event.stop(e);
63                                return false;
64                            }, this.actions[action])
65                        }, this.actions[action].properties);
66                        new Button(properties).placeAt(this.buttonsNode);
67                    }
68                }
69            },
70            refresh: function() {
71                this.titleNode.innerHTML = this.title;
72            },
73            _onClick: function(e){
74                var preventDefault = this.onClick(e) === false;
75                if (preventDefault) {
76                    event.stop(e);
77                }
78                return !preventDefault;
79            },
80            onClick: function(e) {
81            },
82            _setTitleAttr: function(value){
83                this.title = value;
84                this.refresh();
85            }
86        });
87    });
Note: See TracBrowser for help on using the repository browser.