<@cms.category id=categoryId!>
    <#assign category=object/>
    <@cms.model id=modelId!>
        <#assign
            model=object
            fieldList=model.fieldList![]
            requiredFieldList=model.requiredFfieldList![]
        />
<#assign formContent>
    <#if category.allowContribute>
<#noparse><#if user?has_content>
<@cms.content id=id containsAttribute=true>
    <#assign content=object/>
    <#assign attribute=content.attribute/>
</@cms.content>
<form name="contribute" method="post" action="${site.dynamicPath}content/save">
    <input type="hidden" name="_csrf" value="<@tools.csrfToken/>"/>
    <input name="returnUrl" type="hidden" value="${site.dynamicPath}"/></#noparse>
    <input name="categoryId" type="hidden" value="${category.id!}"/>
    <input name="modelId" type="hidden" value="${model.id!}"/>
<#if fieldList?seq_contains('author')>
    <input name="author" type="hidden" value="<#noparse>${(user.nickname)!}</#noparse>"/>
</#if>
    <p>
        <label>${(model.fieldTextMap['title'])!}:</label>
        <input name="title" type="text" size="60" required="true" maxlength="255" value="<#noparse>${(content.title)!}</#noparse>"/>
    </p>
<#if fieldList?seq_contains('description')>
    <p>
        <label>${(model.fieldTextMap['description'])!}:</label>
        <textarea name="description" cols="80" rows="20" maxlength="300"><#noparse>${(content.description)!}</#noparse></textarea>
    </p>
</#if>
<#if model.onlyUrl>
    <p>
        <label>${(model.fieldTextMap['url'])!}:</label>
        <input name="url" type="text" size="60" maxlength="1000" value="<#noparse>${(content.url)!}</#noparse>"/>
    </p>
</#if>
<#if fieldList?seq_contains('content')>
    <p>
        <label>${(model.fieldTextMap['content'])!}:</label>
        <textarea name="text" class="editor" cols="80" rows="20"><#noparse>${(attribute.text)!}</#noparse></textarea>
    </p>
</#if>
    <#include "../include_page/extendData.html"/>
    <@sys.extendFieldList extendId=category.extendId>
        <@extendData extendList=list type="customform"/>
    </@sys.extendFieldList>
    <@extendData extendList=model.extendList type="customform"/>
<#noparse>
    <@sys.configData code="safe">
        <#if object.captcha?has_content && object.captcha?split(",")?seq_contains("contribute")>
    <p>
        <input name="captcha" required="true" type="text" autocomplete="off" placeholder="Captcha" title="Captcha"/>
        <img src="${site.dynamicPath}getCaptchaImage?${.now?long}" alt="captcha" onclick="this.src=this.src+'&'+new Date().getTime()"/>
    </p>
        </#if>
    </@sys.configData>
</#noparse>
    <p><input type="submit" value="<@t.page 'button.save'/>"/></p>
</form>
<#noparse>
<script src="${site.dynamicPath}resource/js/loadscripts.js"></script>
<script>
var editors = document.querySelectorAll(".editor");
if(editors.length){
    window.UEDITOR_HOME_URL = "${site.dynamicPath}resource/plugins/ueditor/";
    var base="${site.dynamicPath}";
    loadScripts(["${site.dynamicPath}resource/plugins/ueditor/ueditor.config.js","${site.dynamicPath}resource/plugins/ueditor/ueditor.all.min.js","${site.dynamicPath}resource/plugins/ueditor/lang/</#noparse><@t.page 'ueditor.lang_js'/><#noparse>"],function(){
        window.UEDITOR_CONFIG.topOffset=0;
        editors.forEach(e => {
            var editor = new baidu.editor.ui.Editor();
            editor.render(e);
        });
        document.querySelector("form[name=contribute]").onsubmit=function(){
            editors.forEach(e => {
                var editor = new baidu.editor.ui.Editor();
                UE.getEditor(e).sync();
            });
        }
    });
}
var files = document.querySelectorAll("form[name=contribute] input[type=file]");
if(files.length){
    files.forEach(f => {
        f.onchange  = function() {
            var file = this.files[0];
            var formData = new FormData();
            formData.append('file', file, file.name );
            formData.append('_csrf', '<@tools.csrfToken/>' );
            if("true"==file.getAttribute("data-private")){
                formData.append('privatefile', "true");
            }
            fetch("${site.dynamicPath}file/doUpload", {
                method: this.method,
                body: formData,
                headers: {
                    'Content-Type': 'multipart/form-data'
                }
            })
            .then(response => response.json())
            .then(data => {
                if(data.success){
                    document.querySelector(file.getAttribute("target")).value=data.fileName;
                }else{
                    alert(data.error);
                }
            })
            .catch(error => alert(error));
          });
    });
}
</script>
<#else>
please <a href="${site.dynamicPath}login.html">login</a>
</#if></#noparse><#else><@t.message 'verify.custom.contribute'/></#if></#assign>
    </@cms.model>
</@cms.category>
    <dl>
        <dt><@t.page 'category'/>:</dt>
        <dd>
            ${(category.name)!}
        </dd>
    </dl>
    <dl>
        <dt><@t.page 'model'/>:</dt>
        <dd>
            ${(model.name)!}
        </dd>
    </dl>
    <dl class="nowrap">
        <dt><@t.page 'source_code'/>:</dt>
        <dd>
            <textarea class="code" mode="freemarkermixed"><@html_escape>${(formContent)!}</@html_escape></textarea>
        </dd>
    </dl>