Skip to content

Commit 9ea8609

Browse files
committed
refactor
1 parent e4820a5 commit 9ea8609

File tree

1 file changed

+16
-26
lines changed
  • services/static-webserver/client/source/class/osparc/desktop/preferences/pages

1 file changed

+16
-26
lines changed

services/static-webserver/client/source/class/osparc/desktop/preferences/pages/TagsPage.js

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,34 @@ qx.Class.define("osparc.desktop.preferences.pages.TagsPage", {
3535
flex: 1
3636
});
3737

38-
this.__createComponents();
38+
this.__renderLayout();
3939
},
4040

4141
members: {
4242
__tagsContainer: null,
4343
__addTagButton: null,
44-
__tagItems: null,
4544

46-
__createComponents: function() {
45+
__renderLayout: function() {
46+
const tags = osparc.store.Tags.getInstance().getTags();
47+
const tagItems = tags.map(tag => new osparc.form.tag.TagItem().set({tag}));
48+
tagItems.forEach(tagItem => {
49+
this.__tagsContainer.add(tagItem);
50+
this.__attachTagItemEvents(tagItem);
51+
});
52+
4753
this.__addTagButton = new qx.ui.form.Button().set({
4854
appearance: "form-button-outlined",
4955
label: this.tr("New Tag"),
5056
icon: "@FontAwesome5Solid/plus/14"
5157
});
5258
osparc.utils.Utils.setIdToWidget(this.__addTagButton, "addTagBtn");
53-
const tags = osparc.store.Tags.getInstance().getTags();
54-
this.__tagItems = tags.map(tag => new osparc.form.tag.TagItem().set({tag}));
55-
this.__renderLayout();
56-
this.__attachEventHandlers();
57-
},
58-
59-
__renderLayout: function() {
60-
this.__tagsContainer.removeAll();
61-
62-
// Print tag items
63-
this.__tagItems.forEach(tagItem => this.__tagsContainer.add(tagItem));
59+
this.__addTagButton.addListener("execute", () => {
60+
const newItem = new osparc.form.tag.TagItem().set({
61+
mode: osparc.form.tag.TagItem.modes.EDIT
62+
});
63+
this.__tagsContainer.add(newItem);
64+
this.__attachTagItemEvents(newItem);
65+
});
6466

6567
// New tag button
6668
const buttonContainer = new qx.ui.container.Composite(new qx.ui.layout.HBox().set({
@@ -70,18 +72,6 @@ qx.Class.define("osparc.desktop.preferences.pages.TagsPage", {
7072
this._add(buttonContainer);
7173
},
7274

73-
__attachEventHandlers: function() {
74-
this.__addTagButton.addListener("execute", () => {
75-
const itemCount = this.__tagsContainer.getChildren().length;
76-
const newItem = new osparc.form.tag.TagItem().set({
77-
mode: osparc.form.tag.TagItem.modes.EDIT
78-
});
79-
this.__attachTagItemEvents(newItem);
80-
this.__tagsContainer.addAt(newItem, Math.max(0, itemCount - 1));
81-
});
82-
this.__tagItems.forEach(tagItem => this.__attachTagItemEvents(tagItem));
83-
},
84-
8575
__attachTagItemEvents: function(tagItem) {
8676
tagItem.addListener("cancelNewTag", e => this.__tagsContainer.remove(e.getTarget()), this);
8777
tagItem.addListener("deleteTag", e => this.__tagsContainer.remove(e.getTarget()));

0 commit comments

Comments
 (0)