window.clickSubmit = function(e)
{
    let checkRelation = false;
    let taskID        = 0;
    let checkTasks    = '';
    $('[name^=status]').each(function()
    {
        taskID = $(this).closest('tr').find('[name^=id]').val();
        if($(this).val() == 'cancel' && tasks[taskID].status != 'cancel')
        {
            checkRelation = true;
            checkTasks   += taskID + ',';
        }
    })
    checkTasks = checkTasks.replace(/^,+|,+$/g, '');

    if(checkRelation && checkTasks)
    {
        let blockSubmit = true;
        $.get($.createLink('task', 'ajaxGetRelation', 'taskIdList=' + checkTasks), function(data)
        {
            if(data)
            {
                zui.Modal.confirm({message: unlinkRelationTip, actions: [{key: 'confirm', text: unlinkLang, btnType: 'primary', class: 'btn-wide'}, {key: 'cancel'}]}).then((res) =>
                {
                    if(res)
                    {
                        const link   = $('#batchEditForm > .panel-body form').attr('action');
                        let formData = $('#batchEditForm > .panel-body form').serialize();
                        let postData = {};
                        let params   = new URLSearchParams(formData);

                        for(const[key, value] of params.entries())
                        {
                            const decodedKey   = decodeURIComponent(key);
                            const decodedValue = decodeURIComponent(value);

                            if(!(decodedKey in postData)) postData[decodedKey] = [];
                            postData[decodedKey].push(decodedValue);
                        }

                        $.ajaxSubmit({url: link, data: postData});
                    }
                    else
                    {
                        return false;
                    }
                })
            }
            else
            {
                blockSubmit = false;
            }
        })

        if(blockSubmit) return false;
    }
}
