aboutsummaryrefslogtreecommitdiff
path: root/js/components/treeview/ninja-leaf.reel/ninja-leaf.js
blob: c6416693cf21f35a731ae95c8da89a6526e261e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* <copyright>
This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
(c) Copyright 2011 Motorola Mobility, Inc.  All Rights Reserved.
</copyright> */

var Montage   = require("montage/core/core").Montage,
    TreeNode = require("js/components/treeview/tree-node").TreeNode;

exports.Leaf = Montage.create(TreeNode, {
    hasTemplate: {
        value: true
    },
    templateDidLoad : {
        value: function() {
            var event = this.treeView.activationEvent;

            ///// Re-set the activation event
            if(event && event !== this.activationEvent) {
                this.delegateEventMap[event] = this.delegateEventMap[this.activationEvent];
                delete this.delegateEventMap[this.activationEvent];
                this.activationEvent = this.treeView.activationEvent;
            }
        }
    },
    prepareForDraw: {
        value : function() {
            var el = this.label._element;

            Object.keys(this.delegateEventMap).forEach(function(event) {
                el.addEventListener(event, this, false);
            }, this);

        }
    },
    handleEvent : {
        value: function(e) {
            var delegateMethod = this.delegateEventMap[e._event.type];
            this.callDelegateMethod(delegateMethod, e);
        }
    },
    callDelegateMethod : {
        value: function(methodName, evt) {
            var delegate = this.treeView.contentController.delegate;
            if(delegate && typeof delegate[methodName] === 'function') {
                delegate[methodName](this.sourceObject, evt);
            }
        }
    },
    draw : {
        value : function() {
            if(this.sourceObject[this.labelKey]) {
                this._labelText = this.sourceObject[this.labelKey];
            }
        }
    },
    activationEvent : {
        value : 'click'
    },
    delegateEventMap : {
        value: {
            'click'     : 'handleNodeActivation',
            'dblclick'  : 'handleDblclick',
            'dragstart' : 'handleDragStart',
            'dragend'   : 'handleDragEnd'
        }
    }


});