Code Improvements

This commit is contained in:
mmk2410 2016-03-11 18:54:58 +01:00
parent 08ee5eaf39
commit 75b705ee2c
14 changed files with 933 additions and 521 deletions

View file

@ -1,41 +1,54 @@
/**
* Created by mmk2410 on 12/6/15.
* JavaScript for the ajax request to edit a article
*
* JavaScript for the functionality to delete blogs
* Copyright (c) 2016 by mmk2410
* License: MIT License
*/
function main() {
// listener and function for recieving the posts of the selected blogs
$("#edit_get_posts").click(function () {
var selectedBlog = $("#edit_selected_blog").val();
$.get("res/get_posts.php", {
blog: selectedBlog
}, function (data) {
$("#edit_select_post").remove();
$("#edit_select_post_info").remove();
$("#edit_post_button").remove();
$("#edit_get_posts").after("<p id='edit_select_post'></p>");
$("#edit_get_posts").after("<p id='edit_select_post_info'>Now select the post you want to edit.</p>");
$("#edit_select_post").append("<select id='edit_selected_post'></select>");
$("#edit_get_posts").after(
"<p id='edit_select_post_info'>" +
"Now select the post you want to edit.</p>"
);
$("#edit_select_post").append(
"<select id='edit_selected_post'></select>"
);
$.each($.parseJSON(data), function (index, value) {
var post = value.substring(0, value.length - 3);
$("#edit_selected_post").append("<option value='" + post + "'>" + post + "</option>");
$("#edit_selected_post").append(
"<option value='" + post + "'>" + post + "</option>"
);
});
$("#edit_select_post").after("<a class='button' id='edit_post_button' " +
"onclick='editPostButton()'>EDIT POST</a>")
$("#edit_select_post").after(
"<a class='button' id='edit_post_button' " +
"onclick='editPostButton()'>EDIT POST</a>"
);
});
});
$("#save_changes").click(function () {
var postTitle = $("#title").val();
var postDate = $("#date").val();
var postAuthor = $("#author").val();
var postTags = $("#tags").val();
var postText = $("#text").val();
var file = "../../articles/" + getVariables['blog'] + "/" + getVariables['post'] + ".md";
console.log(file);
var file = "../../articles/" + getVariables.blog +
"/" + getVariables.post + ".md";
$.post("../res/save.php", {
title: postTitle,
@ -69,4 +82,4 @@ function editPostButton() {
}
$(document).ready(main());
$(document).ready(main());