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.

72 lines
2.0 KiB

  1. import Vue from 'vue';
  2. Vue.use(require('vue-shortkey'));
  3. import annotationMixin from './mixin.js';
  4. import HTTP from './http.js';
  5. var 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: function () {
  22. var value = this.newTodo && this.newTodo.trim()
  23. if (!value) {
  24. return
  25. }
  26. var doc_id = this.items[this.cur].id;
  27. var payload = {text: value}
  28. HTTP.post(`docs/${doc_id}/annotations/`, payload).then(response => {
  29. this.items[this.cur]['labels'].push(response.data)
  30. })
  31. this.newTodo = ''
  32. },
  33. removeTodo: function (todo) {
  34. var doc_id = this.items[this.cur].id;
  35. HTTP.delete(`docs/${doc_id}/annotations/${todo.id}`).then(response => {
  36. this.items[this.cur]['labels'].splice(this.items[this.cur]['labels'].indexOf(todo), 1)
  37. });
  38. },
  39. editTodo: function (todo) {
  40. this.beforeEditCache = todo.text
  41. this.editedTodo = todo
  42. },
  43. doneEdit: function (todo) {
  44. if (!this.editedTodo) {
  45. return
  46. }
  47. this.editedTodo = null
  48. todo.text = todo.text.trim()
  49. if (!todo.text) {
  50. this.removeTodo(todo)
  51. }
  52. var doc_id = this.items[this.cur].id;
  53. HTTP.put(`docs/${doc_id}/annotations/${todo.id}`, todo).then(response => {
  54. console.log(response)
  55. });
  56. },
  57. cancelEdit: function (todo) {
  58. this.editedTodo = null
  59. todo.text = this.beforeEditCache
  60. }
  61. },
  62. created: function () {
  63. this.submit();
  64. }
  65. });