changeset 116:da8f1ba9034d

input/comment: renamed "comment" library to "textbox", and made it more generic
author Goffi <goffi@goffi.org>
date Tue, 30 Jan 2018 07:47:23 +0100
parents 5d9e2270ceb4
children 5992b774a6a4
files default/blog/macros.html default/input/comment.html default/input/field.html default/input/textbox.html default/merge-request/item.html default/static/blog.css default/static/styles.css default/ticket/item.html
diffstat 8 files changed, 79 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/default/blog/macros.html	Tue Jan 30 07:47:21 2018 +0100
+++ b/default/blog/macros.html	Tue Jan 30 07:47:23 2018 +0100
@@ -1,4 +1,4 @@
-{% import 'input/comment.html' as comment with context %}
+{% import 'input/textbox.html' as textbox with context %}
 
 {% macro show_items(items, comments=False, expanded=false, dates_fmt=none) %}
     {# show items and comments items if present after each item,
@@ -26,7 +26,7 @@
             <div id="{{'comments_panel'|cur_gidx}}" class="comments_panel">
                 {% if allow_commenting %}
                     <div class="comment_post">
-                        {{- comment.comment(service=comments_items.service, node=comments_items.node) -}}
+                        {{- textbox.comment(service=comments_items.service, node=comments_items.node) -}}
                     </div>
                 {% endif %}
 
--- a/default/input/comment.html	Tue Jan 30 07:47:21 2018 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-{% import 'input/form.html' as form with context %}
-{% import 'input/field.html' as field %}
-
-{% macro head(service, node) %}
-    {# include data needed to identify the node to use for commenting #}
-    <input type="hidden" name="type" value="comment">
-    <input type="hidden" name="service" value="{{service}}">
-    <input type="hidden" name="node" value="{{node}}">
-{% endmacro %}
-
-{% macro submit() %}
-    <input type="submit" value="{{_("Send")}}">
-{% endmacro %}
-
-{% macro comment(service, node, action='') %}
-{% call form.form(action=action) %}
-    {{ head(service, node) }}
-    {{ field.textarea("body", placeholder=_("Your comment")) }}
-    {{ submit() }}
-{% endcall %}
-{% endmacro %}
-
-{% macro comment_or_login(service, node, action='') %}
-    {# show comment form a a message asking to log in
-       login is checked using profile #}
-    {% if profile %}
-        {{ comment(service, node, action) }}
-    {% else %}
-        <div class="log_request">
-        <p class="not_logged">{% trans %}You are not logged. You need to log in to comment.{% endtrans %}</p>
-        {% if login_url is defined %}
-            <p class="log_in_url">
-                {% trans link_start=('<a href="',login_url,'">')|join|safe, link_end='</a>'|safe %}
-                    To log in {{link_start}}follow this link{{link_end}}
-                {% endtrans %}
-            </p>
-        {% endif %}
-        </div>
-    {% endif %}
-{% endmacro %}
--- a/default/input/field.html	Tue Jan 30 07:47:21 2018 +0100
+++ b/default/input/field.html	Tue Jan 30 07:47:23 2018 +0100
@@ -36,8 +36,8 @@
     </span>
 {% endmacro %}
 
-{% macro textarea(name, rows=10, cols=50, placeholder='') %}
-    <textarea name="{{name}}" rows="{{rows}}" cols="{{cols}}" placeholder="{{placeholder}}"></textarea>
+{% macro textarea(name, rows=10, cols=50, placeholder='', required=false) %}
+    <textarea name="{{name}}" rows="{{rows}}" cols="{{cols}}" placeholder="{{placeholder}}" {{"required" if required}}></textarea>
 {% endmacro %}
 
 {% macro meta(name, value) %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/default/input/textbox.html	Tue Jan 30 07:47:23 2018 +0100
@@ -0,0 +1,52 @@
+{% import 'input/form.html' as form with context %}
+{% import 'input/field.html' as field %}
+
+{% macro head(service, node, type="textbox") %}
+    {# include data needed to identify the node to use for commenting #}
+    <input type="hidden" name="type" value="{{type}}">
+    <input type="hidden" name="service" value="{{service}}">
+    <input type="hidden" name="node" value="{{node}}">
+{% endmacro %}
+
+{% macro submit(label=_("Send")) %}
+    <input type="submit" value="{{label}}">
+{% endmacro %}
+
+{% macro textbox(service, node, action='', placeholder='', submit_label=_("Send"), type="textbox") %}
+    {# generic content area for comments/blog posts/etc. Only a body by default, but new elements can be
+       added by using this macro with call #}
+    {% set extra_content = caller() if caller is defined else '' %}
+    {% call form.form(action=action, class="textbox") %}
+        {{ head(service, node, type) }}
+        {{ extra_content }}
+        {{ field.textarea("body", placeholder=placeholder, required=True) }}
+        {{ submit(label=submit_label) }}
+    {% endcall %}
+{% endmacro %}
+
+{% macro comment(service, node, action='', placeholder=_("Your comment")) %}
+    {{ textbox(service, node, action=action, placeholder=placeholder, type="comment") }}
+{% endmacro %}
+
+{% macro comment_or_login(service, node, action='', placeholder=none) %}
+    {# show comment form a a message asking to log in
+       login is checked using profile #}
+    {% if profile %}
+        {% if placeholder is none %}
+            {{ comment(service, node, action) }}
+        {% else %}
+            {{ comment(service, node, action, placeholder=placeholder) }}
+        {% endif %}
+    {% else %}
+        <div class="log_request">
+        <p class="not_logged">{% trans %}You are not logged. You need to log in to comment.{% endtrans %}</p>
+        {% if login_url is defined %}
+            <p class="log_in_url">
+                {% trans link_start=('<a href="',login_url,'">')|join|safe, link_end='</a>'|safe %}
+                    To log in {{link_start}}follow this link{{link_end}}
+                {% endtrans %}
+            </p>
+        {% endif %}
+        </div>
+    {% endif %}
+{% endmacro %}
--- a/default/merge-request/item.html	Tue Jan 30 07:47:21 2018 +0100
+++ b/default/merge-request/item.html	Tue Jan 30 07:47:23 2018 +0100
@@ -11,7 +11,7 @@
 {% if not embedded %}{% extends 'base/base.html' %}{% endif %}
 {% import 'input/xmlui.html' as xmlui with context %}
 {% import 'blog/macros.html' as blog with context %}
-{% import 'input/comment.html' as comment with context %}
+{% import 'input/textbox.html' as textbox with context %}
 
 {% block title %}{{item|adv_format('[{value.widget_value.id}] {value.widget_value.title}') }}{% endblock %}
 
@@ -43,7 +43,7 @@
         {% endif %}
         {% if comments_node is defined %}
             <div class="comment_post">
-                {{- comment.comment_or_login(service=comments_service, node=comments_node) -}}
+                {{- textbox.comment_or_login(service=comments_service, node=comments_node) -}}
             </div>
         {% endif %}
     </div>
--- a/default/static/blog.css	Tue Jan 30 07:47:21 2018 +0100
+++ b/default/static/blog.css	Tue Jan 30 07:47:23 2018 +0100
@@ -225,11 +225,6 @@
     text-align: center;
 }
 
-.comment_post input {
-    display: block;
-    margin: 0 auto;
-}
-
 .comment_post textarea {
     border-style: solid;
     border-width: 1px  0;
@@ -273,6 +268,7 @@
         background: rgba(200,200,200,0.6);
         border-radius: 0.5em 0.5em 0 0;
         padding: 0 0.5em;
+        margin-top: 1em;
     }
 
 }
--- a/default/static/styles.css	Tue Jan 30 07:47:21 2018 +0100
+++ b/default/static/styles.css	Tue Jan 30 07:47:23 2018 +0100
@@ -221,6 +221,24 @@
     display: block;
 }
 
+/* Textboxes */
+
+form.textbox>* {
+    display: block;
+    margin: 1em auto;
+    text-align: center;
+    max-width: 100%;
+    box-sizing: border-box;
+}
+
+form.textbox>textarea {
+    text-align: left;
+}
+
+.log_request {
+    text-align: center;
+}
+
 /*** Navigation ***/
 
 .prev_next_links ul {
--- a/default/ticket/item.html	Tue Jan 30 07:47:21 2018 +0100
+++ b/default/ticket/item.html	Tue Jan 30 07:47:23 2018 +0100
@@ -11,7 +11,7 @@
 {% if not embedded %}{% extends 'base/base.html' %}{% endif %}
 {% import 'input/xmlui.html' as xmlui with context %}
 {% import 'blog/macros.html' as blog with context %}
-{% import 'input/comment.html' as comment with context %}
+{% import 'input/textbox.html' as textbox with context %}
 
 {% block title %}{{item|adv_format('[{value.widget_value.id}] {value.widget_value.title}') }}{% endblock %}
 
@@ -35,7 +35,7 @@
 {% endif %}
 {% if comments_node is defined %}
     <div class="comment_post">
-        {{- comment.comment_or_login(service=comments_service, node=comments_node) -}}
+        {{- textbox.comment_or_login(service=comments_service, node=comments_node) -}}
     </div>
 {% endif %}
 {% endblock body %}