aboutsummaryrefslogtreecommitdiff
path: root/js/components/treeview/ninja-leaf.reel/ninja-leaf.js
diff options
context:
space:
mode:
authorEric Guzman2012-02-13 10:30:44 -0800
committerEric Guzman2012-02-13 10:30:44 -0800
commite46ab1a8e19f66de6eca68225d9e8b4cba8f90e8 (patch)
tree8904c82119819bfe4b6698ad40cbc33c903bcf12 /js/components/treeview/ninja-leaf.reel/ninja-leaf.js
parent672e6f61647b1b8a5f6f5831284fa44bcb7be883 (diff)
parente4893f7d3c3b9bd7967973197c3ffb5d3a075c91 (diff)
downloadninja-e46ab1a8e19f66de6eca68225d9e8b4cba8f90e8.tar.gz
Merge branch 'refs/heads/TreeComponents' into PresetsPanel
Diffstat (limited to 'js/components/treeview/ninja-leaf.reel/ninja-leaf.js')
-rw-r--r--js/components/treeview/ninja-leaf.reel/ninja-leaf.js43
1 files changed, 36 insertions, 7 deletions
diff --git a/js/components/treeview/ninja-leaf.reel/ninja-leaf.js b/js/components/treeview/ninja-leaf.reel/ninja-leaf.js
index bd566b26..749df3cd 100644
--- a/js/components/treeview/ninja-leaf.reel/ninja-leaf.js
+++ b/js/components/treeview/ninja-leaf.reel/ninja-leaf.js
@@ -5,7 +5,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
5</copyright> */ 5</copyright> */
6 6
7var Montage = require("montage/core/core").Montage, 7var Montage = require("montage/core/core").Montage,
8 Component = require("montage/ui/component").Component;
9 TreeNode = require("js/components/treeview/tree-node").TreeNode; 8 TreeNode = require("js/components/treeview/tree-node").TreeNode;
10 9
11exports.Leaf = Montage.create(TreeNode, { 10exports.Leaf = Montage.create(TreeNode, {
@@ -14,19 +13,39 @@ exports.Leaf = Montage.create(TreeNode, {
14 }, 13 },
15 templateDidLoad : { 14 templateDidLoad : {
16 value: function() { 15 value: function() {
17 this.needsDraw = true; 16 var event = this.treeView.activationEvent;
17
18 ///// Re-set the activation event
19 if(event && event !== this.activationEvent) {
20 this.delegateEventMap[event] = this.delegateEventMap[this.activationEvent];
21 delete this.delegateEventMap[this.activationEvent];
22 this.activationEvent = this.treeView.activationEvent;
23 }
18 } 24 }
19 }, 25 },
20 prepareForDraw: { 26 prepareForDraw: {
21 value : function() { 27 value : function() {
22 this.activationEvent = this.activationEvent || 'click'; 28 var el = this.label._element;
23 this.label._element.addEventListener(this.activationEvent, this.handleNodeActivation.bind(this), false); 29
30 Object.keys(this.delegateEventMap).forEach(function(event) {
31 el.addEventListener(event, this, false);
32 }, this);
33
24 } 34 }
25 }, 35 },
26 handleNodeActivation: { 36 handleEvent : {
27 value: function(e) { 37 value: function(e) {
28 console.log(this.sourceObject); 38 var delegateMethod = this.delegateEventMap[e._event.type];
29 this.treeView.contentController.delegate.applyPresetSelection(this.sourceObject); 39 this.callDelegateMethod(delegateMethod);
40 }
41 },
42 callDelegateMethod : {
43 value: function(methodName) {
44 console.log("Delegate method name: ", methodName);
45 var delegate = this.treeView.contentController.delegate;
46 if(delegate && typeof delegate[methodName] === 'function') {
47 delegate[methodName](this.sourceObject);
48 }
30 } 49 }
31 }, 50 },
32 draw : { 51 draw : {
@@ -35,6 +54,16 @@ exports.Leaf = Montage.create(TreeNode, {
35 this._labelText = this.sourceObject[this.labelKey]; 54 this._labelText = this.sourceObject[this.labelKey];
36 } 55 }
37 } 56 }
57 },
58 activationEvent : {
59 value : 'click'
60 },
61 delegateEventMap : {
62 value: {
63 'click' : 'handleNodeActivation',
64 'dragstart' : 'handleDragStart',
65 'dragend' : 'handleDragEnd'
66 }
38 } 67 }
39 68
40 69