Skip to content

Commit 0bc2185

Browse files
🐛 [Frontend] Fix: Selected Pricing Unit bgColor (#6646)
Co-authored-by: Dustin Kaiser <[email protected]>
1 parent cdbaf0c commit 0bc2185

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,16 @@ qx.Class.define("osparc.service.PricingUnitsList", {
6464
__populateList: function(pricingUnits) {
6565
this.getChildControl("pricing-units-container").removeAll();
6666

67-
if (pricingUnits.length === 0) {
67+
if (pricingUnits.length) {
68+
const pUnits = new osparc.study.PricingUnits(pricingUnits, null, false);
69+
this.getChildControl("pricing-units-container").add(pUnits);
70+
} else {
6871
const notFound = new qx.ui.basic.Label().set({
6972
value: this.tr("No Tiers found"),
7073
font: "text-14"
7174
});
7275
this.getChildControl("pricing-units-container").add(notFound);
73-
return;
7476
}
75-
76-
pricingUnits.forEach(pricingUnit => {
77-
const pUnit = new osparc.study.PricingUnit(pricingUnit).set({
78-
allowGrowY: false
79-
});
80-
this.getChildControl("pricing-units-container").add(pUnit);
81-
});
82-
83-
const buttons = this.getChildControl("pricing-units-container").getChildren();
84-
const keepDefaultSelected = () => {
85-
buttons.forEach(btn => {
86-
btn.setValue(btn.getUnitData().isDefault());
87-
});
88-
};
89-
keepDefaultSelected();
90-
buttons.forEach(btn => btn.addListener("execute", () => keepDefaultSelected()));
9177
}
9278
}
9379
});

services/static-webserver/client/source/class/osparc/study/PricingUnits.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
qx.Class.define("osparc.study.PricingUnits", {
1919
extend: qx.ui.container.Composite,
2020

21-
construct: function(pricingUnits, preselectedPricingUnit) {
21+
construct: function(pricingUnits, preselectedPricingUnit, changeSelectionAllowed = true) {
2222
this.base(arguments);
2323

2424
this.set({
25-
layout: new qx.ui.layout.HBox(5)
25+
layout: new qx.ui.layout.HBox(5),
26+
allowGrowY: false,
2627
});
2728

28-
this.__buildLayout(pricingUnits, preselectedPricingUnit);
29+
this.__buildLayout(pricingUnits, preselectedPricingUnit, changeSelectionAllowed);
2930
},
3031

3132
properties: {
@@ -38,7 +39,7 @@ qx.Class.define("osparc.study.PricingUnits", {
3839
},
3940

4041
members: {
41-
__buildLayout: function(pricingUnits, preselectedPricingUnit) {
42+
__buildLayout: function(pricingUnits, preselectedPricingUnit, changeSelectionAllowed) {
4243
const buttons = [];
4344
pricingUnits.forEach(pricingUnit => {
4445
const button = new osparc.study.PricingUnit(pricingUnit);
@@ -47,7 +48,12 @@ qx.Class.define("osparc.study.PricingUnits", {
4748
});
4849

4950
const groupOptions = new qx.ui.form.RadioGroup();
50-
buttons.forEach(btn => groupOptions.add(btn));
51+
buttons.forEach(btn => {
52+
groupOptions.add(btn);
53+
btn.bind("value", btn, "backgroundColor", {
54+
converter: selected => selected ? "background-main-1" : "transparent"
55+
});
56+
});
5157

5258
if (preselectedPricingUnit) {
5359
const buttonFound = buttons.find(button => button.getUnitData().getPricingUnitId() === preselectedPricingUnit["pricingUnitId"]);
@@ -63,12 +69,19 @@ qx.Class.define("osparc.study.PricingUnits", {
6369
});
6470
}
6571

66-
buttons.forEach(button => button.addListener("changeValue", e => {
67-
if (e.getData()) {
68-
const selectedUnitId = button.getUnitData().getPricingUnitId();
69-
this.setSelectedUnitId(selectedUnitId);
72+
buttons.forEach(button => {
73+
if (!changeSelectionAllowed) {
74+
button.setCursor("default");
7075
}
71-
}));
76+
button.addListener("execute", () => {
77+
if (changeSelectionAllowed) {
78+
const selectedUnitId = button.getUnitData().getPricingUnitId();
79+
this.setSelectedUnitId(selectedUnitId);
80+
} else {
81+
buttons.forEach(btn => btn.setValue(btn.getUnitData().isDefault()));
82+
}
83+
});
84+
});
7285
}
7386
}
7487
});

0 commit comments

Comments
 (0)