Skip to content

Commit 01eabbe

Browse files
committed
better practises
1 parent f71e3ca commit 01eabbe

File tree

1 file changed

+33
-71
lines changed
  • services/static-webserver/client/source/class/osparc/form/tag

1 file changed

+33
-71
lines changed

services/static-webserver/client/source/class/osparc/form/tag/TagItem.js

Lines changed: 33 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -84,83 +84,53 @@ qx.Class.define("osparc.form.tag.TagItem", {
8484
},
8585

8686
members: {
87-
__tag: null,
88-
__description: null,
89-
__nameInput: null,
90-
__descriptionInput: null,
91-
__colorInput: null,
92-
__colorButton: null,
93-
__loadingIcon: null,
9487
__validationManager: null,
9588

9689
_createChildControlImpl: function(id) {
9790
let control;
9891
switch (id) {
9992
case "tag":
100-
// Tag sample on display mode
101-
if (this.__tag === null) {
102-
this.__tag = new osparc.ui.basic.Tag();
103-
this.bind("name", this.__tag, "value");
104-
this.bind("color", this.__tag, "color");
105-
}
106-
control = this.__tag;
93+
control = new osparc.ui.basic.Tag();
94+
this.bind("name", control, "value");
95+
this.bind("color", control, "color");
10796
break;
10897
case "description":
109-
// Description label on display mode
110-
if (this.__description === null) {
111-
this.__description = new qx.ui.basic.Label().set({
112-
rich: true
113-
});
114-
this.bind("description", this.__description, "value");
115-
}
116-
control = this.__description;
98+
control = new qx.ui.basic.Label().set({
99+
rich: true,
100+
allowGrowX: true,
101+
});
102+
this.bind("description", control, "value");
117103
break;
118104
case "name-input":
119-
// Tag name input in edit mode
120-
if (this.__nameInput === null) {
121-
this.__nameInput = new qx.ui.form.TextField().set({
122-
required: true
123-
});
124-
this.__validationManager.add(this.__nameInput);
125-
this.__nameInput.getContentElement().setAttribute("autocomplete", "off");
126-
}
127-
control = this.__nameInput;
105+
control = new qx.ui.form.TextField().set({
106+
required: true
107+
});
108+
this.__validationManager.add(control);
109+
control.getContentElement().setAttribute("autocomplete", "off");
128110
break;
129111
case "description-input":
130-
// Tag description input in edit mode
131-
if (this.__descriptionInput === null) {
132-
this.__descriptionInput = new qx.ui.form.TextArea().set({
133-
autoSize: true,
134-
minimalLineHeight: 1
135-
});
136-
}
137-
control = this.__descriptionInput;
112+
control = new qx.ui.form.TextArea().set({
113+
autoSize: true,
114+
minimalLineHeight: 1
115+
});
138116
break;
139117
case "color-input":
140-
// Color input in edit mode
141-
if (this.__colorInput === null) {
142-
this.__colorInput = new qx.ui.form.TextField().set({
143-
value: this.getColor(),
144-
width: 60,
145-
required: true
146-
});
147-
this.__colorInput.bind("value", this.getChildControl("color-button"), "backgroundColor");
148-
this.__colorInput.bind("value", this.getChildControl("color-button"), "textColor", {
149-
converter: value => osparc.utils.Utils.getContrastedBinaryColor(value)
150-
});
151-
this.__validationManager.add(this.__colorInput, osparc.utils.Validators.hexColor);
152-
}
153-
control = this.__colorInput;
118+
control = new qx.ui.form.TextField().set({
119+
value: this.getColor(),
120+
width: 60,
121+
required: true
122+
});
123+
control.bind("value", this.getChildControl("color-button"), "backgroundColor");
124+
control.bind("value", this.getChildControl("color-button"), "textColor", {
125+
converter: value => osparc.utils.Utils.getContrastedBinaryColor(value)
126+
});
127+
this.__validationManager.add(control, osparc.utils.Validators.hexColor);
154128
break;
155129
case "color-button":
156-
// Random color generator button in edit mode
157-
if (this.__colorButton === null) {
158-
this.__colorButton = new qx.ui.form.Button(null, "@FontAwesome5Solid/sync-alt/12");
159-
this.__colorButton.addListener("execute", () => {
160-
this.getChildControl("color-input").setValue(osparc.utils.Utils.getRandomColor());
161-
}, this);
162-
}
163-
control = this.__colorButton;
130+
control = new qx.ui.form.Button(null, "@FontAwesome5Solid/sync-alt/12");
131+
control.addListener("execute", () => {
132+
this.getChildControl("color-input").setValue(osparc.utils.Utils.getRandomColor());
133+
}, this);
164134
break;
165135
}
166136
return control || this.base(arguments, id);
@@ -212,16 +182,8 @@ qx.Class.define("osparc.form.tag.TagItem", {
212182
},
213183

214184
__renderDisplayMode: function() {
215-
const tagContainer = new qx.ui.container.Composite(new qx.ui.layout.HBox()).set({
216-
width: 100
217-
});
218-
tagContainer.add(this.getChildControl("tag"));
219-
this._add(tagContainer);
220-
const descriptionContainer = new qx.ui.container.Composite(new qx.ui.layout.HBox());
221-
descriptionContainer.add(this.getChildControl("description"), {
222-
width: "100%"
223-
});
224-
this._add(descriptionContainer, {
185+
this._add(this.getChildControl("tag"));
186+
this._add(this.getChildControl("description"), {
225187
flex: 1
226188
});
227189
this._add(this.__tagItemButtons());

0 commit comments

Comments
 (0)