From c0fce534c255ef1e25779e2f0e8de95bb4e160cf Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Mon, 23 Apr 2012 11:55:08 -0700 Subject: CSS Panel - Add styles view delegate. Add handling for adding rules to stylesheets --- js/panels/css-panel/rule-list.reel/rule-list.js | 112 +++++++++++++----------- 1 file changed, 61 insertions(+), 51 deletions(-) (limited to 'js/panels/css-panel/rule-list.reel/rule-list.js') diff --git a/js/panels/css-panel/rule-list.reel/rule-list.js b/js/panels/css-panel/rule-list.reel/rule-list.js index 44d6d864..ebd7428b 100644 --- a/js/panels/css-panel/rule-list.reel/rule-list.js +++ b/js/panels/css-panel/rule-list.reel/rule-list.js @@ -8,15 +8,10 @@ var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component; exports.RuleList = Montage.create(Component, { - hasTemplate: { - value: true - }, - listElement : { - value: null - }, - _rules: { - value: null - }, + + ruleNodeName : { value: 'li' }, + + _rules: { value: null }, rules: { get: function() { return this._rules; @@ -28,62 +23,77 @@ exports.RuleList = Montage.create(Component, { //debugger; console.log('list: ', list); this._rules = list; + + ///// remove previsouly added rules + if(this.childComponents){ + this.childComponents.forEach(function(ruleComponent) { + this.removeRule(ruleComponent); + }, this); + } + + this._rules.forEach(function(rule) { + this.addRule(rule); + }, this); + this.needsDraw = true; - this._needsAppend = true; + } }, - templateDidLoad : { - value: function() { - console.log("Rule List : template did load"); - //this.condition = true; - this.needsDraw = true; - //debugger; - } + + childComponents : { + value: [], + distinct: true }, - prepareForDraw : { - value: function() { - console.log("Rule List : prepare for draw"); - } + + rulesToDraw : { + value: [], + distinct: true }, - draw : { - value: function() { - console.log("Rule List - Draw"); - if(this._needsAppend) { - this._rules.forEach(function(rule) { - var componentBase = this.supportedRules[rule.type], - instance, el; - - if(componentBase) { - el = document.createElement(this.ruleNodeName); - instance = Montage.create(componentBase); - instance.element = el; - instance.rule = rule; - this.element.appendChild(instance.element); - instance.needsDraw = true; - } + addRule: { + value: function(rule) { + var componentBase = this.supportedRules[rule.type], + instance, el; - }, this); + ///// Draw the rule if we have a template for the rule type + if(componentBase) { + instance = Montage.create(componentBase); + instance.rule = rule; + this.rulesToDraw.push(instance); + this.needsDraw = true; } - console.log("Rule List : draw"); } }, - _createRuleComponent: { - value: function(ruleType) { + update : { + value: function() { + this.childComponents.forEach(function(component) { + component.update(); + }, this); + + //// TODO: find new styles based on selection } }, - ruleNodeName : { - value: 'li' + + willDraw : { + value: function() { + this.rulesToDraw.forEach(function(component) { + component.element = document.createElement(this.ruleNodeName); + }, this); + + } }, - ruleComponents : { - value: { - "1" : 'css-style-rule', - "3" : 'css-import-rule', - "4" : 'css-media-rule', - "5" : 'css-font-face-rule', - "6" : 'css-page-rule', - "10" : 'namespace-rule' + + draw : { + value: function() { + //// Iterate through all rules that need draw and append them + this.rulesToDraw.forEach(function(component) { + this.element.appendChild(component.element); + component.needsDraw = true; + }, this); + + ///// Null out any rules that were just drawn + this.rulesToDraw.length = 0; } } }); -- cgit v1.2.3