Newer
Older
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
<template>
<b-modal id="rename-group-modal" title="Rename group" ok-title="Rename" @ok="renameGroup">
<b-form inline>
<label class="w-25" for="new-group-name-input">Group name:</label>
<b-form-input v-model="newGroupName"
id="new-group-name-input"
class="w-75"
aria-describedby="new-group-name-input-feedback"
:state="newGroupNameState"
v-on:input="resetError">
</b-form-input>
<b-form-invalid-feedback id="new-group-name-input-feedback">{{newGroupNameError}}</b-form-invalid-feedback>
</b-form>
</b-modal>
</template>
<script>
import client from 'api-client';
export default {
name: 'RenameGroupModal',
computed: {
newGroupNameState() {
if(this.newGroupNameError) {
return 'invalid';
}
}
},
data: function() {
return {
groupId: null,
oldGroupName: null,
newGroupName: null,
newGroupNameError: null
};
},
methods: {
resetError: function() {
this.newGroupNameError = null;
},
openRenameGroupModal: function(group) {
this.newGroupName = group.groupName;
this.groupId = group.groupId;
this.$bvModal.show('rename-group-modal');
},
renameGroup: function(event) {
// Prevent modal from closing
event.preventDefault();
if(!this.newGroupName) {
this.newGroupNameError = "Group name is required";
return;
}
if(this.oldGroupName === this.newGroupName) {
this.$bvModal.hide('rename-group-modal');
return;
}
let parent = this.$store.getters.selectedGroupId;
client.renameGroup(this.groupId, this.newGroupName, this.$store.state.input)
.then(res => {
if(res.status === 400) {
this.newGroupNameError = res.message;
} else {
this.$store.commit('updateGroupsPanel', res);
this.$bvModal.hide('rename-group-modal');
}
});
}
}
}
</script>