<?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='css/jquery.dataTables-1.10.7.css') }}">
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', file='css/scheduler_ui.css') }}">
    <script type="text/javascript" src="{{ url_for('static', file='js/jquery-2.1.4.min.js') }}"></script>
    <script type="text/javascript" src="{{ url_for('static', file='js/mx_utils.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>
            {%- if not handler -%}
                <select name="process_name" style="width: 236px">
                {%- for process_name, process_entry in synergy_process_context.items() -%}
                    <option value="{{ process_name }}" {%- if process_name == 'BashDriver' -%} selected {%- endif -%} >{{ process_name }}</option>
                {%- endfor -%}
                </select>
            {%- else -%}
                <input type="text" name="process_name" style="text-align: left"
                       value="{{ handler.process_entry.process_name }}" readonly>
            {%- endif -%}
            </td>
            <td></td>
        </tr>
        <tr>
            <td>Entry name:</td>
            <td><input type="text" name="entry_name" style="text-align: left"
                       value="{% if handler %}{{ handler.process_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.process_entry.description }}{% endif %}"></td>
            <td>Human-readable description of the schedulable item</td>
        </tr>

        <tr>
            <td>Is Active:</td>
            <td>
                <label><input type="checkbox" name="is_on" id="is_on"
                        {% if handler and handler.process_entry.is_on %} checked {% endif %} /></label>
            </td>
            <td>Defines whether the schedulable is active and running OR deactivated and idle</td>
        </tr>

        <tr>
            <td>Trigger time:</td>
            <td><input type="text" maxlength="32" name="trigger_frequency" style="text-align: left"
                       value="{%- if handler %}{{ handler.process_entry.trigger_frequency }}{%- endif %}"/></td>
            <td>
                - <strong>every XXX</strong><br/> where XXX stands for seconds;<br/>For instance: "every 60"
                <br/><br/>
                - <strong>at DoW-HH:MM, ..., DoW-HH:MM</strong><br/> where DoW is numerical Day Of Week (Mon-0, Sun-6, *-every day);
                <br/>For instance:<br/>"at 2-15:00" - specifies Wed, 15:00 UTC
                <br/>"at *-12:00, 3-09:09" specifies everyday at 12:00 UTC and Thu at 15:00 UTC
            </td>
        </tr>
        <tr>
            <td>Arguments:</td>
            <td><textarea rows="10" cols="30" name="arguments">
                {%- if handler -%}
                    {{ handler.process_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">
            {%- if not handler -%}
                <input type="submit" name="insert_button" value="Insert" onclick="closeWindow()"/>
            {%- else -%}
                <input type="submit" name="update_button" value="Update" onclick="closeWindow()"/>
                <input type="submit" name="delete_button" value="Delete" onclick="closeWindow()"/>
            {%- 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>
