RequestTime.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div class="timeslot">
  3. <Multiselect v-model="newValue.timezone" :options="timezones" @input="update" />
  4. <input v-model="newValue.startTime" type="text" class="timeslot--start"
  5. placeholder="08:00" @input="update">
  6. <input v-model="newValue.endTime" type="text" placeholder="18:00"
  7. @input="update">
  8. </div>
  9. </template>
  10. <script>
  11. import { Multiselect } from 'nextcloud-vue/dist/Components/Multiselect'
  12. import moment from 'moment-timezone'
  13. import valueMixin from '../../mixins/valueMixin'
  14. const zones = moment.tz.names()
  15. export default {
  16. name: 'RequestTime',
  17. components: {
  18. Multiselect
  19. },
  20. mixins: [
  21. valueMixin
  22. ],
  23. props: {
  24. value: {
  25. type: String,
  26. default: '1 MB'
  27. }
  28. },
  29. data() {
  30. return {
  31. valid: false,
  32. newValue: {
  33. startTime: null,
  34. endTime: null,
  35. timezone: moment.tz.guess()
  36. }
  37. }
  38. },
  39. computed: {
  40. timezones() {
  41. return zones
  42. }
  43. },
  44. methods: {
  45. updateInternalValue(value) {
  46. var data = JSON.parse(value)
  47. var startTime = data[0].split(' ', 2)[0]
  48. var endTime = data[1].split(' ', 2)[0]
  49. var timezone = data[0].split(' ', 2)[1]
  50. this.newValue = {
  51. startTime: startTime,
  52. endTime: endTime,
  53. timezone: timezone
  54. }
  55. },
  56. validate() {
  57. return this.newValue.startTime && this.newValue.startTime.match(/^(0[0-9]|1[0-9]|2[0-3]|[0-9]):[0-5][0-9]$/i) !== null
  58. && this.newValue.endTime && this.newValue.endTime.match(/^(0[0-9]|1[0-9]|2[0-3]|[0-9]):[0-5][0-9]$/i) !== null
  59. && moment.tz.zone(this.newValue.timezone) !== null
  60. },
  61. update() {
  62. if (this.validate()) {
  63. const output = `["${this.newValue.startTime} ${this.newValue.timezone}","${this.newValue.endTime} ${this.newValue.timezone}"]`
  64. this.$emit('input', output)
  65. this.valid = true
  66. } else {
  67. this.valid = false
  68. }
  69. }
  70. }
  71. }
  72. </script>
  73. <style scoped lang="scss">
  74. .timeslot {
  75. display: flex;
  76. flex-grow: 1;
  77. flex-wrap: wrap;
  78. max-width: 180px;
  79. .multiselect {
  80. width: 100%;
  81. margin-bottom: 5px;
  82. }
  83. input[type=text] {
  84. width: 50%;
  85. margin: 0;
  86. margin-bottom: 5px;
  87. &.timeslot--start {
  88. margin-right: 5px;
  89. width: calc(50% - 5px);
  90. }
  91. }
  92. }
  93. </style>