@@ -487,22 +487,7 @@ define([
487487 // set run button
488488 vpConfig . getData ( 'runType' , 'vpcfg' ) . then ( function ( data ) {
489489 vpLog . display ( VP_LOG_TYPE . DEVELOP , 'Runtype get data' , data ) ;
490- if ( data == undefined || data == null || data === '' ) {
491- data = 'run' ; // default = run
492- }
493- that . config . runType = data ;
494- $ ( that . wrapSelector ( `.vp-popup-run-type[value="${ data } "]` ) ) . prop ( 'checked' , true ) ;
495- $ ( that . wrapSelector ( '.vp-popup-run-button' ) ) . attr ( 'data-type' , data ) ;
496- let runTitle = 'Run code' ;
497- switch ( data ) {
498- case 'run-save' :
499- runTitle = 'Save to block & Run code' ;
500- break ;
501- case 'add' :
502- runTitle = 'Add code to cell' ;
503- break ;
504- }
505- $ ( that . wrapSelector ( '.vp-popup-run-button' ) ) . prop ( 'title' , runTitle ) ;
490+ that . _setDefaultRunType ( data ) ;
506491 } ) ;
507492 evt . stopPropagation ( ) ;
508493 break ;
@@ -527,24 +512,15 @@ define([
527512 // Click detail radio
528513 $ ( this . wrapSelector ( '.vp-popup-run-type' ) ) . on ( 'click' , function ( evt ) {
529514 let runType = $ ( that . wrapSelector ( '.vp-popup-run-type[name=runType]:checked' ) ) . val ( ) ;
530- that . config . runType = runType ;
531515 // save as vpConfig
532516 vpConfig . setData ( { runType : runType } , 'vpcfg' ) ;
533- $ ( that . wrapSelector ( '.vp-popup-run-button' ) ) . attr ( 'data-type' , runType ) ;
534- let runTitle = 'Run code' ;
535- switch ( runType ) {
536- case 'run-save' :
537- runTitle = 'Save to block & Run code' ;
538- break ;
539- case 'add' :
540- runTitle = 'Add code to cell' ;
541- break ;
542- }
543- $ ( that . wrapSelector ( '.vp-popup-run-button' ) ) . prop ( 'title' , runTitle ) ;
517+ that . _setDefaultRunType ( runType ) ;
544518 } ) ;
545519 // Click detail buttons
546520 $ ( this . wrapSelector ( '.vp-popup-detail-action-button' ) ) . on ( 'click' , function ( evt ) {
547521 var btnType = $ ( this ) . data ( 'type' ) ;
522+ vpConfig . setData ( { runType : runType } , 'vpcfg' ) ;
523+ that . _setDefaultRunType ( btnType ) ; // run, run-save, add
548524 switch ( btnType ) {
549525 // case 'apply':
550526 // that.save();
@@ -749,22 +725,7 @@ define([
749725 let that = this ;
750726 vpConfig . getData ( 'runType' , 'vpcfg' ) . then ( function ( data ) {
751727 vpLog . display ( VP_LOG_TYPE . DEVELOP , 'Runtype get data' , data ) ;
752- if ( data == undefined || data == null || data === '' ) {
753- data = 'run' ; // default = run
754- }
755- that . config . runType = data ;
756- $ ( that . wrapSelector ( `.vp-popup-run-type[value="${ data } "]` ) ) . prop ( 'checked' , true ) ;
757- $ ( that . wrapSelector ( '.vp-popup-run-button' ) ) . attr ( 'data-type' , data ) ;
758- let runTitle = 'Run code' ;
759- switch ( data ) {
760- case 'run-save' :
761- runTitle = 'Save to block & Run code' ;
762- break ;
763- case 'add' :
764- runTitle = 'Add code to cell' ;
765- break ;
766- }
767- $ ( that . wrapSelector ( '.vp-popup-run-button' ) ) . prop ( 'title' , runTitle ) ;
728+ that . _setDefaultRunType ( data ) ;
768729 } ) ;
769730 }
770731
@@ -911,6 +872,25 @@ define([
911872 vpLog . display ( VP_LOG_TYPE . DEVELOP , 'savedState' , that . state ) ;
912873 }
913874
875+ _setDefaultRunType ( runType ) {
876+ if ( runType == undefined || runType == null || runType === '' ) {
877+ runType = 'run' ; // default = run
878+ }
879+ this . config . runType = runType ;
880+ $ ( this . wrapSelector ( `.vp-popup-run-type[value="${ runType } "]` ) ) . prop ( 'checked' , true ) ;
881+ $ ( this . wrapSelector ( '.vp-popup-run-button' ) ) . attr ( 'data-type' , runType ) ;
882+ let runTitle = 'Run code' ; // when runType is 'run'
883+ switch ( runType ) {
884+ case 'run-save' :
885+ runTitle = 'Save to block & Run code' ;
886+ break ;
887+ case 'add' :
888+ runTitle = 'Add code to cell' ;
889+ break ;
890+ }
891+ $ ( this . wrapSelector ( '.vp-popup-run-button' ) ) . prop ( 'title' , runTitle ) ;
892+ }
893+
914894 _getTagValue ( tag ) {
915895 let id = tag . id ;
916896 let tagName = $ ( tag ) . prop ( 'tagName' ) ; // returns with UpperCase
0 commit comments