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
20 v-if="devs.includes(st.user.id)"
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="devs.includes(st.user.id)")
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 { getDate, getTime } from "@/utils/datetime";
47 import { processModalClick } from "@/utils/modalClick";
52 devs: [1], //for now the only dev is me
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: "" },
68 data: { cursor: this.cursor },
70 // The returned list is sorted from most recent to oldest
71 this.newsList = res.newsList;
72 const L = res.newsList.length;
73 if (L > 0) this.cursor = res.newsList[L - 1].added;
74 else this.hasMore = false;
80 // Mark that I've read the news:
81 localStorage.setItem("newsRead", Date.now());
82 if (this.st.user.id > 0) ajax("/newsread", "PUT");
83 document.getElementById("newsMenu").classList.remove("somenews");
85 .getElementById("newnewsDiv")
86 .addEventListener("click", processModalClick);
89 formatDatetime: function(dt) {
90 const dtObj = new Date(dt);
91 const timePart = getTime(dtObj);
92 // Show minutes but not seconds:
94 getDate(dtObj) + " " + timePart.substr(0, timePart.lastIndexOf(":"))
97 parseHtml: function(txt) {
98 return !txt.match(/<[/a-zA-Z]+>/)
99 ? txt.replace(/\n/g, "<br/>") //no HTML tag
102 adjustHeight: function() {
103 const newsContent = document.getElementById("newsContent");
104 // https://stackoverflow.com/a/995374
105 newsContent.style.height = "1px";
106 newsContent.style.height = 10 + newsContent.scrollHeight + "px";
108 resetCurnews: function() {
110 this.curnews.content = "";
111 // No need for added and uid fields: never updated
113 gotoPrevNext: function(n, dir) {
114 document.getElementById("n" + n.id)[
115 (dir < 0 ? "previous" : "next") + "ElementSibling"].scrollIntoView();
117 showModalNews: function() {
119 window.doClick("modalNews");
121 sendNews: function() {
122 const edit = this.curnews.id > 0;
123 this.infoMsg = "Processing... Please wait";
126 edit ? "PUT" : "POST",
128 data: { news: this.curnews },
131 let n = this.newsList.find(n => n.id == this.curnews.id);
132 if (!!n) n.content = this.curnews.content;
135 content: this.curnews.content,
137 uid: this.st.user.id,
140 this.newsList = [newNews].concat(this.newsList);
142 document.getElementById("modalNews").checked = false;
149 editNews: function(n) {
150 this.curnews.content = n.content;
151 this.curnews.id = n.id;
152 // No need for added and uid fields: never updated
153 window.doClick("modalNews");
155 deleteNews: function(n) {
156 if (confirm(this.st.tr["Are you sure?"])) {
157 this.infoMsg = "Processing... Please wait";
164 const nIdx = this.newsList.findIndex(nw => nw.id == n.id);
165 this.newsList.splice(nIdx, 1);
167 document.getElementById("modalNews").checked = false;
173 loadMore: function() {
178 data: { cursor: this.cursor },
180 const L = res.newsList.length;
182 this.newsList = this.newsList.concat(res.newsList);
183 this.cursor = res.newsList[L - 1].added;
184 } else this.hasMore = false;
194 [type="checkbox"].modal+div .card
211 button#writeNewsBtn, button#loadMoreBtn
217 padding: 0 5px 0 var(--universal-margin)
222 display: inline-block
224 margin: var(--universal-margin)
234 border-top: 1px solid grey
235 @media screen and (max-width: 767px)