aboutsummaryrefslogtreecommitdiff
path: root/js/panels/Materials/materials-library-panel.reel/materials-library-panel.js
diff options
context:
space:
mode:
authorPierre Frisch2011-12-22 07:25:50 -0800
committerValerio Virgillito2012-01-27 11:18:17 -0800
commitb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch)
tree0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/panels/Materials/materials-library-panel.reel/materials-library-panel.js
parent2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff)
downloadninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/panels/Materials/materials-library-panel.reel/materials-library-panel.js')
-rw-r--r--js/panels/Materials/materials-library-panel.reel/materials-library-panel.js205
1 files changed, 205 insertions, 0 deletions
diff --git a/js/panels/Materials/materials-library-panel.reel/materials-library-panel.js b/js/panels/Materials/materials-library-panel.reel/materials-library-panel.js
new file mode 100644
index 00000000..f97e1a27
--- /dev/null
+++ b/js/panels/Materials/materials-library-panel.reel/materials-library-panel.js
@@ -0,0 +1,205 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7var Tree = require("js/components/tree.reel").Tree,
8 Button = require("js/components/button.reel").Button,
9 MaterialsPopup = require("js/panels/Materials/materials-popup.reel").MaterialsPopup,
10 PopupMananger = require("js/components/popup-manager.reel").PopupMananger;
11
12exports.MaterialsLibraryPanel = (require("montage/core/core").Montage).create(require("montage/ui/component").Component, {
13
14 _hasFocus: {
15 enumerable: false,
16 value: false
17 },
18
19 prepareForDraw: {
20 enumerable: false,
21 value: function() {
22 var treeHolderDiv = document.getElementById("materials_library_tree");
23 var materialsTree = Tree.create();
24 materialsTree.element = treeHolderDiv;
25 materialsTree.dataProvider = this._loadXMLDoc("js/panels/Materials/Materials.xml");
26 materialsTree.needsDraw = true;
27
28 materialsTree.addEventListener("change", this, true);
29
30 var addButton = Button.create();
31 addButton.element = document.getElementById("ml_add_btn");
32 addButton.label = "Add";
33 addButton.needsDraw = true;
34 addButton.addEventListener("action", this, true);
35
36 var copyButton = Button.create();
37 copyButton.element = document.getElementById("ml_copy_btn");
38 copyButton.label = "Copy";
39 copyButton.needsDraw = true;
40 copyButton.addEventListener("action", this, true);
41
42 var deleteButton = Button.create();
43 deleteButton.element = document.getElementById("ml_delete_btn");
44 deleteButton.label = "Delete";
45 deleteButton.needsDraw = true;
46 deleteButton.addEventListener("action", this, true);
47 }
48 },
49
50 willDraw: {
51 enumerable: false,
52 value: function() {
53
54 }
55 },
56
57 draw: {
58 enumerable: false,
59 value: function() {
60
61 }
62 },
63
64 _loadXMLDoc: {
65 value:function(dname) {
66 if (window.XMLHttpRequest) {
67 xhttp = new XMLHttpRequest();
68 }
69 xhttp.open("GET", dname, false);
70 xhttp.send();
71 return xhttp.responseXML;
72 }
73 },
74
75 captureAction: {
76 value:function(event) {
77 switch(event._currentTarget.label)
78 {
79 case "Add":
80 console.log("Add new material");
81 break;
82 case "Copy":
83 console.log("Copy selected material");
84 break;
85 case "Delete":
86 console.log("Delete selected material");
87 break;
88 }
89 }
90 },
91
92 captureChange: {
93 value:function(e) {
94 var tNode = e._event.treeNode;
95 var left, top;
96 //TODO: Figure out if this is the best way to detect where user clicked
97 var mouseEvent = e._event.mouseEvent;
98 if (mouseEvent.clientX && mouseEvent.clientY) {
99 if (mouseEvent.clientX > (parseInt(document.width)/2)) {
100 left = mouseEvent.clientX - mouseEvent.offsetX-2;
101 top = mouseEvent.currentTarget.clientHeight/2+mouseEvent.clientY - mouseEvent.offsetY;
102 } else {
103 left = mouseEvent.clientX - mouseEvent.offsetX+parseInt(mouseEvent.currentTarget.clientWidth);
104 top = mouseEvent.clientY - mouseEvent.offsetY;
105 }
106 }
107
108 this._showMaterialPopup(left + 'px', top + 'px', 'right', 'top', tNode.id);
109 }
110 },
111
112 _materialPopup: {
113 enumerable:true,
114 value:null
115 },
116
117 _showMaterialPopup: {
118 enumerable: false,
119 value: function (x, y, side, align, materialID) {
120 if (this._materialPopup && this._materialPopup.opened) {
121 if (this._materialPopup.popup.position.x === x && this._materialPopup.popup.position.y === y) {
122 this._hideMaterialPopup();
123 } else {
124 this._materialPopup.popup.position = {x: x, y: y};
125 this._materialPopup.popup.tooltip = {side: side, align: align};
126 this._materialPopup.popup.base.loadMaterials(materialID);
127 //TODO: Tooltip needs to be fixed to allow aligning to change on fly
128 //this._materialPopup.popup.drawTooltip();
129 }
130 } else {
131 ////////////////////////////////////////////////////
132 //Creating popup from m-js component
133 var popup = document.createElement('div');
134 var content = document.createElement('div');
135 var popupBase = MaterialsPopup.create();
136
137
138 //TODO: Check to see if this HACK is needed
139 //(elements needs to be on DOM to be drawn)
140 document.body.appendChild(popup);
141 popupBase.element = popup;
142 popupBase.needsDraw = true;
143 document.body.removeChild(popup);
144 //Adding drawn element to container
145 content.appendChild(popupBase.element);
146
147 //Creating an instance of the popup and sending in created material popup content
148 this._materialPopup = {};
149 this._materialPopup.popup = PopupMananger.createPopup(content, {x: x, y: y}, {side: side, align: align});
150 this._materialPopup.popup.element.style.opacity = 0;
151 this._materialPopup.popup.base = popupBase;
152 popupBase._material = MaterialsLibrary.getMaterial( materialID );
153 popupBase._materialName = materialID;
154 //TODO: Fix this animation/draw HACK (Move to didDraw callback)
155 setTimeout(function () {
156 this._materialPopup.popup.element.style.opacity = 1;
157 this._materialPopup.popup.base.loadMaterials(materialID);
158 }.bind(this), 150);
159
160
161
162 //Popup was added, so it's opened
163 this._materialPopup.opened = true;
164 //TODO: Fix this HACK, it listens to this canvas to be clicked to close popup
165 document.getElementById('stageAndScenesContainer').addEventListener('click', this, false);
166 }
167 }
168 },
169 ////////////////////////////////////////////////////////////////////
170 //
171 handleClick: {
172 enumerable: true,
173 value: function (e) {
174 //TODO: Fix this HACK
175 if (e._event.target.id === 'stageCanvas' && this._materialPopup.opened) {
176 this._handleDocumentClick(e);
177 }
178 }
179 },
180 ////////////////////////////////////////////////////////////////////
181 //
182 _handleDocumentClick: {
183 enumerable: false,
184 value: function (e) {
185 this._hideMaterialPopup();
186 //TODO: Fix this HACK
187 document.getElementById('stageAndScenesContainer').removeEventListener ('click', this, false);
188 }
189 },
190 //////////////