add types of group
This commit is contained in:
parent
556f8a24c0
commit
6364056ae1
|
@ -69,11 +69,18 @@ func (h *ApplicationHandler) CreateGroupModule(w http.ResponseWriter, r *http.Re
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if r.FormValue("type") == "" {
|
||||||
|
|
||||||
|
fmt.Println("invalid type")
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
groupid := uuid.NewString()
|
groupid := uuid.NewString()
|
||||||
|
|
||||||
dataMap := map[string]any{
|
dataMap := map[string]any{
|
||||||
"name": r.FormValue("name"),
|
"name": r.FormValue("name"),
|
||||||
|
"type": r.FormValue("type"),
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := structpb.NewValue(dataMap)
|
data, err := structpb.NewValue(dataMap)
|
||||||
|
@ -101,7 +108,8 @@ func (h *ApplicationHandler) CreateGroupModule(w http.ResponseWriter, r *http.Re
|
||||||
http.Redirect(w, r, fmt.Sprintf("/app/group_module/groups/%s", groupid), http.StatusFound)
|
http.Redirect(w, r, fmt.Sprintf("/app/group_module/groups/%s", groupid), http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h.Renderer.CreateGroupModule(w, r)
|
group_types := h.config.GetStringSlice("modules.groups.group_types")
|
||||||
|
h.Renderer.CreateGroupModule(w, r, group_types)
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterAcccount(r *http.Request, a *mobilityaccounts.Account) bool {
|
func filterAcccount(r *http.Request, a *mobilityaccounts.Account) bool {
|
||||||
|
|
|
@ -38,10 +38,12 @@ func (renderer *Renderer) Groups(w http.ResponseWriter, r *http.Request, groups
|
||||||
renderer.Render("group_module", w, r, files, state)
|
renderer.Render("group_module", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (renderer *Renderer) CreateGroupModule(w http.ResponseWriter, r *http.Request) {
|
func (renderer *Renderer) CreateGroupModule(w http.ResponseWriter, r *http.Request, group_types []string) {
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.group_module.create_group.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.group_module.create_group.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, groupMenu)
|
state := NewState(r, renderer.ThemeConfig, groupMenu)
|
||||||
|
state.ViewState = map[string]any{
|
||||||
|
"group_types": group_types,
|
||||||
|
}
|
||||||
renderer.Render("group_module", w, r, files, state)
|
renderer.Render("group_module", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,14 +8,17 @@
|
||||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 md:px-8 mt-8" x-data="{
|
<div class="max-w-7xl mx-auto px-4 sm:px-6 md:px-8 mt-8" x-data="{
|
||||||
fields: {
|
fields: {
|
||||||
name: null,
|
name: null,
|
||||||
|
type: null,
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
name: ['required'],
|
name: ['required'],
|
||||||
|
type: ['required'],
|
||||||
},
|
},
|
||||||
formValidation: {
|
formValidation: {
|
||||||
valid: false,
|
valid: false,
|
||||||
fields: {
|
fields: {
|
||||||
name: {valid: null},
|
name: {valid: null},
|
||||||
|
type: {valid: null},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isFormValid: true,
|
isFormValid: true,
|
||||||
|
@ -33,6 +36,7 @@
|
||||||
}
|
}
|
||||||
return this.formValidation.valid
|
return this.formValidation.valid
|
||||||
}
|
}
|
||||||
|
|
||||||
}">
|
}">
|
||||||
<form class="space-y-6" method="POST" @submit="submit">
|
<form class="space-y-6" method="POST" @submit="submit">
|
||||||
<div class="bg-white shadow px-4 py-5 sm:rounded-lg sm:p-6">
|
<div class="bg-white shadow px-4 py-5 sm:rounded-lg sm:p-6">
|
||||||
|
@ -43,16 +47,30 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-5 md:mt-0 md:col-span-2">
|
<div class="mt-5 md:mt-0 md:col-span-2">
|
||||||
<div class="grid grid-cols-6 gap-6">
|
<div class="grid grid-cols-6 gap-6">
|
||||||
<div class="col-span-6">
|
<div class="col-span-5">
|
||||||
<label for="name" class="block text-sm font-medium text-gray-700">Nom de groupe</label>
|
<label for="name" class="block text-sm font-medium text-gray-700">Nom de groupe</label>
|
||||||
<input type="text" name="name" id="name"
|
<input type="text" name="name" id="name"
|
||||||
class="mt-1 focus:ring-co-blue focus:border-co-blue block w-full shadow-sm sm:text-sm rounded-2xl"
|
class="mt-1 focus:ring-co-blue focus:border-co-blue block w-full shadow-sm sm:text-sm rounded-2xl"
|
||||||
x-model="fields.name" @blur="validateField('name')"
|
x-model="fields.name" @blur="validateField('name')"
|
||||||
:class="formValidation.fields.name.valid == false ? 'border-co-red border-2' : 'border-gray-300'">
|
:class="formValidation.fields.name.valid == false ? 'border-co-red border-2' : 'border-gray-300'">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-span-3">
|
||||||
|
<label for="type" class="block text-sm font-medium text-gray-700">Type de groupe</label>
|
||||||
|
<select id="type" name="type"
|
||||||
|
x-model="fields.type" @blur="validateField('type')"
|
||||||
|
class="max-w-lg mt-1 block focus:ring-co-blue focus:border-co-blue w-full shadow-sm sm:max-w-xs sm:text-sm rounded-2xl"
|
||||||
|
:class="formValidation.fields.type.valid == false ? 'border-co-red border-2' : 'border-gray-300'">
|
||||||
|
<option value="" selected></option>
|
||||||
|
{{range .ViewState.group_types}}
|
||||||
|
<option value="{{.}}">{{.}}</option>
|
||||||
|
{{end}}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-end">
|
<div class="flex justify-end">
|
||||||
<a href="/app/group_module/">
|
<a href="/app/group_module/">
|
||||||
|
@ -63,5 +81,6 @@
|
||||||
class="ml-3 inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-2xl text-white bg-co-blue hover:bg-co-blue focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-co-blue">Créer le groupe</button>
|
class="ml-3 inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-2xl text-white bg-co-blue hover:bg-co-blue focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-co-blue">Créer le groupe</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
|
@ -21,6 +21,11 @@
|
||||||
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
|
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
|
||||||
{{.ViewState.group.Data.name}}</dd>
|
{{.ViewState.group.Data.name}}</dd>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="py-4 sm:py-5 sm:grid sm:grid-cols-3 sm:gap-4">
|
||||||
|
<dt class="text-sm font-medium text-gray-500">Type</dt>
|
||||||
|
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
|
||||||
|
{{.ViewState.group.Data.type}}</dd>
|
||||||
|
</div>
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue