git @ Cat's Eye Technologies Lexeduct / a5397ee
I love these partial refactors without unit tests or anything Chris Pressey 6 years ago
1 changed file(s) with 33 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
3333 transformersPanel.style.display = "inline-block";
3434 transformersPanel.style.verticalAlign = "top";
3535
36 var MAX_TRANSFORMERS = 8; // TODO dynamic
36 var MAX_TRANSFORMER_SLOTS = 8; // TODO dynamic
3737 var transformerSlots = [];
3838
3939 var transformerNames = [["identity", "---"]];
5555 }
5656 }
5757 return cfg;
58 };
59
60 var makeParametersPanel = function(container, parameters) {
61 var panel = yoob.makeDiv(container);
62 for (var key in parameters) {
63 if (parameters.hasOwnProperty(key)) {
64 var label = yoob.makeSpan(panel, key);
65 label.style.width = "50%";
66 var input = yoob.makeTextInput(panel, 24);
67 input.style.width = "50%";
68 // TODO: populate it with the default
69 yoob.makeLineBreak(panel);
70 }
71 }
72 return panel;
7358 };
7459
7560 var process = function() {
9782 });
9883 yoob.makeLineBreak(transformersPanel);
9984
100 for (var i = 0; i < MAX_TRANSFORMERS; i++) {
101 // XXX this now needs to be a closure to captur variables correctly
85 var updateParametersPanel = function(panel, parameters) {
86 panel.innerHTML = ""; // delete any previous controls
87 for (var key in parameters) {
88 if (parameters.hasOwnProperty(key)) {
89 var label = yoob.makeSpan(panel, key);
90 label.style.width = "50%";
91 var input = yoob.makeTextInput(panel, 24);
92 input.style.width = "50%";
93 // TODO: populate it with the default
94 input.onchange = function() {
95 alert('TODO: update transformerSlots.selectedParameters or smth here');
96 if (liveMode) {
97 process();
98 }
99 }
100 yoob.makeLineBreak(panel);
101 }
102 }
103 };
104
105 var makeTransformerSlot = function(container, index) {
102106 var select = yoob.makeSelect(
103107 transformersPanel, "Transformer " + (i+1), transformerNames
104108 );
105109 yoob.makeLineBreak(transformersPanel);
106 var panelContainer = yoob.makeDiv(transformersPanel);
110 var parametersPanel = yoob.makeDiv(transformersPanel);
107111 select.onchange = function(e) {
108112 if (liveMode) {
109113 process();
110114 }
111 makeParametersPanel(panelContainer);
115 updateParametersPanel(parametersPanel);
112116 };
113117
114118 //------------ deprecated...
122126 yoob.makeLineBreak(transformersPanel);
123127 //------------
124128
129 return {
130 select: select,
131 optionsInput: optionsInput,
132 parametersPanel: parametersPanel
133 };
134 };
125135
126 transformerSlots.push({
127 select: select,
128 optionsInput: optionsInput
129 });
136 for (var i = 0; i < MAX_TRANSFORMER_SLOTS; i++) {
137 var slot = makeTransformerSlot(transformersPanel, index);
138 transformerSlots.push(slot);
130139 }
131140
132141 output = yoob.makeTextArea(container, 40, 20);