EditStation.vue 6.9 KB

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