Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <div>
  3.     <div class="controller">
  4.       <v-btn @click="changeMonth(-1)" flat icon>
  5.         <v-icon>keyboard_arrow_left</v-icon>
  6.       </v-btn>
  7.       <span>{{ currentDate.format('MMMM') }}</span>
  8.       <v-btn @click="changeMonth(1)" flat icon>
  9.         <v-icon>keyboard_arrow_right</v-icon>
  10.       </v-btn>
  11.     </div>
  12.     <v-card class="time-card" xs12 v-for="day in days" :key="day.day">
  13.       <v-layout row wrap>
  14.         <v-flex xs3 class="date">
  15.           <span>{{ day.day }}</span>
  16.           <div></div>
  17.           <span>{{ day.name }}</span>
  18.         </v-flex>
  19.         <v-flex xs9>
  20.           <TimePicker v-model="day.start" @change="changed = true" label="Van" :required="false" />
  21.           <TimePicker v-model="day.end" @change="changed = true" label="Tot" :required="false" />
  22.         </v-flex>
  23.       </v-layout>
  24.     </v-card>
  25.     <v-dialog v-model="saveChanges" width="500">
  26.       <v-card>
  27.         <v-card-title class="headline grey lighten-2" primary-title>
  28.           Je hebt aanpassingen gemaakt. Wil je deze opslaan?
  29.         </v-card-title>
  30.  
  31.         <v-divider></v-divider>
  32.  
  33.         <v-card-actions>
  34.           <v-btn color="danger" flat @click="changeMonth(false, true)">
  35.             Dismiss
  36.           </v-btn>
  37.           <v-spacer></v-spacer>
  38.           <v-btn color="success" flat @click="submitForm()">
  39.             Save
  40.           </v-btn>
  41.         </v-card-actions>
  42.       </v-card>
  43.     </v-dialog>
  44.     <v-btn @click="submitForm()" fixed fab bottom right color="success">
  45.       <v-icon>save</v-icon>
  46.     </v-btn>
  47.  
  48.     <v-snackbar v-model="saved" :timeout="3000" bottom>Beschikbaarheid opgeslagen</v-snackbar>
  49.   </div>
  50. </template>
  51.  
  52. <script>
  53. import moment from 'moment'
  54. import { FormValidator } from '~/components/form/InputMixin'
  55.  
  56. export default {
  57.   created () {
  58.     this.getDays()
  59.   },
  60.   data: () => ({
  61.     currentDate: moment(),
  62.     days: [],
  63.     saved: false,
  64.     changed: false,
  65.     saveChanges: false,
  66.     addMonths: 0
  67.   }),
  68.   methods: {
  69.     getDays () {
  70.       // Clear days so it can be refilled
  71.       this.days = []
  72.  
  73.       // Month and year for the days
  74.       const month = this.currentDate.month()
  75.       const year = this.currentDate.year()
  76.  
  77.       const names = Object.freeze(
  78.         ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'])
  79.       const date = new Date(year, month, 1)
  80.       let fullDate = ''
  81.  
  82.       setTimeout(() => {
  83.         while (date.getMonth() === month) {
  84.           fullDate = date.getDate() + '-' + month + '-' + year
  85.           this.days.push({
  86.             day: date.getDate(),
  87.             name: names[date.getDay()],
  88.             fullDate: fullDate
  89.           })
  90.           date.setDate(date.getDate() + 1)
  91.         }
  92.       }, 500)
  93.     },
  94.     submit () {
  95.       console.log(this.availability)
  96.       this.saved = true
  97.       this.saveChanges = false
  98.       this.changed = false
  99.     },
  100.     changeMonth (addMonths, force = false) {
  101.       if (this.changed && !force) {
  102.         this.saveChanges = true
  103.         this.addMonths = addMonths
  104.       } else {
  105.         addMonths = addMonths || this.addMonths
  106.         this.currentDate.add(addMonths, 'months')
  107.         this.getDays()
  108.  
  109.         if (force) {
  110.           this.saveChanges = false
  111.           this.changed = false
  112.         }
  113.       }
  114.     }
  115.   },
  116.   mixins: [FormValidator]
  117. }
  118. </script>
  119.  
  120. <style lang="postcss" scoped>
  121. @import '~/assets/style/root.css';
  122.  
  123. .controller {
  124.     display: flex;
  125.     justify-content: space-between;
  126.  
  127.     font-size: 1.5rem;
  128. }
  129.  
  130. .time-card {
  131.     padding: 10px;
  132.     margin: 20px 10px;
  133.  
  134.     & .layout {
  135.         align-items: center;
  136.         & .date {
  137.             color: var(--primary-color);
  138.             font-weight: bold;
  139.             font-size: 1.5rem;
  140.             text-align: center;
  141.  
  142.             & div {
  143.                 border: 1px solid var(--primary-color-darker);
  144.                 width: 70%;
  145.                 margin: auto;
  146.             }
  147.         }
  148.     }
  149. }
  150. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement