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

Last change on this file since 411 was 411, checked in by tjcschipper, 13 years ago
  • LESS is finally ready for use. Some small visual bugs remain.
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],function(declare,lang,on,dom,event,domClass,Button,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,templateString){
13    return declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin],{
14        templateString: templateString,
15        baseClass: 'rftLineWithActions',
16        title: '',
17        selectable: false,
18        userObject: null,
19
20        actions: null,
21        postCreate: function() {
22            dom.setSelectable(this.domNode, false); // Text selection, has nothing to do with object selection!
23            on(this.domNode,'click',lang.hitch(this,'_onClick'));
24        },
25        startup: function() {
26            if ( this._started ){ return; }
27            this.inherited(arguments);
28            this._setupActions();
29            this.refresh();
30        },
31        _setupActions: function() {
32            if ( this.actions === null ) {
33                return;
34            }
35            for (var action in this.actions) {
36                var properties;
37                if (this.actions[action].properties.blockButton === true) {
38                    properties = lang.mixin({
39                        baseClass: 'rftBlockButton',
40                        label: "Default",
41                        iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon,
42                        title: this.actions[action].properties.tooltip,
43                        onClick: lang.hitch(this, function(action, e){
44                            action.callback && action.callback(e);
45                            event.stop(e);
46                            return false;
47                        }, this.actions[action])
48                    }, this.actions[action].properties);
49                    new Button(properties).placeAt(this.buttonsNode);
50                } else {
51                    properties = lang.mixin({
52                        baseClass: 'rftInlineButton',
53                        label: "Default",
54                        showLabel: false,
55                        iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon,
56                        title: this.actions[action].properties.tooltip,
57                        onClick: lang.hitch(this, function(action, e){
58                            action.callback && action.callback(e);
59                            event.stop(e);
60                            return false;
61                        }, this.actions[action])
62                    }, this.actions[action].properties);
63                    new Button(properties).placeAt(this.buttonsNode);
64                }
65            }
66        },
67        refresh: function() {
68            this.titleNode.innerHTML = this.title;
69        },
70        _onClick: function(e){
71            var preventDefault = this.onClick(e) === false;
72            if (preventDefault) {
73                event.stop(e);
74            }
75            return !preventDefault;
76        },
77        onClick: function(e) {
78        },
79        _setTitleAttr: function(value){
80            this.title = value;
81            this.refresh();
82        }
83    });
84});
Note: See TracBrowser for help on using the repository browser.