Browse Source

Control Panel, new template file form, fix actions names

Vova Tkach 5 years ago
parent
commit
6c704adbae

File diff suppressed because it is too large
+ 0 - 0
engine/assets/tmpl.cp.base.go


+ 2 - 2
engine/assets/tmpl.cp.base.html

@@ -11,7 +11,7 @@
 				<link rel="stylesheet" href="{{$.System.PathCssCpWysiwygPell}}">
 			{{end}}
 		{{end}}
-		{{if eq $.System.CpModule "template"}}
+		{{if eq $.System.CpModule "templates"}}
 			<link rel="stylesheet" href="{{$.System.PathCssCpCodeMirror}}">
 		{{end}}
 		<link rel="stylesheet" href="{{$.System.PathCssStyles}}" />
@@ -113,7 +113,7 @@
 				<script src="{{$.System.PathJsCpWysiwygPell}}"></script>
 			{{end}}
 		{{end}}
-		{{if eq $.System.CpModule "template"}}
+		{{if eq $.System.CpModule "templates"}}
 			<script src="{{$.System.PathJsCpCodeMirror}}"></script>
 		{{end}}
 		<script src="{{$.System.PathJsCpScripts}}"></script>

+ 52 - 8
engine/modules/module_template.go

@@ -34,13 +34,14 @@ func (this *Modules) template_GetThemeFiles(wrap *wrapper.Wrapper) []string {
 
 func (this *Modules) RegisterModule_Template() *Module {
 	return this.newModule(MInfo{
-		Mount:  "template",
-		Name:   "Template",
+		Mount:  "templates",
+		Name:   "Templates",
 		Order:  802,
 		System: true,
 		Icon:   assets.SysSvgIconView,
 		Sub: &[]MISub{
-			{Mount: "default", Name: "Editor", Show: true, Icon: assets.SysSvgIconEdit},
+			{Mount: "default", Name: "Template editor", Show: true, Icon: assets.SysSvgIconEdit},
+			{Mount: "create", Name: "Add new template", Show: true, Icon: assets.SysSvgIconPlus},
 			{Mount: "restore", Name: "Restore", Show: true, Icon: assets.SysSvgIconRestore},
 		},
 	}, nil, func(wrap *wrapper.Wrapper) (string, string, string) {
@@ -48,7 +49,7 @@ func (this *Modules) RegisterModule_Template() *Module {
 		sidebar := ""
 		if wrap.CurrSubModule == "" || wrap.CurrSubModule == "default" {
 			content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
-				{Name: "Editor"},
+				{Name: "Template editor"},
 			})
 
 			files := this.template_GetThemeFiles(wrap)
@@ -80,7 +81,7 @@ func (this *Modules) RegisterModule_Template() *Module {
 					{
 						Kind:  builder.DFKHidden,
 						Name:  "action",
-						Value: "template-edit-theme-file",
+						Value: "templates-edit-theme-file",
 					},
 					{
 						Kind:    builder.DFKText,
@@ -92,7 +93,7 @@ func (this *Modules) RegisterModule_Template() *Module {
 								`<div class="row">` +
 								`<div class="col-12">` +
 								`<div style="position:relative;">` +
-								`<button type="button" class="btn btn-success" onclick="return fave.ActionRestoreThemeFile('template-restore-file','` + selected_file + `','Are you sure want to restore theme file?');" style="position:absolute;right:0;">Restore</button>` +
+								`<button type="button" class="btn btn-success" onclick="return fave.ActionRestoreThemeFile('templates-restore-file','` + selected_file + `','Are you sure want to restore theme file?');" style="position:absolute;right:0;">Restore</button>` +
 								`<select class="form-control ignore-lost-data" id="lbl_file" name="file" onchange="setTimeout(function(){$('#lbl_file').val('` + selected_file + `')},500);document.location='/cp/` + wrap.CurrModule + `/?file='+encodeURI(this.value);">` +
 								list_of_files +
 								`</select>` +
@@ -124,6 +125,49 @@ func (this *Modules) RegisterModule_Template() *Module {
 					</div>
 				</div>`
 			}
+		} else if wrap.CurrSubModule == "create" {
+			content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
+				{Name: "Add new template"},
+			})
+
+			content += builder.DataForm(wrap, []builder.DataFormField{
+				{
+					Kind:  builder.DFKHidden,
+					Name:  "action",
+					Value: "templates-create-theme-file",
+				},
+				{
+					Kind:    builder.DFKText,
+					Caption: "Theme file",
+					Name:    "file",
+					Value:   "0",
+					CallBack: func(field *builder.DataFormField) string {
+						return `<div class="form-group n1">` +
+							`<div class="row">` +
+							`<div class="col-12">` +
+							`<div style="position:relative;">` +
+							`<input class="form-control ignore-lost-data" type="text" id="lbl_name" name="name" value="" minlength="1" maxlength="250" placeholder="New template file name without extension" autocomplete="off" required>` +
+							`</div>` +
+							`</div>` +
+							`</div>` +
+							`</div>`
+					},
+				},
+				{
+					Kind: builder.DFKText,
+					CallBack: func(field *builder.DataFormField) string {
+						return `<div class="form-group last"><div class="row"><div class="col-12"><textarea class="form-control tmpl-editor" name="content" data-emode="html" placeholder="" autocomplete="off"></textarea></div></div></div>`
+					},
+				},
+				{
+					Kind: builder.DFKSubmit,
+					CallBack: func(field *builder.DataFormField) string {
+						return `<div class="row d-lg-none"><div class="col-12"><div class="pt-3"><button type="submit" class="btn btn-primary" data-target="add-edit-button">Save</button></div></div></div>`
+					},
+				},
+			})
+
+			sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Add</button>`
 		} else if wrap.CurrSubModule == "restore" {
 			content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
 				{Name: "Restore"},
@@ -139,12 +183,12 @@ func (this *Modules) RegisterModule_Template() *Module {
 				{
 					Kind: builder.DFKSubmit,
 					CallBack: func(field *builder.DataFormField) string {
-						return `<div class="row d-lg-none"><div class="col-12"><div class="pt-3"><button type="button" class="btn btn-danger" onclick="return fave.ActionRestoreThemeFile('template-restore-file-all','all','WARNING! Are you sure want to restore all theme files?');">Restore</button></div></div></div>`
+						return `<div class="row d-lg-none"><div class="col-12"><div class="pt-3"><button type="button" class="btn btn-danger" onclick="return fave.ActionRestoreThemeFile('templates-restore-file-all','all','WARNING! Are you sure want to restore all theme files?');">Restore</button></div></div></div>`
 					},
 				},
 			})
 
-			sidebar += `<button class="btn btn-danger btn-sidebar" onclick="return fave.ActionRestoreThemeFile('template-restore-file-all','all','WARNING! Are you sure want to restore all theme files?');" id="add-edit-button">Restore</button>`
+			sidebar += `<button class="btn btn-danger btn-sidebar" onclick="return fave.ActionRestoreThemeFile('templates-restore-file-all','all','WARNING! Are you sure want to restore all theme files?');" id="add-edit-button">Restore</button>`
 		}
 		return this.getSidebarModules(wrap), content, sidebar
 	})

+ 1 - 1
engine/modules/module_template_act_edit_theme_file.go

@@ -10,7 +10,7 @@ import (
 
 func (this *Modules) RegisterAction_TemplateEditThemeFile() *Action {
 	return this.newAction(AInfo{
-		Mount:     "template-edit-theme-file",
+		Mount:     "templates-edit-theme-file",
 		WantAdmin: true,
 	}, func(wrap *wrapper.Wrapper) {
 		pf_file := utils.Trim(wrap.R.FormValue("file"))

+ 1 - 1
engine/modules/module_template_act_restore_file.go

@@ -11,7 +11,7 @@ import (
 
 func (this *Modules) RegisterAction_TemplateRestoreFile() *Action {
 	return this.newAction(AInfo{
-		Mount:     "template-restore-file",
+		Mount:     "templates-restore-file",
 		WantAdmin: true,
 	}, func(wrap *wrapper.Wrapper) {
 		pf_file := utils.Trim(wrap.R.FormValue("file"))

+ 1 - 1
engine/modules/module_template_act_restore_file_all.go

@@ -11,7 +11,7 @@ import (
 
 func (this *Modules) RegisterAction_TemplateRestoreFileAll() *Action {
 	return this.newAction(AInfo{
-		Mount:     "template-restore-file-all",
+		Mount:     "templates-restore-file-all",
 		WantAdmin: true,
 	}, func(wrap *wrapper.Wrapper) {
 		pf_file := utils.Trim(wrap.R.FormValue("file"))

Some files were not shown because too many files changed in this diff