Simplify code

This commit is contained in:
Björn Fromme
2019-10-02 16:22:37 +02:00
parent 3c32cfc05b
commit 2d6d8e840c
3 changed files with 52 additions and 60 deletions
@@ -19,8 +19,7 @@
</template> </template>
</div> </div>
<div class="col-xs-12 col-md-6"> <div class="col-xs-12 col-md-6">
<div class="checkbox" v-for="action in crmData.actions" <div class="checkbox" v-for="action in crmData.actions" v-if="action.changeable === true">
v-if="action.changeable === true">
<label :class="{ disabled: !action.changeable}"> <label :class="{ disabled: !action.changeable}">
<input type="checkbox" class="form-control" <input type="checkbox" class="form-control"
v-model="action.value" :disabled="!action.changeable"/> v-model="action.value" :disabled="!action.changeable"/>
@@ -56,7 +55,19 @@
} }
}, },
created () { created () {
this.load() this.beginLoading();
return this.getClient().get('/api/crm-selections')
.then(response => {
this.crmData = response.data
}).catch(error => {
this.alert({
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
})
}).finally(() => {
this.endLoading()
});
}, },
methods: { methods: {
...mapMutations(['beginLoading', 'endLoading', 'alert']), ...mapMutations(['beginLoading', 'endLoading', 'alert']),
@@ -67,21 +78,6 @@
} }
}); });
}, },
load () {
this.beginLoading();
return this.getClient().get('/api/crm-selections')
.then(response => {
this.crmData = response.data
}).catch(error => {
this.alert({
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
})
}).finally(() => {
this.endLoading()
});
},
save () { save () {
this.beginLoading(); this.beginLoading();
@@ -61,31 +61,28 @@
} }
}, },
created () { created () {
this.load() this.beginLoading();
const client = axios.create({
headers: {
'Authorization': 'Bearer ' + this.authToken
}
});
return client.get('/api/events')
.then(response => {
this.events = response.data;
}).catch(error => {
this.alert({
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
});
}).finally(() => {
this.endLoading();
});
}, },
methods: { methods: {
...mapMutations(['beginLoading', 'endLoading', 'alert']), ...mapMutations(['beginLoading', 'endLoading', 'alert']),
load () {
this.beginLoading();
const client = axios.create({
headers: {
'Authorization': 'Bearer ' + this.authToken
}
});
return client.get('/api/events')
.then(response => {
this.events = response.data;
}).catch(error => {
this.alert({
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
});
}).finally(() => {
this.endLoading();
});
},
formatBookingDate (date) { formatBookingDate (date) {
if (!date) { if (!date) {
return '-' return '-'
@@ -60,9 +60,13 @@
{{ timeFrame | period }} {{ timeFrame | period }}
</label> </label>
</div> </div>
<form-checkbox :value.sync="userData.monthLong"> <div class="checkbox">
Ich habe Zeit und würde gerne über einen Monat am Stück in eine Destination. <label>
</form-checkbox> <input type="checkbox" class="form-control" v-model="userData.monthLong"/>
<span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>
Ich habe Zeit und würde gerne über einen Monat am Stück in eine Destination.
</label>
</div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
@@ -84,12 +88,10 @@
import dayjs from 'dayjs' import dayjs from 'dayjs'
import 'dayjs/locale/de' import 'dayjs/locale/de'
import FormGroup from './components/FormGroup'; import FormGroup from './components/FormGroup';
import FormCheckbox from './components/FormCheckbox';
export default { export default {
components: { components: {
FormGroup, FormGroup
FormCheckbox
}, },
data () { data () {
return { return {
@@ -112,19 +114,6 @@
} }
}); });
}, },
load () {
this.beginLoading();
return this.getClient().get('/api/teamer-data')
.then(response => {
this.abilities = response.data.abilities;
this.timeFrames = response.data.timeFrames;
this.jobProfiles = response.data.jobProfiles;
}).catch(error => {
}).finally(() => {
this.endLoading();
});
},
save () { save () {
const data = { const data = {
abilities: this.userData.abilities, abilities: this.userData.abilities,
@@ -156,7 +145,17 @@
} }
}, },
created () { created () {
this.load() this.beginLoading();
return this.getClient().get('/api/teamer-data')
.then(response => {
this.abilities = response.data.abilities;
this.timeFrames = response.data.timeFrames;
this.jobProfiles = response.data.jobProfiles;
}).catch(error => {
}).finally(() => {
this.endLoading();
});
}, },
computed: { computed: {
...mapState(['userData', 'loading', 'authToken']) ...mapState(['userData', 'loading', 'authToken'])