Advertisement
Guest User

Untitled

a guest
Jan 13th, 2025
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.36 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <!-- Required meta tags -->
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7.  
  8. <!-- Bootstrap CSS -->
  9. <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
  10.  
  11. <!--Bootstrap 5 icons CDN-->
  12. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
  13.  
  14. <title>CRUD Operations</title>
  15.  
  16. <link rel="stylesheet" href="style.css">
  17. </head>
  18. <body>
  19.  
  20.  
  21. <section class="p-3">
  22.  
  23. <div class="row">
  24. <div class="col-12">
  25. <button class="btn btn-primary newUser" data-bs-toggle="modal" data-bs-target="#userForm">New User <i class="bi bi-people"></i></button>
  26. </div>
  27. </div>
  28.  
  29. <div class="row">
  30. <div class="col-12">
  31. <table class="table table-striped table-hover mt-3 text-center table-bordered">
  32.  
  33. <thead>
  34. <tr>
  35. <th>Vorname</th>
  36. <th>Nachname</th>
  37. <th>Passwort</th>
  38. <th>Email</th>
  39. </tr>
  40. </thead>
  41.  
  42. <tbody id="data"></tbody>
  43.  
  44. </table>
  45. </div>
  46. </div>
  47.  
  48. </section>
  49.  
  50.  
  51. <!--Modal Form-->
  52. <div class="modal fade" id="userForm">
  53. <div class="modal-dialog modal-dialog-centered modal-lg">
  54. <div class="modal-content">
  55.  
  56. <div class="modal-header">
  57. <h4 class="modal-title">Fill the Form</h4>
  58. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  59. </div>
  60.  
  61. <div class="modal-body">
  62.  
  63. <form action="#" id="myForm">
  64.  
  65. <div class="card imgholder">
  66. <label for="imgInput" class="upload">
  67. <input type="file" name="" id="imgInput">
  68. <i class="bi bi-plus-circle-dotted"></i>
  69. </label>
  70. <img src="./image/Profile Icon.webp" alt="" width="200" height="200" class="img">
  71. </div>
  72.  
  73. <div class="inputField">
  74. <div>
  75. <label for="name">Vorname:</label>
  76. <input type="text" name="" id="name" required>
  77. </div>
  78. <div>
  79. <label for="Nachname">Nachnem:</label>
  80. <input type="text" name="" id="name" required>
  81. </div>
  82. <div>
  83. <label for="email">email:</label>
  84. <input type="text" name="" id="email" required>
  85. </div>
  86. <div>
  87. <label for="passwort">passwort:</label>
  88. <input type="passwort" name="" id="passwort" required>
  89. </div>
  90.  
  91.  
  92.  
  93. </form>
  94. </div>
  95.  
  96. <div class="modal-footer">
  97. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
  98. <button type="submit" form="myForm" class="btn btn-primary submit">Submit</button>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103.  
  104. <!--Read Data Modal-->
  105. <div class="modal fade" id="readData">
  106. <div class="modal-dialog modal-dialog-centered modal-lg">
  107. <div class="modal-content">
  108.  
  109. <div class="modal-header">
  110. <h4 class="modal-title">Profile</h4>
  111. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  112. </div>
  113.  
  114. <div class="modal-body">
  115.  
  116. <form action="#" id="myForm">
  117.  
  118. <div class="card imgholder">
  119. <img src="./image/Profile Icon.webp" alt="" width="200" height="200" class="showImg">
  120. </div>
  121.  
  122. <div class="inputField">
  123. <div>
  124. <label for="name">Vorname:</label>
  125. <input type="text" name="" id="name" required>
  126. </div>
  127. <div>
  128. <label for="Nachname">Nachnem:</label>
  129. <input type="text" name="" id="name" required>
  130. </div>
  131. <div>
  132. <label for="email">email:</label>
  133. <input type="text" name="" id="email" required>
  134. </div>
  135. <div>
  136. <label for="passwort">passwort:</label>
  137. <input type="passwort" name="" id="passwort" required>
  138. </div>
  139.  
  140. </form>
  141. </div>
  142. </div>
  143. </div>
  144. </div>
  145.  
  146.  
  147. <!-- Option 1: Bootstrap Bundle with Popper -->
  148. <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
  149.  
  150. <script src="app.js"></script>
  151. </body>
  152. </html>
  153.  
  154. TYPESCRIPT
  155.  
  156. var form = document.getElementById("myForm"),
  157. imgInput = document.querySelector(".img"),
  158. file = document.getElementById("imgInput"),
  159. Vornamw = document.getElementById("Vorname "),
  160. Nachname = document.getElementById("Nachname"),
  161. Email = document.getElementById("email"),
  162. Passwort = document.getElementById("passwort "),
  163. submitBtn = document.querySelector(".submit"),
  164. userInfo = document.getElementById("data"),
  165. modal = document.getElementById("userForm"),
  166. modalTitle = document.querySelector("#userForm .modal-title"),
  167. newUserBtn = document.querySelector(".newUser")
  168.  
  169.  
  170. let getData = localStorage.getItem('userProfile') ? JSON.parse(localStorage.getItem('userProfile')) : []
  171.  
  172. let isEdit = false, editId
  173. showInfo()
  174.  
  175. newUserBtn.addEventListener('click', ()=> {
  176. submitBtn.innerText = 'Submit',
  177. modalTitle.innerText = "Fill the Form"
  178. isEdit = false
  179. imgInput.src = "./image/Profile Icon.webp"
  180. form.reset()
  181. })
  182.  
  183.  
  184. file.onchange = function(){
  185. if(file.files[0].size < 1000000){ // 1MB = 1000000
  186. var fileReader = new FileReader();
  187.  
  188. fileReader.onload = function(e){
  189. imgUrl = e.target.result
  190. imgInput.src = imgUrl
  191. }
  192.  
  193. fileReader.readAsDataURL(file.files[0])
  194. }
  195. else{
  196. alert("This file is too large!")
  197. }
  198. }
  199.  
  200. ————
  201.  
  202.  
  203. function showInfo(){
  204. document.querySelectorAll('.employeeDetails').forEach(info => info.remove())
  205. getData.forEach((element, index) => {
  206. let createElement = `<tr class="employeeDetails">
  207. <td>${index+1}</td>
  208. <td><img src="${element.picture}" alt="" width="50" height="50"></td>
  209. <td>${element.employeeVorname}</td>
  210. <td>${element.employeeNachname}</td>
  211. <td>${element.employeeEmail}</td>
  212. <td>${element.employeePasswort}</td>
  213.  
  214.  
  215. <td>
  216. <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>
  217.  
  218. <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>
  219.  
  220. <button class="btn btn-danger" onclick="deleteInfo(${index})"><i class="bi bi-trash"></i></button>
  221.  
  222. </td>
  223. </tr>`
  224.  
  225. userInfo.innerHTML += createElement
  226. })
  227. }
  228. showInfo()
  229.  
  230.  
  231. function readInfo(pic, name, age, city, email, phone, post, sDate){
  232. document.querySelector('.showImg').src = pic,
  233. document.querySelector('#showName').value = name,
  234. document.querySelector("#showNachname").value = Nachname,
  235. document.querySelector("#showEmail").value = email,
  236. document.querySelector("#showPasswort").value = passwort,
  237. }
  238.  
  239.  
  240. function editInfo(index, pic, name, Nachname, Email, Passwort){
  241. isEdit = true
  242. editId = index
  243. imgInput.src = pic
  244. userName.value = name
  245. Nachname.value = nachname
  246. email.value = Email,
  247. Passwort .value = Passwort ,
  248.  
  249. submitBtn.innerText = "Update"
  250. modalTitle.innerText = "Update The Form"
  251. }
  252.  
  253.  
  254. function deleteInfo(index){
  255. if(confirm("Are you sure want to delete?")){
  256. getData.splice(index, 1)
  257. localStorage.setItem("userProfile", JSON.stringify(getData))
  258. showInfo()
  259. }
  260. }
  261.  
  262.  
  263. form.addEventListener('submit', (e)=> {
  264. e.preventDefault()
  265.  
  266. const information = {
  267. picture: imgInput.src == undefined ? "./image/Profile Icon.webp" : imgInput.src,
  268. employeeName: userName.value,
  269. employeeNachname : nachname.value,
  270. employeeEmail: email.value,
  271. employeePasswort : Passwort .value,
  272. }
  273.  
  274. if(!isEdit){
  275. getData.push(information)
  276. }
  277. else{
  278. isEdit = false
  279. getData[editId] = information
  280. }
  281.  
  282. localStorage.setItem('userProfile', JSON.stringify(getData))
  283.  
  284. submitBtn.innerText = "Submit"
  285. modalTitle.innerHTML = "Fill The Form"
  286.  
  287. showInfo()
  288.  
  289. form.reset()
  290.  
  291. imgInput.src = "./image/Profile Icon.webp"
  292.  
  293. // modal.style.display = "none"
  294. // document.querySelector(".modal-backdrop").remove()
  295. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement