1 | define(['dojo/_base/declare','dojo/_base/lang','dojo/on','dojo/dom', 'dojo/dom-class', 'dijit/form/Button', |
---|
2 | 'dijit/_WidgetBase','dijit/_TemplatedMixin','dijit/_WidgetsInTemplateMixin', |
---|
3 | 'dojo/text!./templates/LineWithActionsWidget.html' |
---|
4 | ], |
---|
5 | function(declare,lang,on,dom,domClass,Button,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,templateString){ |
---|
6 | return declare('rft.ui.LineWithActionsWidgetThijs',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin],{ |
---|
7 | templateString: templateString, |
---|
8 | baseClass: 'rftLineWithButtons', |
---|
9 | title: '', |
---|
10 | modifiers: "blue", |
---|
11 | userObject: null, |
---|
12 | actions: {}, |
---|
13 | postCreate: function() { |
---|
14 | dom.setSelectable(this.domNode, false); |
---|
15 | on(this.titleNode,'click',lang.hitch(this,'_onClick')); |
---|
16 | }, |
---|
17 | startup: function() { |
---|
18 | this.inherited(arguments); |
---|
19 | this._setupActions(); |
---|
20 | domClass.add(this.domNode, this.modifiers); |
---|
21 | this.refresh(); |
---|
22 | }, |
---|
23 | _setupActions: function() { |
---|
24 | for (var action in this.actions) { |
---|
25 | |
---|
26 | if (this.actions[action].properties.blockButton == true) { // BlockButton |
---|
27 | var properties = lang.mixin({ |
---|
28 | baseClass: 'rftBlockButton', |
---|
29 | modifiers: this.modifiers, |
---|
30 | label: action, |
---|
31 | iconClass: 'rftIcon rftIcon'+action, |
---|
32 | title: action, |
---|
33 | onClick: lang.hitch(this, function(){ |
---|
34 | this.actions[action].callback(this.userObject); |
---|
35 | }) |
---|
36 | }, |
---|
37 | this.actions[action].properties); |
---|
38 | properties["class"] = properties.modifiers; |
---|
39 | new Button(properties).placeAt(this.buttonsNode); |
---|
40 | } else { //InlineButton |
---|
41 | var properties = lang.mixin({ |
---|
42 | baseClass: 'rftInlineButton', |
---|
43 | modifiers: 'black', |
---|
44 | showLabel: false, |
---|
45 | iconClass: 'rftIcon rftIcon'+action, |
---|
46 | title: action, |
---|
47 | onClick: lang.hitch(this, function(){ |
---|
48 | this.actions[action].callback(this.userObject); |
---|
49 | }) |
---|
50 | }, |
---|
51 | this.actions[action].properties); |
---|
52 | properties["class"] = properties.modifiers; |
---|
53 | new Button(properties).placeAt(this.buttonsNode); |
---|
54 | } |
---|
55 | } |
---|
56 | }, |
---|
57 | refresh: function() { |
---|
58 | this.titleNode.innerHTML = this.title; |
---|
59 | }, |
---|
60 | _onClick: function(e){ |
---|
61 | var preventDefault = this.onClick(e) === false; |
---|
62 | if(preventDefault){ |
---|
63 | e.preventDefault(); |
---|
64 | } |
---|
65 | return !preventDefault; |
---|
66 | }, |
---|
67 | onClick: function(e) {} |
---|
68 | }); |
---|
69 | }); |
---|