Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html lang="en">
- <head>
- <!-- Required meta tags -->
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <!-- Bootstrap CSS -->
- <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
- <!--Bootstrap 5 icons CDN-->
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
- <title>CRUD Operations</title>
- <link rel="stylesheet" href="style.css">
- </head>
- <body>
- <section class="p-3">
- <div class="row">
- <div class="col-12">
- <button class="btn btn-primary newUser" data-bs-toggle="modal" data-bs-target="#userForm">New User <i class="bi bi-people"></i></button>
- </div>
- </div>
- <div class="row">
- <div class="col-12">
- <table class="table table-striped table-hover mt-3 text-center table-bordered">
- <thead>
- <tr>
- <th>Vorname</th>
- <th>Nachname</th>
- <th>Passwort</th>
- <th>Email</th>
- </tr>
- </thead>
- <tbody id="data"></tbody>
- </table>
- </div>
- </div>
- </section>
- <!--Modal Form-->
- <div class="modal fade" id="userForm">
- <div class="modal-dialog modal-dialog-centered modal-lg">
- <div class="modal-content">
- <div class="modal-header">
- <h4 class="modal-title">Fill the Form</h4>
- <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
- </div>
- <div class="modal-body">
- <form action="#" id="myForm">
- <div class="card imgholder">
- <label for="imgInput" class="upload">
- <input type="file" name="" id="imgInput">
- <i class="bi bi-plus-circle-dotted"></i>
- </label>
- <img src="./image/Profile Icon.webp" alt="" width="200" height="200" class="img">
- </div>
- <div class="inputField">
- <div>
- <label for="name">Vorname:</label>
- <input type="text" name="" id="name" required>
- </div>
- <div>
- <label for="Nachname">Nachnem:</label>
- <input type="text" name="" id="name" required>
- </div>
- <div>
- <label for="email">email:</label>
- <input type="text" name="" id="email" required>
- </div>
- <div>
- <label for="passwort">passwort:</label>
- <input type="passwort" name="" id="passwort" required>
- </div>
- </form>
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
- <button type="submit" form="myForm" class="btn btn-primary submit">Submit</button>
- </div>
- </div>
- </div>
- </div>
- <!--Read Data Modal-->
- <div class="modal fade" id="readData">
- <div class="modal-dialog modal-dialog-centered modal-lg">
- <div class="modal-content">
- <div class="modal-header">
- <h4 class="modal-title">Profile</h4>
- <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
- </div>
- <div class="modal-body">
- <form action="#" id="myForm">
- <div class="card imgholder">
- <img src="./image/Profile Icon.webp" alt="" width="200" height="200" class="showImg">
- </div>
- <div class="inputField">
- <div>
- <label for="name">Vorname:</label>
- <input type="text" name="" id="name" required>
- </div>
- <div>
- <label for="Nachname">Nachnem:</label>
- <input type="text" name="" id="name" required>
- </div>
- <div>
- <label for="email">email:</label>
- <input type="text" name="" id="email" required>
- </div>
- <div>
- <label for="passwort">passwort:</label>
- <input type="passwort" name="" id="passwort" required>
- </div>
- </form>
- </div>
- </div>
- </div>
- </div>
- <!-- Option 1: Bootstrap Bundle with Popper -->
- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
- <script src="app.js"></script>
- </body>
- </html>
- TYPESCRIPT
- var form = document.getElementById("myForm"),
- imgInput = document.querySelector(".img"),
- file = document.getElementById("imgInput"),
- Vornamw = document.getElementById("Vorname "),
- Nachname = document.getElementById("Nachname"),
- Email = document.getElementById("email"),
- Passwort = document.getElementById("passwort "),
- submitBtn = document.querySelector(".submit"),
- userInfo = document.getElementById("data"),
- modal = document.getElementById("userForm"),
- modalTitle = document.querySelector("#userForm .modal-title"),
- newUserBtn = document.querySelector(".newUser")
- let getData = localStorage.getItem('userProfile') ? JSON.parse(localStorage.getItem('userProfile')) : []
- let isEdit = false, editId
- showInfo()
- newUserBtn.addEventListener('click', ()=> {
- submitBtn.innerText = 'Submit',
- modalTitle.innerText = "Fill the Form"
- isEdit = false
- imgInput.src = "./image/Profile Icon.webp"
- form.reset()
- })
- file.onchange = function(){
- if(file.files[0].size < 1000000){ // 1MB = 1000000
- var fileReader = new FileReader();
- fileReader.onload = function(e){
- imgUrl = e.target.result
- imgInput.src = imgUrl
- }
- fileReader.readAsDataURL(file.files[0])
- }
- else{
- alert("This file is too large!")
- }
- }
- ————
- function showInfo(){
- document.querySelectorAll('.employeeDetails').forEach(info => info.remove())
- getData.forEach((element, index) => {
- let createElement = `<tr class="employeeDetails">
- <td>${index+1}</td>
- <td><img src="${element.picture}" alt="" width="50" height="50"></td>
- <td>${element.employeeVorname}</td>
- <td>${element.employeeNachname}</td>
- <td>${element.employeeEmail}</td>
- <td>${element.employeePasswort}</td>
- <td>
- <button class="btn btn-success" onclick="readInfo('${element.picture}', '${element.employeeName}', '${element.employeeNachname}', '${element.employeeEmail}', '${element.employeePasswort}', '$" data-bs-toggle="modal" data-bs-target="#readData"><i class="bi bi-eye"></i></button>
- <button class="btn btn-primary" onclick="editInfo(${index}, '${element.picture}', '${element.employeeName}', '${element.employeeNachname}', '${element.employeeEmail}', '${element.employeePASSWORT}', '$" data-bs-toggle="modal" data-bs-target="#userForm"><i class="bi bi-pencil-square"></i></button>
- <button class="btn btn-danger" onclick="deleteInfo(${index})"><i class="bi bi-trash"></i></button>
- </td>
- </tr>`
- userInfo.innerHTML += createElement
- })
- }
- showInfo()
- function readInfo(pic, name, age, city, email, phone, post, sDate){
- document.querySelector('.showImg').src = pic,
- document.querySelector('#showName').value = name,
- document.querySelector("#showNachname").value = Nachname,
- document.querySelector("#showEmail").value = email,
- document.querySelector("#showPasswort").value = passwort,
- }
- function editInfo(index, pic, name, Nachname, Email, Passwort){
- isEdit = true
- editId = index
- imgInput.src = pic
- userName.value = name
- Nachname.value = nachname
- email.value = Email,
- Passwort .value = Passwort ,
- submitBtn.innerText = "Update"
- modalTitle.innerText = "Update The Form"
- }
- function deleteInfo(index){
- if(confirm("Are you sure want to delete?")){
- getData.splice(index, 1)
- localStorage.setItem("userProfile", JSON.stringify(getData))
- showInfo()
- }
- }
- form.addEventListener('submit', (e)=> {
- e.preventDefault()
- const information = {
- picture: imgInput.src == undefined ? "./image/Profile Icon.webp" : imgInput.src,
- employeeName: userName.value,
- employeeNachname : nachname.value,
- employeeEmail: email.value,
- employeePasswort : Passwort .value,
- }
- if(!isEdit){
- getData.push(information)
- }
- else{
- isEdit = false
- getData[editId] = information
- }
- localStorage.setItem('userProfile', JSON.stringify(getData))
- submitBtn.innerText = "Submit"
- modalTitle.innerHTML = "Fill The Form"
- showInfo()
- form.reset()
- imgInput.src = "./image/Profile Icon.webp"
- // modal.style.display = "none"
- // document.querySelector(".modal-backdrop").remove()
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement