Advertisement
madrahimov

Untitled

Feb 14th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. const StoresStore = {
  2. namespaced: true,
  3. state: {
  4. stores: [],
  5. store: {},
  6. errors: {},
  7. progress: '',
  8. pagination: {}
  9. },
  10. mutations: {
  11. one(state, data) {
  12. state.errors = {}
  13. state.store = data.store;
  14. return state;
  15. },
  16. many(state, data) {
  17. state.stores= data.stores;
  18. state.pagination = data.pagination;
  19. return state;
  20. },
  21. progress(state, step) {
  22. state.progress = step;
  23. return state.progress;
  24. },
  25. errors(state, data) {
  26. state.errors = helpers.showErrors(data);
  27. return state.errors;
  28. }
  29. },
  30. actions: {
  31. index(context, query) {
  32. $.ajax({
  33. url: `stores?${query}`,
  34. type: 'get',
  35. data: query,
  36. success: function(data) {
  37. context.commit('many', data)
  38. }
  39. })
  40. },
  41. new(context, id) {
  42. $.ajax({
  43. url: `stores/new`,
  44. type: 'get',
  45. success: function(data) {
  46. context.commit('one', data)
  47. }
  48. })
  49. },
  50. create(context, form) {
  51. context.commit('progress', 'loading')
  52. return new Promise((resolve, reject) => {
  53. $.ajax({
  54. url: `stores`,
  55. type: 'post',
  56. data: {
  57. musician: form
  58. },
  59. success: function(data) {
  60. context.commit('progress', 'success')
  61. resolve(data);
  62. },
  63. error: function(data) {
  64. context.commit('progress', 'failed')
  65. context.commit('errors', data)
  66. }
  67. })
  68. })
  69. },
  70. edit(context, id) {
  71. $.ajax({
  72. url: `stores/${id}/edit`,
  73. type: 'get',
  74. success: function(data) {
  75. context.commit('one', data);
  76. }
  77. });
  78. },
  79. update(context, musician) {
  80. context.commit('progress', 'loading')
  81. $.ajax({
  82. url: `stores/${musician.id}`,
  83. type: 'put',
  84. data: {
  85. musician: musician
  86. },
  87. success: function(data) {
  88. context.commit('progress', 'success')
  89. context.commit('one', data);
  90. },
  91. error: function(data) {
  92. context.commit('progress', 'failed')
  93. context.commit('errors', data);
  94. }
  95. })
  96. },
  97. destroy(context, musician_id) {
  98. return new Promise((resolve, reject) => {
  99. $.ajax({
  100. url: `stores/${musician_id}`,
  101. type: 'delete',
  102. success: function(data) {
  103. resolve(data);
  104. },
  105. error: function(data) {
  106. reject(data);
  107. }
  108. });
  109. });
  110. }
  111. }
  112. };
  113.  
  114. export default StoresStore;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement