Skip to main content

forms/
script.rs

1//! The script form descriptors.
2
3use crate::descriptor::{Action, Field, Form, Kind, TEXT, field};
4use crate::template::SOURCE;
5
6const ENABLED: Field = field(
7    "enabled",
8    "State",
9    Kind::Choice {
10        options: &[("true", "Enabled"), ("false", "Disabled")],
11        default: Some("true"),
12    },
13    false,
14);
15
16/// Create a script from an optional name, its source and its state.
17pub const SCRIPT_CREATE: Form = Form {
18    name: "script-create",
19    title: "Create script",
20    fields: &[
21        field("name", "Name", TEXT, false),
22        field("source", "Source", SOURCE, true),
23        ENABLED,
24    ],
25    action: Action::Mutation,
26};
27
28/// Replace the name, the source and the state of a script; the revision
29/// covers all three.
30pub const SCRIPT_EDIT: Form = Form {
31    name: "script-edit",
32    title: "Edit script",
33    fields: &[
34        field("id", "Id", Kind::Hidden, true),
35        field("revision", "Revision", Kind::Hidden, true),
36        field("name", "Name", TEXT, false),
37        field("source", "Source", SOURCE, true),
38        ENABLED,
39    ],
40    action: Action::LoadMutation,
41};