## -*- coding: utf-8 -*-
<%inherit file="/base/base.html"/>

## don't trigger flash messages on this page
<%def name="flash_msg()">
</%def>

<%block name="title">
    ${_('%s Creating Repository') % c.repo_name}
</%block>

<%def name="breadcrumbs_links()">
    ${_('Creating repository')} ${c.repo}
</%def>

<%block name="header_menu">
    ${self.menu('repositories')}
</%block>
<%def name="main()">
<div class="panel panel-primary">
    <div class="panel-heading clearfix">
        ${self.breadcrumbs()}
    </div>

    <div class="panel-body">
            <h4 class="text-center">
                ${_('Repository "%(repo_name)s" is being created, you will be redirected when this process is finished.' % {'repo_name':c.repo_name})}
            </h4>

        <div id="progress">
            <div class="progress progress-striped active">
                <div class="progress-bar" role="progressbar"
                    aria-valuenow="100" aria-valuemin="0" aria-valuemax="100">
                </div>
            </div>
        </div>
        <div id="progress_error" style="display: none;">
            <div class="alert alert-danger">
                ${_("We're sorry but error occurred during this operation. Please check your Kallithea server logs, or contact administrator.")}
            </div>
        </div>
    </div>
</div>

<script>
(function worker() {
  $.ajax({
    url: ${h.js(h.url('repo_check_home', repo_name=c.repo_name, repo=c.repo, task_id=c.task_id))},
    success: function(data) {
      if(data.result === true){
          //redirect to created fork if our ajax loop tells us to do so.
          window.location = ${h.js(h.url('summary_home', repo_name = c.repo))};
      }
    },
    complete: function(resp, status) {
      if (resp.status == 200){
          // Schedule the next request when the current one's complete
          setTimeout(worker, 1000);
      }
      else{
          $("#progress").html($('#progress_error').html());
      }
    }
  });
})();
</script>
</%def>
