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
//! InputImage - Controller (field type)

use core::fmt::Debug;
use serde::{Deserialize, Serialize};

use crate::models::helpers::ImageData;

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct InputImage {
    pub id: String, // The value is determined automatically. Format: "model-name--field-name".
    pub label: String, // Web form field name.
    pub field_type: String, // Field type.
    pub input_type: String, // The value is determined automatically.
    pub name: String, // The value is determined automatically.
    pub value: Option<ImageData>, // Sets the value of an element.
    pub default: Option<ImageData>, // Value by default
    pub media_root: String, // Root partition for storing files.
    pub media_url: String, // Url address to the root section.
    pub target_dir: String, // Directory for images inside media directory (inner path). Example: "images/avatars".
    pub accept: String,     // Example: "image/jpeg,image/png,image/gif"
    pub placeholder: String, // Displays prompt text.
    pub required: bool,     // Mandatory field.
    pub disabled: bool,     // Blocks access and modification of the element.
    pub readonly: bool,     // Specifies that the field cannot be modified by the user.
    pub thumbnails: Vec<(String, u32)>, // From one to four inclusive. Example: vec![("xs", 150),("sm", 300),("md", 600),("lg", 1200)] Hint: An Intel i7-4770 processor or better is recommended.
    pub is_hide: bool,                  // Hide field from user.
    pub other_attrs: String, // Example: r# "autofocus tabindex="some number" size="some numberString::new()#.
    pub css_classes: String, // Example: "class-name-1 class-name-2".
    pub hint: String,        // Additional explanation for the user.
    pub warning: String,     // The value is determined automatically.
    pub error: String,       // The value is determined automatically.
    pub group: u32, // To optimize field traversal in the `paladins/check()` method. Hint: It is recommended not to change.
}

impl Default for InputImage {
    fn default() -> Self {
        Self {
            id: String::new(),
            label: String::new(),
            field_type: String::from("InputImage"),
            input_type: String::from("file"),
            name: String::new(),
            value: None,
            default: None,
            media_root: String::from("./media"),
            media_url: String::from("/media"),
            target_dir: String::from("images"),
            accept: String::new(),
            placeholder: String::new(),
            required: false,
            disabled: false,
            readonly: false,
            thumbnails: Vec::new(),
            is_hide: false,
            other_attrs: String::new(),
            css_classes: String::new(),
            hint: String::new(),
            warning: String::new(),
            error: String::new(),
            group: 9,
        }
    }
}

impl InputImage {
    pub fn get(&self) -> Option<ImageData> {
        self.value.clone()
    }
    pub fn set(&mut self, value: ImageData) {
        self.value = Some(value);
    }
}