pagetop 0.5.0

Un entorno de desarrollo para crear soluciones web modulares, extensibles y configurables.
Documentation
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
use pagetop::prelude::*;

use pagetop_bootsier::prelude::*;

include_locales!(LOC from "examples/locale");

struct FormControls;

impl Extension for FormControls {
    fn dependencies(&self) -> Vec<ExtensionRef> {
        vec![&pagetop_aliner::Aliner, &pagetop_bootsier::Bootsier]
    }

    fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
        scfg.route("/", service::web::get().to(form_controls));
    }
}

async fn form_controls(request: HttpRequest) -> ResultPage<Markup, ErrorPage> {
    Page::new(request)
        .with_child(
            Intro::default()
                .with_opening(IntroOpening::Custom)
                .with_title(L10n::t("title", &LOC))
                .with_slogan(L10n::t("slogan", &LOC))
                .with_button(None::<(L10n, FnPathByContext)>)
                // Bloque 1: casillas, interruptores y botones de opción.
                .with_child(
                    Block::new()
                        .with_title(L10n::t("block_selections", &LOC))
                        .with_child(
                            Form::new()
                                .with_id("form-selections")
                                .with_action("/")
                                .with_method(form::Method::Post)
                                // Casillas e interruptores (form::Checkbox).
                                .with_child(
                                    form::Fieldset::new()
                                        .with_legend(L10n::t("fieldset_checkbox", &LOC))
                                        .with_description(L10n::t("desc_checkbox", &LOC))
                                        .with_child(
                                            form::Checkbox::new()
                                                .with_name("accept_terms")
                                                .with_label(L10n::t("label_terms", &LOC))
                                                .with_required(true),
                                        )
                                        .with_child(
                                            form::Checkbox::new()
                                                .with_name("accept_marketing")
                                                .with_label(L10n::t("label_marketing", &LOC))
                                                .with_checked(true)
                                                .with_inline(true),
                                        )
                                        .with_child(
                                            form::Checkbox::new()
                                                .with_name("newsletter")
                                                .with_label(L10n::t("label_newsletter", &LOC))
                                                .with_inline(true),
                                        )
                                        .with_child(
                                            form::Checkbox::switch()
                                                .with_name("notifications")
                                                .with_label(L10n::t("label_notifications", &LOC))
                                                .with_checked(true)
                                                .with_reverse(true),
                                        )
                                        .with_child(
                                            form::Checkbox::switch()
                                                .with_name("dark_mode")
                                                .with_label(L10n::t("label_dark_mode", &LOC))
                                                .with_disabled(true),
                                        ),
                                )
                                // Grupo de casillas de verificación (form::check::Field).
                                .with_child(
                                    form::Fieldset::new()
                                        .with_legend(L10n::t("fieldset_checkgroup", &LOC))
                                        .with_child(
                                            form::check::Field::new()
                                                .with_name("interests")
                                                .with_label(L10n::t("label_interests", &LOC))
                                                .with_help_text(L10n::t("help_interests", &LOC))
                                                .with_item(
                                                    form::check::Item::new(
                                                        "rust",
                                                        L10n::t("check_rust", &LOC),
                                                    )
                                                    .with_checked(true),
                                                )
                                                .with_item(form::check::Item::new(
                                                    "web",
                                                    L10n::t("check_web", &LOC),
                                                ))
                                                .with_item(form::check::Item::new(
                                                    "ai",
                                                    L10n::t("check_ai", &LOC),
                                                ))
                                                .with_item(
                                                    form::check::Item::new(
                                                        "games",
                                                        L10n::t("check_games", &LOC),
                                                    )
                                                    .with_disabled(true),
                                                ),
                                        ),
                                )
                                // Botones de opción (form::radio::Field).
                                .with_child(
                                    form::Fieldset::new()
                                        .with_legend(L10n::t("fieldset_radio", &LOC))
                                        .with_child(
                                            form::radio::Field::new()
                                                .with_name("frequency")
                                                .with_label(L10n::t("label_frequency", &LOC))
                                                .with_item(form::radio::Item::new(
                                                    "daily",
                                                    L10n::t("radio_daily", &LOC),
                                                ))
                                                .with_item(
                                                    form::radio::Item::new(
                                                        "weekly",
                                                        L10n::t("radio_weekly", &LOC),
                                                    )
                                                    .with_checked(true),
                                                )
                                                .with_item(form::radio::Item::new(
                                                    "monthly",
                                                    L10n::t("radio_monthly", &LOC),
                                                ))
                                                .with_item(
                                                    form::radio::Item::new(
                                                        "never",
                                                        L10n::t("radio_never", &LOC),
                                                    )
                                                    .with_disabled(true),
                                                ),
                                        ),
                                )
                                // Campo oculto (form::Hidden).
                                .with_child(
                                    form::Hidden::new()
                                        .with_name("origin")
                                        .with_value("form-selections"),
                                )
                                // Botones de acción.
                                .with_child(
                                    Button::submit(L10n::t("btn_submit", &LOC))
                                        .with_color(ButtonColor::Background(Color::Primary)),
                                )
                                .with_child(
                                    Button::reset(L10n::t("btn_reset", &LOC))
                                        .with_color(ButtonColor::Outline(Color::Secondary)),
                                )
                                .with_child(
                                    Button::plain(L10n::t("btn_cancel", &LOC))
                                        .with_color(ButtonColor::Link),
                                ),
                        ),
                )
                // Bloque 2: campos de texto, multilínea y rango.
                .with_child(
                    Block::new()
                        .with_title(L10n::t("block_text", &LOC))
                        .with_child(
                            Form::new()
                                .with_id("form-text")
                                .with_action("/")
                                .with_method(form::Method::Post)
                                // Campos de texto (form::input::Field).
                                .with_child(
                                    form::Fieldset::new()
                                        .with_legend(L10n::t("fieldset_text", &LOC))
                                        .with_child(
                                            form::input::Field::text()
                                                .with_name("name")
                                                .with_label(L10n::t("label_name", &LOC))
                                                .with_placeholder(L10n::t("placeholder_name", &LOC))
                                                .with_required(true),
                                        )
                                        .with_child(
                                            form::input::Field::email()
                                                .with_name("email")
                                                .with_label(L10n::t("label_email", &LOC))
                                                .with_placeholder(L10n::t(
                                                    "placeholder_email",
                                                    &LOC,
                                                ))
                                                .with_autocomplete(
                                                    Some(form::Autocomplete::email()),
                                                )
                                                .with_required(true),
                                        )
                                        .with_child(
                                            form::input::Field::password()
                                                .with_name("password")
                                                .with_label(L10n::t("label_password", &LOC))
                                                .with_autocomplete(Some(
                                                    form::Autocomplete::new_password(),
                                                ))
                                                .with_required(true),
                                        )
                                        .with_child(
                                            form::input::Field::telephone()
                                                .with_name("phone")
                                                .with_label(L10n::t("label_phone", &LOC))
                                                .with_placeholder(L10n::t(
                                                    "placeholder_phone",
                                                    &LOC,
                                                )),
                                        )
                                        .with_child(
                                            form::input::Field::url()
                                                .with_name("website")
                                                .with_label(L10n::t("label_url", &LOC))
                                                .with_placeholder(L10n::t("placeholder_url", &LOC)),
                                        )
                                        .with_child(
                                            form::input::Field::search()
                                                .with_name("search")
                                                .with_label(L10n::t("label_search", &LOC))
                                                .with_placeholder(L10n::t(
                                                    "placeholder_search",
                                                    &LOC,
                                                )),
                                        ),
                                )
                                // Área de texto (form::Textarea).
                                .with_child(
                                    form::Fieldset::new()
                                        .with_legend(L10n::t("fieldset_textarea", &LOC))
                                        .with_child(
                                            form::Textarea::new()
                                                .with_name("comment")
                                                .with_label(L10n::t("label_comment", &LOC))
                                                .with_placeholder(L10n::t(
                                                    "placeholder_comment",
                                                    &LOC,
                                                ))
                                                .with_rows(Some(4))
                                                .with_help_text(L10n::t("help_comment", &LOC)),
                                        ),
                                )
                                // Control deslizante (form::Range).
                                .with_child(
                                    form::Fieldset::new()
                                        .with_legend(L10n::t("fieldset_range", &LOC))
                                        .with_child(
                                            form::Range::new()
                                                .with_name("rating")
                                                .with_label(L10n::t("label_rating", &LOC))
                                                .with_min(Some(1.0))
                                                .with_max(Some(10.0))
                                                .with_step(Some(1.0))
                                                .with_value(Some(5.0))
                                                .with_help_text(L10n::t("help_rating", &LOC)),
                                        ),
                                )
                                // Campo oculto (form::Hidden).
                                .with_child(
                                    form::Hidden::new()
                                        .with_name("origin")
                                        .with_value("form-text"),
                                )
                                // Botones de acción.
                                .with_child(
                                    Button::submit(L10n::t("btn_submit", &LOC))
                                        .with_color(ButtonColor::Background(Color::Primary)),
                                )
                                .with_child(
                                    Button::reset(L10n::t("btn_reset", &LOC))
                                        .with_color(ButtonColor::Outline(Color::Secondary)),
                                )
                                .with_child(
                                    Button::plain(L10n::t("btn_cancel", &LOC))
                                        .with_color(ButtonColor::Link),
                                ),
                        ),
                )
                // Bloque 3: listas de selección y etiquetas flotantes.
                .with_child(
                    Block::new()
                        .with_title(L10n::t("block_lists", &LOC))
                        .with_child(
                            Form::new()
                                .with_id("form-lists")
                                .with_action("/")
                                .with_method(form::Method::Post)
                                // Listas de selección (form::select::Field).
                                .with_child(
                                    form::Fieldset::new()
                                        .with_legend(L10n::t("fieldset_select", &LOC))
                                        .with_child(
                                            form::select::Field::new()
                                                .with_name("language")
                                                .with_label(L10n::t("label_language", &LOC))
                                                .with_item(
                                                    form::select::Item::new(
                                                        "",
                                                        L10n::t("select_choose", &LOC),
                                                    )
                                                    .with_selected(true),
                                                )
                                                .with_group(
                                                    form::select::Group::new(L10n::t(
                                                        "select_group_europe",
                                                        &LOC,
                                                    ))
                                                    .with_item(form::select::Item::new(
                                                        "es",
                                                        L10n::t("select_spanish", &LOC),
                                                    ))
                                                    .with_item(form::select::Item::new(
                                                        "fr",
                                                        L10n::t("select_french", &LOC),
                                                    )),
                                                )
                                                .with_group(
                                                    form::select::Group::new(L10n::t(
                                                        "select_group_americas",
                                                        &LOC,
                                                    ))
                                                    .with_item(form::select::Item::new(
                                                        "en",
                                                        L10n::t("select_english", &LOC),
                                                    ))
                                                    .with_item(form::select::Item::new(
                                                        "pt",
                                                        L10n::t("select_portuguese", &LOC),
                                                    )),
                                                )
                                                .with_item(
                                                    form::select::Item::new(
                                                        "xx",
                                                        L10n::t("select_disabled", &LOC),
                                                    )
                                                    .with_disabled(true),
                                                )
                                                .with_required(true),
                                        )
                                        .with_child(
                                            form::select::Field::new()
                                                .with_name("technologies")
                                                .with_label(L10n::t("label_technologies", &LOC))
                                                .with_item(
                                                    form::select::Item::new(
                                                        "rust",
                                                        L10n::n("Rust"),
                                                    )
                                                    .with_selected(true),
                                                )
                                                .with_item(
                                                    form::select::Item::new(
                                                        "python",
                                                        L10n::n("Python"),
                                                    )
                                                    .with_selected(true),
                                                )
                                                .with_item(form::select::Item::new(
                                                    "javascript",
                                                    L10n::n("JavaScript"),
                                                ))
                                                .with_item(form::select::Item::new(
                                                    "go",
                                                    L10n::n("Go"),
                                                ))
                                                .with_item(form::select::Item::new(
                                                    "typescript",
                                                    L10n::n("TypeScript"),
                                                ))
                                                .with_multiple(true)
                                                .with_rows(Some(4))
                                                .with_help_text(L10n::t("help_technologies", &LOC)),
                                        ),
                                )
                                // Etiquetas flotantes.
                                .with_child(
                                    form::Fieldset::new()
                                        .with_legend(L10n::t("fieldset_floating", &LOC))
                                        .with_child(
                                            form::input::Field::text()
                                                .with_name("fl_name")
                                                .with_label(L10n::t("label_name", &LOC))
                                                .with_placeholder(L10n::t("placeholder_name", &LOC))
                                                .with_floating_label(true)
                                                .with_required(true),
                                        )
                                        .with_child(
                                            form::Textarea::new()
                                                .with_name("fl_comment")
                                                .with_label(L10n::t("label_comment", &LOC))
                                                .with_placeholder(L10n::t(
                                                    "placeholder_comment",
                                                    &LOC,
                                                ))
                                                .with_floating_label(true),
                                        )
                                        .with_child(
                                            form::select::Field::new()
                                                .with_name("fl_country")
                                                .with_label(L10n::t("label_country", &LOC))
                                                .with_item(
                                                    form::select::Item::new(
                                                        "",
                                                        L10n::t("select_choose", &LOC),
                                                    )
                                                    .with_selected(true),
                                                )
                                                .with_item(form::select::Item::new(
                                                    "de",
                                                    L10n::t("select_germany", &LOC),
                                                ))
                                                .with_item(form::select::Item::new(
                                                    "es",
                                                    L10n::t("select_spain", &LOC),
                                                ))
                                                .with_item(form::select::Item::new(
                                                    "fr",
                                                    L10n::t("select_france", &LOC),
                                                ))
                                                .with_item(form::select::Item::new(
                                                    "pt",
                                                    L10n::t("select_portugal", &LOC),
                                                ))
                                                .with_floating_label(true)
                                                .with_required(true),
                                        ),
                                )
                                // Campo oculto (form::Hidden).
                                .with_child(
                                    form::Hidden::new()
                                        .with_name("origin")
                                        .with_value("form-lists"),
                                )
                                // Botones de acción.
                                .with_child(
                                    Button::submit(L10n::t("btn_submit", &LOC))
                                        .with_color(ButtonColor::Background(Color::Primary)),
                                )
                                .with_child(
                                    Button::reset(L10n::t("btn_reset", &LOC))
                                        .with_color(ButtonColor::Outline(Color::Secondary)),
                                )
                                .with_child(
                                    Button::plain(L10n::t("btn_cancel", &LOC))
                                        .with_color(ButtonColor::Link),
                                ),
                        ),
                ),
        )
        .render()
}

#[pagetop::main]
async fn main() -> std::io::Result<()> {
    Application::prepare(&FormControls).run()?.await
}