@@ -33,12 +33,23 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
3333 this . __potentialCollaborators = { } ;
3434 this . __reloadPotentialCollaborators ( ) ;
3535
36+ this . __shareWithEmailEnabled = false ;
37+ if ( this . __resourceData [ "resourceType" ] === "study" ) {
38+ osparc . utils . DisabledPlugins . isShareWithEmailEnabled ( )
39+ . then ( isEnabled => {
40+ if ( isEnabled ) {
41+ this . __shareWithEmailEnabled = true ;
42+ }
43+ } ) ;
44+ }
45+
3646 this . center ( ) ;
3747 this . open ( ) ;
3848 } ,
3949
4050 events : {
41- "addCollaborators" : "qx.event.type.Data"
51+ "addCollaborators" : "qx.event.type.Data" ,
52+ "shareWithEmails" : "qx.event.type.Data" ,
4253 } ,
4354
4455 members : {
@@ -65,14 +76,35 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
6576 this . add ( control ) ;
6677 break ;
6778 }
79+ case "filter-layout" :
80+ control = new qx . ui . container . Composite ( new qx . ui . layout . HBox ( 5 ) ) ;
81+ this . add ( control ) ;
82+ break ;
6883 case "text-filter" : {
6984 control = new osparc . filter . TextFilter ( "name" , "collaboratorsManager" ) ;
7085 control . setCompact ( true ) ;
7186 const filterTextField = control . getChildControl ( "textfield" ) ;
7287 filterTextField . setPlaceholder ( this . tr ( "Search" ) ) ;
7388 filterTextField . setBackgroundColor ( "transparent" ) ;
7489 this . addListener ( "appear" , ( ) => filterTextField . focus ( ) ) ;
75- this . add ( control ) ;
90+ this . getChildControl ( "filter-layout" ) . add ( control , {
91+ flex : 1
92+ } ) ;
93+ break ;
94+ }
95+ case "send-email-button" : {
96+ control = new qx . ui . form . Button ( this . tr ( "Send email" ) ) ;
97+ control . exclude ( ) ;
98+ control . addListener ( "execute" , ( ) => {
99+ const textField = this . getChildControl ( "text-filter" ) . getChildControl ( "textfield" ) ;
100+ const email = textField . getValue ( ) ;
101+ if ( osparc . auth . core . Utils . checkEmail ( email ) ) {
102+ const invitedButton = this . __invitedButton ( email ) ;
103+ this . getChildControl ( "potential-collaborators-list" ) . addAt ( invitedButton , 0 ) ;
104+ invitedButton . setValue ( true ) ;
105+ }
106+ } ) ;
107+ this . getChildControl ( "filter-layout" ) . add ( control ) ;
76108 break ;
77109 }
78110 case "potential-collaborators-list" : {
@@ -143,11 +175,18 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
143175 const textFilter = this . getChildControl ( "text-filter" ) ;
144176 const filterTextField = textFilter . getChildControl ( "textfield" ) ;
145177 filterTextField . addListener ( "input" , e => {
146- const filterValue = e . getData ( ) ;
178+ const inputValue = e . getData ( ) ;
147179 if ( this . __searchDelayer ) {
148180 clearTimeout ( this . __searchDelayer ) ;
149181 }
150- if ( filterValue . length > 3 ) {
182+ const sendEmailButton = this . getChildControl ( "send-email-button" ) ;
183+ sendEmailButton . exclude ( ) ;
184+ if ( inputValue . length > 3 ) {
185+ if ( this . __shareWithEmailEnabled ) {
186+ if ( osparc . auth . core . Utils . checkEmail ( inputValue ) ) {
187+ sendEmailButton . show ( ) ;
188+ }
189+ }
151190 const waitBeforeSearching = 1000 ;
152191 this . __searchDelayer = setTimeout ( ( ) => {
153192 this . __searchUsers ( ) ;
@@ -220,13 +259,10 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
220259 this . __addPotentialCollaborators ( ) ;
221260 } ,
222261
223- __collaboratorButton : function ( collaborator , preSelected = false ) {
262+ __collaboratorButton : function ( collaborator ) {
224263 const collaboratorButton = new osparc . filter . CollaboratorToggleButton ( collaborator ) ;
225264 collaboratorButton . groupId = collaborator . getGroupId ( ) ;
226- collaboratorButton . setValue ( preSelected ) ;
227- if ( ! preSelected ) {
228- collaboratorButton . subscribeToFilterGroup ( "collaboratorsManager" ) ;
229- }
265+ collaboratorButton . subscribeToFilterGroup ( "collaboratorsManager" ) ;
230266
231267 collaboratorButton . addListener ( "changeValue" , e => {
232268 const selected = e . getData ( ) ;
@@ -242,6 +278,34 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
242278 return collaboratorButton ;
243279 } ,
244280
281+ __invitedButton : function ( email ) {
282+ if ( email in this . __selectedCollaborators ) {
283+ return this . __selectedCollaborators [ email ] ;
284+ }
285+
286+ const collaboratorData = {
287+ label : email ,
288+ email : email ,
289+ description : null ,
290+ } ;
291+ const collaborator = qx . data . marshal . Json . createModel ( collaboratorData ) ;
292+ const collaboratorButton = new osparc . filter . CollaboratorToggleButton ( collaborator ) ;
293+ collaboratorButton . setIconSrc ( "@FontAwesome5Solid/envelope/14" ) ;
294+
295+ collaboratorButton . addListener ( "changeValue" , e => {
296+ const selected = e . getData ( ) ;
297+ if ( selected ) {
298+ this . __selectedCollaborators [ collaborator . getEmail ( ) ] = collaborator ;
299+ collaboratorButton . unsubscribeToFilterGroup ( "collaboratorsManager" ) ;
300+ } else if ( collaborator . getEmail ( ) in this . __selectedCollaborators ) {
301+ delete this . __selectedCollaborators [ collaborator . getEmail ( ) ] ;
302+ collaboratorButton . subscribeToFilterGroup ( "collaboratorsManager" ) ;
303+ }
304+ this . getChildControl ( "share-button" ) . setEnabled ( Boolean ( Object . keys ( this . __selectedCollaborators ) . length ) ) ;
305+ } , this ) ;
306+ return collaboratorButton ;
307+ } ,
308+
245309 __addPotentialCollaborators : function ( foundCollaborators = [ ] ) {
246310 const potentialCollaborators = Object . values ( this . __potentialCollaborators ) . concat ( foundCollaborators ) ;
247311 const potentialCollaboratorList = this . getChildControl ( "potential-collaborators-list" ) ;
@@ -315,10 +379,47 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
315379 }
316380 }
317381 if ( Object . keys ( this . __selectedCollaborators ) . length ) {
318- this . fireDataEvent ( "addCollaborators" , {
319- selectedGids : Object . keys ( this . __selectedCollaborators ) ,
320- newAccessRights,
321- } ) ;
382+ const selectedGIds = Object . keys ( this . __selectedCollaborators ) . filter ( key => qx . lang . Type . isNumber ( key ) ) ;
383+ const selectedEmails = Object . keys ( this . __selectedCollaborators ) . filter ( key => osparc . auth . core . Utils . checkEmail ( key ) ) ;
384+
385+ const addCollaborators = ( ) => {
386+ if ( selectedGIds . length ) {
387+ this . fireDataEvent ( "addCollaborators" , {
388+ selectedGids : selectedGIds ,
389+ newAccessRights,
390+ } ) ;
391+ }
392+ } ;
393+
394+ const sendEmails = message => {
395+ if ( selectedEmails . length ) {
396+ this . fireDataEvent ( "shareWithEmails" , {
397+ selectedEmails,
398+ newAccessRights,
399+ message,
400+ } ) ;
401+ }
402+ } ;
403+
404+ if ( selectedEmails . length ) {
405+ const dialog = new osparc . ui . window . Confirmation ( ) ;
406+ dialog . setCaption ( this . tr ( "Add Message" ) ) ;
407+ dialog . setMessage ( this . tr ( "Add a message to include in the email (optional)" ) ) ;
408+ dialog . getConfirmButton ( ) . setLabel ( this . tr ( "Send" ) ) ;
409+ const messageEditor = new qx . ui . form . TextArea ( ) . set ( {
410+ autoSize : true ,
411+ minHeight : 70 ,
412+ maxHeight : 140 ,
413+ } ) ;
414+ dialog . addWidget ( messageEditor ) ;
415+ dialog . open ( ) ;
416+ dialog . addListener ( "close" , ( ) => {
417+ addCollaborators ( ) ;
418+ sendEmails ( messageEditor . getValue ( ) ) ;
419+ } , this ) ;
420+ } else {
421+ addCollaborators ( ) ;
422+ }
322423 }
323424 }
324425 }
0 commit comments