aboutsummaryrefslogtreecommitdiff
path: root/js/panels/Panel.reel/Panel.js
blob: efa287c513c6f9cb552ae05bde0d4186d44122ea (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/* <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;
var Component = require("montage/ui/component").Component;

exports.Panel = Montage.create(Component, {


    reelDidLoad: {
       value: function() {
       }
    },

    collapsedHeight: {
        value:26
    },

    _isFirstDraw: {
        value:false
    },

    _panelBase: {
       value: null
    },

    panelBase: {
       get: function()
        {
            return this._panelBase;
        },
        set: function(value)
        {
            this._panelBase = value;
            this.needsDraw = true;
        }
    },

    _panelContent: {
        value: null
    },

    panelContent: {
        get: function()
        {
            return this._panelContent;
        },
        set: function(value)
        {
            if (this._panelContent === value) {
                return;
            }
            this._panelContent = value;
            this.needsDraw = true;
        }
    },

    collapseToggle: {
        value: function() {
            if (this.panelBase.forcedCollapse) {
                this.panelBase.forcedCollapse = false;
                this.panelBase.collapsed = false;
                this.needsDraw = true;

            } else {
                this.panelBase.collapsed = !this.panelBase.collapsed;
                this.needsDraw = true;
            }
            NJevent("panelCollapsed", this);
        }
},

    closePanel: {
        value: function() {
            NJevent("panelClose", this);
        }
    },

    handleMouseover: {
        value: function() {
            this.element.draggable = true;
        }
    },

    handleMouseout: {
        value: function() {
            this.element.draggable = false;
        }
    },

    _resizer: {
        value: null
    },

    resizer: {
        get: function() {
            return this._resizer;
        },
        set: function(val) {
            this._resizer = val;
        }
    },


    resized: {
        value: function() {
            this.panelBase.contentHeight = parseInt(this.element.style.height);
            this.needsDraw = true;
        }
    },

    //TODO: Find out why without This following function drop event wont fire ???
    handleEvent: {
        value:function(e) {
            e.preventDefault();
            e.stopImmediatePropagation();

        }
    },

    captureDragover: {
        value:function(e) {
            e.preventDefault();
            e.stopImmediatePropagation();
            this.element.style.backgroundColor = "#917B56";
        }
    },

    captureDragleave: {
        value: function() {
            this.element.style.backgroundColor = "";
        }
    },

    handleDrop: {
        value:function(e) {
            e.stopPropagation(); // Stops some browsers from redirecting.
            e.preventDefault();
            this.element.style.backgroundColor = "";
            NJevent("panelOrderChanged", this);
        }
    },

    handleDragstart: {
        value:function(e) {
            e.dataTransfer.effectAllowed = 'move';
            e.dataTransfer.setData('text/html', this.element.innerHTML);
            NJevent("panelSelected", this);
        }
    },

    handleDragEnter: {
        value: function(e) {
            this.element.classList.add("over");
        }
    },

    handleDragend: {
        value:function() {

        }
    },


    prepareForDraw: {
        value:function() {
            if (!this._isFirstDraw) {
                this._isFirstDraw = true;

                // Initialize Panel
                // Drag Drop Functions
                this.element.addEventListener("drop", this, false);
                this.element.addEventListener("dragover", this, true);
                this.element.addEventListener("dragleave", this, true);
                this.element.addEventListener("dragenter", this, false);
                this.element.addEventListener("dragstart", this, false);
                
                // Handle Functionality
                this.element.getElementsByClassName("panelTitle")[0].addEventListener("mouseover", this, false);
                this.element.getElementsByClassName("panelTitle")[0].addEventListener("mouseout", this, false);
                // Arrow Collapse Button Initiate
                this.element.getElementsByClassName("arrowIcon")[0].addEventListener("click", this.collapseToggle.bind(this), false);
                // Close Button
                this.element.getElementsByClassName("closeBtn")[0].addEventListener("click", this.closePanel.bind(this), false);
                //Resized Event
                if(typeof this.resizer.value == "number") this.panelBase.contentHeight = this.resizer.value;
                this.resizer.element.addEventListener("mouseup",this.resized.bind(this),false);
            }
        }
    },

    draw: {
        value: function() {
            //If the panel is set not to be visible. We dont bother doing anything else to it. till the next draw cycle that its set visible true
            // Actually thinking about it now. this might not work.
            if (!this.panelBase.visible) this.element.style.display = "none";
            else this.element.style.display = null;

            //Draw if collapsed or not
            if(this.panelBase.collapsed || this.panelBase.forcedCollapse) {
                this.element.classList.add("collapsed");
                this.element.style.height = this.panelBase.collapsedHeight + "px";
            }
            else {
                this.element.classList.remove("collapsed");
                this.element.style.height = this.panelBase.contentHeight + "px";
            }

            var pContentDiv = this.element.getElementsByClassName("panelObjects")[0];

            //Figure out Heights (min, max, and current)
            if (this.panelBase.isStatic || this.panelBase.isLocked) {
                this.element.style.minHeight = this.panelBase.contentHeight + "px";
                this.element.style.maxHeight = this.panelBase.contentHeight + "px";
                this.resizer.element.style.cursor = "default";
            } else {
                this.element.style.minHeight = this.panelBase.minHeight + "px";
                this.element.style.maxHeight = "";
                this.resizer.element.style.cursor = null;
            }

            if (this.panelBase.scrollable) pContentDiv.style.overflow = "auto";
            else pContentDiv.style.overflow = "hidden";
            this.element.getElementsByClassName("panelTitle")[0].innerHTML = this.panelBase.panelName;
            //pContentDiv.appendChild(this.panelBase.content);
            this.panelContent.content = this.panelBase.content;

        }
    }
});