1{% extends "base.html" %}
2{% load projecttags %}
3{% load humanize %}
4
5{% block title %} Create a new project - Toaster {% endblock %}
6
7{% block pagecontent %}
8<div class="row">
9  <div class="col-md-12">
10    <div class="page-header">
11          <h1>Create a new project</h1>
12        </div>
13    {% if alert %}
14      <div class="alert alert-danger" role="alert">{{alert}}</div>
15    {% endif %}
16
17        <form method="POST"  action="{%url "newproject_specific" project_pk %}">{% csrf_token %}
18          <div class="form-group" id="validate-project-name">
19            <label class="control-label">Project name <span class="text-muted">(required)</span></label>
20            <input type="text" class="form-control" required id="new-project-name" name="display_projectname" value="{{projectname}}" disabled>
21          </div>
22          <p class="help-block text-danger" style="display: none;" id="hint-error-project-name">A project with this name exists. Project names must be unique.</p>
23        <input type="hidden" name="ptype" value="build" />
24        <input type="hidden" name="projectname" value="{{projectname}}" />
25
26        {% if releases.count > 0 %}
27				<div class="release form-group">
28            {% if releases.count > 1 %}
29              <label class="control-label">
30                Release
31                <span class="glyphicon glyphicon-question-sign get-help" title="The version of the build system you want to use"></span>
32              </label>
33              <select name="projectversion" id="projectversion" class="form-control">
34                {% for release in releases %}
35                    <option value="{{release.id}}"
36                        {%if defaultbranch == release.name %}
37                            selected
38                        {%endif%}
39                     >{{release.description}}</option>
40                {% endfor %}
41              </select>
42              <div class="row">
43                <div class="col-md-4">
44                {% for release in releases %}
45                  <div class="helptext" id="description-{{release.id}}" style="display: none">
46                    <span class="help-block">{{release.helptext|safe}}</span>
47                  </div>
48                {% endfor %}
49            {% else %}
50              <input type="hidden" name="projectversion" value="{{releases.0.id}}"/>
51            {% endif %}
52                </div>
53              </div>
54            </fieldset>
55        {% endif %}
56            <div class="top-air">
57              <input type="submit" id="create-project-button" class="btn btn-primary btn-lg" value="Create project"/>
58              <span class="help-inline" style="vertical-align:middle;">To create a project, you need to specify the release</span>
59            </div>
60
61        </form>
62      </div>
63    </div>
64
65    <script type="text/javascript">
66        $(document).ready(function () {
67            // hide the new project button, name is preset
68            $("#new-project-button").hide();
69
70            // enable submit button when all required fields are populated
71            $("input#new-project-name").on('input', function() {
72                if ($("input#new-project-name").val().length > 0 ){
73                    $('.btn-primary').removeAttr('disabled');
74                    $(".help-inline").css('visibility','hidden');
75                }
76                else {
77                    $('.btn-primary').attr('disabled', 'disabled');
78                    $(".help-inline").css('visibility','visible');
79                }
80            });
81
82            // show relevant help text for the selected release
83            var selected_release = $('select').val();
84            $("#description-" + selected_release).show();
85
86            $('select').change(function(){
87                var new_release = $('select').val();
88                $(".helptext").hide();
89                $('#description-' + new_release).fadeIn();
90            });
91
92        });
93    </script>
94
95{% endblock %}
96