Working delete and hide of the post

This commit is contained in:
2017-06-12 16:15:34 +03:00
parent b1dcf5f72d
commit 41991a68dd
4 changed files with 45 additions and 13 deletions

View File

@@ -3,10 +3,15 @@
<br/>
<button onclick="getForum(prompt('ForumId: ', '1'))">GetForum</button>
<button onclick="getForums()">GetAllForums</button>
<button onclick="addForum()">AddForum</button>
<button onclick="addForum(prompt('Title: ', 'Uus postitus'))">AddForum</button>
<button onclick="changeForumTitle(prompt('ForumId: ', '1'), prompt('ForumTitle: ', 'Muudetud'))">ChangeForumTitle</button>
<br/>
<button onclick="searchForumAuthor(prompt('Author: ', 'veeb'))">SearchForumAuthor</button>
<button onclick="deleteForum(prompt('ForumId: ', '1'), true)">DeleteForum</button>
<button onclick="deleteForum(prompt('ForumId: ', '1'), false)">HideForum</button>
<br/>
<button onclick="searchForum('author', prompt('Author: ', 'veeb'))">SearchForumAuthor</button>
<button onclick="searchForum('title', prompt('Title: ', 'test'))">SearchForumTitle</button>
<code><pre id="output"></pre></code>
<script>
@@ -30,12 +35,12 @@
});
}
function addForum() {
function addForum(title) {
var dto = {
Author: "Veebileht",
Body: "Siia tuleb äge pikk sisu mingist asjast",
Description: "Siia kirjeldus",
Title: "Uhiuus postitus"
Title: title
}
fetch("/api/foorum",
{
@@ -44,7 +49,7 @@
'Content-Type': 'application/json'
},
body: JSON.stringify(dto)
});
}).then(resp => getForums());
}
function changeForumTitle(id, title) {
@@ -61,8 +66,17 @@
});
}
function searchForumAuthor(author) {
fetch("/api/search?author="+author).then(resp => {
function deleteForum(id, permanent) {
var q = "";
if (permanent) {
q = "?permanent=true";
}
fetch("/api/foorum/"+id+q, { method: 'DELETE'});
}
function searchForum(what, author) {
fetch("/api/search?"+what+"="+author).then(resp => {
return resp.json();
}).then(data => {
console.log(data);