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);
}
guint i;
+ gchar *attr_class;
+
ZakFormCgiFormElementPrivate *priv;
priv = ZAK_FORM_CGI_FORM_ELEMENT_GET_PRIVATE (element);
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)
{
}
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)))
/*
- * 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
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);
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)
{
ZakFormCgiFormElementCheckPrivate *priv = ZAK_FORM_CGI_FORM_ELEMENT_CHECK_GET_PRIVATE (zak_form_cgi_form_element_check);
+ priv->text = g_strdup ("");
+ priv->in_line = TRUE;
}
/**
*/
ZakFormCgiFormElement
*zak_form_cgi_form_element_check_new_attrs (const gchar *id,
- ...)
+ ...)
{
va_list ap;
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)
{
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
{
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
*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);
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;
}
/* 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);
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);