<script>
var filesSuffix=["html","htm","ftl","xml","text","txt","zip"];
function checkFileType(){
    $.each($('input[name=files]',$.pdialog.getCurrent())[0].files,function(index,file){
        var filenames=file.name.toLowerCase().split('.');
        if(-1 == $.inArray(filenames[filenames.length-1], filesSuffix)){
            alertMsg.error('<@t.page 'upload.template_warn'/>');
            return false;
        }
    });
    return true;
}
</script>
<form action="cmsTemplate/doUpload?callbackType=closeCurrent&navTabId=cmsTemplate/list" method="post" enctype="multipart/form-data" class="pageForm required-validate" onsubmit="return iframeCallback(this, dialogAjaxDone)">
    <input type="hidden" name="_csrf" value="<@_csrfToken admin=true/>"/>
    <div class="pageFormContent" layoutH>
        <dl class="nowrap">
            <dt><@t.page 'file'/>:</dt>
            <dd>
                <input type="hidden" name="path" value="${path!}"/>
                <input type="file" name="files" class="required" size="30" multiple="multiple"/>
            </dd>
        </dl>
        <dl class="nowrap zipencoding hide">
            <dt><@t.page 'file.encoding'/>:</dt>
            <dd>
                <label style="width:auto;"><input type="radio" name="encoding" value="utf-8" checked="checked"/><@t.page 'file.encoding.utf8'/></label>
                <br/>
                <label style="width:auto;"><input type="radio" name="encoding" value="gbk"/><@t.page 'file.encoding.gbk'/></label>
            </dd>
        </dl>
    </div>
    <div class="formBar">
        <ul>
        <#if site.parentId?has_content>
            <li><button type="button" class="buttonDisabled"><@t.page 'site.parent_maintain'/></button></li>
        <#else>
            <li><button type="submit" class="buttonActive" onclick="return checkFileType();"><@t.page 'upload'/></button></li>
        </#if>
            <li><button type="button" class="button close"><@t.page 'button.close'/></button></li>
        </ul>
    </div>
</form>
<script>
$(".pageFormContent",$.pdialog.getCurrent()).on("change","input[type=file]",function(){
    $('.zipencoding',$.pdialog.getCurrent()).hide();
    if($(this).length && $(this)[0].files){
        $.each($(this)[0].files, function(i, file) {
            var filenames=file.name.toLowerCase().split('.');
            if("zip" == filenames[filenames.length-1]){
                $('.zipencoding',$.pdialog.getCurrent()).show();
            }
        });
    }
});
</script>