1 | define(['dojo/_base/declare','dojo/_base/lang','dojo/on','dojo/dom','dijit/form/Button', |
---|
2 | 'dijit/_WidgetBase','dijit/_TemplatedMixin','dijit/_WidgetsInTemplateMixin', |
---|
3 | 'dojo/text!./templates/LineWithActionsWidget.html'], |
---|
4 | function(declare,lang,on,dom,Button,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,templateString){ |
---|
5 | return declare('rft.ui.LineWithActionsWidget',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin],{ |
---|
6 | templateString: templateString, |
---|
7 | baseClass: 'rftLineWithButtons', |
---|
8 | title: '', |
---|
9 | userObject: null, |
---|
10 | actions: {}, |
---|
11 | postCreate: function() { |
---|
12 | dom.setSelectable(this.domNode, false); |
---|
13 | on(this.titleNode,'click',lang.hitch(this,'_onClick')); |
---|
14 | }, |
---|
15 | startup: function() { |
---|
16 | this.inherited(arguments); |
---|
17 | this._setupActions(); |
---|
18 | this.refresh(); |
---|
19 | }, |
---|
20 | _setupActions: function() { |
---|
21 | for (var action in this.actions) { |
---|
22 | new Button({ |
---|
23 | label: action, |
---|
24 | //iconClass: 'dijitIconSearch', |
---|
25 | //showLabel: false, |
---|
26 | onClick: lang.hitch(this,function(){ |
---|
27 | this.actions[action](this.userObject); |
---|
28 | }) |
---|
29 | }).placeAt(this.buttonsNode); |
---|
30 | } |
---|
31 | }, |
---|
32 | refresh: function() { |
---|
33 | this.titleNode.innerHTML = this.title; |
---|
34 | }, |
---|
35 | _onClick: function(e){ |
---|
36 | var preventDefault = this.onClick(e) === false; |
---|
37 | if(preventDefault){ |
---|
38 | e.preventDefault(); |
---|
39 | } |
---|
40 | return !preventDefault; |
---|
41 | }, |
---|
42 | onClick: function(e) {} |
---|
43 | }); |
---|
44 | }); |
---|