aboutsummaryrefslogtreecommitdiff
path: root/js/models
diff options
context:
space:
mode:
authorArmen Kesablyan2012-06-11 11:17:41 -0700
committerArmen Kesablyan2012-06-11 11:17:41 -0700
commit278769df00ced8620fd73371e38fe2e43f07ca3b (patch)
treedeb505c8a66b660eee1f17a2c6c4c575c7939f6f /js/models
parent555fd6efa605b937800b3979a4c68fa7eb8666ae (diff)
parent0f040acabfb7a4bf3138debec5aff869487ceb11 (diff)
downloadninja-278769df00ced8620fd73371e38fe2e43f07ca3b.tar.gz
Merge branch 'refs/heads/master' into binding
Conflicts: js/document/models/html.js js/document/views/design.js js/ninja.reel/ninja.js Signed-off-by: Armen Kesablyan <armen@motorola.com>
Diffstat (limited to 'js/models')
-rwxr-xr-xjs/models/app-model.js26
-rwxr-xr-xjs/models/element-model.js100
2 files changed, 125 insertions, 1 deletions
diff --git a/js/models/app-model.js b/js/models/app-model.js
index 1c599a32..ceba653e 100755
--- a/js/models/app-model.js
+++ b/js/models/app-model.js
@@ -9,6 +9,32 @@ var Montage = require("montage/core/core").Montage,
9 9
10exports.AppModel = Montage.create(Component, { 10exports.AppModel = Montage.create(Component, {
11 11
12 _currentDocument: {
13 value : null
14 },
15
16 currentDocument : {
17 get : function() {
18 return this._currentDocument;
19 },
20 set : function(value) {
21 if (value === this._currentDocument) {
22 return;
23 }
24
25 if(this._currentDocument && this._currentDocument.currentView === "design") {
26 this._currentDocument.model.draw3DGrid = this.show3dGrid;
27 }
28
29 this._currentDocument = value;
30
31 if(this._currentDocument && this._currentDocument.currentView === "design") {
32 this.show3dGrid = this._currentDocument.model.draw3DGrid;
33 }
34
35 }
36 },
37
12 _livePreview: { 38 _livePreview: {
13 value: false 39 value: false
14 }, 40 },
diff --git a/js/models/element-model.js b/js/models/element-model.js
index 966158e4..76f15b21 100755
--- a/js/models/element-model.js
+++ b/js/models/element-model.js
@@ -10,7 +10,105 @@ var Montage = require("montage/core/core").Montage,
10 ControllerFactory = require("js/controllers/elements/controller-factory").ControllerFactory, 10 ControllerFactory = require("js/controllers/elements/controller-factory").ControllerFactory,
11 PiData = require("js/data/pi/pi-data").PiData; 11 PiData = require("js/data/pi/pi-data").PiData;
12 12
13exports.ElementModel = Montage.create(Montage, { 13var modelGenerator = exports.modelGenerator = function() {
14 var info = getInfoForElement(this);
15
16 Object.defineProperty(this, "_model", {
17 configurable: true,
18 enumerable: false,
19 writable: true,
20 value: Montage.create(elmo, {
21 type: { value: info.type},
22 selection: { value: info.selection},
23 controller: { value: info.controller},
24 pi: { value: info.pi},
25 props3D: { value: info.props3d},
26 shapeModel: { value: info.shapeModel},
27 isShape: { value: info.isShape}
28 })
29 });
30
31 if(this._model.selection !== "body") {
32 this._model.props3D.init(this, false);
33 }
34
35 return this._model;
36};
37
38var getInfoForElement = function(el) {
39 var elementName, controller, pi, shapeModel = null, isShape = false, isComponent = false;
40
41 elementName = el.nodeName.toLowerCase();
42 controller = elementNameToController(elementName);
43 pi = elementNameToPi(elementName);
44
45 // Element is a shape
46 if(el.getAttribute("data-RDGE-id")) {
47 controller = "shape";
48 shapeModel = Montage.create(ShapeModel);
49 isShape = true;
50 }
51
52 if(el.nodeName.toLowerCase() === "ninja-content") {
53 elementName = "body";
54 controller = elementNameToController(elementName);
55 pi = elementNameToPi(elementName);
56 }
57
58 // TODO: Add this in case there is no controller for the component
59 /*
60 if(el.getAttribute("data-montage-id")) {
61 elementName = null;
62 this.isComponent = true;
63 }
64 */
65
66 // Element is a component
67 if(el.controller) {
68 var componentInfo = Montage.getInfoForObject(el.controller);
69 var componentName = componentInfo.objectName;//.toLowerCase();
70
71 controller = "component";
72 elementName = componentName;
73 pi = elementNameToPi(componentName.replace(/\s+/g, ''));
74 isComponent = true;
75 }
76
77 return {
78 type: el.nodeName,
79 selection: elementName,
80 controller: ControllerFactory.getController(controller),
81 pi: pi,
82 props3d: Montage.create(Properties3D),
83 shapeModel: shapeModel,
84 isShape: isShape,
85 isComponent: isComponent
86 }
87};
88
89var elementNameToController = function(name) {
90 if(name === "div" || name === "custom") {
91 return "block";
92 } else if(name === "img") {
93 return "image";
94 } else {
95 return name;
96 }
97};
98
99var elementNameToPi = function(name) {
100 if(!name) return null;
101
102 var piString = name + "Pi";
103
104 if(!PiData.hasOwnProperty(piString)) {
105 piString = "blockPi";
106 }
107
108 return piString;
109};
110
111var elmo = exports.ElementModel = Montage.create(Montage, {
14 key: { value: "_model_"}, 112 key: { value: "_model_"},
15 113
16 type: { value: null }, // Tag type that was created 114 type: { value: null }, // Tag type that was created