{% extends 'layouts/master-page' %}
{% block title %}{{ listType }} management{% endblock %}
{% block head %}
  <script type="text/javascript" src="/static/js/custom/list.js"></script>
{% endblock %}
{% block content %}
  <!-- Values -->
  <input id="values" type="hidden" value="{{listType}}">
  <!-- breadcrumb -->
  <ol class="breadcrumb">
    <li><a href="/admin">Admin</a></li>
    <li class="active">{{listType}}</li>
  </ol>
  <!-- add items -->
  <!-- Status -->
  <div id="status" class="hidden">
    <span id="status_icon"></span>
    <div id="status_message"></div>
  </div>
  <!-- Add new rule -->
  <div class="well well-small">
    <table class="table"><tr><td class="listInput">
      <form id='addcpe' class="nav form-search" onsubmit="addItem('cpe'); return false;">
        <strong>Add an item to the {{ listType }}</strong> <br />
        <input id="cpeid" type="text" placeholder="full or partial CPE" pattern="(cpe:/|cpe:2.3:)[a-z0-9/.:%-_~]+" /> <br />
        <textarea id="cpecomments" rows="4" placeholder="comments, separated by enter"></textarea> <br />
        <input id="cpeadd" type="submit" value="Add"/>
      </form>
      <a href="/admin/listmanagement">Browse...</a>
    </td><td class="listInputCenter">
      <p>or</p>
    </td><td class="listInput">
      <form id='addkeyword' class="nav form-horizontal" onsubmit="addItem('-'); return false;">
        <strong>Add CPE keywords to the {{ listType }}</strong> <br />
        <div>
          <select class="form-control" id="keywordselect">
            <option value="targetsoftware">Target Software</option>
            <option value="targethardware">Target Hardware</option>
          </select>
          <input id="keywordid" type="text" class="form-control" placeholder="Target Software/Hardware Name">
        </div>
        <textarea id="keywordcomments"rows="4" placeholder="comments, separated by enter"></textarea> <br />
        <input id="keywordadd" type="submit" value="Add"/>
      </form>
    </td></tr></table>
  </div>
  <!-- Current rules -->
  {% set rulesList = rules|list %}
  <table class="table table-even">
    <tr>
      <td>
        <b>CPE Rules</b>
        <table id="cpes" class="table table-hover table-striped table-condensed">
          <thead><tr class="warning"><td></td><td></td><td>Rule</td><td>Comments</td></tr></thead>
          <tbody>
            {% for ruleID in rulesList if ruleID['type']=='cpe' %}
              <tr>
                <td><a href="javascript:remove('{{ruleID['id']}}')"><span class="glyphicon glyphicon-remove"></span></a></td>
                {% if ruleID['comments'] is defined %}
                  <td><a id="edit"><span class="glyphicon glyphicon-edit"></span></a></td>
                {% else %}
                  <td><a id="edit"><span class="glyphicon glyphicon-edit"></span></a></td>
                {% endif %}
                <td>{{ ruleID['id'] }}</td>
                <td>
                  <ul>
                    {% for comment in ruleID['comments'] %}
                      <li>{{ comment }}</li>
                    {% endfor %}
                  </ul>
                </td>
              </tr>
            {% endfor %}
          </tbody>
        </table>
      </td>
      <td>
        <b>Keywords</b>
        <table id="keywords" class="table table-hover table-striped table-condensed">
          <thead><tr class="warning"><td></td><td></td><td>Rule</td><td>Keyword</td><td>Comments</td></tr></thead>
          <tbody>
            {% for ruleID in rulesList if ruleID['type']!='cpe' %}
              <tr>
                <td><a href="javascript:remove('{{ruleID['id']}}')"><span class="glyphicon glyphicon-remove"></span></a></td>
                {% if ruleID['comments'] is defined %}
                  <td><a id="edit"><span class="glyphicon glyphicon-edit"></span></a></td>
                {% else %}
                  <td><a id="edit"><span class="glyphicon glyphicon-edit"></span></a></td>
                {% endif %}
                <td>{{ ruleID['id'] }}</td>
                <td>
                  {% if ruleID['type'] == 'targethardware' %}
                    Target Hardware
                  {% elif ruleID['type'] == 'targetsoftware' %}
                    Target Software
                  {% endif %}
                </td>
                <td>
                  <ul>
                    {% for comment in ruleID['comments'] %}
                      <li>{{ comment }}</li>
                    {% endfor %}
                  </ul>
                </td>
              </tr>
            {% endfor %}
          </tbody>
        </table>
      </td>
    </tr>
  </table>
{% endblock %}
