diff options
Diffstat (limited to 'js/panels/Materials/materials-library-panel.reel/materials-library-panel.js')
-rwxr-xr-x | js/panels/Materials/materials-library-panel.reel/materials-library-panel.js | 143 |
1 files changed, 129 insertions, 14 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 cf0d4e93..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 | |||
@@ -1,20 +1,66 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | 2 | Copyright (c) 2012, Motorola Mobility, Inc |
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | 3 | All Rights Reserved. |
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | BSD License. |
5 | |||
6 | Redistribution and use in source and binary forms, with or without | ||
7 | modification, are permitted provided that the following conditions are met: | ||
8 | |||
9 | - Redistributions of source code must retain the above copyright notice, | ||
10 | this list of conditions and the following disclaimer. | ||
11 | - Redistributions in binary form must reproduce the above copyright | ||
12 | notice, this list of conditions and the following disclaimer in the | ||
13 | documentation and/or other materials provided with the distribution. | ||
14 | - Neither the name of Motorola Mobility nor the names of its contributors | ||
15 | may be used to endorse or promote products derived from this software | ||
16 | without specific prior written permission. | ||
17 | |||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
28 | POSSIBILITY OF SUCH DAMAGE. | ||
5 | </copyright> */ | 29 | </copyright> */ |
6 | 30 | ||
7 | var Montage = require("montage/core/core").Montage, | 31 | var Montage = require("montage/core/core").Montage, |
8 | Component = require("montage/ui/component").Component, | 32 | Component = require("montage/ui/component").Component, |
9 | MaterialsData = require("js/panels/Materials/materials-data.json"), | 33 | MaterialsData = require("js/panels/Materials/materials-data.json"), |
10 | 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; | ||
11 | 37 | ||
12 | exports.MaterialsLibraryPanel = Montage.create(Component, { | 38 | exports.MaterialsLibraryPanel = Montage.create(Component, { |
13 | 39 | ||
40 | deleteButton: { | ||
41 | value: null | ||
42 | }, | ||
43 | |||
14 | materialsData: { | 44 | materialsData: { |
15 | value: null | 45 | value: null |
16 | }, | 46 | }, |
17 | 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 | |||
18 | _hasFocus: { | 64 | _hasFocus: { |
19 | enumerable: false, | 65 | enumerable: false, |
20 | value: false | 66 | value: false |
@@ -36,21 +82,32 @@ exports.MaterialsLibraryPanel = Montage.create(Component, { | |||
36 | value:function(event) { | 82 | value:function(event) { |
37 | switch(event._currentTarget.label) | 83 | switch(event._currentTarget.label) |
38 | { | 84 | { |
39 | case "Add": | 85 | case "Duplicate": |
40 | console.log("Add new material"); | 86 | this.duplicateMaterial(); |
41 | break; | 87 | break; |
42 | case "Copy": | 88 | case "Edit": |
43 | console.log("Copy selected material"); | 89 | // console.log("Edit selected material"); |
90 | this._showMaterialPopup({ materialId: this.materialId }); | ||
44 | break; | 91 | break; |
45 | case "Delete": | 92 | case "Delete": |
46 | console.log("Delete selected material"); | 93 | this.deleteMaterial(); |
47 | break; | 94 | break; |
48 | } | 95 | } |
49 | } | 96 | } |
50 | }, | 97 | }, |
51 | 98 | ||
52 | handleNodeActivation: { | 99 | handleNodeActivation: { |
53 | 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; | ||
54 | this._showMaterialPopup({ materialId: obj.id }); | 111 | this._showMaterialPopup({ materialId: obj.id }); |
55 | } | 112 | } |
56 | }, | 113 | }, |
@@ -58,7 +115,6 @@ exports.MaterialsLibraryPanel = Montage.create(Component, { | |||
58 | handleShowMaterialPopup: { | 115 | handleShowMaterialPopup: { |
59 | enumerable: false, | 116 | enumerable: false, |
60 | value: function (event) { | 117 | value: function (event) { |
61 | //this._showMaterialPopup(event.detail.materialId); | ||
62 | this._showMaterialPopup(event.detail); | 118 | this._showMaterialPopup(event.detail); |
63 | } | 119 | } |
64 | }, | 120 | }, |
@@ -80,15 +136,16 @@ exports.MaterialsLibraryPanel = Montage.create(Component, { | |||
80 | if(!this._materialPopup) | 136 | if(!this._materialPopup) |
81 | { | 137 | { |
82 | this._materialPopup = Popup.create(); | 138 | this._materialPopup = Popup.create(); |
139 | this._materialInfo.materialsLibraryRef = this; | ||
83 | this._materialPopup.content = this._materialInfo; | 140 | this._materialPopup.content = this._materialInfo; |
141 | this._materialPopup.delegate = this; | ||
84 | this._materialPopup.modal = false; | 142 | this._materialPopup.modal = false; |
85 | this.eventManager.addEventListener("hideMaterialPopup", this, false); | 143 | this.eventManager.addEventListener("hideMaterialPopup", this, false); |
86 | this._materialPopup.addEventListener("show", this, false); | 144 | this._materialPopup.addEventListener("show", this, false); |
87 | } | 145 | } |
88 | this._materialPopup.show(); | 146 | this._materialPopup.show(); |
89 | 147 | ||
90 | materialID = materialObj.materialId; | 148 | this._materialInfo.loadMaterials(materialObj.materialId, materialObj.useSelection, materialObj.whichMaterial); |
91 | this._materialInfo.loadMaterials(materialID, materialObj.useSelection, materialObj.whichMaterial); | ||
92 | } | 149 | } |
93 | }, | 150 | }, |
94 | 151 | ||
@@ -96,8 +153,66 @@ exports.MaterialsLibraryPanel = Montage.create(Component, { | |||
96 | enumerable: false, | 153 | enumerable: false, |
97 | value: function (event) { | 154 | value: function (event) { |
98 | if(this._materialPopup){ | 155 | if(this._materialPopup){ |
156 | // console.log("hiding material popup"); | ||
157 | this._materialInfo.destroy(); | ||
99 | this._materialPopup.hide(); | 158 | this._materialPopup.hide(); |
100 | } | 159 | } |
101 | } | 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) { | ||