From dbd3a60478db35b0b12baa2ca54a0712d880951f Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Fri, 3 Feb 2012 15:50:35 -0800 Subject: button component using json data Signed-off-by: Valerio Virgillito --- js/controllers/elements/component-controller.js | 8 ++- js/data/pi/pi-data.js | 20 -------- .../ComponentsPanelBase.js | 60 +++++++++++++++++++--- 3 files changed, 59 insertions(+), 29 deletions(-) diff --git a/js/controllers/elements/component-controller.js b/js/controllers/elements/component-controller.js index 7a8acb3a..1b0591be 100644 --- a/js/controllers/elements/component-controller.js +++ b/js/controllers/elements/component-controller.js @@ -15,8 +15,11 @@ exports.ComponentController = Montage.create(ElementController, { case "label": return this.application.ninja.currentDocument.getComponentFromElement(el).label; break; + case "enabled": + return this.application.ninja.currentDocument.getComponentFromElement(el).enabled; + break; default: - return ElementController.getProperty(el, prop); + return ElementController.getProperty(el, prop, true); } } }, @@ -27,6 +30,9 @@ exports.ComponentController = Montage.create(ElementController, { case "label": this.application.ninja.currentDocument.getComponentFromElement(el).label = value; break; + case "enabled": + this.application.ninja.currentDocument.getComponentFromElement(el).enabled = value; + break; default: ElementController.setProperty(el, p, value); } diff --git a/js/data/pi/pi-data.js b/js/data/pi/pi-data.js index 9edb0399..de5cd34d 100644 --- a/js/data/pi/pi-data.js +++ b/js/data/pi/pi-data.js @@ -525,26 +525,6 @@ exports.PiData = Montage.create( Montage, { ] } ] - }, - - componentPi: { - value: [ - { - label: "Button", - - Section: [ - [ - { - type: "textbox", - id: "Label", - prop: "label", - defaultValue: "Button", - label: "Label" - } - ] - ] - } - ] } }); diff --git a/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js b/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js index 8c81b3ab..d9decd2c 100644 --- a/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js +++ b/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js @@ -4,11 +4,12 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -var Montage = require("montage/core/core").Montage, - Component = require("montage/ui/component").Component, - NJUtils = require("js/lib/NJUtils").NJUtils; +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component, + NJUtils = require("js/lib/NJUtils").NJUtils; -var treeControlModule = require("js/components/tree.reel"); +var treeControlModule = require("js/components/tree.reel"); +var PIData = require("js/data/pi/pi-data").PiData; var ComponentsPanelBase = exports.ComponentsPanelBase = Montage.create(Component, { @@ -29,6 +30,11 @@ var ComponentsPanelBase = exports.ComponentsPanelBase = Montage.create(Component "name": "label", "type": "string", "default": "Button" + }, + { + "name": "enabled", + "type": "boolean", + "default": "true" } ] } @@ -43,8 +49,48 @@ var ComponentsPanelBase = exports.ComponentsPanelBase = Montage.create(Component _loadComponents: { value: function() { this.components = [ - {component: "Button", data: "montage/ui/button.reel/button.json"} + {name: "Button", data: "montage/ui/button.reel/button.json"} ]; + + // Build the PI objects for each component + for(var i = 0, component; component = this.components[i]; i++) { + var piIdentifier = component.name + "Pi"; + var piObj = []; + var section = {}; + + + section.label = component.name + " Properties"; + section.Section = []; + + for(var j = 0, props; props = this._testButtonJson.properties[j]; j++) { + var row = {}; + row.type = this.getControlType(props.type); + row.id = props.name; + row.prop = props.name; + row.defaultValue = props["default"]; + row.label = props.name; + + section.Section.push([row]); + } + + PIData[piIdentifier] = []; + PIData[piIdentifier].push(section); + + } + + } + }, + + getControlType: { + value: function(type) { + switch(type) { + case "string": + return "textbox"; + case "boolean": + return "checkbox"; + default: + alert("Conversion not implemented for ", type); + } } }, @@ -135,7 +181,7 @@ var ComponentsPanelBase = exports.ComponentsPanelBase = Montage.create(Component value: function(name) { var el; el = NJUtils.makeNJElement(name, "Button", "component"); - //el.elementModel.pi = "buttonPi"; + el.elementModel.pi = "ButtonPi"; el.setAttribute("type", "button"); return el; } @@ -151,11 +197,9 @@ var ComponentsPanelBase = exports.ComponentsPanelBase = Montage.create(Component if(componentType == "Button"){ componentEl = NJUtils.makeNJElement("button", componentType, "component");//, {"type": "button"}); componentEl.setAttribute("type", "button"); - //componentEl.innerHTML = "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; -- cgit v1.2.3