aboutsummaryrefslogtreecommitdiff
path: root/js/panels/css-panel/rule-list.reel/rule-list.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/panels/css-panel/rule-list.reel/rule-list.js')
-rw-r--r--js/panels/css-panel/rule-list.reel/rule-list.js116
1 files changed, 116 insertions, 0 deletions
diff --git a/js/panels/css-panel/rule-list.reel/rule-list.js b/js/panels/css-panel/rule-list.reel/rule-list.js
new file mode 100644
index 00000000..4ed3ec11
--- /dev/null
+++ b/js/panels/css-panel/rule-list.reel/rule-list.js
@@ -0,0 +1,116 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */
6
7var Montage = require("montage/core/core").Montage,
8 Component = require("montage/ui/component").Component;
9
10exports.RuleList = Montage.create(Component, {
11 focusDelegate : { value: null },
12 ruleNodeName : { value: 'li' },
13 _needsScrollToBottom: { value: null },
14
15 _rules: { value: null },
16 rules: {
17 get: function() {
18 return this._rules;
19 },
20 set: function(list) {
21 if(!list) {
22 return null;
23 }
24 //debugger;
25 console.log('list: ', list);
26 this._rules = list;
27
28 ///// remove previsouly added rules
29 if(this.childComponents){
30 this.childComponents.forEach(function(ruleComponent) {
31 this.removeRule(ruleComponent);
32 }, this);
33 }
34
35 this._rules.forEach(function(rule) {
36 this.addRule(rule);
37 }, this);
38
39 this.needsDraw = true;
40
41 }
42 },
43
44 childComponents : {
45 value: [],
46 distinct: true
47 },
48
49 rulesToDraw : {
50 value: [],
51 distinct: true
52 },
53
54 addRule: {
55 value: function(rule) {
56 var componentBase = this.supportedRules[rule.type],
57 instance, el;
58
59 ///// Draw the rule if we have a template for the rule type
60 if(componentBase) {
61 instance = Montage.create(componentBase);
62 instance.rule = rule;
63
64 if(this.focusDelegate) {
65 instance.focusDelegate = this.focusDelegate;
66 }
67
68 this.rulesToDraw.push(instance);
69 this.needsDraw = true;
70 }
71
72 return instance;
73 }
74 },
75
76 update : {
77 value: function() {
78 this.childComponents.forEach(function(component) {
79 component.update();
80 }, this);
81
82 //// TODO: find new styles based on selection
83 }
84 },
85
86 willDraw : {
87 value: function() {
88 this.rulesToDraw.forEach(function(component) {
89 component.element = document.createElement(this.ruleNodeName);
90 }, this);
91
92 }
93 },
94
95 draw : {
96 value: function() {
97 ///// If needed, scroll to bottom
98 if(this._needsScrollToBottom) {
99 ///// Make sure the appended rule item is visible (scrolled-to)
100 this.element.scrollTop = this.element.offsetHeight;
101 console.log("Scroll top:", this.element.scrollTop);
102 this._needsScrollToBottom = false;
103 }
104
105 //// Iterate through all rules that need draw and append them
106 this.rulesToDraw.forEach(function(component) {
107 this.element.appendChild(component.element);
108 this._needsScrollToBottom = this.needsDraw = true;
109 component.needsDraw = true;
110 }, this);
111
112 ///// Null out any rules that were just drawn
113 this.rulesToDraw.length = 0;
114 }
115 }
116});