Blame view
src/pages/changeStudents/changeStudents.vue
5.3 KB
11d037abe
|
1 2 |
<template> <v-app id="login"> |
fa975e45a
|
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<!-- LOADER --> <div class="loader" v-if="showLoader"> <v-progress-circular indeterminate color="white"></v-progress-circular> </div> <!-- SNACKBAR --> <v-snackbar :timeout="timeout" :top="y === 'top'" :right="x === 'right'" :vertical="mode === 'vertical'" v-model="snackbar" :color="snackbarColor" > {{ text }} <v-spacer></v-spacer> <v-btn flat text @click="snackbar = false">X</v-btn> </v-snackbar> |
11d037abe
|
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<v-container fluid fill-height> <v-layout> <v-flex xs12 sm8 md8 lg5 offset-sm2 offset-lg3 class="mt-5"> <v-card flat class="card-style pa-2" dark id="form"> <v-layout> <v-flex xs12> <label class="title text-xs-center">Change Student</label> </v-flex> </v-layout> <v-card-text> <v-flex xs12 sm8 md8 lg8 offset-sm2> <v-form class="mt-3"> <v-select :items="studentsData" item-text="name" item-value="_id" v-model="changeStudent" label="Students" ></v-select> </v-form> </v-flex> </v-card-text> <v-card-actions> <v-flex text-xs-center> <v-btn round dark :loading="loading" @click="change" class="add-button">Change</v-btn> </v-flex> </v-card-actions> |
11d037abe
|
48 49 50 51 52 53 54 55 |
</v-card> </v-flex> </v-layout> </v-container> </v-app> </template> <script> import http from "@/Services/http.js"; |
fa975e45a
|
56 |
import AllApiCalls from "@/Services/AllApiCalls.js"; |
11d037abe
|
57 58 |
export default { |
fa975e45a
|
59 |
mixins: [AllApiCalls], |
11d037abe
|
60 61 62 63 64 65 66 67 68 69 |
data() { return { snackbar: false, y: "top", x: "right", mode: "", timeout: 4000, text: "", loading: false, valid: false, |
610e873a0
|
70 |
changeStudent: "", |
fa975e45a
|
71 |
studentsData: [], |
11d037abe
|
72 73 74 75 76 77 78 |
}; }, mounted() { this.getparentStudents(); }, methods: { change() { |
11d037abe
|
79 80 81 82 83 84 85 |
localStorage.setItem("parentStudentId", this.changeStudent); this.$router.replace({ path: "/" }); }, getparentStudents() { this.showLoader = true; http() .get("/parentStudentsList") |
fa975e45a
|
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
.then((response) => { console.log("students - ", response.data.data.students); /* prepare an array of false status students */ var indexStatusFalse = []; for (var i = 0; i < response.data.data.students.length; i++) { if (response.data.data.students[i].status == false) { indexStatusFalse.push(i); } } /* introduce a property named disabled in response to make false staus students disbled */ for (var i = 0; i < indexStatusFalse.length; i++) { response.data.data.students[indexStatusFalse[i]].disabled = true; } /* make an array of students to be displayed in select box */ |
11d037abe
|
100 |
this.studentsData = response.data.data.students; |
fa975e45a
|
101 102 103 104 |
/* counter to keep a track of number of students that are disabled or false */ var counter = 0; /* if zero element of false students list is > 0 then make first student as defalut selected */ if (indexStatusFalse[0] > 0) { |
27ec4269c
|
105 106 |
this.changeStudent = response.data.data.students[0]._id; } |
fa975e45a
|
107 108 109 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 |
console.log("indexStatusFalse - ", indexStatusFalse); /* if false student is the first one in the list then see if the next is also false */ if (indexStatusFalse[0] == 0) { if (indexStatusFalse.length > 1) { for (var i = 1; i < indexStatusFalse.length; i++) { if (indexStatusFalse[i] == i) { if (indexStatusFalse[i - 1] == i - 1) { counter = i + 1; continue; } } else { counter = i; break; } } } else { counter = 1; } } console.log("counter - ", counter); if (counter == response.data.data.students.length) { this.seeSnackbar( "Your wards have been removed you will be logged out", "warning" ); setTimeout(() => { this.$store.dispatch("setToken", null); this.$router.replace({ path: "/" }); this.$store.dispatch("Id", null); }, 3000); } else { this.changeStudent = response.data.data.students[counter]._id; } |
610e873a0
|
140 |
localStorage.setItem("parentStudentId", this.changeStudent); |
11d037abe
|
141 142 143 144 145 146 |
localStorage.setItem( "parentClassId", response.data.data.students[0].classId ); this.showLoader = false; }) |
fa975e45a
|
147 |
.catch((err) => { |
11d037abe
|
148 149 150 |
console.log("err====>", err); this.showLoader = false; }); |
fa975e45a
|
151 |
}, |
11d037abe
|
152 153 154 155 |
}, computed: { color() { return this.loading ? "success" : "error"; |
fa975e45a
|
156 157 |
}, }, |
11d037abe
|
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
}; </script> <style scoped> img { position: absolute; top: 13px; left: 50px; } .v-btn--large { padding: 0px 74px; } @media screen and (max-width: 769px) { .v-btn--large { font-size: 14px; height: 44px; padding: 0 32px; } } </style> |