{% extends "base.html" %}

{% block navigation %}
    <ts-sketch-navigation sketch-id="{{ sketch.id }}" active="timelines" graphs-enabled="{{ graphs_enabled }}"></ts-sketch-navigation>
{% endblock %}

{% block main %}

    <div class="modal" id="edit-timeline-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Edit timeline</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form" action="{{ url_for('sketch_views.timeline', sketch_id=sketch.id, timeline_id=timeline.id) }}" method="post">
                        <div class="form-group">
                            <div class="col-sm-12">
                                <strong>Title</strong>
                                <input class="form-control" id="name" name="name" type="text" value="{{ timeline.name }}" autofocus="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-12">
                                <strong>Description</strong>
                                <textarea rows="10" class="form-control" id="description" name="description">{{ timeline.description }}</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-12">
                                <div class="pull-left" style="width:20px;height:20px;background:#{{ timeline.color }}; margin-right: 10px;"></div>
                                <strong>Color</strong>
                                <br><br>
                                <input type="text" class="form-control" id="color" name="color" value="{{ timeline.color }}" />
                            </div>
                        </div>
                        <input type="submit" class="btn btn-primary" value="Save"/>
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        {{ timeline_form.csrf_token }}
                    </form>
                </div>
            </div>
        </div>
    </div>

        <div class="row">
            <div class="col-md-12">

                {% if timeline.get_status.status == 'fail' %}
                <div class="card" style="background:#d9534f; color:#fff;">
                    <strong>Oops.. something is wrong with this timeline:</strong>
                    <br>
                    <br>
                    <pre>
                        {{ timeline.searchindex.description }}
                    </pre>
                </div>
                {% endif %}

                <div class="card card-top">
                    <div class="pull-left" style="width:50px;height:50px;background:#{{ timeline.color }};cursor: pointer" data-toggle="modal" data-target="#edit-timeline-modal"></div>
                    {% if sketch.has_permission(user=current_user, permission='write') %}
                        <button class="btn btn-default pull-right " data-toggle="modal" data-target="#edit-timeline-modal" style="margin-left:10px;width:50px;"><i class="fa fa-pencil"></i></button>
                    {% endif %}
                    <h4 style="margin-left:80px;padding-top: 17px;">{{ timeline.name }}</h4>
                    <br>
                    {% if timeline.description != timeline.name %}
                        <p style="white-space: pre-wrap;word-wrap: break-word;">{{ timeline.description }}</p>
                        <br>
                    {% endif %}
                    <table class="table table-hover">
                        <thead>
                        <th>Datastore index</th>
                        <th>Original timeline name</th>
                        <th>Added by</th>
                        <th width="130px">Added</th>
                        </thead>
                        <tr>
                            <td>{{ timeline.searchindex.index_name }}</td>
                            <td>{{ timeline.searchindex.name }}</td>
                            <td>{{ timeline.user.name }}</td>
                            <td>{{ timeline.created_at.strftime('%Y-%m-%d %H:%M') }}</td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>

{% endblock %}
