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.5 KiB

  1. axios.defaults.xsrfCookieName = 'csrftoken';
  2. axios.defaults.xsrfHeaderName = 'X-CSRFToken';
  3. var base_url = window.location.href.split('/').slice(3, 5).join('/');
  4. const HTTP = axios.create({
  5. baseURL: `/api/${base_url}/`,
  6. })
  7. var vm = new Vue({
  8. el: '#mail-app',
  9. delimiters: ['[[', ']]'],
  10. data: {
  11. labels: [],
  12. labelText: '',
  13. selectedShortkey: '',
  14. backgroundColor: '#209cee',
  15. textColor: '#ffffff',
  16. },
  17. methods: {
  18. addLabel: function () {
  19. var payload = {
  20. text: this.labelText,
  21. shortcut: this.selectedShortkey,
  22. background_color: this.backgroundColor,
  23. text_color: this.textColor
  24. };
  25. HTTP.post('labels/', payload).then(response => {
  26. this.reset();
  27. this.labels.push(response.data);
  28. })
  29. },
  30. removeLabel: function (label) {
  31. var label_id = label.id;
  32. HTTP.delete(`labels/${label_id}`).then(response => {
  33. var index = this.labels.indexOf(label)
  34. this.labels.splice(index, 1)
  35. })
  36. },
  37. reset: function () {
  38. this.labelText = '';
  39. this.selectedShortkey = '';
  40. this.backgroundColor = '#209cee';
  41. this.textColor = '#ffffff';
  42. }
  43. },
  44. created: function () {
  45. HTTP.get('labels').then(response => {
  46. this.labels = response.data
  47. })
  48. }
  49. })