thing.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. 'use strict';
  2. var Vue = require('vue'),
  3. Core = require('./core.js');
  4. var vueThingAdd = new Vue({
  5. el: '#modalAdd',
  6. data: {
  7. content: ''
  8. },
  9. created: function () {
  10. $('#modalAdd').on('shown.bs.modal', function () {
  11. $(this).find("[autofocus]:first").focus();
  12. });
  13. },
  14. methods: {
  15. close: function () {
  16. $('#modalAdd').modal('hide');
  17. },
  18. open: function () {
  19. this.content = '';
  20. $('#modalAdd').modal('show');
  21. },
  22. save: function () {
  23. Core.things.add(this.content, function (error) {
  24. if (error) return console.error(error);
  25. vueThingAdd.close();
  26. });
  27. }
  28. }
  29. });
  30. var vueThingEdit = new Vue({
  31. el: '#modalEdit',
  32. data: {
  33. thing: {}
  34. },
  35. created: function () {
  36. $('#modalEdit').on('shown.bs.modal', function () {
  37. $(this).find("[autofocus]:first").focus();
  38. });
  39. },
  40. methods: {
  41. close: function () {
  42. $('#modalEdit').modal('hide');
  43. },
  44. open: function (thing) {
  45. this.thing = thing;
  46. $('#modalEdit').find("[autofocus]:first").focus();
  47. $('#modalEdit').modal('show');
  48. },
  49. save: function () {
  50. Core.things.edit(this.thing, function (error) {
  51. if (error) return console.error(error);
  52. vueThingEdit.close();
  53. });
  54. }
  55. }
  56. });
  57. var vueThingDelete = new Vue({
  58. el: '#modalDel',
  59. data: {
  60. thing: {}
  61. },
  62. methods: {
  63. close: function () {
  64. $('#modalDel').modal('hide');
  65. },
  66. open: function (thing) {
  67. this.thing = thing;
  68. $('#modalDel').modal('show');
  69. },
  70. del: function () {
  71. Core.things.del(this.thing, function (error) {
  72. if (error) return console.error(error);
  73. vueThingDelete.close();
  74. });
  75. }
  76. }
  77. });
  78. module.exports = {
  79. add: vueThingAdd,
  80. edit: vueThingEdit,
  81. del: vueThingDelete
  82. };