window.loadHost = function(obj)
{
    const $tr = $(obj.target).closest('tr');
    $.getJSON($.createLink('host', 'ajaxGetByService', "serviceID=" + $tr.find('[name^=service]').val()), function(data)
    {
        const existsVal = $tr.find('[name^="hosts"]').val();
        const removeVal = $tr.find('[name^="remove"]').val();

        const $existsPicker = $tr.find('[name^="hosts"]').zui('Picker');
        const $removePicker = $tr.find('[name^="remove"]').zui('Picker');

        $existsPicker.render({items: data});
        $removePicker.render({items: data});

        $existsPicker.$.setValue(existsVal);
        $removePicker.$.setValue(removeVal);
    })
}

window.renderRowData = function($row, index, scope)
{
    if(typeof scope == 'undefined' || !scope) return;

    setTimeout(function()
    {
        const hosts = [];
        for(let hostID in scope.hostPairs) hosts.push({text: scope.hostPairs[hostID], value: hostID});

        const $hosts  = $row.find('.form-batch-control > [data-name=hosts]').zui('Picker');
        const $remove = $row.find('.form-batch-control > [data-name=remove]').zui('Picker');
        $hosts.render({items: hosts});
        $remove.render({items: hosts});
        $hosts.$.setValue(scope.hosts.split(','));
        $remove.$.setValue(scope.remove.split(','));
    }, 10)
}
