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">{% 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="projectname">
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
24                <label class="project-form">Project type:</label>
25                {% if releases.count > 0 %}
26                    <label class="project-form radio" style="padding-left: 35px;"><input id='type-new'    type="radio" name="ptype" value="new"/> New project</label>
27                {% endif %}
28                    <label class="project-form radio" style="padding-left: 35px;"><input id='type-import' type="radio" name="ptype" value="import"/> Import command line project</label>
29
30        {% if releases.count > 0 %}
31          <div class="release form-group">
32            {% if releases.count > 1 %}
33              <label class="control-label">
34                Release
35                <span class="glyphicon glyphicon-question-sign get-help" title="The version of the build system you want to use for this project"></span>
36              </label>
37              <select name="projectversion" id="projectversion" class="form-control">
38                {% for release in releases %}
39                    <option value="{{release.id}}"
40                        {%if defaultbranch == release.name %}
41                            selected
42                        {%endif%}
43                     >{{release.description}}</option>
44                {% endfor %}
45              </select>
46              <div class="row">
47                <div class="col-md-4">
48                {% for release in releases %}
49                  <div class="helptext" id="description-{{release.id}}" style="display: none">
50                    <span class="help-block">{{release.helptext|safe}}</span>
51                  </div>
52                {% endfor %}
53                </div>
54              </div>
55            {% else %}
56              <input type="hidden" name="projectversion" value="{{releases.0.id}}"/>
57            {% endif %}
58
59              <input type="checkbox" class="checkbox-mergeattr" name="mergeattr" value="mergeattr">  Merged Toaster settings (Command line user compatibility)
60              <span class="glyphicon glyphicon-question-sign get-help" title="Place the Toaster settings into the standard 'local.conf' and 'bblayers.conf' instead of 'toaster_bblayers.conf' and 'toaster.conf'"></span>
61
62           </div>
63        {% endif %}
64
65            <div class="build-import form-group" id="import-project">
66              <label class="control-label">Import existing project directory
67                <span class="glyphicon glyphicon-question-sign get-help" title="Enter a path to an existing build directory, import the existing settings, and create a Toaster Project for it."></span>
68              </label>
69              <input style="width: 33%;"type="text" class="form-control" required id="import-project-dir" name="importdir">
70            </div>
71
72            <div class="top-air">
73              <input type="submit" id="create-project-button" class="btn btn-primary btn-lg" value="Create project"/>
74              <span class="help-inline" style="vertical-align:middle;">To create a project, you need to enter a project name</span>
75            </div>
76
77        </form>
78      </div>
79    </div>
80
81    <script type="text/javascript">
82        $(document).ready(function () {
83            // hide the new project button
84            $("#new-project-button").hide();
85            $('.btn-primary').attr('disabled', 'disabled');
86            $('#type-new').attr('checked', 'checked');
87
88            // enable submit button when all required fields are populated
89            $("input#new-project-name").on('input', function() {
90                if ($("input#new-project-name").val().length > 0 ){
91                    $('.btn-primary').removeAttr('disabled');
92                    $(".help-inline").css('visibility','hidden');
93                }
94                else {
95                    $('.btn-primary').attr('disabled', 'disabled');
96                    $(".help-inline").css('visibility','visible');
97                }
98            });
99
100            // show relevant help text for the selected release
101            var selected_release = $('select').val();
102            $("#description-" + selected_release).show();
103
104
105            $('select').change(function(){
106                var new_release = $('select').val();
107                $(".helptext").hide();
108                $('#description-' + new_release).fadeIn();
109            });
110
111            libtoaster.makeProjectNameValidation($("#new-project-name"),
112                 $("#hint-error-project-name"), $("#validate-project-name"),
113                 $(".btn-primary"));
114
115
116			// Hide the project release when you select an analysis project
117			function projectType() {
118				if ($("input[type='radio']:checked").val() == 'new') {
119					$('.build-import').fadeOut();
120					$('.release').fadeIn();
121                    $('#import-project-dir').removeAttr('required');
122				}
123				else {
124					$('.release').fadeOut();
125					$('.build-import').fadeIn();
126                    $('#import-project-dir').attr('required', 'required');
127				}
128			}
129			projectType();
130
131			$('input:radio').change(function(){
132				projectType();
133			});
134        });
135    </script>
136
137{% endblock %}
138