thing.js 2.1 KB

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