1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
pub mod caching;
pub mod html_controls;
pub mod output_data;
pub mod validation;
#[derive(Default, serde::Serialize, serde::Deserialize, PartialEq, Clone, Debug)]
pub struct FileData {
#[serde(default)]
pub path: String,
#[serde(default)]
pub url: String,
#[serde(default)]
pub name: String,
#[serde(default, with = "mongodb::bson::compat::u2f")]
pub size: u32,
}
#[derive(Default, serde::Serialize, serde::Deserialize, PartialEq, Clone, Debug)]
pub struct ImageData {
#[serde(default)]
pub path: String,
#[serde(default)]
pub path_xs: String,
#[serde(default)]
pub path_sm: String,
#[serde(default)]
pub path_md: String,
#[serde(default)]
pub path_lg: String,
#[serde(default)]
pub url: String,
#[serde(default)]
pub url_xs: String,
#[serde(default)]
pub url_sm: String,
#[serde(default)]
pub url_md: String,
#[serde(default)]
pub url_lg: String,
#[serde(default)]
pub name: String,
#[serde(default, with = "mongodb::bson::compat::u2f")]
pub size: u32,
#[serde(default, with = "mongodb::bson::compat::u2f")]
pub width: u32,
#[serde(default, with = "mongodb::bson::compat::u2f")]
pub height: u32,
}
#[derive(serde::Serialize, serde::Deserialize, PartialEq, Clone, Debug)]
pub struct Widget {
pub id: String,
pub label: String,
pub widget: String,
pub input_type: String,
pub name: String,
pub value: String,
pub accept: String,
pub placeholder: String,
pub pattern: String,
pub minlength: usize,
pub maxlength: usize,
pub required: bool,
pub checked: bool,
pub unique: bool,
pub disabled: bool,
pub readonly: bool,
pub step: String,
pub min: String,
pub max: String,
pub options: Vec<(String, String)>,
pub thumbnails: Vec<(String, u32)>,
pub other_attrs: String,
pub css_classes: String,
pub hint: String,
pub warning: String,
pub error: String,
pub common_msg: String,
}
impl Default for Widget {
fn default() -> Self {
Widget {
id: String::new(),
label: String::new(),
widget: String::from("inputText"),
input_type: String::from("text"),
name: String::new(),
value: String::new(),
accept: String::new(),
placeholder: String::new(),
pattern: String::new(),
minlength: 0_usize,
maxlength: 256_usize,
required: false,
checked: false,
unique: false,
disabled: false,
readonly: false,
step: String::from("1"),
min: String::new(),
max: String::new(),
options: Vec::new(),
thumbnails: Vec::new(),
other_attrs: String::new(),
css_classes: String::new(),
hint: String::new(),
warning: String::new(),
error: String::new(),
common_msg: String::new(),
}
}
}
#[derive(serde::Deserialize)]
pub struct TransMapWidgets {
pub map_widgets: std::collections::HashMap<String, Widget>,
}
pub trait ToForm {
fn key() -> String;
fn form_name() -> String;
fn fields_name() -> Result<Vec<String>, Box<dyn std::error::Error>>;
fn widgets() -> Result<std::collections::HashMap<String, Widget>, Box<dyn std::error::Error>>;
fn self_to_json(&self) -> Result<serde_json::value::Value, Box<dyn std::error::Error>>;
}