1 | define(['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: 'rftLineWithButtons', |
---|
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 | domClass.add(this.domNode, "inheritBgColor bg"); |
---|
30 | this.refresh(); |
---|
31 | }, |
---|
32 | _setupActions: function() { |
---|
33 | if ( this.actions === null ) { |
---|
34 | return; |
---|
35 | } |
---|
36 | for (var action in this.actions) { |
---|
37 | var properties; |
---|
38 | if (this.actions[action].properties.blockButton === true) { |
---|
39 | properties = lang.mixin({ |
---|
40 | baseClass: 'rftBlockButton', |
---|
41 | "class": "inheritBgColor light", |
---|
42 | label: "Default", |
---|
43 | iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon, |
---|
44 | title: this.actions[action].properties.tooltip, |
---|
45 | onClick: lang.hitch(this, function(action, e){ |
---|
46 | action.callback && action.callback(e); |
---|
47 | event.stop(e); |
---|
48 | return false; |
---|
49 | }, this.actions[action]) |
---|
50 | }, this.actions[action].properties); |
---|
51 | new Button(properties).placeAt(this.buttonsNode); |
---|
52 | } else { |
---|
53 | properties = lang.mixin({ |
---|
54 | baseClass: 'rftInlineButton', |
---|
55 | label: "Default", |
---|
56 | showLabel: false, |
---|
57 | iconClass: 'rftIcon rftIcon'+this.actions[action].properties.icon, |
---|
58 | title: this.actions[action].properties.tooltip, |
---|
59 | onClick: lang.hitch(this, function(action, e){ |
---|
60 | action.callback && action.callback(e); |
---|
61 | event.stop(e); |
---|
62 | return false; |
---|
63 | }, this.actions[action]) |
---|
64 | }, this.actions[action].properties); |
---|
65 | new Button(properties).placeAt(this.buttonsNode); |
---|
66 | } |
---|
67 | } |
---|
68 | }, |
---|
69 | refresh: function() { |
---|
70 | this.titleNode.innerHTML = this.title; |
---|
71 | }, |
---|
72 | _onClick: function(e){ |
---|
73 | var preventDefault = this.onClick(e) === false; |
---|
74 | if (preventDefault) { |
---|
75 | event.stop(e); |
---|
76 | } |
---|
77 | return !preventDefault; |
---|
78 | }, |
---|
79 | onClick: function(e) { |
---|
80 | }, |
---|
81 | _setTitleAttr: function(value){ |
---|
82 | this.title = value; |
---|
83 | this.refresh(); |
---|
84 | } |
---|
85 | }); |
---|
86 | }); |
---|