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.

50 lines
1.1 KiB

  1. import Vue from 'vue';
  2. import HTTP from './http';
  3. const vm = new Vue({
  4. el: '#mail-app',
  5. delimiters: ['[[', ']]'],
  6. data: {
  7. labels: [],
  8. labelText: '',
  9. selectedShortkey: '',
  10. backgroundColor: '#209cee',
  11. textColor: '#ffffff',
  12. },
  13. methods: {
  14. addLabel() {
  15. const payload = {
  16. text: this.labelText,
  17. shortcut: this.selectedShortkey,
  18. background_color: this.backgroundColor,
  19. text_color: this.textColor,
  20. };
  21. HTTP.post('labels/', payload).then((response) => {
  22. this.reset();
  23. this.labels.push(response.data);
  24. });
  25. },
  26. removeLabel(label) {
  27. const labelId = label.id;
  28. HTTP.delete(`labels/${labelId}`).then((response) => {
  29. const index = this.labels.indexOf(label);
  30. this.labels.splice(index, 1);
  31. });
  32. },
  33. reset() {
  34. this.labelText = '';
  35. this.selectedShortkey = '';
  36. this.backgroundColor = '#209cee';
  37. this.textColor = '#ffffff';
  38. },
  39. },
  40. created() {
  41. HTTP.get('labels').then((response) => {
  42. this.labels = response.data;
  43. });
  44. },
  45. });