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.

107 lines
2.1 KiB

  1. import Vue from 'vue';
  2. import annotationMixin from './demo_mixin';
  3. Vue.use(require('vue-shortkey'));
  4. const vm = new Vue({
  5. el: '#mail-app',
  6. delimiters: ['[[', ']]'],
  7. data: {
  8. newTodo: '',
  9. editedTodo: null,
  10. docs: [{
  11. id: 1,
  12. text: 'If it had not been for his help, I would have failed.',
  13. },
  14. {
  15. id: 10,
  16. text: 'According to this magazine, my favorite actress will marry a jazz musician next spring.',
  17. },
  18. {
  19. id: 11,
  20. text: "It's not always possible to eat well when you are traveling in this part of the world.",
  21. },
  22. {
  23. id: 12,
  24. text: "It's still early. We should all just chill for a bit.",
  25. },
  26. {
  27. id: 13,
  28. text: "She got a master's degree three years ago.",
  29. },
  30. {
  31. id: 13,
  32. text: 'We adopted an alternative method.',
  33. },
  34. ],
  35. annotations: [
  36. [
  37. {
  38. id: 1,
  39. text: "S'il ne m'avait pas aidé, j'aurais échoué.",
  40. },
  41. {
  42. id: 2,
  43. text: "S'il ne m'avait pas aidée, j'aurais échoué.",
  44. },
  45. ],
  46. [],
  47. [],
  48. [],
  49. [],
  50. [],
  51. ],
  52. },
  53. mixins: [annotationMixin],
  54. directives: {
  55. 'todo-focus': function(el, binding) {
  56. if (binding.value) {
  57. el.focus();
  58. }
  59. },
  60. },
  61. methods: {
  62. addTodo() {
  63. const value = this.newTodo && this.newTodo.trim();
  64. if (!value) {
  65. return;
  66. }
  67. const payload = {
  68. text: value,
  69. id: this.annotationId++,
  70. };
  71. this.annotations[this.pageNumber].push(payload);
  72. this.newTodo = '';
  73. },
  74. removeTodo(todo) {
  75. const index = this.annotations[this.pageNumber].indexOf(todo);
  76. this.annotations[this.pageNumber].splice(index, 1);
  77. },
  78. editTodo(todo) {
  79. this.beforeEditCache = todo.text;
  80. this.editedTodo = todo;
  81. },
  82. doneEdit(todo) {
  83. if (!this.editedTodo) {
  84. return;
  85. }
  86. this.editedTodo = null;
  87. todo.text = todo.text.trim();
  88. if (!todo.text) {
  89. this.removeTodo(todo);
  90. }
  91. },
  92. cancelEdit(todo) {
  93. this.editedTodo = null;
  94. todo.text = this.beforeEditCache;
  95. },
  96. },
  97. });