<@tools.placeMetadata path=path>
    <#assign a=object/>
<#assign formContent>
    <#if a.allowContribute>
        <#assign
            fieldList=a.fieldList![]
            requiredFieldList=a.requiredFieldList![]
        />
<#if !a.allowAnonymous>
<#noparse>
<#if user?has_content>
</#noparse>
</#if>
<#noparse>
<@cms.place id=id containsAttribute=true>
    <#assign place=object/>
    <#assign attribute=place.attribute/>
</@cms.place>
<form name="contribute" method="post" action="${site.dynamicPath}place/save"></#noparse>
<#if !a.allowAnonymous>
    <input type="hidden" name="_csrf" value="<#noparse><@tools.csrfToken/></#noparse>"/>
</#if>
    <input name="path" type="hidden" value="${(path)!}"/>
    <input name="returnUrl" type="hidden" value="<#noparse>${site.dynamicPath}</#noparse>"/>
    <p>
        <label>${(a.fieldTextMap['title'])!}:</label>
        <input name="title" type="text" size="60" required="required" maxlength="255" value="<#noparse>${(place.title)!}</#noparse>"/>
    </p>
<#if fieldList?seq_contains('description')>
    <p>
        <label>${(a.fieldTextMap['description'])!}:</label>
        <textarea name="description" maxlength="300"><#noparse>${(place.description)!}</#noparse></textarea>
    </p>
</#if>
<#if fieldList?seq_contains('url')>
    <p>
        <label>${(a.fieldTextMap['url'])!}:</label>
        <input name="url" type="text" size="60" maxlength="1000" value="<#noparse>${(place.url)!}</#noparse>"/>
    </p>
</#if>
<#if fieldList?seq_contains('cover')>
    <p>
        <label>${(a.fieldTextMap['cover'])!}:</label>
        <input name="cover" type="text" size="50" maxlength="1000" value="<#noparse>${(place.cover)!}</#noparse>"/>
    </p>
</#if>
    <#include "../include_page/extendData.html"/>
    <@extendData extendList=a.extendList type="customform"/>
<#noparse>
    <@sys.configData code="safe">
        <#if object.captcha?has_content && object.captcha?split(",")?seq_contains("contribute")>
    <p>
        <input name="captcha" required="required" 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>
</#noparse>
<#if a.adminIds?has_content>
    ${'<#assign path=\''?no_esc+path+'\'/>'?no_esc}
<#noparse>
    <@tools.placeMetadata path=path><#assign a=object/></@tools.placeMetadata>
    <#if user?has_content&&(a.adminIds)?has_content&&a.adminIds?seq_contains(user.id)>
        <#macro merge name value><#if !.vars[name]?has_content><@"<#assign ${name}=''>"?interpret /></#if><#if value?has_content><@"<#assign ${name}=${name}+'${value},'>"?interpret /></#if></#macro>
        <@cms.placeList path=path advanced=true pageIndex=pageNum pageSize=numPerPage>
            <#list page.list as a>
                <@merge 'userIds' a.userId!/>
            </#list>
            <@sys.user ids=userIds!><#assign userMap=map!/></@sys.user>
            <#list page.list as a>
                    <p>
                        <a href="${a.url}" target="_blank">${a.title}</a> ${a.clicks} [${(userMap[a.userId?string].nickname)!}]
                    <#if 2=a.status>
                        <a href="${site.dynamicPath}place/check?id=${a.id}&returnUrl=${site.dynamicPath}&_csrf=<@tools.csrfToken/>">Check</a>
                    <#elseif 1=a.status>
                        <a href="${site.dynamicPath}place/uncheck?id=${a.id}&returnUrl=${site.dynamicPath}&_csrf=<@tools.csrfToken/>">Uncheck</a>
                    </#if>
                        <a href="${site.dynamicPath}place/delete?id=${a.id}&returnUrl=${site.dynamicPath}&_csrf=<@tools.csrfToken/>">Delete</a>
                    </p>
            </#list>
        </@cms.placeList>
    </#if>
</#noparse>
            <#if !a.allowAnonymous>
<#noparse>
<#else>
please <a href="${site.dynamicPath}login.html">login</a>
</#if>
</#noparse>
</#if>
            </#if>
        <#else>
<@t.message 'verify.custom.contribute'/>
    </#if>
</#assign>
</@tools.placeMetadata>
<div class="pageFormContent" layoutH>
    <dl class="nowrap">
        <dt><@t.page 'place'/>:</dt>
        <dd>
            ${(path)!} ${(a.alias)!}
        </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>
</div>