view src/ltpdarepo/templates/query.html @ 107:22b950fee548

Complete named queries support.
author Daniele Nicolodi <daniele@grinta.net>
date Tue, 23 Aug 2011 18:04:12 +0200
parents 0d259fd52ca0
children f075650d3e1d
line wrap: on
line source

{% extends "objs.html" %}

{% block head %}
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='dropdown.css') }}" />
    <script type="text/javascript" src="{{ url_for('static', filename='jquery.js') }}"></script>
    <script type="text/javascript" src="{{ url_for('static', filename='dropdown.js') }}"></script>
    <script type="text/javascript" src="{{ url_for('static', filename='querywidget.js') }}"></script>
    <script type="text/javascript">
      var criteria = {{ indexes|tojson|safe }};
      $(function () {
        $.dropdown.replace($("select"));
        $("#save").live('click', function () {
          var query = $(".query form").serialize();
          if (! query)
            return false;
          var form = $(document.createElement('form')).attr({
            'action': '{{ url_for('manage.queries.create') }}',
            'method': 'POST' });
          form.append($(document.createElement('input')).attr({
            'type': 'hidden',
            'name': 'query',
            'value': query }));
          form.append($(document.createElement('input')).attr({
            'type': 'hidden',
            'name': 'db',
            'value': '{{ database.id }}' }));
          $("body").append(form);
          form.submit();
          form.remove();
          return false;
        });
      });
    </script>
{% endblock %}

{% block above %}
<div class="query wrapper">
  <form method="GET" action="">
    {% block extra %}{% endblock %}
    <div id="criteria" class="wrapper">
      {% for field, op, value, error in query %}
      {% set cssclass = '' %}
      {% if error %}{% set cssclass = cssclass + 'error' %}{% endif %}
      <div class="criteria wrapper">
        <span class="querywidget field">{{ indexes[field]['name'] }}</span>
        <input type="hidden" name="field" value="{{ field }}" />
        <select class="querywidget operator" name="operator">
          {% for name in indexes[field]['operators'] %}
          {% if op == name %}
          <option value="{{ name }}" selected="selected">{{ name }}</option>
          {% else %}
          <option value="{{ name }}">{{ name }}</option>
          {% endif %}
          {% endfor %}
        </select>
        {% if indexes[field]['type'] == 'enum' %}
        <select class="querywidget value" name="value">
          {% for name in indexes[field]['values'] %}
          {% if value == name %}
          <option value="{{ name }}" selected="selected">{{ name }}</option>
          {% else %}
          <option value="{{ name }}">{{ name }}</option>
          {% endif %}
          {% endfor %}
        </select>
        {% else %}
        <input class="querywidget value {{ cssclass }}" autocomplete="off" type="text" name="value" value="{{ value }}" />
        {% endif %}
        <input class="querywidget remove" type="button" name="remove" value="&times;" />
      </div>
      {% endfor %}
    </div>

    <select id="add">
      <option value="" selected="selected">Add criteria&hellip;</option>
      {% for key, index in indexes.iteritems() %}
      <option value="{{ key }}">{{ index['name'] }}</option>
      {% endfor %}
    </select>

    <input type="submit" value="search" />

    {% if 'admin' in g.identity.roles %}
    <input id="save" type="submit" name="save" value="save query" />
    {% endif %}

  </form>
</div>
{% endblock %}