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/edit.js

86 lines
2.6 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 edit a article
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
$("#edit_get_posts").click(function () {
2016-03-11 18:54:58 +01:00
2015-12-06 15:19:16 +01:00
var selectedBlog = $("#edit_selected_blog").val();
$.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
$("#edit_select_post").remove();
$("#edit_select_post_info").remove();
$("#edit_post_button").remove();
$("#edit_get_posts").after("<p id='edit_select_post'></p>");
2016-03-11 18:54:58 +01:00
$("#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>"
);
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
$("#edit_selected_post").append(
"<option value='" + post + "'>" + post + "</option>"
);
2015-12-06 15:19:16 +01:00
});
2016-03-11 18:54:58 +01:00
$("#edit_select_post").after(
"<a class='button' id='edit_post_button' " +
"onclick='editPostButton()'>EDIT POST</a>"
);
2015-12-06 15:19:16 +01:00
});
});
$("#save_changes").click(function () {
2016-03-11 18:54:58 +01:00
2015-12-06 15:19:16 +01:00
var postTitle = $("#title").val();
var postDate = $("#date").val();
var postAuthor = $("#author").val();
var postTags = $("#tags").val();
var postText = $("#text").val();
2016-03-11 18:54:58 +01:00
var file = "../../articles/" + getVariables.blog +
"/" + getVariables.post + ".md";
2015-12-06 15:19:16 +01:00
$.post("../res/save.php", {
title: postTitle,
date: postDate,
author: postAuthor,
tags: postTags,
text: postText,
file: file
}, function (data) {
if (data == "0") {
alert("File successfully changed.");
window.open("../");
} else if (data == "1") {
alert("Error while saving the changes.");
} else if (data == "-1") {
alert("file");
}
});
});
}
/**
* Delete the selected posts
*/
function editPostButton() {
var selectedBlog = $("#edit_selected_blog").val();
var selectedPost = $("#edit_selected_post").val();
var href = "./edit/?blog=" + selectedBlog + "&post=" + selectedPost;
window.open(href);
}
2016-03-11 18:54:58 +01:00
$(document).ready(main());