Browse Source

CP render, fix update cp user action

Vova Tkach 6 years ago
parent
commit
b7da0dbc19
2 changed files with 49 additions and 5 deletions
  1. 21 0
      consts/consts.go
  2. 28 5
      modules/module_index.go

+ 21 - 0
consts/consts.go

@@ -1,5 +1,9 @@
 package consts
 
+import (
+	"html/template"
+)
+
 const Debug = true
 const ServerVersion = "1.0.1"
 const AssetsVersion = "1"
@@ -43,6 +47,23 @@ type TmplData struct {
 	Data   interface{}
 }
 
+type TmplDataCpBase struct {
+	Title              string
+	BodyClasses        string
+	UserId             int
+	UserFirstName      string
+	UserLastName       string
+	UserEmail          string
+	UserPassword       string
+	UserAvatarLink     string
+	NavBarModules      template.HTML
+	NavBarModulesSys   template.HTML
+	ModuleCurrentAlias string
+	SidebarLeft        template.HTML
+	Content            template.HTML
+	SidebarRight       template.HTML
+}
+
 type TmplDataMainMenuItem struct {
 	Name   string
 	Link   string

+ 28 - 5
modules/module_index.go

@@ -5,10 +5,11 @@ import (
 	_ "github.com/go-sql-driver/mysql"
 
 	"fmt"
-	"net/http"
+	"html/template"
 	"os"
 	"strconv"
 
+	"golang-fave/assets"
 	"golang-fave/consts"
 	"golang-fave/engine/wrapper"
 	"golang-fave/utils"
@@ -35,10 +36,29 @@ func (this *Modules) RegisterModule_Index() *Module {
 		})
 	}, func(wrap *wrapper.Wrapper) {
 		// Back-end
-		wrap.W.WriteHeader(http.StatusOK)
-		wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
-		wrap.W.Header().Set("Content-Type", "text/html; charset=utf-8")
-		wrap.W.Write([]byte(`INDEX BackEnd func call (` + wrap.CurrModule + `)`))
+		body_class := "cp"
+		nav_bar_modules_all := ""
+		nav_bar_modules_sys := ""
+		page_sb_left := "Left"
+		page_content := "Content"
+		page_sb_right := "Right"
+
+		wrap.RenderBackEnd(assets.TmplCpBase, consts.TmplDataCpBase{
+			Title:              "Fave " + consts.ServerVersion,
+			BodyClasses:        body_class,
+			UserId:             wrap.User.A_id,
+			UserFirstName:      wrap.User.A_first_name,
+			UserLastName:       wrap.User.A_last_name,
+			UserEmail:          wrap.User.A_email,
+			UserPassword:       "",
+			UserAvatarLink:     "https://s.gravatar.com/avatar/" + utils.GetMd5(wrap.User.A_email) + "?s=80&r=g",
+			NavBarModules:      template.HTML(nav_bar_modules_all),
+			NavBarModulesSys:   template.HTML(nav_bar_modules_sys),
+			ModuleCurrentAlias: "index",
+			SidebarLeft:        template.HTML(page_sb_left),
+			Content:            template.HTML(page_content),
+			SidebarRight:       template.HTML(page_sb_right),
+		})
 	})
 }
 
@@ -262,5 +282,8 @@ func (this *Modules) RegisterAction_CpUserSettings() *Action {
 				return
 			}
 		}
+
+		// Reload current page
+		wrap.Write(`window.location.reload(false);`)
 	})
 }