summaryrefslogblamecommitdiffstats
path: root/webapp/src/store/groups.js
blob: 8ce7f6bcf6cd95f3eb4d4cdcd8ac0c7f09fe7f87 (plain) (tree)
1
2
3
4
5
6
7
8
9





                         

                           
                   




                                       



                                                                                              
       







                                        


            
                                                                   

                                                                       
                                                                                                   


                                                                                                        
         

                                       
                                                                



                                                                                        
                                                                                     

                                              


     
import axios from 'axios'

export default {
  namespaced: true,
  state: {
    groupChain: [],
    activeTab: 0,
    editGroupDialog: false,
    editGroup: null
  },
  mutations: {
    updateActiveTab (state, tabIndex) {
      state.activeTab = tabIndex
    },
    setGroupInChain (state, { tabIndex, group }) {
      if (state.groupChain.length <= tabIndex || state.groupChain[tabIndex].id !== group.id) {
        state.groupChain = state.groupChain.slice(0, tabIndex)
        state.groupChain.push(group)
      }
    },
    openEditGroupDialog (state, group) {
      state.editGroupDialog = true
      state.editGroup = group
    },
    closeEditGroupDialog (state) {
      state.editGroupDialog = false
      state.editGroup = null
    }
  },
  actions: {
    loadGroupInChain (context, { id, name, tabIndex, switchTab }) {
      var getSubGroups = axios.get('/api/groups/getSubGroups?id=' + id)
      var getClients = axios.get('/api/groups/getClients?id=' + id)
      axios.all([getSubGroups, getClients]).then(axios.spread((groupRespsonse, clientResponse) => {
        var group = { id: id, name: name, subGroups: groupRespsonse.data, clients: clientResponse.data }
        context.commit('setGroupInChain', { group: group, tabIndex: tabIndex })
        if (switchTab) context.commit('updateActiveTab', tabIndex)
      }))
    },
    editGroup (context, { id, name }) {
      axios.get('/api/groups/getParents?id=' + id).then(res => {
        context.commit('openEditGroupDialog', { id: id, name: name, parents: res.data })
      })
    },
    saveGroup (context) {
      axios.post('/api/groups/update?id=' + context.state.editGroup.id).then(res => {
        context.commit('closeEditGroupDialog')
      })
    }
  }
}