Attendee.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <md-list-item class="attendee-list-item md-double-line" :key="attendee._id">
  3. <md-icon>person</md-icon>
  4. <div v-if="!edit" class="md-list-text-container">
  5. <span>{{ attendee.name }}</span>
  6. <vue-markdown v-if="attendee.notes" class="attendee-notes" :source="attendee.notes" :break="false"></vue-markdown>
  7. </div>
  8. <div v-if="edit">
  9. <md-input-container md-inline>
  10. <md-input @keyup.enter.native="updateAttendee()" @keydown.esc.native="edit = false" v-model="attendee.name" ref="updateAttendeeName" />
  11. </md-input-container>
  12. <div class="notes-editor-list-item">
  13. <md-input-container md-inline>
  14. <label>notes</label>
  15. <md-input @keyup.enter.native="updateAttendee()" @keydown.esc.native="edit = false" v-model="attendee.notes" />
  16. </md-input-container>
  17. </div>
  18. </div>
  19. <md-menu v-if="isAuthorized(attendee.created_by) && !edit" md-align-trigger>
  20. <md-button class="md-icon-button" md-menu-trigger>
  21. <md-icon>more_vert</md-icon>
  22. </md-button>
  23. <md-menu-content>
  24. <md-menu-item @click="editAttendee()">
  25. <span>edit</span>
  26. <md-icon>edit</md-icon>
  27. </md-menu-item>
  28. <md-menu-item @click="deleteAttendee()">
  29. <span>delete</span>
  30. <md-icon>cancel</md-icon>
  31. </md-menu-item>
  32. </md-menu-content>
  33. </md-menu>
  34. <ibt-dialog ref="dialogObj" />
  35. </md-list-item>
  36. </template>
  37. <script>
  38. import IbtDialog from './IbtDialog.vue';
  39. import VueMarkdown from 'vue-markdown';
  40. export default {
  41. props: {attendee: {default: {}}},
  42. data: function () {
  43. return {
  44. edit: false
  45. }
  46. },
  47. computed: {
  48. loggedInUser() {
  49. return this.$store.state.loggedInUser;
  50. },
  51. settings() {
  52. return this.$store.state.settings || {};
  53. }
  54. },
  55. beforeCreate: function() {
  56. this.attendeesUrl = this.$resource('attendees{/id}');
  57. },
  58. methods: {
  59. isAuthorized(ownerID) {
  60. return (!ownerID && !this.$store.state.settings.protectUnregistered) || this.$store.state.loggedInUser.isAdmin || (this.$store.state.loggedInUser._id && this.$store.state.loggedInUser._id == ownerID);
  61. },
  62. editAttendee() {
  63. this.edit = true;
  64. // FIXME: it's so wrong it hurts, but any other attempt to set the focus
  65. // failed, being called too early. Also, I don't know how I can access
  66. // Vue.nextTick from here.
  67. var that = this;
  68. setTimeout(function() { that.$refs.updateAttendeeName.$el.focus(); }, 400);
  69. },
  70. updateAttendee() {
  71. this.attendeesUrl.update({id: this.attendee._id}, this.attendee).then((response) => {
  72. return response.json();
  73. }, (response) => {
  74. this.$refs.dialogObj.show({text: 'unable to update the attendee'});
  75. }).then((json) => {
  76. this.edit = false;
  77. this.$emit('updated');
  78. });
  79. },
  80. deleteAttendee() {
  81. this.attendeesUrl.delete({id: this.attendee._id}).then((response) => {
  82. return response.json();
  83. }, (response) => {
  84. this.$refs.dialogObj.show({text: 'unable to delete the attendee'});
  85. }).then((json) => {
  86. this.$emit('updated');
  87. });
  88. }
  89. },
  90. components: { IbtDialog, VueMarkdown }
  91. };
  92. </script>
  93. <style>
  94. .md-list-item .md-list-item-holder>.md-icon:first-child {
  95. margin-right: 16px;
  96. }
  97. .attendee-list-item {
  98. min-width: 250px;
  99. }
  100. .attendee-list-item button {
  101. padding-left: 0px !important;
  102. padding-right: 0px !important;
  103. }
  104. .attendee-notes {
  105. font-style: italic !important;
  106. }
  107. .notes-editor-list-item {
  108. margin-bottom: 0px !important;
  109. padding-left: 16px;
  110. }
  111. .notes-editor-list-item ul {
  112. padding-top: 0px !important;
  113. padding-bottom: 0px !important;
  114. }
  115. .notes-editor-list-item .md-theme-default.md-list {
  116. background-color: transparent;
  117. }
  118. .notes-editor-list-item button:hover {
  119. background-color: transparent !important;
  120. }
  121. .attendee-notes {
  122. max-width: 120px;
  123. }
  124. .attendee-notes > p {
  125. margin: 0px;
  126. }
  127. </style>