Initial baseline WACloud CI3 production
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title w-100 text-center">Tambah User</h5>
|
||||
</div>
|
||||
|
||||
<form id="formUser" action="<?= base_url('user_management/save'); ?>" method="post">
|
||||
<div class="modal-body">
|
||||
<div class="form-group mb-3">
|
||||
<label>Nama</label>
|
||||
<input type="text" name="name" class="form-control" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label>Username</label>
|
||||
<input type="text" name="username" class="form-control" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label>Password</label>
|
||||
<input type="text" name="password" class="form-control" required>
|
||||
</div>
|
||||
<?php if($_SESSION['user_id'] == 1) { ?>
|
||||
<div class="form-group mb-3">
|
||||
<label>Role</label>
|
||||
<select class="form-control" name="role" required>
|
||||
<option value="">--- Pilih Role ---</option>
|
||||
<option value="admin">Admin</option>
|
||||
<option value="user">User</option>
|
||||
</select>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="form-group mb-3">
|
||||
<label>WhatsApp Number</label>
|
||||
<select class="form-control" name="whatsapp_id" required>
|
||||
<option value="">--- Pilih ---</option>
|
||||
<?php foreach ($phone_numbers as $p): ?>
|
||||
<option value="<?= $p->id ?>">
|
||||
<?= substr($p->phone_number, 0, 2) === '62' ? $p->phone_number : '62' . $p->phone_number ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">Simpan</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -0,0 +1,42 @@
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title w-100 text-center">Edit User</h5>
|
||||
</div>
|
||||
|
||||
<form id="formUser" action="<?= site_url('user_management/save'); ?>" method="post">
|
||||
<input type="hidden" name="id" value="<?= $user->id; ?>">
|
||||
<div class="modal-body">
|
||||
<div class="form-group mb-3">
|
||||
<label>Nama</label>
|
||||
<input type="text" name="name" value="<?= $user->name; ?>" class="form-control" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label>Username</label>
|
||||
<input type="text" name="username" value="<?= $user->username; ?>" class="form-control" required>
|
||||
</div>
|
||||
<?php if($_SESSION['user_id'] == 1) { ?>
|
||||
<div class="form-group mb-3">
|
||||
<label>Role</label>
|
||||
<select class="form-control" name="role" required>
|
||||
<option value="">--- Pilih Role ---</option>
|
||||
<option value="admin" <?= ($user->role == 'admin') ? 'selected' : '' ?>>Admin</option>
|
||||
<option value="user" <?= ($user->role == 'user') ? 'selected' : '' ?>>User</option>
|
||||
</select>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="form-group mb-3">
|
||||
<label>WhatsApp Number</label>
|
||||
<select class="form-control" name="whatsapp_id" required>
|
||||
<option value="">--- Pilih ---</option>
|
||||
<?php foreach ($phone_numbers as $p): ?>
|
||||
<option value="<?= $p->id ?>" <?= ($user->whatsapp_id == $p->id) ? 'selected' : '' ?>>
|
||||
<?= substr($p->phone_number, 0, 2) === '62' ? $p->phone_number : '62' . $p->phone_number ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">Update</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -0,0 +1,155 @@
|
||||
<div class="container mt-4">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-6 center-v">
|
||||
<h5>Daftar User Management</h5>
|
||||
</div>
|
||||
<div class="col-6 text-end">
|
||||
<button class="btn btn-primary btn-sm mb-3" id="btnAdd">Tambah User</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-bordered" id="userTable">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th class="mw-20">No</th>
|
||||
<th>Nama</th>
|
||||
<th>Username</th>
|
||||
<th>Role</th>
|
||||
<th class="mw-70">Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="userModal" tabindex="-1" aria-labelledby="userModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content" id="modalContent">
|
||||
<!-- konten add/edit akan dimuat via AJAX -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
|
||||
// 🔹 Load Data Awal
|
||||
function loadData() {
|
||||
$.ajax({
|
||||
url: "<?= base_url('user_management/get_list'); ?>",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(res) {
|
||||
let html = "";
|
||||
if (res.length > 0) {
|
||||
$.each(res, function(i, row) {
|
||||
html += `
|
||||
<tr>
|
||||
<td class="center-all mw-20">${i+1}</td>
|
||||
<td>${row.name}</td>
|
||||
<td>${row.username}</td>
|
||||
<td class="center-all">${row.role}</td>
|
||||
<td class="center-all mw-70">
|
||||
<button class="btn btn-sm btn-warning btnEdit" style="margin-right: 5px;" data-id="${row.id}">Edit</button>
|
||||
<button class="btn btn-sm btn-danger btnDelete" data-id="${row.id}">Hapus</button>
|
||||
</td>
|
||||
</tr>`;
|
||||
});
|
||||
} else {
|
||||
html = `<tr><td colspan="4" class="text-center">Belum ada data</td></tr>`;
|
||||
}
|
||||
$("#userTable tbody").html(html);
|
||||
}
|
||||
});
|
||||
}
|
||||
loadData();
|
||||
|
||||
// 🔹 Tombol Tambah
|
||||
$("#btnAdd").on("click", function() {
|
||||
$("#modalContent").load("<?= base_url('user_management/add'); ?>", function() {
|
||||
$("#userModal").modal("show");
|
||||
});
|
||||
});
|
||||
|
||||
// 🔹 Tombol Edit
|
||||
$(document).on("click", ".btnEdit", function() {
|
||||
let id = $(this).data("id");
|
||||
$("#modalContent").load("<?= base_url('user_management/edit/'); ?>" + id, function() {
|
||||
$("#userModal").modal("show");
|
||||
});
|
||||
});
|
||||
|
||||
// 🔹 Submit Form Add/Edit
|
||||
$(document).on("submit", "#formUser", function(e) {
|
||||
e.preventDefault();
|
||||
let form = $(this);
|
||||
$.ajax({
|
||||
url: form.attr("action"),
|
||||
type: "POST",
|
||||
data: form.serialize(),
|
||||
dataType: "json",
|
||||
success: function(res) {
|
||||
if (res.status == "success") {
|
||||
$("#userModal").modal("hide");
|
||||
loadData();
|
||||
Swal.fire("Berhasil!", res.message, "success");
|
||||
} else {
|
||||
Swal.fire("Gagal!", res.message, "error");
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
Swal.fire("Error!", "Terjadi kesalahan pada server", "error");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 🔹 DELETE DENGAN SWEETALERT
|
||||
$(document).on("click", ".btnDelete", function() {
|
||||
const id = $(this).data("id");
|
||||
|
||||
Swal.fire({
|
||||
title: "Yakin hapus user ini?",
|
||||
text: "Data yang dihapus tidak dapat dikembalikan!",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#d33",
|
||||
cancelButtonColor: "#3085d6",
|
||||
confirmButtonText: "Ya, hapus!",
|
||||
cancelButtonText: "Batal"
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
url: "<?= site_url('user_management/delete/'); ?>" + id,
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
success: function(res) {
|
||||
if (res.status === "success") {
|
||||
Swal.fire({
|
||||
icon: "success",
|
||||
title: "Berhasil!",
|
||||
text: res.message,
|
||||
timer: 1500,
|
||||
showConfirmButton: false
|
||||
});
|
||||
loadData();
|
||||
} else {
|
||||
Swal.fire("Gagal!", res.message, "error");
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
Swal.fire("Error!", "Terjadi kesalahan di server.", "error");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user