X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FNews.vue;h=1aebbd3467f24ba2e61e16e2d6a5869459d0b25d;hb=a041d5d84031f29fc001597a9ac958d6a3e6de76;hp=e23a6e24ffc1530e3d4cae811b5943895fb1622a;hpb=604b951e4dc4647da9b251c5fff4ecb4c7b1b298;p=vchess.git diff --git a/client/src/views/News.vue b/client/src/views/News.vue index e23a6e24..1aebbd34 100644 --- a/client/src/views/News.vue +++ b/client/src/views/News.vue @@ -1,8 +1,11 @@ @@ -41,31 +50,38 @@ export default { st: store.state, cursor: 0, //ID of last showed news hasMore: true, //a priori there could be more news to load - curnews: {id:0, content:""}, + curnews: { id: 0, content: "" }, newsList: [], - infoMsg: "", + infoMsg: "" }; }, created: function() { - ajax("/news", "GET", {cursor:this.cursor}, (res) => { - this.newsList = res.newsList; - const L = res.newsList.length; - if (L > 0) - this.cursor = res.newsList[L-1].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.getElementById("newnewsDiv").addEventListener("click", processModalClick); - }, - computed: { - sortedNewsList: function() { - return this.newsList.sort( (n1,n2) => n1.added - n2.added ); - }, + document + .getElementById("newnewsDiv") + .addEventListener("click", processModalClick); }, methods: { formatDatetime: function(dt) { const dtObj = new Date(dt); - return getDate(dtObj) + " " + getTime(dtObj); + const timePart = getTime(dtObj); + // Show minutes but not seconds: + return ( + getDate(dtObj) + " " + timePart.substr(0, timePart.lastIndexOf(":")) + ); }, parseHtml: function(txt) { return !txt.match(/<[/a-zA-Z]+>/) @@ -76,7 +92,7 @@ export default { const newsContent = document.getElementById("newsContent"); // https://stackoverflow.com/questions/995168/textarea-to-resize-based-on-content-length newsContent.style.height = "1px"; - newsContent.style.height = (10+newsContent.scrollHeight)+"px"; + newsContent.style.height = 10 + newsContent.scrollHeight + "px"; }, resetCurnews: function() { this.curnews.id = 0; @@ -85,7 +101,7 @@ export default { }, showModalNews: function() { this.resetCurnews(); - doClick('modalNews'); + window.doClick("modalNews"); }, sendNews: function() { const edit = this.curnews.id > 0; @@ -93,27 +109,25 @@ export default { 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 = this.newsList.concat([newNews]); + { + 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(); } ); }, @@ -121,34 +135,43 @@ export default { this.curnews.content = n.content; this.curnews.id = n.id; // No need for added and uid fields: never updated - doClick('modalNews'); + window.doClick("modalNews"); }, deleteNews: function(n) { - if (confirm(this.st.tr["Are you sure?"])) - { + 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) + ajax( + "/news", + "GET", { - this.newsList = this.newsList.concat(res.newsList); - const L = res.newsList.length; - if (L > 0) - this.cursor = res.newsList[L-1].id; + 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; + } } - else - this.hasMore = false; - }); - }, - }, + ); + } + } }; @@ -156,11 +179,37 @@ export default { [type="checkbox"].modal+div .card max-width: 767px max-height: 100% + textarea#newsContent + margin: 0 width: 100% min-height: 200px max-height: 100% + #dialog padding: 5px color: blue + +#writeNews + padding-top: 50px + +button#writeNewsBtn, button#loadMoreBtn + margin-top: 0 + margin-bottom: 0 + +span.ndt + color: darkblue + padding: 0 5px 0 var(--universal-margin) + +.news + padding-top: 10px + & > div + display: inline-block + +.margintop + margin-top: 25px + border-top: 1px solid grey +@media screen and (max-width: 767px) + .margintop + margin-top: 10px