Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>Setting Akun SLO | INKINDO</title>
- <link
- rel="stylesheet"
- href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css"
- />
- <link
- rel="stylesheet"
- href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css"
- />
- <link rel="icon" href="https://slo.inkindo.co.id/favicon.ico" />
- <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
- </head>
- <body>
- <div class="container-fluid mt-5">
- <div class="row">
- <div class="col-md-4 col-sm-12 mb-3">
- <div class="list-group" id="list-tab" role="tablist">
- <a
- class="list-group-item list-group-item-action active"
- data-toggle="list"
- href="#pjt"
- role="tab"
- >PJT</a
- >
- <a
- class="list-group-item list-group-item-action"
- data-toggle="list"
- href="#tt"
- role="tab"
- >TT</a
- >
- <a
- class="list-group-item list-group-item-action"
- data-toggle="list"
- href="#gm"
- role="tab"
- >GM/Biasa</a
- >
- </div>
- </div>
- <div class="col-md-8 col-sm-12">
- <div class="tab-content">
- <div class="tab-pane active" id="pjt" role="tabpanel">
- <button class="btn btn-primary add-data" data-role="pjt">
- Add PJT
- </button>
- <div class="table-responsive mt-3">
- <table class="table table-bordered table-striped">
- <thead class="thead-dark">
- <tr>
- <th>#</th>
- <th>Nama</th>
- <th>Username</th>
- <th>Password</th>
- <th>Aksi</th>
- </tr>
- </thead>
- <tbody id="data-pjt"></tbody>
- </table>
- </div>
- </div>
- <div class="tab-pane" id="tt" role="tabpanel">
- <button class="btn btn-primary add-data" data-role="tt">
- Add TT
- </button>
- <div class="table-responsive mt-3">
- <table class="table table-bordered table-striped">
- <thead class="thead-dark">
- <tr>
- <th>#</th>
- <th>Nama</th>
- <th>Username</th>
- <th>Password</th>
- <th>Aksi</th>
- </tr>
- </thead>
- <tbody id="data-tt"></tbody>
- </table>
- </div>
- </div>
- <div class="tab-pane" id="gm" role="tabpanel">
- <button class="btn btn-primary add-data" data-role="gm">
- Add GM/Biasa
- </button>
- <div class="table-responsive mt-3">
- <table class="table table-bordered table-striped">
- <thead class="thead-dark">
- <tr>
- <th>#</th>
- <th>Nama</th>
- <th>Username</th>
- <th>Password</th>
- <th>Aksi</th>
- </tr>
- </thead>
- <tbody id="data-gm"></tbody>
- </table>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <!-- Modal -->
- <div
- class="modal fade"
- id="add-modal"
- tabindex="-1"
- role="dialog"
- aria-labelledby="exampleModalLabel"
- aria-hidden="true"
- >
- <div class="modal-dialog" role="document">
- <div class="modal-content">
- <div class="modal-header">
- <h5 class="modal-title">semua ada Add PJT</h5>
- <button
- type="button"
- class="close"
- data-dismiss="modal"
- aria-label="Close"
- >
- <span aria-hidden="true">×</span>
- </button>
- </div>
- <div class="modal-body">
- <div class="form-group">
- <input type="hidden" id="role" />
- <input type="hidden" id="id" />
- <label for="nama">Nama</label>
- <input type="text" class="form-control" id="nama" />
- </div>
- <div class="form-group">
- <label for="username">Username</label>
- <input type="text" class="form-control" id="username" />
- </div>
- <div class="form-group">
- <label for="password">Password</label>
- <input type="text" class="form-control" id="password" />
- </div>
- </div>
- <div class="modal-footer">
- <button
- type="button"
- class="btn btn-secondary"
- data-dismiss="modal"
- >
- Close
- </button>
- <button type="button" class="btn btn-primary asd" id="save-data">
- Save
- </button>
- </div>
- </div>
- </div>
- </div>
- <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.3/dist/umd/popper.min.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/js/bootstrap.min.js"></script>
- <script>
- $(document).ready(function () {
- const setLocalStorage = (key, value) =>
- window.localStorage.setItem(key, value);
- const getLocalStorage = (key) => window.localStorage.getItem(key);
- const arrayData = (role) => JSON.parse(getLocalStorage(role)) || [];
- const getAkun = (role, id) => {
- const getData = JSON.parse(getLocalStorage(role));
- const akun = getData.find((o) => o.id == id);
- return akun;
- };
- const createList = (role, nama, username, password, id) => {
- const oldData = arrayData(role);
- let objData;
- let newList;
- if (id) {
- newList = oldData.map((item) => {
- if (item.id == id) {
- objData = {
- id,
- nama,
- username,
- password,
- };
- return objData;
- }
- return item;
- });
- } else {
- objData = {
- id: Math.round(Math.random() * 100),
- nama,
- username,
- password,
- };
- newList = [...oldData, objData];
- }
- return newList;
- };
- const newAkun = (role, nama, username, password, id) => {
- const listData = createList(role, nama, username, password, id);
- return setLocalStorage(role, JSON.stringify(listData));
- };
- const deleteAkun = (role, id) => {
- const oldData = arrayData(role);
- const filterData = oldData.filter((item) => item.id !== parseInt(id));
- return setLocalStorage(role, JSON.stringify(filterData));
- };
- const createRow = (role, select) => {
- const data = arrayData(role);
- let rowData = "";
- if (data.length == 0) {
- return $(select).append(
- `<tr class="text-center"><td colspan="5">Data ${role.toUpperCase()} tidak ada</td></tr>`
- );
- }
- data.forEach((el, index) => {
- rowData += `<tr>
- <td>${index + 1}</td>
- <td>${el.nama}</td><td>${el.username}</td>
- <td>${el.password}</td>
- <td>
- <button class="btn btn-warning btn-sm my-1 edit-data" data-role="${role}" data-id="${
- el.id
- }">
- <i class="fa-solid fa-pen-to-square"></i>
- </button>
- <button class="btn btn-danger btn-sm my-1 remove-data" data-nama="${
- el.nama
- }" data-role="${role}" data-id="${el.id}">
- <i class="fa-solid fa-trash"></i>
- </button></td>
- </tr>`;
- });
- $(select).append(rowData);
- };
- createRow("pjt", "#data-pjt");
- createRow("tt", "#data-tt");
- createRow("gm", "#data-gm");
- // add and edit
- const clearInput = () => {
- $("#role").val("");
- $("#nama").val("");
- $("#username").val("");
- $("#password").val("");
- $("#id").val("");
- };
- $(".add-data").on("click", function () {
- clearInput();
- const roleData = $(this).attr("data-role");
- $("#role").val(roleData);
- $("#add-modal").modal("show");
- $(".modal-title").text(`Add ${roleData.toUpperCase()}`);
- });
- $("#save-data").on("click", function () {
- const role = $("#role").val();
- const nama = $("#nama").val();
- const username = $("#username").val();
- const password = $("#password").val();
- const idEdit = $("#id").val();
- const isModeEdit = idEdit !== "";
- const kataAlert = isModeEdit ? "Diedit" : "Ditambah";
- newAkun(role, nama, username, password, idEdit);
- Swal.fire("Sukses", `Akun Berhasil ${kataAlert}`, "success").then(
- () => {
- location.reload();
- }
- );
- });
- $(".edit-data").on("click", function () {
- let roleData = $(this).attr("data-role");
- let idData = $(this).attr("data-id");
- const dataAkun = getAkun(roleData, idData);
- let { nama, role, username, password } = dataAkun;
- $("#role").val(roleData);
- $("#nama").val(nama);
- $("#username").val(username);
- $("#password").val(password);
- $("#id").val(idData);
- $("#add-modal").modal("show");
- $(".modal-title").text(`Edit ${roleData.toUpperCase()}`);
- });
- $(".remove-data").on("click", function () {
- let roleData = $(this).attr("data-role");
- let idData = $(this).attr("data-id");
- let namaData = $(this).attr("data-nama");
- Swal.fire({
- title: "Apakah kamu yakin?",
- html: `ingin menghapus akun ${roleData.toUpperCase()} dengan nama <b>${namaData}</b>? <br/> Anda tidak akan dapat mengembalikan ini!`,
- icon: "warning",
- showCancelButton: true,
- confirmButtonColor: "#3085d6",
- cancelButtonColor: "#d33",
- confirmButtonText: "Ya, Hapus!",
- cancelButtonText: "Batal",
- }).then((result) => {
- if (result.isConfirmed) {
- deleteAkun(roleData, idData);
- Swal.fire({
- title: "Dihapus!",
- html: `Akun ${roleData.toUpperCase()} dengan nama <b>${namaData}</b> telah dihapus.`,
- icon: "success",
- }).then(() => {
- location.reload();
- });
- }
- });
- });
- });
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment