Skip to content

Commit 4970024

Browse files
committed
approve working
1 parent d197315 commit 4970024

File tree

1 file changed

+73
-14
lines changed

1 file changed

+73
-14
lines changed

services/static-webserver/client/source/class/osparc/po/UsersPending.js

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,81 @@ qx.Class.define("osparc.po.UsersPending", {
2020
extend: osparc.po.BaseView,
2121

2222
statics: {
23+
createInvitationForm: function() {
24+
const form = new qx.ui.form.Form();
25+
26+
const extraCreditsInUsd = new qx.ui.form.Spinner().set({
27+
minimum: 0,
28+
maximum: 1000,
29+
value: 100
30+
});
31+
form.add(extraCreditsInUsd, qx.locale.Manager.tr("Welcome Credits (USD)"), null, "credits");
32+
33+
const withExpiration = new qx.ui.form.CheckBox().set({
34+
value: false
35+
});
36+
form.add(withExpiration, qx.locale.Manager.tr("With expiration"), null, "withExpiration");
37+
38+
const trialDays = new qx.ui.form.Spinner().set({
39+
minimum: 1,
40+
maximum: 1000,
41+
value: 1
42+
});
43+
withExpiration.bind("value", trialDays, "visibility", {
44+
converter: val => val ? "visible" : "excluded"
45+
});
46+
form.add(trialDays, qx.locale.Manager.tr("Trial Days"), null, "trialDays");
47+
48+
return form;
49+
},
50+
2351
createApproveButton: function(email) {
24-
const button = new osparc.ui.form.FetchButton(qx.locale.Manager.tr("Approve"));
52+
const button = new qx.ui.form.Button(qx.locale.Manager.tr("Approve"));
2553
button.addListener("execute", () => {
26-
button.setFetching(true);
27-
const params = {
28-
data: {
29-
email,
30-
},
31-
};
32-
osparc.data.Resources.fetch("poUsers", "approveUser", params)
33-
.then(() => {
34-
osparc.FlashMessenger.logAs(qx.locale.Manager.tr("User approved"), "INFO");
35-
})
36-
.catch(err => osparc.FlashMessenger.logError(err))
37-
.finally(() => button.setFetching(false));
54+
const form = this.createInvitationForm();
55+
const approveBtn = new osparc.ui.form.FetchButton(qx.locale.Manager.tr("Approve"));
56+
approveBtn.set({
57+
appearance: "form-button"
58+
});
59+
form.addButton(approveBtn);
60+
const layout = new qx.ui.container.Composite(new qx.ui.layout.VBox(10));
61+
const invitationForm = new qx.ui.form.renderer.Single(form);
62+
layout.add(invitationForm);
63+
const win = osparc.ui.window.Window.popUpInWindow(layout, email, 350, 150).set({
64+
clickAwayClose: false,
65+
resizable: false,
66+
showClose: true
67+
});
68+
win.open();
69+
approveBtn.addListener("execute", () => {
70+
if (!osparc.data.Permissions.getInstance().canDo("user.invitation.generate", true)) {
71+
return;
72+
}
73+
if (form.validate()) {
74+
approveBtn.setFetching(true);
75+
const params = {
76+
data: {
77+
email,
78+
},
79+
};
80+
const extraCreditsInUsd = form.getItems()["credits"].getValue();
81+
if (extraCreditsInUsd > 0) {
82+
params.data["extraCreditsInUsd"] = extraCreditsInUsd;
83+
}
84+
if (form.getItems()["withExpiration"].getValue()) {
85+
params.data["trialAccountDays"] = form.getItems()["trialDays"].getValue();
86+
}
87+
osparc.data.Resources.fetch("poUsers", "approveUser", params)
88+
.then(() => {
89+
osparc.FlashMessenger.logAs(qx.locale.Manager.tr("User approved"), "INFO");
90+
})
91+
.catch(err => osparc.FlashMessenger.logError(err))
92+
.finally(() => {
93+
approveBtn.setFetching(false);
94+
win.close();
95+
});
96+
}
97+
});
3898
});
3999
return button;
40100
},
@@ -165,7 +225,6 @@ qx.Class.define("osparc.po.UsersPending", {
165225

166226
let row = 1;
167227
pendingUsers.forEach(pendingUser => {
168-
console.log("Pending user", pendingUser);
169228
pendingUsersLayout.add(new qx.ui.basic.Label(pendingUser.firstName + " " + pendingUser.lastName), {
170229
row,
171230
column: 0,

0 commit comments

Comments
 (0)