@@ -27,12 +27,13 @@ qx.Class.define("osparc.study.SaveAsTemplate", {
2727  /** 
2828   * @param  studyData {Object} Object containing part or the entire serialized Study Data 
2929   */ 
30-   construct : function ( studyData )  { 
30+   construct : function ( studyData ,   makeItPublic   =   false )  { 
3131    this . base ( arguments ) ; 
3232
3333    this . _setLayout ( new  qx . ui . layout . VBox ( 20 ) ) ; 
3434
3535    this . __studyDataClone  =  osparc . data . model . Study . deepCloneStudyObject ( studyData ) ; 
36+     this . __makeItPublic  =  makeItPublic ; 
3637
3738    this . __buildLayout ( ) ; 
3839  } , 
@@ -43,10 +44,26 @@ qx.Class.define("osparc.study.SaveAsTemplate", {
4344
4445  members : { 
4546    __studyDataClone : null , 
47+     __makeItPublic : null , 
4648    __form : null , 
47-     __publishTemplateBtn : null , 
49+     __createTemplateBtn : null , 
4850
4951    __buildLayout : function ( )  { 
52+       let  introText  =  "" ; 
53+       if  ( this . __makeItPublic )  { 
54+         introText  +=  this . tr ( "This project will be published and accessible to everyone." ) ; 
55+         introText  +=  "<br>" ; 
56+         introText  +=  this . tr ( "All users will see it and can copy it." ) ; 
57+       }  else  { 
58+         introText  +=  this . tr ( "This project will be saved as a template." ) ; 
59+         introText  +=  "<br>" ; 
60+         introText  +=  this . tr ( "The users you select will be able to see it and copy it." ) ; 
61+       } 
62+       this . _add ( new  qx . ui . basic . Label ( introText ) . set ( { 
63+         font : "text-14" , 
64+         rich : true , 
65+       } ) ) ; 
66+ 
5067      const  form  =  this . __form  =  new  qx . ui . form . Form ( ) ; 
5168      this . _add ( new  qx . ui . form . renderer . Single ( form ) ) ; 
5269
@@ -56,11 +73,14 @@ qx.Class.define("osparc.study.SaveAsTemplate", {
5673      } ) ; 
5774      form . add ( publishWithData ,  this . tr ( "Publish with data" ) ,  null ,  "publishWithData" ) ; 
5875
59-       if  ( osparc . product . Utils . isS4LProduct ( ) )  { 
76+       if  ( osparc . data . Permissions . getInstance ( ) . isTester ( ) )  { 
6077        const  templateTypeSB  =  new  qx . ui . form . SelectBox ( ) . set ( { 
6178          allowGrowX : false , 
6279        } ) ; 
6380        const  templateTypes  =  [ { 
81+           label : "Template" , 
82+           id : null , 
83+         } ,  { 
6484          label : "Tutorial" , 
6585          id : null , 
6686        } ,  { 
@@ -74,33 +94,42 @@ qx.Class.define("osparc.study.SaveAsTemplate", {
7494        form . add ( templateTypeSB ,  this . tr ( "Template Type" ) ,  null ,  "templateType" ) ; 
7595      } 
7696
77-       const  shareWith  =  this . __shareWith  =  new  osparc . share . ShareTemplateWith ( this . __studyDataClone ) ; 
78-       this . _add ( shareWith ) ; 
97+       if  ( ! this . __makeItPublic )  { 
98+         const  shareWith  =  this . __shareWith  =  new  osparc . share . ShareTemplateWith ( this . __studyDataClone ) ; 
99+         this . _add ( shareWith ) ; 
100+       } 
79101
80-       const  publishTemplateBtn  =  this . __publishTemplateBtn  =  new  qx . ui . form . Button ( ) . set ( { 
102+       const  createTemplateBtn  =  this . __createTemplateBtn  =  new  qx . ui . form . Button ( ) . set ( { 
81103        appearance : "strong-button" , 
82-         label : this . tr ( "Publish" ) , 
104+         label : this . __makeItPublic  ?  this . tr ( "Publish"  )  :  this . tr ( "Create Template ") , 
83105        allowGrowX : false , 
84106        alignX : "right" 
85107      } ) ; 
86-       publishTemplateBtn . addListener ( "execute" ,  ( )  =>  this . __publishTemplate ( ) ,  this ) ; 
87-       this . _add ( publishTemplateBtn ) ; 
108+       createTemplateBtn . addListener ( "execute" ,  ( )  =>  this . __createTemplate ( ) ,  this ) ; 
109+       this . _add ( createTemplateBtn ) ; 
88110    } , 
89111
90-     __publishTemplate : function ( )  { 
112+     __createTemplate : function ( )  { 
91113      const  publishWithDataCB  =  this . __form . getItem ( "publishWithData" ) ; 
92114      const  templateTypeSB  =  this . __form . getItem ( "templateType" ) ; 
93115      const  templateType  =  templateTypeSB  ? templateTypeSB . getSelection ( ) [ 0 ] . getModel ( )  : null ; 
94116
95-       const  readAccessRole  =  osparc . data . Roles . STUDY [ "read" ] ; 
96117      // AccessRights will be POSTed after the template is created. 
97118      // No need to add myself, backend will automatically do it 
98119      const  accessRights  =  { } ; 
99120      this . __studyDataClone [ "accessRights" ]  =  { } ; 
100-       const  selectedGroupIDs  =  this . __shareWith . getSelectedGroups ( ) ; 
101-       selectedGroupIDs . forEach ( gid  =>  { 
102-         accessRights [ gid ]  =  readAccessRole . accessRights ; 
103-       } ) ; 
121+       if  ( this . __makeItPublic )  { 
122+         // share the template with the everyone group 
123+         const  groupsStore  =  osparc . store . Groups . getInstance ( ) ; 
124+         const  groupProductEveryone  =  groupsStore . getEveryoneProductGroup ( ) ; 
125+         accessRights [ groupProductEveryone . getGroupId ( ) ]  =  osparc . data . Roles . STUDY [ "read" ] . accessRights ; 
126+       }  else  { 
127+         const  selectedGroupIDs  =  this . __shareWith . getSelectedGroups ( ) ; 
128+         const  readAccessRole  =  osparc . data . Roles . STUDY [ "read" ] ; 
129+         selectedGroupIDs . forEach ( gid  =>  { 
130+           accessRights [ gid ]  =  readAccessRole . accessRights ; 
131+         } ) ; 
132+       } 
104133
105134      this . fireDataEvent ( "publishTemplate" ,  { 
106135        "studyData" : this . __studyDataClone , 
@@ -110,8 +139,8 @@ qx.Class.define("osparc.study.SaveAsTemplate", {
110139      } ) ; 
111140    } , 
112141
113-     getPublishTemplateButton : function ( )  { 
114-       return  this . __publishTemplateBtn ; 
142+     getCreateTemplateButton : function ( )  { 
143+       return  this . __createTemplateBtn ; 
115144    } 
116145  } 
117146} ) ; 
0 commit comments