From 47df0aff81c25334b129047bb227ea5015357eda Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Thu, 9 Feb 2012 16:22:03 -0800 Subject: Setting defaults and more cleanup Signed-off-by: Valerio Virgillito --- js/controllers/elements/component-controller.js | 12 ++ .../ComponentsPanelBase.js | 65 ++-------- node_modules/components-data/textfield.json | 4 +- .../montage-application-cloud/main.reel/main.js | 141 ++------------------- 4 files changed, 34 insertions(+), 188 deletions(-) diff --git a/js/controllers/elements/component-controller.js b/js/controllers/elements/component-controller.js index 1b0591be..33b9b79a 100644 --- a/js/controllers/elements/component-controller.js +++ b/js/controllers/elements/component-controller.js @@ -18,6 +18,12 @@ exports.ComponentController = Montage.create(ElementController, { case "enabled": return this.application.ninja.currentDocument.getComponentFromElement(el).enabled; break; + case "disabled": + return this.application.ninja.currentDocument.getComponentFromElement(el).disabled; + break; + case "value": + return this.application.ninja.currentDocument.getComponentFromElement(el).value; + break; default: return ElementController.getProperty(el, prop, true); } @@ -33,6 +39,12 @@ exports.ComponentController = Montage.create(ElementController, { case "enabled": this.application.ninja.currentDocument.getComponentFromElement(el).enabled = value; break; + case "disabled": + this.application.ninja.currentDocument.getComponentFromElement(el).disabled = value; + break; + case "value": + this.application.ninja.currentDocument.getComponentFromElement(el).value = value; + break; default: ElementController.setProperty(el, p, value); } diff --git a/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js b/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js index 33241d42..953c0484 100644 --- a/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js +++ b/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js @@ -160,7 +160,7 @@ var ComponentsPanelBase = exports.ComponentsPanelBase = Montage.create(Component var that = this; var element = this.makeComponent(component.component); - this.application.ninja.currentDocument._window.addComponent(element, {type: component.name, path: component.module, name: "Button"}, function(instance, element) { + this.application.ninja.currentDocument._window.addComponent(element, {name: component.name, path: component.module}, function(instance, element) { var pos = that.getStageCenter(); @@ -181,73 +181,24 @@ var ComponentsPanelBase = exports.ComponentsPanelBase = Montage.create(Component makeComponent: { value: function(name) { + var el; + switch(name) { case "button": - var el; el = NJUtils.makeNJElement(name, "Button", "component"); el.elementModel.pi = "ButtonPi"; el.setAttribute("type", "button"); - return el; + el.innerHTML = "Button"; + break; case "textfield": { - var el; - el = NJUtils.makeNJElement("input", "Text Field", "component"); + el = NJUtils.makeNJElement("input", "Textfield", "component"); el.elementModel.pi = "TextfieldPi"; el.setAttribute("type", "text"); - return el; + break; } } - } - }, - - ___addComponentToStage:{ - value:function(component, dropX, dropY){ -// var compW = 100, -// compH = 100, -// - var componentEl, componentInstance; - - if(componentType == "Button"){ - componentEl = NJUtils.makeNJElement("button", componentType, "component");//, {"type": "button"}); - componentEl.setAttribute("type", "button"); - - componentInstance = this.application.ninja.currentDocument._window.addComponent(componentEl, {type: componentType, path: "montage/ui/button.reel", name: "Button"}, this.callback); - - }else if(componentType == "Checkbox"){ - compW = 53; - compH = 53; -// elementType = "input"; - } - - /* - componentContainer = NJUtils.makeNJElement("div", componentType, "component"); - componentContainer.elementModel.isComponent = true; - */ - var styles = { - 'position': 'absolute', - 'top' : dropY + 'px', - 'left' : dropX + 'px', -// 'width' : compW + 'px', -// 'height' : compH + 'px', - '-webkit-transform-style' : 'preserve-3d', - '-webkit-transform' : 'perspective(1400) matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' - }; - - - //componentElement = NJUtils.makeNJElement(elementType, "ComponentDiv", "block"); - - //componentContainer.appendChild(componentElement); - - this.application.ninja.currentDocument.setComponentInstance(componentInstance, componentEl); - - NJevent("elementAdding", {"el": componentEl, "data":styles}); - /* - var componentRef = this.application.ninja.currentDocument._window.addComponent(componentElement, componentType); - - */ - - - + return el; } }, diff --git a/node_modules/components-data/textfield.json b/node_modules/components-data/textfield.json index 2a21394a..4f8a1499 100644 --- a/node_modules/components-data/textfield.json +++ b/node_modules/components-data/textfield.json @@ -13,9 +13,9 @@ "default": "Button" }, { - "name": "enabled", + "name": "disabled", "type": "boolean", - "default": "true" + "default": "false" } ] } \ No newline at end of file diff --git a/user-document-templates/montage-application-cloud/main.reel/main.js b/user-document-templates/montage-application-cloud/main.reel/main.js index 2e331cdc..86871fd3 100644 --- a/user-document-templates/montage-application-cloud/main.reel/main.js +++ b/user-document-templates/montage-application-cloud/main.reel/main.js @@ -32,140 +32,23 @@ exports.Main = Montage.create(Component, { }, addComponentToUserDocument:{ - value:function(containerElement, componentType, callback){ - var component = null; - switch(componentType.type){ - case "Button": + value:function(element, data, callback){ - var button = require.async(componentType.path) - .then(function (button) { - var buttonObj = button["Button"]; - var btIns = buttonObj.create(); + var component; - btIns.element = containerElement; - btIns.deserializedFromTemplate(); + component = require.async(data.path) + .then(function(component) { + var componentRequire = component[data.name]; + var componentInstance = componentRequire.create(); - btIns.needsDraw = true; - btIns.label = "Button"; - callback(btIns, containerElement); - }) - .end(); + componentInstance.element = element; + componentInstance.deserializedFromTemplate(); + componentInstance.needsDraw = true; - break; - case "Textfield": - var tf = require.async(componentType.path) - .then(function (tf) { - var buttonObj = tf["Textfield"]; - var btIns = buttonObj.create(); + callback(componentInstance, element); + }) + .end(); - btIns.element = containerElement; - btIns.deserializedFromTemplate(); - - btIns.needsDraw = true; - btIns.value = "Button"; - callback(btIns, containerElement); - }) - .end(); - break - case "Checkbox": - component = Checkbox.create(); - component.element = containerElement; - component.needsDraw = true; - break; - case "Condition": - component = Condition.create(); - component.element = containerElement; - component.needsDraw = true; - break; - case "DynamicText": - component = DynamicText.create(); - component.element = containerElement; - component.value = "Label"; - component.needsDraw = true; - break; - case "HotText": - component = HotText.create(); - component.element = containerElement; - component.needsDraw = true; - break; - case "HotTextUnit": - component = HotTextUnit.create(); - component.element = containerElement; - component.needsDraw = true; - break; - case "FlowController": - component = FlowController.create(); - component.element = containerElement; - component.needsDraw = true; - break; - case "ImageContainer": - component = ImageContainer.create(); - component.element = containerElement; - component.element.style.width = "285px"; - component.element.style.height = "235px"; - component.src = "placeholder.jpg"; - component.needsDraw = true; - break; - case "Progress": - component = Progress.create(); - component.element = containerElement; - component.loading = true; - component.needsDraw = true; - break; - case "Repetition": - component = Repetition.create(); - component.element = containerElement; - component.needsDraw = true; - break; - case "Scrollview": - component = Scrollview.create(); - component.element = containerElement; - component.element.style.width = "200px"; - component.element.style.height = "200px"; - var dummyContent = document.createElement("div"); - dummyContent.innerHTML = ""; - component.element.appendChild(dummyContent); - component.needsDraw = true; - break; - case "Slider": - component = Slider.create(); - component.element = containerElement; -// component.value = 0; -// component._minValue = 0; -// component._maxValue = 100; - component.needsDraw = true; - break; - case "Slot": - component = Slot.create(); - component.element = containerElement; - component.needsDraw = true; - break; - case "Substitution": - component = Substitution.create(); - component.element = containerElement; - component.needsDraw = true; - break; - case "TextArea": - component = TextArea.create(); - component.element = containerElement; - component.needsDraw = true; - break; - case "Toggle": - component = Toggle.create(); - component.element = containerElement; - component.needsDraw = true; - break; - case "ToggleButton": - component = ToggleButton.create(); - component.element = containerElement; - component.element.classList.add("text"); - component.needsDraw = true; - break; - default: - console.log("Unrecognized component type"); - } - //console.log(component); - return component; } } -- cgit v1.2.3