<script type="text/javascript">
	function change_project_name() {
    bootbox.prompt({ 
        size: "medium",
        title: "Change Project Name to:",
        value: "<%= @project.name %>",
        callback: function(value){ 
          if (value) {
            $.getScript("/projects/<%= @project.id %>/update_name?value=" + value);
          }
        }
    });
      
	}
	
</script>


<h2><%= I18n.t(:edit_project) %>:
  <!--
	<a href="#" id="project_name" data-type="text" data-pk="1" data-url="/projects/<%= @project.id %>/update_name" data-title="<%= I18n.t(:change_project_name) %>"><%= @project.name %></a>
	-->

  <% if current_user && current_user.is_admin? %>
	<a href="javascript:void(0);" id="project_name" onclick="change_project_name();"><span id="project_name_display"><%= @project.name %></span></a>
  <% else %>
		<span id="project_name_display"><%= @project.name %></span>	
	<% end%>
	
  <span style="font-size: 15px;">(<%= @project.identifier %>)</span>

  <% if File.exist?(@project.checkout_dir) %>
      &nbsp;
      <a href="/projects/<%= @project.id %>/duplicate" class="btn btn-sm btn-info"><%= I18n.t(:duplicate) %></a>
  <% end %>

      &nbsp;
      <a href="/projects/<%= @project.id %>/user_stories" class="btn btn-sm btn-default"><%= I18n.t(:user_stories) %></a>
    
</h2>

<% if current_user && current_user.is_admin? %>
    <p>
      Config file: <i><%= @project.config_file_path %></i> (<a href="/projects/<%= @project.id %>">show project config</a>)
    </p>
<% end %>


<% if @errors && @errors.any? %>
    <div class='alert alert-danger' style="margin-right: 3%;">
      <% @errors.each do |err|%>
        <div><%= err %></div>
      <% end %>
    </div>		
<% end %>


<% if @project.builds.count > 0 %>
    <% if !File.exist?(@project.working_dir) && RACK_ENV != "showcase" %>

        <div class="alert alert-danger">

          <%= I18n.t(:configuration_error) %>: <strong><%= @project.working_dir %> </strong> not found in BuildWise
          working directory. Make sure the above exists (create it if not), then in command window, change to the
          directory, run the following command :
          <pre>git clone &lt;YOUR_GIT_REPO&gt; sources</pre>

        </div>

    <% elsif !File.exist?(@project.working_dir + "/sources") && RACK_ENV != "showcase" %>

        <div class="alert alert-danger">

          <%= I18n.t(:configuration_error) %>: The project sources not checked out in BuildWise working directory. In
          command window, change to <strong><%= @project.working_dir %> </strong>, run the following command :
          <pre>git clone &lt;YOUR_GIT_REPO&gt; sources</pre>
        </div>

    <% end %>
<% end %>

<%=  partial(:'projects/distribution_rule_modal', :locals => {:project => @project}) %>

<%=  partial(:'projects/load_operation_criteria_modal', :locals => {:project => @project}) %>

<% form_for(@project, "/projects/#{@project.id}", :method => "post" ) do %>

  <%=  partial(:'projects/form', :locals => {:project => @project}) %>

<div class="config-section-content">
  <div class="form-group form-group-sm row">
    <label class="col-sm-2 form-control-label" for="contact_header">&nbsp; </label>
    <div class=" col-sm-9">
      <input type="submit" value="<%= I18n.t(:save) %>" class="btn btn-primary" id="save-project-btn" 
             <% if current_user.nil? %>disabled="true"
      <% end %>
             data-toggle="tooltip" data-placement="bottom" title="
        <% if RACK_ENV == 'showcase' %>Disabled for ShowCase mode
        <% else %>Save the project settings
        <% end %>"
      />
      <a href="/" class="btn btn-default">Cancel</a>
    </div>
  </div>
 </div>
<% end %>


<script type="text/javascript" charset="utf-8">

    <% if current_user && (current_user.is_admin? || current_user.has_role?("builder", @project) ) %>

    $(document).ready(function () {
        // $('#project_name').editable({
        //     placement: 'bottom'
        // });
    });

    <% end %>
</script>
