EditStation.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div>
  3. <modal title='Edit Station'>
  4. <div slot='body'>
  5. <label class='label'>Display name</label>
  6. <div class='control is-grouped'>
  7. <p class='control is-expanded'>
  8. <input class='input' type='text' placeholder='Station Display Name' v-model='editing.displayName' autofocus>
  9. </p>
  10. <p class='control'>
  11. <a class='button is-info' @click='updateDisplayName()' href='#'>Update</a>
  12. </p>
  13. </div>
  14. <label class='label'>Description</label>
  15. <div class='control is-grouped'>
  16. <p class='control is-expanded'>
  17. <input class='input' type='text' placeholder='Station Display Name' v-model='editing.description'>
  18. </p>
  19. <p class='control'>
  20. <a class='button is-info' @click='updateDescription()' href='#'>Update</a>
  21. </p>
  22. </div>
  23. <label class='label'>Privacy</label>
  24. <div class='control is-grouped'>
  25. <p class='control is-expanded'>
  26. <span class='select'>
  27. <select v-model='editing.privacy'>
  28. <option :value='"public"'>Public</option>
  29. <option :value='"unlisted"'>Unlisted</option>
  30. <option :value='"private"'>Private</option>
  31. </select>
  32. </span>
  33. </p>
  34. <p class='control'>
  35. <a class='button is-info' @click='updatePrivacy()' href='#'>Update</a>
  36. </p>
  37. </div>
  38. <div class='control is-grouped' v-if="editing.type === 'community'">
  39. <p class="control is-expanded party-mode-outer">
  40. <label class="checkbox party-mode-inner">
  41. <input type="checkbox" v-model="editing.partyMode">
  42. &nbsp;Party mode
  43. </label>
  44. </p>
  45. <p class='control'>
  46. <a class='button is-info' @click='updatePartyMode()' href='#'>Update</a>
  47. </p>
  48. </div>
  49. <button class='button is-danger' @click='deleteStation()' v-if="$parent.type === 'community'">Delete station</button>
  50. </div>
  51. </modal>
  52. </div>
  53. </template>
  54. <script>
  55. import { Toast } from 'vue-roaster';
  56. import Modal from './Modal.vue';
  57. import io from '../../io';
  58. export default {
  59. data: function() {
  60. return {
  61. editing: {
  62. _id: '',
  63. type: '',
  64. displayName: '',
  65. description: '',
  66. privacy: 'private',
  67. partyMode: false
  68. }
  69. }
  70. },
  71. methods: {
  72. updateDisplayName: function () {
  73. let _this = this;
  74. this.socket.emit('stations.updateDisplayName', this.editing._id, this.editing.displayName, res => {
  75. if (res.status === 'success') {
  76. if (_this.$parent.station) _this.$parent.station.displayName = _this.editing.displayName;
  77. else {
  78. _this.$parent.stations.forEach((station, index) => {
  79. if (station._id === _this.editing._id) return _this.$parent.stations[index].displayName = _this.editing.displayName;
  80. });
  81. }
  82. }
  83. Toast.methods.addToast(res.message, 8000);
  84. });
  85. },
  86. updateDescription: function () {
  87. let _this = this;
  88. this.socket.emit('stations.updateDescription', this.editing._id, this.editing.description, res => {
  89. if (res.status === 'success') {
  90. if (_this.$parent.station) _this.$parent.station.description = _this.editing.description;
  91. else {
  92. _this.$parent.stations.forEach((station, index) => {
  93. if (station._id === station._id) return _this.$parent.stations[index].description = _this.editing.description;
  94. });
  95. }
  96. return Toast.methods.addToast(res.message, 4000);
  97. }
  98. Toast.methods.addToast(res.message, 8000);
  99. });
  100. },
  101. updatePrivacy: function () {
  102. let _this = this;
  103. this.socket.emit('stations.updatePrivacy', this.editing._id, this.editing.privacy, res => {
  104. if (res.status === 'success') {
  105. if (_this.$parent.station) _this.$parent.station.privacy = _this.editing.privacy;
  106. else {
  107. _this.$parent.stations.forEach((station, index) => {
  108. if (station._id === station._id) return _this.$parent.stations[index].privacy = _this.editing.privacy;
  109. });
  110. }
  111. return Toast.methods.addToast(res.message, 4000);
  112. }
  113. Toast.methods.addToast(res.message, 8000);
  114. });
  115. },
  116. updatePartyMode: function () {
  117. let _this = this;
  118. this.socket.emit('stations.updatePartyMode', this.editing._id, this.editing.partyMode, res => {
  119. if (res.status === 'success') {
  120. if (_this.$parent.station) _this.$parent.station.partyMode = _this.editing.partyMode;
  121. else {
  122. _this.$parent.stations.forEach((station, index) => {
  123. if (station._id === station._id) return _this.$parent.stations[index].partyMode = _this.editing.partyMode;
  124. });
  125. }
  126. return Toast.methods.addToast(res.message, 4000);
  127. }
  128. Toast.methods.addToast(res.message, 8000);
  129. });
  130. },
  131. deleteStation: function() {
  132. let _this = this;
  133. this.socket.emit('stations.remove', this.editing._id, res => {
  134. Toast.methods.addToast(res.message, 8000);
  135. if (res.status === 'success' && _this.$parent.station) location.href = '/';
  136. });
  137. }
  138. },
  139. ready: function () {
  140. let _this = this;
  141. io.getSocket(socket => {
  142. _this.socket = socket;
  143. });
  144. },
  145. events: {
  146. closeModal: function() {
  147. this.$parent.modals.editStation = false;
  148. },
  149. editStation: function(station) {
  150. for (let prop in station) {
  151. this.editing[prop] = station[prop];
  152. }
  153. this.$parent.modals.editStation = true;
  154. }
  155. },
  156. components: { Modal }
  157. }
  158. </script>
  159. <style type='scss' scoped>
  160. .controls {
  161. display: flex;
  162. a {
  163. display: flex;
  164. align-items: center;
  165. }
  166. }
  167. .table { margin-bottom: 0; }
  168. h5 { padding: 20px 0; }
  169. .party-mode-inner, .party-mode-outer {
  170. display: flex;
  171. align-items: center;
  172. }
  173. </style>