aboutsummaryrefslogtreecommitdiff
path: root/resources/vue/store/theme-settings.module.js
blob: a0ae0747fb6bd399dc7d55327e45d0ce7507037e (plain)
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
const getDefaultState = () => {
    return {
        httpClient: null,
        userId: null,

        showThemeAddDialog: false,
        showThemeAddImportDialog: false,
        showThemeAddCopyDialog: false,
    };
};

const initialState = getDefaultState();

const getters = {

    httpClient(state) {
        return state.httpClient;
    },
    userId(state) {
        return state.userId;
    },
    showThemeAddDialog(state) {
        return state.showThemeAddDialog;
    },
    showThemeAddImportDialog(state) {
        return state.showThemeAddImportDialog;
    },
    showThemeAddCopyDialog(state) {
        return state.showThemeAddCopyDialog;
    },
};

export const state = { ...initialState };


export const actions = {
    // setters
    setHttpClient({ commit }, httpClient) {
        commit('setHttpClient', httpClient);
    },
    setUserId({ commit }, userId) {
        commit('setUserId', userId);
    },

    setShowThemeAddDialog({ commit }, show) {
        commit('setShowThemeAddDialog', show);
    },
    setShowThemeAddImportDialog({ commit }, show) {
        commit('setShowThemeAddImportDialog', show);
    },
    setShowThemeAddCopyDialog({ commit }, show) {
        commit('setShowThemeAddCopyDialog', show);
    },

    // actions
    async updateTheme({ dispatch }, { theme }) {
        await dispatch('studip-themes/update', theme, { root: true });

        return dispatch(
            'studip-themes/loadById',
            { id: theme.id },
            { root: true }
        );
    },

    async activateTheme({ dispatch }, { theme }) {
        const activeTheme = {
            id: theme.id,
            attributes: {
                active: true,
            }
        };
        await dispatch('studip-themes/update', activeTheme, { root: true });

        return true;
    },

    async addTheme({ dispatch, rootGetters }) {
        await dispatch('studip-themes/create', {}, { root: true });
        const created = rootGetters['studip-themes/lastCreated'];

        await dispatch(
            'studip-themes/loadById',
            { id: created.id },
            { root: true }
        );

        return created;
    },

    createThemeFromData( { dispatch }, { theme }) {
        dispatch('studip-themes/create', theme, { root: true });
    },

    deleteTheme({ dispatch }, data) {
        return dispatch('studip-themes/delete', data, { root: true });
    },
}
export const mutations = {
    setHttpClient(state, httpClient) {
        state.httpClient = httpClient;
    },
    setUserId(state, data) {
        state.userId = data;
    },

    setShowThemeAddDialog(state, show) {
        state.showThemeAddDialog = show;
    },
    setShowThemeAddImportDialog(state, show) {
        state.showThemeAddImportDialog = show;
    },
    setShowThemeAddCopyDialog(state, show) {
        state.showThemeAddCopyDialog = show;
    },
};

export default {
    namespaced: true,
    state,
    actions,
    mutations,
    getters,
};