|
| 1 | +/* ************************************************************************ |
| 2 | +
|
| 3 | + osparc - the simcore frontend |
| 4 | +
|
| 5 | + https://osparc.io |
| 6 | +
|
| 7 | + Copyright: |
| 8 | + 2023 IT'IS Foundation, https://itis.swiss |
| 9 | +
|
| 10 | + License: |
| 11 | + MIT: https://opensource.org/licenses/MIT |
| 12 | +
|
| 13 | + Authors: |
| 14 | + * Odei Maiz (odeimaiz) |
| 15 | +
|
| 16 | +************************************************************************ */ |
| 17 | + |
| 18 | +qx.Class.define("osparc.admin.Announcements", { |
| 19 | + extend: osparc.po.BaseView, |
| 20 | + |
| 21 | + members: { |
| 22 | + _createChildControlImpl: function(id) { |
| 23 | + let control; |
| 24 | + switch (id) { |
| 25 | + case "create-announcement": |
| 26 | + control = this.__createAnnouncements(); |
| 27 | + this._add(control); |
| 28 | + break; |
| 29 | + case "announcement-container": { |
| 30 | + control = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)); |
| 31 | + this._add(control, { |
| 32 | + flex: 1 |
| 33 | + }); |
| 34 | + break; |
| 35 | + } |
| 36 | + } |
| 37 | + return control || this.base(arguments, id); |
| 38 | + }, |
| 39 | + |
| 40 | + _buildLayout: function() { |
| 41 | + this.getChildControl("create-announcement"); |
| 42 | + this.getChildControl("announcement-container"); |
| 43 | + }, |
| 44 | + |
| 45 | + __createAnnouncements: function() { |
| 46 | + const announcementGroupBox = osparc.po.BaseView.createGroupBox(this.tr("Create announcement")); |
| 47 | + |
| 48 | + const announcementForm = this.__createAnnouncementForm(); |
| 49 | + const form = new qx.ui.form.renderer.Single(announcementForm); |
| 50 | + announcementGroupBox.add(form); |
| 51 | + |
| 52 | + return announcementGroupBox; |
| 53 | + }, |
| 54 | + |
| 55 | + __createAnnouncementForm: function() { |
| 56 | + const form = new qx.ui.form.Form(); |
| 57 | + |
| 58 | + const title = new qx.ui.form.TextField().set({ |
| 59 | + placeholder: this.tr("title") |
| 60 | + }); |
| 61 | + form.add(title, this.tr("Title")); |
| 62 | + |
| 63 | + const description = new qx.ui.form.TextArea().set({ |
| 64 | + placeholder: this.tr("description"), |
| 65 | + maxHeight: 60 |
| 66 | + }); |
| 67 | + form.add(description, this.tr("Description")); |
| 68 | + |
| 69 | + const link = new qx.ui.form.TextField().set({ |
| 70 | + placeholder: this.tr("link") |
| 71 | + }); |
| 72 | + form.add(link, this.tr("Link")); |
| 73 | + |
| 74 | + const widgetLogin = new qx.ui.form.CheckBox().set({ |
| 75 | + value: false |
| 76 | + }); |
| 77 | + form.add(widgetLogin, this.tr("Login")); |
| 78 | + |
| 79 | + const widgetRibbon = new qx.ui.form.CheckBox().set({ |
| 80 | + value: false |
| 81 | + }); |
| 82 | + form.add(widgetRibbon, this.tr("Ribbon")); |
| 83 | + |
| 84 | + const widgetUserMenu = new qx.ui.form.CheckBox().set({ |
| 85 | + value: false |
| 86 | + }); |
| 87 | + form.add(widgetUserMenu, this.tr("User Menu")); |
| 88 | + |
| 89 | + const dateFormat = new qx.util.format.DateFormat("dd/MM/yyyy"); |
| 90 | + const now = new Date(); |
| 91 | + |
| 92 | + const start = new qx.ui.form.DateField(); |
| 93 | + start.setDateFormat(dateFormat); |
| 94 | + start.setValue(now); |
| 95 | + form.add(start, this.tr("Start")); |
| 96 | + |
| 97 | + const end = new qx.ui.form.DateField(); |
| 98 | + end.setDateFormat(dateFormat); |
| 99 | + end.setValue(now); |
| 100 | + form.add(end, this.tr("End")); |
| 101 | + |
| 102 | + const generateAnnouncementBtn = new osparc.ui.form.FetchButton(this.tr("Generate")); |
| 103 | + generateAnnouncementBtn.set({appearance: "form-button"}); |
| 104 | + generateAnnouncementBtn.addListener("execute", () => { |
| 105 | + const products = [osparc.product.Utils.getProductName()]; |
| 106 | + const widgets = []; |
| 107 | + if (widgetLogin.getValue()) { |
| 108 | + widgets.push("login"); |
| 109 | + } |
| 110 | + if (widgetRibbon.getValue()) { |
| 111 | + widgets.push("ribbon"); |
| 112 | + } |
| 113 | + if (widgetUserMenu.getValue()) { |
| 114 | + widgets.push("user-menu"); |
| 115 | + } |
| 116 | + if (widgets.length === 0) { |
| 117 | + const msg = "Select at least one widget"; |
| 118 | + osparc.FlashMessenger.getInstance().logAs(msg, "WARNING"); |
| 119 | + } |
| 120 | + const announcementData = { |
| 121 | + "id": osparc.utils.Utils.uuidV4(), |
| 122 | + "products": products, |
| 123 | + "title": title.getValue() ? title.getValue() : "", |
| 124 | + "description": description.getValue() ? description.getValue() : "", |
| 125 | + "link": link.getValue() ? link.getValue() : "", |
| 126 | + "widgets": widgets, |
| 127 | + "start": start.getValue(), |
| 128 | + "end": end.getValue(), |
| 129 | + }; |
| 130 | + this.__populateAnnouncementLayout(announcementData); |
| 131 | + }, this); |
| 132 | + form.addButton(generateAnnouncementBtn); |
| 133 | + |
| 134 | + return form; |
| 135 | + }, |
| 136 | + |
| 137 | + __populateAnnouncementLayout: function(announcementData) { |
| 138 | + const vBox = this.getChildControl("announcement-container"); |
| 139 | + vBox.removeAll(); |
| 140 | + |
| 141 | + const announcementField = new qx.ui.form.TextArea(JSON.stringify(announcementData)).set({ |
| 142 | + readOnly: true |
| 143 | + }); |
| 144 | + vBox.add(announcementField); |
| 145 | + |
| 146 | + const copyAnnouncementBtn = new qx.ui.form.Button(this.tr("Copy announcement")).set({ |
| 147 | + alignX: "left", |
| 148 | + allowGrowX: false, |
| 149 | + }); |
| 150 | + copyAnnouncementBtn.set({appearance: "form-button"}); |
| 151 | + copyAnnouncementBtn.addListener("execute", () => { |
| 152 | + if (osparc.utils.Utils.copyTextToClipboard(JSON.stringify(announcementData))) { |
| 153 | + copyAnnouncementBtn.setIcon("@FontAwesome5Solid/check/12"); |
| 154 | + } |
| 155 | + }); |
| 156 | + vBox.add(copyAnnouncementBtn); |
| 157 | + }, |
| 158 | + } |
| 159 | +}); |
0 commit comments