changeset 101:21a1a69b4525

Introduce a POST_button macro and use it in the delete_button one.
author Benoît Allard <benoit.allard@greenbone.net>
date Tue, 14 Oct 2014 10:23:08 +0200
parents 5535ac5fef37
children 65341d05a8f8
files farol/static/style.css farol/templates/macros.j2
diffstat 2 files changed, 20 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/farol/static/style.css	Fri Oct 10 10:25:35 2014 +0200
+++ b/farol/static/style.css	Tue Oct 14 10:23:08 2014 +0200
@@ -14,7 +14,7 @@
 }
 */
 
-form.delete {
+form.inlined-form {
   display: inline-block;
 }
 
--- a/farol/templates/macros.j2	Fri Oct 10 10:25:35 2014 +0200
+++ b/farol/templates/macros.j2	Tue Oct 14 10:23:08 2014 +0200
@@ -169,15 +169,28 @@
 {% endif %}
 {% endmacro %}
 
+{% macro POST_button(url, text, fields, out=False, style='btn-default') %}
+{% if caller and out %}
+  {{ caller('$(this).next()') }}
+{% endif %}
+<form class="inlined-form" action="{{ url }}" method="POST"{{ ' style="display:none"' if out}}>
+  {% for elem in fields %}
+  <input type=hidden name="{{ elem }}", value="{{ fields[elem] }}">
+  {% endfor %}
+  {% if caller %}
+    {{ caller('parentNode') if not out }}
+  {% else %}
+  <button type="submit" class="btn {{ style }}">{{ text }}</button>
+  {% endif %}
+</form>
+{% endmacro %}
+
 {% macro delete_button(url, hiddens={}, text="delete") %}
-<form class="delete" action="{{ url }}" method="POST">
-  {% for elem in hiddens %}
-  <input type=hidden name="{{ elem }}", value="{{ hiddens[elem] }}">
-  {% endfor %}
-  <a href="#" onclick="parentNode.submit();return false;">
+  {% call(selector) POST_button(url, text, hiddens) %}
+  <a href="#" onclick="{{ selector }}.submit();return false;">
     <span class="label label-danger">
       <strong>{{ text }}</strong>
     </span>
   </a>
-</form>
+  {% endcall %}
 {% endmacro %}

http://farol.wald.intevation.org