$("#groupTable").fancyTable({
	sortCsortColumn: 1,
	sortable: true,
	pagination: true,
	searchable: true,
	globalSearch: true,
	perPage: 10,
})

function create() {
	let value = $("#groupName").val();
	if (value) {
		$.ajax({
			type: "POST",
			data: JSON.stringify({ Value: value }),
			url: "/Home/Group/Overwiev?handler=CreateGroup",
			headers: { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() },
			contentType: "application/json; charset=utf-8",
			dataType: "json",
			success: function (response) {
				handleResponse(response);
			}
		})
	} else {
		alert("Please fill name.")
	}
}

function leave(idGroup, idOwner) {
	$.ajax({
		type: "POST",
		data: JSON.stringify(createPost(idGroup, idOwner)),
		url: "/Home/Group/Overwiev?handler=Leave",
		headers: { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() },
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		success: function (response) {
			handleResponse(response);
		}
	})
}

function handleResponse(response) {
	if (response) {
		location.reload();
	}
}

function createPost(id, value) {
	let ret = {
		IdGroup: id,
		Value: value
	}
	return ret;
}

$(document).ready(function () {
	$("#partID").text("Group");
	$("#sectionID").text("Overview");
})