[510] | 1 | define([ |
---|
| 2 | "../lib/object", |
---|
| 3 | "dijit/_TemplatedMixin", |
---|
| 4 | "dijit/_WidgetBase", |
---|
| 5 | "dijit/_WidgetsInTemplateMixin", |
---|
| 6 | "dijit/form/Button", |
---|
| 7 | "dojo/_base/declare", |
---|
| 8 | "dojo/_base/event", |
---|
| 9 | "dojo/_base/lang", |
---|
| 10 | "dojo/dom", |
---|
| 11 | "dojo/dom-class", |
---|
| 12 | "dojo/on", |
---|
| 13 | "dojo/text!./templates/LineWithActionsWidget.html" |
---|
| 14 | ], function(objectFuns, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, Button, declare, event, lang, dom, domClass, on, templateString) { |
---|
[443] | 15 | return declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin],{ |
---|
| 16 | templateString: templateString, |
---|
| 17 | baseClass: 'rftLineWithActions', |
---|
| 18 | title: '', |
---|
| 19 | selectable: false, |
---|
| 20 | userObject: null, |
---|
| 21 | |
---|
| 22 | actions: null, |
---|
| 23 | postCreate: function() { |
---|
| 24 | dom.setSelectable(this.domNode, false); // Text selection, has nothing to do with object selection! |
---|
[494] | 25 | this.own(on(this.domNode,'click',lang.hitch(this,'_onClick'))); |
---|
[443] | 26 | }, |
---|
| 27 | startup: function() { |
---|
| 28 | if ( this._started ){ return; } |
---|
| 29 | this.inherited(arguments); |
---|
| 30 | this._setupActions(); |
---|
| 31 | this.refresh(); |
---|
| 32 | }, |
---|
| 33 | _setupActions: function() { |
---|
| 34 | if ( this.actions === null ) { |
---|
| 35 | return; |
---|
| 36 | } |
---|
[510] | 37 | objectFuns.forEach(this.actions, function(value,action){ |
---|
| 38 | var properties; |
---|
| 39 | if (value.properties.blockButton === true) { |
---|
| 40 | properties = lang.mixin({ |
---|
| 41 | baseClass: 'rftBlockButton', |
---|
| 42 | label: "Default", |
---|
| 43 | iconClass: 'rftIcon rftIcon'+value.properties.icon, |
---|
| 44 | title: value.properties.tooltip, |
---|
| 45 | onClick: lang.hitch(this, function(action, e){ |
---|
| 46 | if ( action.callback ) { action.callback(e); } |
---|
| 47 | if ( e ) { event.stop(e); } |
---|
| 48 | return false; |
---|
| 49 | }, value) |
---|
| 50 | }, value.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'+value.properties.icon, |
---|
| 58 | title: value.properties.tooltip, |
---|
| 59 | onClick: lang.hitch(this, function(action, e){ |
---|
| 60 | if ( action.callback ) { action.callback(e); } |
---|
| 61 | if ( e ) { event.stop(e); } |
---|
| 62 | return false; |
---|
| 63 | }, value) |
---|
| 64 | }, value.properties); |
---|
| 65 | new Button(properties).placeAt(this.buttonsNode); |
---|
[443] | 66 | } |
---|
[510] | 67 | },this); |
---|
[443] | 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) { |
---|
[490] | 75 | if ( e ) { event.stop(e); } |
---|
[443] | 76 | } |
---|
| 77 | return !preventDefault; |
---|
| 78 | }, |
---|
| 79 | onClick: function(/*e*/) { |
---|
| 80 | }, |
---|
| 81 | _setTitleAttr: function(value){ |
---|
| 82 | this.title = value; |
---|
| 83 | this.refresh(); |
---|
| 84 | } |
---|
| 85 | }); |
---|
| 86 | }); |
---|