1818qx . 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