Skip to content

Commit

Permalink
✔️ Delete Contact
Browse files Browse the repository at this point in the history
  • Loading branch information
700software committed Jan 12, 2021
1 parent f3cd779 commit dc75b55
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main/java/com/sample/PostDeleteContact.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.sample;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static com.sample.Globals.respondPlain;

@WebServlet(
urlPatterns = "/delete-contact"
)
public class PostDeleteContact extends HttpServlet {

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

int id = Integer.parseInt(req.getParameter("id"));

OurData.THE_MAP.remove(id);

respondPlain(resp, 200, true, "{}");
}
}
26 changes: 26 additions & 0 deletions src/main/webapp/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@ form.onsubmit = function () {
})
}

deleteButton.onclick = function () {
var button = this
if (button.getAttribute('data-state'))
return false
button.setAttribute('data-state', 'confirm')
if (!confirm('Really, delete this?')) {
button.removeAttribute('data-state')
return false
}
button.setAttribute('data-state', 'hold')
ajaxWave({
url: 'delete-contact' + location.search,
postdata: '',
callback: function (wave, request) {
if (request.status == 200 && wave.json) {
button.setAttribute('data-state', 'thanks')
location = './'
} else {
button.setAttribute('data-state', 'whoops')
alert(wave.text || wave.whoops)
button.removeAttribute('data-state')
}
},
})
}

function formData(form) {
var data = ''
for (var i = 0; i < form.elements.length; i++) {
Expand Down

0 comments on commit dc75b55

Please sign in to comment.