From e28eb9158a50d7e6d97dbc68066e591ac600c241 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 5 Jun 2012 21:40:44 -0700 Subject: removing all model creators. The elementModel is now a getter that will create a new model when needed. Signed-off-by: Valerio Virgillito --- js/models/element-model.js | 96 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) (limited to 'js/models') 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, ControllerFactory = require("js/controllers/elements/controller-factory").ControllerFactory, PiData = require("js/data/pi/pi-data").PiData; -exports.ElementModel = Montage.create(Montage, { +var modelGenerator = exports.modelGenerator = function() { + var info = getInfoForElement(this); + + Object.defineProperty(this, "_model", { + configurable: true, + enumerable: false, + writable: true, + value: Montage.create(elmo, { + type: { value: info.type}, + selection: { value: info.selection}, + controller: { value: info.controller}, + pi: { value: info.pi}, + props3D: { value: info.props3d}, + shapeModel: { value: info.shapeModel}, + isShape: { value: info.isShape} + }) + }); + + if(this._model.selection === "body") { + this._model.props3D.init(this, true); + } else { + this._model.props3D.init(this, false); + } + + return this._model; +}; + +var getInfoForElement = function(el) { + var elementName, controller, pi, shapeModel = null, isShape = false, isComponent = false; + + elementName = el.nodeName.toLowerCase(); + controller = elementNameToController(elementName); + pi = elementNameToPi(elementName); + + // Element is a shape + if(el.getAttribute("data-RDGE-id")) { + controller = "shape"; + shapeModel = Montage.create(ShapeModel); + isShape = true; + } + + // TODO: Add this in case there is no controller for the component + /* + if(el.getAttribute("data-montage-id")) { + elementName = null; + this.isComponent = true; + } + */ + + // Element is a component + if(el.controller) { + var componentInfo = Montage.getInfoForObject(el.controller); + var componentName = componentInfo.objectName;//.toLowerCase(); + + controller = "component"; + elementName = componentName; + pi = elementNameToPi(componentName.replace(/\s+/g, '')); + isComponent = true; + } + + return { + type: el.nodeName, + selection: elementName, + controller: ControllerFactory.getController(controller), + pi: pi, + props3d: Montage.create(Properties3D), + shapeModel: shapeModel, + isShape: isShape, + isComponent: isComponent + } +}; + +var elementNameToController = function(name) { + if(name === "div" || name === "custom") { + return "block"; + } else if(name === "img") { + return "image"; + } else { + return name; + } +}; + +var elementNameToPi = function(name) { + if(!name) return null; + + var piString = name + "Pi"; + + if(!PiData.hasOwnProperty(piString)) { + piString = "blockPi"; + } + + return piString; +}; + +var elmo = exports.ElementModel = Montage.create(Montage, { key: { value: "_model_"}, type: { value: null }, // Tag type that was created -- cgit v1.2.3 From 488ae8d98deb30009cb8b5b2da464fe52940050b Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 6 Jun 2012 16:20:25 -0700 Subject: fixing a rotation and zoom bug Signed-off-by: Valerio Virgillito --- js/models/element-model.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'js/models') diff --git a/js/models/element-model.js b/js/models/element-model.js index ea25e5b1..c9fb58d8 100755 --- a/js/models/element-model.js +++ b/js/models/element-model.js @@ -28,9 +28,7 @@ var modelGenerator = exports.modelGenerator = function() { }) }); - if(this._model.selection === "body") { - this._model.props3D.init(this, true); - } else { + if(this._model.selection !== "body") { this._model.props3D.init(this, false); } -- cgit v1.2.3