diff options
author | Valerio Virgillito | 2012-06-05 21:40:44 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-06-05 21:40:44 -0700 |
commit | e28eb9158a50d7e6d97dbc68066e591ac600c241 (patch) | |
tree | 1615affe62374ae67eaecb8b1966a2f464559dfa /js/models/element-model.js | |
parent | d7555c35b357e28a1e1ccc1c4edc4fe04d2b139a (diff) | |
download | ninja-e28eb9158a50d7e6d97dbc68066e591ac600c241.tar.gz |
removing all model creators.
The elementModel is now a getter that will create a new model when needed.
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/models/element-model.js')
-rwxr-xr-x | js/models/element-model.js | 96 |
1 files changed, 95 insertions, 1 deletions
diff --git a/js/models/element-model.js b/js/models/element-model.js index 966158e4..ea25e5b1 100755 --- a/js/models/element-model.js +++ b/js/models/element-model.js | |||
@@ -10,7 +10,101 @@ 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 | ||
13 | exports.ElementModel = Montage.create(Montage, { | 13 | var 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, true); | ||
33 | } else { | ||
34 | this._model.props3D.init(this, false); | ||
35 | } | ||
36 | |||
37 | return this._model; | ||
38 | }; | ||
39 | |||
40 | var getInfoForElement = function(el) { | ||
41 | var elementName, controller, pi, shapeModel = null, isShape = false, isComponent = false; | ||
42 | |||
43 | elementName = el.nodeName.toLowerCase(); | ||
44 | controller = elementNameToController(elementName); | ||
45 | pi = elementNameToPi(elementName); | ||
46 | |||
47 | // Element is a shape | ||
48 | if(el.getAttribute("data-RDGE-id")) { | ||
49 | controller = "shape"; | ||
50 | shapeModel = Montage.create(ShapeModel); | ||
51 | isShape = true; | ||
52 | } | ||
53 | |||
54 | // TODO: Add this in case there is no controller for the component | ||
55 | /* | ||
56 | if(el.getAttribute("data-montage-id")) { | ||
57 | elementName = null; | ||
58 | this.isComponent = true; | ||
59 | } | ||
60 | */ | ||
61 | |||
62 | // Element is a component | ||
63 | if(el.controller) { | ||
64 | var componentInfo = Montage.getInfoForObject(el.controller); | ||
65 | var componentName = componentInfo.objectName;//.toLowerCase(); | ||
66 | |||
67 | controller = "component"; | ||
68 | elementName = componentName; | ||
69 | pi = elementNameToPi(componentName.replace(/\s+/g, '')); | ||
70 | isComponent = true; | ||
71 | } | ||
72 | |||
73 | return { | ||
74 | type: el.nodeName, | ||
75 | selection: elementName, | ||
76 | controller: ControllerFactory.getController(controller), | ||
77 | pi: pi, | ||
78 | props3d: Montage.create(Properties3D), | ||
79 | shapeModel: shapeModel, | ||
80 | isShape: isShape, | ||
81 | isComponent: isComponent | ||
82 | } | ||
83 | }; | ||
84 | |||
85 | var elementNameToController = function(name) { | ||
86 | if(name === "div" || name === "custom") { | ||
87 | return "block"; | ||
88 | } else if(name === "img") { | ||
89 | return "image"; | ||
90 | } else { | ||
91 | return name; | ||
92 | } | ||
93 | }; | ||
94 | |||
95 | var elementNameToPi = function(name) { | ||
96 | if(!name) return null; | ||
97 | |||
98 | var piString = name + "Pi"; | ||
99 | |||
100 | if(!PiData.hasOwnProperty(piString)) { | ||
101 | piString = "blockPi"; | ||
102 | } | ||
103 | |||
104 | return piString; | ||
105 | }; | ||
106 | |||
107 | var elmo = exports.ElementModel = Montage.create(Montage, { | ||
14 | key: { value: "_model_"}, | 108 | key: { value: "_model_"}, |
15 | 109 | ||
16 | type: { value: null }, // Tag type that was created | 110 | type: { value: null }, // Tag type that was created |