<commit_before>define(['utils', 'server'], 
function(Utils, Server){
	
	Classes = {};
	
	Classes.init = function(){
		switch(Utils.getCurrentUser().role){
		case "FEDERATION_ADMIN":
			break;
		case "NODE_ADMIN":
			break;
		case "CLASSOWNER":
			initClassownerClassesAside();
			initCreateClassPage();
			initCreateTaskPage();
			break;
		default:
			createStudentJoinClassPages();
			createAllStudentTaskPages();
			initStudentClassesAside();
			initStudentJoinClass(false);
		}
	};
	
	initCreateClassPage = function(){
		initNodeDropdown();
		initCreateBtn();
	};
	
	var currentClassId = 0;
	
	initCreateTaskPage = function(){
		$("#createTaskBtn").on("click",function(){
			var newTask = new Object();
			//TODO: check inputs
			newTask.name = $("#inputTaskName").val();
			newTask.description = $("#inputTaskDescription").val();
			
			newTask.id = Server.addTask(currentClassId, newTask);
			
			var taskLink = $("<li>").append($("<a>").attr("href","#classownerTask"+newTask.id).append($("<i>").addClass("fa fa-minus fa-li"), newTask.name).on("click",function(e){
				e.preventDefault();
				openDesktopTab("#classownerTask"+newTask.id);
				//TODO: create this task page
			}));
			
			$("#"+currentClassId+"TaskList").prepend(taskLink);
			
			$("#inputTaskName").val('');
			$("#inputTaskDescription").val('');
		});
	};
	
	initNodeDropdown = function(){
		var nodes = Server.getAllNodes();
		
		$.each(nodes, function(i, node) {
			var nodeItem = $("<li>").append($("<a>").attr("tabindex",-1).html(node.name).on("click",function(){
				var nodeDiv = "";
				var deleteBtn = $("<button>").addClass("btn span4").html("Delete").on("click",function(){
					nodeDiv.remove();
				});
				nodeDiv = $("<div>").addClass("span12 nomargin").append("<span class='span8'>"+node.name+" </span>",deleteBtn).val(node.id);
				$("#addedNodes").append(nodeDiv);
			}));
			$("#availableNodes").append(nodeItem);
		});
	};
	
	initCreateBtn = function(){
		$("#createClassBtn").on("click",function(){
			var newClass = new Object();
			newClass.name = $("#className").val();
			newClass.description = $("#classDescripion").val();
			newClass.owner = Utils.getCurrentUser();
			newClass.nodes = [];
			$.each($("#addedNodes").children(), function(i, nodeItem) {
				var node = new Object();
				node.name = nodeItem.children[0].innerHTML;
				node.id = nodeItem.value;
				newClass.nodes.push(node);
			});
			
			newClass.id = Server.createClass(newClass);
			
			createClassownerClassForAsideList(newClass);
			
			createClassParticipantsPage(newClass);
			createClassResourcesPage(newClass);
			
			$("#className").val('');
			$("#classDescripion").val('');
			$("#addedNodes").empty();
			initCollapseHeaders();
			openDesktopTab("#class"+newClass.id+"_participants");
		});
	};
	
	createClassParticipantsPage = function(newClass){
		var title = $("<div>").append($("<h3>").html(newClass.name),"<hr/>");
		var header = $("<h4>").html("Participants");
		var tableheader = $("<tr>").append($("<td>"),$("<td>"),$("<td>"),$("<td>").html("Task 1"),$("<td>").html("Task 2"),$("<td>").html("Task 3"));
		var participants = $("<div>").append($("<table>").attr("id","class"+newClass.id+"ParticipantsTable").append(tableheader));
		
		var addheader = $("<h4>").html("Add participant");
		var ul = $('<ul>').addClass("dropdown-menu");
		
		var participantsUsernames = [];
		if(newClass.participants != null){
			$.each(newClass.participants, function(i, user) {
				participantsUsernames.push(user.username);
			});
		}
		var currentlyChosenUser = null;
		var allUsers = Utils.getAllUsers();
		$.each(allUsers, function(i, user) {
			if(user.role == "STUDENT" && ($.inArray(user.username, participantsUsernames) == -1)){
				var userdropdownOption = $("<li>").append($('<a>').attr("tabindex",-1).html(user.username).on('click',function(){
					currentlyChosenUser = user;
					$("#usersDropdown"+newClass.id).html("<b>"+user.username+"</b> ("+user.firstName+" "+user.lastName+")");
				}));
				ul.append(userdropdownOption);
			}
		});
		var dropdown = $("<div>").addClass("dropdown").attr("style","margin-bottom:"+25*allUsers.length+"px");
		dropdown.append("<button class='btn dropdown-toggle' type='button' id='usersDropdown"+newClass.id+"' data-toggle='dropdown'>Available users</button>");
		var addBtn = $("<button>").addClass("btn margin3").html("Add").on('click',function(){
			if(currentlyChosenUser != null){
				createParticipantRow(newClass.id,currentlyChosenUser);
				Server.addParticipant(newClass.id, currentlyChosenUser.username);
				currentlyChosenUser = null;
			}
		});
		dropdown.append(ul,addBtn);
		var addParticipant = $("<div>").append(addheader,dropdown);
		
		var page = $("<div>").attr("id","class"+newClass.id+"_participants").addClass("row-fluid tab-pane").append(title,header,participants,"<hr>",addParticipant);
		$("#desktop").append(page);
		
		if(newClass.participants != null){
			$.each(newClass.participants, function(i, user) {
				createParticipantRow(newClass.id,user);
			});
		}
	};
	
	createParticipantRow = function(classid,user){
		var deleteUserBtn = $("<td>").append($("<a>").addClass("margin3 btn").html("Delete").on('click',function(){
			if(Server.deleteParticipant(classid, user.username) == "success"){
				row.remove();
			}			
		}));
		var detailsBtn = $("<td>").append($("<a>").addClass("margin3 btn").html("Details").on('click',function(){
			Utils.showUserModal(Server.getUser(user.username));			
		}));
		
		var row = $("<tr>").append("<td><b>"+user.username+"</b> ("+user.firstName+" "+user.lastName+")</td>",detailsBtn,deleteUserBtn,"<td class='centered'><i class='fa fa-square-o fa-lg'></i></td>","<td class='centered'><i class='fa fa-square-o fa-lg'></i></td>","<td class='centered'><i class='fa fa-square-o fa-lg'></i></td>");
		$("#class"+classid+"ParticipantsTable").append(row);
	};
	
	createClassResourcesPage = function(newClass){
		var title = $("<div>").append($("<h3>").html(newClass.name),"<hr/>");
		var header = $("<h4>").html("Topology of the resources");
		
		var page = $("<div>").attr("id","class"+newClass.id+"_resources").addClass("row-fluid tab-pane").append(title,header);
		$("#desktop").append(page);
	};
	
	createClassownerClassForAsideList = function(newClass){
		var name = $("<a>").append($("<i>").addClass("collapseSign fa fa-caret-right fa-li"),newClass.name);
		var header = $("<div>").addClass("collapseHeader").attr("data-toggle","collapse").attr("data-target","#"+newClass.id+"Options").append(name);
		
		var participantsLink = $("<li>").append($("<a>").attr("href","#class"+newClass.id+"_participants").append($("<i>").addClass("fa fa-minus fa-li"),"Participants").on("click",function(e){
			e.preventDefault();
			openDesktopTab("#class"+newClass.id+"_participants");
		}));
		var resourcesLink = $("<li>").append($("<a>").attr("href","#class"+newClass.id+"_resources").append($("<i>").addClass("fa fa-minus fa-li"),"Resources").on("click",function(e){
			e.preventDefault();
			openDesktopTab("#class"+newClass.id+"_resources");
		}));
		
		var tasksHeaderLink = $("<a>").attr("id","tasksToggle").append($("<i>").addClass("collapseSign fa fa-caret-right fa-li"),"Tasks");
		var tasksHeader = $("<div>").addClass("collapseHeader").attr("data-toggle","collapse").attr("data-target","#"+newClass.id+"Tasks").append(tasksHeaderLink);
		var createTaskLink = $("<li>").append($("<a>").attr("href","#createtask").append($("<i>").addClass("fa fa-plus fa-li"),"Create task").on("click",function(e){
			e.preventDefault();
			currentClassId = newClass.id;
			openDesktopTab("#createtask");
		}));
		
		var tasks = $("<ul>").addClass("navigationLink fa-ul").attr("id",newClass.id+"TaskList").append(createTaskLink);
		
		if(newClass.tasks != null){
			$.each(newClass.tasks, function(i, task) {		
				var taskLink = $("<li>").append($("<a>").attr("href","#classownerTask"+task.id).append($("<i>").addClass("fa fa-minus fa-li"), task.name).on("click",function(e){
					e.preventDefault();
					openDesktopTab("#classownerTask"+task.id);
					//TODO: create this task page
				}));
				tasks.prepend(taskLink);
			});
		}
		var tasksList =  $("<div>").attr("id",newClass.id+"Tasks").addClass("row-fluid collapse out").append(tasks);
		var tasksToggle = $("<li>").append(tasksHeader,tasksList);
		<commit_msg>simple input checking for new tasks<commit_after>define(['utils', 'server'], 
function(Utils, Server){
	
	Classes = {};
	
	Classes.init = function(){
		switch(Utils.getCurrentUser().role){
		case "FEDERATION_ADMIN":
			break;
		case "NODE_ADMIN":
			break;
		case "CLASSOWNER":
			initClassownerClassesAside();
			initCreateClassPage();
			initCreateTaskPage();
			break;
		default:
			createStudentJoinClassPages();
			createAllStudentTaskPages();
			initStudentClassesAside();
			initStudentJoinClass(false);
		}
	};
	
	initCreateClassPage = function(){
		initNodeDropdown();
		initCreateBtn();
	};
	
	var currentClassId = 0;
	
	initCreateTaskPage = function(){
		$("#createTaskBtn").on("click",function(){
			var newTask = new Object();
			newTask.name = $("#inputTaskName").val();
			newTask.description = $("#inputTaskDescription").val();
			
			if(newTask.name == null || newTask.name.length < 1){
				alert("Please enter a task name!");
				return;
			}
			if(newTask.description == null || newTask.description.length < 1){
				alert("Please enter a task description!");
				return;
			}
			
			newTask.id = Server.addTask(currentClassId, newTask);
			
			var taskLink = $("<li>").append($("<a>").attr("href","#classownerTask"+newTask.id).append($("<i>").addClass("fa fa-minus fa-li"), newTask.name).on("click",function(e){
				e.preventDefault();
				openDesktopTab("#classownerTask"+newTask.id);
				//TODO: create this classowner task page
			}));
			
			$("#"+currentClassId+"TaskList").prepend(taskLink);
			
			$("#inputTaskName").val('');
			$("#inputTaskDescription").val('');
		});
	};
	
	initNodeDropdown = function(){
		var nodes = Server.getAllNodes();
		
		$.each(nodes, function(i, node) {
			var nodeItem = $("<li>").append($("<a>").attr("tabindex",-1).html(node.name).on("click",function(){
				var nodeDiv = "";
				var deleteBtn = $("<button>").addClass("btn span4").html("Delete").on("click",function(){
					nodeDiv.remove();
				});
				nodeDiv = $("<div>").addClass("span12 nomargin").append("<span class='span8'>"+node.name+" </span>",deleteBtn).val(node.id);
				$("#addedNodes").append(nodeDiv);
			}));
			$("#availableNodes").append(nodeItem);
		});
	};
	
	initCreateBtn = function(){
		$("#createClassBtn").on("click",function(){
			var newClass = new Object();
			newClass.name = $("#className").val();
			newClass.description = $("#classDescripion").val();
			newClass.owner = Utils.getCurrentUser();
			newClass.nodes = [];
			$.each($("#addedNodes").children(), function(i, nodeItem) {
				var node = new Object();
				node.name = nodeItem.children[0].innerHTML;
				node.id = nodeItem.value;
				newClass.nodes.push(node);
			});
			
			newClass.id = Server.createClass(newClass);
			
			createClassownerClassForAsideList(newClass);
			
			createClassParticipantsPage(newClass);
			createClassResourcesPage(newClass);
			
			$("#className").val('');
			$("#classDescripion").val('');
			$("#addedNodes").empty();
			initCollapseHeaders();
			openDesktopTab("#class"+newClass.id+"_participants");
		});
	};
	
	createClassParticipantsPage = function(newClass){
		var title = $("<div>").append($("<h3>").html(newClass.name),"<hr/>");
		var header = $("<h4>").html("Participants");
		var tableheader = $("<tr>").append($("<td>"),$("<td>"),$("<td>"),$("<td>").html("Task 1"),$("<td>").html("Task 2"),$("<td>").html("Task 3"));
		var participants = $("<div>").append($("<table>").attr("id","class"+newClass.id+"ParticipantsTable").append(tableheader));
		
		var addheader = $("<h4>").html("Add participant");
		var ul = $('<ul>').addClass("dropdown-menu");
		
		var participantsUsernames = [];
		if(newClass.participants != null){
			$.each(newClass.participants, function(i, user) {
				participantsUsernames.push(user.username);
			});
		}
		var currentlyChosenUser = null;
		var allUsers = Utils.getAllUsers();
		$.each(allUsers, function(i, user) {
			if(user.role == "STUDENT" && ($.inArray(user.username, participantsUsernames) == -1)){
				var userdropdownOption = $("<li>").append($('<a>').attr("tabindex",-1).html(user.username).on('click',function(){
					currentlyChosenUser = user;
					$("#usersDropdown"+newClass.id).html("<b>"+user.username+"</b> ("+user.firstName+" "+user.lastName+")");
				}));
				ul.append(userdropdownOption);
			}
		});
		var dropdown = $("<div>").addClass("dropdown").attr("style","margin-bottom:"+25*allUsers.length+"px");
		dropdown.append("<button class='btn dropdown-toggle' type='button' id='usersDropdown"+newClass.id+"' data-toggle='dropdown'>Available users</button>");
		var addBtn = $("<button>").addClass("btn margin3").html("Add").on('click',function(){
			if(currentlyChosenUser != null){
				createParticipantRow(newClass.id,currentlyChosenUser);
				Server.addParticipant(newClass.id, currentlyChosenUser.username);
				currentlyChosenUser = null;
			}
		});
		dropdown.append(ul,addBtn);
		var addParticipant = $("<div>").append(addheader,dropdown);
		
		var page = $("<div>").attr("id","class"+newClass.id+"_participants").addClass("row-fluid tab-pane").append(title,header,participants,"<hr>",addParticipant);
		$("#desktop").append(page);
		
		if(newClass.participants != null){
			$.each(newClass.participants, function(i, user) {
				createParticipantRow(newClass.id,user);
			});
		}
	};
	
	createParticipantRow = function(classid,user){
		var deleteUserBtn = $("<td>").append($("<a>").addClass("margin3 btn").html("Delete").on('click',function(){
			if(Server.deleteParticipant(classid, user.username) == "success"){
				row.remove();
			}			
		}));
		var detailsBtn = $("<td>").append($("<a>").addClass("margin3 btn").html("Details").on('click',function(){
			Utils.showUserModal(Server.getUser(user.username));			
		}));
		
		var row = $("<tr>").append("<td><b>"+user.username+"</b> ("+user.firstName+" "+user.lastName+")</td>",detailsBtn,deleteUserBtn,"<td class='centered'><i class='fa fa-square-o fa-lg'></i></td>","<td class='centered'><i class='fa fa-square-o fa-lg'></i></td>","<td class='centered'><i class='fa fa-square-o fa-lg'></i></td>");
		$("#class"+classid+"ParticipantsTable").append(row);
	};
	
	createClassResourcesPage = function(newClass){
		var title = $("<div>").append($("<h3>").html(newClass.name),"<hr/>");
		var header = $("<h4>").html("Topology of the resources");
		
		var page = $("<div>").attr("id","class"+newClass.id+"_resources").addClass("row-fluid tab-pane").append(title,header);
		$("#desktop").append(page);
	};
	
	createClassownerClassForAsideList = function(newClass){
		var name = $("<a>").append($("<i>").addClass("collapseSign fa fa-caret-right fa-li"),newClass.name);
		var header = $("<div>").addClass("collapseHeader").attr("data-toggle","collapse").attr("data-target","#"+newClass.id+"Options").append(name);
		
		var participantsLink = $("<li>").append($("<a>").attr("href","#class"+newClass.id+"_participants").append($("<i>").addClass("fa fa-minus fa-li"),"Participants").on("click",function(e){
			e.preventDefault();
			openDesktopTab("#class"+newClass.id+"_participants");
		}));
		var resourcesLink = $("<li>").append($("<a>").attr("href","#class"+newClass.id+"_resources").append($("<i>").addClass("fa fa-minus fa-li"),"Resources").on("click",function(e){
			e.preventDefault();
			openDesktopTab("#class"+newClass.id+"_resources");
		}));
		
		var tasksHeaderLink = $("<a>").attr("id","tasksToggle").append($("<i>").addClass("collapseSign fa fa-caret-right fa-li"),"Tasks");
		var tasksHeader = $("<div>").addClass("collapseHeader").attr("data-toggle","collapse").attr("data-target","#"+newClass.id+"Tasks").append(tasksHeaderLink);
		var createTaskLink = $("<li>").append($("<a>").attr("href","#createtask").append($("<i>").addClass("fa fa-plus fa-li"),"Create task").on("click",function(e){
			e.preventDefault();
			currentClassId = newClass.id;
			openDesktopTab("#createtask");
		}));
		
		var tasks = $("<ul>").addClass("navigationLink fa-ul").attr("id",newClass.id+"TaskList").append(createTaskLink);
		
		if(newClass.tasks != null){
			$.each(newClass.tasks, function(i, task) {		
				var taskLink = $("<li>").append($("<a>").attr("href","#classownerTask"+task.id).append($("<i>").addClass("fa fa-minus fa-li"), task.name).on("click",function(e){
					e.preventDefault();
					openDesktopTab("#classownerTask"+task.id);
					//TODO: create this classowner task page
				}));
				tasks.prepend(taskLink);
			});
		}
		var tasksList =  $("<div>").attr("id",newClass.id+"Tasks").addClass("row-fluid collapse out").append(tasks);
		var tasksToggle = $("<li>").append(tasksHeader,tasksList);
		
{'fraction_non_alphanumeric': 0.23807260412334383, 'fraction_numerical': 0.002733052106232547, 'mean_word_length': 5.434250764525994, 'pattern_counts': {'":': 6, '<': 169, '<?xml version=': 0, '>': 167, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1529316', 'n_tokens_mistral': 6230, 'n_tokens_neox': 5409, 'n_words': 706}