aboutsummaryrefslogtreecommitdiff
path: root/js/panels/Materials/materials-library-panel.reel/materials-library-panel.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/panels/Materials/materials-library-panel.reel/materials-library-panel.js')
-rwxr-xr-xjs/panels/Materials/materials-library-panel.reel/materials-library-panel.js111
1 files changed, 101 insertions, 10 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
index b5d6bb96..d6df8229 100755
--- a/js/panels/Materials/materials-library-panel.reel/materials-library-panel.js
+++ b/js/panels/Materials/materials-library-panel.reel/materials-library-panel.js
@@ -31,14 +31,36 @@ POSSIBILITY OF SUCH DAMAGE.
31var Montage = require("montage/core/core").Montage, 31var Montage = require("montage/core/core").Montage,
32 Component = require("montage/ui/component").Component, 32 Component = require("montage/ui/component").Component,
33 MaterialsData = require("js/panels/Materials/materials-data.json"), 33 MaterialsData = require("js/panels/Materials/materials-data.json"),
34 Popup = require("montage/ui/popup/popup.reel").Popup; 34 Popup = require("montage/ui/popup/popup.reel").Popup,
35 MaterialsModel = require("js/models/materials-model").MaterialsModel,
36 LeafNode = require("js/components/treeview/ninja-leaf.reel").Leaf;
35 37
36exports.MaterialsLibraryPanel = Montage.create(Component, { 38exports.MaterialsLibraryPanel = Montage.create(Component, {
37 39
40 deleteButton: {
41 value: null
42 },
43
38 materialsData: { 44 materialsData: {
39 value: null 45 value: null
40 }, 46 },
41 47
48 materialId: {
49 value: null
50 },
51
52 selectedMaterialNode: {
53 value: null
54 },
55
56 customMaterialsBranch: {
57 value: null
58 },
59
60 customMaterialsCounter: {
61 value: 2
62 },
63
42 _hasFocus: { 64 _hasFocus: {
43 enumerable: false, 65 enumerable: false,
44 value: false 66 value: false
@@ -60,21 +82,32 @@ exports.MaterialsLibraryPanel = Montage.create(Component, {
60 value:function(event) { 82 value:function(event) {
61 switch(event._currentTarget.label) 83 switch(event._currentTarget.label)
62 { 84 {
63 case "Add": 85 case "Duplicate":
64 console.log("Add new material"); 86 this.duplicateMaterial();
65 break; 87 break;
66 case "Copy": 88 case "Edit":
67 console.log("Copy selected material"); 89// console.log("Edit selected material");
90 this._showMaterialPopup({ materialId: this.materialId });
68 break; 91 break;
69 case "Delete": 92 case "Delete":
70 console.log("Delete selected material"); 93 this.deleteMaterial();
71 break; 94 break;
72 } 95 }
73 } 96 }
74 }, 97 },
75 98
76 handleNodeActivation: { 99 handleNodeActivation: {
77 value:function(obj) { 100 value: function(obj, event) {
101 this.selectedMaterialNode = event.currentTarget;
102 this.materialId = obj.id;
103 this.deleteButton.enabled = !!obj.canDelete;
104 }
105 },
106
107 handleDblclick: {
108 value:function(obj, event) {
109 this.selectedMaterialNode = event.currentTarget;
110 this.materialId = obj.id;
78 this._showMaterialPopup({ materialId: obj.id }); 111 this._showMaterialPopup({ materialId: obj.id });
79 } 112 }
80 }, 113 },
@@ -82,7 +115,6 @@ exports.MaterialsLibraryPanel = Montage.create(Component, {
82 handleShowMaterialPopup: { 115 handleShowMaterialPopup: {
83 enumerable: false, 116 enumerable: false,
84 value: function (event) { 117 value: function (event) {
85 //this._showMaterialPopup(event.detail.materialId);
86 this._showMaterialPopup(event.detail); 118 this._showMaterialPopup(event.detail);
87 } 119 }
88 }, 120 },
@@ -104,15 +136,16 @@ exports.MaterialsLibraryPanel = Montage.create(Component, {
104 if(!this._materialPopup) 136 if(!this._materialPopup)
105 { 137 {
106 this._materialPopup = Popup.create(); 138 this._materialPopup = Popup.create();
139 this._materialInfo.materialsLibraryRef = this;
107 this._materialPopup.content = this._materialInfo; 140 this._materialPopup.content = this._materialInfo;
141 this._materialPopup.delegate = this;
108 this._materialPopup.modal = false; 142 this._materialPopup.modal = false;
109 this.eventManager.addEventListener("hideMaterialPopup", this, false); 143 this.eventManager.addEventListener("hideMaterialPopup", this, false);
110 this._materialPopup.addEventListener("show", this, false); 144 this._materialPopup.addEventListener("show", this, false);
111 } 145 }
112 this._materialPopup.show(); 146 this._materialPopup.show();
113 147
114 materialID = materialObj.materialId; 148 this._materialInfo.loadMaterials(materialObj.materialId, materialObj.useSelection, materialObj.whichMaterial);
115 this._materialInfo.loadMaterials(materialID, materialObj.useSelection, materialObj.whichMaterial);
116 } 149 }
117 }, 150 },
118 151
@@ -120,8 +153,66 @@ exports.MaterialsLibraryPanel = Montage.create(Component, {
120 enumerable: false, 153 enumerable: false,
121 value: function (event) { 154 value: function (event) {
122 if(this._materialPopup){ 155 if(this._materialPopup){
156// console.log("hiding material popup");
157 this._materialInfo.destroy();
123 this._materialPopup.hide(); 158 this._materialPopup.hide();
124 } 159 }
125 } 160 }
161 },
162
163 duplicateMaterial: {
164 enumerable: false,
165 value: function (matCopyName) {
166// console.log("Duplicate selected material");
167 var mat = MaterialsModel.getMaterial(this.materialId);
168 if(mat) {
169 var matCopy = mat.dup();
170 if(!matCopyName) {
171 matCopyName = this.materialId + "_" + this.customMaterialsCounter++;
172 }
173 matCopy.setName(matCopyName);
174 MaterialsModel.addMaterial(matCopy);
175
176 var leaf = LeafNode.create();
177 leaf.id = matCopyName;
178 leaf.label = matCopyName;
179 leaf.treeNodeType = "leaf";
180 leaf.canDelete = true;
181 if(!this.customMaterialsBranch) {
182 this.customMaterialsBranch = this.materialsController.branchControllers[2];
183 }
184 this.customMaterialsBranch.content.push(leaf);
185 }
186 }
187 },
188
189 deleteMaterial: {
190 enumerable: false,
191 value: function () {
192// console.log("Delete selected material");
193 if(!this.customMaterialsBranch) {
194 this.customMaterialsBranch = this.materialsController.branchControllers[2];
195 }
196
197 var mat = MaterialsModel.getMaterial(this.materialId);
198 if(mat) {
199 MaterialsModel.removeMaterial(this.materialId);
200
201 var index = this.customMaterialsBranch.selectedIndexes[0];
202 this.customMaterialsBranch.content.splice(index, 1);
203 }
204
205 this.deleteButton.enabled = false;
206 }
207 },
208
209 willPositionPopup: {
210 value: function(popup, defaultPosition) {
211 var content = popup.content.element,
212 contentHt = parseFloat(content.style.height) || content.offsetHeight || 0,
213 contentWd = parseFloat(content.style.width) || content.offsetWidth || 0,
214 pt = webkitConvertPointFromNodeToPage(this.selectedMaterialNode, new WebKitPoint(0, 0));
215 return {top: pt.y - contentHt + 10, left: pt.x - contentWd + 10};
216 }
126 } 217 }
127}); 218});