Fix
[vchess.git] / client / src / views / News.vue
index a4ce579..664b595 100644 (file)
@@ -17,18 +17,21 @@ main
   .row
     .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
       button#writeNewsBtn(
-        v-if="devs.includes(st.user.id)"
+        v-if="devTeam"
         @click="showModalNews"
       )
         | {{ st.tr["Write news"] }}
       .news(
         v-for="n,idx in newsList"
+        :id="'n' + n.id"
         :class="{margintop:idx>0}"
       )
         span.ndt {{ formatDatetime(n.added) }}
-        .dev-buttons(v-if="devs.includes(st.user.id)")
+        .dev-buttons(v-if="devTeam")
           button(@click="editNews(n)") {{ st.tr["Edit"] }}
           button(@click="deleteNews(n)") {{ st.tr["Delete"] }}
+        button(@click="gotoPrevNext(n, 1)") {{ st.tr["Previous_n"] }}
+        button(@click="gotoPrevNext(n, -1)") {{ st.tr["Next_n"] }}
         .news-content(v-html="parseHtml(n.content)")
       button#loadMoreBtn(
         v-if="hasMore"
@@ -40,13 +43,13 @@ main
 <script>
 import { store } from "@/store";
 import { ajax } from "@/utils/ajax";
+import params from "@/parameters";
 import { getDate, getTime } from "@/utils/datetime";
 import { processModalClick } from "@/utils/modalClick";
 export default {
   name: "my-news",
   data: function() {
     return {
-      devs: [1], //for now the only dev is me
       st: store.state,
       // timestamp of oldest showed news:
       cursor: Number.MAX_SAFE_INTEGER,
@@ -57,6 +60,11 @@ export default {
       infoMsg: ""
     };
   },
+  computed: {
+    devTeam: function() {
+      return params.devs.includes(this.st.user.id);
+    }
+  },
   created: function() {
     ajax(
       "/news",
@@ -98,7 +106,7 @@ export default {
     },
     adjustHeight: function() {
       const newsContent = document.getElementById("newsContent");
-      // https://stackoverflow.com/questions/995168/textarea-to-resize-based-on-content-length
+      // https://stackoverflow.com/a/995374
       newsContent.style.height = "1px";
       newsContent.style.height = 10 + newsContent.scrollHeight + "px";
     },
@@ -107,6 +115,10 @@ export default {
       this.curnews.content = "";
       // No need for added and uid fields: never updated
     },
+    gotoPrevNext: function(n, dir) {
+      document.getElementById("n" + n.id)[
+        (dir < 0 ? "previous" : "next") + "ElementSibling"].scrollIntoView();
+    },
     showModalNews: function() {
       this.resetCurnews();
       window.doClick("modalNews");
@@ -122,7 +134,7 @@ export default {
           success: (res) => {
             if (edit) {
               let n = this.newsList.find(n => n.id == this.curnews.id);
-              if (n) n.content = this.curnews.content;
+              if (!!n) n.content = this.curnews.content;
             } else {
               const newNews = {
                 content: this.curnews.content,
@@ -183,7 +195,7 @@ export default {
 };
 </script>
 
-<style lang="sass">
+<style lang="sass" scoped>
 [type="checkbox"].modal+div .card
   max-width: 767px
   max-height: 100%
@@ -209,6 +221,15 @@ span.ndt
   color: darkblue
   padding: 0 5px 0 var(--universal-margin)
 
+.margintop
+  margin-top: 25px
+  border-top: 1px solid grey
+@media screen and (max-width: 767px)
+  .margintop
+    margin-top: 10px
+</style>
+
+<style lang="sass">
 .news
   padding-top: 10px
   & > .dev-buttons
@@ -221,11 +242,4 @@ span.ndt
       display: block
       margin-top: 10px
       content: " "
-
-.margintop
-  margin-top: 25px
-  border-top: 1px solid grey
-@media screen and (max-width: 767px)
-  .margintop
-    margin-top: 10px
 </style>