window.insertListToPerf = function()
{
    const dtable      = zui.DTable.query($('#stories'));
    const checkedList = dtable.$.getChecks();
    if(!checkedList.length) return;

    const url      = $.createLink('perfproject', 'create', `analysisID=${analysisID}`);
    const formData = new FormData();
    formData.append('source', 1);
    formData.append('name', perfTableList['productStory'] + dataAnalysisLang);
    formData.append('acl', 'private');
    formData.append('table', tableName);
    formData.append('tabletype', 'table');
    formData.append('datatype', 'view');
    formData.append('whitelist', '');
    formData.append('sourcetype', 'select');
    formData.append('idList', checkedList.join(','));

    $.post(url, formData, function(resp)
    {
        resp = JSON.parse(resp);
        if(resp.result == 'success')
        {
            zui.Modal.hide();
            const url = $.createLink('perfproject', 'analysis', 'analysisID=' + analysisID);
            analysisID != 0 ? location.href = url : loadPage($.createLink('perfproject', 'firstanalysis', 'projectID=' + resp.projectID));
        }
    });
}

window.changeListType = function(event)
{
    const data = tableList.filter(item => item.key == $(event).val())[0];
    data.params = `${data.params}&blockID=${analysisID}`;
    zui.Modal.hide();
    zui.Modal.open({
        size: 'lg',
        url: $.createLink(data.module, data.method, data.params)
    });
}

window.setShowGrades = function()
{
    const showGrades = $('[name^=showGrades]').zui('picker').$.state.value;
    if(oldShowGrades == showGrades) return;

    const module = tab == 'product' || from == 'doc' || from == 'perf' ? storyType : tab;
    const link   = $.createLink('product', 'ajaxSetShowGrades', 'module=' + module + '&showGrades=' + showGrades);
    $.get(link, function()
    {
        if(from == 'doc' || from == 'perf')
        {
            const currentLink = $.createLink('product', 'browse', `productID=${productID}&branch=${branch}&browseType=${browseType}&param=${param}&storyType=${storyType}&orderBy=${orderBy}&recTotal=${recTotal}&recPerPage=${recPerPage}&pageID=${pageID}&projectID=${projectID}&from=${from}&blockID=${blockID}`);
            loadModal(currentLink);
        }
        else
        {
            loadCurrentPage();
        }
    });
}
