<commit_before>$(function()
{
    
    var availableBlocks;
    var ajaxContext = 'Chamilo\\Core\\Home\\Ajax';
    var ajaxUri = getPath('WEB_PATH') + 'index.php';
    var translationContext = 'Chamilo\\Core\\Home';
    
    $(document).ready(function()
    {
        bindPortalActions();
        makeColumnsResizable();
        makeBlocksSortable();
        makeTabsSortable();
    });
    
    function bindPortalActions()
    {
        $(document).on('click', "a.portal-add-block:not(.dropdown-toggle)", displayBlockScreen);
        $(document).on('click', "a.portal-package-hide", hideBlockScreen);
        $(document).on('click', "a.portal-add-column", addColumn);
        $(document).on('click', "a.portal-add-tab", addTab);
        $(document).on('click', ".portal-package-blocks a", addBlock);
        
        $(document).on('click', ".portal-action-block-delete", deleteBlock);
        $(document).on('click', ".portal-action-column-delete", deleteColumn);
        $(document).on('click', ".portal-action-tab-delete", deleteTab);
        $(document).on('click', ".portal-action-block-show", showBlock);
        $(document).on('click', ".portal-action-block-hide", hideBlock);
        $(document).on('click', ".portal-action-block-configure", configureBlock);
        $(document).on('click', ".portal-block-form .btn[name=submit]", saveBlockConfiguration);
        $(document).on('click', ".portal-block-form .btn[name=cancel]", cancelBlockConfiguration);
        
        $(document).on('input', "#portal-package-name", filterComponents);
        $(document).on('change', "#portal-package-context", filterComponents);
        
        $(document).on('dblclick', ".portal-nav-tabs .portal-action-tab-title", displayTabTitlePanel);
        $(document).on('click', ".portal-tab-panel .portal-tab-panel-hide", hideTabTitlePanel);
        $(document).on('click', ".portal-tab-panel .portal-tab-title-save", saveTabTitle);
    }
    
    function getAvailableBlocks()
    {
        var parameters = {
            'application' : ajaxContext,
            'go' : 'block_list'
        };
        
        var response = $.ajax({
            type : "POST",
            url : ajaxUri,
            data : parameters,
            async : false
        }).success(function(json)
        {
            availableBlocks = json.properties.blocks;
            renderAvailablePackages();
            renderAvailableComponents();
        });
    }
    
    function displayBlockScreen(e, ui)
    {
        e.preventDefault();

        getAvailableBlocks();

        $(".portal-package-container").removeClass('hidden').addClass('show');
    }
    
    function hideBlockScreen(e, ui)
    {
        e.preventDefault();
        $(".portal-package-container").removeClass('show').addClass('hidden');
    }
    
    function renderAvailablePackages()
    {
        var packagesList = $("#portal-package-context");
        var ordering = [];
        
        for ( var i in availableBlocks)
        {
            ordering[i] = availableBlocks[i].name;
        }
        
        ordering = asort(ordering);
        
        for ( var i in ordering)
        {
            var availablePackage = $('<option></option>');
            availablePackage.attr('value', i);
            
            packageImage = $('<img />');
            packageImage.prop('src', availableBlocks[i].image);
            availablePackage.append(packageImage);
            
            availablePackage.append(availableBlocks[i].name);
            
            packagesList.append(availablePackage);
        }
    }
    
    function renderAvailableComponents()
    {
        var componentsList = $(".portal-package-blocks");
        
        componentsList.empty();
        
        for ( var i in availableBlocks)
        {
            for ( var j in availableBlocks[i].components)
            {
                var blockName = availableBlocks[i].components[j].name;
                
                var column = $('<div />');
                column.addClass('col-xs-12 col-sm-4 col-md-3 col-lg-2');
                
                var availableComponent = $('<a />');
                column.append(availableComponent);
                
                availableComponent.addClass('btn btn-default btn-block');
                availableComponent.css('cursor', 'pointer');
                availableComponent.attr('data-block', availableBlocks[i].components[j].id);
                availableComponent.prop('title', availableBlocks[i].components[j].name);
                
                componentImage = $('<img />');
                componentImage.css('width', '16px');
                componentImage.css('height', '16px');
                componentImage.prop('src', availableBlocks[i].components[j].image);
                availableComponent.append(componentImage);
                
                availableComponent.append(availableBlocks[i].components[j].name);
                
                componentsList.append(column);
            }
        }
    }
    
    function addBlock(e, ui)
    {
        e.preventDefault();
        
        var column, columnId, order, isEmpty;
        
        column = $(".portal-tab:visible .portal-column:last");
        columnId = column.data('element-id');
        isEmpty = $(".portal-column-empty:visible", column).length != 0;
        
        var parameters = {
            'application' : ajaxContext,
            'go' : 'BlockAdd',
            'block' : $(this).data('block'),
            'column' : columnId
        };
        
        var response = $.ajax({
            type : "POST",
            url : ajaxUri,
            data : parameters
        }).success(
                function(json)
                {
                    if (json.result_code == 200)
                    {
                        column.prepend(json.properties.block);
                        $('.portal-column[data-element-id="' + columnId + '"] .portal-column-empty')
                                .removeClass('show').addClass('hidden');
                    }
                });
    }
    
    function addColumn(e, ui)
    {
        e.preventDefault();
        
        var tab, tabId;
        
        tab = $(".portal-tab:visible");
        tabId = tab.data('element-id');
        
        var parameters = {
            'application' : ajaxContext,
            'go' : 'ColumnAdd',
            'tab' : tabId
        };
        
        var response = $.ajax({<commit_msg>Fixed a home javascript bug<commit_after>$(function()
{
    
    var availableBlocks;
    var ajaxContext = 'Chamilo\\Core\\Home\\Ajax';
    var ajaxUri = getPath('WEB_PATH') + 'index.php';
    var translationContext = 'Chamilo\\Core\\Home';
    
    $(document).ready(function()
    {
        bindPortalActions();
        makeColumnsResizable();
        makeBlocksSortable();
        makeTabsSortable();
    });
    
    function bindPortalActions()
    {
        $(document).on('click', "a.portal-add-block:not(.dropdown-toggle)", displayBlockScreen);
        $(document).on('click', "a.portal-package-hide", hideBlockScreen);
        $(document).on('click', "a.portal-add-column", addColumn);
        $(document).on('click', "a.portal-add-tab", addTab);
        $(document).on('click', ".portal-package-blocks a", addBlock);
        
        $(document).on('click', ".portal-action-block-delete", deleteBlock);
        $(document).on('click', ".portal-action-column-delete", deleteColumn);
        $(document).on('click', ".portal-action-tab-delete", deleteTab);
        $(document).on('click', ".portal-action-block-show", showBlock);
        $(document).on('click', ".portal-action-block-hide", hideBlock);
        $(document).on('click', ".portal-action-block-configure", configureBlock);
        $(document).on('click', ".portal-block-form .btn[name=submit]", saveBlockConfiguration);
        $(document).on('click', ".portal-block-form .btn[name=cancel]", cancelBlockConfiguration);
        
        $(document).on('input', "#portal-package-name", filterComponents);
        $(document).on('change', "#portal-package-context", filterComponents);
        
        $(document).on('dblclick', ".portal-nav-tabs .portal-action-tab-title", displayTabTitlePanel);
        $(document).on('click', ".portal-tab-panel .portal-tab-panel-hide", hideTabTitlePanel);
        $(document).on('click', ".portal-tab-panel .portal-tab-title-save", saveTabTitle);
    }
    
    function getAvailableBlocks()
    {
        var parameters = {
            'application' : ajaxContext,
            'go' : 'block_list'
        };
        
        var response = $.ajax({
            type : "POST",
            url : ajaxUri,
            data : parameters,
            async : false
        }).success(function(json)
        {
            availableBlocks = json.properties.blocks;
            renderAvailablePackages();
            renderAvailableComponents();
        });
    }
    
    function displayBlockScreen(e, ui)
    {
        e.preventDefault();

        getAvailableBlocks();

        $(".portal-package-container").removeClass('hidden').addClass('show');
    }
    
    function hideBlockScreen(e, ui)
    {
        e.preventDefault();
        $(".portal-package-container").removeClass('show').addClass('hidden');
    }
    
    function renderAvailablePackages()
    {
        var packagesList = $("#portal-package-context");
        var ordering = [];
        
        for ( var i in availableBlocks)
        {
            ordering[i] = availableBlocks[i].name;
        }
        
        ordering = asort(ordering);
        
        for ( var i in ordering)
        {
            var availablePackage = $('<option></option>');
            availablePackage.attr('value', i);
            
            packageImage = $('<img />');
            packageImage.prop('src', availableBlocks[i].image);
            availablePackage.append(packageImage);
            
            availablePackage.append(availableBlocks[i].name);
            
            packagesList.append(availablePackage);
        }
    }
    
    function renderAvailableComponents()
    {
        var componentsList = $(".portal-package-blocks");
        
        componentsList.empty();
        
        for ( var i in availableBlocks)
        {
            for ( var j in availableBlocks[i].components)
            {
                var blockName = availableBlocks[i].components[j].name;
                
                var column = $('<div />');
                column.addClass('col-xs-12 col-sm-4 col-md-3 col-lg-2');
                
                var availableComponent = $('<a />');
                column.append(availableComponent);
                
                availableComponent.addClass('btn btn-default btn-block');
                availableComponent.css('cursor', 'pointer');
                availableComponent.attr('data-block', availableBlocks[i].components[j].id);
                availableComponent.prop('title', availableBlocks[i].components[j].name);
                
                componentImage = $('<img />');
                componentImage.css('width', '16px');
                componentImage.css('height', '16px');
                componentImage.prop('src', availableBlocks[i].components[j].image);
                availableComponent.append(componentImage);
                
                availableComponent.append(availableBlocks[i].components[j].name);
                
                componentsList.append(column);
            }
        }
    }
    
    function addBlock(e, ui)
    {
        e.preventDefault();
        
        var column, columnId, order, isEmpty;
        
        column = $(".portal-tab:visible .portal-column:last");
        columnId = column.data('element-id');
        isEmpty = $(".portal-column-empty:visible", column).length != 0;
        
        var parameters = {
            'application' : ajaxContext,
            'go' : 'BlockAdd',
            'block' : $(this).data('block'),
            'column' : columnId
        };
        
        var response = $.ajax({
            type : "POST",
            url : ajaxUri,
            data : parameters
        }).success(
                function(json)
                {
                    if (json.result_code == 200)
                    {
                        column.prepend(json.properties.block);
                        $('.portal-column[data-element-id="' + columnId + '"] .portal-column-empty')
                                .removeClass('show').addClass('hidden');

                        getAvailableBlocks();
                    }
                });
    }
    
    function addColumn(e, ui)
    {
        e.preventDefault();
        
        var tab, tabId;
        
        tab = $(".portal-tab:visible");
        tabId = tab.data('element-id');
        
        var parameters = {
            'application' : ajaxContext,
            'go' : 'ColumnAdd',
            'tab' : tabId
        };
        
        var response = $.ajax({
{'fraction_non_alphanumeric': 0.14747288252942534, 'fraction_numerical': 0.0020001538579890762, 'mean_word_length': 1.7583280288563548, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2648202', 'n_tokens_mistral': 3389, 'n_tokens_neox': 3370, 'n_words': 538}