<form action="cmsWebFile/doUpload?callbackType=closeCurrent&navTabId=cmsWebFile/list" method="post" autocomplete="off" 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"/>
                <label class="override hide"><input type="checkbox" name="override" checked="checked"><@t.page 'upload.override'/></label>
            </dd>
        </dl>
    </div>
    <div class="formBar">
        <ul>
            <li><button type="submit" class="buttonActive"><@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(){
    if($(this).length && $(this)[0].files){
        var fileNames = [];
        $.each($(this)[0].files, function(i, file) {
            fileNames.push(file.name);
        });
        $.ajax({
            url:'cmsWebFile/check',
            type: 'POST',
            async: false,
            data: {
                fileNames : fileNames,
                path : $("input[name=path]",$.pdialog.getCurrent()).val(),
                _csrf : $("input[name=_csrf]",$.pdialog.getCurrent()).val()
            },
            success: function (result) {
                if(true==result){
                    $('.override').show();
                } else {
                    $('.override').hide();
                }
            }
        });
    }
});
</script>