<commit_before>{% block artists_widget %}
    {% spaceless %}
        {{ block('collection_widget') }}
        
        <button class="btn btn-success" id="addArtist" class="add_tag_link">{{ 'Add artist'|trans }}</button>
        <script>
            var SelectSmartOptions = function (selector) {

                // @TODO check if element is only 1
                this.element = jQuery(selector);

                this.getElement = function () {
                    return this.element;
                };

                this.setUrl = function (url) {
                    this.url = url;
                },
                this.getUrl = function() {
                    return this.url;
                };
            };
            
            /**
             * 
             * @param {SelectSmartOptions} options
             * @returns {undefined}
             */
            var SelectSmartRemote = function(options) {
                options.getElement().select2({
                    ajax: {
                        url: options.getUrl(),
                        dataType: "json",
                        processResults: function(data) {
                            
                            console.log(data);
                            
                            var more = true;
                            var totalItems = data.pagination.currentPage * data.pagination.itemNumberPerPage;
                            
                            if (totalItems >= data.pagination.totalItemCount) {
                                more = false;
                            }
                            
                            var returnData = {
                                results: [],
                                pagination: {
                                    more: more
                                }
                            };

                            var i = 0;
                            for (i = 0; i < data.items.length; i++) {
                                returnData.results.push({
                                    id: data.items[i].id,
                                    text: data.items[i].name
                                });
                            }

                            return returnData;
                        },
                        data: function (params) {
                            var filters = [];
                            if (params.term) {
                                filters = [
                                    {
                                        value: params.term,
                                        operator: 'like',
                                        field: 'name'
                                    }
                                ];
                            }

                            return {
                                filters: filters,
                                page: params.page,
                                perPage: 10
                            };
                        }
                    },
                    escapeMarkup: function(e) { return _.escape(e); }
                });
            };
            
            
            function artistSelect(element) {
                var $deleteElement = jQuery('<button class="btn btn-danger">{{ 'delete'|trans }}</button>');
                $deleteElement.click(function() {
                    jQuery(this).parents('.form-group:first').remove();
                });
                $deleteElement.insertAfter(jQuery(element));
                
                
                var options = new SelectSmartOptions(element);
                options.setUrl('/proxy/api/artists?groups%5B0%5D=Acl&groups%5B1%5D=List');
            
               new SelectSmartRemote(options);
            };
            
            jQuery(document).ready(function () {
                
                jQuery('select[name^="lyric\["]').each(function(key, el) { artistSelect(el); });
                
                var $addTagLink = $('#addArtist');
                var $collectionHolder;
                
                // Get the ul that holds the collection of artsts
                $collectionHolder = $('#lyric_artists');

                // count the current form inputs we have (e.g. 2), use that as the new
                // index when inserting a new item (e.g. 2)
                $collectionHolder.data('index', $collectionHolder.find(':input').length);

                $addTagLink.on('click', function (e) {
                    // prevent the link from creating a "#" on the URL
                    e.preventDefault();

                    // add a new tag form (see next code block)
                    addTagForm($collectionHolder);
                });
            });

            function addTagForm($collectionHolder) {
                // Get the data-prototype explained earlier
                var prototype = $collectionHolder.attr('data-prototype');

                // get the new index
                var index = $collectionHolder.data('index');

                // Replace '__name__' in the prototype's HTML to
                // instead be a number based on how many items we have
                var newForm = prototype.replace(/__name__/g, index);
                var $newForm = jQuery(newForm);

                // increase the index with one for the next item
                $collectionHolder.data('index', index + 1);

                // Display the form in the page in an li, before the "Add a tag" link li
                $('#addArtist').before($newForm);
                artistSelect($newForm.find('select'));
            }
        </script>
        
    {% endspaceless %}
{% endblock %}
<commit_msg>removed debug log<commit_after>{% block artists_widget %}
    {% spaceless %}
        {{ block('collection_widget') }}
        
        <button class="btn btn-success" id="addArtist" class="add_tag_link">{{ 'Add artist'|trans }}</button>
        <script>
            var SelectSmartOptions = function (selector) {

                // @TODO check if element is only 1
                this.element = jQuery(selector);

                this.getElement = function () {
                    return this.element;
                };

                this.setUrl = function (url) {
                    this.url = url;
                },
                this.getUrl = function() {
                    return this.url;
                };
            };
            
            /**
             * 
             * @param {SelectSmartOptions} options
             * @returns {undefined}
             */
            var SelectSmartRemote = function(options) {
                options.getElement().select2({
                    ajax: {
                        url: options.getUrl(),
                        dataType: "json",
                        processResults: function(data) {
                            var more = true;
                            var totalItems = data.pagination.currentPage * data.pagination.itemNumberPerPage;
                            
                            if (totalItems >= data.pagination.totalItemCount) {
                                more = false;
                            }
                            
                            var returnData = {
                                results: [],
                                pagination: {
                                    more: more
                                }
                            };

                            var i = 0;
                            for (i = 0; i < data.items.length; i++) {
                                returnData.results.push({
                                    id: data.items[i].id,
                                    text: data.items[i].name
                                });
                            }

                            return returnData;
                        },
                        data: function (params) {
                            var filters = [];
                            if (params.term) {
                                filters = [
                                    {
                                        value: params.term,
                                        operator: 'like',
                                        field: 'name'
                                    }
                                ];
                            }

                            return {
                                filters: filters,
                                page: params.page,
                                perPage: 10
                            };
                        }
                    },
                    escapeMarkup: function(e) { return _.escape(e); }
                });
            };
            
            
            function artistSelect(element) {
                var $deleteElement = jQuery('<button class="btn btn-danger">{{ 'delete'|trans }}</button>');
                $deleteElement.click(function() {
                    jQuery(this).parents('.form-group:first').remove();
                });
                $deleteElement.insertAfter(jQuery(element));
                
                
                var options = new SelectSmartOptions(element);
                options.setUrl('/proxy/api/artists?groups%5B0%5D=Acl&groups%5B1%5D=List');
            
               new SelectSmartRemote(options);
            };
            
            jQuery(document).ready(function () {
                
                jQuery('select[name^="lyric\["]').each(function(key, el) { artistSelect(el); });
                
                var $addTagLink = $('#addArtist');
                var $collectionHolder;
                
                // Get the ul that holds the collection of artsts
                $collectionHolder = $('#lyric_artists');

                // count the current form inputs we have (e.g. 2), use that as the new
                // index when inserting a new item (e.g. 2)
                $collectionHolder.data('index', $collectionHolder.find(':input').length);

                $addTagLink.on('click', function (e) {
                    // prevent the link from creating a "#" on the URL
                    e.preventDefault();

                    // add a new tag form (see next code block)
                    addTagForm($collectionHolder);
                });
            });

            function addTagForm($collectionHolder) {
                // Get the data-prototype explained earlier
                var prototype = $collectionHolder.attr('data-prototype');

                // get the new index
                var index = $collectionHolder.data('index');

                // Replace '__name__' in the prototype's HTML to
                // instead be a number based on how many items we have
                var newForm = prototype.replace(/__name__/g, index);
                var $newForm = jQuery(newForm);

                // increase the index with one for the next item
                $collectionHolder.data('index', index + 1);

                // Display the form in the page in an li, before the "Add a tag" link li
                $('#addArtist').before($newForm);
                artistSelect($newForm.find('select'));
            }
        </script>
        
    {% endspaceless %}
{% endblock %}

{'fraction_non_alphanumeric': 0.09421879112202824, 'fraction_numerical': 0.002631809807877884, 'mean_word_length': 0.8636586562040216, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2653741', 'n_tokens_mistral': 2542, 'n_tokens_neox': 2320, 'n_words': 555}