You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.7 KiB

  1. import Vue from 'vue';
  2. import annotationMixin from './mixin';
  3. import HTTP from './http';
  4. Vue.use(require('vue-shortkey'));
  5. const vm = new Vue({
  6. el: '#mail-app',
  7. delimiters: ['[[', ']]'],
  8. data: {
  9. newTodo: '',
  10. editedTodo: null,
  11. },
  12. mixins: [annotationMixin],
  13. directives: {
  14. 'todo-focus': function(el, binding) {
  15. if (binding.value) {
  16. el.focus();
  17. }
  18. },
  19. },
  20. methods: {
  21. addTodo() {
  22. const value = this.newTodo && this.newTodo.trim();
  23. if (!value) {
  24. return;
  25. }
  26. const docId = this.docs[this.pageNumber].id;
  27. const payload = {
  28. text: value,
  29. };
  30. HTTP.post(`docs/${docId}/annotations/`, payload).then((response) => {
  31. this.annotations[this.pageNumber].push(response.data);
  32. });
  33. this.newTodo = '';
  34. },
  35. removeTodo(todo) {
  36. const docId = this.docs[this.pageNumber].id;
  37. HTTP.delete(`docs/${docId}/annotations/${todo.id}`).then((response) => {
  38. const index = this.annotations[this.pageNumber].indexOf(todo);
  39. this.annotations[this.pageNumber].splice(index, 1);
  40. });
  41. },
  42. editTodo(todo) {
  43. this.beforeEditCache = todo.text;
  44. this.editedTodo = todo;
  45. },
  46. doneEdit(todo) {
  47. if (!this.editedTodo) {
  48. return;
  49. }
  50. this.editedTodo = null;
  51. todo.text = todo.text.trim();
  52. if (!todo.text) {
  53. this.removeTodo(todo);
  54. }
  55. const docId = this.docs[this.pageNumber].id;
  56. HTTP.put(`docs/${docId}/annotations/${todo.id}`, todo).then((response) => {
  57. console.log(response);
  58. });
  59. },
  60. cancelEdit(todo) {
  61. this.editedTodo = null;
  62. todo.text = this.beforeEditCache;
  63. },
  64. },
  65. });