Blame view
src/pages/Library/eBook.vue
25.2 KB
687e0b929
|
1 |
<template> |
68d742034
|
2 3 |
<v-container fluid class="body-color"> <!-- ****** EDITS EBOOK DETAILS ****** --> |
710438de6
|
4 5 6 7 8 9 10 11 12 |
<v-dialog v-model="editEbookDialog" max-width="600px"> <v-card flat class="card-style pa-2" dark> <v-layout> <v-flex xs12> <label class="title text-xs-center">Edit E-Book</label> <v-icon size="24" class="right" @click="editEbookDialog = false">cancel</v-icon> </v-flex> </v-layout> <v-card-text> |
109a6218c
|
13 |
<v-flex xs12 class="text-xs-center text-sm-center text-md-center text-lg-center"> |
710438de6
|
14 15 16 |
<input type="file" style="display: none" |
109a6218c
|
17 |
ref="editImage" |
710438de6
|
18 |
accept="image/*" |
109a6218c
|
19 |
@change="onEditImagePicked" |
710438de6
|
20 |
/> |
710438de6
|
21 |
<img |
109a6218c
|
22 |
v-if="editedItem.coverPhotoUrl" |
710438de6
|
23 |
:src="editedItem.coverPhotoUrl" |
109a6218c
|
24 |
height="160" |
710438de6
|
25 26 27 28 |
width="160" alt="eBooks" class="pa-2" /> |
710438de6
|
29 30 31 32 33 34 35 36 37 |
<img src="/static/icon/user.png" v-if="editedItem.coverPhotoUrl == ''" height="160" width="160" alt="Books" /> </v-flex> <v-container grid-list-md> |
109a6218c
|
38 |
<v-flex xs12 sm12> |
68d742034
|
39 |
<v-layout> |
710438de6
|
40 41 42 |
<v-flex xs4 class="pt-4 subheading"> <label class="right hidden-xs-only hidden-sm-only">Name :</label> <label class="right hidden-lg-only hidden-md-only hidden-xl-only">Name :</label> |
68d742034
|
43 |
</v-flex> |
710438de6
|
44 45 46 47 48 49 50 51 |
<v-flex xs8 class="ml-3"> <v-text-field v-model="editedItem.name" placeholder="fill your full Name" name="name" type="text" required ></v-text-field> |
68d742034
|
52 |
</v-flex> |
710438de6
|
53 54 |
</v-layout> </v-flex> |
109a6218c
|
55 |
<v-flex xs12 sm12> |
710438de6
|
56 57 58 59 |
<v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right hidden-xs-only hidden-sm-only">Author :</label> <label class="right hidden-lg-only hidden-md-only hidden-xl-only">Author :</label> |
68d742034
|
60 |
</v-flex> |
710438de6
|
61 62 63 64 65 66 67 68 |
<v-flex xs8 class="ml-3"> <v-text-field v-model="editedItem.author" placeholder="fill your full author" name="name" type="text" required ></v-text-field> |
68d742034
|
69 70 |
</v-flex> </v-layout> |
710438de6
|
71 |
</v-flex> |
109a6218c
|
72 |
<v-flex xs12 sm12> |
68d742034
|
73 |
<v-layout> |
710438de6
|
74 75 76 77 78 |
<v-flex xs4 class="pt-4 subheading"> <label class="right hidden-xs-only hidden-sm-only">Class :</label> <label class="right hidden-lg-only hidden-md-only hidden-xl-only">Class :</label> </v-flex> <v-flex xs8 class="ml-3"> |
109a6218c
|
79 80 81 82 83 84 |
<v-select v-model="editedItem.classId" :items="addClass" label="Select Class" item-text="classNum" item-value="_id" |
710438de6
|
85 86 |
type="_id" required |
109a6218c
|
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
></v-select> </v-flex> </v-layout> </v-flex> <v-flex xs12 sm12> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right hidden-xs-only hidden-sm-only">Upload Image :</label> <label class="right hidden-lg-only hidden-md-only hidden-xl-only">UploadImage :</label> </v-flex> <v-flex xs8 class="ml-3"> <v-text-field label="Select Image" @click="editPickImage" v-model="editImageName" append-icon="attach_file" ></v-text-field> </v-flex> </v-layout> </v-flex> <v-flex xs12> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Upload File:</label> </v-flex> <v-flex xs8 class="ml-3"> <input type="file" style="display: none" ref="editFile" @change="onEditFilePicked" /> <v-text-field label="Select File" @click="editPickFile" v-model="editFileName" append-icon="attach_file" |
710438de6
|
124 |
></v-text-field> |
68d742034
|
125 126 |
</v-flex> </v-layout> |
710438de6
|
127 |
</v-flex> |
109a6218c
|
128 129 130 131 132 |
<v-card-actions> <v-spacer></v-spacer> <v-btn round dark @click="save" :loading="editLoading" class="add-button">Save</v-btn> <v-spacer></v-spacer> </v-card-actions> |
710438de6
|
133 |
</v-container> |
68d742034
|
134 135 136 137 138 |
</v-card-text> </v-card> </v-dialog> <!-- ****** PROFILE VIEW ALL NEWS DEATILS ****** --> |
59793b95a
|
139 |
<v-dialog v-model="viewEbookDialog" max-width="600px" scrollable> |
710438de6
|
140 141 142 |
<v-card flat class="card-style pa-3" dark> <v-layout> <v-flex xs12> |
59793b95a
|
143 |
<label class="title text-xs-center">View E-book</label> |
710438de6
|
144 145 146 147 148 149 |
<v-icon size="24" class="right" @click="viewEbookDialog = false">cancel</v-icon> </v-flex> </v-layout> <v-layout> <v-flex align-center justify-center layout text-xs-center class="mt-3"> <v-avatar size="100px"> |
59793b95a
|
150 151 |
<img src="/static/icon/user.png" v-if="!editedItem.coverPhotoUrl" /> <img :src="editedItem.coverPhotoUrl" v-else-if="editedItem.coverPhotoUrl" /> |
710438de6
|
152 153 154 155 156 |
</v-avatar> </v-flex> </v-layout> <v-container grid-list-md> <v-layout wrap> |
59793b95a
|
157 |
<v-flex xs12 sm12> |
710438de6
|
158 159 160 161 162 163 164 165 166 167 168 |
<v-layout> <v-flex xs6 sm6> <h5 class="right my-1"> <b>Name:</b> </h5> </v-flex> <v-flex sm6 xs6> <h5 class="my-1 left">{{ editedItem.name }}</h5> </v-flex> </v-layout> </v-flex> |
59793b95a
|
169 |
<v-flex xs12 sm12> |
710438de6
|
170 |
<v-layout> |
59793b95a
|
171 |
<v-flex xs6 sm6> |
710438de6
|
172 173 174 175 |
<h5 class="right my-1"> <b>Author:</b> </h5> </v-flex> |
59793b95a
|
176 |
<v-flex sm6 xs6> |
710438de6
|
177 178 179 180 181 |
<h5 class="my-1 left">{{ editedItem.author }}</h5> </v-flex> </v-layout> </v-flex> </v-layout> |
59793b95a
|
182 |
<v-flex xs12 sm12> |
710438de6
|
183 184 185 186 187 188 189 |
<v-layout> <v-flex xs6 sm6> <h5 class="right my-1"> <b>Class:</b> </h5> </v-flex> <v-flex sm6 xs6> |
7281a47c4
|
190 |
<h5 class="my-1 left">{{ editedItem.classId .classNum}}</h5> |
710438de6
|
191 192 193 |
</v-flex> </v-layout> </v-flex> |
710438de6
|
194 |
</v-container> |
68d742034
|
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
</v-card> </v-dialog> <!-- ****** EXISTING-USERS NEWS 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="addEBookDialog = true" > <v-icon dark>add</v-icon> </v-btn> <v-btn round class="open-dialog-button hidden-sm-only hidden-xs-only" dark @click="addEBookDialog = true" > <v-icon class="white--text pr-1" size="20">add</v-icon>Add E-Book </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
|
221 |
<img src="/static/icon/search.png" alt="icon" /> |
68d742034
|
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
</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="eBookData" :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="td td-row text-xs-center"> |
109a6218c
|
242 243 244 245 |
<v-avatar size="40"> <img :src="props.item.coverPhotoUrl" v-if="props.item.coverPhotoUrl" alt="ebooks" /> <img src="/static/icon/user.png" v-if="!props.item.coverPhotoUrl" /> </v-avatar> |
68d742034
|
246 247 248 249 250 251 252 253 254 255 256 257 |
</td> <td class="td td-row text-xs-center">{{ props.item.name}}</td> <td class="td td-row text-xs-center">{{ props.item.author}}</td> <td class="td td-row text-xs-center">{{ props.item.classId.classNum}}</td> <td class="td td-row text-xs-center"> <span> <v-tooltip top> <img slot="activator" style="cursor:pointer; width:25px; height:25px; " class="mr-3" @click="profile(props.item)" |
aa310d61a
|
258 |
src="/static/icon/view.png" |
68d742034
|
259 260 261 262 263 264 265 266 267 |
/> <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
|
268 |
src="/static/icon/edit.png" |
68d742034
|
269 270 271 272 273 274 275 276 |
/> <span>Edit</span> </v-tooltip> <v-tooltip top> <img slot="activator" style="cursor:pointer; width:20px; height:20px; " @click="deleteItem(props.item)" |
aa310d61a
|
277 |
src="/static/icon/delete.png" |
68d742034
|
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
/> <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 E-BOOK ****** --> <v-dialog v-model="addEBookDialog" max-width="600px"> <v-card flat class="card-style pa-2" dark> <v-layout> <v-flex xs12> <label class="title text-xs-center">Add E-Book</label> <v-icon size="24" class="right" @click="addEBookDialog = false">cancel</v-icon> |
687e0b929
|
299 |
</v-flex> |
68d742034
|
300 301 302 303 |
</v-layout> <v-form ref="form" v-model="valid" lazy-validation> <v-container fluid> <v-layout> |
710438de6
|
304 |
<v-flex xs12 class="text-xs-center text-sm-center text-md-center text-lg-center"> |
68d742034
|
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
<input type="file" style="display: none" ref="image" accept="image/*" @change="onImagePicked" /> <v-layout justify-center> <v-flex v-if="files != ''"> <img :src="files" height="150" width="150" /> </v-flex> </v-layout> <img src="/static/icon/user.png" v-if="files ==''" height="80" width="80px;" /> </v-flex> </v-layout> <v-flex xs12> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Name:</label> </v-flex> <v-flex xs7 class="ml-3"> <v-text-field v-model="addEBooks.name" |
710438de6
|
328 |
placeholder="fill name" |
68d742034
|
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
name="name" type="text" :rules="titleRules" 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">Author:</label> </v-flex> <v-flex xs7 class="ml-3"> <v-text-field v-model="addEBooks.author" placeholder="fill your Author Name" name="name" type="text" :rules="titleRules" 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">Class:</label> </v-flex> <v-flex xs7 class="ml-3"> <v-select v-model="addEBooks.classId" :items="addClass" label="Select Class" item-text="classNum" item-value="_id" :rules="titleRules" required ></v-select> </v-flex> </v-layout> </v-flex> <v-flex xs12> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Upload Image:</label> </v-flex> <v-flex xs7 class="ml-3"> <v-text-field label="Select Image" @click="pickImage" |
109a6218c
|
381 |
v-model="imageName" |
a76a6f135
|
382 |
:rules="uploadImageRule" |
68d742034
|
383 |
append-icon="attach_file" |
68d742034
|
384 385 386 387 388 389 390 391 392 |
></v-text-field> </v-flex> </v-layout> </v-flex> <v-flex xs12> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Upload File:</label> </v-flex> |
109a6218c
|
393 |
<v-flex xs8 class="ml-3"> |
68d742034
|
394 395 396 397 |
<input type="file" style="display: none" ref="file" @change="onFilePicked" /> <v-text-field label="Select File" @click="pickFile" |
109a6218c
|
398 |
v-model="fileName" |
a76a6f135
|
399 |
:rules="uploadFileRule" |
68d742034
|
400 |
append-icon="attach_file" |
68d742034
|
401 402 403 404 405 406 407 408 409 410 |
></v-text-field> </v-flex> </v-layout> </v-flex> <v-flex xs12> <v-layout> <v-flex xs4 class="pt-3 subheading"> <label class="right">Private:</label> </v-flex> <v-flex xs7 class="ml-3"> |
a76a6f135
|
411 |
<v-checkbox v-model="addEBooks.private" :rules="uploadPrivateRule"></v-checkbox> |
68d742034
|
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
</v-flex> </v-layout> </v-flex> <v-layout> <v-flex xs12> <v-card-actions> <v-spacer></v-spacer> <v-btn @click="clear" round dark class="clear-button">clear</v-btn> <v-btn @click="submit" round dark :loading="loading" class="add-button">Add</v-btn> </v-card-actions> </v-flex> </v-layout> </v-container> </v-form> </v-card> </v-dialog> |
687e0b929
|
428 429 430 |
<div class="loader" v-if="showLoader"> <v-progress-circular indeterminate color="white"></v-progress-circular> </div> |
68d742034
|
431 |
</v-container> |
687e0b929
|
432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
</template> <script> import http from "@/Services/http.js"; import Util from "@/util"; export default { data: () => ({ snackbar: false, y: "top", x: "right", mode: "", timeout: 3000, text: "", |
68d742034
|
446 447 |
show: true, showSearch: false, |
687e0b929
|
448 |
loading: false, |
6c05a9f84
|
449 |
loadingUpadte: false, |
687e0b929
|
450 451 452 |
date: null, search: "", showLoader: false, |
710438de6
|
453 454 |
editEbookDialog: false, viewEbookDialog: false, |
687e0b929
|
455 |
valid: true, |
68d742034
|
456 |
addEBookDialog: false, |
109a6218c
|
457 |
editLoading: false, |
ab54b5656
|
458 |
addClass: [], |
687e0b929
|
459 |
addSection: [], |
687e0b929
|
460 |
pagination: { |
68d742034
|
461 |
rowsPerPage: 10 |
687e0b929
|
462 463 |
}, imageName: "", |
ab54b5656
|
464 |
fileName: "", |
687e0b929
|
465 466 467 468 |
imageUrl: "", imageFile: "", image: [], upload: "", |
ab54b5656
|
469 470 |
files: "", anyFile: "", |
687e0b929
|
471 472 |
titleRules: [v => !!v || " Tilte is required"], descriptionRules: [v => !!v || " Description is required"], |
a76a6f135
|
473 474 475 |
uploadImageRule: [v => !!v || " field is required"], uploadFileRule: [v => !!v || " fied is required"], uploadPrivateRule: [v => !!v || " fied is required"], |
687e0b929
|
476 477 |
headers: [ { |
109a6218c
|
478 |
align: "left", |
687e0b929
|
479 480 481 482 |
text: "No", sortable: false, value: "No" }, |
ab54b5656
|
483 484 485 |
{ text: "Photo", vaue: "fileUrl", sortable: false, align: "center" }, { text: "Name", vaue: "name", sortable: false, align: "center" }, { text: "Author", value: "author", sortable: false, align: "center" }, |
687e0b929
|
486 |
{ |
ab54b5656
|
487 488 |
text: "Class", value: "classId", |
687e0b929
|
489 490 491 492 493 |
sortable: false, align: "center" }, { text: "Action", value: "", sortable: false, align: "center" } ], |
ab54b5656
|
494 |
eBookData: [], |
687e0b929
|
495 |
editedIndex: -1, |
ab54b5656
|
496 497 498 499 |
addEBooks: { private: false }, editedItem: {}, |
d5fcb1cd1
|
500 501 502 503 504 |
editedItem: { classId: { classNum: "" } }, |
710438de6
|
505 |
token: "", |
109a6218c
|
506 507 508 509 510 |
uploadCover: {}, editImageName: "", editFiles: "", editAnyFile: "", editFileName: "" |
687e0b929
|
511 512 |
}), methods: { |
109a6218c
|
513 514 515 |
editPickImage() { this.$refs.editImage.click(); }, |
ab54b5656
|
516 |
pickImage() { |
687e0b929
|
517 518 |
this.$refs.image.click(); }, |
ab54b5656
|
519 520 521 |
pickFile() { this.$refs.file.click(); }, |
109a6218c
|
522 523 524 |
editPickFile() { this.$refs.editFile.click(); }, |
ab54b5656
|
525 |
onImagePicked(e) { |
687e0b929
|
526 527 528 529 530 531 532 533 |
// console.log(e) const files = e.target.files; /** fetch Image Name **/ if (files[0] !== undefined) { this.imageName = files[0].name; if (this.imageName.lastIndexOf(".") <= 0) { return; } |
687e0b929
|
534 |
/** Select many image and showing many image add to news card **/ |
687e0b929
|
535 536 537 |
const fr = new FileReader(); fr.readAsDataURL(files[0]); fr.addEventListener("load", () => { |
ab54b5656
|
538 |
this.files = fr.result; |
687e0b929
|
539 540 541 542 |
}); } else { this.imageName = ""; this.imageFile = ""; |
ab54b5656
|
543 |
this.files = ""; |
687e0b929
|
544 545 546 |
this.imageUrl = ""; } }, |
109a6218c
|
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
onEditImagePicked(e) { // console.log(e) const files = e.target.files; /** fetch Image Name **/ if (files[0] !== undefined) { this.editImageName = files[0].name; if (this.editImageName.lastIndexOf(".") <= 0) { return; } /** Select many image and showing many image add to news card **/ const fr = new FileReader(); fr.readAsDataURL(files[0]); fr.addEventListener("load", () => { this.editFiles = fr.result; }); } else { this.editImageName = ""; this.editFiles = ""; } }, |
6c05a9f84
|
567 |
getEBooksList() { |
687e0b929
|
568 |
this.showLoader = true; |
687e0b929
|
569 |
http() |
ab54b5656
|
570 |
.get("/getEBooksList", { |
99cd79184
|
571 |
params: { schoolId: this.$store.state.schoolId }, |
ab54b5656
|
572 |
headers: { Authorization: "Bearer " + this.token } |
687e0b929
|
573 574 |
}) .then(response => { |
ab54b5656
|
575 |
this.eBookData = response.data.data; |
687e0b929
|
576 |
this.showLoader = false; |
687e0b929
|
577 |
}) |
00e4bc4e1
|
578 |
.catch(error => { |
687e0b929
|
579 580 |
// console.log("err====>", err); this.showLoader = false; |
6c05a9f84
|
581 582 583 584 585 |
if (error.response.status === 401) { this.$router.replace({ path: "/" }); this.$store.dispatch("setToken", null); this.$store.dispatch("Id", null); } |
ab54b5656
|
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 |
}); }, onFilePicked(e) { // console.log(e) const files = e.target.files; /** fetch Image Name **/ if (files[0] !== undefined) { this.fileName = files[0].name; if (this.fileName.lastIndexOf(".") <= 0) { return; } const fr = new FileReader(); fr.readAsDataURL(files[0]); fr.addEventListener("load", () => { this.anyFile = fr.result; // console.log(" this.anyFile Url", this.anyFile ) |
687e0b929
|
602 |
}); |
ab54b5656
|
603 604 605 606 |
} else { this.anyFile = ""; this.fileName = ""; } |
687e0b929
|
607 |
}, |
109a6218c
|
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 |
onEditFilePicked(e) { // console.log(e) const files = e.target.files; /** fetch Image Name **/ if (files[0] !== undefined) { this.editFileName = files[0].name; if (this.editFileName.lastIndexOf(".") <= 0) { return; } const fr = new FileReader(); fr.readAsDataURL(files[0]); fr.addEventListener("load", () => { this.editAnyFile = fr.result; // console.log(" this.anyFile Url", this.anyFile ) }); } else { this.editAnyFile = ""; this.editFileName = ""; } }, |
687e0b929
|
628 629 |
editItem(item) { this.files = []; |
ab54b5656
|
630 |
this.editedIndex = this.eBookData.indexOf(item); |
687e0b929
|
631 |
this.editedItem = Object.assign({}, item); |
6c05a9f84
|
632 |
this.editedItem.className = item.classId.classNum; |
710438de6
|
633 |
this.editEbookDialog = true; |
687e0b929
|
634 635 |
}, profile(item) { |
ab54b5656
|
636 |
this.editedIndex = this.eBookData.indexOf(item); |
687e0b929
|
637 |
this.editedItem = Object.assign({}, item); |
710438de6
|
638 |
this.viewEbookDialog = true; |
687e0b929
|
639 640 |
}, deleteItem(item) { |
6c05a9f84
|
641 642 |
let deleteEBooks = { ebookId: item._id |
687e0b929
|
643 644 645 |
}; http() .delete( |
6c05a9f84
|
646 |
"/deleteEBook", |
687e0b929
|
647 |
confirm("Are you sure you want to delete this?") && { |
6c05a9f84
|
648 |
params: deleteEBooks |
687e0b929
|
649 650 651 |
} ) .then(response => { |
6c05a9f84
|
652 653 654 |
this.snackbar = true; this.text = "Successfully delete Existing News"; this.getEBooksList(); |
687e0b929
|
655 656 |
}) .catch(error => { |
6c05a9f84
|
657 658 |
this.snackbar = true; this.text = error.response.data.message; |
687e0b929
|
659 660 |
}); }, |
687e0b929
|
661 |
close() { |
710438de6
|
662 |
this.editEbookDialog = false; |
687e0b929
|
663 664 |
}, close1() { |
710438de6
|
665 |
this.viewEbookDialog = false; |
687e0b929
|
666 667 |
}, submit() { |
687e0b929
|
668 |
if (this.$refs.form.validate()) { |
109a6218c
|
669 |
this.loading = true; |
a76a6f135
|
670 671 |
var uploadCover = ""; var uploadFile = ""; |
687e0b929
|
672 |
if (this.files) { |
ab54b5656
|
673 |
const [baseUrl, imageUrl] = this.files.split(/,/); |
a76a6f135
|
674 675 |
uploadCover = imageUrl; console.log("anyFile.split(/,/)", uploadCover); |
ab54b5656
|
676 677 678 |
} if (this.anyFile) { const [baseUrl, fileUrl] = this.anyFile.split(/,/); |
a76a6f135
|
679 680 |
uploadFile = fileUrl; console.log("anyFile.split(/,/)", uploadFile); |
687e0b929
|
681 |
} |
710438de6
|
682 683 684 685 686 |
let data = { classId: this.addEBooks.classId, name: this.addEBooks.name, author: this.addEBooks.author, private: this.addEBooks.private, |
a76a6f135
|
687 688 |
uploadCover: uploadCover, uploadFile: uploadFile |
710438de6
|
689 |
}; |
687e0b929
|
690 |
http() |
710438de6
|
691 |
.post("/createEBook", data) |
687e0b929
|
692 |
.then(response => { |
a76a6f135
|
693 694 |
this.getEBooksList(); // this.getEBooksList = []; |
68d742034
|
695 |
this.addEBookDialog = false; |
109a6218c
|
696 |
this.snackbar = true; |
710438de6
|
697 698 |
this.text = response.data.message; this.color = "green"; |
687e0b929
|
699 |
this.loading = false; |
109a6218c
|
700 |
(this.imageName = ""), (this.fileName = ""); |
687e0b929
|
701 702 |
}) .catch(error => { |
6c05a9f84
|
703 704 |
this.snackbar = true; this.text = error.response.data.message; |
710438de6
|
705 |
this.color = "red"; |
687e0b929
|
706 707 708 709 710 |
}); } }, clear() { this.$refs.form.reset(); |
495e4037c
|
711 712 |
this.addEBooks.uploadCover = ""; this.files = ""; |
687e0b929
|
713 714 |
}, save() { |
109a6218c
|
715 |
this.editLoading = true; |
6c05a9f84
|
716 |
this.loadingUpadte = true; |
109a6218c
|
717 718 |
if (this.editFiles) { const [baseUrl, imageUrl] = this.editFiles.split(/,/); |
6c05a9f84
|
719 720 |
this.editedItem.uploadCover = imageUrl; // console.log("anyFile.split(/,/)", this.addEBooks.uploadCover); |
687e0b929
|
721 |
} |
109a6218c
|
722 723 |
if (this.editAnyFile) { const [baseUrl, fileUrl] = this.editAnyFile.split(/,/); |
6c05a9f84
|
724 725 |
this.editedItem.uploadFile = fileUrl; // console.log("anyFile.split(/,/)", this.addEBooks.uploadFile); |
ab54b5656
|
726 |
} |
109a6218c
|
727 728 729 |
if (this.editedItem.classId._id) { this.editedItem.classId = this.editedItem.classId._id; } |
6c05a9f84
|
730 |
this.editedItem.ebookId = this.editedItem._id; |
109a6218c
|
731 |
console.log("this.editedItem", this.editedItem); |
687e0b929
|
732 |
http() |
6c05a9f84
|
733 |
.put("/updateEBook", this.editedItem) |
687e0b929
|
734 |
.then(response => { |
6c05a9f84
|
735 736 737 738 |
this.loadingUpadte = false; this.snackbar = true; this.text = "Successfully Edit Existing E-Book"; this.getEBooksList(); |
109a6218c
|
739 |
this.editLoading = false; |
6c05a9f84
|
740 741 742 743 |
this.editedItem.uploadFile = ""; this.editedItem.uploadCover = ""; this.anyFile = ""; this.files = ""; |
687e0b929
|
744 745 746 |
this.close(); }) .catch(error => { |
109a6218c
|
747 |
this.editLoading = false; |
6c05a9f84
|
748 749 750 |
this.loadingUpadte = false; this.snackbar = true; this.text = error.response.data.message; |
687e0b929
|
751 752 |
// console.log(error); }); |
ab54b5656
|
753 754 755 756 757 758 759 760 761 762 763 764 765 |
}, getAllClass() { http() .get("/getClassesList", { headers: { Authorization: "Bearer " + this.token } }) .then(response => { this.addClass = response.data.data; }) .catch(err => { // console.log("err====>", err); // this.$router.replace({ path: "/" }); }); |
68d742034
|
766 767 768 769 770 771 772 773 |
}, displaySearch() { (this.show = false), (this.showSearch = true); }, closeSearch() { this.showSearch = false; this.show = true; this.search = ""; |
687e0b929
|
774 775 776 |
} }, mounted() { |
ab54b5656
|
777 |
this.token = this.$store.state.token; |
6c05a9f84
|
778 |
this.getEBooksList(); |
ab54b5656
|
779 |
this.getAllClass(); |
006544386
|
780 |
// this.getBookData(); |
ab54b5656
|
781 |
// this.editItem; |
687e0b929
|
782 783 |
} }; |
68d742034
|
784 |
</script> |