<commit_before>$(document).ready(function() {
	//add close for all actions
	$('#popup').on('click', '#close', function(event) {
		$('#popup').hide();
		event.preventDefault();
	});
	
	//add
	$('#controlsAdd').click(function(event) {
		$.ajax({
			url: 'ajax.php',
			type: 'POST',
			data: {
				'action': 'add',
				'type': 'employee'
			}
		}).done(function(data) {
			$('#popup > div').html(data.html);
			$('#popup').show();
			
			$('#addBtn').click(function() {
				var ajaxData = $('#popup input[type!="checkbox"], #popup select').serializeArray();
				ajaxData.push({'name': 'action', 'value': 'addSave'});
				ajaxData.push({'name': 'type', 'value': 'employee'});
				$.ajax({
					url: 'ajax.php',
					type: 'POST',
					data: ajaxData
				}).done(function(data) {
				});
			});
		});
		event.preventDefault();
	});
	
	//edit
	$('#controlsEdit').click(function(event) {
		if ($('#controlsEdit').hasClass('controlsEditEnabled')) {
			var ajaxData;
			if ($('.selectCheckbox:checked').length == 0) {
				ajaxData = {'action': 'edit', 'type': 'employee', 'id': id};
			}
			else if ($('.selectCheckbox:checked').length == 1) {
				ajaxData = {'action': 'edit', 'type': 'employee', 'id': $('.selectCheckbox:checked').attr('id')};
			}
			else {
				ajaxData = {'action': 'editMany', 'type': 'employee'};
			}
			$.ajax({
				url: 'ajax.php',
				type: 'POST',
				data: ajaxData
			}).done(function(data) {
				$('#popup > div').html(data.html);
				$('#popup').show();
				if (ajaxData.action == 'editMany') {
					$('#popup input[type="checkbox"]').click(function() {
						$(this).next().next().prop('disabled', !$(this).prop('checked'));
					});
				}
				
				$('#editBtn').click(function() {
					var selectedIDs = $('.selectCheckbox:checked')
						.map(function() { return this.id; })
						.get();
					var action = ($('.selectCheckbox:checked').length > 1) ? 'editMany' : 'edit';
					ajaxData = {'action': action, 'type': 'employee', 'id': selectedIDs};
				});
			});
		}
		event.preventDefault();
	});
	
	//delete
	$('#controlsDelete').click(function(event) {
		if ($('#controlsDelete').hasClass('controlsDeleteEnabled')) {
			$.ajax({
				url: 'ajax.php',
				type: 'POST',
				data: {
					'action': 'delete',
					'type': 'employee'
				}
			}).done(function(data) {
				$('#popup > div').html(data.html);
				$('#popup').show();
			});<commit_msg>Added creating, updating and deleting items.<commit_after>$(document).ready(function() {
	//add close for all actions
	$('#popup').on('click', '#close', function(event) {
		$('#popup').hide();
		event.preventDefault();
	});
	
	//add
	$('#controlsAdd').click(function(event) {
		$.ajax({
			url: 'ajax.php',
			type: 'POST',
			data: {
				'action': 'add',
				'type': 'employee'
			}
		}).done(function(data) {
			$('#popup > div > div').html(data.html);
			$('#popup').show();
			
			$('#addBtn').click(function() {
				var ajaxData = $('#popup input[type!="checkbox"], #popup select').serializeArray();
				ajaxData.push({'name': 'action', 'value': 'addSave'});
				ajaxData.push({'name': 'type', 'value': 'employee'});
				$.ajax({
					url: 'ajax.php',
					type: 'POST',
					data: ajaxData
				}).done(function(data) {
					$('#popup .invalid').removeClass('invalid');
					if (data.status == 'success') {
						$('#popup > div > div').html(data.html);
					}
					else {
						$.each(data, function(key, value) {
							if (key != 'status') {
								$('#popup [name=' + key + ']').addClass('invalid');
								$('#popup [name=' + key + ']').qtip({
									'content': value,
									'style': {'classes': 'qtip-tipsy-custom'},
									'position': {
										'my': 'bottom center',
										'at': 'top center'
									},
									show: {'event': 'focus'},
									hide: {'event': 'blur'}
								});
							}
						});
					}
				});
			});
		});
		event.preventDefault();
	});
	
	//edit
	$('#controlsEdit').click(function(event) {
		if ($('#controlsEdit').hasClass('controlsEditEnabled')) {
			var ajaxData;
			var $checked = $('.selectCheckbox:checked');
			if ($checked.length == 0) {
				ajaxData = {'action': 'edit', 'type': 'employee', 'id': id};
			}
			else if ($checked.length == 1) {
				ajaxData = {'action': 'edit', 'type': 'employee', 'id': $checked.attr('id')};
			}
			else {
				ajaxData = {'action': 'editMany', 'type': 'employee'};
			}
			
			$.ajax({
				url: 'ajax.php',
				type: 'POST',
				data: ajaxData
			}).done(function(data) {
				$('#popup > div > div').html(data.html);
				$('#popup').show();
				if (ajaxData.action == 'editMany') {
					$('#popup input[type="checkbox"]').click(function() {
						$(this).next().next().prop('disabled', !$(this).prop('checked'));
					});
				}
				
				$('#editBtn').click(function() {
					//if action is editMany, make sure we selected at least one field to change
					if ($checked.length > 1 && $('#popup input[type="checkbox"]:checked').length == 0) {
						return;
					}
					
					//get the ids we're changing
					var selectedIDs = [];
					if ($checked.length == 0) {
						selectedIDs.push(id);
					}
					else {
						$.each($checked, function(index, value) {
							selectedIDs.push(value.id);
						});
					}
					var idStr = selectedIDs.join();
					
					ajaxData = $('#popup input[type!="checkbox"], #popup select').serializeArray();
					ajaxData.push({'name': 'action', 'value': 'editSave'});
					ajaxData.push({'name': 'type', 'value': 'employee'});
					ajaxData.push({'name': 'id', 'value': idStr});
					
					$.ajax({
						url: 'ajax.php',
						type: 'POST',
						data: ajaxData
					}).done(function(data) {
						$('#popup .invalid').removeClass('invalid');
						if (data.status == 'success') {
							location.reload();
						}
						else {
							$.each(data, function(key, value) {
								if (key != 'status') {
									$('#popup [name=' + key + ']').addClass('invalid');
									$('#popup [name=' + key + ']').qtip({
										'content': value,
										'style': {'classes': 'qtip-tipsy-custom'},
										'position': {
											'my': 'bottom center',
											'at': 'top center'
										},
										show: {'event': 'focus'},
										hide: {'event': 'blur'}
									});
								}
							});
						}
					});
				});
			});
		}
		event.preventDefault();
	});
	
	//delete
	$('#controlsDelete').click(function(event) {
		if ($('#controlsDelete').hasClass('controlsDeleteEnabled')) {
			var ajaxData;
			var $checked = $('.selectCheckbox:checked');
			if ($checked.length == 0) {
				ajaxData = {'action': 'delete', 'type': 'employee', 'id': id};
			}
			else if ($checked.length == 1) {
				ajaxData = {'action': 'delete', 'type': 'employee', 'id': $checked.attr('id')};
			}
			else {
				ajaxData = {'action': 'deleteMany', 'type': 'employee'};
			}
		
			$.ajax({
				url: 'ajax.php',
				type: 'POST',
				data: ajaxData
			}).done(function(data) {
				$('#popup > div > div').html(data.html);
				$('#popup').show();
				
				$('#deleteBtn').click(function() {
					//get the ids we're changing
					var selectedIDs = [];
					if ($checked.length == 0) {
						selectedIDs.push(id);
					}
					else {
						$.each($checked, function(index, value) {
							selectedIDs.push(value.id);
						});
					}
					var idStr = selectedIDs.join();
				
					$.ajax({
						url: 'ajax.php',
						type: 'POST',
						data: {
							'action': 'deleteSave',
							'type': 'employee',
							'id': idStr
						}
					}).done(function(data) {
						location.reload();
					});
				});
			});
{'fraction_non_alphanumeric': 0.23657493988779055, 'fraction_numerical': 0.001469409564520438, 'mean_word_length': 2.677308447937132, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '6017883', 'n_tokens_mistral': 3355, 'n_tokens_neox': 2429, 'n_words': 483}