diff --git a/handlers/dev/md.natunit.handlers.go b/handlers/dev/md.natunit.handlers.go new file mode 100644 index 0000000..4df537b --- /dev/null +++ b/handlers/dev/md.natunit.handlers.go @@ -0,0 +1,1036 @@ +package dev_handlers + +import ( + breadcrumadmin "cpone/component/breadcrumbadmin" + customtextfieldsearch "cpone/component/customtextfieldsearch" + navbarmenu "cpone/component/navbar" + "cpone/component/pagination" + sidebaruserprofile "cpone/component/sidebar_user_profile" + customtoastv2 "cpone/component/toastbootstrap" + "cpone/models" + "cpone/services" + "cpone/utils" + dev_mdnatunitview "cpone/views/dev/mdnatunit" + "fmt" + "strconv" + "strings" + + "github.com/a-h/templ" + "github.com/labstack/echo/v4" + "go.uber.org/zap" +) + +type MdNatUnitServices interface { + GetListMdNatUnit(search string, currentPage int, rowPerPage int) ([]models.NatUnit, int, error) + GetMdNatUnitBreadCrumb(title string) (models.BreadCrumbV1, error) + AddMdNatUnit(code string, name string) (models.NatUnit, error) + GetMdNatUnitByID(id string) (models.NatUnit, error) + EditMdNatUnit(id string, code string, name string) (models.NatUnit, error) + DeleteMdNatUnit(id string) (models.NatUnit, error) +} + +func NeWMdNatUnitHandler(nu MdNatUnitServices) *MdNatUnitHandler { + return &MdNatUnitHandler{ + MdNatUnitServices: nu, + } +} + +type MdNatUnitHandler struct { + MdNatUnitServices MdNatUnitServices +} + +func (nh *MdNatUnitHandler) HandleShowMdNatUnitScreen(c echo.Context) error { + logger, _ := zap.NewProduction() + + tableID := utils.GenerateRandomID("tablebody") + paginationID := utils.GenerateRandomID("paginationid") + searchID := utils.GenerateRandomID("searchid") + dialogAddID := utils.GenerateRandomID("dialogaddID") + dialogAddBodyID := utils.GenerateRandomID("dialogaddbodyID") + dialogEditID := utils.GenerateRandomID("dialogEditID") + dialogEditBodyID := utils.GenerateRandomID("dialogEditbodyID") + dialogDeleteID := utils.GenerateRandomID("dialogDeleteID") + dialogDeleteBodyID := utils.GenerateRandomID("dialogDeletebodyID") + dataMenu, err := services.GetMenu() + fmt.Println(dataMenu) + fmt.Println(err) + if err != nil { + fmt.Println(dataMenu) + return err + } + + //get user login + dataUser, err := services.GetUserLogin() + fmt.Println(dataUser) + fmt.Println(err) + if err != nil { + fmt.Println(dataUser) + return err + } + defer logger.Sync() + logger.Info("LOAD USER DEV", + zap.Any("data", dataUser), + ) + + title := "Master Unit" + + dataBreadCrumb, err := nh.MdNatUnitServices.GetMdNatUnitBreadCrumb(title) + fmt.Println(dataBreadCrumb) + fmt.Println(err) + if err != nil { + defer logger.Sync() + logger.Info("ERROR BREADCRUMB DEV", + zap.Any("error", err), + ) + fmt.Println(dataBreadCrumb) + return err + } + + defer logger.Sync() + logger.Info("LOAD BREADCRUMB DEV", + zap.Any("data", dataBreadCrumb), + ) + //Breadcrumb component + breadcrumbComponent := breadcrumadmin.MainBreadcrumbAdminV1(dataBreadCrumb) + // navbar menu + navbarmenuComponent := navbarmenu.NavbarMenu(dataMenu) + + // navbar user + navbaruserComponent := navbarmenu.Navbar(dataUser) + + // sidebar + sidebaruserprofileComponent := sidebaruserprofile.Navbaruserprofile(dataUser) + + //Table component + dataNatUnit, totalPage, err := nh.MdNatUnitServices.GetListMdNatUnit("", 1, 5) + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET NAT UNTI", + zap.Any("error", err), + ) + fmt.Println(dataNatUnit) + return err + } + + tableComponent := dev_mdnatunitview.TableNatUnit(dataNatUnit, + tableID, + "/dev/md/natunit/openedit", + "#"+dialogEditBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "/dev/md/natunit/opendelete", + "#"+dialogDeleteBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + ) + + //filter nat unit component + natUnitFilterComponent := customtextfieldsearch.MainCustomTextFieldSearchV3(searchID, + "search", + "Cari Kode/Nama", + "text", + "/dev/md/natunit/filter", + "input changed delay:500ms, search", + "#"+paginationID, "#loadingcontent", "", "outerHTML", "#tableID, #paginationID, #searchID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + dev_mdnatunitview.BeforeRequestContent(), + dev_mdnatunitview.AfterRequestContent()) + + //Pagination + natUnitPaginationComponent := pagination.PaginationV3( + totalPage, + 1, + "/dev/md/natunit/changepage", + paginationID, + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "#"+paginationID, + "outerHTML", "", "", + dev_mdnatunitview.BeforeRequestContent(), + dev_mdnatunitview.AfterRequestContent(), + ) + + // modal add form + dialogAddBodyCmp := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogAddBodyID, dev_mdnatunitview.JsHideModal(""), + ) + + modalActionAddCmp := dev_mdnatunitview.ActionFormNatUnit( + "/dev/md/natunit/closeaddform", + "#"+dialogAddBodyID, + "outerHTML", + "#"+dialogAddID, + ) + + btnCloseModalAdd := dev_mdnatunitview.BtnCloseFormNatUnit( + "/dev/md/natunit/closeaddform", + "#"+dialogAddBodyID, + "outerHTML", + "#"+dialogAddID, + ) + + modalAddFormComponent := dev_mdnatunitview.NatUnitForm( + models.NatUnitFormComponent{ + IDComponent: "formnatunit", + Link: "/dev/md/natunit/add", + HxTarget: "#" + dialogAddBodyID, + HxSwap: "outerHTML", + HxInclude: "#tableID, #paginationID, #searchID, #dialogAddBodyID, #dialogAddID, #dialogDeleteBodyID, #dialogEditBodyID, #" + searchID + ", #currpage" + paginationID, + ModalID: dialogAddID, + ModalTitle: "New - Unit", + DialogBody: dialogAddBodyCmp, + DialogAction: modalActionAddCmp, + ButtonCLose: btnCloseModalAdd, + }, + ) + + // modal edit form + dialogEditBodyCmp := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogEditBodyID, dev_mdnatunitview.JsHideModal(""), + ) + + modalActionEditCmp := dev_mdnatunitview.ActionFormNatUnit( + "/dev/md/natunit/closeeditform", + "#"+dialogEditBodyID, + "outerHTML", + "#"+dialogEditID, + ) + + btnCloseModalEdit := dev_mdnatunitview.BtnCloseFormNatUnit( + "/dev/md/natunit/closeeditform", + "#"+dialogEditBodyID, + "outerHTML", + "#"+dialogEditID, + ) + + modalEditFormComponent := dev_mdnatunitview.NatUnitForm( + models.NatUnitFormComponent{ + IDComponent: "formnatunit", + Link: "dev/md/natunit/edit", + HxTarget: "#" + dialogEditBodyID, + HxSwap: "outerHTML", + HxInclude: "#tableID, #paginationID, #searchID, #dialogDeleteBodyID, #dialogEditBodyID, #dialogEditID, #" + searchID + ", #currpage" + paginationID, + ModalID: dialogEditID, + ModalTitle: "New - Unit", + DialogBody: dialogEditBodyCmp, + DialogAction: modalActionEditCmp, + ButtonCLose: btnCloseModalEdit, + }, + ) + + // modal delete form + dialogDeleteBodyCmp := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogDeleteBodyID, dev_mdnatunitview.JsHideModal("")) + modalActionDeleteCmp := dev_mdnatunitview.ActionFormNatUnit( + "/dev/md/natunit/closedeleteform", + "#"+dialogDeleteBodyID, + "outerHTML", + "#"+dialogDeleteID) + btnCloaseModalDelete := dev_mdnatunitview.BtnCloseFormNatUnit( + "/dev/md/natunit/closedeleteform", + "#"+dialogDeleteBodyID, + "outerHTML", + "#"+dialogDeleteID) + modalDeleteFormComponent := dev_mdnatunitview.NatUnitForm( + models.NatUnitFormComponent{ + IDComponent: "formnatunit", + Link: "/dev/md/natunit/delete", + HxTarget: "#" + dialogDeleteBodyID, + HxSwap: "outerHTML", + HxInclude: "#tableID, #paginationID, #searchID, #dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #" + searchID + ", #currpage" + paginationID, + ModalID: dialogDeleteID, + ModalTitle: "New - Unit", + DialogBody: dialogDeleteBodyCmp, + DialogAction: modalActionDeleteCmp, + ButtonCLose: btnCloaseModalDelete, + }, + ) + + // content, css, js + content := dev_mdnatunitview.MdNatUnitScreen( + tableID, + paginationID, + searchID, + dialogAddID, + dialogAddBodyID, + dialogEditID, + dialogEditBodyID, + dialogDeleteID, + dialogDeleteBodyID, + breadcrumbComponent, + tableComponent, + natUnitFilterComponent, + natUnitPaginationComponent, + modalAddFormComponent, + modalEditFormComponent, + modalDeleteFormComponent, + ) + css := dev_mdnatunitview.CssMdNatUnit() + js := dev_mdnatunitview.JsMdNatUnit() + + view := dev_mdnatunitview.ShowMdNatUnitScreen( + title, + content, + css, + js, + navbarmenuComponent, + navbaruserComponent, + sidebaruserprofileComponent, + ) + + return utils.View(c, view) +} + +func (nh *MdNatUnitHandler) HandleFilterMdNatUnit(c echo.Context) error { + search := c.QueryParam("search") + searchID := c.QueryParam("searchID") + tableID := c.QueryParam("tableID") + paginationID := c.QueryParam("paginationID") + dialogEditBodyID := c.QueryParam("dialogEditBodyID") + dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID") + var retval []templ.Component + logger, _ := zap.NewProduction() + + dataNatUnit, totalpage, err := nh.MdNatUnitServices.GetListMdNatUnit(search, 1, 5) + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET NAT UNTI", + zap.Any("error", err), + ) + fmt.Println(dataNatUnit) + return err + } + tableComponent := dev_mdnatunitview.TableNatUnit(dataNatUnit, + tableID, + "/dev/md/natunit/openedit", + "#"+dialogEditBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "/dev/md/natunit/opendelete", + "#"+dialogDeleteBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID") + natUnitPaginationComponent := pagination.PaginationV3( + totalpage, + 1, + "/dev/md/natunit/changepage", + paginationID, + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "#"+paginationID, + "outerHTML", "", "", + dev_mdnatunitview.BeforeRequestContent(), + dev_mdnatunitview.AfterRequestContent(), + ) + retval = append(retval, tableComponent) + retval = append(retval, natUnitPaginationComponent) + return utils.ViewMulti(c, retval) +} + +func (nh *MdNatUnitHandler) HandlerChangePageMdNatUnit(c echo.Context) error { + search := c.QueryParam("search") + pageparam := c.QueryParam("page") + tableID := c.QueryParam("tableID") + searchID := c.QueryParam("searchID") + paginationID := c.QueryParam("paginationID") + dialogEditBodyID := c.QueryParam("dialogEditBodyID") + dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID") + + var retval []templ.Component + logger, _ := zap.NewProduction() + page, err := strconv.Atoi(pageparam) + if err != nil { + defer logger.Sync() + logger.Info("ERROR CONVERT PAGE PARAM", + zap.Any("page", page), + zap.Any("error ", err), + ) + return err + } + + dataNatUnit, totalpage, err := nh.MdNatUnitServices.GetListMdNatUnit(search, page, 5) + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET NAT UNIT", + zap.Any("error", err), + ) + fmt.Println(dataNatUnit) + return err + } + tableComponent := dev_mdnatunitview.TableNatUnit(dataNatUnit, + tableID, + "/dev/md/natunit/openedit", + "#"+dialogEditBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "/dev/md/natunit/opendelete", + "#"+dialogDeleteBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + ) + natUnitPaginationComponent := pagination.PaginationV3( + totalpage, + page, + "/dev/md/natunit/changepage", + paginationID, + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "#"+paginationID, + "outerHTML", "", "", + dev_mdnatunitview.BeforeRequestContent(), + dev_mdnatunitview.AfterRequestContent(), + ) + retval = append(retval, tableComponent) + retval = append(retval, natUnitPaginationComponent) + return utils.ViewMulti(c, retval) +} + +func (nh *MdNatUnitHandler) HandlerCloseFormAdd(c echo.Context) error { + dialogAddBodyID := c.FormValue("dialogAddBodyID") + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogAddBodyID, dev_mdnatunitview.JsHideModal("")) + return utils.View(c, newForm) +} + +func (nh *MdNatUnitHandler) HandlerAddNatUnit(c echo.Context) error { + logger, _ := zap.NewProduction() + defer logger.Sync() + + // prm form addnatunit + code := c.FormValue("natunitcode") + name := c.FormValue("natunitname") + 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 UNIT PARAM", + zap.Any("code", code), + zap.Any("nama", name), + zap.Any("tableid", tableID), + zap.Any("search", search), + zap.Any("currpage", currPage), + ) + + formValidation := "" + codeValidation := "" + nameValidation := "" + if strings.TrimSpace(code) == "" { + formValidation = "Code unit tidak boleh kosong" + codeValidation = "Code unit tidak boleh kosong" + nameValidation = "" + } + if strings.TrimSpace(name) == "" { + formValidation = "Nama unit tidak boleh kosong" + codeValidation = "" + nameValidation = "Nama unit tidak boleh kosong" + } + if strings.TrimSpace(code) == "" && strings.TrimSpace(name) == "" { + formValidation = "Code dan nama unit tidak boleh kosong" + codeValidation = "Code unit tidak boleh kosong" + nameValidation = "Nama unit tidak boleh kosong" + + } + + if formValidation != "" || codeValidation != "" || nameValidation != "" { + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + ErrorMsg: codeValidation, + Value: code, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + ErrorMsg: nameValidation, + Value: name, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogAddBodyID, dev_mdnatunitview.JsHideModal("")) + return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", formValidation, "warning"), newForm}) + } + + // add nat unit service + dataNatUnit, err := nh.MdNatUnitServices.AddMdNatUnit(code, name) + if err != nil { + logger.Info("Error", + zap.Any("Error", err), + zap.Any("code", code), + zap.Any("name", name), + ) + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + ErrorMsg: codeValidation, + Value: code, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + ErrorMsg: nameValidation, + Value: name, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogAddBodyID, dev_mdnatunitview.JsHideModal("")) + return utils.ViewMulti(c, []templ.Component{ + customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"), + newForm}) + } + logger.Info("ADD UNIT", + zap.Any("return", dataNatUnit), + zap.Any("code", code), + zap.Any("name", name), + ) + + // get list nat unit for table + dataNatUnitList, totalPage, err := nh.MdNatUnitServices.GetListMdNatUnit(search, currPage, 5) + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET UNIT", + zap.Any("error", err), + ) + fmt.Println(dataNatUnit) + return err + } + + // table component + tableComponent := dev_mdnatunitview.TableNatUnit( + dataNatUnitList, + tableID, + "/dev/md/natunit/openedit", + "#"+dialogEditBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "/dev/md/natunit/opendelete", + "#"+dialogDeleteBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + ) + + // pagination component + natUnitPaginationComponent := pagination.PaginationV3( + totalPage, + currPage, + "/dev/md/natunit/changepage", + paginationID, + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "#"+paginationID, + "outerHTML", "", "true", + dev_mdnatunitview.BeforeRequestContent(), + dev_mdnatunitview.AfterRequestContent(), + ) + + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + ErrorMsg: codeValidation, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + ErrorMsg: nameValidation, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogAddBodyID, dev_mdnatunitview.JsHideModal("#"+dialogAddID)) + toastSuccess := customtoastv2.CustomToastV2Show("Success", "Berhasil insert unit "+name, "success") + + return utils.ViewMulti(c, []templ.Component{ + toastSuccess, + tableComponent, + natUnitPaginationComponent, + newForm, + }) +} + +func (nh *MdNatUnitHandler) HandlerOpenEditForm(c echo.Context) error { + id := c.QueryParam("id") + dialogEditID := c.QueryParam("dialogEditID") + dialogEditBodyID := c.QueryParam("dialogEditBodyID") + + dataNatUnit, err := nh.MdNatUnitServices.GetMdNatUnitByID(id) + if err != nil { + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogEditBodyID, dev_mdnatunitview.JsHideModal("")) + return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Error", "Get unit error", "danger"), newForm}) + } + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + Value: dataNatUnit.Nat_UnitCode, + Type: "text", + ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitname", + Placeholder: "Kode Unit", + Value: dataNatUnit.Nat_UnitName, + Type: "text", + ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Value: strconv.Itoa(dataNatUnit.Nat_UnitID), + Type: "hidden", + ID: "natunitinputid"}, + + dialogEditBodyID, dev_mdnatunitview.JsShowModal("#"+dialogEditID)) + + return utils.View(c, newForm) +} + +func (nh *MdNatUnitHandler) HandlerCloseFormEdit(c echo.Context) error { + dialogEditBodyID := c.FormValue("dialogEditBodyID") + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + Type: "text", ID: "natunitinputname"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogEditBodyID, dev_mdnatunitview.JsHideModal("")) + return utils.View(c, newForm) +} + +func (nh *MdNatUnitHandler) HandlerEditNatUnit(c echo.Context) error { + logger, _ := zap.NewProduction() + defer logger.Sync() + + // prm form addnatunit + code := c.FormValue("natunitcode") + name := c.FormValue("natunitname") + id := c.FormValue("natunitid") + 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") + dialogEditID := c.FormValue("dialogEditID") + dialogEditBodyID := c.FormValue("dialogEditBodyID") + dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID") + + currPage, err := strconv.Atoi(currPagePrm) + if err != nil { + return err + } + logger.Info("ADD NAT UNIT PARAM", + zap.Any("code", code), + zap.Any("nama", name), + zap.Any("tableid", tableID), + zap.Any("search", search), + zap.Any("currpage", currPage), + ) + + formValidation := "" + codeValidation := "" + nameValidation := "" + if strings.TrimSpace(code) == "" { + formValidation = "Code unit tidak boleh kosong" + codeValidation = "Code unit tidak boleh kosong" + nameValidation = "" + } + if strings.TrimSpace(name) == "" { + formValidation = "Nama unit tidak boleh kosong" + codeValidation = "" + nameValidation = "Nama unit tidak boleh kosong" + } + if strings.TrimSpace(code) == "" && strings.TrimSpace(name) == "" { + formValidation = "Code dan nama unit tidak boleh kosong" + codeValidation = "Code unit tidak boleh kosong" + nameValidation = "Nama unit tidak boleh kosong" + + } + + if formValidation != "" || codeValidation != "" || nameValidation != "" { + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + ErrorMsg: codeValidation, + Value: code, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + ErrorMsg: nameValidation, + Value: name, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogEditBodyID, dev_mdnatunitview.JsHideModal("")) + return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", formValidation, "warning"), newForm}) + } + + // edit nat unit service + dataNatUnit, err := nh.MdNatUnitServices.EditMdNatUnit(id, code, name) + if err != nil { + logger.Info("Error", + zap.Any("Error", err), + zap.Any("code", code), + zap.Any("name", name), + ) + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + ErrorMsg: codeValidation, + Value: code, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + ErrorMsg: nameValidation, + Value: name, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogEditBodyID, dev_mdnatunitview.JsHideModal("")) + return utils.ViewMulti(c, []templ.Component{ + customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"), newForm}) + } + + logger.Info("ADD NAT UNIT", + zap.Any("return", dataNatUnit), + zap.Any("code", code), + zap.Any("name", name), + ) + + // get list nat unit for table + dataNatUnitList, totalPage, err := nh.MdNatUnitServices.GetListMdNatUnit(search, currPage, 5) + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET NAT UNIT", + zap.Any("error", err), + ) + fmt.Println(dataNatUnit) + return err + } + + // table component + tableComponent := dev_mdnatunitview.TableNatUnit( + dataNatUnitList, + tableID, + "/dev/md/natunit/openedit", + "#"+dialogEditBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "/dev/md/natunit/opendelete", + "#"+dialogDeleteBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + ) + + // pagination component + natUnitPaginationComponent := pagination.PaginationV3( + totalPage, + currPage, + "/dev/md/natunit/changepage", + paginationID, + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "#"+paginationID, + "outerHTML", "", "true", + dev_mdnatunitview.BeforeRequestContent(), + dev_mdnatunitview.AfterRequestContent(), + ) + + var retVal []templ.Component + newForm := dev_mdnatunitview.BodyFormNatUnit( + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitcode", + Placeholder: "Kode Unit", + ErrorMsg: codeValidation, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Nama Unit", + Name: "natunitname", + Placeholder: "Nama Unit", + ErrorMsg: nameValidation, + Type: "text"}, + models.CustomTextFieldv2Prm{ + Label: "Kode Unit", + Name: "natunitid", + Placeholder: "Kode Unit", + Type: "hidden", ID: "natunitinputid"}, + dialogEditBodyID, dev_mdnatunitview.JsHideModal("#"+dialogEditID)) + toastSuccess := customtoastv2.CustomToastV2Show("Success", "Berhasil edit Unit "+name, "success") + retVal = append(retVal, toastSuccess) + retVal = append(retVal, tableComponent) + retVal = append(retVal, natUnitPaginationComponent) + retVal = append(retVal, newForm) + return utils.ViewMulti(c, retVal) +} + +func (nh *MdNatUnitHandler) HandlerOpenDeleteForm(c echo.Context) error { + id := c.QueryParam("id") + dialogDeleteID := c.QueryParam("dialogDeleteID") + dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID") + + dataNatUnit, err := nh.MdNatUnitServices.GetMdNatUnitByID(id) + if err != nil { + newForm := dev_mdnatunitview.DeleteConfirmationBody( + models.CustomTextFieldv2Prm{Name: "natunitid", Type: "hidden", Value: strconv.Itoa(dataNatUnit.Nat_UnitID)}, + dialogDeleteBodyID, + "Apakah anda yakin menghapus unit berikut ?", + []string{"Kode", "Unit"}, + []string{"", ""}, + dev_mdnatunitview.JsShowModal("")) + return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Error", "Get unit error", "danger"), newForm}) + } + newForm := dev_mdnatunitview.DeleteConfirmationBody( + models.CustomTextFieldv2Prm{Name: "natunitid", Type: "hidden", Value: strconv.Itoa(dataNatUnit.Nat_UnitID)}, + dialogDeleteBodyID, + "Apakah anda yakin menghapus unit berikut ?", + []string{"Kode", "Unit"}, + []string{dataNatUnit.Nat_UnitCode, dataNatUnit.Nat_UnitName}, + dev_mdnatunitview.JsShowModal("#"+dialogDeleteID)) + return utils.View(c, newForm) +} + +func (nh *MdNatUnitHandler) HandlerCloseFormDelete(c echo.Context) error { + dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID") + newForm := dev_mdnatunitview.DeleteConfirmationBody( + models.CustomTextFieldv2Prm{Name: "natunitid", Type: "hidden", Value: ""}, + dialogDeleteBodyID, + "Apakah anda yakin menghapus unit berikut ?", + []string{"Kode", "Unit"}, + []string{"", ""}, + dev_mdnatunitview.JsShowModal("")) + return utils.View(c, newForm) +} + +func (nh *MdNatUnitHandler) HandlerDeleteNatUnit(c echo.Context) error { + logger, _ := zap.NewProduction() + defer logger.Sync() + + // prm form addnatunit + id := c.FormValue("natunitid") + 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") + dialogDeleteID := c.FormValue("dialogDeleteID") + dialogEditBodyID := c.FormValue("dialogEditBodyID") + dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID") + + currPage, err := strconv.Atoi(currPagePrm) + if err != nil { + return err + } + logger.Info("ADD NAT UNIT PARAM", + + zap.Any("tableid", tableID), + zap.Any("search", search), + zap.Any("currpage", currPage), + ) + + // edit nat unit service + dataNatUnit, err := nh.MdNatUnitServices.DeleteMdNatUnit(id) + if err != nil { + logger.Info("Error", + zap.Any("Error", err), + ) + newForm := dev_mdnatunitview.DeleteConfirmationBody( + models.CustomTextFieldv2Prm{Name: "natunitid", Type: "hidden", Value: ""}, + dialogDeleteBodyID, + "Apakah anda yakin menghapus unit berikut ?", + []string{"Kode", "Unit"}, + []string{"", ""}, + dev_mdnatunitview.JsShowModal("")) + return utils.ViewMulti(c, []templ.Component{ + customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"), + newForm}) + } + logger.Info("ADD Unit", + zap.Any("return", dataNatUnit), + ) + + // get list nat unit fo table + dataNatUnitList, totalPage, err := nh.MdNatUnitServices.GetListMdNatUnit(search, currPage, 5) + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET Unit", + zap.Any("error", err), + ) + fmt.Println(dataNatUnit) + return err + } + if len(dataNatUnitList) == 0 && totalPage > 1 { + currPage = currPage - 1 + dataNatUnitList, _, err = nh.MdNatUnitServices.GetListMdNatUnit(search, currPage, 5) + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET UNIT", + zap.Any("error", err), + ) + return err + } + } + + // table component + tableComponent := dev_mdnatunitview.TableNatUnit( + dataNatUnitList, + tableID, + "/dev/md/natunit/openedit", + "#"+dialogEditBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "/dev/md/natunit/opendelete", + "#"+dialogDeleteBodyID, + "outerHTML", + "#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + ) + + // pagination component + natUnitPaginationComponent := pagination.PaginationV3( + totalPage, + currPage, + "/dev/md/natunit/changepage", + paginationID, + "#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID", + "#"+paginationID, + "outerHTML", "", "true", + dev_mdnatunitview.BeforeRequestContent(), + dev_mdnatunitview.AfterRequestContent(), + ) + + var retVal []templ.Component + newForm := dev_mdnatunitview.DeleteConfirmationBody( + models.CustomTextFieldv2Prm{Name: "natunitid", Type: "hidden", Value: ""}, + dialogDeleteBodyID, + "Apakah anda yakin menghapus unit berikut ?", + []string{"Kode", "Unit"}, + []string{"", ""}, + dev_mdnatunitview.JsHideModal("#"+dialogDeleteID)) + toastSuccess := customtoastv2.CustomToastV2Show("Success", "Berhasil delete Unit ", "success") + retVal = append(retVal, toastSuccess) + retVal = append(retVal, tableComponent) + retVal = append(retVal, natUnitPaginationComponent) + retVal = append(retVal, newForm) + return utils.ViewMulti(c, retVal) +} diff --git a/handlers/routes.go b/handlers/routes.go index 8989bd5..0d83ec4 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -262,4 +262,18 @@ func SetupRoutesDev(app *echo.Echo, appStore db.AppStore) { dev.POST("/groupresult/add", devGRhandlers.AddGroupResult) dev.POST("/groupresult/edit", devGRhandlers.EditGroupResult) dev.POST("/groupresult/delete", devGRhandlers.DeleteGroupResult) + // masterdata nat unit + devMdNatUnitServices := dev_services.NewMdNatUnitServices(appStore) + devMdNatUnitHandlers := dev_handlers.NeWMdNatUnitHandler(devMdNatUnitServices) + dev.GET("/md/natunit", devMdNatUnitHandlers.HandleShowMdNatUnitScreen) + dev.GET("/md/natunit/filter", devMdNatUnitHandlers.HandleFilterMdNatUnit) + dev.GET("/md/natunit/changepage", devMdNatUnitHandlers.HandlerChangePageMdNatUnit) + dev.POST("/md/natunit/closeaddform", devMdNatUnitHandlers.HandlerCloseFormAdd) + dev.POST("/md/natunit/add", devMdNatUnitHandlers.HandlerAddNatUnit) + dev.GET("/md/natunit/openedit", devMdNatUnitHandlers.HandlerOpenEditForm) + dev.POST("/md/natunit/closeeditform", devMdNatUnitHandlers.HandlerCloseFormEdit) + dev.POST("/md/natunit/edit", devMdNatUnitHandlers.HandlerEditNatUnit) + dev.GET("/md/natunit/opendelete", devMdNatUnitHandlers.HandlerOpenDeleteForm) + dev.POST("/md/natunit/closedeleteform", devMdNatUnitHandlers.HandlerCloseFormDelete) + dev.POST("/md/natunit/delete", devMdNatUnitHandlers.HandlerDeleteNatUnit) } diff --git a/models/natunit.models.go b/models/natunit.models.go new file mode 100644 index 0000000..2f5301f --- /dev/null +++ b/models/natunit.models.go @@ -0,0 +1,29 @@ +package models + +import "github.com/a-h/templ" + +type NatUnit struct { + Nomor string `db:"nomor"` + Nat_UnitID int `db:"Nat_UnitID"` + Nat_UnitCode string `db:"Nat_UnitCode"` + Nat_UnitName string `db:"Nat_UnitName"` + Nat_UnitCreated string `db:"Nat_UnitCreated"` + Nat_UnitLastUpdated string `db:"Nat_UnitLastUpdated"` + Nat_UnitIsActive string `db:"Nat_UnitIsActive"` +} + +type NatUnitFormComponent struct { + IDComponent string + Link string + HxTarget string + HxSwap string + HxInclude string + ModalID string + ModalTitle string + InputName CustomTextFieldv2Prm + InputCode CustomTextFieldv2Prm + InputID CustomTextFieldv2Prm + DialogBody templ.Component + DialogAction templ.Component + ButtonCLose templ.Component +} diff --git a/services/dev/md.natunit.services.go b/services/dev/md.natunit.services.go new file mode 100644 index 0000000..94fc76d --- /dev/null +++ b/services/dev/md.natunit.services.go @@ -0,0 +1,262 @@ +package dev_services + +import ( + "cpone/db" + "cpone/models" + dbx "cpone/package/database" + "fmt" + "math" + "strconv" + "strings" + + "go.uber.org/zap" +) + +func NewMdNatUnitServices(uStore db.AppStore) *MdNatUnitServices { + return &MdNatUnitServices{ + MdNatUnitStore: uStore, + } +} + +type MdNatUnitServices struct { + MdNatUnitStore db.AppStore +} + +func (nu *MdNatUnitServices) GetListMdNatUnit(search string, currentPage int, rowPerPage int) ([]models.NatUnit, int, error) { + var natUnitList []models.NatUnit + var totalData int + offset := (currentPage - 1) * rowPerPage + prm := "%" + strings.TrimSpace(search) + "%" + querytotal := `SELECT COUNT(*) + FROM nat_unit + WHERE Nat_UnitIsActive = 'Y' + AND (Nat_UnitCode LIKE ? OR Nat_UnitName LIKE ?)` + + if err := dbx.Handlex.Get(&totalData, querytotal, prm, prm); err != nil { + return nil, 0, fmt.Errorf("error querying database: %v", err) + } + + query := `SELECT ROW_NUMBER() OVER (ORDER BY Nat_UnitID DESC) AS nomor, + Nat_UnitID, + Nat_UnitCode, + Nat_UnitName, + Nat_UnitCreated, + Nat_UnitLastUpdated, + Nat_UnitIsActive + FROM nat_unit + WHERE Nat_UnitIsActive = 'Y' + AND (Nat_UnitCode LIKE ? OR Nat_UnitName LIKE ?) + ORDER BY Nat_UnitID DESC + LIMIT ? OFFSET ?` + + if err := dbx.Handlex.Select(&natUnitList, query, prm, prm, rowPerPage, offset); err != nil { + return nil, 0, fmt.Errorf("error querying database: %v", err) + } + totalPage := int(math.Ceil(float64(totalData) / float64(rowPerPage))) + + return natUnitList, totalPage, nil +} + +func (nu *MdNatUnitServices) GetMdNatUnitBreadCrumb(title string) (models.BreadCrumbV1, error) { + var ret models.BreadCrumbV1 + + dummyBreadcrumb := []models.BreadCrumbV1{ + { + Title: "Master Unit", + Item: []models.ItemBreadCrumbV1{ + { + Item: "Dashboard", + Url: "/dev/dashboard", + }, + { + Item: "Master", + Url: "/dev/master", + }, + { + Item: "Unit", + Url: "", + }, + }, + }, + + { + Title: "Master User", + Item: []models.ItemBreadCrumbV1{ + { + Item: "Dashboard", + Url: "/dev/dashboard", + }, + { + Item: "Master", + Url: "/dev/master", + }, + { + Item: "User", + Url: "", + }, + }, + }, + } + + for _, breadcrumb := range dummyBreadcrumb { + if breadcrumb.Title == title { + ret = breadcrumb + return ret, nil + } + } + + return ret, nil +} + +func (nu *MdNatUnitServices) GetMdNatUnitByID(id string) (models.NatUnit, error) { + logger, _ := zap.NewProduction() + + var data models.NatUnit + err := dbx.Handlex.Get(&data, `SELECT * FROM nat_unit + WHERE Nat_UnitID = ?`, id) + + if err != nil { + defer logger.Sync() + logger.Error("Error get data unit by id", + zap.String("ID", id), + zap.Error(err), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + return data, nil +} + +func (nu *MdNatUnitServices) AddMdNatUnit(code string, name string) (models.NatUnit, error) { + logger, _ := zap.NewProduction() + var data models.NatUnit + var datacek []models.NatUnit + + qryCek := `SELECT Nat_UnitCode FROM nat_unit + WHERE Nat_UnitCode = ? AND Nat_UnitIsActive = 'Y'` + err := dbx.Handlex.Select(&datacek, qryCek, code) + + if err != nil { + defer logger.Sync() + logger.Error("Error cek data by code", + zap.String("code", code), + zap.Any("datacek", datacek), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + + if len(datacek) > 0 { + defer logger.Sync() + logger.Error("Code already taken by another data", + zap.String("code", code), + ) + return data, fmt.Errorf("code sudah dipakai") + } + + qry := `INSERT INTO nat_unit + (Nat_UnitCode, + Nat_UnitName) VALUES(?,?)` + rst := dbx.Handlex.MustExec(qry, code, name) + insertedID, err := rst.LastInsertId() + if err != nil { + defer logger.Sync() + logger.Error("Error Insert natunit", + zap.String("code", code), + zap.String("name", name), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + + s := strconv.Itoa(int(insertedID)) + data, err = nu.GetMdNatUnitByID(s) + if err != nil { + defer logger.Sync() + logger.Error("Error get natunit by id", + zap.String("code", code), + zap.String("name", name), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + return data, nil +} + +func (nu *MdNatUnitServices) EditMdNatUnit(id string, code string, name string) (models.NatUnit, error) { + logger, _ := zap.NewProduction() + var data models.NatUnit + var datacek []models.NatUnit + + qryCek := `SELECT Nat_UnitCode FROM nat_unit + WHERE Nat_UnitCode = ? AND Nat_UnitIsActive = 'Y' AND Nat_UnitID <> ?` + err := dbx.Handlex.Select(&datacek, qryCek, code, id) + + if err != nil { + defer logger.Sync() + logger.Error("Error cek data by code", + zap.String("code", code), + zap.Any("datacek", datacek), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + + if len(datacek) > 0 { + defer logger.Sync() + logger.Error("Code already taken by another data", + zap.String("code", code), + ) + return data, fmt.Errorf("code sudah dipakai") + } + + qry := `UPDATE nat_unit + SET Nat_UnitCode = ?, + Nat_UnitName = ?, + Nat_UnitLastUpdated = NOW() + WHERE Nat_UnitID = ?` + rst := dbx.Handlex.MustExec(qry, code, name, id) + _, err = rst.RowsAffected() + if err != nil { + defer logger.Sync() + logger.Error("Error Update natunit", + zap.String("code", code), + zap.String("name", name), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + + data, err = nu.GetMdNatUnitByID(id) + if err != nil { + defer logger.Sync() + logger.Error("Error get natunit by id", + zap.String("code", code), + zap.String("name", name), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + return data, nil +} + +func (nu *MdNatUnitServices) DeleteMdNatUnit(id string) (models.NatUnit, error) { + logger, _ := zap.NewProduction() + var data models.NatUnit + qry := `UPDATE nat_unit + SET Nat_UnitLastUpdated = NOW(), + Nat_UnitIsActive = 'N' + WHERE Nat_UnitID = ?` + rst := dbx.Handlex.MustExec(qry, id) + _, err := rst.RowsAffected() + if err != nil { + defer logger.Sync() + logger.Error("Error delete nat unit", + zap.String("id", id), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + + data, err = nu.GetMdNatUnitByID(id) + if err != nil { + defer logger.Sync() + logger.Error("Error get nat unit by id", + zap.String("id", id), + ) + return data, fmt.Errorf("QUERY_FAILED") + } + return data, nil +} diff --git a/views/dev/mdnatunit/mdnatunit.templ b/views/dev/mdnatunit/mdnatunit.templ new file mode 100644 index 0000000..8553193 --- /dev/null +++ b/views/dev/mdnatunit/mdnatunit.templ @@ -0,0 +1,212 @@ +package dev_mdnatunitview + +import ( + "cpone/layout" + "cpone/component/customtextfield" + "cpone/models" +) + +templ MdNatUnitScreen( + tableID string, + paginationID string, + searchID string, + dialogAddID string, + dialogAddBodyID string, + dialogEditID string, + dialogEditBodyID string, + dialogDeleteID string, + dialogDeleteBodyID string, + breadcrumb templ.Component, + tablecontent templ.Component, + filterComponent templ.Component, + paginationComponent templ.Component, + modalAddForm templ.Component, + modalEditForm templ.Component, + modalDeleteForm templ.Component) { +
+ @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "tableID", + Name: "tableID", + Type: "hidden", + Value: tableID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "paginationID", + Name: "paginationID", + Type: "hidden", + Value: paginationID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "searchID", + Name: "searchID", + Type: "hidden", + Value: searchID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogAddID", + Name: "dialogAddID", + Type: "hidden", + Value: dialogAddID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogAddBodyID", + Name: "dialogAddBodyID", + Type: "hidden", + Value: dialogAddBodyID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogEditID", + Name: "dialogEditID", + Type: "hidden", + Value: dialogEditID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogEditBodyID", + Name: "dialogEditBodyID", + Type: "hidden", + Value: dialogEditBodyID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogDeleteID", + Name: "dialogDeleteID", + Type: "hidden", + Value: dialogDeleteID}) + @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogDeleteBodyID", + Name: "dialogDeleteBodyID", + Type: "hidden", + Value: dialogDeleteBodyID}) +
+
+ @breadcrumb +
+
+ //
+
+ +
+
+
+ +
+
+ @filterComponent +
+ @tablecontent + @paginationComponent + @modalAddForm + @modalEditForm + @modalDeleteForm +
+ //
+
+ Loading... +
+
+
+
+
+} + +templ CssMdNatUnit() { + + + + +} + +templ JsMdNatUnit() { + +} + +script BeforeRequestContent() { + const loadingParent = document.getElementById("loading-parent"); + const loadingChild = document.getElementById("loading-child"); + const loadingSpinner = document.getElementById("loading-spinner"); + + loadingParent.classList.add("overlay"); + loadingParent.classList.add("overlay-block"); + loadingChild.classList.add("overlay-layer"); + loadingSpinner.classList.remove("d-none"); +} + +script AfterRequestContent() { + const loadingParent = document.getElementById("loading-parent"); + const loadingChild = document.getElementById("loading-child"); + const loadingSpinner = document.getElementById("loading-spinner"); + + loadingParent.classList.remove("overlay"); + loadingParent.classList.remove("overlay-block"); + loadingChild.classList.remove("overlay-layer"); + loadingSpinner.classList.add("d-none"); +} + +templ ShowMdNatUnitScreen(title string, cmp templ.Component, css templ.Component, js templ.Component, + navbarmenu templ.Component, + navbaruser templ.Component, + userprofile templ.Component) { + @layout.CorporateLayout(title, css, js, navbarmenu, navbaruser, userprofile) { + @cmp + } +} diff --git a/views/dev/mdnatunit/mdnatunit_templ.go b/views/dev/mdnatunit/mdnatunit_templ.go new file mode 100644 index 0000000..0cd19d8 --- /dev/null +++ b/views/dev/mdnatunit/mdnatunit_templ.go @@ -0,0 +1,314 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.663 +package dev_mdnatunitview + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import ( + "cpone/component/customtextfield" + "cpone/layout" + "cpone/models" +) + +func MdNatUnitScreen( + tableID string, + paginationID string, + searchID string, + dialogAddID string, + dialogAddBodyID string, + dialogEditID string, + dialogEditBodyID string, + dialogDeleteID string, + dialogDeleteBodyID string, + breadcrumb templ.Component, + tablecontent templ.Component, + filterComponent templ.Component, + paginationComponent templ.Component, + modalAddForm templ.Component, + modalEditForm templ.Component, + modalDeleteForm templ.Component) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "tableID", + Name: "tableID", + Type: "hidden", + Value: tableID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "paginationID", + Name: "paginationID", + Type: "hidden", + Value: paginationID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "searchID", + Name: "searchID", + Type: "hidden", + Value: searchID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogAddID", + Name: "dialogAddID", + Type: "hidden", + Value: dialogAddID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogAddBodyID", + Name: "dialogAddBodyID", + Type: "hidden", + Value: dialogAddBodyID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogEditID", + Name: "dialogEditID", + Type: "hidden", + Value: dialogEditID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogEditBodyID", + Name: "dialogEditBodyID", + Type: "hidden", + Value: dialogEditBodyID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogDeleteID", + Name: "dialogDeleteID", + Type: "hidden", + Value: dialogDeleteID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "dialogDeleteBodyID", + Name: "dialogDeleteBodyID", + Type: "hidden", + Value: dialogDeleteBodyID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = breadcrumb.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = filterComponent.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = tablecontent.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = paginationComponent.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = modalAddForm.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = modalEditForm.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = modalDeleteForm.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Loading...
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func CssMdNatUnit() templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var4 := templ.GetChildren(ctx) + if templ_7745c5c3_Var4 == nil { + templ_7745c5c3_Var4 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func JsMdNatUnit() templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var5 := templ.GetChildren(ctx) + if templ_7745c5c3_Var5 == nil { + templ_7745c5c3_Var5 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func BeforeRequestContent() templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_BeforeRequestContent_911f`, + Function: `function __templ_BeforeRequestContent_911f(){const loadingParent = document.getElementById("loading-parent"); + const loadingChild = document.getElementById("loading-child"); + const loadingSpinner = document.getElementById("loading-spinner"); + + loadingParent.classList.add("overlay"); + loadingParent.classList.add("overlay-block"); + loadingChild.classList.add("overlay-layer"); + loadingSpinner.classList.remove("d-none"); +}`, + Call: templ.SafeScript(`__templ_BeforeRequestContent_911f`), + CallInline: templ.SafeScriptInline(`__templ_BeforeRequestContent_911f`), + } +} + +func AfterRequestContent() templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_AfterRequestContent_6cc0`, + Function: `function __templ_AfterRequestContent_6cc0(){const loadingParent = document.getElementById("loading-parent"); + const loadingChild = document.getElementById("loading-child"); + const loadingSpinner = document.getElementById("loading-spinner"); + + loadingParent.classList.remove("overlay"); + loadingParent.classList.remove("overlay-block"); + loadingChild.classList.remove("overlay-layer"); + loadingSpinner.classList.add("d-none"); +}`, + Call: templ.SafeScript(`__templ_AfterRequestContent_6cc0`), + CallInline: templ.SafeScriptInline(`__templ_AfterRequestContent_6cc0`), + } +} + +func ShowMdNatUnitScreen(title string, cmp templ.Component, css templ.Component, js templ.Component, + navbarmenu templ.Component, + navbaruser templ.Component, + userprofile templ.Component) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var6 := templ.GetChildren(ctx) + if templ_7745c5c3_Var6 == nil { + templ_7745c5c3_Var6 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var7 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + templ_7745c5c3_Err = cmp.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = io.Copy(templ_7745c5c3_W, templ_7745c5c3_Buffer) + } + return templ_7745c5c3_Err + }) + templ_7745c5c3_Err = layout.CorporateLayout(title, css, js, navbarmenu, navbaruser, userprofile).Render(templ.WithChildren(ctx, templ_7745c5c3_Var7), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} diff --git a/views/dev/mdnatunit/mdnatunitformmodal.templ b/views/dev/mdnatunit/mdnatunitformmodal.templ new file mode 100644 index 0000000..f0d47b0 --- /dev/null +++ b/views/dev/mdnatunit/mdnatunitformmodal.templ @@ -0,0 +1,187 @@ +package dev_mdnatunitview + +import "cpone/models" +import "cpone/component/modal" +import "cpone/component/customtextfield" + +templ NatUnitForm(data models.NatUnitFormComponent) { +
+
+ @modalcomponent.Modal(data.ModalID, + data.ModalTitle, + data.DialogBody, + data.DialogAction, + data.ButtonCLose) +
+
+} + +script HandleFormBeforeRequest() { + console.log("handle disable btn add"); + const btnActCancel = document.querySelectorAll('.btnactcancel'); + const btnactsavedata = document.querySelectorAll('.btnactsavedata'); + + for (let i = 0; i < btnActCancel.length; i++) { + btnActCancel[i].setAttribute('disabled', 'true'); + + } + for (let i = 0; i < btnactsavedata.length; i++) { + btnactsavedata[i].setAttribute('disabled', 'true'); + + } +} + +script HandleFormAfterRequest() { + console.log("handle enable btn add"); + + const btnactcancel = document.querySelectorAll('.btnactcancel'); + const btnactsavedata = document.querySelectorAll('.btnactsavedata'); + + + for (let i = 0; i < btnactcancel.length; i++) { + btnactcancel[i].removeAttribute('disabled'); + + } + for (let i = 0; i < btnactsavedata.length; i++) { + btnactsavedata[i].removeAttribute('disabled'); + + } +} + +templ BodyFormNatUnit(inputId models.CustomTextFieldv2Prm, + inputCode models.CustomTextFieldv2Prm, + inputName models.CustomTextFieldv2Prm, + componentID string, + hxOnLoad templ.ComponentScript) { +
+ @customtextfield.CustomTextFieldv2( + inputId) + @customtextfield.CustomTextFieldv2( + inputCode) + @customtextfield.CustomTextFieldv2( + inputName) +
+} + +script JsHideModal(modalID string) { + $(modalID).modal('hide') +} + +script JsShowModal(modalID string) { + $(modalID).modal('show') + const btnactcancel = document.querySelectorAll('.btnactcancel'); + const btnactsavedata = document.querySelectorAll('.btnactsavedata'); + + + for (let i = 0; i < btnactcancel.length; i++) { + btnactcancel[i].removeAttribute('disabled'); + + } + for (let i = 0; i < btnactsavedata.length; i++) { + btnactsavedata[i].removeAttribute('disabled'); + + } +} + +templ ActionFormNatUnit(LinkClose string, targetClose string, hxSwapClose string, modalID string) { +
+ + +
+} + +templ BtnCloseFormNatUnit(LinkClose string, targetClose string, hxSwapClose string, modalID string) { + +} + +templ DeleteConfirmationBody(inputId models.CustomTextFieldv2Prm, + componentID string, + message string, + datHeader []string, + dataText []string, + hxOnLoad templ.ComponentScript) { +
+

{ message }

+
+
+
+ for _, v := range datHeader { +
{ v }
+ } +
+
+ for _, v := range dataText { +
+ { v } +
+ } +
+
+
+ @customtextfield.CustomTextFieldv2(inputId) +
+} + +templ ActionFormUserGroupDelete(LinkClose string, targetClose string, hxSwapClose string, modalID string) { +
+ + +
+} diff --git a/views/dev/mdnatunit/mdnatunitformmodal_templ.go b/views/dev/mdnatunit/mdnatunitformmodal_templ.go new file mode 100644 index 0000000..3e93fcd --- /dev/null +++ b/views/dev/mdnatunit/mdnatunitformmodal_templ.go @@ -0,0 +1,649 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.663 +package dev_mdnatunitview + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import "cpone/models" +import "cpone/component/modal" +import "cpone/component/customtextfield" + +func NatUnitForm(data models.NatUnitFormComponent) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, HandleFormBeforeRequest(), HandleFormAfterRequest()) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = modalcomponent.Modal(data.ModalID, + data.ModalTitle, + data.DialogBody, + data.DialogAction, + data.ButtonCLose).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func HandleFormBeforeRequest() templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_HandleFormBeforeRequest_2922`, + Function: `function __templ_HandleFormBeforeRequest_2922(){console.log("handle disable btn add"); + const btnActCancel = document.querySelectorAll('.btnactcancel'); + const btnactsavedata = document.querySelectorAll('.btnactsavedata'); + + for (let i = 0; i < btnActCancel.length; i++) { + btnActCancel[i].setAttribute('disabled', 'true'); + + } + for (let i = 0; i < btnactsavedata.length; i++) { + btnactsavedata[i].setAttribute('disabled', 'true'); + + } +}`, + Call: templ.SafeScript(`__templ_HandleFormBeforeRequest_2922`), + CallInline: templ.SafeScriptInline(`__templ_HandleFormBeforeRequest_2922`), + } +} + +func HandleFormAfterRequest() templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_HandleFormAfterRequest_956b`, + Function: `function __templ_HandleFormAfterRequest_956b(){console.log("handle enable btn add"); + + const btnactcancel = document.querySelectorAll('.btnactcancel'); + const btnactsavedata = document.querySelectorAll('.btnactsavedata'); + + + for (let i = 0; i < btnactcancel.length; i++) { + btnactcancel[i].removeAttribute('disabled'); + + } + for (let i = 0; i < btnactsavedata.length; i++) { + btnactsavedata[i].removeAttribute('disabled'); + + } +}`, + Call: templ.SafeScript(`__templ_HandleFormAfterRequest_956b`), + CallInline: templ.SafeScriptInline(`__templ_HandleFormAfterRequest_956b`), + } +} + +func BodyFormNatUnit(inputId models.CustomTextFieldv2Prm, + inputCode models.CustomTextFieldv2Prm, + inputName models.CustomTextFieldv2Prm, + componentID string, + hxOnLoad templ.ComponentScript) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var9 := templ.GetChildren(ctx) + if templ_7745c5c3_Var9 == nil { + templ_7745c5c3_Var9 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, hxOnLoad) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2( + inputId).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2( + inputCode).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2( + inputName).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func JsHideModal(modalID string) templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_JsHideModal_da6c`, + Function: `function __templ_JsHideModal_da6c(modalID){$(modalID).modal('hide') +}`, + Call: templ.SafeScript(`__templ_JsHideModal_da6c`, modalID), + CallInline: templ.SafeScriptInline(`__templ_JsHideModal_da6c`, modalID), + } +} + +func JsShowModal(modalID string) templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_JsShowModal_b74d`, + Function: `function __templ_JsShowModal_b74d(modalID){$(modalID).modal('show') + const btnactcancel = document.querySelectorAll('.btnactcancel'); + const btnactsavedata = document.querySelectorAll('.btnactsavedata'); + + + for (let i = 0; i < btnactcancel.length; i++) { + btnactcancel[i].removeAttribute('disabled'); + + } + for (let i = 0; i < btnactsavedata.length; i++) { + btnactsavedata[i].removeAttribute('disabled'); + + } +}`, + Call: templ.SafeScript(`__templ_JsShowModal_b74d`, modalID), + CallInline: templ.SafeScriptInline(`__templ_JsShowModal_b74d`, modalID), + } +} + +func ActionFormNatUnit(LinkClose string, targetClose string, hxSwapClose string, modalID string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var12 := templ.GetChildren(ctx) + if templ_7745c5c3_Var12 == nil { + templ_7745c5c3_Var12 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, JsHideModal(modalID)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func BtnCloseFormNatUnit(LinkClose string, targetClose string, hxSwapClose string, modalID string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var17 := templ.GetChildren(ctx) + if templ_7745c5c3_Var17 == nil { + templ_7745c5c3_Var17 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, JsHideModal(modalID)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func DeleteConfirmationBody(inputId models.CustomTextFieldv2Prm, + componentID string, + message string, + datHeader []string, + dataText []string, + hxOnLoad templ.ComponentScript) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var22 := templ.GetChildren(ctx) + if templ_7745c5c3_Var22 == nil { + templ_7745c5c3_Var22 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, hxOnLoad) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var25 string + templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(message) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunitformmodal.templ`, Line: 143, Col: 14} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, v := range datHeader { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var26 string + templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(v) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunitformmodal.templ`, Line: 148, Col: 68} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, v := range dataText { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var27 string + templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(v) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunitformmodal.templ`, Line: 154, Col: 10} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(inputId).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func ActionFormUserGroupDelete(LinkClose string, targetClose string, hxSwapClose string, modalID string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var28 := templ.GetChildren(ctx) + if templ_7745c5c3_Var28 == nil { + templ_7745c5c3_Var28 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, JsHideModal(modalID)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} diff --git a/views/dev/mdnatunit/mdnatunittable.templ b/views/dev/mdnatunit/mdnatunittable.templ new file mode 100644 index 0000000..ef93b98 --- /dev/null +++ b/views/dev/mdnatunit/mdnatunittable.templ @@ -0,0 +1,130 @@ +package dev_mdnatunitview + +import ( + "cpone/component/table" + "cpone/models" + "strconv" +) + +templ TableNatUnit(data []models.NatUnit, + tableID string, + hxGetEdit string, + hxTargetEdit string, + hxSwapEdit string, + hxIncludeEdit string, + hxGetDelete string, + hxTargetDelete string, + hxSwapDelete string, + hxIncludeDelete string, +) { +
+ @tablecomponent.TableV3([]string{"KODE", "UNIT", "AKSI"}, + []string{"40%", "40%", "20%"}, + RowNatUnit(data, + hxGetEdit, + hxTargetEdit, + hxSwapEdit, + hxIncludeEdit, + hxGetDelete, + hxTargetDelete, + hxSwapDelete, + hxIncludeDelete, + )) +
+} + +templ RowNatUnit(data []models.NatUnit, + hxGetEdit string, + hxTargetEdit string, + hxSwapEdit string, + hxIncludeEdit string, + hxGetDelete string, + hxTargetDelete string, + hxSwapDelete string, + hxIncludeDelete string, +) { + if len(data) == 0 { + + Data Tidak Ditemukan + + } + for _, v := range data { + + { v.Nat_UnitCode } + { v.Nat_UnitName } + + @TableAction(v.Nat_UnitID, + hxGetEdit, + hxTargetEdit, + hxSwapEdit, + hxIncludeEdit, + hxGetDelete, + hxTargetDelete, + hxSwapDelete, + hxIncludeDelete, + ) + + + } +} + +templ TableAction( + id int, + hxGetEdit string, + hxTargetEdit string, + hxSwapEdit string, + hxIncludeEdit string, + hxGetDelete string, + hxTargetDelete string, + hxSwapDelete string, + hxIncludeDelete string, +) { +
+ + + Edit + + + + Hapus + +
+} + +script HandleBeforeRequestRow(id string) { + var cusid_ele = document.getElementsByClassName('btnactionug'); + for (var i = 0; i < cusid_ele.length; ++i) { + var item = cusid_ele[i]; + item.classList.add('disabled'); + } + // console.log(id) +} + +script HandleAfterRequestRow(id string) { + var cusid_ele = document.getElementsByClassName('btnactionug'); + for (var i = 0; i < cusid_ele.length; ++i) { + var item = cusid_ele[i]; + item.classList.remove('disabled'); + } + // console.log(id) +} diff --git a/views/dev/mdnatunit/mdnatunittable_templ.go b/views/dev/mdnatunit/mdnatunittable_templ.go new file mode 100644 index 0000000..e0eaa9b --- /dev/null +++ b/views/dev/mdnatunit/mdnatunittable_templ.go @@ -0,0 +1,439 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.663 +package dev_mdnatunitview + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import ( + "cpone/component/table" + "cpone/models" + "strconv" +) + +func TableNatUnit(data []models.NatUnit, + tableID string, + hxGetEdit string, + hxTargetEdit string, + hxSwapEdit string, + hxIncludeEdit string, + hxGetDelete string, + hxTargetDelete string, + hxSwapDelete string, + hxIncludeDelete string, +) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = tablecomponent.TableV3([]string{"KODE", "UNIT", "AKSI"}, + []string{"40%", "40%", "20%"}, + RowNatUnit(data, + hxGetEdit, + hxTargetEdit, + hxSwapEdit, + hxIncludeEdit, + hxGetDelete, + hxTargetDelete, + hxSwapDelete, + hxIncludeDelete, + )).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func RowNatUnit(data []models.NatUnit, + hxGetEdit string, + hxTargetEdit string, + hxSwapEdit string, + hxIncludeEdit string, + hxGetDelete string, + hxTargetDelete string, + hxSwapDelete string, + hxIncludeDelete string, +) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var3 := templ.GetChildren(ctx) + if templ_7745c5c3_Var3 == nil { + templ_7745c5c3_Var3 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + if len(data) == 0 { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Data Tidak Ditemukan") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + for _, v := range data { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var4 string + templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(v.Nat_UnitCode) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 53, Col: 23} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var5 string + templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(v.Nat_UnitName) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\mdnatunit\mdnatunittable.templ`, Line: 54, Col: 23} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = TableAction(v.Nat_UnitID, + hxGetEdit, + hxTargetEdit, + hxSwapEdit, + hxIncludeEdit, + hxGetDelete, + hxTargetDelete, + hxSwapDelete, + hxIncludeDelete, + ).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func TableAction( + id int, + hxGetEdit string, + hxTargetEdit string, + hxSwapEdit string, + hxIncludeEdit string, + hxGetDelete string, + hxTargetDelete string, + hxSwapDelete string, + hxIncludeDelete string, +) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var6 := templ.GetChildren(ctx) + if templ_7745c5c3_Var6 == nil { + templ_7745c5c3_Var6 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, HandleBeforeRequestRow(strconv.Itoa(id)), HandleAfterRequestRow(strconv.Itoa(id))) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" Edit\r ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, HandleBeforeRequestRow(strconv.Itoa(id)), HandleAfterRequestRow(strconv.Itoa(id))) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" Hapus\r
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func HandleBeforeRequestRow(id string) templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_HandleBeforeRequestRow_9a4e`, + Function: `function __templ_HandleBeforeRequestRow_9a4e(id){var cusid_ele = document.getElementsByClassName('btnactionug'); + for (var i = 0; i < cusid_ele.length; ++i) { + var item = cusid_ele[i]; + item.classList.add('disabled'); + } + // console.log(id) +}`, + Call: templ.SafeScript(`__templ_HandleBeforeRequestRow_9a4e`, id), + CallInline: templ.SafeScriptInline(`__templ_HandleBeforeRequestRow_9a4e`, id), + } +} + +func HandleAfterRequestRow(id string) templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_HandleAfterRequestRow_9e81`, + Function: `function __templ_HandleAfterRequestRow_9e81(id){var cusid_ele = document.getElementsByClassName('btnactionug'); + for (var i = 0; i < cusid_ele.length; ++i) { + var item = cusid_ele[i]; + item.classList.remove('disabled'); + } + // console.log(id) +}`, + Call: templ.SafeScript(`__templ_HandleAfterRequestRow_9e81`, id), + CallInline: templ.SafeScriptInline(`__templ_HandleAfterRequestRow_9e81`, id), + } +}