18
18
qx . Class . define ( "osparc.study.PricingUnits" , {
19
19
extend : qx . ui . container . Composite ,
20
20
21
- construct : function ( pricingUnits , preselectedPricingUnit ) {
21
+ construct : function ( pricingUnits , preselectedPricingUnit , changeSelectionAllowed = true ) {
22
22
this . base ( arguments ) ;
23
23
24
24
this . set ( {
25
- layout : new qx . ui . layout . HBox ( 5 )
25
+ layout : new qx . ui . layout . HBox ( 5 ) ,
26
+ allowGrowY : false ,
26
27
} ) ;
27
28
28
- this . __buildLayout ( pricingUnits , preselectedPricingUnit ) ;
29
+ this . __buildLayout ( pricingUnits , preselectedPricingUnit , changeSelectionAllowed ) ;
29
30
} ,
30
31
31
32
properties : {
@@ -38,7 +39,7 @@ qx.Class.define("osparc.study.PricingUnits", {
38
39
} ,
39
40
40
41
members : {
41
- __buildLayout : function ( pricingUnits , preselectedPricingUnit ) {
42
+ __buildLayout : function ( pricingUnits , preselectedPricingUnit , changeSelectionAllowed ) {
42
43
const buttons = [ ] ;
43
44
pricingUnits . forEach ( pricingUnit => {
44
45
const button = new osparc . study . PricingUnit ( pricingUnit ) ;
@@ -47,7 +48,12 @@ qx.Class.define("osparc.study.PricingUnits", {
47
48
} ) ;
48
49
49
50
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
+ } ) ;
51
57
52
58
if ( preselectedPricingUnit ) {
53
59
const buttonFound = buttons . find ( button => button . getUnitData ( ) . getPricingUnitId ( ) === preselectedPricingUnit [ "pricingUnitId" ] ) ;
@@ -63,12 +69,19 @@ qx.Class.define("osparc.study.PricingUnits", {
63
69
} ) ;
64
70
}
65
71
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" ) ;
70
75
}
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
+ } ) ;
72
85
}
73
86
}
74
87
} ) ;
0 commit comments