changeset 102:65341d05a8f8

Spawn a Modal when loading a doc, and another one is already loaded
author Benoît Allard <benoit.allard@greenbone.net>
date Tue, 14 Oct 2014 10:25:43 +0200
parents 21a1a69b4525
children 8a9fdf02bf5b
files farol/main.py farol/static/style.css farol/templates/base.j2 farol/templates/new.j2
diffstat 4 files changed, 44 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/farol/main.py	Tue Oct 14 10:23:08 2014 +0200
+++ b/farol/main.py	Tue Oct 14 10:25:43 2014 +0200
@@ -80,7 +80,8 @@
         error = None
     except ValidationError as ve:
         error = ve
-    return dict(has_current=True, vulnerabilities=vulns, products=prods, error=error)
+    return dict(has_current=True, vulnerabilities=vulns, products=prods,
+                error=error, current_id=cvrf.getDocId())
 
 @app.template_filter('secure_filename')
 def makeId(string):
@@ -140,10 +141,7 @@
 @app.route('/new', methods=['GET', 'POST'])
 def new():
     if request.method != 'POST':
-        current_id = None
-        if has_current():
-            current_id = get_current().getDocId()
-        return render_template('new.j2', has_document=has_current(), now=utcnow(), current_id=current_id)
+        return render_template('new.j2', has_document=has_current(), now=utcnow())
 
     if 'rhsa' in request.form:
         set_RHSA(request.form['id'])
--- a/farol/static/style.css	Tue Oct 14 10:23:08 2014 +0200
+++ b/farol/static/style.css	Tue Oct 14 10:25:43 2014 +0200
@@ -18,6 +18,11 @@
   display: inline-block;
 }
 
+/* To behave as a link, it should'nt have padding ... */
+.btn-link {
+  padding: 0;
+}
+
 .footer {
   height: 130px;
   margin-top: 20px;
--- a/farol/templates/base.j2	Tue Oct 14 10:23:08 2014 +0200
+++ b/farol/templates/base.j2	Tue Oct 14 10:25:43 2014 +0200
@@ -23,6 +23,8 @@
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 -#}
 
+{% from "macros.j2" import modal, POST_button -%}
+
 <!doctype html>
 
 <html lang="en">
@@ -96,10 +98,20 @@
           <li class="dropdown">
             <a href="#" class="dropdown-toggle" data-toggle="dropdown">Cache <span class="caret"></span></a>
             <ul class="dropdown-menu" role="menu">
-              <li role="presentation"{{ ' class="disabled"' if not has_current }}><a role="menuitem" tabindex="-1" href="{{ url_for('cache.save') }}">Save current</a>
+              <li role="presentation"{{ ' class="disabled"' if not has_current }}><a role="menuitem" tabindex="-1" href="{{ url_for('cache.save') }}">Save {{ current_id }}</a>
               </li>
               <li role="presentation" class="divider"></li>
-              {% for element in cache | sort %}<li role="presentation"><a href="{{ url_for('cache.load', element=element)}}">{{ element }}</a></li>{% endfor %}
+              {% for element in cache | sort %}
+                <li role="presentation">
+                  {% if has_current %}
+                    <a href="#{{element}}_modal" data-toggle="modal">Load {{ element }}</a>
+                  {% else %}
+                    {% call(selector) POST_button(url_for('cache.load', element=element), out=True) %}
+                      <a role="menuitem" href="#" onclick="{{ selector }}.submit();return false;">Load {{ element }}</a>
+                    {% endcall %}
+                  {% endif %}
+                </li>
+              {% endfor %}
             </ul>
           </li>
           {% endif %}
@@ -107,6 +119,19 @@
       </div>{# /.navbar-collapse #}
     </div>{# /.container-fluid #}
   </nav>
+  {% if has_current %}
+    {% for element in cache %}
+      {# Put the modals for the load action here #}
+      {% call modal(element + '_modal', 'Load %s from cache' % element) %}
+        <p>You asked to load <strong>{{ element }}</strong>, your changes to <strong>{{ current_id }}</strong> will be lost.</p>
+        <p>Do you want to save <strong>{{ current_id }}</strong> first ?</p>
+      </div>
+      <div class="modal-footer">
+        <a href="{{ url_for('cache.save') }}" class="btn btn-success">Save {{ current_id }}</a>
+        {{ POST_button(url_for('cache.load', element=element), text="Load " + element, style="btn-danger") }}
+      {% endcall %}
+    {% endfor %}
+  {% endif %}
   <div class="main container">
     {% with messages = get_flashed_messages(with_categories=True) %}
       {% if messages %}
--- a/farol/templates/new.j2	Tue Oct 14 10:23:08 2014 +0200
+++ b/farol/templates/new.j2	Tue Oct 14 10:25:43 2014 +0200
@@ -171,7 +171,15 @@
 {% if caching %}
   {% call panel(heading="Load a document from the cache", title=4, collapsible=False) %}
   <ul>
-    {% for element in cache | sort %}<li><a href="{{ url_for('cache.load', element=element)}}">{{ element }}</a></li>{% endfor %}
+    {% for element in cache | sort %}
+      <li>
+        {% if has_current %}
+          <a href="#{{element}}_modal" data-toggle="modal">{{ element }}</a>
+        {% else %}
+          {{ POST_button(url_for('cache.load', element=element), text=element, style="btn-link") }}
+        {% endif %}
+      </li>
+    {% endfor %}
   </ul>
   {% endcall %}
 {% endif %}

http://farol.wald.intevation.org