{% extends "master.html" %}
{% from "_formhelper.html" import render_bootstrap_field %}

{% block title %}New project{% endblock %}
{% set tag = "new_project" %}


{% block content %}
<div class="container">
  <div class="row justify-content-around">
    <div class="col-md-8">
      <div class="card mt-5">
        <div class="card-header">
          <strong>Create new Project</strong>
        </div>
        <div class="card-body">
          <form action="{{ url_for('ui_ns.new_project') }}" method="post">
            {{ render_bootstrap_field(form.name, field_description="the name of your project") }}
            {{ render_bootstrap_field(form.description, field_description="short description of the project") }}
            {{ render_bootstrap_field(form.namespace, field_description="namespace of the project") }}
            {{ render_bootstrap_field(form.url, field_description="url of the project's website") }}
            {{ render_bootstrap_field(form.avatar_email, field_description="libravatar email address avatar email") }}
            {% if config.get('PRIVATE_PROJECTS', False) %}
              {{ render_bootstrap_field(form.private, field_description="To mark the repo private") }}
            {% endif %}
            {% if not config.get('DISABLE_MIRROR_IN', False) %}
            {{ render_bootstrap_field(form.mirrored_from, field_description="Mirror this project from another git server") }}
            {% endif %}
            {{ render_bootstrap_field(form.create_readme, field_description="Create a README file automatically") }}
            {% if form.repospanner_region %}
              {{ render_bootstrap_field(form.repospanner_region, field_description="repoSpanner region to create the project in") }}
            {% endif %}
            <input class="btn btn-primary" type="submit" value="Create" title="Update description">
            <input type="button" class="btn btn-default float-right"
              value="Cancel" onclick="history.back();">
            {{ form.csrf_token }}
          </form>
        </div>
      </div>
    </div>
  </div>
  <div class="row justify-content-around">
    <div class="col-md-8">
        <div class="mt-3">
          <p id="mirrored_doc">
            Note that Pagure only supports mirroring from a public server.
          </p>
        </div>
    </div>
  </div>
</div>
{% endblock %}


{% if config.get('PRIVATE_PROJECTS', False) %}
{% block jscripts %}
{{ super() }}
<script type="text/javascript">
var _user = '{{ g.fas_user.username }}';
$('#private').change(function(){
  var _private = $('#private').is(':checked');
  if (_private) {
    $('#namespace').append($('<option></option>').val(_user).html(_user));
    $('#namespace').val(_user);
    $('#namespace').attr("disabled", "disabled");
  } else {
    $("#namespace>option[value='" + _user + "']").remove();
    $('#namespace').removeAttr("disabled");
  }
});
{% if not config.get('DISABLE_MIRROR_IN', False) %}
function update_if_mirror() {
  if ($('#mirrored_from').val()){
    $('#create_readme').attr("disabled", "disabled");
    $('#create_readme').prop('checked', false);
    $('#mirrored_doc').show();
  } else {
    $('#create_readme').removeAttr("disabled");
    $('#mirrored_doc').hide();
  }
};
$('#mirrored_from').keyup(function(){
  update_if_mirror();
});
update_if_mirror();
{% endif %}
</script>
{% endblock %}
{% endif %}
