/
AddUserWizard.vue
161 lines (149 loc) · 5.98 KB
/
AddUserWizard.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
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
79
80
81
82
83
84
85
86
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<template>
<div class="modal fade" id="addUserModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h2><IconifyIcon v-bind:icon="icons.userIcon"></IconifyIcon> Add User Wizard</h2>
<button type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
id="addUserCloseButton"
>
<span aria-hidden="true"></span>
</button>
</div>
<div class="modal-body">
<div v-if="userFixList.length > 0"
class="row">
<div class="col-md-4">
<strong>Add Users</strong>
<p class="text-instructions">
Use the following multiple select to select which users you want to add to this
{{destination}}.
</p>
<p class="text-instructions">
Please note: A user's group has to be added to the {{destination}} before the user
can be added.
</p>
</div>
<div class="col-md-8">
<v-select :options="userFixList"
v-model="userModel"
multiple
></v-select>
</div>
</div>
<div v-else
class="row"
>
<div class="col-md-6">
<strong>Sorry - no results</strong>
<p class="text-instructions">
This could be because
<ul>
<li>There are no more users left to add</li>
<li>
The user you are after is in a group not current added to this {{destination}}
</li>
</ul>
</p>
</div>
<div class="col-md-6 no-search">
<img src="/static/NearBeach/images/placeholder/questions.svg" alt="Sorry - there are no results" />
</div>
</div>
</div>
<div class="modal-footer">
<button type="button"
class="btn btn-secondary"
data-bs-dismiss="modal"
>Close</button>
<button type="button"
class="btn btn-primary"
v-bind:disabled="userModel.length==0"
v-on:click="addUser"
>Add User(s)</button>
</div>
</div>
</div>
</div>
</template>
<script>
const axios = require('axios');
//Mixins
import errorModalMixin from "../../../mixins/errorModalMixin";
import iconMixin from "../../../mixins/iconMixin";
export default {
name: "AddUserWizard",
props: [
'destination',
'locationId',
'refreshUserList'
],
mixins: [
errorModalMixin,
iconMixin,
],
data() {
return {
userFixList: [],
userModel: [],
}
},
methods: {
addUser: function() {
//Construct the data_to_send array
const data_to_send = new FormData();
//Look through all of the results in user model and append
this.userModel.forEach(row => {
data_to_send.append('user_list',row['value']);
});
//User axios to send the data to the backend
axios.post(
`/object_data/${this.destination}/${this.locationId}/add_user/`,
data_to_send
).then(response => {
//Emit the data up
this.$emit('update_user_list',response['data']);
//Close the modal
document.getElementById("addUserCloseButton").click();
//Clear the models
this.userModel = [];
//Update the list of users
this.getUserList();
}).catch(error => {
this.showErrorModal(error, this.destination);
});
},
getUserList: function() {
axios.post(
`/object_data/${this.destination}/${this.locationId}/user_list_all/`,
).then(response => {
//Clear the user fix list
this.userFixList = response['data'].map(row => {
return {
'value': row['id'],
'label': `${row['username']}: ${row['first_name']} ${row['last_name']}`
}
});
});
}
},
watch: {
refreshUserList: function() {
//Looks like the system has send the call function to reset the user list.
if (this.refreshUserList) {
this.getUserList();
}
//Turn it false again
this.$emit('reset_refresh_user_list');
},
},
mounted() {
this.getUserList();
},
}
</script>
<style scoped>
</style>