Skip to content

Commit 9311ee8

Browse files
committed
accept only one
1 parent 85b96d1 commit 9311ee8

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

services/static-webserver/client/source/class/osparc/info/CommentAdd.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ qx.Class.define("osparc.info.CommentAdd", {
2020
extend: qx.ui.core.Widget,
2121

2222
/**
23-
* @param studyId {String} Study Id
23+
* @param studyData {Object} serialized Study Data
2424
* @param conversationId {String} Conversation Id
2525
*/
26-
construct: function(studyId, conversationId = null) {
26+
construct: function(studyData, conversationId = null) {
2727
this.base(arguments);
2828

29-
this.__studyId = studyId;
29+
this.__studyData = studyData;
3030
this.__conversationId = conversationId;
3131

3232
this._setLayout(new qx.ui.layout.VBox(5));
@@ -39,7 +39,7 @@ qx.Class.define("osparc.info.CommentAdd", {
3939
},
4040

4141
members: {
42-
__studyId: null,
42+
__studyData: null,
4343
__conversationId: null,
4444

4545
_createChildControlImpl: function(id) {
@@ -134,8 +134,9 @@ qx.Class.define("osparc.info.CommentAdd", {
134134
__notifyUserTapped: function() {
135135
const showOrganizations = false;
136136
const showAccessRights = false;
137-
const recipientsManager = new osparc.share.NewCollaboratorsManager(currentStudy, showOrganizations, showAccessRights);
138-
// OM: extend NewCollaboratorsManager to only allow one user selected
137+
const recipientsManager = new osparc.share.NewCollaboratorsManager(this.__studyData, showOrganizations, showAccessRights).set({
138+
acceptOnlyOne: true,
139+
});
139140
recipientsManager.setCaption(this.tr("Notify user"));
140141
recipientsManager.getActionButton().setLabel(this.tr("Notify"));
141142
recipientsManager.addListener("addCollaborators", e => {
@@ -147,7 +148,7 @@ qx.Class.define("osparc.info.CommentAdd", {
147148
this.__postNotify(userGid);
148149
} else {
149150
// create new conversation first
150-
osparc.study.Conversations.addConversation(this.__studyId)
151+
osparc.study.Conversations.addConversation(this.__studyData["uuid"])
151152
.then(data => {
152153
this.__conversationId = data["conversationId"];
153154
this.__postNotify(userGid);
@@ -162,7 +163,7 @@ qx.Class.define("osparc.info.CommentAdd", {
162163
this.__postMessage();
163164
} else {
164165
// create new conversation first
165-
osparc.study.Conversations.addConversation(this.__studyId)
166+
osparc.study.Conversations.addConversation(this.__studyData["uuid"])
166167
.then(data => {
167168
this.__conversationId = data["conversationId"];
168169
this.__postMessage();
@@ -174,7 +175,7 @@ qx.Class.define("osparc.info.CommentAdd", {
174175
const commentField = this.getChildControl("comment-field");
175176
const comment = commentField.getChildControl("text-area").getValue();
176177
if (comment) {
177-
osparc.study.Conversations.addMessage(this.__studyId, this.__conversationId, comment)
178+
osparc.study.Conversations.addMessage(this.__studyData["uuid"], this.__conversationId, comment)
178179
.then(data => {
179180
this.fireDataEvent("commentAdded", data);
180181
commentField.getChildControl("text-area").setValue("");
@@ -184,7 +185,7 @@ qx.Class.define("osparc.info.CommentAdd", {
184185

185186
__postNotify: function(userGroupId = 10) {
186187
if (userGroupId) {
187-
osparc.study.Conversations.notifyUser(this.__studyId, this.__conversationId, userGroupId)
188+
osparc.study.Conversations.notifyUser(this.__studyData["uuid"], this.__conversationId, userGroupId)
188189
.then(data => {
189190
console.log(data);
190191
});

services/static-webserver/client/source/class/osparc/info/Conversation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ qx.Class.define("osparc.info.Conversation", {
161161
this._add(this.__loadMoreMessages);
162162

163163
if (osparc.data.model.Study.canIWrite(this.__studyData["accessRights"])) {
164-
const addMessages = new osparc.info.CommentAdd(this.__studyData["uuid"], this.getConversationId());
164+
const addMessages = new osparc.info.CommentAdd(this.__studyData, this.getConversationId());
165165
addMessages.setPaddingLeft(10);
166166
addMessages.addListener("commentAdded", e => {
167167
const data = e.getData();

services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
5555
"shareWithEmails": "qx.event.type.Data",
5656
},
5757

58+
properties: {
59+
acceptOnlyOne: {
60+
check: "Boolean",
61+
init: false,
62+
event: "changeAcceptOnlyOne"
63+
}
64+
},
65+
5866
members: {
5967
__resourceData: null,
6068
__showOrganizations: null,
@@ -276,6 +284,7 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
276284

277285
__collaboratorButton: function(collaborator) {
278286
const collaboratorButton = new osparc.filter.CollaboratorToggleButton(collaborator);
287+
collaborator.button = collaboratorButton;
279288
collaboratorButton.groupId = collaborator.getGroupId();
280289
collaboratorButton.subscribeToFilterGroup("collaboratorsManager");
281290

@@ -298,6 +307,7 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
298307
};
299308
const collaborator = qx.data.marshal.Json.createModel(collaboratorData);
300309
const collaboratorButton = new osparc.filter.CollaboratorToggleButton(collaborator);
310+
collaborator.button = collaboratorButton;
301311
collaboratorButton.setIconSrc("@FontAwesome5Solid/envelope/14");
302312

303313
collaboratorButton.addListener("changeValue", e => {
@@ -309,6 +319,11 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
309319

310320
__collaboratorSelected: function(selected, collaboratorGidOrEmail, collaborator, collaboratorButton) {
311321
if (selected) {
322+
if (this.isAcceptOnlyOne() && Object.keys(this.__selectedCollaborators).length) {
323+
// unselect the previous collaborator
324+
const id = Object.keys(this.__selectedCollaborators)[0];
325+
this.__selectedCollaborators[id].button.setValue(false);
326+
}
312327
this.__selectedCollaborators[collaboratorGidOrEmail] = collaborator;
313328
collaboratorButton.unsubscribeToFilterGroup("collaboratorsManager");
314329
} else if (collaborator.getGroupId() in this.__selectedCollaborators) {

0 commit comments

Comments
 (0)