3 input#modalNews.modal(type="checkbox")
6 data-checkbox="modalNews"
9 label.modal-close(for="modalNews")
11 v-model="curnews.content"
12 :placeholder="st.tr['News go here']"
15 button(@click="sendNews()") {{ st.tr["Send"] }}
16 #dialog.text-center {{ st.tr[infoMsg] }}
18 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
21 @click="showModalNews"
23 | {{ st.tr["Write news"] }}
25 v-for="n,idx in newsList"
27 :class="{margintop:idx>0}"
29 span.ndt {{ formatDatetime(n.added) }}
30 .dev-buttons(v-if="devTeam")
31 button(@click="editNews(n)") {{ st.tr["Edit"] }}
32 button(@click="deleteNews(n)") {{ st.tr["Delete"] }}
33 button(@click="gotoPrevNext(n, 1)") {{ st.tr["Previous_n"] }}
34 button(@click="gotoPrevNext(n, -1)") {{ st.tr["Next_n"] }}
35 .news-content(v-html="parseHtml(n.content)")
40 | {{ st.tr["Load more"] }}
44 import { store } from "@/store";
45 import { ajax } from "@/utils/ajax";
46 import params from "@/parameters";
47 import { getDate, getTime } from "@/utils/datetime";
48 import { processModalClick } from "@/utils/modalClick";
54 // timestamp of oldest showed news:
55 cursor: Number.MAX_SAFE_INTEGER,
56 // hasMore == TRUE: a priori there could be more news to load
58 curnews: { id: 0, content: "" },
65 return params.devs.includes(this.st.user.id);
73 data: { cursor: this.cursor },
75 // The returned list is sorted from most recent to oldest
76 this.newsList = res.newsList;
77 const L = res.newsList.length;
78 if (L > 0) this.cursor = res.newsList[L - 1].added;
79 else this.hasMore = false;
85 // Mark that I've read the news:
86 localStorage.setItem("newsRead", Date.now());
87 if (this.st.user.id > 0) ajax("/newsread", "PUT");
88 document.getElementById("newsMenu").classList.remove("somenews");
90 .getElementById("newnewsDiv")
91 .addEventListener("click", processModalClick);
94 formatDatetime: function(dt) {
95 const dtObj = new Date(dt);
96 const timePart = getTime(dtObj);
97 // Show minutes but not seconds:
99 getDate(dtObj) + " " + timePart.substr(0, timePart.lastIndexOf(":"))
102 parseHtml: function(txt) {
103 return !txt.match(/<[/a-zA-Z]+>/)
104 ? txt.replace(/\n/g, "<br/>") //no HTML tag
107 adjustHeight: function() {
108 const newsContent = document.getElementById("newsContent");
109 // https://stackoverflow.com/a/995374
110 newsContent.style.height = "1px";
111 newsContent.style.height = 10 + newsContent.scrollHeight + "px";
113 resetCurnews: function() {
115 this.curnews.content = "";
116 // No need for added and uid fields: never updated
118 gotoPrevNext: function(n, dir) {
119 document.getElementById("n" + n.id)[
120 (dir < 0 ? "previous" : "next") + "ElementSibling"].scrollIntoView();
122 showModalNews: function() {
124 window.doClick("modalNews");
126 sendNews: function() {
127 const edit = this.curnews.id > 0;
128 this.infoMsg = "Processing... Please wait";
131 edit ? "PUT" : "POST",
133 data: { news: this.curnews },
136 let n = this.newsList.find(n => n.id == this.curnews.id);
137 if (!!n) n.content = this.curnews.content;
140 content: this.curnews.content,
142 uid: this.st.user.id,
145 this.newsList = [newNews].concat(this.newsList);
147 document.getElementById("modalNews").checked = false;
154 editNews: function(n) {
155 this.curnews.content = n.content;
156 this.curnews.id = n.id;
157 // No need for added and uid fields: never updated
158 window.doClick("modalNews");
160 deleteNews: function(n) {
161 if (confirm(this.st.tr["Are you sure?"])) {
162 this.infoMsg = "Processing... Please wait";
169 const nIdx = this.newsList.findIndex(nw => nw.id == n.id);
170 this.newsList.splice(nIdx, 1);
172 document.getElementById("modalNews").checked = false;
178 loadMore: function() {
183 data: { cursor: this.cursor },
185 const L = res.newsList.length;
187 this.newsList = this.newsList.concat(res.newsList);
188 this.cursor = res.newsList[L - 1].added;
189 } else this.hasMore = false;
198 <style lang="sass" scoped>
199 [type="checkbox"].modal+div .card
216 button#writeNewsBtn, button#loadMoreBtn
222 padding: 0 5px 0 var(--universal-margin)
226 border-top: 1px solid grey
227 @media screen and (max-width: 767px)
236 display: inline-block
238 margin: var(--universal-margin)