{% extends "base.html" %}
{% load custom_tags %}
{% load static %}
{% get_media_prefix %}.
{% block styling %}
	.statistic:not(.last-stat){
		border-right: 1px solid #e0e1e2 ;
	}
	.statistics th:not(.last-th){
		border-right: 1px solid #dddddd;
	}
{% endblock %}
	
{% block content %}
<br>
<div class="ui container" id="summary">
	<div class="ui grid" style="margin-top: 1rem;">
		<div class="six wide column">
			<div class="ui fluid raised card" style="">
				<div class="content">
					<div class="ui two statistics" style="">
						<div class="teal statistic">
							<div class="value">
								{{ current_round.roundNo }}
							</div>
							<div class="label">
								<br>
								Current Round
							</div>
						</div>
						<div class="red statistic last-stat">
							<div class="text value" style="padding-top: 1rem;">
								{{ current_round.endDate }}
							</div>
							<div class="label">
								<br>
								Last date 
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="ten wide column">
			<div class="ui fluid raised card">
				<div class="content">
					<div class="ui three statistics divided">
						<div class="yellow statistic">
							<div class="value">
								{{ allApplications|length }}
							</div>
							<div class="label">
								<br>
								Total Applications
							</div>
						</div>
						<div class="green statistic">
							<div class="value">
								{{ ProjectWiseShortlistedApplications|get_count_multilist }}
							</div>
							<div class="label">
								<br>
								Shortlisted applications
							</div>
						</div>
						<div class="ui grid">

						</div>
						<div class="statistic last-stat" >
							<div class="value" style="color:#5279a2;" >
								{{ allotedStudents|length }}
							</div>
							<div class="label">
								<br>
								Alloted students
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<br>
	<div class="ui yellow icon large floating message" style="margin-top: 3rem;">
		<i class="calendar check icon"></i>
		<div class="content">
			<div class="header" style="padding-bottom:1rem;">
				Time remaining for Round {{ current_round.roundNo }}
			</div>
			<div class="ui progress {% get_progress_color current_round.endDate %}" data-percent="{% get_progress_percent current_round  %}" id="time-progress" style="opacity: 0.85">
				  <div class="bar">
				    <div class="progress"></div>
				  </div>
				  <div class="label header">{%  get_remaining_days current_round.endDate  %}</div>
			</div>
		</div>
	</div>
</div>

<br>
<br>
<div class="ui {% if user_type == 'facad' %}five{% else %}four{% endif %} item stackable tabs inverted menu " style="font-size: large;">
	<a class="item active" data-tab="first">Applications</a>
	<a class="item" data-tab="second">Shortlisted Applications</a>
	<a class="item" data-tab="third">Open positions</a>
	<a class="item" data-tab="fourth">Alloted students</a>
	{% if user_type == 'facad' %}<a class="item" data-tab="fifth">FacAd dashboard</a>{% endif %}
</div>

<div class="ui tab active" data-tab="first">
{% if availablePositions|length == 0 %}
	<div class="ui warning message">
	  <i class="close icon"></i>
	  <div class="header ui center aligned">
	    Information to Faculty
	  </div>
	  <ul>
	  	<li>You have not added any <span class="medium header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">Projects</span> yet.</li>
	  </ul>
	</div>
{% elif allApplications|length == 0 %}
	<div class="ui warning message">
	  <i class="close icon"></i>
	  <div class="header ui center aligned">
	    Information to Faculty
	  </div>
	  <ul>
	  	<li><span class="medium header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">No applications</span> are submitted to you yet.</li>
	  </ul>
	</div>
{% else %}
	
	<div class="ui warning message">
		  <i class="close icon"></i>
		  <div class="header ui center aligned">
		    Instructions to Faculty
		  </div>
		  <ul>
		  	<li>Use the <span class="header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); "> Info </span> button to know more about the student.</li>
		  	<li>Click on <span class="header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); "> Shortlist </span> to allocate priority to said student.</li>
		  	<li>You can find the shortlisted applications in the <span class="header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">Shortlisted Applications</span> tab.</li>
		  </ul>
		</div>
	<table id="applications" class="ui table raised segment center aligned" style="width:100%">
		<thead>
			<tr>
				<th>NAME</th>
				<th>POSITION</th>
				<th>CGPA</th>
				<th>DATE</th>
				<th class="last-th">ACTIONS</th>
			</tr>
		</thead>
		<tbody>
			{% for application in allApplications %}
				<tr>
					<td>
						{{ application.student.student.get_full_name }}
					</td>
					<td>
						{{ application.project.title }}
					</td>
					<td>
						<div style="display: none;">{% get_normalized_grades application.student.get_cgpa %}</div>
						<div class="ui yellow rating" data-rating="{% get_normalized_grades application.student.get_cgpa %}" data-max-rating="5">
						</td>
					<td>
						{{ application.date }}
					</td>
					<td>
						<div class="" style="display: inline-flex;">
							<button class="ui vk button" onclick="show_student_detail('{{ application.student.id }}-{{ application.project.id }}')">
								<i class="address card icon"></i>
								Info
							</button>
							<form action="{% url 'gap:shortlist' %}" method="POST" class="ui column">
								{% csrf_token %}
								<input type="hidden" name="student_Id" value="{{ application.student.id }}">
								<input type="hidden" name="project_Id" value="{{ application.project.id }}">
								<input type="hidden" name="action" value="shortlist">
								<button class="ui icon right labeled teal button" onclick="return confirm('Do you want to SHORTLIST this application?');" >
									<i class="check icon"></i>
									Shortlist
								</button>
							</form>
						</div>	
					</td>
				</tr>
			{% endfor %}
		</tbody>
	</table>
{% endif %}
</div>
<div class="ui tab " data-tab="second">
	<div class="ui warning message">
	  
	  <div class="header ui center aligned">
	    Instructions to use the priority window
	  </div>
	  <ul>
	  	<li>Each card represents priorities to <span class="header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">Individual projects</span> proposed by you. You can see the ribbon to understand which project you are working with.</li>
	  	<li>Arrangement of the applications should be in <span class="header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">Ascending order</span>.</li>
	  	<li>You can <span class="medium header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">hold and move</span> the applications to change the priority arrangements. </li>
	  	<li>Click on the <span class="header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">Update priorities</span> to make changes permanent.</li>
	  </ul>
	</div>
	{% for shortlistedApplications in ProjectWiseShortlistedApplications %}
		<div style="padding: 2em 0;margin: 2em 0;">
			<div class="ui grid">
				<div class="right floated four wide column">
					<button class="fluid ui labeled {% get_table_color forloop.counter0 %} icon button" onclick="submit_priorities({{ forloop.counter0 }},{% with application=shortlistedApplications|index:0 %}{{ application.project.id }}{% endwith %})" >
						<i class="plus icon"></i>
						Update priorities
					</button>
				</div>
			</div>
			<div class="ui segment fluid raised card">
				<div class="ui middle aligned selection divided list" style="margin-bottom: 0px;">
					<div class="item" style="padding-bottom: 0px;padding-top: 0px;background-color: rgb(0,0,0,0.03);">
						<a class="left aligned floating ui {% get_table_color forloop.counter0 %} ribbon label">{% with application=shortlistedApplications|index:0 %} {{ application.project.title }} {% endwith %}</a>
						<div class="ui grid center aligned divided" style="margin-top: 0px;">
							<div class="four wide column ui tiny header">NAME</div>
							<div class="four wide column ui tiny header ">POSITION</div>
							<div class="two wide column ui tiny header">CGPA</div>
							<div class="two wide column ui tiny header">SHORTLISTED ON</div>
							<div class="four wide column ui tiny header">ACTIONS</div>
						</div>
					</div>
					<div class="ui divider" style="margin-bottom: 0px;"></div>
				</div>
				<div class="ui middle aligned selection divided list" style="margin-top: 0px;" id="sortable-{{ forloop.counter0 }}">
					{% for application in shortlistedApplications %}
						<div class="item">
							<div class="ui grid">
								<input type="hidden" readonly="" disabled="" class="applied-student-id" value="{{ application.student.id }}">
								<div class="column four wide center aligned middle aligned"><div class="ui medium ">{{ application.student.student.get_full_name }}</div></div>
								<div class="column four wide center aligned middle aligned"><div class="ui medium ">{{ application.project.title }}</div></div>
								<div class="column two wide center aligned middle aligned"><div class="ui star yellow rating" data-rating="{% get_normalized_grades application.student.get_cgpa %}" data-max-rating="5"></div></div>
								<div class="column two wide center aligned middle aligned"><div>{{ application.date }}</div></div>
								<div class="center aligned four wide column">
									<div class="ui center aligned" style="display: inline-flex;">
										<button class="ui vk button" onclick="show_student_detail( '{{ application.student.id }}-{{ application.project.id }}' )">
											<i class="address card icon"></i>
											Info
										</button>
										<form action="{% url 'gap:shortlist' %}" method="POST" class="ui column">
											{% csrf_token %}
											<input type="hidden" name="student_Id" value="{{ application.student.id }}">
											<input type="hidden" name="project_Id" value="{{ application.project.id }}">
											<input type="hidden" name="action" value="discard">
											<button class="ui right labeled icon negative button" onclick="return confirm('Do you want to DISCARD this application?');">
											<i class="trash icon"></i>
											Discard
										</button>
										</form>
									</div>	
								</div>
							</div>
						</div>
					{% endfor %}
				</div>
			</div>
		</div>
	{% endfor %}
</div>
<div class="ui tab" data-tab="third">
	<div class="ui warning message">
	  <i class="close icon"></i>
	  <div class="header ui center aligned">
	    Information to Faculty
	  </div>
	  <ul>
	  	<li>Use <span class="medium header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">Add new Project</span> to mention the projects available under you.</li>
	  	<li>To make changes to existing projects use the <span class="medium header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">Update</span> button .</li>
	  </ul>
	</div>
	<div class="ui grid">
		<div class="right floated four wide column">
			<button class="fluid ui labeled teal icon button" onclick="show_new_position_form()" >
				<i class="plus icon"></i>
				Add new Project
			</button>
		</div>
	</div>
	<div class="ui segment fluid raised card">
		<div class="ui middle aligned selection divided list" style="margin-bottom: 0px;">
			<div class="item" style="padding-bottom: 0px;padding-top: 0px;background-color: rgb(0,0,0,0.03);">
				<div class="ui grid center aligned divided" style="margin-top: 0px;">
					<div class="three wide column ui tiny header">PROJECT TITLE</div>
					<div class="three wide column ui tiny header ">DESCRIPTION</div>
					<div class="two wide column ui tiny header">CONTACT DETAILS</div>
					<div class="three wide column ui tiny header">REQUISITES</div>
					<div class="two wide column ui tiny header">AVAILABLE POSITIONS</div>
					<div class="three wide column ui tiny header">ACTIONS</div>
				</div>

			</div>
			<div class="ui divider" style="margin-bottom: 0px;"></div>
		</div>
		<div class="ui middle aligned selection divided list" style="margin-top: 0px;" >
			{% for opening in availablePositions %}
			<div class="item">
				<div class="ui grid">
					<div class="column three wide center aligned middle aligned"><div class="ui medium ">{{ opening.title }}</div></div>
					<div class="column three wide center aligned middle aligned"><div class="ui medium ">{{ opening.description }}</div></div>
					<div class="column two wide center aligned middle aligned">{{ opening.contact_details }}</div>
					<div class="column three wide center aligned middle aligned">
						<table class="ui table">
							<thead>
								<tr>
									<th>Subject</th>
									<th>CGPA</th>

								</tr>
							</thead>
							<tbody>
								{% for requisite in opening.get_requisites %}
								<tr>
									<td>{{ requisite.Subject }}</td>
									<td>{{ requisite.cgpa }}</td>
								</tr>
								{% endfor %}
							</tbody>
						</table>
					</div>
					<div class="column two wide center aligned middle aligned">
						{{ opening.total_positions }}
					</div>
					<div class="right floated three wide column middle aligned">
						<div class="ui center aligned">
							<button class="ui vk button">
								<i class="address card icon"></i>
								Info
							</button>
							<button class="ui right labeled icon brown button" onclick="show_update_form({{ forloop.counter0 }})">
								<i class="edit icon"></i>
								Update
							</button>
						</div>	
					</div>
				</div>
			</div>
			{% endfor %}
		</div>
	</div>
</div>
<div class="ui tab" data-tab="fourth">
	{% if allotedStudents|length == 0 %}
		<div class="ui warning message">
		  <i class="close icon"></i>
		  <div class="header ui center aligned">
		    Information to Faculty
		  </div>
		  <ul>
		  	<li>You are not alloted any <span class="medium header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">students</span> yet.</li>
		  </ul>
		</div>
	{% else %}
	<div class="ui segment fluid raised card">
		<div class="ui middle aligned selection divided list" style="margin-bottom: 0px;">
			<div class="item" style="padding-bottom: 0px;padding-top: 0px;background-color: rgb(0,0,0,0.03);">
				<div class="ui grid center aligned divided" style="margin-top: 0px;">
					<div class="two wide column ui tiny header">ROUND NUMBER</div>
					<div class="four wide column ui tiny header ">NAME</div>
					<div class="four wide column ui tiny header">PROJECT</div>
					<div class="two wide column ui tiny header">CGPA</div>
					<div class="four wide column ui tiny header">ACTIONS</div>
				</div>

			</div>
			<div class="ui divider" style="margin-bottom: 0px;"></div>
		</div>
		<div class="ui middle aligned selection divided list" style="margin-top: 0px;">
			{% for student in allotedStudents %}
				<div class="item">
					<div class="ui grid ">
						<div class="column two wide center aligned middle aligned">{{ student.roundNo }}</div>
						<div class="column four wide center aligned middle aligned"><div class="ui medium ">{{ student.student.student.get_full_name }}</div></div>
						<div class="column four wide center aligned middle aligned"><div class="ui medium ">{{ student.project.title }}</div></div>
						<div class="column two wide center aligned middle aligned"><div class="ui star yellow rating" data-rating="{% get_normalized_grades student.student.get_cgpa %}"></div></div>
						<div class="right floated four wide column">
							<div class="ui center aligned">
								<button class="ui vk button" onclick="show_student_detail( '{{ student.student.id }}-{{ student.project.id }}' )">
									<i class="address card icon"></i>
									Info
								</button>
							</div>	
						</div>

					</div>
				</div>
			{% endfor %}
		</div>
	</div>
	{% endif %}
</div>


{% if user_type == 'facad' %}
	<div class="ui tab" data-tab="fifth" style="padding-top: 2em;">
		<div class="ui stackable height stretched grid">
			<div class="nine wide column">
				<div class="ui fluid raised card">
					<div class="content">
						<h3 class="ui center aligned" style="color:slategrey;">Round Details</h3>
					</div>
					<div class="content">
						<form class="ui form" method="POST">
						<table class="ui celled brown definition table center aligned">
						  <thead>
						    <tr>
						    	<th>Actions</th>
						      <th>Round Number</th>
						      <th>Start Date</th>
						      <th>End Date</th>
						    </tr>
						  </thead>
						  <tbody>
						  	{% for roundDetail in roundDetails %}
						  		{% if forloop.counter != roundDetails|length %}
						  			<tr>
								    	<td class="collapsing">
								          <button type="button" class="ui small button inverted blue disabled">Update</button>
								      	</td>
								      	<td>Round {{ forloop.counter }}</td>
								      	<td>{{ roundDetail.startDate }}</td>
								      	<td>{{ roundDetail.startDate }}</td>
								    </tr>
						  		{% else %}
						  			<tr class="olive">
						  					{% csrf_token %}
						  					<input type="hidden" name="roundDetailUpdate" value="true">
									    	<td class="collapsing">
										    	<div class="latest-round-form" style="display: none;">
										        	<button type="submit" class="ui small button secondary">Submit</button>
										    	</div>
										    	<div class="latest-round-detail">
										        	<button type="button" class="ui small button blue" onclick="show_round_detail_form()">Update</button>
										        </div>
									      	</td>
											<td>
												<div class="" style="display: none;">
													{{ RoundUpdateform.roundNo  }}
												</div>
												<div class="">
													{{ forloop.counter }}
												</div>
											</td>
											<td>
												<div class="latest-round-form" style="display: none;">
													<div class="ui calendar date_picker">
													  <div class="ui input left icon">
													    <i class="calendar icon"></i>
													    {{ RoundUpdateform.startDate }}
													  </div>
													</div>
												</div>
												<div class="latest-round-detail">
													{{ roundDetail.startDate }}
												</div>
											</td>
											<td>
												<div class="latest-round-form" style="display: none;">
													<div class="ui calendar date_picker">
													  <div class="ui input left icon">
													    <i class="calendar icon"></i>
													    {{ RoundUpdateform.endDate }}
													  </div>
													</div>
												</div>
												<div class="latest-round-detail">
													{{ roundDetail.endDate }}
												</div>
											</td> 
										
							    	</tr>
						  		{% endif %}
						  	{% endfor %}
						  </tbody>
						</table>
						</form>
					</div>
					<div class="content">
						<div class="center aligned four wide column">
							<form action="{% url 'gap:generateMapping' %}" method="POST" class="ui column">
								{% csrf_token %}
								<button class="fluid ui flexible labeled teal icon button"type="submit" onclick="return confirm('Do you want to SHORTLIST this application?');" >
									Generate Mappings
								</button>
							</form>
						</div>
					</div>
				</div>
			</div>
			<div class="seven wide column">
				<div class="ui fluid teal card">
					<div class="content">
						<div class="ui center aligned header" style="color:slategrey;">Alloted students vs Unalloted students</div>
					</div>
					<div class="content">							
						<canvas id="alloted-unalloted" ></canvas>
					</div>	
				</div>
			</div>
			<div class="sixteen wide column" style="padding-top: 2em;">
				<div class="ui fluid teal card">
					<div class="content">
						<div class="ui center aligned header" style="color:slategrey;">Allotments done so far
						<button class="ui right floated flexible labeled teal icon button" onclick="$(this).find('a')[0].click()" >
							<i class="file download icon"></i>
							<a href="{{ MEDIA_URL }}{{ ALLOCATION_PDF_NAME }}" style="display: none;" target="_blank"></a>
							Download allotments
						</button>
						</div>
					</div>
					<div class="content">
						<table id="generatedAllotments" class="ui table raised segment center aligned" style="width:100%">
							<thead>
								<tr>
									<th>ROUND NUMBER</th>
									<th>STUDENT</th>
									<th>FACULTY</th>
									<th>PROJECT</th>
								</tr>
							</thead>
							<tbody>
								{% for allotment in AllotmentsSoFar %}
									<tr>
										<td>
											{{ allotment.roundNo }}
										</td>
										<td>
											{{ allotment.student.student.get_full_name }}
										</td>
										<td>
											{{ allotment.faculty.get_full_name }}
										</td>
										<td>
											{{ allotment.project.title }}
										</td>
									</tr>
								{% endfor %}
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
{% endif %}


{% endblock %}


{% block modals %}

{% for application in allApplications %}
<div id="application-{{ application.student.id }}-{{ application.project.id }}" class="ui long modal">
	<i class="close icon"></i>
	<div class="header">
		APPLICATION
	</div>
	<div class="content">
		<div class="ui grid">
			<div class="six wide column ui center aligned middle aligned" style="padding-top: 5rem;">
				<div class="ui medium image">
					<div class="ui large icon header">
						<i class="user circle massive grey icon"></i>
					</div>
				</div>
			</div>
			<div class="ten wide fluid column">
				<div class="ui image">

					<div class="ui large header center aligned brown">Application Details</div>
					<div class="ui divider"></div>
					<br>
					<div class="ui grid center aligned">
						<div class="six wide column">
							<div class="ui medium header left aligned">
								Application number	
							</div>	
						</div>
						<div class="two wide column">
							<div class="ui small header center aligned">
								: 	
							</div>	
						</div>
						<div class="five wide column">
							<div class="ui medium header center aligned grey">
								{{ application.student.id }}-{{ application.project.id }}	
							</div>	
						</div>
						<div class="six wide column">
							<div class="ui medium header left aligned">
								Applicant Name
							</div>	
						</div>
						<div class="two wide column">
							<div class="ui small header center aligned">
								: 	
							</div>	
						</div>
						<div class="five wide column">
							<div class="ui medium header center aligned grey">
								{{ application.student.student.get_full_name }}
							</div>	
						</div>

						
						<div class="six wide column">
							<div class="ui medium header left aligned">
								Email ID	
							</div>	
						</div>
						<div class="two wide column">
							<div class="ui small header center aligned">
								: 	
							</div>	
						</div>
						<div class="five wide column">
							<div class="ui medium header center aligned grey">
								{{ application.student.student.email }}
							</div>	
						</div>
						<div class="eleven wide column center aligned">
							<div class="ui icon info message">
								<i class="download icon"></i>
								<div class="content">
									<div class="header">
										Resume of the applicant
									</div>
									{% with resume=application.student.get_resume_details %}
										{% if resume %}
											{% with 'resume-uploads/'|add:'/'|add:resume.file.file.name as image_static %}
											<div class="ui center aligned" ><a href="{% static image_static %}" target="_blank">Click me to download resume</a></div>
											{% endwith %}
										{% else %}
											<div class="ui center aligned" ><div style="color:slategrey;">Student has not uploaded the resume</div></div>
										{% endif %}
									{% endwith %}
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>

		<br>
		<br>

		<div class="ui">
			<div class="ui large header center aligned brown">
				Applicant Details
			</div>
			<div class="ui divider"></div>
			
			<h3><u>Project Details</u></h3>
			<div class="ui segment fluid raised card">
				<div class="ui middle aligned selection divided list" style="margin-bottom: 0px;">
					<div class="item" style="padding-bottom: 0px;padding-top: 0px;background-color: rgb(0,0,0,0.03);">
						<div class="ui grid center aligned divided" style="margin-top: 0px;">
							<div class="four wide column ui tiny header">PROJECT TITLE</div>
							<div class="four wide column ui tiny header">PROGRAMMING LANGUAGES</div>
							<div class="six wide column ui tiny header">DESCRIPTION</div>
							<div class="two wide column ui tiny header">GITHUB</div>
						</div>

					</div>
					<div class="ui divider" style="margin-bottom: 0px;"></div>
				</div>
				<div class="ui middle aligned selection divided list" style="margin-top: 0px;">
					{% for project in application.student.get_project_details %}
						<div class="item">
							<div class="ui grid ">
								<div class="column four wide center aligned middle aligned"><div class="ui medium ">{{ project.title }}</div></div>
								<div class="column four wide center aligned middle aligned">
									<div class="ui">
										{% for language in project.languages %}
											<a class="ui tiny {% get_color language %} tag label">{{ language }}</a>
										{% endfor %}
									</div>
								</div>
								<div class="column six wide center aligned middle aligned">{{ project.description }}</div>
								<div class="column two wide center aligned middle aligned"><a href="{{ project.link }}">Link</a></div>
							</div>
						</div>
					{% endfor %}
				</div>
			</div>
			<br>
			<div class="ui center aligned"><h3><u>Educational Details</u></h3></div>
			<div class="ui segment fluid raised card">
				<div class="ui middle aligned selection divided list" style="margin-bottom: 0px;">
					<div class="item" style="padding-bottom: 0px;padding-top: 0px;background-color: rgb(0,0,0,0.03);">
						<div class="ui grid center aligned divided" style="margin-top: 0px;">
							<div class="four wide column ui tiny header">EXAMINATION</div>
							<div class="five wide column ui tiny header ">BOARD</div>
							<div class="four wide column ui tiny header">PERCENTAGE or CGPA</div>
							<div class="three wide column ui tiny header">YEAR</div>
						</div>

					</div>
					<div class="ui divider" style="margin-bottom: 0px;"></div>
				</div>
				<div class="ui middle aligned selection divided list" style="margin-top: 0px;">		
					{% for education in application.student.get_education_details %}
						<div class="item">
							<div class="ui grid">
								<div class="column four wide center aligned middle aligned"><div class="ui medium">{{ education.exam }}</div></div>
								<div class="column five wide center aligned middle aligned"><div class="ui medium ">{{ education.board }}</div></div>
								<div class="column four wide center aligned middle aligned"><div class="ui star yellow rating" data-rating="{% get_normalized_grades education.cgpa %}" data-max-rating="5"></div></div>
								<div class="column three wide center aligned middle aligned">{{ education.year }}</div>
							</div>
						</div>
					{% endfor %}
				</div>
			</div>
		</div>
	</div>
	<div class="actions">
		<div class="ui secondary right labeled deny icon button">
			Close
			<i class="times icon"></i>
		</div>
	</div>
</div>
{% endfor %}


{% for shortlistedApplications in ProjectWiseShortlistedApplications %}
	{% for application in shortlistedApplications %}
		<div id="application-{{ application.student.id }}-{{ application.project.id }}" class="ui long modal">
			<i class="close icon"></i>
			<div class="header">
				APPLICATION
			</div>
			<div class="content">
				<div class="ui grid">
					<div class="six wide column ui center aligned middle aligned" style="padding-top: 5rem;">
						<div class="ui medium image">
							<div class="ui large icon header">
								<i class="user circle massive grey icon"></i>
							</div>
						</div>
					</div>
					<div class="ten wide fluid column">
						<div class="ui image">

							<div class="ui large header center aligned brown">Application Details</div>
							<div class="ui divider"></div>
							<br>
							<div class="ui grid center aligned">
								<div class="six wide column">
									<div class="ui medium header left aligned">
										Application number	
									</div>	
								</div>
								<div class="two wide column">
									<div class="ui small header center aligned">
										: 	
									</div>	
								</div>
								<div class="five wide column">
									<div class="ui medium header center aligned grey">
										{{ application.student.id }}-{{ application.project.id }}	
									</div>	
								</div>
								<div class="six wide column">
									<div class="ui medium header left aligned">
										Applicant Name
									</div>	
								</div>
								<div class="two wide column">
									<div class="ui small header center aligned">
										: 	
									</div>	
								</div>
								<div class="five wide column">
									<div class="ui medium header center aligned grey">
										{{ application.student.student.get_full_name }}
									</div>	
								</div>

								
								<div class="six wide column">
									<div class="ui medium header left aligned">
										Email ID	
									</div>	
								</div>
								<div class="two wide column">
									<div class="ui small header center aligned">
										: 	
									</div>	
								</div>
								<div class="five wide column">
									<div class="ui medium header center aligned grey">
										{{ application.student.student.email }}
									</div>	
								</div>
								<div class="eleven wide column center aligned">
									<div class="ui icon info message">
										<i class="download icon"></i>
										<div class="content">
											<div class="header">
												Resume of the applicant 
											</div>
											{% with resume=application.student.get_resume_details %}
												{% if resume %}
													{% with 'resume-uploads/'|add:'/'|add:resume.file.file.name as image_static %}
														<div class="ui center aligned" ><a href="{% static image_static %}" target="_blank">Click me to download resume</a></div>
													{% endwith %}
												{% else %}
													<div class="ui center aligned" ><div style="color:slategrey;">Student has not uploaded the resume</div></div>
												{% endif %}
											{% endwith %}

										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>

				<br>
				<br>

				<div class="ui">
					<div class="ui large header center aligned brown">
						Applicant Details
					</div>
					<div class="ui divider"></div>
					
					<h3><u>Project Details</u></h3>
					<div class="ui segment fluid raised card">
						<div class="ui middle aligned selection divided list" style="margin-bottom: 0px;">
							<div class="item" style="padding-bottom: 0px;padding-top: 0px;background-color: rgb(0,0,0,0.03);">
								<div class="ui grid center aligned divided" style="margin-top: 0px;">
									<div class="four wide column ui tiny header">PROJECT TITLE</div>
									<div class="four wide column ui tiny header">PROGRAMMING LANGUAGES</div>
									<div class="six wide column ui tiny header">DESCRIPTION</div>
									<div class="two wide column ui tiny header">GITHUB</div>
								</div>

							</div>
							<div class="ui divider" style="margin-bottom: 0px;"></div>
						</div>
						<div class="ui middle aligned selection divided list" style="margin-top: 0px;">
							{% for project in application.student.get_project_details %}
								<div class="item">
									<div class="ui grid ">
										<div class="column four wide center aligned middle aligned"><div class="ui medium ">{{ project.title }}</div></div>
										<div class="column four wide center aligned middle aligned">
											<div class="ui">
												{% for language in project.languages %}
													<a class="ui tiny {% get_color language %} tag label">{{ language }}</a>
												{% endfor %}
											</div>
										</div>
										<div class="column six wide center aligned middle aligned">{{ project.description }}</div>
										<div class="column two wide center aligned middle aligned"><a href="{{ project.link }}">Link</a></div>
									</div>
								</div>
							{% endfor %}
						</div>
					</div>
					<br>
					<div class="ui center aligned"><h3><u>Educational Details</u></h3></div>
					<div class="ui segment fluid raised card">
						<div class="ui middle aligned selection divided list" style="margin-bottom: 0px;">
							<div class="item" style="padding-bottom: 0px;padding-top: 0px;background-color: rgb(0,0,0,0.03);">
								<div class="ui grid center aligned divided" style="margin-top: 0px;">
									<div class="four wide column ui tiny header">EXAMINATION</div>
									<div class="five wide column ui tiny header ">BOARD</div>
									<div class="four wide column ui tiny header">PERCENTAGE or CGPA</div>
									<div class="three wide column ui tiny header">YEAR</div>
								</div>

							</div>
							<div class="ui divider" style="margin-bottom: 0px;"></div>
						</div>
						<div class="ui middle aligned selection divided list" style="margin-top: 0px;">		
							{% for education in application.student.get_education_details %}
								<div class="item">
									<div class="ui grid">
										<div class="column four wide center aligned middle aligned"><div class="ui medium">{{ education.exam }}</div></div>
										<div class="column five wide center aligned middle aligned"><div class="ui medium ">{{ education.board }}</div></div>
										<div class="column four wide center aligned middle aligned"><div class="ui star yellow rating" data-rating="{% get_normalized_grades education.cgpa %}" data-max-rating="5"></div></div>
										<div class="column three wide center aligned middle aligned">{{ education.year }}</div>
									</div>
								</div>
							{% endfor %}
						</div>
					</div>
				</div>
			</div>
			<div class="actions">
				<div class="ui secondary right labeled deny icon button">
					Close
					<i class="times icon"></i>
				</div>
			</div>
		</div>
	{% endfor %}
{% endfor %}

{% for application in allotedStudents %}
<div id="application-{{ application.student.id }}-{{ application.project.id }}" class="ui long modal">
	<i class="close icon"></i>
	<div class="header">
		APPLICATION
	</div>
	<div class="content">
		<div class="ui grid">
			<div class="six wide column ui center aligned middle aligned" style="padding-top: 5rem;">
				<div class="ui medium image">
					<div class="ui large icon header">
						<i class="user circle massive grey icon"></i>
					</div>
				</div>
			</div>
			<div class="ten wide fluid column">
				<div class="ui image">

					<div class="ui large header center aligned brown">Application Details</div>
					<div class="ui divider"></div>
					<br>
					<div class="ui grid center aligned">
						<div class="six wide column">
							<div class="ui medium header left aligned">
								Application number	
							</div>	
						</div>
						<div class="two wide column">
							<div class="ui small header center aligned">
								: 	
							</div>	
						</div>
						<div class="five wide column">
							<div class="ui medium header center aligned grey">
								{{ application.student.id }}-{{ application.project.id }}	
							</div>	
						</div>
						<div class="six wide column">
							<div class="ui medium header left aligned">
								Applicant Name
							</div>	
						</div>
						<div class="two wide column">
							<div class="ui small header center aligned">
								: 	
							</div>	
						</div>
						<div class="five wide column">
							<div class="ui medium header center aligned grey">
								{{ application.student.student.get_full_name }}
							</div>	
						</div>

						
						<div class="six wide column">
							<div class="ui medium header left aligned">
								Email ID	
							</div>	
						</div>
						<div class="two wide column">
							<div class="ui small header center aligned">
								: 	
							</div>	
						</div>
						<div class="five wide column">
							<div class="ui medium header center aligned grey">
								{{ application.student.student.email }}
							</div>	
						</div>
						<div class="eleven wide column center aligned">
							<div class="ui icon info message">
								<i class="download icon"></i>
								<div class="content">
									<div class="header">
										Resume of the applicant
									</div>

									{% if application.student.resume.file %}
										{% with 'resume-uploads/'|add:'/'|add:application.student.resume.file.name as image_static %}
										<div class="ui center aligned" ><a href="{% static image_static %}" target="_blank">Click me to download resume</a></div>
										{% endwith %}
									{% else %}
										<div class="ui center aligned" ><div style="color:slategrey;">Student has not uploaded the resume</div></div>
									{% endif %}
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>

		<br>
		<br>

		<div class="ui">
			<div class="ui large header center aligned brown">
				Applicant Details
			</div>
			<div class="ui divider"></div>
			
			<h3><u>Project Details</u></h3>
			<div class="ui segment fluid raised card">
				<div class="ui middle aligned selection divided list" style="margin-bottom: 0px;">
					<div class="item" style="padding-bottom: 0px;padding-top: 0px;background-color: rgb(0,0,0,0.03);">
						<div class="ui grid center aligned divided" style="margin-top: 0px;">
							<div class="four wide column ui tiny header">PROJECT TITLE</div>
							<div class="four wide column ui tiny header">PROGRAMMING LANGUAGES</div>
							<div class="six wide column ui tiny header">DESCRIPTION</div>
							<div class="two wide column ui tiny header">GITHUB</div>
						</div>

					</div>
					<div class="ui divider" style="margin-bottom: 0px;"></div>
				</div>
				<div class="ui middle aligned selection divided list" style="margin-top: 0px;">
					{% for project in application.student.get_project_details %}
						<div class="item">
							<div class="ui grid ">
								<div class="column four wide center aligned middle aligned"><div class="ui medium ">{{ project.title }}</div></div>
								<div class="column four wide center aligned middle aligned">
									<div class="ui">
										{% for language in project.languages %}
											<a class="ui tiny {% get_color language %} tag label">{{ language }}</a>
										{% endfor %}
									</div>
								</div>
								<div class="column six wide center aligned middle aligned">{{ project.description }}</div>
								<div class="column two wide center aligned middle aligned"><a href="{{ project.link }}">Link</a></div>
							</div>
						</div>
					{% endfor %}
				</div>
			</div>
			<br>
			<div class="ui center aligned"><h3><u>Educational Details</u></h3></div>
			<div class="ui segment fluid raised card">
				<div class="ui middle aligned selection divided list" style="margin-bottom: 0px;">
					<div class="item" style="padding-bottom: 0px;padding-top: 0px;background-color: rgb(0,0,0,0.03);">
						<div class="ui grid center aligned divided" style="margin-top: 0px;">
							<div class="four wide column ui tiny header">EXAMINATION</div>
							<div class="five wide column ui tiny header ">BOARD</div>
							<div class="four wide column ui tiny header">PERCENTAGE or CGPA</div>
							<div class="three wide column ui tiny header">YEAR</div>
						</div>

					</div>
					<div class="ui divider" style="margin-bottom: 0px;"></div>
				</div>
				<div class="ui middle aligned selection divided list" style="margin-top: 0px;">		
					{% for education in application.student.get_education_details %}
						<div class="item">
							<div class="ui grid">
								<div class="column four wide center aligned middle aligned"><div class="ui medium">{{ education.exam }}</div></div>
								<div class="column five wide center aligned middle aligned"><div class="ui medium ">{{ education.board }}</div></div>
								<div class="column four wide center aligned middle aligned"><div class="ui star yellow rating" data-rating="{% get_normalized_grades education.cgpa %}" data-max-rating="5"></div></div>
								<div class="column three wide center aligned middle aligned">{{ education.year }}</div>
							</div>
						</div>
					{% endfor %}
				</div>
			</div>
		</div>
	</div>
	<div class="actions">
		<div class="ui secondary right labeled deny icon button">
			Close
			<i class="times icon"></i>
		</div>
	</div>
</div>
{% endfor %}


<div id="new-position" class="ui long modal">
	<i class="close icon"></i>
	<div class="header">
		NEW POSITION
	</div>
	<div class="content">
		<form class="ui form" id="new-position-form" method="POST">
			{% csrf_token %}
			<div class="two fields">
				<div class="twelve wide field">
					<label>{{ newPosition.title.label }}</label>
					{{ newPosition.title }}
				</div>
				<div class="four wide field">
					<label>{{ newPosition.total_positions.label }}</label>
					{{ newPosition.total_positions }}
				</div>
			</div>
			<div class="field">
				<label>{{ newPosition.contact_details.label }}</label>
				{{ newPosition.contact_details }}
			</div>
			<div class="field">
				<label>{{ newPosition.description.label }}</label>
				{{ newPosition.description }}
			</div>
			<div class="field">
				<label>Requisites</label>
				<div class="requisitesList">
					<table style="width: 100%;">
						<thead>
							<tr>
								<th class="col-3">Subject</th>
								<th>CGPA</th>
							</tr>
						</thead>
						<tbody class='requisites'>
							{% for form in requisitesForm %}
							<tr id="{{ form.prefix }}-row" class="requisites-form">
								<td>{{ form.Subject }}</td>
								<td>{{ form.cgpa }}</td>
								<td>
									<a id="remove-{{ form.prefix }}-delete" name="remove-{{ form.prefix }}-delete" href="javascript:void(0)" class="delete-row" onclick="deleterequisitesForm(this,'{{ form.prefix }}')">Delete</a>
								</td>
							</tr>
							{% endfor %}
						</tbody>
						<tfoot>
							<tr>
								<td colspan ="2"><a href="javascript:void(0)" class="add-row" onclick="addRequesiteForm()">Add another</a></td>
							</tr>
						</tfoot>
					</table>
					{{ requisitesForm.management_form }}
				</div>
			</div>
		</form>
	</div>
	<div class="actions">
			<button class="ui black button" type="reset" form="new-position-form">
				Reset
			</button>
			<button class="ui positive right labeled icon button" type="submit" form="new-position-form">
				Submit
				<i class="checkmark icon"></i>
			</button>
	</div>
</div>

<div id="updateforms">
{% for updateform in updateforms %}
<div id="update-position-{{ forloop.counter0 }}" class="ui long modal">
	<i class="close icon"></i>
	<div class="header">
		NEW POSITION
	</div>
	<div class="content">
		<form class="ui form" id="update-position-form-{{ forloop.counter0 }}" method="POST">
			{% csrf_token %}
			 <input type="hidden" id="id_positionId" name="positionId" value="{{ updateform.instance.id }}">
			<div class="two fields">
				<div class="twelve wide field">
					<label>{{ updateform.title.label }}</label>
					{{ updateform.title }}
				</div>
				<div class="four wide field">
					<label>{{ updateform.total_positions.label }}</label>
					{{ updateform.total_positions }}
				</div>
			</div>
			<div class="field">
				<label>{{ updateform.contact_details.label }}</label>
				{{ updateform.contact_details }}
			</div>
			<div class="field">
				<label>{{ updateform.description.label }}</label>
				{{ updateform.description }}
			</div>
			<div class="field">
				<label>Requisites</label>
				<div class="requisitesList">
					<table style="width: 100%;">
						<thead>
							<tr>
								<th class="col-3">Subject</th>
								<th>CGPA</th>
							</tr>
						</thead>
						{% with updaterequisiteform=updaterequisiteforms|index:forloop.counter0 %}
						<tbody class='update-requisites'>
							{% for form in updaterequisiteform %}
							<tr id="update-{{ form.prefix }}-row" class="update-requisites-form">
								<td>{{ form.Subject }}</td>
								<td>{{ form.cgpa }}</td>
								<td>
									<a id="remove-update-{{ form.prefix }}-delete" name="remove-update-{{ form.prefix }}-delete" href="javascript:void(0)" class="delete-row" onclick="deleteupdaterequisitesForm(this,'#update-position-form-{{ forloop.parentloop.counter0 }}',{% if form.id.value is not None %}true{% else %}false{% endif %})">Delete</a>
								</td>
								{% if form.id.value is not None %}
								{% for hidden in form.hidden_fields %}
						        	{{ hidden }}
						    	{% endfor %}
					    	{% endif %}
							</tr>
							{% endfor %}
						</tbody>
						<tfoot>
							<tr>
								{{ updaterequisiteform.management_form }}
								<td colspan ="2"><a href="javascript:void(0)" class="update-add-row" onclick="addUpdateRequesiteForm('#update-position-form-{{ forloop.counter0 }}')">Add another</a></td>
							</tr>
						</tfoot>
						{% endwith %}
					</table>
				</div>
			</div>
		</form>
	</div>
	<div class="actions">
			<button class="ui black button" type="reset" form="update-position-form-{{ forloop.counter0 }}">
				Reset
			</button>
			<button class="ui positive right labeled icon button" type="submit" form="update-position-form-{{ forloop.counter0 }}">
				Submit
				<i class="checkmark icon"></i>
			</button>
	</div>
</div>
{% endfor %}
</div>


{% endblock %}



{% block scripts %}
	
$(document).ready(function() {
	window.requisitesformCount = parseInt($('#new-position #id_requisites-TOTAL_FORMS').val());
	window.requisitesformInst = $('.requisites-form:first').clone(true).get(0);
	window.updaterequisitesformInst = $('.update-requisites-form:last').clone(true).get(0);
	window.requisitesPrefix = 'requisites-';
	window.updaterequisitePrefix = 'update-requisites-'
	$('#time-progress').progress();
	$(".rating").rating('disable');
	$('.menu .item').tab();
	$('.date_picker').calendar({
	type: 'date',
	 minDate: new Date(),
	formatter: {
      date: function (date, settings) {
        if (!date) return '';
        var day = date.getDate();
        var month = date.getMonth() + 1;
        var year = date.getFullYear();
        return year + '-' + month + '-' + day;
      }
    }
	});
	$( function() {
	{% for projects in ProjectWiseShortlistedApplications %}
		$( "#sortable-{{ forloop.counter0 }}" ).sortable();
		$( "#sortable-{{ forloop.counter0 }}" ).disableSelection();
	{% endfor %}
	});
	$('#applications').DataTable({
		columnDefs: [ { orderable: false, targets: [4] } ],
	});
	{% if user_type == 'facad' %}
	$('#generatedAllotments').DataTable({
	});
	{% endif %}
	$('.ui.dropdown').dropdown();
	sync_total_forms();
	{% if messages %}
		{% for message in messages %}
			$('body')
			.toast({
			  class: "error",
			  title: "Error logging in",
			  displayTime: 3000,
			  closeIcon: true,
			  position: "top center",
			  showIcon: "exclamation",
			  message: '{{ message }}',
			});
		{% endfor %}
	{% endif %}
	{% if user_type == 'facad' %}
		render_stats_tab();
	{% endif %}
} );

{% if user_type == 'facad' %}
function render_stats_tab(){
	var lineChartData = {
			labels: [ {% for round in roundDetails %}'Round {{ round.roundNo }}', {% endfor %}],
			datasets: [{
				label: 'Allotted Students',
				borderColor: 'rgb(255, 99, 132)',
				backgroundColor: 'rgb(255, 99, 132)',
				fill: false,
				data: [{% for round in roundDetails %}{% if forloop.counter != roundDetails|length %}{{ round.allocated }}, {% endif %}{% endfor %}],
			},
			{
				label: 'Unallotted Students',
				borderColor: 'rgb(132, 99, 255)',
				backgroundColor: 'rgb(132, 99, 255)',
				fill: false,
				data: [ {% for round in roundDetails %}{% if forloop.counter != roundDetails|length %}{{ round.unallocated }}, {% endif %}{% endfor %} ],
			}]
		};
	var ctx = document.getElementById('alloted-unalloted').getContext('2d');
	myLine = new Chart(ctx, {
		type: 'line',
		data: lineChartData,
		options: {
					responsive: true,
					interaction: {
						mode: 'index'
					},
					stacked: false,
					title: {
						display: false,
					},
					scales: {
						yAxes: [{
					      scaleLabel: {
					        display: true,
					        labelString: 'Cumulative number of Students'
					      } 
					    }]						
					},
				}
	});

	var facultyallocationData = {
			labels: ['Faculty 1', 'Faculty 2', 'Faculty 3', 'Faculty 4', 'Faculty 5'],
			datasets: [{
				data: [10,15,20,22,23],
				backgroundColor:['red','orange','teal','green','blue'],
			}]
		};
	var ctx = document.getElementById('faculty-allocation').getContext('2d');
	myLine = new Chart(ctx, {
		type: 'doughnut',
		data: facultyallocationData,
		options: {
					responsive: true,
					interaction: {
						mode: 'index'
					},
					title: {
						display: false,
					},
					animation: {
						animateScale: true,
						animateRotate: true
					},
				}
	});

	var facultyunallocationData = {
			labels: ['Faculty 1', 'Faculty 2', 'Faculty 3', 'Faculty 4', 'Faculty 5'],
			datasets: [{
				data: [10,15,20,22,23],
				backgroundColor:['red','orange','teal','green','blue'],
			}]
		};
	var ctx = document.getElementById('faculty-unallocation').getContext('2d');
	myLine = new Chart(ctx, {
		type: 'doughnut',
		data: facultyunallocationData,
		options: {
					responsive: true,
					interaction: {
						mode: 'index'
					},
					title: {
						display: false,
					},
					animation: {
						animateScale: true,
						animateRotate: true
					},
				}
	});
}

function show_round_detail_form(){
	$('.latest-round-detail').hide();
	$('.latest-round-form').show();
}
{% endif %}


function sync_total_forms(){
	$('#updateforms .requisitesList').each(function(){
		$(this).find('#id_requisites-TOTAL_FORMS').val($(this).find('.update-requisites-form').length);
	});
}

function show_student_detail(id){
	$(".modals #application-"+id).modal('show');
}

function show_update_form(id){
	$(".modals #update-position-"+id).modal('show');
}

function show_new_position_form(){
	$(".modals #new-position").modal('show');
}

function updateElementIndex(row,index) {
	$(row).children().children().each(function(){
		curr_id = $(this).attr('id');
		if(curr_id==null){
			curr_id = $(this).find('select').attr('id');
			new_id = curr_id.replace(/[0-9]+/gi,index);
			$(this).find('select').attr('id',new_id);
			curr_name = $(this).find('select').attr('name');
			new_name = curr_name.replace(/[0-9]+/gi,index);
			$(this).find('select').attr('name',new_name);
		}
		else{
			new_id = curr_id.replace(/[0-9]+/gi,index);
			$(this).attr('id',new_id);
			curr_name = $(this).attr('name');
			new_name = curr_name.replace(/[0-9]+/gi,index);
			$(this).attr('name',new_name);
		}
	});
}

function addRequesiteForm(){
	var row = $(window.requisitesformInst).clone(true);
	requisitesformCount = parseInt($('#new-position #id_requisites-TOTAL_FORMS').val());
	$(row).find(".ui.dropdown").dropdown();
	if(requisitesformCount == 0){
		$('#new-position .requisites ').html(row);
	}
	else{
		$(row).attr('id',window.requisitesPrefix+requisitesformCount+'-row').insertAfter($('#new-position  .requisites-form:last'));
		var forms = $('#new-position  .requisites-form');
		$(forms).each(function(index){
			updateElementIndex(this,index);
		});
	}
	$(row).find('.delete-row').attr('onclick','deleterequisitesForm(this,"'+window.requisitesPrefix+requisitesformCount+'")');
	$('#new-position #id_requisites-TOTAL_FORMS').val(requisitesformCount+1);
	
	return false;
}

function deleterequisitesForm(btn){
	$(btn).parents('.requisites-form').remove();
	var forms = $('#new-position .requisites-form');
	requisitesformCount = parseInt($('#new-position #id_requisites-TOTAL_FORMS').val());
	$('#new-position #id_requisites-TOTAL_FORMS').val(requisitesformCount-1);
	$(forms).each(function(index){
		$(this).attr('id',window.requisitesPrefix+index+'-row');
		updateElementIndex(this,index);
	});

	return false;
}

function addUpdateRequesiteForm(id){
	var row = $(window.updaterequisitesformInst).clone(true);
	requisitesformCount = parseInt($(id + ' #id_requisites-TOTAL_FORMS').val());
	$(row).find(".ui.dropdown").dropdown();
	if(requisitesformCount == 0){
		$(id+' .update-requisites ').html(row);
	}
	else{
		$(row).attr('id',window.updaterequisitePrefix+requisitesformCount+'-row').insertAfter($(id +' .update-requisites-form:last'));
		var forms = $(id + ' .update-requisites-form');
		$(forms).each(function(index){
			updateElementIndex(this,index);
		});
	}
	$(row).find('.delete-row').attr('onclick','deleteupdaterequisitesForm(this,"'+String(id)+'")');
	$(id + ' #id_requisites-TOTAL_FORMS').val(requisitesformCount+1);
	
	return false;
}

function deleteupdaterequisitesForm(btn,id,filled_row){
	if(filled_row){
		count = $(id + ' #id_requisites-INITIAL_FORMS').val();
		$(id + ' #id_requisites-INITIAL_FORMS').val(parseInt(count)-1);
	}
	$(btn).parents('.update-requisites-form').remove();
	var forms = $(id + ' .update-requisites-form');
	requisitesformCount = parseInt($(id + ' #id_requisites-TOTAL_FORMS').val());
	$(id + ' #id_requisites-TOTAL_FORMS').val(requisitesformCount-1);
	$(forms).each(function(index){
		$(this).attr('id',window.updaterequisitePrefix+index+'-row');
		updateElementIndex(this,index);
	});
	return false;
}

function submit_priorities(index,projectId){
	$.ajax({
          type: 'POST',
          url: '{% url "gap:updatePriorities" %}',
          data: {
            user: 'faculty',
            projectId: String(projectId),
            priorities: JSON.stringify({'priority_list':$('#sortable-'+String(index)+' .applied-student-id').map(function(){return $(this).val()}).get()}),
            csrfmiddlewaretoken: '{{ csrf_token }}',
        },
        success: function (json) {
            $('body')
			.toast({
			  class: "success",
			  title: "Priority Updation for "+json["title"],
			  displayTime: 3000,
			  closeIcon: true,
			  position: "top center",
			  showIcon: "check",
			  message: json["successMessage"],
			  className: {
			        toast: 'ui icon message'
			    }
			});
        },
        error: function (error) {
        error_message = error["responseJSON"]["detail"];
        $('body')
			.toast({
			  class: "red",
			  title: "Error updating priorities for <b>" + error["responseJSON"]["title"]+"</b>",
			  displayTime: 5000,
			  closeIcon: true,
			  position: "top center",
			  showIcon: "exclamation",
			  message: error_message,
			  className: {
			        toast: 'ui message'
			    }
			});
        }
    });
}


{% endblock %}