Consolidated shared editor-related params

This commit is contained in:
Asaf Gartner 2022-09-15 00:44:27 +03:00
parent c9ee420dbb
commit c489d0ffa9
6 changed files with 35 additions and 22 deletions

View File

@ -1,7 +1,7 @@
{{ template "base.html" . }}
{{ define "extrahead" }}
{{ template "markdown_previews.html" . }}
{{ template "markdown_previews.html" .TextEditor }}
<script src="{{ static "js/base64.js" }}"></script>
<script src="{{ static "js/markdown_upload.js" }}"></script>
@ -116,8 +116,8 @@
</div>
<script>
const maxFileSize = {{ .MaxFileSize }};
const uploadUrl = {{ .UploadUrl }};
const maxFileSize = {{ .TextEditor.MaxFileSize }};
const uploadUrl = {{ .TextEditor.UploadUrl }};
const form = document.querySelector('#form');
const titleField = document.querySelector('#title'); // may be undefined, be careful!

View File

@ -1,7 +1,7 @@
{{ template "base.html" . }}
{{ define "extrahead" }}
{{ template "markdown_previews.html" . }}
{{ template "markdown_previews.html" .TextEditor }}
<script src="{{ static "js/tabs.js" }}"></script>
<script src="{{ static "js/image_selector.js" }}"></script>
<script src="{{ static "js/templates.js" }}"></script>
@ -407,8 +407,8 @@
document.querySelector('.upload_bar'),
description,
doMarkdown,
{{ .MaxFileSize }},
{{ .UploadUrl }}
{{ .TextEditor.MaxFileSize }},
{{ .TextEditor.UploadUrl }}
);
</script>

View File

@ -389,6 +389,12 @@ type Tag struct {
Url string
}
type TextEditor struct {
ParserName string
MaxFileSize int
UploadUrl string
}
type EduArticle struct {
Title string
Slug string

View File

@ -317,12 +317,14 @@ func getEditorDataForEduArticle(
SubmitLabel: "Submit",
CanEditPostTitle: true,
MaxFileSize: AssetMaxSize(currentUser),
UploadUrl: urlContext.BuildAssetUpload(),
ShowEduOptions: true,
PreviewClass: "edu-article",
ParserName: "parseMarkdownEdu",
TextEditor: templates.TextEditor{
ParserName: "parseMarkdownEdu",
MaxFileSize: AssetMaxSize(currentUser),
UploadUrl: urlContext.BuildAssetUpload(),
},
}
if article != nil {

View File

@ -51,9 +51,7 @@ type editorData struct {
ShowEduOptions bool
PreviewClass string
ParserName string
MaxFileSize int
UploadUrl string
TextEditor templates.TextEditor
}
func getEditorDataForNew(urlContext *hmnurl.UrlContext, currentUser *models.User, baseData templates.BaseData, replyPost *templates.Post) editorData {
@ -61,8 +59,10 @@ func getEditorDataForNew(urlContext *hmnurl.UrlContext, currentUser *models.User
BaseData: baseData,
CanEditPostTitle: replyPost == nil,
PostReplyingTo: replyPost,
MaxFileSize: AssetMaxSize(currentUser),
UploadUrl: urlContext.BuildAssetUpload(),
TextEditor: templates.TextEditor{
MaxFileSize: AssetMaxSize(currentUser),
UploadUrl: urlContext.BuildAssetUpload(),
},
}
if replyPost != nil {
@ -79,8 +79,10 @@ func getEditorDataForEdit(urlContext *hmnurl.UrlContext, currentUser *models.Use
CanEditPostTitle: p.Thread.FirstID == p.Post.ID,
IsEditing: true,
EditInitialContents: p.CurrentVersion.TextRaw,
MaxFileSize: AssetMaxSize(currentUser),
UploadUrl: urlContext.BuildAssetUpload(),
TextEditor: templates.TextEditor{
MaxFileSize: AssetMaxSize(currentUser),
UploadUrl: urlContext.BuildAssetUpload(),
},
}
}

View File

@ -419,8 +419,7 @@ type ProjectEditData struct {
APICheckUsernameUrl string
LogoMaxFileSize int
MaxFileSize int
UploadUrl string
TextEditor templates.TextEditor
}
func ProjectNew(c *RequestContext) ResponseData {
@ -463,8 +462,10 @@ func ProjectNew(c *RequestContext) ResponseData {
APICheckUsernameUrl: hmnurl.BuildAPICheckUsername(),
LogoMaxFileSize: ProjectLogoMaxFileSize,
MaxFileSize: AssetMaxSize(c.CurrentUser),
UploadUrl: c.UrlContext.BuildAssetUpload(),
TextEditor: templates.TextEditor{
MaxFileSize: AssetMaxSize(c.CurrentUser),
UploadUrl: c.UrlContext.BuildAssetUpload(),
},
}, c.Perf)
return res
}
@ -606,8 +607,10 @@ func ProjectEdit(c *RequestContext) ResponseData {
APICheckUsernameUrl: hmnurl.BuildAPICheckUsername(),
LogoMaxFileSize: ProjectLogoMaxFileSize,
MaxFileSize: AssetMaxSize(c.CurrentUser),
UploadUrl: c.UrlContext.BuildAssetUpload(),
TextEditor: templates.TextEditor{
MaxFileSize: AssetMaxSize(c.CurrentUser),
UploadUrl: c.UrlContext.BuildAssetUpload(),
},
}, c.Perf)
return res
}