Attendee.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <md-list-item :key="attendee._id">
  3. <md-icon>person</md-icon>
  4. <span v-if="!edit">{{attendee.name}}</span>
  5. <md-input-container md-inline v-if="edit">
  6. <md-input @keyup.enter.native="updateAttendee()" v-model="attendee.name" ref="updateAttendeeName" />
  7. </md-input-container>
  8. <md-button class="md-icon-button md-list-action" @click="editAttendee()">
  9. <md-icon>edit</md-icon>
  10. </md-button>
  11. <md-button class="md-icon-button md-list-action" @click="deleteAttendee()">
  12. <md-icon>cancel</md-icon>
  13. </md-button>
  14. </md-list-item>
  15. </template>
  16. <script>
  17. export default {
  18. props: {attendee: {default: {}}},
  19. data: function () {
  20. return {
  21. edit: false
  22. }
  23. },
  24. beforeCreate: function() {
  25. this.attendeesUrl = this.$resource('attendees{/id}');
  26. },
  27. methods: {
  28. editAttendee() {
  29. this.edit = true;
  30. // FIXME: it's so wrong it hurts, but any other attempt to set the focus
  31. // failed, being called too early. Also, I don't know how I can access
  32. // Vue.nextTick from here.
  33. var that = this;
  34. setTimeout(function() { that.$refs.updateAttendeeName.$el.focus(); }, 400);
  35. },
  36. updateAttendee() {
  37. this.attendeesUrl.update({id: this.attendee._id}, this.attendee).then((response) => {
  38. return response.json();
  39. }, (response) => {
  40. alert('updateAttendee: failed to update resource');
  41. }).then((json) => {
  42. this.edit = false;
  43. this.$emit('updated');
  44. });
  45. },
  46. deleteAttendee() {
  47. this.attendeesUrl.delete({id: this.attendee._id}).then((response) => {
  48. return response.json();
  49. }, (response) => {
  50. alert('deleteAttendee: failed to delete resource');
  51. }).then((json) => {
  52. this.$emit('updated');
  53. });
  54. }
  55. }
  56. };
  57. </script>
  58. <style>
  59. .md-list-item .md-list-item-holder>.md-icon:first-child {
  60. margin-right: 16px;
  61. }
  62. </style>