mirai/ui/windows/TaskWindow.slint
2024-10-08 16:36:01 +02:00

93 lines
2 KiB
Text

import { Date, ComboBox } from "std-widgets.slint";
import { VTextInput, VButton, VDatePicker, VText, VCheckBox, Palette } from "@vynui";
import { Backend } from "../Backend.slint";
export struct NewTaskData {
sourceId: int,
eventId: int,
title: string,
scheduled: bool,
date: Date
}
export struct SaveTaskData {
sourceId: int,
id: int,
title: string,
scheduled: bool,
date: Date,
}
export component TaskWindow inherits Window {
title: "Mirai - " + (taskId == -1 ? "New task" : "Edit task");
min-width: 100px;
max-width: 1920px;
preferred-width: 512px;
min-height: 100px;
max-height: 4000px;
default-font-size: 16px;
background: Palette.background;
in-out property<int> taskId: -1;
in-out property<int> eventId: -1;
in-out property<bool> scheduled <=> scheduledInput.checked;
in-out property<Date> taskDate <=> taskDateInput.date;
in-out property<string> taskTitle <=> taskTitleInput.text;
in-out property<int> taskSourceIndex <=> sourceInput.current-index;
callback create(NewTaskData);
callback save(SaveTaskData);
VerticalLayout {
padding: 16px;
spacing: 8px;
VText {
text: taskId == -1 ? "New task" : "Edit task";
}
sourceInput := ComboBox {
model: Backend.sources;
enabled: taskId == -1 && eventId == -1;
}
taskTitleInput := VTextInput {
label: "Content";
wrap: word-wrap;
accepted => { button.clicked() }
}
scheduledInput := VCheckBox {
text: "Scheduled";
}
taskDateInput := VDatePicker {
label: "Date";
enabled: eventId == -1 && scheduledInput.checked;
}
button := VButton {
text: taskId == -1 ? "Create" : "Save";
clicked => {
if (taskId == -1) {
create({
sourceId: taskSourceIndex,
eventId: eventId,
title: taskTitle,
scheduled: scheduled,
date: taskDate,
});
} else {
save({
sourceId: taskSourceIndex,
id: taskId,
title: taskTitle,
scheduled: scheduled,
date: taskDate,
});
}
}
}
}
}
export { Backend }