@@ -3,7 +3,16 @@ div.flex
33 div
44 q-btn( color ="positive" icon ='mdi-content-save-plus' @click ="create" v-show ="isNew" v-if ="crud.create" )
55 q-tooltip.text-body2 Créer
6- q-toggle.q-pa-md.q-gutter-y-xl ( v-if ="props.identity?._id" @click ="activate" color ="green" left-label ='Inactif' label ="Actif" v-model ="activation" )
6+ q-toggle.q-pa-md.q-gutter-y-lg ( unchecked-icon ="mdi-account-cancel"
7+ checked-icon ="mdi-account-check"
8+ size ="xl"
9+ @click ="activate"
10+ :color ="setActivateColor()"
11+ label ="Activation"
12+ v-model ="props.identity.dataStatus"
13+ :true-value ="1"
14+ :false-value ="0"
15+ )
716 q-btn.q-mx-xs ( @click ="sendInit" color ="primary" icon ="mdi-email-arrow-right" :disabled ="props.identity.state != IdentityState.SYNCED" )
817 q-tooltip.text-body2 ( slot ="trigger" ) Envoyer le mail d'invitation
918 q-btn.q-mx-xs ( @click ="submit" color ="positive" icon ="mdi-check" v-show ="!isNew" v-if ="crud.update" )
@@ -61,16 +70,39 @@ async function create() {
6170 // console.log('submit from actions')
6271 emits (' create' )
6372}
73+ function setActivateColor(){
74+ if (props .identity .lastBackendSync != " " ){
75+ return " green"
76+ }else {
77+ return " grey"
78+ }
79+ }
80+ function showActivate(){
81+ if (props .identity .lastBackendSync != " " ){
82+ return true
83+ }else {
84+ return false
85+ }
86+ }
6487async function activate(){
88+
89+
6590 let message= " "
6691 let bouton = " "
67- debugger
68- if (activation . value === false ){
92+ let initialStatus = 0
93+ if (props . identity . dataStatus === 0 ){
6994 message = " Voulez vous vraiment désactiver l'identité"
7095 bouton = " Désactiver"
96+ initialStatus = 1
7197 }else {
7298 message = " Voulez vous vraiment activer l'identité"
7399 bouton = " Activer"
100+ initialStatus = 0
101+ }
102+ debugger
103+ if (showActivate () === false ){
104+ props .identity .dataStatus = initialStatus
105+ return
74106 }
75107
76108 $q .dialog ({
@@ -88,14 +120,29 @@ async function activate(){
88120 label: ' Annuler' ,
89121 },
90122 }).onOk (async () => {
123+ alert (' test =' + props .identity .dataStatus )
91124 const requestOptions= {method: ' POST' ,
92- body:JSON .stringify ({id:props .identity ._id ,status:activation .value })}
93- const data= await $http .post (' /management/identities/activation' , requestOptions )
94- .catch (error => {
95- alert (' There was an error!' );
125+ body:JSON .stringify ({id:props .identity ._id ,status:props .identity .dataStatus === 1 ? true : false })}
126+ try {
127+ const data= await $http .post (' /management/identities/activation' , requestOptions )
128+ $q .notify ({
129+ message: ' Le statut a été mis à jour : ' ,
130+ color: ' positive' ,
131+ position: ' top-right' ,
132+ icon: ' mdi-check-circle-outline' ,
133+ })
134+ }catch (error ){
135+ props .identity .dataStatus = initialStatus
136+ $q .notify ({
137+ message: ' Impossible de modifier le statut : ' + error .response ._data .message ,
138+ color: ' negative' ,
139+ position: ' top-right' ,
140+ icon: ' mdi-alert-circle-outline' ,
96141 })
142+ }
143+
97144 }).onCancel (() => {
98- activation . value = activation . value === true ? activation . value = false : activation . value = true
145+ props . identity . dataStatus = initialStatus
99146 })
100147
101148}
0 commit comments