<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="<@tools.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"/>
                <label><input type="checkbox" name="overwrite" class="form-check-input" checked="checked"><@t.page 'upload.overwrite'/></label>
            </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>
            <li><button type="submit" class="buttonActive" title="ctrl+s" onclick="return checkFileType();"><@t.page 'upload'/></button></li>
            <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>