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

Last change on this file since 356 was 356, checked in by tjcschipper, 13 years ago
File size: 2.7 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                        modifiers: "blue",
19                        selectable: false,
20                        userObject: null,
21
22                        actions: {},
23                        postCreate: function() {
24                                dom.setSelectable(this.domNode, false); // Text selection, has nothing to do with object selection!
25                                on(this.domNode,'click',lang.hitch(this,'_onClick'));
26                        },
27                        startup: function() {
28                                this.inherited(arguments);
29                                this._setupActions();
30                                domClass.add(this.domNode, this.modifiers);
31                                this.refresh();
32                        },
33                        _setupActions: function() {
34                                for (var action in this.actions) {
35                                        var properties;
36                                        if (this.actions[action].properties.blockButton == true) {
37                                                properties = lang.mixin({
38                                                        baseClass: 'rftBlockButton',
39                                                        modifiers: this.modifiers,
40                                                        label: "Default",
41                                                        iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon,
42                                                        title: action,
43                                                        onClick: lang.hitch(this, dojo.partial(function(ac, e){
44                                                                lang.hitch(this, this.actions[ac].callback )(e);
45                                                                event.stop(e);
46                                                                return false;
47                                                        }, action))
48                                                }, this.actions[action].properties);
49                                                        properties["class"] = properties.modifiers;
50                                                        new Button(properties).placeAt(this.buttonsNode);
51                                                } else {
52                                                        properties = lang.mixin({
53                                                                baseClass: 'rftInlineButton',
54                                                                modifiers: 'black',
55                                                                label: "Default",
56                                                                showLabel: false,
57                                                                iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon,
58                                                                title: action,
59                                                                onClick: lang.hitch(this, dojo.partial(function(ac, e){
60                                                                        lang.hitch(this, this.actions[ac].callback)(e);
61                                                                        event.stop(e);
62                                                                        return false;
63                                                                }, action))
64                                                        }, this.actions[action].properties);
65                                                        properties["class"] = properties.modifiers;
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.