[355] | 1 | define(['dojo/_base/declare', |
---|
[406] | 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){ |
---|
[407] | 13 | return declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin],{ |
---|
[406] | 14 | templateString: templateString, |
---|
[411] | 15 | baseClass: 'rftLineWithActions', |
---|
[406] | 16 | title: '', |
---|
| 17 | selectable: false, |
---|
| 18 | userObject: null, |
---|
[355] | 19 | |
---|
[406] | 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){ |
---|
[426] | 44 | if ( action.callback ) { action.callback(e); } |
---|
[406] | 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){ |
---|
[426] | 58 | if ( action.callback ) { action.callback(e); } |
---|
[406] | 59 | event.stop(e); |
---|
| 60 | return false; |
---|
| 61 | }, this.actions[action]) |
---|
| 62 | }, this.actions[action].properties); |
---|
| 63 | new Button(properties).placeAt(this.buttonsNode); |
---|
[402] | 64 | } |
---|
[370] | 65 | } |
---|
[406] | 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 | }, |
---|
[426] | 77 | onClick: function(/*e*/) { |
---|
[406] | 78 | }, |
---|
| 79 | _setTitleAttr: function(value){ |
---|
| 80 | this.title = value; |
---|
| 81 | this.refresh(); |
---|
| 82 | } |
---|
[370] | 83 | }); |
---|
[406] | 84 | }); |
---|