|
| 1 | +/* ************************************************************************ |
| 2 | +
|
| 3 | + osparc - the simcore frontend |
| 4 | +
|
| 5 | + https://osparc.io |
| 6 | +
|
| 7 | + Copyright: |
| 8 | + 2025 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 | + |
| 19 | +qx.Class.define("osparc.widget.DateTimeChooser", { |
| 20 | + extend: osparc.ui.window.Window, |
| 21 | + |
| 22 | + construct: function(winTitle, value) { |
| 23 | + this.base(arguments, winTitle || this.tr("Choose a Date and Time")); |
| 24 | + |
| 25 | + const width = 260; |
| 26 | + const height = 26; |
| 27 | + this.set({ |
| 28 | + layout: new qx.ui.layout.VBox(10), |
| 29 | + autoDestroy: true, |
| 30 | + modal: true, |
| 31 | + width, |
| 32 | + height, |
| 33 | + showMaximize: false, |
| 34 | + showMinimize: false, |
| 35 | + showClose: true, |
| 36 | + resizable: false, |
| 37 | + clickAwayClose: false, |
| 38 | + }); |
| 39 | + |
| 40 | + const dateTimeField = this.getChildControl("date-time-field"); |
| 41 | + if (value) { |
| 42 | + dateTimeField.setValue(value); |
| 43 | + } |
| 44 | + this.getChildControl("cancel-button"); |
| 45 | + this.getChildControl("save-button"); |
| 46 | + |
| 47 | + this.center(); |
| 48 | + |
| 49 | + this.__attachEventHandlers(); |
| 50 | + }, |
| 51 | + |
| 52 | + events: { |
| 53 | + "dateChanged": "qx.event.type.Data", |
| 54 | + }, |
| 55 | + |
| 56 | + members: { |
| 57 | + _createChildControlImpl: function(id) { |
| 58 | + let control; |
| 59 | + switch (id) { |
| 60 | + case "date-time-field": |
| 61 | + control = new osparc.ui.form.DateTimeField(); |
| 62 | + this.add(control); |
| 63 | + break; |
| 64 | + case "buttons-layout": |
| 65 | + control = new qx.ui.container.Composite(new qx.ui.layout.HBox(5).set({ |
| 66 | + alignX: "right" |
| 67 | + })); |
| 68 | + this.add(control); |
| 69 | + break; |
| 70 | + case "cancel-button": |
| 71 | + control = new qx.ui.form.Button(this.tr("Cancel")).set({ |
| 72 | + appearance: "form-button-text", |
| 73 | + }); |
| 74 | + control.addListener("execute", () => this.close(), this); |
| 75 | + this.getChildControl("buttons-layout").add(control); |
| 76 | + break; |
| 77 | + case "save-button": { |
| 78 | + control = new qx.ui.form.Button(this.tr("Save")).set({ |
| 79 | + appearance: "form-button", |
| 80 | + }); |
| 81 | + control.addListener("execute", e => { |
| 82 | + const dateTimeField = this.getChildControl("date-time-field"); |
| 83 | + const data = { |
| 84 | + newValue: dateTimeField.getValue() |
| 85 | + }; |
| 86 | + this.fireDataEvent("dateChanged", data); |
| 87 | + }, this); |
| 88 | + this.getChildControl("buttons-layout").add(control); |
| 89 | + break; |
| 90 | + } |
| 91 | + } |
| 92 | + return control || this.base(arguments, id); |
| 93 | + }, |
| 94 | + |
| 95 | + __attachEventHandlers: function() { |
| 96 | + let command = new qx.ui.command.Command("Enter"); |
| 97 | + command.addListener("execute", () => { |
| 98 | + this.getChildControl("save-button").execute(); |
| 99 | + command.dispose(); |
| 100 | + command = null; |
| 101 | + }); |
| 102 | + |
| 103 | + let commandEsc = new qx.ui.command.Command("Esc"); |
| 104 | + commandEsc.addListener("execute", () => { |
| 105 | + this.close(); |
| 106 | + commandEsc.dispose(); |
| 107 | + commandEsc = null; |
| 108 | + }); |
| 109 | + } |
| 110 | + } |
| 111 | +}); |
0 commit comments