From: Andrea Zagli Date: Sun, 16 Aug 2020 14:01:10 +0000 (+0200) Subject: Test of ZakFormForm::delete with json provider. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=fb10848a8a3ffb1ff53ed9916f594216d54b64be;p=zakform%2Ftests Test of ZakFormForm::delete with json provider. --- diff --git a/src/json_ini.c b/src/json_ini.c index e18c361..e4f54a2 100644 --- a/src/json_ini.c +++ b/src/json_ini.c @@ -40,6 +40,7 @@ main (int argc, char *argv[]) gint id; ZakFormCgiForm *form; + ZakFormCgiFormElement *element; ZakFormJsonProvider *provider; @@ -85,50 +86,74 @@ main (int argc, char *argv[]) "action", g_strdup_printf ("json_ini?filename=%s", filename), NULL); + provider = zak_form_json_provider_new_from_file (filename); + if (zak_form_form_load_from_file (ZAK_FORM_FORM (form), XMLDIR "/cgi.xml")) { zak_form_cgi_form_set_bootstrap_version (form, "4"); if (zak_cgi_main_is_post (zakcgimain)) { - /* validating the form */ zak_form_cgi_form_bind (form); - if (zak_form_form_is_valid (ZAK_FORM_FORM (form))) + + if (zak_cgi_main_get_stdin_field (zakcgimain, "delete") != NULL) { - g_string_append (str, "
Form is valid!!!
"); - provider = zak_form_json_provider_new_from_file (filename); if (provider != NULL) { - zak_form_form_insert (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (provider)); + zak_form_form_delete (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (provider)); g_object_unref (provider); + g_string_append (str, "
Deleted!!!
"); } } else { - g_string_append (str, "
Form is not valid!!!"); - - guint m; - GPtrArray *ar_messages = zak_form_form_get_messages (ZAK_FORM_FORM (form)); - if (ar_messages != NULL) + /* validating the form */ + if (zak_form_form_is_valid (ZAK_FORM_FORM (form))) + { + g_string_append (str, "
Form is valid!!!
"); + if (provider != NULL) + { + zak_form_form_insert (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (provider)); + g_object_unref (provider); + } + } + else { - if (ar_messages->len > 0) + g_string_append (str, "
Form is not valid!!!"); + + guint m; + GPtrArray *ar_messages = zak_form_form_get_messages (ZAK_FORM_FORM (form)); + if (ar_messages != NULL) { - g_string_append (str, "\n
    \n"); - for (m = 0; m < ar_messages->len; m++) + if (ar_messages->len > 0) { - g_string_append_printf (str, "\n
  • %s
  • ", (gchar *)g_ptr_array_index (ar_messages, m)); + g_string_append (str, "\n
      \n"); + for (m = 0; m < ar_messages->len; m++) + { + g_string_append_printf (str, "\n
    • %s
    • ", (gchar *)g_ptr_array_index (ar_messages, m)); + } + g_string_append (str, "\n
    \n"); } - g_string_append (str, "\n
\n"); } - } - g_string_append (str, "
"); + g_string_append (str, "
"); + + element = zak_form_cgi_form_element_submit_new_attrs ("delete", + "zak-cgi-content", "Delete", + NULL); + zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element)); - g_string_append (str, zak_form_cgi_form_render (form)); + g_string_append (str, zak_form_cgi_form_render (form)); + } } } else { + element = zak_form_cgi_form_element_submit_new_attrs ("delete", + "zak-cgi-content", "Delete", + NULL); + zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element)); + zak_form_form_clear (ZAK_FORM_FORM (form)); if (id > 0) { @@ -141,6 +166,7 @@ main (int argc, char *argv[]) g_object_unref (provider); } } + g_string_append (str, zak_form_cgi_form_render (form)); } }