aboutsummaryrefslogtreecommitdiff
path: root/js/models
diff options
context:
space:
mode:
Diffstat (limited to 'js/models')
-rwxr-xr-xjs/models/element-model.js94
1 files changed, 93 insertions, 1 deletions
diff --git a/js/models/element-model.js b/js/models/element-model.js
index 966158e4..c9fb58d8 100755
--- a/js/models/element-model.js
+++ b/js/models/element-model.js
@@ -10,7 +10,99 @@ 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 // TODO: Add this in case there is no controller for the component
53 /*
54 if(el.getAttribute("data-montage-id")) {
55 elementName = null;
56 this.isComponent = true;
57 }
58 */
59
60 // Element is a component
61 if(el.controller) {
62 var componentInfo = Montage.getInfoForObject(el.controller);
63 var componentName = componentInfo.objectName;//.toLowerCase();
64
65 controller = "component";
66 elementName = componentName;
67 pi = elementNameToPi(componentName.replace(/\s+/g, ''));
68 isComponent = true;
69 }
70
71 return {
72 type: el.nodeName,
73 selection: elementName,
74 controller: ControllerFactory.getController(controller),
75 pi: pi,
76 props3d: Montage.create(Properties3D),
77 shapeModel: shapeModel,
78 isShape: isShape,
79 isComponent: isComponent
80 }
81};
82
83var elementNameToController = function(name) {
84 if(name === "div" || name === "custom") {
85 return "block";
86 } else if(name === "img") {
87 return "image";
88 } else {
89 return name;
90 }
91};
92
93var elementNameToPi = function(name) {
94 if(!name) return null;
95
96 var piString = name + "Pi";
97
98 if(!PiData.hasOwnProperty(piString)) {
99 piString = "blockPi";
100 }
101
102 return piString;
103};
104
105var elmo = exports.ElementModel = Montage.create(Montage, {
14 key: { value: "_model_"}, 106 key: { value: "_model_"},
15 107
16 type: { value: null }, // Tag type that was created 108 type: { value: null }, // Tag type that was created