<script type="text/javascript" charset="utf-8">
	function trim(s){ 
	  return ( s || '' ).replace( /^\s+|\s+$/g, '' ); 
	}	
  function set_identifier() {
    var entered_name = $("#name").val();
    if (!$("#identifier").val()) {
      var default_identifier = $.trim(trim(entered_name).toLowerCase().replace(/ /g, '-'));
      $("#identifier").val(default_identifier);
    }
  }

	function set_parallel() {
    var ui_test_task_value = $("#ui_test_task").val();  
    if (ui_test_task_value.endsWith("ci:ui_tests:quick")) {
      ui_test_task_value = ui_test_task_value.replace("ci:ui_tests:quick", "ci:ui_tests:full");
      $("#ui_test_task").val(ui_test_task_value);
    }
    
    var project_name = $("#name").val();
    var project_identifier = $("#identifier").val();    
    
    if (project_name.includes("Sequential")){
      $("#name").val(project_name.replace("Sequential", "Parallel"));      
    }
    if (project_identifier.includes("sequential")){
      $("#identifier").val(project_identifier.replace("sequential", "parallel"));      
    }
        
		$(".parallel-build").show();
	}
  
	function set_sequential() {
    var ui_test_task_value = $("#ui_test_task").val();
    if (ui_test_task_value.endsWith("ci:ui_tests:full")) {
      ui_test_task_value = ui_test_task_value.replace("ci:ui_tests:full", "ci:ui_tests:quick");
      $("#ui_test_task").val(ui_test_task_value);
    }

    var project_name = $("#name").val();
    var project_identifier = $("#identifier").val();    
    
    if (project_name.includes("Parallel")){
      $("#name").val(project_name.replace("Parallel", "Sequential"));      
    }
    if (project_identifier.includes("parallel")){
      $("#identifier").val(project_identifier.replace("parallel", "sequential"));      
    }    
		$(".parallel-build").hide();
	}
</script>


<h2><%= I18n.t(:duplicate_project) %>: <%= @project.name %></h2>

<div style="margin-bottom: 10px;"><%= I18n.t(:duplicate_project_intro) %></div>

<form name="duplicate_project_form" method="post" action="/projects/<%= @project.id %>/duplicate" class="form-horizontal">

  <div class="form-group form-group-sm row">
    <label class="col-sm-3 form-control-label" for="contact_header"><%= I18n.t(:new_project_name) %>:</label>
    <div class="col-sm-6">
      <input type="text" name="new_project_name" id="name" onchange="set_identifier();" onfocusout="set_identifier()" class="form-control" value="<%= @project.name %>">
    </div>
  </div>

  <div class="form-group form-group-sm row">
    <label class="col-sm-3 form-control-label" for="contact_header"><%= I18n.t(:new_project_identifier) %>:</label>
    <div class="col-sm-6">
      <input type="text" name="new_project_identifier" id="identifier" class="form-control" value="">
    </div>
  </div>

  <div class="form-group form-group-sm row">
    <label class="col-sm-3 form-control-label" for="contact_header"><%= I18n.t(:execution_mode) %>: </label>
    <div class="col-sm-6" style="margin-top: 5px;">
					<div>
					 <input type="radio" onclick="set_sequential();" name="is_parallel" value="false" <%unless @project.config.is_parallel%>checked="checked"<%end%>> <b style="margin-left: 0.3rem;">Sequential</b>
					 <label style="width: 3rem;">&nbsp;</label>
					 <input type="radio" onclick="set_parallel();" name="is_parallel" value="true" <%if @project.config.is_parallel%>checked="checked"<%end%>> <b style="margin-left: 0.3rem;">Parallel</b>
				  </div>
    </div>
  </div>

    <div class="form-group form-group-sm row parallel-build"  <% unless @project.config.is_parallel %>style="display:none;" <% end %>>
      <label class="col-sm-3 form-control-label" for="contact_header"><%= I18n.t(:app_name) %> <% if @project.config.is_parallel%><span class="mandatory">*</span><% end %></label>
      <div class="col-sm-6">
        <input type="text" name="app_name" value="<%= @project.config.app_name rescue nil %>" class="form-control"/>
        <div class="hint hint-below"><%= raw I18n.t(:app_name_hint) %></div>
      </div>
    </div>


    <div class="form-group form-group-sm row parallel-build"  <% unless @project.config.is_parallel %>style="display:none;" <% end %>>
      <label class="col-sm-3 form-control-label" for="contact_header">Work directory on Agents:</label>
      <div class="col-sm-9">
        <input type="text" name="agent_work_dir" value="<%= @project.config.agent_work_dir rescue nil %>" class="form-control"/>
        <div class="hint hint-below"><%= I18n.t(:work_dir_on_buildwise_agents) %>  <code>
          <% if RUBY_PLATFORM =~ /mingw/ %>c:\work\myproject<% else %>/Users/me/myproject<% end %></code></div>
      </div>
    </div>

  <div class="form-group form-group-sm row">
    <label class="col-sm-3 form-control-label" for="contact_header"><%= I18n.t(:ui_test_task) %>: </label>
    <div class="col-sm-6">
      <input type="text" name="ui_test_task" id="ui_test_task" class="form-control" value="<%= @project.config.ui_test_step.task rescue nil %>" placeholder="task for new project">
    </div>
  </div>


  <div class="form-group form-group-sm row">
    <label class="col-sm-3 form-control-label" for="contact_header"><%= I18n.t(:branch) %>:</label>
    <div class="col-sm-3">
      <input type="text" name="new_scm_branch" class="form-control" placeholder="<%= I18n.t(:default_to_master_branch) %>">
    </div>
  </div>

  <div class="form-group row">
    <label class="col-sm-3 form-control-label">&nbsp; </label>
    <div class=" col-sm-9">
      <%= submit_tag value: I18n.t(:clone), :class => "btn btn-primary" %>
      <a href="/" class="btn btn-default"><%= I18n.t(:cancel) %></a>
    </div>
  </div>

</form>
