settings.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. $('.backdrop').removeClass('hide');
  15. $('.settings').addClass('open');
  16. },
  17. hide: function () {
  18. this.open = false;
  19. // wait for animation to finish
  20. setTimeout(function () {
  21. $('.backdrop').addClass('hide');
  22. $('.settings').removeClass('open');
  23. }, 500);
  24. },
  25. toggleSettings: function () {
  26. if (this.open) this.hide();
  27. else this.show();
  28. },
  29. saveSettings: function () {
  30. Core.settings.set(this.settings);
  31. Core.settings.save(function (error) {
  32. if (error) return console.error(error);
  33. vueSettings.hide();
  34. });
  35. },
  36. exportThings: function () {
  37. Core.things.export();
  38. vueSettings.hide();
  39. },
  40. importFileChanged: function () {
  41. this.importFile = this.$els.importfile.files[0];
  42. console.log('---', this.importFile)
  43. },
  44. importThings: function () {
  45. var data = new FormData();
  46. data.append('import', this.$els.importfile.files[0]);
  47. Core.things.import(data, function (error) {
  48. if (error) console.error(error);
  49. vueSettings.hide();
  50. vueSettings.importFile = null;
  51. // TODO refresh
  52. });
  53. },
  54. importThingsCancel: function () {
  55. this.importFile = null;
  56. console.log(this.$els.importfile)
  57. },
  58. logout: function () {
  59. vueSettings.hide();
  60. Core.session.logout();
  61. }
  62. }
  63. });
  64. module.exports = vueSettings;