From 4c3aac5eabd93052b1554a03d78235215bb49db4 Mon Sep 17 00:00:00 2001
From: Valerio Virgillito
Date: Tue, 29 May 2012 00:34:40 -0700
Subject: document bindings phase 1

- using array controller to bind the current document to all ninja components
- removed open document event
- removed references to the document controller

Signed-off-by: Valerio Virgillito <valerio@motorola.com>
---
 js/panels/properties.reel/properties.js            | 40 ++++++----
 .../sections/three-d-view.reel/three-d-view.js     | 91 ++++++++++------------
 2 files changed, 67 insertions(+), 64 deletions(-)

(limited to 'js/panels/properties.reel')

diff --git a/js/panels/properties.reel/properties.js b/js/panels/properties.reel/properties.js
index 84b0d589..e99f58e9 100755
--- a/js/panels/properties.reel/properties.js
+++ b/js/panels/properties.reel/properties.js
@@ -13,6 +13,32 @@ var ElementsMediator = require("js/mediators/element-mediator").ElementMediator;
 
 exports.Properties = Montage.create(Component, {
 
+    _currentDocument: {
+        value : null,
+        enumerable : false
+    },
+
+    currentDocument : {
+        get : function() {
+            return this._currentDocument;
+        },
+        set : function(value) {
+            if (value === this._currentDocument) {
+                return;
+            }
+
+            this._currentDocument = value;
+
+            if(this._currentDocument.currentView === "design") {
+                // Save a reference of the pi inside the document view to be able to clear
+                this._currentDocument.model.views.design.propertiesPanel = this;
+
+                // Display the default document root PI
+                this.displayElementProperties(this._currentDocument.model.documentRoot);
+            }
+        }
+    },
+
     elementName: {
         value: null
     },
@@ -46,7 +72,7 @@ exports.Properties = Montage.create(Component, {
 
     prepareForDraw: {
         value : function() {
-            this.eventManager.addEventListener("openDocument", this, false);
+            this.eventManager.addEventListener("elementChange", this, false);
             this.eventManager.addEventListener("selectionChange", this, false);
             this.eventManager.addEventListener("closeDocument", this, false);
 
@@ -65,18 +91,6 @@ exports.Properties = Montage.create(Component, {
         }
     },
 
-    handleOpenDocument: {
-        value: function() {
-            this.eventManager.addEventListener( "elementChange", this, false);
-
-            // Save a reference of the pi inside the document view to be able to clear
-            this.application.ninja.currentDocument.model.views.design.propertiesPanel = this;
-
-            // Display the default document root PI
-            this.displayElementProperties(this.application.ninja.currentDocument.model.documentRoot);
-        }
-    },
-
     handleCloseDocument: {
         value: function(){
             this.clear();
diff --git a/js/panels/properties.reel/sections/three-d-view.reel/three-d-view.js b/js/panels/properties.reel/sections/three-d-view.reel/three-d-view.js
index e16e3509..0320c327 100755
--- a/js/panels/properties.reel/sections/three-d-view.reel/three-d-view.js
+++ b/js/panels/properties.reel/sections/three-d-view.reel/three-d-view.js
@@ -26,8 +26,7 @@ exports.ThreeD = Montage.create(Component, {
         set: function(value) {
             this._axisMode = value;
             
-            if(value === 0)
-            {
+            if(value === 0) {
                 this.inGlobalMode = false;
                 this.x3D = 0;
                 this.y3D = 0;
@@ -36,13 +35,10 @@ exports.ThreeD = Montage.create(Component, {
                 this.xAngle = 0;
                 this.yAngle = 0;
                 this.zAngle = 0;
-            }
-            else
-            {
+            } else {
                 this.inGlobalMode = true;
                 var item = this.item;
-                if(item)
-                {
+                if(item) {
                     this.x3D = item.elementModel.props3D.x3D;
                     this.y3D = item.elementModel.props3D.y3D;
                     this.z3D = item.elementModel.props3D.z3D;
@@ -114,8 +110,7 @@ exports.ThreeD = Montage.create(Component, {
     handleAction: {
         value: function(event) {
             if(event.currentTarget.identifier === "flatten") {
-                this.application.ninja.elementMediator.setProperty([this.item],
-                                                                    "-webkit-transform-style",
+                this.application.ninja.elementMediator.setProperty([this.item], "-webkit-transform-style",
                                                                     event.currentTarget.checked ? ["flat"] : ["preserve-3d"]);
             }
         }
@@ -127,11 +122,7 @@ exports.ThreeD = Montage.create(Component, {
                 return;
             }
 
-            this.apply3DProperties(event.currentTarget.identifier,
-                                    event.currentTarget,
-                                    this.item,
-                                    this.inGlobalMode,
-                                    false);
+            this.apply3DProperties(event.currentTarget.identifier, event.currentTarget, this.item, this.inGlobalMode, false);
 
             this._curMat = null;
             this._curProp = null;
@@ -144,28 +135,24 @@ exports.ThreeD = Montage.create(Component, {
                 return;
             }
 
-            this.apply3DProperties(event.currentTarget.identifier,
-                            event.currentTarget,
-                            this.item,
-                            this.inGlobalMode,
-                            true);
+            this.apply3DProperties(event.currentTarget.identifier, event.currentTarget, this.item, this.inGlobalMode, true);
         }
     },
 
     apply3DProperties : {
         value : function(prop, value, item, inGlobalMode, isChanging){
-            if(!this._curMat)
-            {
+            if(!this._curMat) {
                 this._curMat = this.application.ninja.elementMediator.getMatrix(item);
             }
+
             var curMat = this._curMat;
             var delta = value.value;
-            if(inGlobalMode)
-            {
-                if(!this._curProp)
-                {
+            if(inGlobalMode) {
+
+                if(!this._curProp) {
                     this._curProp = this.application.ninja.elementMediator.get3DProperty(item, prop);
                 }
+
                 delta -= this._curProp;
             }
 
@@ -193,31 +180,47 @@ exports.ThreeD = Montage.create(Component, {
             }
 
             var mat = [];
-            if(inGlobalMode)
-            {
+            if(inGlobalMode) {
                 glmat4.multiply(xFormMat, curMat, mat);
-            }
-            else
-            {
+            } else {
                 glmat4.multiply(curMat, xFormMat, mat);
             }
 
-            if(isChanging)
-            {
+            if(isChanging) {
                 this.application.ninja.elementMediator.setMatrix(item, mat, true);
-            }
-            else
-            {
+            } else {
                 this.application.ninja.elementMediator.setMatrix(item, mat, false);
 
-                if(!inGlobalMode)
-                {
+                if(!inGlobalMode) {
                     value.value = 0;
                 }
             }
         }
     },
 
+    currentDocument : {
+        get : function() {
+            return this._currentDocument;
+        },
+        set : function(value) {
+            if (value === this._currentDocument) {
+                return;
+            }
+
+            this._currentDocument = value;
+
+            if(this._currentDocument.currentView === "design") {
+                // Save a reference of the pi inside the document view to be able to clear
+                Object.defineBinding(this, "item", {
+                    boundObject: this,
+                    boundObjectPropertyPath: "application.ninja.selectedElements",
+                    boundValueMutator: this._getSelectedItem,
+                    oneway: true
+                });
+            }
+        }
+    },
+
     templateDidLoad : {
         value: function() {
             Object.defineBinding(this, "axisMode", {
@@ -225,20 +228,6 @@ exports.ThreeD = Montage.create(Component, {
                 boundObjectPropertyPath: "selectedIndex",
                 oneway: false
             });
-
-            this.eventManager.addEventListener("openDocument", this, false);
-        }
-    },
-
-    handleOpenDocument: {
-        value: function() {
-
-            Object.defineBinding(this, "item", {
-                boundObject: this,
-                boundObjectPropertyPath: "application.ninja.selectedElements",
-                boundValueMutator: this._getSelectedItem,
-                oneway: true
-            });
         }
     },
 
-- 
cgit v1.2.3


From 31b094ee21102f99a4021d505bc3a28527c9e23d Mon Sep 17 00:00:00 2001
From: Valerio Virgillito
Date: Wed, 30 May 2012 01:33:20 -0700
Subject: Fixing the close document.

Signed-off-by: Valerio Virgillito <valerio@motorola.com>
---
 js/panels/properties.reel/properties.js | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

(limited to 'js/panels/properties.reel')

diff --git a/js/panels/properties.reel/properties.js b/js/panels/properties.reel/properties.js
index e99f58e9..4b663220 100755
--- a/js/panels/properties.reel/properties.js
+++ b/js/panels/properties.reel/properties.js
@@ -29,7 +29,9 @@ exports.Properties = Montage.create(Component, {
 
             this._currentDocument = value;
 
-            if(this._currentDocument.currentView === "design") {
+            if(!value) {
+                this.clear();
+            } else if(this._currentDocument.currentView === "design") {
                 // Save a reference of the pi inside the document view to be able to clear
                 this._currentDocument.model.views.design.propertiesPanel = this;
 
@@ -74,7 +76,6 @@ exports.Properties = Montage.create(Component, {
         value : function() {
             this.eventManager.addEventListener("elementChange", this, false);
             this.eventManager.addEventListener("selectionChange", this, false);
-            this.eventManager.addEventListener("closeDocument", this, false);
 
             // This will be a toggle option
             if(this.application.ninja.appData.PILiveUpdate) {
@@ -91,12 +92,6 @@ exports.Properties = Montage.create(Component, {
         }
     },
 
-    handleCloseDocument: {
-        value: function(){
-            this.clear();
-        }
-    },
-
     /**
      * Blur and Key up to handle change in the Element ID field.
      */
-- 
cgit v1.2.3


From 752f76fa464e2c9e48b4a0e5429a5b8062c00b39 Mon Sep 17 00:00:00 2001
From: Nivesh Rajbhandari
Date: Wed, 30 May 2012 13:38:39 -0700
Subject: PI's 3d section was not  binding correctly to the current document.

Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
---
 js/panels/properties.reel/properties.html                            | 5 ++++-
 js/panels/properties.reel/sections/three-d-view.reel/three-d-view.js | 4 ++++
 2 files changed, 8 insertions(+), 1 deletion(-)

(limited to 'js/panels/properties.reel')

diff --git a/js/panels/properties.reel/properties.html b/js/panels/properties.reel/properties.html
index ac0dab5a..b9aa206b 100755
--- a/js/panels/properties.reel/properties.html
+++ b/js/panels/properties.reel/properties.html
@@ -56,7 +56,10 @@
                 }
             },
             "threeDProperties": {
-                "prototype": "js/panels/properties.reel/sections/three-d-view.reel[ThreeD]"
+                "prototype": "js/panels/properties.reel/sections/three-d-view.reel[ThreeD]",
+                "bindings": {
+                    "currentDocument": {"<-": "@owner.currentDocument"}
+                }
             },
 
             "CustomSections": {
diff --git a/js/panels/properties.reel/sections/three-d-view.reel/three-d-view.js b/js/panels/properties.reel/sections/three-d-view.reel/three-d-view.js
index 0320c327..49907c9d 100755
--- a/js/panels/properties.reel/sections/three-d-view.reel/three-d-view.js
+++ b/js/panels/properties.reel/sections/three-d-view.reel/three-d-view.js
@@ -198,6 +198,10 @@ exports.ThreeD = Montage.create(Component, {
         }
     },
 
+    _currentDocument: {
+        value : null
+    },
+
     currentDocument : {
         get : function() {
             return this._currentDocument;
-- 
cgit v1.2.3


From 501221d0bbf776ce71bc7ae0f482c931f6651659 Mon Sep 17 00:00:00 2001
From: Valerio Virgillito
Date: Wed, 30 May 2012 14:51:25 -0700
Subject: fixing the timeline current document bindings

Signed-off-by: Valerio Virgillito <valerio@motorola.com>
---
 js/panels/properties.reel/properties.js | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

(limited to 'js/panels/properties.reel')

diff --git a/js/panels/properties.reel/properties.js b/js/panels/properties.reel/properties.js
index 4b663220..d05fb058 100755
--- a/js/panels/properties.reel/properties.js
+++ b/js/panels/properties.reel/properties.js
@@ -14,8 +14,7 @@ var ElementsMediator = require("js/mediators/element-mediator").ElementMediator;
 exports.Properties = Montage.create(Component, {
 
     _currentDocument: {
-        value : null,
-        enumerable : false
+        value : null
     },
 
     currentDocument : {
-- 
cgit v1.2.3


From 66632a6e0de0998ff6d36abdaa8c3a546eada0f5 Mon Sep 17 00:00:00 2001
From: Valerio Virgillito
Date: Wed, 30 May 2012 23:02:46 -0700
Subject: fixing the closing of documents

Signed-off-by: Valerio Virgillito <valerio@motorola.com>
---
 js/panels/properties.reel/sections/three-d-view.reel/three-d-view.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'js/panels/properties.reel')

diff --git a/js/panels/properties.reel/sections/three-d-view.reel/three-d-view.js b/js/panels/properties.reel/sections/three-d-view.reel/three-d-view.js
index 49907c9d..104d474d 100755
--- a/js/panels/properties.reel/sections/three-d-view.reel/three-d-view.js
+++ b/js/panels/properties.reel/sections/three-d-view.reel/three-d-view.js
@@ -213,7 +213,7 @@ exports.ThreeD = Montage.create(Component, {
 
             this._currentDocument = value;
 
-            if(this._currentDocument.currentView === "design") {
+            if(this._currentDocument && this._currentDocument.currentView === "design") {
                 // Save a reference of the pi inside the document view to be able to clear
                 Object.defineBinding(this, "item", {
                     boundObject: this,
-- 
cgit v1.2.3


From e1fe603a7c002073f8ac13623f8cc8dc43efb59d Mon Sep 17 00:00:00 2001
From: Valerio Virgillito
Date: Thu, 31 May 2012 10:27:46 -0700
Subject: fixing selection when switching documents

Signed-off-by: Valerio Virgillito <valerio@motorola.com>
---
 js/panels/properties.reel/properties.js | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

(limited to 'js/panels/properties.reel')

diff --git a/js/panels/properties.reel/properties.js b/js/panels/properties.reel/properties.js
index d05fb058..934a3851 100755
--- a/js/panels/properties.reel/properties.js
+++ b/js/panels/properties.reel/properties.js
@@ -28,15 +28,17 @@ exports.Properties = Montage.create(Component, {
 
             this._currentDocument = value;
 
-            if(!value) {
+//            if(!value) {
                 this.clear();
-            } else if(this._currentDocument.currentView === "design") {
-                // Save a reference of the pi inside the document view to be able to clear
-                this._currentDocument.model.views.design.propertiesPanel = this;
+//            }
 
+            /*
+            else if(this._currentDocument.currentView === "design") {
                 // Display the default document root PI
-                this.displayElementProperties(this._currentDocument.model.documentRoot);
+                //this.displayElementProperties(this._currentDocument.model.documentRoot);
+//                this.displaySelection(this._currentDocument.model.selection);
             }
+            */
         }
     },
 
@@ -181,6 +183,20 @@ exports.Properties = Montage.create(Component, {
         }
     },
 
+    displaySelection: {
+        value: function(selection) {
+            if(selection.length === 0) {
+                this.displayElementProperties(this._currentDocument.model.documentRoot);
+            } else {
+                if(selection.length === 1) {
+                    this.displayElementProperties(this.application.ninja.selectedElements[0]);
+                } else {
+                    this.displayGroupProperties(this.application.ninja.selectedElements);
+                }
+            }
+        }
+    },
+
     clear: {
         value: function() {
             this.elementName.value = "";
-- 
cgit v1.2.3