]> saetta.ns0.it Git - zakform/tests/commitdiff
Test of ZakFormForm::delete with json provider. master
authorAndrea Zagli <azagli@libero.it>
Sun, 16 Aug 2020 14:01:10 +0000 (16:01 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 16 Aug 2020 14:01:10 +0000 (16:01 +0200)
src/json_ini.c

index e18c3614a57ca708b5ebcbb9f8c61879f77163fc..e4f54a26fe2ae6820969714d212863c348ae6507 100644 (file)
@@ -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, "<div class=\"alert alert-success\" role=\"alert\">Form is valid!!!</div>");
-                                                       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, "<div class=\"alert alert-success\" role=\"alert\">Deleted!!!</div>");
                                                                }
                                                }
                                        else
                                                {
-                                                       g_string_append (str, "<div class=\"alert alert-danger\" role=\"alert\">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, "<div class=\"alert alert-success\" role=\"alert\">Form is valid!!!</div>");
+                                                                       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, "<div class=\"alert alert-danger\" role=\"alert\">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<ul>\n");
-                                                                                       for (m = 0; m < ar_messages->len; m++)
+                                                                                       if (ar_messages->len > 0)
                                                                                                {
-                                                                                                       g_string_append_printf (str, "\n<li>%s</li>", (gchar *)g_ptr_array_index (ar_messages, m));
+                                                                                                       g_string_append (str, "\n<ul>\n");
+                                                                                                       for (m = 0; m < ar_messages->len; m++)
+                                                                                                               {
+                                                                                                                       g_string_append_printf (str, "\n<li>%s</li>", (gchar *)g_ptr_array_index (ar_messages, m));
+                                                                                                               }
+                                                                                                       g_string_append (str, "\n</ul>\n");
                                                                                                }
-                                                                                       g_string_append (str, "\n</ul>\n");
                                                                                }
-                                                               }
 
-                                                       g_string_append (str, "</div>");
+                                                                       g_string_append (str, "</div>");
+
+                                                                       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));
                                }
                }