{{/*
This file is part of SystemTestPortal.
Copyright (C) 2017  Institute of Software Technology, University of Stuttgart

SystemTestPortal 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 3 of the License, or
(at your option) any later version.

SystemTestPortal 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 SystemTestPortal.  If not, see <http://www.gnu.org/licenses/>.
*/}}

{{define "tab-content"}}
<div class="modal fade" id="helpModal">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Test Sequence Details</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span>&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <table class="help-table">
                    <tr>
                        <td colspan="2">
                            In this view you can change the details of a test sequence.
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2"><h5>Buttons</h5></td>
                    </tr>
                    <tr>
                        <td>
                            <button class="btn btn-secondary">
                                <i class="fa fa-times" aria-hidden="true"></i>
                                <span class="d-none d-sm-inline"> Abort</span>
                            </button>
                        </td>
                        <td>Abort editing and get back to the test sequence details.</td>
                    </tr>
                    <tr>
                        <td>
                            <button class="btn btn-success" type="button">
                                <i class="fa fa-floppy-o" aria-hidden="true"></i>
                                <span class="d-none d-sm-inline"> Save</span>
                            </button>
                        </td>
                        <td>Confirm changes, save them and return back to the details.</td>
                    </tr>
                    <tr>
                        <td colspan="2"><h5>Form Fields</h5></td>
                    </tr>
                    <tr>
                        <td>
                            <strong>Test Sequence Name</strong>
                        </td>
                        <td>Enter a short but descriptive name for the test sequence.</td>
                    </tr>
                    <tr>
                        <td>
                            <strong>Test Sequence Description</strong>
                        </td>
                        <td>Describe the purpose of that test sequence in some sentences.</td>
                    </tr>
                    <tr>
                        <td>
                            <strong>Test Sequence Conditions</strong>
                        </td>
                        <td>State some conditions that must be fulfilled prior to test sequence execution.</td>
                    </tr>
                    <tr>
                        <td>
                            <strong>Test Cases</strong>
                        </td>
                        <td>Add some test cases here.</td>
                    </tr>
                    <tr>
                        <td>
                            <strong>Variants & Versions</strong>
                        </td>
                        <td>Based on your selected test cases, these are automatically calculated.</td>
                    </tr>
                    <tr>
                        <td>
                            <strong>Estimated Test Time (hh:mm)</strong>
                        </td>
                        <td>Based on your selected test cases, it's automatically calculated .</td>
                    </tr>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="modal-testsequence-save" tabindex="-1" role="dialog" aria-labelledby="modal-testsequence-save-label">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="modal-testsequence-save-label">Save Test Sequence</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span>&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <!-- don't beak the following two lines, otherwise the placeholder will not be diplaced properly-->
                    <textarea class="form-control" id="inputCommitMessage" rows="4"
                              placeholder="Why did you edit the test sequence? (Optional)"></textarea>
                </div>
            </div>
            <div class="modal-footer">
                <div class="checkbox mr-auto">
                    <label><input type="checkbox" id="minorUpdate">
                        <abbr title="This is only a minor edit">Minor Change</abbr>
                    </label>
                </div>
                <button id="buttonSave" type="button" class="btn btn-primary">Save</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
<div class="tab-card card" id="tabTestsequences">
    <form id="testsequenceEdit">
        <nav class="navbar navbar-light action-bar p-3">
            <div class="input-group flex-nowrap">
                <button class="btn btn-secondary" id="buttonAbortEdit">
                    <i class="fa fa-times" aria-hidden="true"></i>
                    <span class="d-none d-sm-inline"> Abort</span>
                </button>
                <button type="button" class="btn btn-success ml-2"
                        data-toggle="modal" onclick="checkForChanges()">
                    <i class="fa fa-floppy-o" aria-hidden="true"></i>
                    <span class="d-none d-sm-inline"> Save</span>
                </button>
            </div>
        </nav>
        <div class="row tab-side-bar-row">
            <div class="col-md-9 p-3">
                <h4 class="mb-3">Edit {{ .TestSequence.Name }}</h4>
                <div class="form-group">
                    <label for="inputTestSequenceName"><strong>Test Sequence Name</strong></label>
                    <input class="form-control" id="inputTestSequenceName"
                           placeholder="Enter test sequence name, e.g. 'Buy a short distance ticket'" value="{{ .TestSequence.Name }}" required>
                </div>
                {{ with .TestSequenceVersion }}
                <div class="form-group">
                    <label for="inputTestSequenceDescription"><strong>Test Sequence Description</strong></label>
                    <textarea class="form-control" id="inputTestSequenceDescription" rows="4"
                              placeholder="Describe the test sequence, e.g. 'This test sequence tests ticket buy options'">{{ .Description }}</textarea>
                </div>
                <div class="form-group">
                    <label for="inputTestSequencePreconditions"><strong>Test Sequence Conditions</strong></label>
                    <textarea class="form-control" id="inputTestSequencePreconditions" rows="4"
                              placeholder="Enter preconditions, e.g. 'The system must be up and running in idle'">{{ .Preconditions }}</textarea>
                </div>
                <div class="form-group">
                    <div class="form-inline d-flex justify-content-start">
                        <label><strong>Test Cases</strong></label>
                        <button type="button" class="btn btn-sm btn-primary ml-auto mb-2" id="buttonAddTestcase"
                                data-toggle="modal" data-target="#modal-testcase-selection">
                            Add Test Case
                        </button>
                    </div>
                    <ul id="testCasesList" class="list-group">
                        {{ if .Cases }}
                            {{ range .Cases }}
                            <li class="list-group-item testCaseInTestSequence" id="{{ .Name }}">
                                <span>{{ .Name }}</span>
                                <button type="button" class="remove-test-case close ml-auto" aria-label="Remove">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </li>
                            {{ end }}
                        {{ else }}
                            <li class="list-group-item" id="testCaseListPlaceholder">
                                <span class="text-muted">No Test Cases</span>
                                <a type="button" class="add-test-case close ml-auto" aria-label="Add TestCase"
                                   data-toggle="modal" data-target="#modal-testcase-selection">
                                    <span aria-hidden="true">+</span>
                                </a>
                            </li>
                        {{ end }}
                    </ul>
                </div>
            </div>
            <div class="col-md-3 p-3 tab-side-bar">
                <div class="form-row">
                    <div class="form-group">
                        <label for="inputTestsequenceTime"><strong>Estimated Test Duration</strong></label>
                        <p class="text-muted" id="testsequenceTime">
                             {{ if and (eq .SequenceInfo.DurationHours 0) (eq .SequenceInfo.DurationMin 0) }}
                             No Test Duration
                             {{ else }}
                                 {{ if gt .SequenceInfo.DurationHours 0 }}
                                     {{ .SequenceInfo.DurationHours }}
                                     {{ if eq .SequenceInfo.DurationHours 1 }} Hour {{ else }} Hours {{ end }}
                                 {{ end }}
                                 {{ if gt .SequenceInfo.DurationMin 0 }}
                                    {{ .SequenceInfo.DurationMin }}
                                    {{ if eq .SequenceInfo.DurationMin 1 }}
                                        Minute
                                    {{ else }}
                                        Minutes
                                    {{ end }}
                                 {{ end }}
                             {{ end }}
                             {{ end }}
                        </p>
                    </div>
                </div>
            </div>
            {{template "modal-testcase-selection" . }}
            {{template "modal-manage-versions" . }}
        </div>
    </form>
    <script src="/static/js/project/testsequences.js"></script>
   <script type="text/javascript">

        // Save the original test sequence. It is needed to check for changes.
        testsequence = {{ .TestSequence }};
    </script>
    <script>
        assignEventsToNameTextField();
        assignButtonsTestSequence();
    </script>
</div>
{{end}}