blob: 8589aed3ad9354faeda69525f2071ee62561c600 [file] [log] [blame]
Sukanya Pandeybe6858c2020-12-16 20:08:01 +05301<template>
2 <b-container fluid="xl">
3 <page-title :description="$t('pagePowerRestorePolicy.description')" />
4
5 <b-row>
6 <b-col sm="8" md="6" xl="12">
7 <b-form-group :label="$t('pagePowerRestorePolicy.powerPoliciesLabel')">
8 <b-form-radio
9 v-for="policy in powerRestorePolicies"
10 :key="policy.state"
11 v-model="currentPowerRestorePolicy"
12 :value="policy.state"
13 name="power-restore-policy"
14 >
15 {{ policy.desc }}
16 </b-form-radio>
17 </b-form-group>
18 </b-col>
19 </b-row>
20
21 <b-button variant="primary" type="submit" @click="submitForm">
22 {{ $t('global.action.saveSettings') }}
23 </b-button>
24 </b-container>
25</template>
26
27<script>
28import PageTitle from '@/components/Global/PageTitle';
29import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
30import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
31import BVToastMixin from '@/components/Mixins/BVToastMixin';
32
33export default {
34 name: 'PowerRestorePolicy',
35 components: { PageTitle },
36 mixins: [VuelidateMixin, BVToastMixin, LoadingBarMixin],
37 beforeRouteLeave(to, from, next) {
38 this.hideLoader();
39 next();
40 },
41 data() {
42 return {
43 policyValue: null,
44 };
45 },
46 computed: {
47 powerRestorePolicies() {
48 return this.$store.getters['powerPolicy/powerRestorePolicies'];
49 },
50 currentPowerRestorePolicy: {
51 get() {
52 return this.$store.getters['powerPolicy/powerRestoreCurrentPolicy'];
53 },
54 set(policy) {
55 this.policyValue = policy;
56 },
57 },
58 },
59 created() {
60 this.startLoader();
61 Promise.all([
62 this.$store.dispatch('powerPolicy/getPowerRestorePolicies'),
63 this.$store.dispatch('powerPolicy/getPowerRestoreCurrentPolicy'),
64 ]).finally(() => this.endLoader());
65 },
66 methods: {
67 submitForm() {
68 this.startLoader();
69 this.$store
70 .dispatch(
71 'powerPolicy/setPowerRestorePolicy',
72 this.policyValue || this.currentPowerRestorePolicy
73 )
74 .then((message) => this.successToast(message))
75 .catch(({ message }) => this.errorToast(message))
76 .finally(() => this.endLoader());
77 },
78 },
79};
80</script>