mirror of
https://github.com/DreamExposure/DisCal-Discord-Bot.git
synced 2026-05-05 16:49:38 -05:00
Event deleting in dashboard!
This commit is contained in:
@@ -8,6 +8,7 @@ import com.cloudcraftgaming.discal.api.object.calendar.CalendarData;
|
||||
import com.cloudcraftgaming.discal.api.object.event.EventData;
|
||||
import com.cloudcraftgaming.discal.api.object.event.Recurrence;
|
||||
import com.cloudcraftgaming.discal.api.object.web.WebGuild;
|
||||
import com.cloudcraftgaming.discal.api.utils.EventUtils;
|
||||
import com.cloudcraftgaming.discal.api.utils.ExceptionHandler;
|
||||
import com.cloudcraftgaming.discal.web.handler.DiscordAccountHandler;
|
||||
import com.google.api.client.util.DateTime;
|
||||
@@ -175,6 +176,26 @@ public class EventEndpoint {
|
||||
}
|
||||
|
||||
public static String deleteEvent(Request request, Response response) {
|
||||
JSONObject requestBody = new JSONObject(request.body());
|
||||
String eventId = requestBody.getString("id");
|
||||
|
||||
Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
|
||||
WebGuild g = (WebGuild) m.get("selected");
|
||||
g.setSettings(DatabaseManager.getManager().getSettings(Long.valueOf(g.getId())));
|
||||
|
||||
//okay, time to properly delete the event
|
||||
if (EventUtils.deleteEvent(g.getSettings(), eventId)) {
|
||||
//Deleted!
|
||||
JSONObject r = new JSONObject();
|
||||
r.put("message", "Successfully deleted event!");
|
||||
response.body(r.toString());
|
||||
} else {
|
||||
//Oh nos! we failed >.<
|
||||
JSONObject r = new JSONObject();
|
||||
r.put("message", "Failed to delete event!");
|
||||
response.status(500);
|
||||
response.body(r.toString());
|
||||
}
|
||||
|
||||
return response.body();
|
||||
}
|
||||
|
||||
@@ -175,13 +175,27 @@ function getEventsForSelectedDate() {
|
||||
for (var i = 0; i < obj.count; i++) {
|
||||
var event = obj.events[i];
|
||||
|
||||
//Create button
|
||||
var button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.setAttribute("data-toggle", "modal");
|
||||
button.setAttribute("data-target", "#modal-" + event.id);
|
||||
button.innerHTML = "Edit";
|
||||
container.appendChild(button);
|
||||
//Create Edit Button
|
||||
var editButton = document.createElement("button");
|
||||
editButton.type = "button";
|
||||
editButton.setAttribute("data-toggle", "modal");
|
||||
editButton.setAttribute("data-target", "#modal-" + event.id);
|
||||
editButton.innerHTML = "Edit";
|
||||
container.appendChild(editButton);
|
||||
|
||||
//Create Delete button
|
||||
var deleteButton = document.createElement("button");
|
||||
deleteButton.type = "button";
|
||||
deleteButton.innerHTML = "Delete";
|
||||
deleteButton.className = "danger";
|
||||
deleteButton.id = "delete-" + event.id;
|
||||
deleteButton.onclick = function (ev) {
|
||||
deleteEvent(this.id)
|
||||
};
|
||||
container.appendChild(deleteButton);
|
||||
|
||||
container.appendChild(document.createElement("br"));
|
||||
container.appendChild(document.createElement("br"));
|
||||
|
||||
//Create modal container
|
||||
var modalContainer = document.createElement("div");
|
||||
@@ -314,7 +328,6 @@ function getEventsForSelectedDate() {
|
||||
form.appendChild(document.createElement("br"));
|
||||
|
||||
//Color
|
||||
//TODO: Make this a proper dropdown
|
||||
var colorLabel = document.createElement("label");
|
||||
colorLabel.innerHTML = "Color";
|
||||
colorLabel.appendChild(document.createElement("br"));
|
||||
@@ -466,6 +479,20 @@ function selectDate(clickedId) {
|
||||
}
|
||||
}
|
||||
|
||||
function deleteEvent(clickedId) {
|
||||
var eventId = clickedId.replace("delete-", "");
|
||||
var bodyRaw = {"id": eventId};
|
||||
|
||||
var q = $.post("/api/v1/events/delete", JSON.stringify(bodyRaw), function (response) {
|
||||
var obj = JSON.parse(response);
|
||||
|
||||
location.reload();
|
||||
})
|
||||
.fail(function () {
|
||||
alert("Our hippos failed to delete your event! If this continues contact the devs so we can get them working again");
|
||||
}, "json");
|
||||
}
|
||||
|
||||
function init() {
|
||||
setMonth({date: calendar.todaysDate});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user