]> saetta.ns0.it Git - zakform/cgi/commitdiff
Added properties text and inline to ZakFormCgiFormElementCheck.
authorAndrea Zagli <azagli@libero.it>
Sat, 6 May 2017 15:15:27 +0000 (17:15 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 6 May 2017 15:15:27 +0000 (17:15 +0200)
src/formelement.c
src/formelementcheck.c
src/formelementcheck.h
src/formelementradio.c

index f17829c5d92bdf409a3d908f390dd0b52125c711..ef619580e6b8cffa096cd69e259bebd58e02ec6f 100644 (file)
@@ -138,7 +138,7 @@ zak_form_cgi_form_element_set_label (ZakFormCgiFormElement *element, const gchar
 
                        g_hash_table_replace (priv->ht_label_attrs, "zak-cgi-content", g_strdup (label));
                        g_hash_table_replace (priv->ht_label_attrs, "for", priv->id != NULL  ? g_strdup (priv->id) : g_strdup (""));
-                       g_hash_table_replace (priv->ht_label_attrs, "class", "control-label");
+                       g_hash_table_replace (priv->ht_label_attrs, "class", g_strdup ("control-label"));
 
                        zak_form_element_set_long_name (ZAK_FORM_ELEMENT (element), label);
                }
@@ -174,6 +174,8 @@ gchar
 
        guint i;
 
+       gchar *attr_class;
+
        ZakFormCgiFormElementPrivate *priv;
 
        priv = ZAK_FORM_CGI_FORM_ELEMENT_GET_PRIVATE (element);
@@ -193,8 +195,6 @@ gchar
 
        if (ZAK_FORM_CGI_IS_FORM_ELEMENT (element) && ZAK_FORM_CGI_FORM_ELEMENT_GET_CLASS (element)->render != NULL)
                {
-                       gchar *attr_class;
-
                        attr_class = g_hash_table_lookup (priv->ht_attrs, "class");
                        if (attr_class != NULL)
                                {
@@ -206,7 +206,7 @@ gchar
                                }
                        else
                                {
-                                       g_hash_table_replace (priv->ht_attrs, g_strdup ("class"), g_strdup ("form-control"));
+                                       g_hash_table_replace (priv->ht_attrs, "class", g_strdup ("form-control"));
                                }
 
                        if (!zak_form_element_get_editable (ZAK_FORM_ELEMENT (element)))
index 804209577b44ae9883cc0107ad42450965f9e334..a8c1b83d17bf92a35663e34ff9bad4a5e73e0f37 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2016 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2017 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
@@ -31,13 +31,13 @@ static void zak_form_cgi_form_element_check_init (ZakFormCgiFormElementCheck *za
 static gchar *zak_form_cgi_form_element_check_render (ZakFormCgiFormElement *element);
 
 static void zak_form_cgi_form_element_check_set_property (GObject *object,
-                               guint property_id,
-                               const GValue *value,
-                               GParamSpec *pspec);
+                                                          guint property_id,
+                                                          const GValue *value,
+                                                          GParamSpec *pspec);
 static void zak_form_cgi_form_element_check_get_property (GObject *object,
-                               guint property_id,
-                               GValue *value,
-                               GParamSpec *pspec);
+                                                          guint property_id,
+                                                          GValue *value,
+                                                          GParamSpec *pspec);
 
 static void zak_form_cgi_form_element_check_dispose (GObject *gobject);
 static void zak_form_cgi_form_element_check_finalize (GObject *gobject);
@@ -47,7 +47,8 @@ static void zak_form_cgi_form_element_check_finalize (GObject *gobject);
 typedef struct _ZakFormCgiFormElementCheckPrivate ZakFormCgiFormElementCheckPrivate;
 struct _ZakFormCgiFormElementCheckPrivate
        {
-               gpointer empty;
+               gchar *text;
+               gboolean in_line;
        };
 
 G_DEFINE_TYPE (ZakFormCgiFormElementCheck, zak_form_cgi_form_element_check, ZAK_FORM_CGI_TYPE_FORM_ELEMENT)
@@ -73,6 +74,8 @@ zak_form_cgi_form_element_check_init (ZakFormCgiFormElementCheck *zak_form_cgi_f
 {
        ZakFormCgiFormElementCheckPrivate *priv = ZAK_FORM_CGI_FORM_ELEMENT_CHECK_GET_PRIVATE (zak_form_cgi_form_element_check);
 
+       priv->text = g_strdup ("");
+       priv->in_line = TRUE;
 }
 
 /**
@@ -99,7 +102,7 @@ ZakFormCgiFormElement
  */
 ZakFormCgiFormElement
 *zak_form_cgi_form_element_check_new_attrs (const gchar *id,
-                                                                          ...)
+                                            ...)
 {
        va_list ap;
 
@@ -115,12 +118,53 @@ ZakFormCgiFormElement
        g_hash_table_replace (ht_attrs, "type", "checkbox");
 
        ZAK_FORM_CGI_FORM_ELEMENT_CLASS (zak_form_cgi_form_element_check_parent_class)->construct (zak_form_cgi_form_element_check,
-                                                                                                                                                                        id,
-                                                                                                                                                                        ht_attrs);
+                                    id,
+                                    ht_attrs);
 
        return zak_form_cgi_form_element_check;
 }
 
+gchar
+*zak_form_cgi_form_element_check_get_text (ZakFormCgiFormElementCheck *element)
+{
+       ZakFormCgiFormElementCheckPrivate *priv = ZAK_FORM_CGI_FORM_ELEMENT_CHECK_GET_PRIVATE (element);
+       g_warning("TEXT %s",priv->text);
+       return g_strdup (priv->text);
+}
+
+void
+zak_form_cgi_form_element_check_set_text (ZakFormCgiFormElementCheck *element, const gchar *text)
+{
+       ZakFormCgiFormElementCheckPrivate *priv = ZAK_FORM_CGI_FORM_ELEMENT_CHECK_GET_PRIVATE (element);
+
+       g_free (priv->text);
+
+       if (text == NULL)
+               {
+                       priv->text = g_strdup ("");
+               }
+       else
+               {
+                       priv->text = g_strdup (text);
+               }
+}
+
+gboolean
+zak_form_cgi_form_element_check_get_in_line (ZakFormCgiFormElementCheck *element)
+{
+       ZakFormCgiFormElementCheckPrivate *priv = ZAK_FORM_CGI_FORM_ELEMENT_CHECK_GET_PRIVATE (element);
+
+       return priv->in_line;
+}
+
+void
+zak_form_cgi_form_element_check_set_in_line (ZakFormCgiFormElementCheck *element, gboolean in_line)
+{
+       ZakFormCgiFormElementCheckPrivate *priv = ZAK_FORM_CGI_FORM_ELEMENT_CHECK_GET_PRIVATE (element);
+
+       priv->in_line = in_line;
+}
+
 gboolean
 zak_form_cgi_form_element_check_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode)
 {
@@ -142,16 +186,26 @@ zak_form_cgi_form_element_check_xml_parsing (ZakFormElement *element, xmlNodePtr
        cur = xmlnode->children;
        while (cur != NULL)
                {
-                       if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0)
+                       if (xmlStrEqual (cur->name, (const xmlChar *)"id"))
                                {
                                        id = (gchar *)xmlNodeGetContent (cur);
                                }
-                       else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0)
+                       else if (xmlStrEqual (cur->name, (const xmlChar *)"label"))
                                {
                                        zak_form_cgi_form_element_set_label (ZAK_FORM_CGI_FORM_ELEMENT (element), (gchar *)xmlNodeGetContent (cur), NULL);
                                }
-                       else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0)
+                       else if (xmlStrEqual (cur->name, (const xmlChar *)"text"))
+                               {
+
+                               }
+                       else if (xmlStrEqual (cur->name, (const xmlChar *)"zak-cgi-text"))
+                               {
+                                       zak_form_cgi_form_element_check_set_text (ZAK_FORM_CGI_FORM_ELEMENT_CHECK (element), (gchar *)xmlNodeGetContent (cur));
+                               }
+                       else if (xmlStrEqual (cur->name, (const xmlChar *)"zak-cgi-inline"))
                                {
+                                       zak_form_cgi_form_element_check_set_in_line (ZAK_FORM_CGI_FORM_ELEMENT_CHECK (element),
+                                                                                    (gboolean)xmlStrEqual (xmlNodeGetContent (cur), (const xmlChar *)"TRUE"));
                                }
                        else
                                {
@@ -164,8 +218,8 @@ zak_form_cgi_form_element_check_xml_parsing (ZakFormElement *element, xmlNodePtr
        if (id != NULL)
                {
                        ZAK_FORM_CGI_FORM_ELEMENT_CLASS (zak_form_cgi_form_element_check_parent_class)->construct (ZAK_FORM_CGI_FORM_ELEMENT (element),
-                                                                                                                                                                                        id,
-                                                                                                                                                                                        ht_attrs);
+                                                    id,
+                                                    ht_attrs);
                        ret = TRUE;
                }
        else
@@ -180,13 +234,17 @@ static gchar
 *zak_form_cgi_form_element_check_render (ZakFormCgiFormElement *element)
 {
        gchar *ret;
+       GString *str;
 
        GHashTable *ht_attrs;
 
        gchar *value;
+       gchar *attr_class;
 
        ZakFormCgiFormElementClass *klass;
 
+       ZakFormCgiFormElementCheckPrivate *priv = ZAK_FORM_CGI_FORM_ELEMENT_CHECK_GET_PRIVATE (element);
+
        klass = (ZakFormCgiFormElementClass *)g_type_class_peek_parent (ZAK_FORM_CGI_FORM_ELEMENT_CHECK_GET_CLASS (ZAK_FORM_CGI_FORM_ELEMENT_CHECK (element)));
 
        ht_attrs = klass->get_ht_attrs (element);
@@ -198,7 +256,23 @@ static gchar
                        g_hash_table_insert (ht_attrs, (gpointer)"checked", (gpointer)"checked");
                }
 
-       ret = zak_cgi_tag_tag_ht ("input", zak_form_cgi_form_element_get_id (element), ht_attrs);
+       attr_class = g_hash_table_lookup (ht_attrs, "class");
+       if (attr_class != NULL)
+               {
+                       g_hash_table_insert (ht_attrs, "class", g_strjoinv ("", g_strsplit (attr_class, "form-control", -1)));
+                       g_free (attr_class);
+               }
+
+       str = g_string_new ("");
+       g_string_append_printf (str, "\n%s<label%s>\n%s %s</label>%s",
+                               priv->in_line ? "" : "<div class=\"checkbox\">\n",
+                               priv->in_line ? " class=\"checkbox-inline\"" : "",
+                               zak_cgi_tag_tag_ht ("input", zak_form_cgi_form_element_get_id (element), ht_attrs),
+                               zak_form_cgi_form_element_check_get_text (ZAK_FORM_CGI_FORM_ELEMENT_CHECK (element)),
+                               priv->in_line ? "" : "\n</div><br/>");
+
+       ret = g_strdup (str->str);
+       g_string_free (str, TRUE);
 
        return ret;
 }
@@ -206,9 +280,9 @@ static gchar
 /* PRIVATE */
 static void
 zak_form_cgi_form_element_check_set_property (GObject *object,
-                   guint property_id,
-                   const GValue *value,
-                   GParamSpec *pspec)
+                                              guint property_id,
+                                              const GValue *value,
+                                              GParamSpec *pspec)
 {
        ZakFormCgiFormElementCheck *zak_form_cgi_form_element_check = (ZakFormCgiFormElementCheck *)object;
        ZakFormCgiFormElementCheckPrivate *priv = ZAK_FORM_CGI_FORM_ELEMENT_CHECK_GET_PRIVATE (zak_form_cgi_form_element_check);
@@ -223,9 +297,9 @@ zak_form_cgi_form_element_check_set_property (GObject *object,
 
 static void
 zak_form_cgi_form_element_check_get_property (GObject *object,
-                   guint property_id,
-                   GValue *value,
-                   GParamSpec *pspec)
+                                              guint property_id,
+                                              GValue *value,
+                                              GParamSpec *pspec)
 {
        ZakFormCgiFormElementCheck *zak_form_cgi_form_element_check = (ZakFormCgiFormElementCheck *)object;
        ZakFormCgiFormElementCheckPrivate *priv = ZAK_FORM_CGI_FORM_ELEMENT_CHECK_GET_PRIVATE (zak_form_cgi_form_element_check);
index 538e654522d791e03a1c72527693e1d8b68facf6..666a3c3361e2c1037f6de8bf6b798ad61936e917 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2017 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
@@ -56,6 +56,12 @@ GType zak_form_cgi_form_element_check_get_type (void);
 ZakFormCgiFormElement *zak_form_cgi_form_element_check_new (void);
 ZakFormCgiFormElement *zak_form_cgi_form_element_check_new_attrs (const gchar *id, ...);
 
+gchar *zak_form_cgi_form_element_check_get_text (ZakFormCgiFormElementCheck *element);
+void zak_form_cgi_form_element_check_set_text (ZakFormCgiFormElementCheck *element, const gchar *text);
+
+gboolean zak_form_cgi_form_element_check_get_in_line (ZakFormCgiFormElementCheck *element);
+void zak_form_cgi_form_element_check_set_in_line (ZakFormCgiFormElementCheck *element, gboolean in_line);
+
 gboolean zak_form_cgi_form_element_check_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode);
 
 
index 11a1dbc47ca5b0560d6c16134f19e659bfe44db0..93465af2eb7d281fec7b741229f052e14a411a1b 100644 (file)
@@ -233,6 +233,8 @@ static gchar
        GHashTable *ht_label_attrs;
        GHashTable *ht_attrs_option;
 
+       gchar *attr_class;
+
        gchar *element_value;
 
        guint new_id;
@@ -262,8 +264,6 @@ static gchar
        g_hash_table_iter_init (&iter, priv->ht_options);
        while (g_hash_table_iter_next (&iter, &key, &value))
                {
-                       gchar *attr_class;
-
                        ht_attrs_option = g_hash_table_new (g_str_hash, g_str_equal);
                        zak_utils_ghashtable_copy (ht_attrs, ht_attrs_option);
 
@@ -287,7 +287,7 @@ static gchar
                                                priv->in_line ? " class=\"radio-inline\"" : "",
                                                zak_cgi_tag_tag_ht ("input",
                                                                    g_strdup_printf ("%s_%d",
-                                                                                     zak_form_cgi_form_element_get_id (element),
+                                                                                    zak_form_cgi_form_element_get_id (element),
                                                                                     ++new_id),
                                                                    ht_attrs_option),
                                                value,