]> saetta.ns0.it Git - rust/zakform/commitdiff
c2rs: added support for validator date.
authorAndrea Zagli <azagli@libero.it>
Sun, 21 Jan 2024 08:35:28 +0000 (09:35 +0100)
committerAndrea Zagli <azagli@libero.it>
Sun, 21 Jan 2024 08:35:28 +0000 (09:35 +0100)
src/bin/c2rs.rs

index 1f194ea5d38362160eda334eaa5c1d42815ba01b..94e533a3ee281b131d9d5796f2cb6bf48106e0b3 100644 (file)
@@ -100,6 +100,12 @@ pub struct ZakFormElementFilter {
 pub struct ZakFormElementValidator {
        #[serde(rename = "@type")]
        pub vtype: String,
+       #[serde(rename = "@type_comp")]
+       pub type_comp: String,
+       #[serde(rename = "@value_comp")]
+       pub value_comp: String,
+       #[serde(rename = "$text")]
+       pub text: String,
 }
 
 #[derive(Default, Debug, Clone, PartialEq, Deserialize)]
@@ -248,9 +254,28 @@ fn main() {
                        };
                }
 
-               for validator in e.validators {
+               for (i, validator) in e.validators.into_iter().enumerate() {
                        match validator.vtype.as_str() {
                                "zak_form_element_validator_notempty" => { writeln!(output, r#"fi.add_validator(Box::new(zakform::validators::ValidatorNotEmpty::new("{}_notempty")));"#, e.id); },
+                               "zak_form_element_validator_date" => {
+                                       writeln!(output, r#"let mut v = zakform::validators::ValidatorDate::new("{}_date_{}");"#, e.id, i);
+
+                                       match validator.type_comp.as_str() {
+                                               "lt" => { writeln!(output, "v.set_compare_type(Some(zakform::validators::ValidatorDateCompareType::Less));"); },
+                                               "let" => { writeln!(output, "v.set_compare_type(Some(zakform::validators::ValidatorDateCompareType::LessEq));"); },
+                                               "e" => { writeln!(output, "v.set_compare_type(Some(zakform::validators::ValidatorDateCompareType::Eq));"); },
+                                               "ne" => {},
+                                               "gt" => { writeln!(output, "v.set_compare_type(Some(zakform::validators::ValidatorDateCompareType::Great));"); },
+                                               "get" => { writeln!(output, "v.set_compare_type(Some(zakform::validators::ValidatorDateCompareType::GreatEq));"); },
+                                               _ => { },
+                                       };
+
+                                       if validator.value_comp != "" {
+                                               writeln!(output, r#"v.set_compare_value(Some("{}"));"#, validator.value_comp);
+                                       }
+
+                                       writeln!(output, "fi.add_validator(Box::new(v));");
+                               },
                                _ => { },
                        };
                }