X-Git-Url: https://git.auder.net/?a=blobdiff_plain;ds=sidebyside;f=client%2Fsrc%2Fviews%2FNews.vue;h=1aebbd3467f24ba2e61e16e2d6a5869459d0b25d;hb=e57c4de4148d43e7635e09adcde4e56585aea303;hp=f9e8adcd6f04c6b136167b8364a4a024ef62df24;hpb=e01e086d96f3c0f04761d269e6a34ba0b6014a56;p=vchess.git diff --git a/client/src/views/News.vue b/client/src/views/News.vue index f9e8adcd..1aebbd34 100644 --- a/client/src/views/News.vue +++ b/client/src/views/News.vue @@ -56,11 +56,18 @@ export default { }; }, created: function() { - ajax("/news", "GET", { cursor: this.cursor }, res => { - this.newsList = res.newsList.sort((n1, n2) => n2.added - n1.added); - const L = res.newsList.length; - if (L > 0) this.cursor = this.newsList[0].id; - }); + ajax( + "/news", + "GET", + { + data: { cursor: this.cursor }, + success: (res) => { + this.newsList = res.newsList.sort((n1, n2) => n2.added - n1.added); + const L = res.newsList.length; + if (L > 0) this.cursor = this.newsList[0].id; + } + } + ); }, mounted: function() { document @@ -99,23 +106,30 @@ export default { sendNews: function() { const edit = this.curnews.id > 0; this.infoMsg = "Processing... Please wait"; - ajax("/news", edit ? "PUT" : "POST", { news: this.curnews }, res => { - if (edit) { - let n = this.newsList.find(n => n.id == this.curnews.id); - if (n) n.content = this.curnews.content; - } else { - const newNews = { - content: this.curnews.content, - added: Date.now(), - uid: this.st.user.id, - id: res.id - }; - this.newsList = [newNews].concat(this.newsList); + ajax( + "/news", + edit ? "PUT" : "POST", + { + data: { news: this.curnews }, + success: (res) => { + if (edit) { + let n = this.newsList.find(n => n.id == this.curnews.id); + if (n) n.content = this.curnews.content; + } else { + const newNews = { + content: this.curnews.content, + added: Date.now(), + uid: this.st.user.id, + id: res.id + }; + this.newsList = [newNews].concat(this.newsList); + } + document.getElementById("modalNews").checked = false; + this.infoMsg = ""; + this.resetCurnews(); + } } - document.getElementById("modalNews").checked = false; - this.infoMsg = ""; - this.resetCurnews(); - }); + ); }, editNews: function(n) { this.curnews.content = n.content; @@ -126,22 +140,36 @@ export default { deleteNews: function(n) { if (confirm(this.st.tr["Are you sure?"])) { this.infoMsg = "Processing... Please wait"; - ajax("/news", "DELETE", { id: n.id }, () => { - const nIdx = this.newsList.findIndex(nw => nw.id == n.id); - this.newsList.splice(nIdx, 1); - this.infoMsg = ""; - document.getElementById("modalNews").checked = false; - }); + ajax( + "/news", + "DELETE", + { + data: { id: n.id }, + success: () => { + const nIdx = this.newsList.findIndex(nw => nw.id == n.id); + this.newsList.splice(nIdx, 1); + this.infoMsg = ""; + document.getElementById("modalNews").checked = false; + } + } + ); } }, loadMore: function() { - ajax("/news", "GET", { cursor: this.cursor }, res => { - if (res.newsList.length > 0) { - this.newsList = this.newsList.concat(res.newsList); - const L = res.newsList.length; - if (L > 0) this.cursor = res.newsList[L - 1].id; - } else this.hasMore = false; - }); + ajax( + "/news", + "GET", + { + data: { cursor: this.cursor }, + success: (res) => { + if (res.newsList.length > 0) { + this.newsList = this.newsList.concat(res.newsList); + const L = res.newsList.length; + if (L > 0) this.cursor = res.newsList[L - 1].id; + } else this.hasMore = false; + } + } + ); } } };