#assign textEditorCoreName = richTextEditorBackOffice() >
<#assign textEditorBlogName = blog_editor!'' >
<#assign textEditorName><#if textEditorBlogName !=''>${textEditorBlogName}<#else>${textEditorCoreName!}#if>#assign>
<#assign blogEditorFile=.get_optional_template('blog_${textEditorName}.html')>
<#assign is_content_type = use_content_type!true >
<#-- The blog editor (blog_xxx.html) edits the contenteditable div #div_html_content, copied into the textarea on submit.
A core editor (editor_xxx.html: Autumn Note, Milkdown...) builds itself in place of a textarea and keeps it in sync. -->
<#assign blogCoreEditor = false>
<#if textEditorName?trim !=''>
<#if blogEditorFile.exists>
<@blogEditorFile.include />
<#else>
<#assign coreEditorFile=.get_optional_template('/admin/util/editor/editor_${textEditorName}.html')>
<#if coreEditorFile.exists><@coreEditorFile.include /><#assign blogCoreEditor = true>#if>
#if>
<#else>
<#macro initEditor >
<@row>
<@columns>
<@callOut color='warning w-25 mx-auto' titleLevel='h3' callOutIcon='alert-triangle' title='Aucun editeur disponible !' />
@columns>
@row>
#macro>
#if>
<#-- The content field of the post, shared by create_blog.html and modify_blog.html -->
<#macro blogHtmlContent labelKey>
<#-- In the textarea the HTML of the post is text: escaped, a or an entity it holds stays as it is -->
<#local htmlContentText><#outputformat "HTML">${blog.htmlContent!}#outputformat>#local>
<#if blogCoreEditor>
<@formGroup labelFor='html_content' labelKey=labelKey helpKey='#i18n{blog.edit_blog.message.help}' rows=2 class='mb-0'>
<@input type='textarea' name='html_content' id='html_content' value=htmlContentText />
@formGroup>
<#else>
<@formGroup labelFor='div_html_content' labelKey=labelKey helpKey='#i18n{blog.edit_blog.message.help}' rows=2 class='mb-0'>
<@input type='textarea' name='html_content' id='html_content' value=htmlContentText class='visually-hidden' />
<@div id='div_html_content' class='content-body vmin-dvh-50' params='contenteditable="true"'>${blog.htmlContent!}@div>
@formGroup>
#if>
#macro>
<#-- Starts the editor on the content field: a core editor is given the textarea, the blog editor finds its div by itself -->
<#macro blogInitEditor>
<#if blogCoreEditor><@initEditor selector='#html_content' /><#else><@initEditor />#if>
#macro>
<#macro blogJSInit requiredTags=0>
<@initToast id='blogToastContainer' showAll=false >
<@addToast id='blogToast' content='to change' />
@initToast>
#macro>
<#function getFileExtension fileName>
<#local lastDotIndex = fileName?last_index_of(".")>
<#if lastDotIndex != -1>
<#return fileName?substring(lastDotIndex + 1) >
<#else>
<#return '' >
#if>
#function>
<#-- Tags and attachments cards of the editor side column, shared by create_blog.html and modify_blog.html.
The ids (#tag-list, #tag_doc, #addTag, #content-list, #attachment, #fileType, #btn-add-files) are used by blog.js -->
<#macro blogPropertiesCards>
<#local acceptedTypes = accepted_file_types!'image/*,.pdf,.xls,.doc,.docx,.xlsx,.odt,.ods,.ppt,.pptx,.odp' />
<#-- Tags -->
<@box class='mb-0'>
<@boxHeader title='#i18n{blog.modify_blog.TagsTitle}' titleActions=true>
<@aButton href='jsp/admin/plugins/blog/ManageTags.jsp?plugin_name=blog' target='_blank' color='' class='btn-action' buttonIcon='settings' title='#i18n{blog.manage_blogs.labelManageTags}' hideTitle=['all'] />
@boxHeader>
<@boxBody>
<#if number_mandatory_tags gt 0>
<@alert id='enoughTagsInfo' color='info' title='#i18n{blog.mandatoryTags.minimum.number} : ${number_mandatory_tags}' />
#if>
<@formGroup labelFor='tag_doc' labelKey='#i18n{blog.manage_tags.buttonAdd}' hideLabel=['all'] rows=2 class='mb-0'>
<@inputGroup>
<@select name='tag_doc' id='tag_doc' default_value='' items=list_tag />
<@button type='button' id='addTag' name='addTag' value='addTag' buttonIcon='plus' title='#i18n{blog.manage_tags.buttonAdd}' hideTitle=['all'] />
@inputGroup>
@formGroup>
@boxBody>
<@listGroup id='tag-list' class='list-group-flush'>
<#list blog.tag as tg>
<@listGroupItem id='tag_${tg.idTag}' class='d-flex align-items-center justify-content-between py-2'>
<@span class='badge bg-blue-lt text-truncate'><@icon style='tag' /> ${tg.name!}@span>
<@btnGroup size='sm' ariaLabel='#i18n{portal.util.labelActions}'>
<@button color='ghost-secondary' class='btn-icon btn-down' size='sm' buttonIcon='arrow-down' title='#i18n{blog.create_blog.labelDown}' hideTitle=['all'] params='onclick="doUpdatePriorityTag( ${tg.idTag}, \'moveDown\', ${blog.id} );"' />
<@button color='ghost-secondary' class='btn-icon btn-up' size='sm' buttonIcon='arrow-up' title='#i18n{blog.create_blog.labelUp}' hideTitle=['all'] params='onclick="doUpdatePriorityTag( ${tg.idTag}, \'moveUp\', ${blog.id} );"' />
<@button color='ghost-danger' class='btn-icon' size='sm' name='removeTag' value='removeTag' buttonIcon='x' title='#i18n{blog.create_blog.labelRemove}' hideTitle=['all'] params='onclick="doDeleteTag( ${tg.idTag}, \'${tg.name!?js_string}\', ${blog.id} );"' />
@btnGroup>
@listGroupItem>
#list>
@listGroup>
@box>
<#-- Attachments -->
<@box class='mb-0'>
<@boxHeader title='#i18n{blog.modify_blog.labelAttachment}' titleActions=true>
<#if is_crop_image>
<@button color='action' buttonIcon='upload' title='#i18n{blog.modify_blog.labelAttachment}' hideTitle=['all'] params='data-bs-toggle="modal" data-bs-target="#imageModal"' />
<#else>
<@button id='btn-add-files' color='action' buttonIcon='upload' title='#i18n{blog.modify_blog.labelAttachment}' hideTitle=['all'] />
#if>
@boxHeader>
<@input class='visually-hidden' name='attachment' id='attachment' type='file' accept='${acceptedTypes}' params='onchange="getFile(${blog.id})"' />
<#-- The type of the next upload, read by the crop upload only (getCroppedCanva): getFile takes it from the MIME type of the file -->
<#if is_content_type && is_crop_image>
<@boxBody class='py-2'>
<@formGroup labelFor='fileType' labelKey='#i18n{blog.create_blog.labelContentType}' rows=2 class='mb-0'>
<@select name='fileType' id='fileType' class='form-select form-select-sm'>
<#list image_type as type><@option value=type.idContentType label=type.label />#list>
@select>
@formGroup>
@boxBody>
#if>
<@div class='blog-resources'>
<@listGroup id='content-list' class='list-group-flush'>
<#list blog.docContent![] as docContent>
<@blogDocContentItem docId='${docContent.id}' docName=docContent.textValue!'' contentTypeId=(docContent.contentType.idContentType)!0 />
#list>
@listGroup>
<@blogDocContentItem docId='__ID__' docName='__NAME__.__EXT__' contentTypeId=0 />
@div>
@box>
#macro>
<#-- An attachment of the post. Also rendered in with the placeholders __ID__, __NAME__ and __EXT__,
which setListFile (blog.js) fills for an attachment uploaded in the page: both rows are the same markup -->
<#macro blogDocContentItem docId docName contentTypeId>
<#local isImage=docName?lower_case?matches('.*\\.(png|jpe?g|gif|webp|svg)$') />
<@listGroupItem id='doc_${docId}' class='blog-image d-flex align-items-center gap-2 py-2 ${isImage?then("blog-image-content","blog-file-content")}'>
<#if isImage>
<@img class='avatar avatar-md rounded object-fit-cover' url='servlet/plugins/blogs/file?id_file=${docId}' alt='${docName}' title='${docName}' />
<#else>
<@img class='avatar avatar-md rounded' url='themes/admin/shared/plugins/blog/images/file-type-${getFileExtension(docName)}.svg' alt='' />
#if>
<@div class='flex-fill text-truncate'>
<@link href='servlet/plugins/blogs/file?id_file=${docId}' class='blog-doc-content-link text-reset small' title='#i18n{portal.util.labelDownload} ${docName}'>${docName}@link>
<#if is_content_type>
<#local typeLabel = '' />
<#list image_type as type><#if type.idContentType == contentTypeId><#local typeLabel = type.label?trim />#if>#list>
<@div><@span class='badge bg-secondary-lt blog-content-type-label'>${typeLabel}@span>@div>
#if>
@div>
<@button color='ghost-secondary' class='btn-icon' size='sm' id='doc-actions-${docId}' dropdownMenu=true buttonIcon='dots-vertical' title='#i18n{portal.util.labelActions}' hideTitle=['all']>
<@link class='dropdown-item' href='#' params='onclick="doInsertContent( ${docId}, this.closest( \'.blog-image\' ).querySelector( \'.blog-doc-content-link\' ).textContent.trim( ) ); return false;"'><@icon style='file-plus' class='me-2' />#i18n{blog.create_blog.labelAddToContent}@link>
<@link class='dropdown-item btn-up' href='#' params='onclick="doUpdatePriorityContent( ${docId}, \'moveUp\', ${blog.id} ); return false;"'><@icon style='arrow-up' class='me-2' />#i18n{blog.create_blog.labelUp}@link>
<@link class='dropdown-item btn-down' href='#' params='onclick="doUpdatePriorityContent( ${docId}, \'moveDown\', ${blog.id} ); return false;"'><@icon style='arrow-down' class='me-2' />#i18n{blog.create_blog.labelDown}@link>
<#-- The content type of the attachment: the current one checked, a click saves the one chosen (setContentType, blog.js) -->
<#if is_content_type>
<#list image_type as type>
<#local isCurrent = type.idContentType == contentTypeId />
<@link class='dropdown-item blog-content-type' href='#' params='role="menuitemradio" aria-checked="${isCurrent?c}" data-content-type="${type.idContentType}" onclick="setContentType( this, ${docId}, ${type.idContentType}, ${blog.id} ); return false;"'><@icon style='check' class='me-2${isCurrent?then("", " invisible")}' />${type.label?trim}@link>
#list>
#if>
<@link class='dropdown-item text-danger' href='#' params='onclick="deleteFileContent( ${docId}, ${blog.id} ); return false;"'><@icon style='trash' class='me-2' />#i18n{blog.create_blog.labelRemove}@link>
@button>
@listGroupItem>
#macro>
<#-- Display options and URL card of the editor side column, shared by create_blog.html and modify_blog.html -->
<#macro blogOptionsCard>
<#-- Display options and URL -->
<@box class='mb-0'>
<@boxHeader title='#i18n{blog.modify_blog.labelOptions}' />
<@boxBody>
<@checkBox orientation='switch' id='display_toc' name='display_toc' value='true' checked=blog.displayToc labelKey='#i18n{blog.modify_blog.labelDisplayToc}' />
<@checkBox orientation='switch' id='display_related' name='display_related' value='true' checked=blog.displayRelated labelKey='#i18n{blog.modify_blog.labelDisplayRelated}' />
<#assign maxRelatedWrapperClass><#if !blog.displayRelated>visually-hidden#if>#assign>
<@formGroup id='max_related_wrapper' labelFor='max_related' labelKey='#i18n{blog.modify_blog.labelMaxRelated}' helpKey='#i18n{blog.modify_blog.labelMaxRelated.help}' rows=2 class=maxRelatedWrapperClass>
<@input type='number' name='max_related' id='max_related' value='${blog.maxRelated?c}' min=1 max=20 />
@formGroup>
<#assign urlPattern><#noparse>[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\-\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)#noparse>#assign>
<@formGroup labelFor='url' labelKey='#i18n{blog.create_blog.labelUrl}' helpKey='#i18n{blog.create_blog.labelUrl.help}' rows=2 class='mb-0'>
<@input name='url' id='url' value='${blog.url!}' pattern=urlPattern placeHolder='https://' />
@formGroup>
@boxBody>
@box>
#macro>