/*
- * Copyright (C) 2017 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2017-2020 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
gboolean condition;
gboolean condition_type;
LogicType logic_type;
- ZakFormElementValidator *validator;
+ ZakFormValidator *form_validator;
+ ZakFormElementValidator *element_validator;
ZakFormElement *element;
gchar *message;
} Node;
if (xmlStrEqual (cur->name, (xmlChar *)"condition"))
{
ZakFormElement *element;
- ZakFormElementValidatorConstructorFunc validator_constructor;
GNode *gnode;
Node *n;
n->condition_type= zak_utils_string_to_boolean ((gchar *)xmlGetProp (cur, (xmlChar *)"condition_type"));
- element = zak_form_form_get_element_by_id (form, (gchar *)xmlGetProp (cur, (xmlChar *)"element"));
- if (!ZAK_FORM_IS_ELEMENT (element))
+ if (g_strcmp0((gchar *)xmlGetProp (cur, (xmlChar *)"validator_type"), "form") == 0)
{
- g_warning ("Element «%s» not present in form.",
- (gchar *)xmlGetProp (cur, (xmlChar *)"element"));
- cur = cur->next;
- continue;
- }
+ ZakFormValidatorConstructorFunc validator_constructor;
- validator_constructor = zak_form_get_form_element_validator ((gchar *)xmlGetProp (cur, (xmlChar *)"validator"));
- if (validator_constructor == NULL)
- {
- g_warning ("Validator «%s» not found.",
- (gchar *)xmlGetProp (cur, (xmlChar *)"validator"));
- cur = cur->next;
- continue;
+ n->element_validator = NULL;
+
+ validator_constructor = zak_form_get_form_validator ((gchar *)xmlGetProp (cur, (xmlChar *)"validator"));
+ if (validator_constructor == NULL)
+ {
+ g_warning ("Validator «%s» not found.",
+ (gchar *)xmlGetProp (cur, (xmlChar *)"validator"));
+ cur = cur->next;
+ continue;
+ }
+
+ n->form_validator = validator_constructor ();
+ zak_form_validator_xml_parsing (n->form_validator, cur, form);
}
+ else
+ {
+ ZakFormElementValidatorConstructorFunc validator_constructor;
- n->validator = validator_constructor ();
- zak_form_element_validator_xml_parsing (n->validator, cur);
+ n->form_validator = NULL;
- n->element = element;
+ element = zak_form_form_get_element_by_id (form, (gchar *)xmlGetProp (cur, (xmlChar *)"element"));
+ if (!ZAK_FORM_IS_ELEMENT (element))
+ {
+ g_warning ("Element «%s» not present in form.",
+ (gchar *)xmlGetProp (cur, (xmlChar *)"element"));
+ cur = cur->next;
+ continue;
+ }
+
+ validator_constructor = zak_form_get_form_element_validator ((gchar *)xmlGetProp (cur, (xmlChar *)"validator"));
+ if (validator_constructor == NULL)
+ {
+ g_warning ("Validator «%s» not found.",
+ (gchar *)xmlGetProp (cur, (xmlChar *)"validator"));
+ cur = cur->next;
+ continue;
+ }
+
+ n->element_validator = validator_constructor ();
+ zak_form_element_validator_xml_parsing (n->element_validator, cur);
+
+ n->element = element;
+ }
n->message = NULL;
else if (xmlStrEqual (cur->name, (xmlChar *)"validator"))
{
ZakFormElement *element;
- ZakFormElementValidatorConstructorFunc validator_constructor;
Node *n;
- element = zak_form_form_get_element_by_id (form, (gchar *)xmlGetProp (cur, (xmlChar *)"element"));
- if (!ZAK_FORM_IS_ELEMENT (element))
+ if (g_strcmp0 ((gchar *)xmlGetProp (cur, (xmlChar *)"element"), "form") == 0)
{
- g_warning ("Element «%s» not present in form.",
- (gchar *)xmlGetProp (cur, (xmlChar *)"element"));
- cur = cur->next;
- continue;
- }
+ ZakFormValidatorConstructorFunc validator_constructor;
- n = (Node *)g_new0 (Node, 1);
+ n->element_validator = NULL;
- validator_constructor = zak_form_get_form_element_validator ((gchar *)xmlGetProp (cur, (xmlChar *)"type"));
- if (validator_constructor == NULL)
- {
- g_warning ("Validator «%s» not found.",
- (gchar *)xmlGetProp (cur, (xmlChar *)"type"));
- cur = cur->next;
- continue;
+ n = (Node *)g_new0 (Node, 1);
+
+ validator_constructor = zak_form_get_form_validator ((gchar *)xmlGetProp (cur, (xmlChar *)"type"));
+ if (validator_constructor == NULL)
+ {
+ g_warning ("Validator «%s» not found.",
+ (gchar *)xmlGetProp (cur, (xmlChar *)"type"));
+ cur = cur->next;
+ continue;
+ }
+
+ n->form_validator = validator_constructor ();
+ zak_form_validator_xml_parsing (n->element_validator, cur, form);
}
+ else
+ {
+ ZakFormElementValidatorConstructorFunc validator_constructor;
+
+ n->form_validator = NULL;
- n->validator = validator_constructor ();
- zak_form_element_validator_xml_parsing (n->validator, cur);
+ element = zak_form_form_get_element_by_id (form, (gchar *)xmlGetProp (cur, (xmlChar *)"element"));
+ if (!ZAK_FORM_IS_ELEMENT (element))
+ {
+ g_warning ("Element «%s» not present in form.",
+ (gchar *)xmlGetProp (cur, (xmlChar *)"element"));
+ cur = cur->next;
+ continue;
+ }
- n->element = element;
+ n = (Node *)g_new0 (Node, 1);
+
+ validator_constructor = zak_form_get_form_element_validator ((gchar *)xmlGetProp (cur, (xmlChar *)"type"));
+ if (validator_constructor == NULL)
+ {
+ g_warning ("Validator «%s» not found.",
+ (gchar *)xmlGetProp (cur, (xmlChar *)"type"));
+ cur = cur->next;
+ continue;
+ }
+
+ n->element_validator = validator_constructor ();
+ zak_form_element_validator_xml_parsing (n->element_validator, cur);
+
+ n->element = element;
+ }
if (tree == NULL)
{
if (n_child->condition)
{
- if (zak_form_element_validator_validate (n_child->validator,
- zak_form_element_get_value (n_child->element)) == n_child->condition_type)
+ if (n_child->form_validator != NULL)
{
- switch (n->logic_type)
+ if (zak_form_validator_validate (n_child->element_validator) == n_child->condition_type)
{
- case LOGIC_TYPE_AND:
- ret = (ret && _zak_form_validator_composite_validate (validator, child));
- break;
-
- case LOGIC_TYPE_OR:
- ret = (ret || _zak_form_validator_composite_validate (validator, child));
- break;
+ switch (n->logic_type)
+ {
+ case LOGIC_TYPE_AND:
+ ret = (ret && _zak_form_validator_composite_validate (validator, child));
+ break;
+
+ case LOGIC_TYPE_OR:
+ ret = (ret || _zak_form_validator_composite_validate (validator, child));
+ break;
+ }
+ }
+ }
+ else
+ {
+ if (zak_form_element_validator_validate (n_child->element_validator,
+ zak_form_element_get_value (n_child->element)) == n_child->condition_type)
+ {
+ switch (n->logic_type)
+ {
+ case LOGIC_TYPE_AND:
+ ret = (ret && _zak_form_validator_composite_validate (validator, child));
+ break;
+
+ case LOGIC_TYPE_OR:
+ ret = (ret || _zak_form_validator_composite_validate (validator, child));
+ break;
+ }
}
}
}
}
else
{
- ret = (ret && zak_form_element_validator_validate (n_child->validator,
- zak_form_element_get_value (n_child->element)));
+ if (n_child->form_validator != NULL)
+ {
+ ret = (ret && zak_form_validator_validate (n_child->form_validator));
+ }
+ else
+ {
+ ret = (ret && zak_form_element_validator_validate (n_child->element_validator,
+ zak_form_element_get_value (n_child->element)));
+ }
}
break;
}
else
{
- ret = (ret || zak_form_element_validator_validate (n_child->validator,
- zak_form_element_get_value (n_child->element)));
+ if (n_child->form_validator != NULL)
+ {
+ ret = (ret || zak_form_validator_validate (n_child->form_validator));
+ }
+ else
+ {
+ ret = (ret || zak_form_element_validator_validate (n_child->element_validator,
+ zak_form_element_get_value (n_child->element)));
+ }
}
break;
}