{% extends "base.html" %}

{% autoescape None %}

{% block title %}IceProd Config{% if dataset %} Dataset {{ dataset }}{% end %}{% end %}

{% block head_scripts %}
<link rel="stylesheet" href="/static/submit.css" media="all" type="text/css" />
<link rel="stylesheet" href="/static/documentation.css" media="all" type="text/css" />
{% end %}

{% block page_title %}{% if dataset_id %}{% if edit %}Edit{% else %}View{% end %} Config - <a href="/dataset/{{ dataset_id }}">Dataset {{ dataset }}</a>{% else %}Submit{% end %}{% end %}

{% block sidebar %}
<div class="section macro_box">
    <h3>Macros</h3>
    <ul>
        <li>
            <h4>$(dataset_id)</h4>
            <p class="macro_desc">The dataset_id string.</p>
        </li>
        <li>
            <h4>$(dataset)</h4>
            <p class="macro_desc">The dataset_id in numerical form.</p>
        </li>
        <li>
            <h4>$(jobs_submitted)</h4>
            <p class="macro_desc">The number of jobs in the dataset.</p>
        </li>
        <li>
            <h4>$(job)</h4>
            <p class="macro_desc">The job index within the dataset.</p>
        </li>
        <li>
            <h4>$(task_id)</h4>
            <p class="macro_desc">The task_id string.</p>
        </li>
        <li>
            <h4>$(task)</h4>
            <p class="macro_desc">The task name.</p>
        </li>
    </ul>
</div>
{% end %}

{% block body %}
{% set view_only = bool(dataset_id and not edit) %}
<div id="submit_area">
    {% if not view_only %}
    <form method="post" action="/{% if edit %}config{% else %}submit{% end %}" autocomplete="off">
        {% module xsrf_form_html() %}
    {% end %}
        <textarea name="submit_box" id="submit_box" style="min-height: 500px" autofocus{% if view_only %} readonly{% end %}>{{ config }}</textarea>
        <textarea name="description" id="description" placeholder="Description"{% if view_only %} readonly{% end %}>{{ description }}</textarea>
        <div class="submit_contents">
            {% if dataset_id %}
            <input type="hidden" name="dataset_id" value="{{ dataset_id }}" />
            <input type="hidden" name="edit" value="{{ edit }}" />
                {% if edit %}
            <button id="submit_action">Update</button>
                {% end %}
            {% else %}
            Number of jobs:
            <input name="number_jobs" id="number_jobs" value="{{ jobs_submitted }}" min="1" max="1000000" step="1" type="number">
            Group:
            <select name="group" id="group">
                {% for g in groups %}
                    <option value="{{ g }}" {% if g == group %}selected{% end %}>{{ g }}</option>
                {% end %}
            </select>
            <button id="submit_action">Submit</button>
            {% end %}
        </div>
    {% if not view_only %}
    </form>
    {% end %}
</div>
<div id="error">{{ error }}</div>
{% end %}
