Browse Source

CP: Move shop settings from general tab to Shop tab

Vova Tkach 5 years ago
parent
commit
b1cd4bdf01
3 changed files with 155 additions and 102 deletions
  1. 97 72
      modules/module_settings.go
  2. 0 30
      modules/module_settings_act_general.go
  3. 58 0
      modules/module_settings_act_shop.go

+ 97 - 72
modules/module_settings.go

@@ -26,6 +26,7 @@ func (this *Modules) RegisterModule_Settings() *Module {
 			{Mount: "pagination", Name: "Pagination", Show: true, Icon: assets.SysSvgIconPagination},
 			{Mount: "thumbnails", Name: "Thumbnails", Show: true, Icon: assets.SysSvgIconThumbnails},
 			{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) {
@@ -65,54 +66,6 @@ func (this *Modules) RegisterModule_Settings() *Module {
 						modules_list += `>Shop</option>`
 						modules_list += `</select>`
 
-						price_format_list := ``
-						price_format_list += `<select class="form-control" id="lbl_price-fomat" name="price-fomat">`
-						price_format_list += `<option value="0"`
-						if (*wrap.Config).Shop.Price.Format == 0 {
-							price_format_list += ` selected`
-						}
-						price_format_list += `>100</option>`
-						price_format_list += `<option value="1"`
-						if (*wrap.Config).Shop.Price.Format == 1 {
-							price_format_list += ` selected`
-						}
-						price_format_list += `>100.0</option>`
-						price_format_list += `<option value="2"`
-						if (*wrap.Config).Shop.Price.Format == 2 {
-							price_format_list += ` selected`
-						}
-						price_format_list += `>100.00</option>`
-						price_format_list += `<option value="3"`
-						if (*wrap.Config).Shop.Price.Format == 3 {
-							price_format_list += ` selected`
-						}
-						price_format_list += `>100.000</option>`
-						price_format_list += `<option value="4"`
-						if (*wrap.Config).Shop.Price.Format == 4 {
-							price_format_list += ` selected`
-						}
-						price_format_list += `>100.0000</option>`
-						price_format_list += `</select>`
-
-						price_round_list := ``
-						price_round_list += `<select class="form-control" id="lbl_price-round" name="price-round">`
-						price_round_list += `<option value="0"`
-						if (*wrap.Config).Shop.Price.Round == 0 {
-							price_round_list += ` selected`
-						}
-						price_round_list += `>Don't round</option>`
-						price_round_list += `<option value="1"`
-						if (*wrap.Config).Shop.Price.Round == 1 {
-							price_round_list += ` selected`
-						}
-						price_round_list += `>Round to ceil</option>`
-						price_round_list += `<option value="2"`
-						if (*wrap.Config).Shop.Price.Round == 2 {
-							price_round_list += ` selected`
-						}
-						price_round_list += `>Round to floor</option>`
-						price_round_list += `</select>`
-
 						return `<div class="form-group n3">` +
 							`<div class="row">` +
 							`<div class="col-md-3">` +
@@ -124,30 +77,6 @@ func (this *Modules) RegisterModule_Settings() *Module {
 							`</div>` +
 							`</div>` +
 							`</div>` +
-							`</div>` +
-							`<div class="form-group n3">` +
-							`<div class="row">` +
-							`<div class="col-md-3">` +
-							`<label for="lbl_price-fomat">Price format</label>` +
-							`</div>` +
-							`<div class="col-md-9">` +
-							`<div>` +
-							price_format_list +
-							`</div>` +
-							`</div>` +
-							`</div>` +
-							`</div>` +
-							`<div class="form-group n3">` +
-							`<div class="row">` +
-							`<div class="col-md-3">` +
-							`<label for="lbl_price-round">Price round</label>` +
-							`</div>` +
-							`<div class="col-md-9">` +
-							`<div>` +
-							price_round_list +
-							`</div>` +
-							`</div>` +
-							`</div>` +
 							`</div>`
 					},
 				},
@@ -515,6 +444,102 @@ func (this *Modules) RegisterModule_Settings() *Module {
 				},
 			})
 
+			sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
+		} 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 += `<select class="form-control" id="lbl_price-fomat" name="price-fomat">`
+						price_format_list += `<option value="0"`
+						if (*wrap.Config).Shop.Price.Format == 0 {
+							price_format_list += ` selected`
+						}
+						price_format_list += `>100</option>`
+						price_format_list += `<option value="1"`
+						if (*wrap.Config).Shop.Price.Format == 1 {
+							price_format_list += ` selected`
+						}
+						price_format_list += `>100.0</option>`
+						price_format_list += `<option value="2"`
+						if (*wrap.Config).Shop.Price.Format == 2 {
+							price_format_list += ` selected`
+						}
+						price_format_list += `>100.00</option>`
+						price_format_list += `<option value="3"`
+						if (*wrap.Config).Shop.Price.Format == 3 {
+							price_format_list += ` selected`
+						}
+						price_format_list += `>100.000</option>`
+						price_format_list += `<option value="4"`
+						if (*wrap.Config).Shop.Price.Format == 4 {
+							price_format_list += ` selected`
+						}
+						price_format_list += `>100.0000</option>`
+						price_format_list += `</select>`
+
+						price_round_list := ``
+						price_round_list += `<select class="form-control" id="lbl_price-round" name="price-round">`
+						price_round_list += `<option value="0"`
+						if (*wrap.Config).Shop.Price.Round == 0 {
+							price_round_list += ` selected`
+						}
+						price_round_list += `>Don't round</option>`
+						price_round_list += `<option value="1"`
+						if (*wrap.Config).Shop.Price.Round == 1 {
+							price_round_list += ` selected`
+						}
+						price_round_list += `>Round to ceil</option>`
+						price_round_list += `<option value="2"`
+						if (*wrap.Config).Shop.Price.Round == 2 {
+							price_round_list += ` selected`
+						}
+						price_round_list += `>Round to floor</option>`
+						price_round_list += `</select>`
+
+						return `<div class="form-group n3">` +
+							`<div class="row">` +
+							`<div class="col-md-3">` +
+							`<label for="lbl_price-fomat">Price format</label>` +
+							`</div>` +
+							`<div class="col-md-9">` +
+							`<div>` +
+							price_format_list +
+							`</div>` +
+							`</div>` +
+							`</div>` +
+							`</div>` +
+							`<div class="form-group n3">` +
+							`<div class="row">` +
+							`<div class="col-md-3">` +
+							`<label for="lbl_price-round">Price round</label>` +
+							`</div>` +
+							`<div class="col-md-9">` +
+							`<div>` +
+							price_round_list +
+							`</div>` +
+							`</div>` +
+							`</div>` +
+							`</div>`
+					},
+				},
+				{
+					Kind:   builder.DFKSubmit,
+					Value:  "Save",
+					Target: "add-edit-button",
+				},
+			})
+
 			sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
 		} else if wrap.CurrSubModule == "api" {
 			content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{

+ 0 - 30
modules/module_settings_act_general.go

@@ -12,27 +12,13 @@ func (this *Modules) RegisterAction_SettingsGeneral() *Action {
 		WantAdmin: true,
 	}, func(wrap *wrapper.Wrapper) {
 		pf_module_at_home := wrap.R.FormValue("module-at-home")
-		pf_price_fomat := wrap.R.FormValue("price-fomat")
-		pf_price_round := wrap.R.FormValue("price-round")
 
 		if !utils.IsNumeric(pf_module_at_home) {
 			wrap.MsgError(`Must be integer number`)
 			return
 		}
 
-		if !utils.IsNumeric(pf_price_fomat) {
-			wrap.MsgError(`Must be integer number`)
-			return
-		}
-
-		if !utils.IsNumeric(pf_price_round) {
-			wrap.MsgError(`Must be integer number`)
-			return
-		}
-
 		pfi_module_at_home := utils.StrToInt(pf_module_at_home)
-		pfi_price_fomat := utils.StrToInt(pf_price_fomat)
-		pfi_price_round := utils.StrToInt(pf_price_round)
 
 		// Correct values
 		if pfi_module_at_home < 0 {
@@ -42,23 +28,7 @@ func (this *Modules) RegisterAction_SettingsGeneral() *Action {
 			pfi_module_at_home = 2
 		}
 
-		if pfi_price_fomat < 0 {
-			pfi_price_fomat = 0
-		}
-		if pfi_price_fomat > 4 {
-			pfi_price_fomat = 4
-		}
-
-		if pfi_price_round < 0 {
-			pfi_price_round = 0
-		}
-		if pfi_price_round > 2 {
-			pfi_price_round = 2
-		}
-
 		(*wrap.Config).Engine.MainModule = pfi_module_at_home
-		(*wrap.Config).Shop.Price.Format = pfi_price_fomat
-		(*wrap.Config).Shop.Price.Round = pfi_price_round
 
 		if err := wrap.ConfigSave(); err != nil {
 			wrap.MsgError(err.Error())

+ 58 - 0
modules/module_settings_act_shop.go

@@ -0,0 +1,58 @@
+package modules
+
+import (
+	"golang-fave/engine/wrapper"
+	"golang-fave/utils"
+)
+
+func (this *Modules) RegisterAction_SettingsShop() *Action {
+	return this.newAction(AInfo{
+		WantDB:    true,
+		Mount:     "settings-shop",
+		WantAdmin: true,
+	}, func(wrap *wrapper.Wrapper) {
+		pf_price_fomat := wrap.R.FormValue("price-fomat")
+		pf_price_round := wrap.R.FormValue("price-round")
+
+		if !utils.IsNumeric(pf_price_fomat) {
+			wrap.MsgError(`Must be integer number`)
+			return
+		}
+
+		if !utils.IsNumeric(pf_price_round) {
+			wrap.MsgError(`Must be integer number`)
+			return
+		}
+
+		pfi_price_fomat := utils.StrToInt(pf_price_fomat)
+		pfi_price_round := utils.StrToInt(pf_price_round)
+
+		// Correct values
+		if pfi_price_fomat < 0 {
+			pfi_price_fomat = 0
+		}
+		if pfi_price_fomat > 4 {
+			pfi_price_fomat = 4
+		}
+
+		if pfi_price_round < 0 {
+			pfi_price_round = 0
+		}
+		if pfi_price_round > 2 {
+			pfi_price_round = 2
+		}
+
+		(*wrap.Config).Shop.Price.Format = pfi_price_fomat
+		(*wrap.Config).Shop.Price.Round = pfi_price_round
+
+		if err := wrap.ConfigSave(); err != nil {
+			wrap.MsgError(err.Error())
+			return
+		}
+
+		wrap.ResetCacheBlocks()
+
+		// Reload current page
+		wrap.Write(`window.location.reload(false);`)
+	})
+}