summaryrefslogblamecommitdiffstats
path: root/webapp/src/components/GroupModuleGroupView.vue
blob: 602e05de1f631924d6a2bbbe73b9e4cfe3b87a30 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11










          



                                   

















































                                                                                                                                                                                     
                                           

                                                                                                         

                   
                                                                     
                                    
                                                                                                  


                                                

                                                                                                   
                                                
                        
                    


                   

                    

                                                                             
                                                                                                    
                                        
                                                                                                    
               








                                                                      
                               





                         


                      


                       

     








                                                                 

                       
                                                          




                                                    
                                                                                  


                           
                               

                                                                                         

                 





                                                
                           
     





                                                                   


               
             
               
 






                       










                      
        
<i18n>
{
  "en": {
  },
  "de": {
  }
}
</i18n>

<template>
  <div>
    <v-subheader>Info</v-subheader>
    <v-card>
      <v-card-text>
        <v-layout wrap>
          <v-flex lg4 md6 xs12 order-lg1 order-xs2>
            <v-layout column>
              <v-flex>
                <v-text-field prepend-icon="label" v-if="editMode" class="info-input" label="Name" color="primary" v-model="info.name"></v-text-field>
                <div v-else class="info-input">
                  <div class="body-2 info-heading"><v-icon>label</v-icon><span>Name</span></div>
                  <div class="info-text">{{ group.name || '-' }}</div>
                </div>
              </v-flex>
              <v-flex>
                <v-autocomplete
                  prepend-icon="group_work"
                  v-if="editMode"
                  class="info-input"
                  :items="$store.state.groups.groupList"
                  v-model="parentIds"
                  offset-y
                  label="Parents"
                  color="primary"
                  multiple
                  item-value="id"
                >
                  <template slot="selection" slot-scope="data">
                    <v-chip small :selected="data.selected" @input="removeParent(data.item.id)" close>
                      {{ data.item.name || data.item.id }}
                    </v-chip>
                  </template>
                  <template slot="item" slot-scope="data">
                    <div class="select-item">
                      <v-checkbox class="select-item-checkbox" color="primary" :value="parentIds.includes(data.item.id)" hide-details></v-checkbox>
                      {{ data.item.name || data.item.id }}
                    </div>
                  </template>
                </v-autocomplete>
                <div v-else class="info-input">
                  <div class="body-2 info-heading"><v-icon>description</v-icon><span>Parents</span></div>
                  <div class="info-text">
                    <template v-if="group.parents && group.parents.length > 0">
                      <v-chip v-for="parent in group.parents" :key="parent.id" small>
                        {{ parent.name || parent.id }}
                      </v-chip>
                    </template>
                    <span v-else>-</span>
                  </div>
                </div>
              </v-flex>
            </v-layout>
          </v-flex>
          <v-flex lg4 md6 xs12 order-lg2 order-xs3>
            <v-textarea prepend-icon="description" v-if="editMode" rows="1" auto-grow class="info-input" label="Description" color="primary" v-model="info.description"></v-textarea>
            <div v-else class="info-input">
              <div class="body-2 info-heading"><v-icon>description</v-icon><span>Description</span></div>
              <pre class="info-text">{{ group.description || '-' }}</pre>
            </div>
          </v-flex>
          <v-flex lg4 xs12 order-lg3 order-xs1 class="text-xs-right">
            <div class="info-input">
              <v-btn v-if="!editMode" color="primary" flat @click="editInfo" class="info-buttons">
                <v-icon left>create</v-icon>Edit
              </v-btn>
              <div v-else>
                <v-btn color="primary" flat @click="cancelEdit" class="info-buttons">Cancel</v-btn>
                <v-btn color="primary" @click="saveInfo" class="info-buttons">
                  <v-icon left>save</v-icon>Save
                </v-btn>
              </div>
            </div>
          </v-flex>
        </v-layout>
      </v-card-text>
    </v-card>
    <template v-if="group.id">
      <v-subheader>{{ tabIndex === 0 ? 'Groups' : 'Subgoups' }}</v-subheader>
      <group-module-group-list :tabIndex="tabIndex" :groupId="group.id" :groups="group.subgroups" />
      <v-subheader>Clients</v-subheader>
      <group-module-client-list :tabIndex="tabIndex" :groupId="group.id" :clients="group.clients" />
    </template>
  </div>
</template>

<script>
import GroupModuleGroupList from '@/components/GroupModuleGroupList'
import GroupModuleClientList from '@/components/GroupModuleClientList'

export default {
  name: 'GroupModuleGroupView',
  props: ['tabIndex', 'group'],
  components: {
    GroupModuleGroupList,
    GroupModuleClientList
  },
  data () {
    return {
      editMode: false,
      info: {
        name: '',
        description: ''
      },
      parentIds: []
    }
  },
  created () {
    if (!this.group.id) this.editInfo()
  },
  watch: {
    group (newValue, oldValue) {
      if (!newValue.id) this.editInfo()
      else if (newValue.id !== oldValue.id) this.editMode = false
    }
  },
  methods: {
    removeParent (id) {
      this.parentIds.splice(this.parentIds.indexOf(id), 1)
    },
    editInfo () {
      this.editMode = true
      this.info.name = this.group.name
      this.info.description = this.group.description
      this.parentIds = this.group.parents ? this.group.parents.map(x => x.id) : []
    },
    cancelEdit () {
      this.editMode = false
      if (this.group.id) return
      this.$store.commit('groups/deleteFromTabChain', { index: this.tabIndex, count: 1 })
      this.$store.commit('groups/setActiveTab', this.tabIndex - 1)
    },
    saveInfo () {
      this.$store.dispatch('groups/saveGroup', {
        id: this.group.id,
        info: this.info,
        parentIds: this.parentIds,
        tabIndex: this.tabIndex
      })
      this.editMode = false
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.info-buttons {
  margin: 0;
}
.info-input {
  margin: 20px;
}
.select-item {
  display: flex;
  align-items: center;
}
.select-item-checkbox {
  margin-right: 20px;
}
.info-heading {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}
.info-heading > span {
  margin-left: 10px;
}
.info-text {
  margin-left: 34px;
}
</style>