@@ -22,6 +22,7 @@ qx.Class.define("osparc.study.StudyOptions", {
2222 this . base ( arguments ) ;
2323
2424 this . _setLayout ( new qx . ui . layout . VBox ( 15 ) ) ;
25+ this . __buildLayout ( ) ;
2526
2627 if ( studyId ) {
2728 this . setStudyId ( studyId ) ;
@@ -42,7 +43,14 @@ qx.Class.define("osparc.study.StudyOptions", {
4243 nullable : true ,
4344 event : "changeWallet" ,
4445 apply : "__applyWallet"
45- }
46+ } ,
47+
48+ patchStudy : {
49+ check : "Boolean" ,
50+ init : false ,
51+ nullable : false ,
52+ event : "changePatchStudy" ,
53+ } ,
4654 } ,
4755
4856 events : {
@@ -80,7 +88,31 @@ qx.Class.define("osparc.study.StudyOptions", {
8088 } ) ;
8189 box . setLayout ( new qx . ui . layout . VBox ( 5 ) ) ;
8290 return box ;
83- }
91+ } ,
92+
93+ updateName : function ( studyData , name ) {
94+ return osparc . info . StudyUtils . patchStudyData ( studyData , "name" , name )
95+ . catch ( err => {
96+ console . error ( err ) ;
97+ const msg = err . message || qx . locale . Manager . tr ( "Something went wrong Renaming" ) ;
98+ osparc . FlashMessenger . logAs ( msg , "ERROR" ) ;
99+ } ) ;
100+ } ,
101+
102+ updateWallet : function ( studyId , walletId ) {
103+ const params = {
104+ url : {
105+ studyId,
106+ walletId,
107+ }
108+ } ;
109+ return osparc . data . Resources . fetch ( "studies" , "selectWallet" , params )
110+ . catch ( err => {
111+ console . error ( err ) ;
112+ const msg = err . message || qx . locale . Manager . tr ( "Error selecting Credit Account" ) ;
113+ osparc . FlashMessenger . getInstance ( ) . logAs ( msg , "ERROR" ) ;
114+ } ) ;
115+ } ,
84116 } ,
85117
86118 members : {
@@ -149,6 +181,24 @@ qx.Class.define("osparc.study.StudyOptions", {
149181 control = this . self ( ) . createGroupBox ( this . tr ( "Tiers" ) ) ;
150182 this . getChildControl ( "options-layout" ) . add ( control ) ;
151183 break ;
184+ case "study-pricing-units" : {
185+ const loadingImage = this . getChildControl ( "loading-units-spinner" ) ;
186+ const unitsBoxesLayout = this . getChildControl ( "services-resources-layout" ) ;
187+ const unitsLoading = ( ) => {
188+ loadingImage . show ( ) ;
189+ unitsBoxesLayout . exclude ( ) ;
190+ } ;
191+ const unitsReady = ( ) => {
192+ loadingImage . exclude ( ) ;
193+ unitsBoxesLayout . show ( ) ;
194+ } ;
195+ unitsLoading ( ) ;
196+ control = new osparc . study . StudyPricingUnits ( ) ;
197+ control . addListener ( "loadingUnits" , ( ) => unitsLoading ( ) ) ;
198+ control . addListener ( "unitsReady" , ( ) => unitsReady ( ) ) ;
199+ unitsBoxesLayout . add ( control ) ;
200+ break ;
201+ }
152202 case "buttons-layout" :
153203 control = new qx . ui . container . Composite ( new qx . ui . layout . HBox ( 5 ) . set ( {
154204 alignX : "right"
@@ -193,6 +243,8 @@ qx.Class.define("osparc.study.StudyOptions", {
193243 osparc . data . Resources . fetch ( "studies" , "getWallet" , params )
194244 ] )
195245 . then ( values => {
246+ this . setPatchChanges ( true ) ;
247+
196248 const studyData = values [ 0 ] ;
197249 this . setStudyData ( studyData ) ;
198250
@@ -205,6 +257,12 @@ qx.Class.define("osparc.study.StudyOptions", {
205257
206258 setStudyData : function ( studyData ) {
207259 this . __studyData = osparc . data . model . Study . deepCloneStudyObject ( studyData ) ;
260+
261+ const titleField = this . getChildControl ( "title-field" ) ;
262+ titleField . setValue ( this . __studyData [ "name" ] ) ;
263+
264+ const studyPricingUnits = this . getChildControl ( "study-pricing-units" ) ;
265+ studyPricingUnits . setStudyData ( this . __studyData ) ;
208266 } ,
209267
210268 __applyWallet : function ( wallet ) {
@@ -230,9 +288,6 @@ qx.Class.define("osparc.study.StudyOptions", {
230288 const store = osparc . store . Store . getInstance ( ) ;
231289
232290 const titleField = this . getChildControl ( "title-field" ) ;
233- if ( this . __studyData ) {
234- titleField . setValue ( this . __studyData [ "name" ] ) ;
235- }
236291 titleField . addListener ( "appear" , ( ) => {
237292 titleField . focus ( ) ;
238293 titleField . activate ( ) ;
@@ -267,21 +322,7 @@ qx.Class.define("osparc.study.StudyOptions", {
267322 } ,
268323
269324 __buildOptionsLayout : function ( ) {
270- const loadingImage = this . getChildControl ( "loading-units-spinner" ) ;
271- const unitsBoxesLayout = this . getChildControl ( "services-resources-layout" ) ;
272- const unitsLoading = ( ) => {
273- loadingImage . show ( ) ;
274- unitsBoxesLayout . exclude ( ) ;
275- } ;
276- const unitsReady = ( ) => {
277- loadingImage . exclude ( ) ;
278- unitsBoxesLayout . show ( ) ;
279- } ;
280- unitsLoading ( ) ;
281- const studyPricingUnits = new osparc . study . StudyPricingUnits ( this . __studyData ) ;
282- studyPricingUnits . addListener ( "loadingUnits" , ( ) => unitsLoading ( ) ) ;
283- studyPricingUnits . addListener ( "unitsReady" , ( ) => unitsReady ( ) ) ;
284- unitsBoxesLayout . add ( studyPricingUnits ) ;
325+ this . getChildControl ( "study-pricing-units" ) ;
285326 } ,
286327
287328 __buildButtons : function ( ) {
@@ -297,48 +338,34 @@ qx.Class.define("osparc.study.StudyOptions", {
297338 const openButton = this . getChildControl ( "open-button" ) ;
298339 openButton . setFetching ( true ) ;
299340
300- // first, update the name if necessary
301- const titleSelection = this . getChildControl ( "title-field" ) . getValue ( ) ;
302- if ( this . __studyData && this . __studyData [ "name" ] !== titleSelection ) {
303- await this . __updateName ( this . __studyData , titleSelection ) ;
304- }
341+ if ( this . isPatchStudy ( ) ) {
342+ // first, update the name if necessary
343+ const titleSelection = this . getChildControl ( "title-field" ) . getValue ( ) ;
344+ if ( this . __studyData [ "name" ] !== titleSelection ) {
345+ await this . self ( ) . updateName ( this . __studyData , titleSelection ) ;
346+ }
305347
306- // second, update the wallet if necessary
307- const store = osparc . store . Store . getInstance ( ) ;
308- const walletSelection = this . getChildControl ( "wallet-selector" ) . getSelection ( ) ;
309- const studyId = this . getStudyId ( ) ;
310- if ( studyId && walletSelection . length && walletSelection [ 0 ] [ "walletId" ] ) {
311- const params = {
312- url : {
313- studyId,
314- "walletId" : walletSelection [ 0 ] [ "walletId" ]
315- }
316- } ;
317- osparc . data . Resources . fetch ( "studies" , "selectWallet" , params )
318- . then ( ( ) => {
319- store . setActiveWallet ( this . getWallet ( ) ) ;
320- this . fireEvent ( "startStudy" ) ;
321- } )
322- . catch ( err => {
323- console . error ( err ) ;
324- const msg = err . message || this . tr ( "Error selecting Credit Account" ) ;
325- osparc . FlashMessenger . getInstance ( ) . logAs ( msg , "ERROR" ) ;
326- } )
327- . finally ( ( ) => openButton . setFetching ( false ) ) ;
348+ // second, update the wallet if necessary
349+ const store = osparc . store . Store . getInstance ( ) ;
350+ const walletSelection = this . getChildControl ( "wallet-selector" ) . getSelection ( ) ;
351+ if ( walletSelection . length && walletSelection [ 0 ] [ "walletId" ] ) {
352+ const studyId = this . getStudyId ( ) ;
353+ const walletId = walletSelection [ 0 ] [ "walletId" ] ;
354+ this . self ( ) . updateWallet ( studyId , walletId )
355+ . then ( ( ) => {
356+ store . setActiveWallet ( this . getWallet ( ) ) ;
357+ this . fireEvent ( "startStudy" ) ;
358+ } )
359+ . finally ( ( ) => openButton . setFetching ( false ) ) ;
360+ } else {
361+ store . setActiveWallet ( this . getWallet ( ) ) ;
362+ this . fireEvent ( "startStudy" ) ;
363+ openButton . setFetching ( false ) ;
364+ }
328365 } else {
329- store . setActiveWallet ( this . getWallet ( ) ) ;
330366 this . fireEvent ( "startStudy" ) ;
331367 openButton . setFetching ( false ) ;
332368 }
333369 } ,
334-
335- __updateName : function ( studyData , name ) {
336- return osparc . info . StudyUtils . patchStudyData ( studyData , "name" , name )
337- . catch ( err => {
338- console . error ( err ) ;
339- const msg = this . tr ( "Something went wrong Renaming" ) ;
340- osparc . FlashMessenger . logAs ( msg , "ERROR" ) ;
341- } ) ;
342- }
343370 }
344371} ) ;
0 commit comments