modal with func add data
This commit is contained in:
@@ -6,12 +6,14 @@ import (
|
||||
navbarmenu "cpone/component/navbar"
|
||||
"cpone/component/pagination"
|
||||
sidebaruserprofile "cpone/component/sidebar_user_profile"
|
||||
customtoastv2 "cpone/component/toastbootstrap"
|
||||
"cpone/models"
|
||||
"cpone/services"
|
||||
"cpone/utils"
|
||||
dev_mdsamplestationview "cpone/views/dev/mdsamplestation"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/labstack/echo/v4"
|
||||
@@ -21,6 +23,11 @@ import (
|
||||
type MDSampleStationServices interface {
|
||||
GetMDSampleStationBreadcrumb() (models.BreadCrumbV1, error)
|
||||
GetListSampleStation(search string, currentPage int, rowPerPage int) ([]models.MDSampleStation, int, error)
|
||||
GetMDSampleStationByID(id string) (models.MDSampleStation, error)
|
||||
GetListGroupSampleStation() ([]models.MDSampleStationGroup, error)
|
||||
AddMDSampleStation(code string, name string, group string) (models.MDSampleStation, error)
|
||||
EditMDSampleStation(id string, code string, name string, group string) (models.MDSampleStation, error)
|
||||
DeleteMDSampleStation(id string) (models.MDSampleStation, error)
|
||||
}
|
||||
|
||||
func NewMDSampleStationHandler(ss MDSampleStationServices) *MDSampleStationHandler {
|
||||
@@ -121,6 +128,201 @@ func (mdss *MDSampleStationHandler) HandleShowMDSampleStationScreen(c echo.Conte
|
||||
dev_mdsamplestationview.AfterRequestContent(),
|
||||
)
|
||||
|
||||
// list group dropdown
|
||||
listGroupSS, err := mdss.MDSampleStationServices.GetListGroupSampleStation()
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERROR LIST GROUP DEV", zap.Any("error", err))
|
||||
return err
|
||||
}
|
||||
dropdownGroupItem := dev_mdsamplestationview.ItemGroupDropdown(listGroupSS, 0)
|
||||
|
||||
// modal add form
|
||||
dialogAddBodyCmp := dev_mdsamplestationview.BodyFormMDSampleStation(
|
||||
dialogAddBodyID,
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationid",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "hidden",
|
||||
ID: "samplestationinputid",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationcode",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Nama Sample Station",
|
||||
Name: "samplestationname",
|
||||
Placeholder: "Nama Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
},
|
||||
models.CustomDropdownv1Prm{
|
||||
Label: "Group",
|
||||
Name: "samplestationgroup",
|
||||
ID: "samplestationinputgroup",
|
||||
},
|
||||
dropdownGroupItem,
|
||||
dev_mdsamplestationview.JSHideModal(""),
|
||||
)
|
||||
|
||||
modalActionAddCmp := dev_mdsamplestationview.ActionFormMDSampleStation(
|
||||
"/dev/md/samplestation/closeaddform",
|
||||
"#"+dialogAddBodyID,
|
||||
"outerHTML",
|
||||
"#"+dialogAddID,
|
||||
)
|
||||
|
||||
btnCloseModalAdd := dev_mdsamplestationview.BtnCloseFormMDSampleStation(
|
||||
"/dev/md/samplestation/closeaddform",
|
||||
"#"+dialogAddBodyID,
|
||||
"outerHTML",
|
||||
"#"+dialogAddID,
|
||||
)
|
||||
|
||||
modalAddFormComponent := dev_mdsamplestationview.MDSampleStationForm(
|
||||
models.MDSampleStationForm{
|
||||
IDComponent: "formsamplestation",
|
||||
Link: "/dev/md/samplestation/add",
|
||||
HxTarget: "#" + dialogAddBodyID,
|
||||
HxSwap: "outerHTML",
|
||||
HxInclude: "#tableID, #paginationID, #searchID, #dialogAddBodyID, #dialogAddID, #dialogDeleteBodyID, #dialogEditBodyID, #" + searchID + ", #currpage" + paginationID,
|
||||
ModalID: dialogAddID,
|
||||
ModalTitle: "New-Sample Station",
|
||||
DialogBody: dialogAddBodyCmp,
|
||||
DialogAction: modalActionAddCmp,
|
||||
ButtonClose: btnCloseModalAdd,
|
||||
},
|
||||
)
|
||||
|
||||
// modal edit form
|
||||
dialogEditFormComp := dev_mdsamplestationview.BodyFormMDSampleStation(
|
||||
dialogEditBodyID,
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationid",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "hidden",
|
||||
ID: "samplestationinputid",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationcode",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Nama Sample Station",
|
||||
Name: "samplestationname",
|
||||
Placeholder: "Nama Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
},
|
||||
models.CustomDropdownv1Prm{
|
||||
Label: "Group",
|
||||
Name: "samplestationgroup",
|
||||
ID: "samplestationinputgroup",
|
||||
},
|
||||
dropdownGroupItem,
|
||||
dev_mdsamplestationview.JSHideModal(""),
|
||||
)
|
||||
|
||||
modalActionEditComp := dev_mdsamplestationview.ActionFormMDSampleStation(
|
||||
"/dev/md/samplestation/closeeditform",
|
||||
"#"+dialogEditBodyID,
|
||||
"outerHTML",
|
||||
"#"+dialogEditID,
|
||||
)
|
||||
|
||||
btnCloseModalEdit := dev_mdsamplestationview.BtnCloseFormMDSampleStation(
|
||||
"/dev/md/samplestation/closeeditform",
|
||||
"#"+dialogEditBodyID,
|
||||
"outerHTML",
|
||||
"#"+dialogEditID,
|
||||
)
|
||||
|
||||
modalEditFormComponent := dev_mdsamplestationview.MDSampleStationForm(
|
||||
models.MDSampleStationForm{
|
||||
IDComponent: "formsamplestation",
|
||||
Link: "/dev/md/samplestation/edit",
|
||||
HxTarget: "#" + dialogEditBodyID,
|
||||
HxSwap: "outerHTML",
|
||||
HxInclude: "#tableID, #paginationID, #searchID, #dialogDeleteBodyID, #dialogEditBodyID, #dialogEditID, #" + searchID + ", #currpage" + paginationID,
|
||||
ModalID: dialogEditID,
|
||||
ModalTitle: "Edit - Sample Station",
|
||||
DialogBody: dialogEditFormComp,
|
||||
DialogAction: modalActionEditComp,
|
||||
ButtonClose: btnCloseModalEdit,
|
||||
},
|
||||
)
|
||||
|
||||
// modal delete form
|
||||
dialogDeleteBodyComp := dev_mdsamplestationview.BodyFormMDSampleStation(
|
||||
dialogDeleteBodyID,
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationid",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "hidden",
|
||||
ID: "samplestationinputid",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationcode",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Nama Sample Station",
|
||||
Name: "samplestationname",
|
||||
Placeholder: "Nama Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
},
|
||||
models.CustomDropdownv1Prm{
|
||||
Label: "Group",
|
||||
Name: "samplestationgroup",
|
||||
ID: "samplestationinputgroup",
|
||||
},
|
||||
dropdownGroupItem,
|
||||
dev_mdsamplestationview.JSHideModal(""),
|
||||
)
|
||||
|
||||
modalActionDeleteCmp := dev_mdsamplestationview.ActionFormMDSampleStationDelete(
|
||||
"/dev/md/samplestation/closedeleteform",
|
||||
"#"+dialogDeleteBodyID,
|
||||
"outerHTML",
|
||||
"#"+dialogDeleteID,
|
||||
)
|
||||
|
||||
btnCloseModalDelete := dev_mdsamplestationview.BtnCloseFormMDSampleStation(
|
||||
"/dev/md/samplestation/closedeleteform",
|
||||
"#"+dialogDeleteBodyID,
|
||||
"outerHTML",
|
||||
"#"+dialogDeleteID,
|
||||
)
|
||||
|
||||
modalDeleteFormComponent := dev_mdsamplestationview.MDSampleStationForm(
|
||||
models.MDSampleStationForm{
|
||||
IDComponent: "formsamplestation",
|
||||
Link: "/dev/md/samplestation/delete",
|
||||
HxTarget: "#" + dialogDeleteBodyID,
|
||||
HxSwap: "outerHTML",
|
||||
HxInclude: "#tableID, #paginationID, #searchID, #dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #" + searchID + ", #currpage" + paginationID,
|
||||
ModalID: dialogDeleteID,
|
||||
ModalTitle: "Delete - Sample Station",
|
||||
DialogBody: dialogDeleteBodyComp,
|
||||
DialogAction: modalActionDeleteCmp,
|
||||
ButtonClose: btnCloseModalDelete,
|
||||
},
|
||||
)
|
||||
|
||||
content := dev_mdsamplestationview.ContentMDSampleStation(
|
||||
tableID,
|
||||
paginationID,
|
||||
@@ -135,6 +337,9 @@ func (mdss *MDSampleStationHandler) HandleShowMDSampleStationScreen(c echo.Conte
|
||||
tableComponent,
|
||||
tableFilter,
|
||||
paginationTable,
|
||||
modalAddFormComponent,
|
||||
modalEditFormComponent,
|
||||
modalDeleteFormComponent,
|
||||
)
|
||||
css := dev_mdsamplestationview.CSSMDSampleStation()
|
||||
js := dev_mdsamplestationview.JSMDSampleStation()
|
||||
@@ -241,3 +446,479 @@ func (mdss *MDSampleStationHandler) HandleChangePageSampleStation(c echo.Context
|
||||
retval = append(retval, paginationComp)
|
||||
return utils.ViewMulti(c, retval)
|
||||
}
|
||||
|
||||
// Add Modal form
|
||||
func (mdss *MDSampleStationHandler) HandleCloseFormAdd(c echo.Context) error {
|
||||
logger, _ := zap.NewProduction()
|
||||
|
||||
dataGroupDropdown, err := mdss.MDSampleStationServices.GetListGroupSampleStation()
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERROR GET ITEM DROPDOWN", zap.Any("error", err))
|
||||
return err
|
||||
}
|
||||
itemGroupDropdown := dev_mdsamplestationview.ItemGroupDropdown(dataGroupDropdown, 0)
|
||||
|
||||
dialogAddBodyID := c.FormValue("dialogAddBodyID")
|
||||
newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
|
||||
dialogAddBodyID,
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationid",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "hidden",
|
||||
ID: "samplestationinputid",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationcode",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Nama Sample Station",
|
||||
Name: "samplestationname",
|
||||
Placeholder: "Nama Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
},
|
||||
models.CustomDropdownv1Prm{
|
||||
Label: "Group",
|
||||
Name: "samplestationgroup",
|
||||
ID: "samplestationinputgroup",
|
||||
},
|
||||
itemGroupDropdown,
|
||||
dev_mdsamplestationview.JSHideModal(""),
|
||||
)
|
||||
return utils.View(c, newForm)
|
||||
}
|
||||
|
||||
func (mdss *MDSampleStationHandler) HandleAddMDSampleStation(c echo.Context) error {
|
||||
logger, _ := zap.NewProduction()
|
||||
defer logger.Sync()
|
||||
|
||||
code := c.FormValue("samplestationcode")
|
||||
name := c.FormValue("samplestationname")
|
||||
group := c.FormValue("samplestationgroup")
|
||||
|
||||
tableID := c.FormValue("tableID")
|
||||
paginationID := c.FormValue("paginationID")
|
||||
searchID := c.FormValue("searchID")
|
||||
search := c.FormValue("search")
|
||||
currPagePrm := c.FormValue("currpage" + paginationID)
|
||||
dialogAddBodyID := c.FormValue("dialogAddBodyID")
|
||||
dialogAddID := c.FormValue("dialogAddID")
|
||||
dialogEditBodyID := c.FormValue("dialogEditBodyID")
|
||||
dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID")
|
||||
|
||||
currPage, err := strconv.Atoi(currPagePrm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Info("ADD SAMPLE STATION PARAM",
|
||||
zap.Any("code", code),
|
||||
zap.Any("nama", name),
|
||||
zap.Any("group", group),
|
||||
zap.Any("tableid", tableID),
|
||||
zap.Any("search", search),
|
||||
zap.Any("currpage", currPage),
|
||||
)
|
||||
|
||||
// dropdown item
|
||||
dataItemDropdown, err := mdss.MDSampleStationServices.GetListGroupSampleStation()
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("ERROR GET ITEM DROPDOWN", zap.Any("error", err))
|
||||
return err
|
||||
}
|
||||
itemGroupDropdown := dev_mdsamplestationview.ItemGroupDropdown(dataItemDropdown, 0)
|
||||
|
||||
// check item dropdown
|
||||
var idSelectedGroup int
|
||||
idSelectedGroup, err = strconv.Atoi(group)
|
||||
if err != nil {
|
||||
newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
|
||||
dialogAddBodyID,
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationid",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "hidden",
|
||||
ID: "samplestationinputid",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationcode",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Nama Sample Station",
|
||||
Name: "samplestationname",
|
||||
Placeholder: "Nama Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
},
|
||||
models.CustomDropdownv1Prm{
|
||||
Label: "Group",
|
||||
Name: "samplestationgroup",
|
||||
ID: "samplestationinputgroup",
|
||||
},
|
||||
itemGroupDropdown,
|
||||
dev_mdsamplestationview.JSHideModal(""),
|
||||
)
|
||||
return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", "error convert str to int", "warning"), newForm})
|
||||
}
|
||||
|
||||
for _, x := range dataItemDropdown {
|
||||
if x.ID == idSelectedGroup {
|
||||
group = x.Group
|
||||
}
|
||||
}
|
||||
|
||||
formValidation := ""
|
||||
codeValidation := ""
|
||||
nameValidation := ""
|
||||
groupValidation := ""
|
||||
|
||||
if strings.TrimSpace(code) == "" {
|
||||
formValidation = "Code sample station tidak boleh kosong"
|
||||
codeValidation = "Code sample station tidak boleh kosong"
|
||||
nameValidation = ""
|
||||
groupValidation = ""
|
||||
}
|
||||
if strings.TrimSpace(name) == "" {
|
||||
formValidation = "Nama sample station tidak boleh kosong"
|
||||
codeValidation = ""
|
||||
nameValidation = "Nama sample station tidak boleh kosong"
|
||||
groupValidation = ""
|
||||
}
|
||||
if strings.TrimSpace(group) == "" {
|
||||
formValidation = "Group sample station tidak boleh kosong"
|
||||
codeValidation = ""
|
||||
nameValidation = ""
|
||||
groupValidation = "Group sample station tidak boleh kosong"
|
||||
}
|
||||
if strings.TrimSpace(code) == "" && strings.TrimSpace(name) == "" && strings.TrimSpace(group) == "" {
|
||||
formValidation = "Code, Nama, dan Group tidak boleh kosong"
|
||||
codeValidation = "Code sample station tidak boleh kosong"
|
||||
nameValidation = "Nama sample station tidak boleh kosong"
|
||||
groupValidation = "Group sample station tidak boleh kosong"
|
||||
}
|
||||
|
||||
if formValidation != "" || codeValidation != "" || nameValidation != "" || groupValidation != "" {
|
||||
newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
|
||||
dialogAddBodyID,
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationid",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "hidden",
|
||||
ID: "samplestationinputid",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationcode",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
Value: code,
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Nama Sample Station",
|
||||
Name: "samplestationname",
|
||||
Placeholder: "Nama Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
Value: name,
|
||||
},
|
||||
models.CustomDropdownv1Prm{
|
||||
Label: "Group",
|
||||
Name: "samplestationgroup",
|
||||
ID: "samplestationinputgroup",
|
||||
},
|
||||
itemGroupDropdown,
|
||||
dev_mdsamplestationview.JSHideModal(""),
|
||||
)
|
||||
return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", formValidation, "warning"), newForm})
|
||||
}
|
||||
|
||||
// Add Data to DB
|
||||
dataResp, err := mdss.MDSampleStationServices.AddMDSampleStation(code, name, group)
|
||||
if err != nil {
|
||||
logger.Info("Error Add to DB",
|
||||
zap.Any("Error", err),
|
||||
zap.Any("code", code),
|
||||
zap.Any("name", name),
|
||||
zap.Any("group", group),
|
||||
)
|
||||
newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
|
||||
dialogAddBodyID,
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationid",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "hidden",
|
||||
ID: "samplestationinputid",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationcode",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
Value: code,
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Nama Sample Station",
|
||||
Name: "samplestationname",
|
||||
Placeholder: "Nama Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
Value: name,
|
||||
},
|
||||
models.CustomDropdownv1Prm{
|
||||
Label: "Group",
|
||||
Name: "samplestationgroup",
|
||||
ID: "samplestationinputgroup",
|
||||
},
|
||||
itemGroupDropdown,
|
||||
dev_mdsamplestationview.JSHideModal(""),
|
||||
)
|
||||
return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", formValidation, "warning"), newForm})
|
||||
}
|
||||
logger.Info("Add Sample Station",
|
||||
zap.Any("response", dataResp),
|
||||
zap.Any("code", code),
|
||||
zap.Any("name", name),
|
||||
zap.Any("group", group),
|
||||
)
|
||||
|
||||
// re-initial page
|
||||
dataTableSS, totalPage, err := mdss.MDSampleStationServices.GetListSampleStation(search, currPage, 5)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("error get table data",
|
||||
zap.Any("error", err),
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
tableComp := dev_mdsamplestationview.TableSampleStation(dataTableSS,
|
||||
tableID,
|
||||
"/dev/md/samplestation/openedit",
|
||||
"#"+dialogEditBodyID,
|
||||
"outerHTML",
|
||||
"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
|
||||
"/dev/md/samplestation/opendelete",
|
||||
"#"+dialogDeleteBodyID,
|
||||
"outerHTML",
|
||||
"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
|
||||
)
|
||||
|
||||
paginationComp := pagination.PaginationV3(
|
||||
totalPage,
|
||||
currPage,
|
||||
"/dev/md/samplestation/changepage",
|
||||
paginationID,
|
||||
"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
|
||||
"#"+paginationID,
|
||||
"outerHTML", "", "true",
|
||||
dev_mdsamplestationview.BeforeRequestContent(),
|
||||
dev_mdsamplestationview.AfterRequestContent(),
|
||||
)
|
||||
|
||||
newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
|
||||
dialogAddBodyID,
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationid",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "hidden",
|
||||
ID: "samplestationinputid",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Kode Sample Station",
|
||||
Name: "samplestationcode",
|
||||
Placeholder: "Kode Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
},
|
||||
models.CustomTextFieldv2Prm{
|
||||
Label: "Nama Sample Station",
|
||||
Name: "samplestationname",
|
||||
Placeholder: "Nama Sample Station",
|
||||
Type: "text",
|
||||
ID: "samplestationinputname",
|
||||
},
|
||||
models.CustomDropdownv1Prm{
|
||||
Label: "Group",
|
||||
Name: "samplestationgroup",
|
||||
ID: "samplestationinputgroup",
|
||||
},
|
||||
itemGroupDropdown,
|
||||
dev_mdsamplestationview.JSHideModal("#"+dialogAddID),
|
||||
)
|
||||
toastSucc := customtoastv2.CustomToastV2Show("Success", "Success add group result "+name, "success")
|
||||
|
||||
return utils.ViewMulti(c, []templ.Component{
|
||||
toastSucc,
|
||||
tableComp,
|
||||
paginationComp,
|
||||
newForm,
|
||||
})
|
||||
}
|
||||
|
||||
// Delete Modal form
|
||||
func (mdss *MDSampleStationHandler) HandleOpenDeleteForm(c echo.Context) error {
|
||||
id := c.QueryParam("id")
|
||||
dialogDeleteID := c.QueryParam("dialogDeleteID")
|
||||
dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID")
|
||||
|
||||
dataMDSS, err := mdss.MDSampleStationServices.GetMDSampleStationByID(id)
|
||||
if err != nil {
|
||||
newForm := dev_mdsamplestationview.DeleteConfirmationBody(
|
||||
models.CustomTextFieldv2Prm{
|
||||
Name: "samplestationid",
|
||||
Type: "hidden",
|
||||
Value: strconv.Itoa(dataMDSS.T_SampleStationID),
|
||||
},
|
||||
dialogDeleteBodyID,
|
||||
"Apakah anda yakin menghapus sample station berikut ?",
|
||||
[]string{"Kode", "Nama Sample Station", "Group"},
|
||||
[]string{"", "", ""},
|
||||
dev_mdsamplestationview.JSShowModal(""),
|
||||
)
|
||||
return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Error", "Get Sample Station Error", "danger"), newForm})
|
||||
}
|
||||
newForm := dev_mdsamplestationview.DeleteConfirmationBody(
|
||||
models.CustomTextFieldv2Prm{
|
||||
Name: "samplestationid",
|
||||
Type: "hidden",
|
||||
Value: strconv.Itoa(dataMDSS.T_SampleStationID),
|
||||
},
|
||||
dialogDeleteBodyID,
|
||||
"Apakah anda yakin menghapus sample station berikut ?",
|
||||
[]string{"Kode", "Nama Sample Station", "Group"},
|
||||
[]string{dataMDSS.T_SampleStationCode, dataMDSS.T_SampleStationName, dataMDSS.T_SampleStationIsNonLab},
|
||||
dev_mdsamplestationview.JSShowModal("#"+dialogDeleteID),
|
||||
)
|
||||
return utils.View(c, newForm)
|
||||
}
|
||||
|
||||
func (mdss *MDSampleStationHandler) HandleCloseFormDelete(c echo.Context) error {
|
||||
dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID")
|
||||
newForm := dev_mdsamplestationview.DeleteConfirmationBody(
|
||||
models.CustomTextFieldv2Prm{
|
||||
Name: "samplestationid",
|
||||
Type: "hidden",
|
||||
Value: "",
|
||||
},
|
||||
dialogDeleteBodyID,
|
||||
"Apakah anda yakin menghapus sample station berikut ?",
|
||||
[]string{"Kode", "Nama Sample Station", "Group"},
|
||||
[]string{"", "", ""},
|
||||
dev_mdsamplestationview.JSShowModal(""),
|
||||
)
|
||||
|
||||
return utils.View(c, newForm)
|
||||
}
|
||||
|
||||
func (mdss *MDSampleStationHandler) HandleDeleteMDSS(c echo.Context) error {
|
||||
logger, _ := zap.NewProduction()
|
||||
defer logger.Sync()
|
||||
|
||||
id := c.FormValue("samplestationid")
|
||||
tableID := c.FormValue("tableID")
|
||||
paginationID := c.FormValue("paginationID")
|
||||
searchID := c.FormValue("searchID")
|
||||
search := c.FormValue("search")
|
||||
currPagePrm := c.FormValue("currpage" + paginationID)
|
||||
dialogDeleteID := c.FormValue("dialogDeleteID")
|
||||
dialogEditBodyID := c.FormValue("dialogEditBodyID")
|
||||
dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID")
|
||||
|
||||
currPag, err := strconv.Atoi(currPagePrm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Info("ADD SAMPLE STATION PARAM",
|
||||
zap.Any("tableid", tableID),
|
||||
zap.Any("search", search),
|
||||
zap.Any("currpage", currPag),
|
||||
)
|
||||
|
||||
dataSS, err := mdss.MDSampleStationServices.DeleteMDSampleStation(id)
|
||||
if err != nil {
|
||||
logger.Info("Error", zap.Any("Error", err))
|
||||
|
||||
newForm := dev_mdsamplestationview.DeleteConfirmationBody(
|
||||
models.CustomTextFieldv2Prm{Name: "samplestationid", Type: "hidden", Value: ""},
|
||||
dialogDeleteBodyID,
|
||||
"Apakah anda yakin menghapus sample station berikut ?",
|
||||
[]string{"Kode", "Nama Sample Station", "Group"},
|
||||
[]string{"", "", ""},
|
||||
dev_mdsamplestationview.JSShowModal(""),
|
||||
)
|
||||
return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"), newForm})
|
||||
}
|
||||
|
||||
logger.Info("ADD SAMPLE STATION",
|
||||
zap.Any("return", dataSS),
|
||||
)
|
||||
|
||||
dataSSList, totalPage, err := mdss.MDSampleStationServices.GetListSampleStation(search, currPag, 5)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(dataSSList) == 0 && totalPage > 1 {
|
||||
currPag = currPag - 1
|
||||
dataSSList, _, err = mdss.MDSampleStationServices.GetListSampleStation(search, currPag, 5)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
tableComponent := dev_mdsamplestationview.TableSampleStation(dataSSList,
|
||||
tableID,
|
||||
"/dev/md/samplestation/openedit",
|
||||
"#"+dialogEditBodyID,
|
||||
"outerHTML",
|
||||
"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
|
||||
"/dev/md/samplestation/opendelete",
|
||||
"#"+dialogDeleteBodyID,
|
||||
"outerHTML",
|
||||
"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
|
||||
)
|
||||
|
||||
tablePagination := pagination.PaginationV3(
|
||||
totalPage,
|
||||
currPag,
|
||||
"/dev/md/samplestation/changepage",
|
||||
paginationID,
|
||||
"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
|
||||
"#"+paginationID,
|
||||
"outerHTML", "", "true",
|
||||
dev_mdsamplestationview.BeforeRequestContent(),
|
||||
dev_mdsamplestationview.AfterRequestContent(),
|
||||
)
|
||||
|
||||
var retVal []templ.Component
|
||||
newForm := dev_mdsamplestationview.DeleteConfirmationBody(
|
||||
models.CustomTextFieldv2Prm{Name: "samplestationid", Type: "hidden", Value: ""},
|
||||
dialogDeleteBodyID,
|
||||
"Apakah anda yakin menghapus sample station berikut ?",
|
||||
[]string{"Kode", "Nama Sample Station", "Group"},
|
||||
[]string{"", "", ""},
|
||||
dev_mdsamplestationview.JSHideModal("#"+dialogDeleteID),
|
||||
)
|
||||
toastSuccess := customtoastv2.CustomToastV2Show("Success", "Berhasil menghapus sample station", "success")
|
||||
retVal = append(retVal, toastSuccess)
|
||||
retVal = append(retVal, tableComponent)
|
||||
retVal = append(retVal, tablePagination)
|
||||
retVal = append(retVal, newForm)
|
||||
|
||||
return utils.ViewMulti(c, retVal)
|
||||
}
|
||||
|
||||
@@ -269,6 +269,12 @@ func SetupRoutesDev(app *echo.Echo, appStore db.AppStore) {
|
||||
dev.GET("/md/samplestation", devMDSampleStationHandlers.HandleShowMDSampleStationScreen)
|
||||
dev.GET("/md/samplestation/filter", devMDSampleStationHandlers.HandleFilterMDSS)
|
||||
dev.GET("/md/samplestation/changepage", devMDSampleStationHandlers.HandleChangePageSampleStation)
|
||||
dev.POST("/md/samplestation/add", devMDSampleStationHandlers.HandleAddMDSampleStation)
|
||||
dev.POST("/md/samplestation/closeaddform", devMDSampleStationHandlers.HandleCloseFormAdd)
|
||||
dev.GET("/md/samplestation/opendelete", devMDSampleStationHandlers.HandleOpenDeleteForm)
|
||||
dev.POST("/md/samplestation/closedeleteform", devMDSampleStationHandlers.HandleCloseFormDelete)
|
||||
dev.POST("/md/samplestation/delete", devMDSampleStationHandlers.HandleDeleteMDSS)
|
||||
|
||||
// masterdata nat unit
|
||||
devMdNatUnitServices := dev_services.NewMdNatUnitServices(appStore)
|
||||
devMdNatUnitHandlers := dev_handlers.NeWMdNatUnitHandler(devMdNatUnitServices)
|
||||
|
||||
Reference in New Issue
Block a user