view farol/templates/new.j2 @ 167:000114da182d

New lifting for the 'new' page
author Benoît Allard <benoit.allard@greenbone.net>
date Mon, 05 Jan 2015 11:38:46 +0100
parents 07210df10edd
children 44f12b383e72
line wrap: on
line source
{#
# Description:
# Web Template used in Farol Design
#
# Authors:
# BenoƮt Allard <benoit.allard@greenbone.net>
#
# Copyright:
# Copyright (C) 2014 Greenbone Networks GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#}

{% extends "base.j2" %}
{% from "macros.j2" import textinput, textarea, panel %}
{% from "common_edits.j2" import edit_title_type %}

{% macro input_download(width, type, placeholder, example, help) %}
<div class="col-lg-{{ width }}">
  {% call modal(type | lower + "_modal", type + " help") %}
    {% for p in help.split('\n\n') %}
    <p>{{ p | urlize }}</p>
    {% endfor %}
  {% endcall %}
  <form role="form" method="POST">
    <input type="hidden" name="{{ type | lower}}">
    <div class="form-group">
      <div class="input-group">
        <span class="input-group-addon">{{ type }}: </span>
        <input type="text" class="form-control" name="id" placeholder="{{ placeholder }}" id="{{ type | lower }}_id" required>
        <div class="input-group-btn">
          <button class="btn btn-primary" type="submit">Download</button>
          <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <span class="caret"></span>
            <span class="sr-only">Toggle dropdown</span>
          </button>
          <ul class="dropdown-menu drop-down-menu-right" role="menu">
            <li><a href="#{{ type | lower }}_modal" data-toggle="modal">Help</a></li>
            <li><a href="#" onclick="$('#{{ type | lower }}_id').val('{{ example }}')">Example</a></li>
          </ul>
        </div><!-- /input-group-btn -->
      </div><!-- /input-group -->
    </div>
  </form>
</div>
{% endmacro %}

{% set active='new' %}

{% block title %}New{% endblock %}

{% block content %}
{% if has_document and caching %}
<p class="text-danger">You are currently editing a document: <strong>{{ current_id }}</strong>. Loading a new one will lose your modifications. Do you want to <a href={{ url_for('cache.save') }}>save</a> it first ?</p>
{% endif %}
<h3>New Document</h3>

<div class="panel-group" id="accordion">

  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent="#accordion" href="#fromURL">
          Upload a remote document
        </a>
      </h4>
    </div>
    <div id="fromURL" class="panel-collapse collapse in">
      <div class="panel-body">
        {% for row in input_choices[:-1] | batch(3) %}
        <div class="row">
          {% for (type, placeholder, example, help) in row %}
            {{ input_download(4, type, placeholder, example, help) }}
          {% endfor %}
        </div>
        {% endfor %}
        <div class="row">
          {{ input_download(12, *input_choices[-1]) }}
        </div>
      </div>
    </div>
  </div>

  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent="#accordion" href="#fromFile">
          Upload a local document
        </a>
      </h4>
    </div>
    <div id="fromFile" class="panel-collapse collapse">
      <div class="panel-body">
        <form role="form" method="POST" enctype="multipart/form-data">
          {{ textinput("local", "Local File", type="file", required=True) }}
          <button type="submit" class="btn btn-primary">Upload</button>
        </form>
      </div>
    </div>
  </div>

  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent="#accordion" href="#fromText">
          Upload raw text
        </a>
      </h4>
    </div>
    <div id="fromText" class="panel-collapse collapse">
      <div class="panel-body">
        <form role="form" method="POST">
          {{ textarea("text", "Document content", value='<?xml version="1.0" encoding="utf-8"?>
<cvrfdoc xmlns="http://www.icasi.org/CVRF/schema/cvrf/1.1">
  <DocumentTitle>Title</DocumentTitle>
  <DocumentType>Type</DocumentType>
  <DocumentPublisher Type="Other">
  </DocumentPublisher>
  <DocumentTracking>
    <Identification>
      <ID>1234</ID>
    </Identification>
    <Status>Draft</Status>
    <Version>0.1</Version>
    <RevisionHistory>
      <Revision>
        <Number>0.1</Number>
        <Date>' + now.isoformat() + '</Date>
        <Description>First Revision</Description>
      </Revision>
    </RevisionHistory>
    <InitialReleaseDate>' + now.isoformat() + '</InitialReleaseDate>
    <CurrentReleaseDate>' + now.isoformat() + '</CurrentReleaseDate>
  </DocumentTracking>
</cvrfdoc>' | escape, required=True) }}
          <button type="submit" class="btn btn-primary">Parse</button>
        </form>
      </div>
    </div>
  </div>

  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent="#accordion" href="#newDoc">
          Create an empty Document
        </a>
      </h4>
    </div>
    <div id="newDoc" class="panel-collapse collapse">
      <div class="panel-body">
        <form role="form" method="POST">
          {{ edit_title_type() }}
          <button type="submit" class="btn btn-primary">Create</button>
        </form>
      </div>
    </div>
  </div>

</div>

{% if caching %}
  {% call panel(heading="Load a document from the cache", title=4, collapsible=False) %}
  <ul>
    {% 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>
    {% else %}
      <li><em>Cache is empty</em></li>
    {% endfor %}
  </ul>
  {% endcall %}
{% endif %}

{% endblock %}

http://farol.wald.intevation.org