Skip to content

Commit afe48e5

Browse files
committed
list items are not toggle buttons
1 parent 884f833 commit afe48e5

File tree

2 files changed

+29
-32
lines changed

2 files changed

+29
-32
lines changed

services/static-webserver/client/source/class/osparc/service/ServiceList.js

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ qx.Class.define("osparc.service.ServiceList", {
3636
},
3737

3838
events: {
39-
"changeValue": "qx.event.type.Data",
39+
"changeSelected": "qx.event.type.Data",
4040
"serviceAdd": "qx.event.type.Data"
4141
},
4242

@@ -53,33 +53,26 @@ qx.Class.define("osparc.service.ServiceList", {
5353
},
5454

5555
members: {
56-
__buttonGroup: null,
5756
__filterGroup: null,
5857

5958
_applyModel: function(model) {
6059
this._removeAll();
61-
const group = this.__buttonGroup = new qx.ui.form.RadioGroup().set({
62-
allowEmptySelection: true
63-
});
6460

61+
this.__serviceListItem = [];
6562
model.toArray().forEach(service => {
66-
const button = new osparc.service.ServiceListItem(service);
63+
const item = new osparc.service.ServiceListItem(service);
6764
if (this.__filterGroup !== null) {
68-
button.subscribeToFilterGroup(this.__filterGroup);
65+
item.subscribeToFilterGroup(this.__filterGroup);
6966
}
70-
group.add(button);
71-
this._add(button);
72-
button.addListener("dbltap", () => {
73-
this.fireDataEvent("serviceAdd", button.getService());
74-
}, this);
75-
button.addListener("keypress", e => {
67+
this._add(item);
68+
item.addListener("tap", () => this.__setSelected(item));
69+
item.addListener("dbltap", () => this.fireDataEvent("serviceAdd", item.getService()), this);
70+
item.addListener("keypress", e => {
7671
if (e.getKeyIdentifier() === "Enter") {
77-
this.fireDataEvent("serviceAdd", button.getService());
72+
this.fireDataEvent("serviceAdd", item.getService());
7873
}
7974
}, this);
8075
});
81-
82-
group.addListener("changeValue", e => this.dispatchEvent(e.clone()), this);
8376
},
8477

8578
/**
@@ -88,37 +81,41 @@ qx.Class.define("osparc.service.ServiceList", {
8881
* @return Returns the model of the selected service or null if selection is empty.
8982
*/
9083
getSelected: function() {
91-
if (this.__buttonGroup && this.__buttonGroup.getSelection().length) {
92-
return this.__buttonGroup.getSelection()[0].getService();
84+
const items = this._getChildren();
85+
for (let i=0; i<items.length; i++) {
86+
const item = items[i];
87+
if (item.isVisible() && item.getSelected()) {
88+
return item.getService();
89+
}
9390
}
9491
return null;
9592
},
9693

94+
__setSelected: function(selectedItem) {
95+
this._getChildren().forEach(item => item.setSelected(item === selectedItem));
96+
this.fireDataEvent("changeSelected", selectedItem);
97+
},
98+
9799
/**
98100
* Function checking if the selection is empty or not
99101
*
100102
* @return True if no item is selected, false if there one or more item selected.
101103
*/
102104
isSelectionEmpty: function() {
103-
if (this.__buttonGroup == null) {
104-
return true;
105-
}
106-
return this.__buttonGroup.getSelection().length === 0;
105+
const selecetedItems = this._getChildren().filter(item => item.getSelected());
106+
selecetedItems.length === 0;
107107
},
108108

109109
/**
110110
* Function that selects the first visible button.
111111
*/
112112
selectFirstVisible: function() {
113-
if (this._hasChildren()) {
114-
const buttons = this._getChildren();
115-
let current = buttons[0];
116-
let i = 1;
117-
while (i<buttons.length && !current.isVisible()) {
118-
current = buttons[i++];
119-
}
120-
if (current.isVisible()) {
121-
this.__buttonGroup.setSelection([this._getChildren()[i-1]]);
113+
const items = this._getChildren();
114+
for (let i=0; i<items.length; i++) {
115+
const item = items[i];
116+
if (item.isVisible()) {
117+
this.__setSelected(item);
118+
return;
122119
}
123120
}
124121
}

services/static-webserver/client/source/class/osparc/workbench/ServiceCatalog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ qx.Class.define("osparc.workbench.ServiceCatalog", {
136136
});
137137
scrolledServices.add(serviceList);
138138

139-
this.__serviceList.addListener("changeValue", e => {
139+
this.__serviceList.addListener("changeSelected", e => {
140140
if (e.getData() && e.getData().getService()) {
141141
const selectedService = e.getData().getService();
142142
this.__changedSelection(selectedService.getKey());

0 commit comments

Comments
 (0)