logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

announcement.js (2873B)


  1. import { mapState } from 'vuex'
  2. import AnnouncementEditor from '../announcement_editor/announcement_editor.vue'
  3. import RichContent from '../rich_content/rich_content.jsx'
  4. import localeService from '../../services/locale/locale.service.js'
  5. const Announcement = {
  6. components: {
  7. AnnouncementEditor,
  8. RichContent
  9. },
  10. data () {
  11. return {
  12. editing: false,
  13. editedAnnouncement: {
  14. content: '',
  15. startsAt: undefined,
  16. endsAt: undefined,
  17. allDay: undefined
  18. },
  19. editError: ''
  20. }
  21. },
  22. props: {
  23. announcement: Object
  24. },
  25. computed: {
  26. ...mapState({
  27. currentUser: state => state.users.currentUser
  28. }),
  29. canEditAnnouncement () {
  30. return this.currentUser && this.currentUser.privileges.includes('announcements_manage_announcements')
  31. },
  32. content () {
  33. return this.announcement.content
  34. },
  35. isRead () {
  36. return this.announcement.read
  37. },
  38. publishedAt () {
  39. const time = this.announcement.published_at
  40. if (!time) {
  41. return
  42. }
  43. return this.formatTimeOrDate(time, localeService.internalToBrowserLocale(this.$i18n.locale))
  44. },
  45. startsAt () {
  46. const time = this.announcement.starts_at
  47. if (!time) {
  48. return
  49. }
  50. return this.formatTimeOrDate(time, localeService.internalToBrowserLocale(this.$i18n.locale))
  51. },
  52. endsAt () {
  53. const time = this.announcement.ends_at
  54. if (!time) {
  55. return
  56. }
  57. return this.formatTimeOrDate(time, localeService.internalToBrowserLocale(this.$i18n.locale))
  58. },
  59. inactive () {
  60. return this.announcement.inactive
  61. }
  62. },
  63. methods: {
  64. markAsRead () {
  65. if (!this.isRead) {
  66. return this.$store.dispatch('markAnnouncementAsRead', this.announcement.id)
  67. }
  68. },
  69. deleteAnnouncement () {
  70. return this.$store.dispatch('deleteAnnouncement', this.announcement.id)
  71. },
  72. formatTimeOrDate (time, locale) {
  73. const d = new Date(time)
  74. return this.announcement.all_day ? d.toLocaleDateString(locale) : d.toLocaleString(locale)
  75. },
  76. enterEditMode () {
  77. this.editedAnnouncement.content = this.announcement.pleroma.raw_content
  78. this.editedAnnouncement.startsAt = this.announcement.starts_at
  79. this.editedAnnouncement.endsAt = this.announcement.ends_at
  80. this.editedAnnouncement.allDay = this.announcement.all_day
  81. this.editing = true
  82. },
  83. submitEdit () {
  84. this.$store.dispatch('editAnnouncement', {
  85. id: this.announcement.id,
  86. ...this.editedAnnouncement
  87. })
  88. .then(() => {
  89. this.editing = false
  90. })
  91. .catch(error => {
  92. this.editError = error.error
  93. })
  94. },
  95. cancelEdit () {
  96. this.editing = false
  97. },
  98. clearError () {
  99. this.editError = undefined
  100. }
  101. }
  102. }
  103. export default Announcement