<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', file='scheduler_ui.css') }}">
    <script type="text/javascript" src="{{ url_for('static', file='json_formatter.js') }}"></script>
    <script type="text/javascript" src="{{ url_for('static', file='jquery-1.8.2.min.js') }}"></script>
    <script type="text/javascript">
        window.onunload = refreshParent;
        function refreshParent() {
            window.opener.location.reload();
        }

        function closeWindow() {
            setTimeout("window.close()", 750);
        }
    </script>

    <title>Scheduler Freerun Trigger</title>
</head>

<body>
<pre id="json"></pre>


<form method="POST" action="/action_update_freerun_entry/">
    <table class="one-column-emphasis">
        <tr>
            <td>Process name:</td>
            <td><select name="process_name" style="width: 236px">
                <option value="{% if handler %}{{ handler.scheduler_entry.process_name }}{% endif %}">
                    {%- if handler -%}{{ handler.scheduler_entry.process_name }}{%- endif -%}
                </option>
                <option value="BashDriver">BashDriver</option>
            </select></td>
            <td></td>
        </tr>
        <tr>
            <td>Entry name:</td>
            <td><input type="text" name="entry_name" style="text-align: left"
                       value="{% if handler %}{{ handler.scheduler_entry.entry_name }}{% endif %}"
                    {% if handler %} readonly {% endif %}></td>
            <td>Name of the schedulable item. Has to be unique.</td>
        </tr>

        <tr>
            <td>Description:</td>
            <td><input type="text" name="description" style="text-align: left"
                       value="{% if handler %}{{ handler.scheduler_entry.description }}{% endif %}"></td>
            <td>Human-targeted description of the schedulable item</td>
        </tr>

        <tr>
            <td>State:</td>
            <td><select name="state" style="width: 236px">
                <option value="state_on"
                        {% if handler and handler.scheduler_entry.state == 'state_on' %} selected {% endif %}>
                    STATE_ON
                </option>
                <option value="state_off"
                        {% if handler and handler.scheduler_entry.state == 'state_off'%} selected {% endif %}>
                    STATE_OFF
                </option>
            </select></td>
            <td>STATE_ON - active and running, STATE_OFF - deactivated and idle</td>
        </tr>

        <tr>
            <td>Trigger time:</td>
            <td><input type="text" maxlength="32" name="trigger_time" style="text-align: left"
                       value="{%- if handler %}{{ handler.scheduler_entry.trigger_time }}{%- endif %}"/></td>
            <td>Either of:
                <ul>"every XXX" where XXX stands for seconds; For instance: "every 60"</ul>
                <ul>"at DoW-HH:MM, ..., DoW-HH:MM" where DoW is numerical Day Of Week (Mon-0, Sun-6, *-every day);
                For instance: "at 2-15:00" - specifies Wed, 15:00 UTC
                "at *-12:00, 3-09:09" specifies everyday at 12:00 UTC and Thu at 15:00 UTC</ul>
            </td>
        </tr>
        <tr>
            <td>Arguments:</td>
            <td><textarea rows="10" cols="30" name="arguments">
                {%- if handler -%}
                    {{ handler.scheduler_entry.arguments|jsonify }}
                {%- else -%}
                    {"cmd_path": "", "cmd_file": "", "cmd_args": "", "cmd_host": "" }
                {%- endif -%}</textarea></td>
            <td>This is process-specific set of arguments that are used to construct and run an actual job</td>
        </tr>
        <td colspan="3" align="center">
            <div id="buttons">
                <input type="submit" name="insert_button" value="Insert" onclick="closeWindow()"/>
                <input type="submit" name="update_button" value="Update" onclick="closeWindow()" {% if not handler %} disabled {% endif %}/>
                <input type="submit" name="delete_button" value="Delete" onclick="closeWindow()" {% if not handler %} disabled {% endif %}/>
                <input type="submit" name="cancel_button" value="Cancel" onclick="closeWindow()"/>

                <!-- Need this to have the buttons actually inside div#buttons -->
                <div style="clear:both"></div>
            </div>
        </td>
    </table>
</form>

</body>
</html>
