Skip to content

Commit

Permalink
Select button
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz committed Dec 9, 2024
1 parent 2712dfe commit 4c0e3c5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ qx.Class.define("osparc.study.PricingUnitTier", {
extend: osparc.study.PricingUnit,

events: {
"selectPricingUnit": "qx.event.type.Event",
},

properties: {
Expand All @@ -35,6 +36,13 @@ qx.Class.define("osparc.study.PricingUnitTier", {
nullable: true,
event: "changeShowUnitExtraInfo"
},

showSelectButton: {
check: "Boolean",
init: false,
nullable: true,
event: "changeShowSelectButton"
},
},

members: {
Expand All @@ -60,6 +68,26 @@ qx.Class.define("osparc.study.PricingUnitTier", {
});
this._add(control);
break;
case "select-button":
control = new qx.ui.form.Button().set({
appearance: "strong-button",
center: true,
});
this.bind("value", control, "label", {
converter: value => value ? "Selected" : "Select"
});
this.bind("value", control, "enabled", {
converter: value => !value
});
this.bind("showSelectButton", control, "visibility", {
converter: show => show ? "visible" : "excluded"
});
control.addListener("execute", () => {
this.setValue(true);
this.fireEvent("selectPricingUnit");
});
this._add(control);
break;
}
return control || this.base(arguments, id);
},
Expand Down Expand Up @@ -90,6 +118,9 @@ qx.Class.define("osparc.study.PricingUnitTier", {
});
unitExtraInfo.setValue(text);

// add select button
this.getChildControl("select-button");

// add edit button
this.getChildControl("edit-button");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ qx.Class.define("osparc.study.PricingUnits", {
const buttons = [];
pricingUnitsData.forEach(pricingUnitData => {
const pricingUnit = new osparc.data.model.PricingUnit(pricingUnitData);
const button = new osparc.study.PricingUnitTier(pricingUnit);
const button = new osparc.study.PricingUnitTier(pricingUnit).set({
showSelectButton: changeSelectionAllowed,
});
buttons.push(button);
this._add(button);
});
Expand Down Expand Up @@ -74,13 +76,18 @@ qx.Class.define("osparc.study.PricingUnits", {
if (!changeSelectionAllowed) {
button.setCursor("default");
}
button.addListener("execute", () => {
if (changeSelectionAllowed) {
const selectedUnitId = button.getUnitData().getPricingUnitId();
this.setSelectedUnitId(selectedUnitId);
} else {
buttons.forEach(btn => btn.setValue(btn.getUnitData().getIsDefault()));
}
[
"execute",
"selectPricingUnit",
].forEach(ev => {
button.addListener(ev, () => {
if (changeSelectionAllowed) {
const selectedUnitId = button.getUnitData().getPricingUnitId();
this.setSelectedUnitId(selectedUnitId);
} else {
buttons.forEach(btn => btn.setValue(btn.getUnitData().getIsDefault()));
}
});
});
});
}
Expand Down

0 comments on commit 4c0e3c5

Please sign in to comment.