package modules import ( "html" "io/ioutil" "os" "golang-fave/engine/assets" "golang-fave/engine/builder" "golang-fave/engine/consts" "golang-fave/engine/utils" "golang-fave/engine/wrapper" ) func (this *Modules) RegisterModule_Settings() *Module { return this.newModule(MInfo{ Mount: "settings", Name: "Settings", Order: 801, System: true, Icon: assets.SysSvgIconGear, Sub: &[]MISub{ {Mount: "default", Name: "General", Show: true, Icon: assets.SysSvgIconGear}, {Mount: "robots-txt", Name: "Robots.txt", Show: true, Icon: assets.SysSvgIconBug}, {Mount: "pagination", Name: "Pagination", Show: true, Icon: assets.SysSvgIconPagination}, {Mount: "thumbnails", Name: "Thumbnails", Show: true, Icon: assets.SysSvgIconThumbnails}, {Mount: "domains", Name: "Domains", Show: true, Icon: assets.SysSvgIconApi}, {Mount: "smtp", Name: "SMTP", Show: true, Icon: assets.SysSvgIconEmail}, {Mount: "shop", Name: "Shop", Show: true, Icon: assets.SysSvgIconShop}, {Mount: "api", Name: "API", Show: true, Icon: assets.SysSvgIconApi}, }, }, nil, func(wrap *wrapper.Wrapper) (string, string, string) { content := "" sidebar := "" if wrap.CurrSubModule == "" || wrap.CurrSubModule == "default" { content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{ {Name: "General"}, }) content += builder.DataForm(wrap, []builder.DataFormField{ { Kind: builder.DFKHidden, Name: "action", Value: "settings-general", }, { Kind: builder.DFKText, CallBack: func(field *builder.DataFormField) string { modules_list := `` modules_list += `` return `
` + `
` + `
` + `` + `
` + `
` + `
` + modules_list + `
` + `
` + `
` + `
` }, }, { Kind: builder.DFKCheckBox, Caption: "Maintenance", Name: "maintenance", Value: utils.IntToStr((*wrap.Config).Engine.Maintenance), Hint: "Close web site for maintenance", }, { Kind: builder.DFKCheckBox, Caption: "Blog is enabled", Name: "mod-enabled-blog", Value: utils.IntToStr((*wrap.Config).Modules.Enabled.Blog), Hint: "Module can be enabled or fully disabled", }, { Kind: builder.DFKCheckBox, Caption: "Shop is enabled", Name: "mod-enabled-shop", Value: utils.IntToStr((*wrap.Config).Modules.Enabled.Shop), Hint: "Module can be enabled or fully disabled", }, { Kind: builder.DFKSubmit, Value: "Save", Target: "add-edit-button", }, }) sidebar += `` } else if wrap.CurrSubModule == "robots-txt" { content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{ {Name: "Robots.txt"}, }) fcont := []byte(``) fcont, _ = ioutil.ReadFile(wrap.DTemplate + string(os.PathSeparator) + "robots.txt") content += builder.DataForm(wrap, []builder.DataFormField{ { Kind: builder.DFKHidden, Name: "action", Value: "settings-robots-txt", }, { Kind: builder.DFKText, CallBack: func(field *builder.DataFormField) string { return `
` }, }, { Kind: builder.DFKSubmit, CallBack: func(field *builder.DataFormField) string { return `
` }, }, }) sidebar += `` } else if wrap.CurrSubModule == "pagination" { content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{ {Name: "Pagination"}, }) content += builder.DataForm(wrap, []builder.DataFormField{ { Kind: builder.DFKHidden, Name: "action", Value: "settings-pagination", }, { Kind: builder.DFKNumber, Caption: "Blog main page", Name: "blog-index", Min: "1", Max: "100", Required: true, Value: utils.IntToStr((*wrap.Config).Blog.Pagination.Index), }, { Kind: builder.DFKNumber, Caption: "Blog category page", Name: "blog-category", Min: "1", Max: "100", Required: true, Value: utils.IntToStr((*wrap.Config).Blog.Pagination.Category), }, { Kind: builder.DFKText, Caption: "", Name: "", Value: "", CallBack: func(field *builder.DataFormField) string { return `
` }, }, { Kind: builder.DFKNumber, Caption: "Shop main page", Name: "shop-index", Min: "1", Max: "100", Required: true, Value: utils.IntToStr((*wrap.Config).Shop.Pagination.Index), }, { Kind: builder.DFKNumber, Caption: "Shop category page", Name: "shop-category", Min: "1", Max: "100", Required: true, Value: utils.IntToStr((*wrap.Config).Shop.Pagination.Category), }, { Kind: builder.DFKSubmit, Value: "Save", Target: "add-edit-button", }, }) sidebar += `` } else if wrap.CurrSubModule == "thumbnails" { content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{ {Name: "Thumbnails"}, }) content += builder.DataForm(wrap, []builder.DataFormField{ { Kind: builder.DFKHidden, Name: "action", Value: "settings-thumbnails", }, { Kind: builder.DFKText, CallBack: func(field *builder.DataFormField) string { resize_list := `` resize_list += `` return `
` + `
` + `
` + `` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + resize_list + `
` + `
` + `
` + `
` + `
` + `
` }, }, { Kind: builder.DFKText, CallBack: func(field *builder.DataFormField) string { resize_list := `` resize_list += `` return `
` + `
` + `
` + `` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + resize_list + `
` + `
` + `
` + `
` + `
` + `
` }, }, { Kind: builder.DFKText, CallBack: func(field *builder.DataFormField) string { resize_list := `` resize_list += `` return `
` + `
` + `
` + `` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + resize_list + `
` + `
` + `
` + `
` + `
` + `
` }, }, { Kind: builder.DFKText, CallBack: func(field *builder.DataFormField) string { resize_list := `` resize_list += `` return `
` + `
` + `
` + `` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `
` + resize_list + `
` + `
` + `
` + `
` + `
` + `
` }, }, { Kind: builder.DFKSubmit, Value: "Save", Target: "add-edit-button", }, }) sidebar += `` } else if wrap.CurrSubModule == "domains" { content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{ {Name: "Domains"}, }) fcont := []byte(``) fcont, _ = ioutil.ReadFile(wrap.DConfig + string(os.PathSeparator) + ".domains") content += builder.DataForm(wrap, []builder.DataFormField{ { Kind: builder.DFKHidden, Name: "action", Value: "settings-domains", }, { Kind: builder.DFKText, CallBack: func(field *builder.DataFormField) string { return `
` }, }, { Kind: builder.DFKSubmit, CallBack: func(field *builder.DataFormField) string { return `
` }, }, }) sidebar += `` } else if wrap.CurrSubModule == "smtp" { content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{ {Name: "SMTP"}, }) content += builder.DataForm(wrap, []builder.DataFormField{ { Kind: builder.DFKHidden, Name: "action", Value: "settings-smtp", }, { Kind: builder.DFKText, Caption: "SMTP server host", Name: "smtp-host", Value: (*wrap.Config).SMTP.Host, Hint: "Example: smtp.gmail.com", }, { Kind: builder.DFKNumber, Caption: "SMTP server port", Name: "smtp-port", Min: "0", Max: "9999", Required: true, Value: utils.IntToStr((*wrap.Config).SMTP.Port), Hint: "Example: 587", }, { Kind: builder.DFKText, Caption: "SMTP user login", Name: "smtp-login", Value: (*wrap.Config).SMTP.Login, Hint: "Example: example@gmail.com", }, { Kind: builder.DFKPassword, Caption: "SMTP user password", Name: "smtp-password", Value: "", Hint: "Leave this field empty if you don't want change password", }, { Kind: builder.DFKText, Caption: "Email address for testing", Name: "smtp-test-email", Value: "", Hint: "To this email address will be send test email message if settings are correct", }, { Kind: builder.DFKSubmit, Value: "Save", Target: "add-edit-button", }, }) sidebar += `` } else if wrap.CurrSubModule == "shop" { content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{ {Name: "Shop"}, }) content += builder.DataForm(wrap, []builder.DataFormField{ { Kind: builder.DFKHidden, Name: "action", Value: "settings-shop", }, { Kind: builder.DFKText, CallBack: func(field *builder.DataFormField) string { price_format_list := `` price_format_list += `` price_round_list := `` price_round_list += `` return `
` + `
` + `
` + `` + `
` + `
` + `
` + price_format_list + `
` + `
` + `
` + `
` + `
` + `
` + `
` + `` + `
` + `
` + `
` + price_round_list + `
` + `
` + `
` + `
` }, }, { Kind: builder.DFKText, CallBack: func(field *builder.DataFormField) string { make_checkbox := func(name, caption string, value int) string { checked := "" if value > 0 { checked = " checked" } return `
` } checkboxes := "" checkboxes += make_checkbox("require-last-name", "Last Name", (*wrap.Config).Shop.Orders.RequiredFields.LastName) checkboxes += make_checkbox("require-first-name", "First Name", (*wrap.Config).Shop.Orders.RequiredFields.FirstName) checkboxes += make_checkbox("require-middle-name", "Middle Name", (*wrap.Config).Shop.Orders.RequiredFields.MiddleName) checkboxes += make_checkbox("require-mobile-phone", "Mobile Phone", (*wrap.Config).Shop.Orders.RequiredFields.MobilePhone) checkboxes += make_checkbox("require-email-address", "Email Address", (*wrap.Config).Shop.Orders.RequiredFields.EmailAddress) checkboxes += make_checkbox("require-delivery", "Delivery", (*wrap.Config).Shop.Orders.RequiredFields.Delivery) checkboxes += make_checkbox("require-comment", "Comment", (*wrap.Config).Shop.Orders.RequiredFields.Comment) return `
` + `
` + `
` + `` + `
` + `
` + `
` + checkboxes + `
` + `
` + `
` + `
` }, }, { Kind: builder.DFKCheckBox, Caption: "Accept orders", Name: "accept-orders", Value: utils.IntToStr((*wrap.Config).Shop.Orders.Enabled), }, { Kind: builder.DFKText, Caption: "New order notify email", Name: "new-order-notify-email", Value: (*wrap.Config).Shop.Orders.NotifyEmail, Hint: "Example: example@gmail.com", }, { Kind: builder.DFKText, Caption: "New order email theme (CP)", Name: "new-order-email-theme-cp", Value: (*wrap.Config).Shop.Orders.NewOrderEmailThemeCp, }, { Kind: builder.DFKText, Caption: "New order email theme (User)", Name: "new-order-email-theme-user", Value: (*wrap.Config).Shop.Orders.NewOrderEmailThemeUser, }, { Kind: builder.DFKCheckBox, Caption: "Custom field 1 enabled", Name: "custom-field-1-enabled", Value: utils.IntToStr((*wrap.Config).Shop.CustomFields.Field1.Enabled), }, { Kind: builder.DFKText, Caption: "Custom field 1 caption", Name: "custom-field-1-caption", Value: (*wrap.Config).Shop.CustomFields.Field1.Caption, Hint: "Caption for product custom field", }, { Kind: builder.DFKCheckBox, Caption: "Custom field 2 enabled", Name: "custom-field-2-enabled", Value: utils.IntToStr((*wrap.Config).Shop.CustomFields.Field2.Enabled), }, { Kind: builder.DFKText, Caption: "Custom field 2 caption", Name: "custom-field-2-caption", Value: (*wrap.Config).Shop.CustomFields.Field2.Caption, Hint: "Caption for product custom field", }, { Kind: builder.DFKSubmit, Value: "Save", Target: "add-edit-button", }, }) sidebar += `` } else if wrap.CurrSubModule == "api" { content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{ {Name: "API"}, }) content += builder.DataForm(wrap, []builder.DataFormField{ { Kind: builder.DFKHidden, Name: "action", Value: "settings-api", }, { Kind: builder.DFKCheckBox, Caption: "XML enabled", Name: "xml-enabled", Value: utils.IntToStr((*wrap.Config).API.XML.Enabled), Hint: "XML: /api/products/", }, { Kind: builder.DFKText, Caption: "XML name", Name: "xml-name", Value: (*wrap.Config).API.XML.Name, }, { Kind: builder.DFKText, Caption: "XML company", Name: "xml-company", Value: (*wrap.Config).API.XML.Company, }, { Kind: builder.DFKText, Caption: "XML url", Name: "xml-url", Value: (*wrap.Config).API.XML.Url, }, { Kind: builder.DFKSubmit, Value: "Save", Target: "add-edit-button", }, }) sidebar += `` } return this.getSidebarModules(wrap), content, sidebar }) }