settings.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use strict';
  2. var Vue = require('vue'),
  3. Core = require('./core.js');
  4. var vueSettings = new Vue({
  5. el: '#settings',
  6. data: {
  7. settings: Core.settings.data,
  8. open: false,
  9. importFile: null
  10. },
  11. methods: {
  12. show: function () {
  13. this.open = true;
  14. },
  15. hide: function () {
  16. this.open = false;
  17. },
  18. toggleSettings: function () {
  19. if (this.open) this.hide();
  20. else this.show();
  21. },
  22. saveSettings: function () {
  23. Core.settings.set(this.settings);
  24. Core.settings.save(function (error) {
  25. if (error) return console.error(error);
  26. vueSettings.hide();
  27. });
  28. },
  29. exportThings: function () {
  30. Core.things.export();
  31. vueSettings.hide();
  32. },
  33. importFileChanged: function () {
  34. this.importFile = this.$els.importfile.files[0];
  35. },
  36. importThings: function () {
  37. var data = new FormData();
  38. data.append('import', this.$els.importfile.files[0]);
  39. Core.things.import(data, function (error) {
  40. if (error) console.error(error);
  41. vueSettings.hide();
  42. vueSettings.importFile = null;
  43. // TODO refresh
  44. });
  45. },
  46. importThingsCancel: function () {
  47. this.importFile = null;
  48. },
  49. triggerImportInput: function () {
  50. this.$els.importfile.click();
  51. },
  52. logout: function () {
  53. vueSettings.hide();
  54. Core.session.logout();
  55. }
  56. }
  57. });
  58. module.exports = vueSettings;