Blame view
src/pages/Holiday/holiday.vue
14.5 KB
4bd94ba60
|
1 |
<template> |
68d742034
|
2 3 4 5 6 7 8 9 10 11 12 |
<v-container fluid class="body-color"> <!-- ****** EDIT HOLIDAY ****** --> <v-dialog v-model="editHolidayDialog" max-width="500px"> <v-card flat class="card-style pa-2" dark> <v-layout> <v-flex xs12> <label class="title text-xs-center">Edit Holiday</label> <v-icon size="24" class="right" @click="editHolidayDialog = false">cancel</v-icon> </v-flex> </v-layout> <v-container fluid> |
4bd94ba60
|
13 |
<v-flex xs12 sm12> |
68d742034
|
14 15 16 17 18 19 20 21 22 23 24 25 26 |
<v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Occasion:</label> </v-flex> <v-flex xs8 sm8 class="ml-3"> <v-text-field v-model="editedItem.occasion" placeholder="fill your Occasion" name="name" type="text" ></v-text-field> </v-flex> </v-layout> |
4bd94ba60
|
27 |
</v-flex> |
68d742034
|
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
<v-flex xs12 sm12> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Date:</label> </v-flex> <v-flex xs8 class="ml-3"> <v-menu ref="menu" :close-on-content-click="false" :return-value.sync="editedItem.dateOfHoliday" v-model="menu" :nudge-right="40" lazy transition="scale-transition" offset-y full-width min-width="290px" > <v-text-field |
495e4037c
|
47 |
slot="activator" |
68d742034
|
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
:rules="dateRules" v-model="editedItem.dateOfHoliday" append-icon="event" placeholder="Select date" ></v-text-field> <v-date-picker ref="picker" color="info" v-model="editedItem.dateOfHoliday" @input="$refs.menu.save(editedItem.dateOfHoliday)" ></v-date-picker> </v-menu> </v-flex> </v-layout> </v-flex> <v-layout> <v-flex xs12 sm12> <v-card-actions class="hidden-xs-only hidden-sm-only"> <v-spacer></v-spacer> <v-btn round dark @click="save" class="add-button">Save</v-btn> </v-card-actions> <v-card-actions class="hidden-md-only hidden-lg-only hidden-xl-only"> <v-spacer></v-spacer> <v-btn round dark @click="save" class="add-button">Save</v-btn> <v-spacer></v-spacer> </v-card-actions> </v-flex> </v-layout> </v-container> </v-card> </v-dialog> |
4bd94ba60
|
79 |
|
68d742034
|
80 |
<!-- ****** PROFILE VIEW Holiday DEATILS ****** --> |
4bd94ba60
|
81 |
|
68d742034
|
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
<v-dialog v-model="viewHolidayDialog" max-width="500px"> <v-card flat class="card-style pa-3" dark> <v-layout> <v-flex xs12> <label class="title text-xs-center">View Holiday</label> <v-icon size="24" class="right" @click="viewHolidayDialog = false">cancel</v-icon> </v-flex> </v-layout> <v-card-text> <v-container grid-list-md> <v-layout wrap> <v-flex> <v-layout> <v-flex xs4 sm6> <h5 class="right my-1"> <b>Occasion:</b> </h5> |
4bd94ba60
|
99 |
</v-flex> |
68d742034
|
100 101 |
<v-flex sm6 xs8> <h5 class="my-1">{{ editedItem.occasion }}</h5> |
4bd94ba60
|
102 |
</v-flex> |
68d742034
|
103 104 105 106 107 108 |
</v-layout> <v-layout> <v-flex xs4 sm6> <h5 class="right my-1"> <b>Date:</b> </h5> |
495e4037c
|
109 |
</v-flex> |
68d742034
|
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
<v-flex sm6 xs8> <h5 class="my-1">{{ editedItem.dateOfHoliday }}</h5> </v-flex> </v-layout> </v-flex> </v-layout> </v-container> </v-card-text> </v-card> </v-dialog> <!-- ****** Holiday TABLE ****** --> <v-toolbar color="transparent" flat> <v-btn fab dark class="open-dialog-button hidden-xl-only hidden-md-only hidden-lg-only" small @click="addHolidayDialog = true" > <v-icon dark>add</v-icon> </v-btn> <v-btn round class="open-dialog-button hidden-sm-only hidden-xs-only" dark @click="addHolidayDialog = true" > <v-icon class="white--text pr-1" size="20">add</v-icon>Add Holiday </v-btn> <v-spacer></v-spacer> <v-card-title class="body-1" v-show="show"> <v-btn icon large flat @click="displaySearch"> <v-avatar size="27"> |
aa310d61a
|
143 |
<img src="/static/icon/search.png" alt="icon" /> |
68d742034
|
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
</v-avatar> </v-btn> </v-card-title> <v-flex xs8 sm8 md3 lg2 v-show="showSearch"> <v-layout> <v-text-field v-model="search" label="Search" prepend-inner-icon="search" color="primary"></v-text-field> <v-icon @click="closeSearch" color="error">close</v-icon> </v-layout> </v-flex> </v-toolbar> <v-data-table :headers="headers" :items="holidays" :pagination.sync="pagination" :search="search" > <template slot="items" slot-scope="props"> <tr class="tr"> <td class="td td-row">{{ props.index + 1}}</td> <td class="text-xs-center td td-row">{{ props.item.occasion}}</td> <td class="text-xs-center td td-row">{{ dates(props.item.dateOfHoliday) }}</td> <td class="text-xs-center td td-row"> <span> <v-tooltip top> <img slot="activator" style="cursor:pointer; width:25px; height:25px; " class="mr-3" @click="profile(props.item)" |
aa310d61a
|
173 |
src="/static/icon/view.png" |
68d742034
|
174 175 176 177 178 179 180 181 182 |
/> <span>View</span> </v-tooltip> <v-tooltip top> <img slot="activator" style="cursor:pointer; width:20px; height:18px; " class="mr-3" @click="editItem(props.item)" |
aa310d61a
|
183 |
src="/static/icon/edit.png" |
68d742034
|
184 185 186 187 188 189 190 191 192 |
/> <span>Edit</span> </v-tooltip> <v-tooltip top> <img slot="activator" style="cursor:pointer; width:20px; height:20px; " class="mr-3" @click="deleteItem(props.item)" |
aa310d61a
|
193 |
src="/static/icon/delete.png" |
68d742034
|
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
/> <span>Delete</span> </v-tooltip> </span> </td> </tr> </template> <v-alert slot="no-results" :value="true" color="error" icon="warning" >Your search for "{{ search }}" found no results.</v-alert> </v-data-table> <!-- ****** ADD MULTIPLE Holiday ****** --> <v-dialog v-model="addHolidayDialog" max-width="400px"> <v-card flat class="card-style pa-3" dark> <v-layout> <v-flex xs12> <label class="title text-xs-center">Add Holiday</label> <v-icon size="24" class="right" @click="addHolidayDialog = false">cancel</v-icon> |
4bd94ba60
|
215 |
</v-flex> |
68d742034
|
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
</v-layout> <v-form ref="form" v-model="valid" lazy-validation> <v-container fluid> <v-flex xs12> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Occasion:</label> </v-flex> <v-flex xs8 sm8 class="ml-3"> <v-text-field v-model="addHoliday.occasion" placeholder="fill your Occasion" type="text" :rules="occasionRules" required ></v-text-field> </v-flex> </v-layout> </v-flex> <v-flex xs12> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Date:</label> </v-flex> <v-flex xs8 sm8 class="ml-3"> <v-menu ref="menu1" :close-on-content-click="false" v-model="menu1" :nudge-right="40" :return-value.sync="addHoliday.dateOfHoliday" lazy transition="scale-transition" offset-y full-width min-width="290px" > <v-text-field slot="activator" :rules="dateRules" v-model="addHoliday.dateOfHoliday" append-icon="event" label="Select date" ></v-text-field> <v-date-picker ref="picker" color="info" v-model="addHoliday.dateOfHoliday" @input="$refs.menu1.save(addHoliday.dateOfHoliday)" ></v-date-picker> </v-menu> </v-flex> </v-layout> </v-flex> <v-layout> <v-flex xs12> <v-layout class="right"> <v-btn @click="clear" round class="clear-button" dark>clear</v-btn> <v-btn @click="submit" round dark :loading="loading" class="add-button">Add</v-btn> </v-layout> </v-flex> </v-layout> </v-container> </v-form> </v-card> </v-dialog> <v-snackbar :timeout="timeout" :top="y === 'top'" :right="x === 'right'" :vertical="mode === 'vertical'" v-model="snackbar" :color="color" >{{ text }}</v-snackbar> |
4bd94ba60
|
290 291 292 |
<div class="loader" v-if="showLoader"> <v-progress-circular indeterminate color="white"></v-progress-circular> </div> |
68d742034
|
293 |
</v-container> |
4bd94ba60
|
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
</template> <script> import http from "@/Services/http.js"; import moment from "moment"; export default { data: () => ({ snackbar: false, y: "top", x: "right", mode: "", timeout: 3000, text: "", loading: false, date: null, search: "", |
68d742034
|
311 312 313 314 |
color: "", show: true, addHolidayDialog: false, showSearch: false, |
4bd94ba60
|
315 |
showLoader: false, |
68d742034
|
316 317 |
editHolidayDialog: false, viewHolidayDialog: false, |
4bd94ba60
|
318 |
valid: true, |
4bd94ba60
|
319 |
pagination: { |
68d742034
|
320 |
rowsPerPage: 10 |
4bd94ba60
|
321 322 323 324 325 326 327 328 329 |
}, date: null, menu1: false, menu: false, occasionRules: [v => !!v || "Occasion is required"], dateRules: [v => !!v || "Date is required"], headers: [ { text: "No", |
68d742034
|
330 |
align: "", |
4bd94ba60
|
331 332 333 334 335 336 337 338 339 340 341 342 |
sortable: false, value: "No" }, { text: "Occasion", value: "occasion", sortable: false, align: "center" }, { text: "Date Of Holiday", value: "dateOfHoliday", sortable: false, align: "center" }, { text: "Action", value: "", sortable: false, align: "center" } ], |
68d742034
|
343 |
holidays: [], |
4bd94ba60
|
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
editedIndex: -1, addHoliday: {}, editedItem: {} }), methods: { dates: function(date) { return moment(date).format("MMMM DD, YYYY"); }, getHolidays() { this.showLoader = true; var token = this.$store.state.token; http() .get("/getHolidaysList", { headers: { Authorization: "Bearer " + token } }) .then(response => { |
68d742034
|
360 |
this.holidays = response.data.data; |
4bd94ba60
|
361 362 363 |
this.showLoader = false; }) .catch(err => { |
4bd94ba60
|
364 365 366 367 368 369 370 371 372 |
this.showLoader = false; if (error.response.status === 401) { this.$router.replace({ path: "/" }); this.$store.dispatch("setToken", null); this.$store.dispatch("Id", null); } }); }, editItem(item) { |
68d742034
|
373 |
this.editedIndex = this.holidays.indexOf(item); |
4bd94ba60
|
374 375 |
this.editedItem = Object.assign({}, item); this.editedItem.holidayId = item._id; |
68d742034
|
376 |
this.editHolidayDialog = true; |
4bd94ba60
|
377 378 |
}, profile(item) { |
68d742034
|
379 |
this.editedIndex = this.holidays.indexOf(item); |
4bd94ba60
|
380 |
this.editedItem = Object.assign({}, item); |
68d742034
|
381 |
this.viewHolidayDialog = true; |
4bd94ba60
|
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
}, deleteItem(item) { let deleteHoliday = { holidayId: item._id }; http() .delete( "/deleteHoliday", confirm("Are you sure you want to delete this?") && { params: deleteHoliday } ) .then(response => { this.snackbar = true; this.text = response.data.message; |
68d742034
|
398 |
this.color = "green"; |
4bd94ba60
|
399 400 401 |
this.getHolidays(); }) .catch(error => { |
68d742034
|
402 403 404 |
this.snackbar = true; this.text = error.response.data.message; this.color = "error"; |
4bd94ba60
|
405 406 |
}); }, |
4bd94ba60
|
407 |
close() { |
68d742034
|
408 |
this.editHolidayDialog = false; |
4bd94ba60
|
409 410 411 412 413 414 415 416 417 |
}, submit() { if (this.$refs.form.validate()) { this.loading = true; http() .post("/createHoliday", this.addHoliday) .then(response => { this.snackbar = true; this.text = response.data.message; |
68d742034
|
418 |
this.color = "green"; |
4bd94ba60
|
419 |
this.getHolidays(); |
68d742034
|
420 |
this.addHolidayDialog = false; |
4bd94ba60
|
421 422 423 424 |
this.clear(); this.loading = false; }) .catch(error => { |
68d742034
|
425 426 |
this.snackbar = true; this.text = error.response.data.message; |
4bd94ba60
|
427 |
this.loading = false; |
68d742034
|
428 |
this.color = "error"; |
4bd94ba60
|
429 430 431 432 433 434 435 436 437 438 |
}); } }, clear() { this.$refs.form.reset(); }, save() { http() .put("/updateHoliday", this.editedItem) .then(response => { |
68d742034
|
439 440 |
this.snackbar = true; this.text = response.data.message; |
4bd94ba60
|
441 |
this.getHolidays(); |
68d742034
|
442 443 |
this.color = "green"; this.close(); |
4bd94ba60
|
444 445 |
}) .catch(error => { |
68d742034
|
446 447 448 449 |
this.snackbar = true; this.text = error.response.data.message; this.loading = false; this.color = "error"; |
4bd94ba60
|
450 |
}); |
68d742034
|
451 452 453 454 455 456 457 458 |
}, displaySearch() { (this.show = false), (this.showSearch = true); }, closeSearch() { this.showSearch = false; this.show = true; this.search = ""; |
4bd94ba60
|
459 460 461 462 |
} }, mounted() { this.getHolidays(); |
4bd94ba60
|
463 464 |
} }; |
68d742034
|
465 |
</script> |