This repository has been archived on 2022-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
rangitaki/rcc/res/delete.js

83 lines
2.5 KiB
JavaScript
Raw Permalink Normal View History

2015-12-06 15:19:16 +01:00
/**
2016-03-11 18:54:58 +01:00
* JavaScript for the ajax request to delete blog post
2015-12-06 15:19:16 +01:00
*
2016-03-11 18:54:58 +01:00
* Copyright (c) 2016 by mmk2410
* License: MIT License
2015-12-06 15:19:16 +01:00
*/
function main() {
// listener and function for recieving the posts of the selected blogs
$("#delete_get_posts").click(function () {
2016-03-11 18:54:58 +01:00
2015-12-06 15:19:16 +01:00
var selectedBlog = $("#delete_selected_blog").val();
2016-03-11 18:54:58 +01:00
2015-12-06 15:19:16 +01:00
$.get("res/get_posts.php", {
blog: selectedBlog
}, function (data) {
2016-03-11 18:54:58 +01:00
2015-12-06 15:19:16 +01:00
$("#delete_select_post").remove();
$("#delete_select_post_info").remove();
$("#delete_post_button").remove();
$("#delete_get_posts").after("<p id='delete_select_post'></p>");
2016-03-11 18:54:58 +01:00
$("#delete_get_posts").after(
"<p id='delete_select_post_info'>" +
"Now select the post you want to delete. " +
"Remember that once a post is deleted it can't be restored.</p>"
);
$("#delete_select_post").append(
"<select id='delete_selected_post'></select>"
);
2015-12-06 15:19:16 +01:00
$.each($.parseJSON(data), function (index, value) {
var post = value.substring(0, value.length - 3);
2016-03-11 18:54:58 +01:00
$("#delete_selected_post").append(
"<option value='" + post + "'>" + post + "</option>"
);
2015-12-06 15:19:16 +01:00
});
2016-03-11 18:54:58 +01:00
$("#delete_select_post").after(
"<a class='button' id='delete_post_button' " +
"onclick='deletePostButton()'>DELETE POST</a>"
);
2015-12-06 15:19:16 +01:00
});
});
}
/**
* Delete the selected posts
*/
function deletePostButton() {
var selectedBlog = $("#delete_selected_blog").val();
var selectedPost = $("#delete_selected_post").val();
2016-03-11 18:54:58 +01:00
2015-12-06 15:19:16 +01:00
$.get("res/delete_post.php", {
blog: selectedBlog,
post: selectedPost
}, function (data) {
2016-03-11 18:54:58 +01:00
2015-12-06 15:19:16 +01:00
$("#delete_select_post").remove();
$("#delete_select_post_info").remove();
$("#delete_post_button").remove();
if (data == "901") {
alert("ERROR 901: No post as get argument given.");
} else if (data == "921") {
alert("ERROR 921: No post with given argument available.");
} else if (data == "941") {
alert("ERROR 941: No blog as get argument given");
} else if (data == "961") {
2016-03-11 18:54:58 +01:00
alert(
"ERROR 961: Error while deleting the file. Check if the" +
"web server has the permission to do so."
);
2015-12-06 15:19:16 +01:00
} else if (data == "0") {
alert("Post successfully deleted.");
}
});
}
2016-03-11 18:54:58 +01:00
$(document).ready(main());