<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-process-save" action="/activiti/process/save" method="post">
        <div class="form-group">
            <label class="col-sm-3 control-label">导入流程：</label>
            <div class="col-sm-8">
                <input class="form-control" id="file" name="file" type="file">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">类别：</label>
            <div class="col-sm-8">
                <input class="form-control" id="category" name="category" type="input">
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    var prefix = ctx + "activiti/process";
    function submitHandler() {
        // $('#form-process-save').submit();
        // $.operate.save(prefix + "/save", $('#form-process-save').serialize());
        uploadFile();
    }
    function uploadFile() {
        var formData = new FormData();
        formData.append('file', $('#file')[0].files[0]);
        formData.append('category', document.getElementById("category").value);
        $.ajax({
            url: prefix + "/save",
            type: 'POST',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
            dataType: "json",
            beforeSend: function () {
                uploading = true;
            },
            success: function (res) {
                console.log(res)
                uploading = false;
                if (res.code==0){
                    $.modal.msgSuccess(res.msg);
                    $.modal.close();
                    return;
                }
                $.modal.msgError(res.msg);
            }
        });
    }
</script>
</body>
</html>
