Attendee.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. },
  52. beforeCreate: function() {
  53. this.attendeesUrl = this.$resource('attendees{/id}');
  54. },
  55. methods: {
  56. isAuthorized(ownerID) {
  57. return !ownerID || this.$store.state.loggedInUser.isAdmin || (this.$store.state.loggedInUser._id && this.$store.state.loggedInUser._id == ownerID);
  58. },
  59. editAttendee() {
  60. this.edit = true;
  61. // FIXME: it's so wrong it hurts, but any other attempt to set the focus
  62. // failed, being called too early. Also, I don't know how I can access
  63. // Vue.nextTick from here.
  64. var that = this;
  65. setTimeout(function() { that.$refs.updateAttendeeName.$el.focus(); }, 400);
  66. },
  67. updateAttendee() {
  68. this.attendeesUrl.update({id: this.attendee._id}, this.attendee).then((response) => {
  69. return response.json();
  70. }, (response) => {
  71. this.$refs.dialogObj.show({text: 'unable to update the attendee'});
  72. }).then((json) => {
  73. this.edit = false;
  74. this.$emit('updated');
  75. });
  76. },
  77. deleteAttendee() {
  78. this.attendeesUrl.delete({id: this.attendee._id}).then((response) => {
  79. return response.json();
  80. }, (response) => {
  81. this.$refs.dialogObj.show({text: 'unable to delete the attendee'});
  82. }).then((json) => {
  83. this.$emit('updated');
  84. });
  85. }
  86. },
  87. components: { IbtDialog, VueMarkdown }
  88. };
  89. </script>
  90. <style>
  91. .md-list-item .md-list-item-holder>.md-icon:first-child {
  92. margin-right: 16px;
  93. }
  94. .attendee-list-item {
  95. min-width: 250px;
  96. }
  97. .attendee-list-item button {
  98. padding-left: 0px !important;
  99. padding-right: 0px !important;
  100. }
  101. .attendee-notes {
  102. font-style: italic !important;
  103. }
  104. .notes-editor-list-item {
  105. margin-bottom: 0px !important;
  106. padding-left: 16px;
  107. }
  108. .notes-editor-list-item ul {
  109. padding-top: 0px !important;
  110. padding-bottom: 0px !important;
  111. }
  112. .notes-editor-list-item .md-theme-default.md-list {
  113. background-color: transparent;
  114. }
  115. .notes-editor-list-item button:hover {
  116. background-color: transparent !important;
  117. }
  118. .attendee-notes {
  119. max-width: 120px;
  120. }
  121. .attendee-notes > p {
  122. margin: 0px;
  123. }
  124. </style>