{"size": 3750, "ext": "js", "max_stars_repo_path": "assets/js_admin/artikel.js", "max_stars_repo_name": "dodyprmna/gmit-tiberias-kupang", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assets/js_admin/artikel.js", "max_issues_repo_name": "dodyprmna/gmit-tiberias-kupang", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assets/js_admin/artikel.js", "max_forks_repo_name": "dodyprmna/gmit-tiberias-kupang", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.1612903226, "max_line_length": 68, "alphanum_fraction": 0.4954666667}
$(document).ready(function () {
	list();

	$('[data-plugin="add"]').click(function () {
		$(".panel_add").slideDown();
		$('[data-plugin="add"]').slideUp();
	});

	$('[data-plugin="minimize"]').click(function () {
		$(".panel_add").slideUp();
		$('[data-plugin="add"]').slideDown();
	});

	// ----insert-------

	$("#form_insert").submit(function (e) {
		e.preventDefault();

		$.ajax({
			url: base_url + "Artikel/insert/",
			type: "post",
			dataType: "json",
			data: new FormData(this),
			cache: false,
			contentType: false,
			processData: false,
			success: function (data) {
				if (data["status"]) {
					$("#form_insert")[0].reset();
					swal({
						title: "Berhasil",
						text: data.pesan,
						icon: "success",
					});
					list();
				} else {
					swal({
						title: "Gagal",
						text: data.pesan,
						icon: "error",
					});
				}
			},
		});
	});

	$("#form_update").submit(function (e) {
		e.preventDefault();

		$.ajax({
			url: base_url + "Artikel/update_artikel/",
			type: "post",
			dataType: "json",
			data: new FormData(this),
			cache: false,
			contentType: false,
			processData: false,
			success: function (data) {
				if (data["status"]) {
					swal({
						title: "Berhasil",
						text: data.pesan,
						icon: "success",
					});
					$("#modal_update").modal("hide");
					list();
				} else {
					swal({
						title: "Gagal",
						text: data.pesan,
						icon: "error",
					});
				}
			},
		});
	});

	// ------- update -------
	$(document).on("click", ".btn-update", function () {
		var id = $(this).data("id");

		$.ajax({
			url: base_url + "Artikel/data_update",
			type: "post",
			dataType: "json",
			data: { id: id },
			success: function (data) {
				$("#target_update").html(data["html"]);
			},
		});
	});

	// ------- delete -------
	$(document).on("click", ".btn-delete", function () {
		var id = $(this).data("id");
		var artikel = $(this).data("artikel");

		swal({
			title: "Apakah anda yakin?",
			icon: "warning",
			text: 'ingin menghapus artikel "' + artikel + '"',
			buttons: true,
			dangerMode: true,
		}).then((result) => {
			if (result) {
				$.ajax({
					url: base_url + "Artikel/delete/",
					type: "post",
					dataType: "json",
					data: { id: id },
					success: function (data) {
						if (data["status"]) {
							swal({
								title: "Berhasil",
								text: data.pesan,
								icon: "success",
							});
							list();
						} else {
							swal({
								title: "Gagal",
								text: data.pesan,
								icon: "error",
							});
						}
					},
				});
			}
		});
	});

	// ------- delete file -------
	$(document).on("click", ".btn-delete-file", function () {
		var id = $(this).data("id");
		var nama_file = $(this).data("filename");
		var id_artikel = $(this).data("idartikel");

		swal({
			title: "Apakah anda yakin?",
			icon: "warning",
			buttons: true,
			dangerMode: true,
		}).then((result) => {
			if (result) {
				$.ajax({
					url: base_url + "Artikel/delete_file/",
					type: "post",
					dataType: "json",
					data: { id: id, nama_file: nama_file, id_artikel: id_artikel },
					success: function (data) {
						if (data["status"]) {
							$("#target_update").html(data["html"]);
							swal({
								title: "Berhasil",
								text: data.pesan,
								icon: "success",
							});
						} else {
							swal({
								title: "Gagal",
								text: data.pesan,
								icon: "error",
							});
						}
					},
				});
			}
		});
	});
});

function list() {
	$("#list_data").html("<center><h2>Loading...</h2></center>");

	$.ajax({
		url: base_url + "Artikel/list_artikel",
		dataType: "json",
		success: function (data) {
			$("#list_data").html(data);
			$("#tabel_artikel").dataTable({
				stateSave: true,
			});
		},
	});
}
