<commit_before>/**
 * @param {Object} $ - Global jQuery object
 * @param {Object} bolt - The Bolt module
 */
(function ($, bolt) {
    'use strict';

    /**
     * BUIC filebrowser widget.
     *
     * @license http://opensource.org/licenses/mit-license.php MIT License
     * @author rarila
     *
     * @class buicBrowser
     * @memberOf jQuery.widget.bolt
     */
    $.widget('bolt.buicBrowser', /** @lends jQuery.widget.bolt.buicBrowser.prototype */ {
        /**
         * Event reporting that a file was selected.
         *
         * @event jQuery.widget.bolt.buicBrowser#buicbrowserselected
         * @property {string} path - The path to the selected file
         */

        /**
         * Default options.
         *
         * @property {string} [url] - URL to browse
         */
        options: {
            namespace: '',
            path: '',
            multiselect: false
        },

        /**
         * The constructor of the filebrowser widget.
         *
         * @private
         */
        _create: function () {

            /**
             * The current url.
             *
             * @type {string}
             * @name _url
             * @memberOf jQuery.widget.bolt.buicBrowser.prototype
             * @private
             */
            this._url = bolt.conf('paths.async') + 'browse/' + this.options.namespace +
                            (this.options.path ? '/' + this.options.path : '');

            this._on({
                'click': function() {
                    this._browse();
                }
            });
        },

        /**
         * Browser directory on server.
         *
         * @private
         * @fires jQuery.widget.bolt.buicBrowser#buicbrowserselected
         */
        _browse: function () {
            var self = this,
                data = {},
                files = [],
                allChecked = false;

            $('body').buicModal({
                size: 'large',
                remote: {
                    url:  self._url,
                    data: data
                },
                loaded: function (evt, modal) {
                    // Set data structures
                    modal.body.find('.entry').each(function () {
                        var tr = $(this).closest('tr'),
                            name = $(this).text().trim(),
                            ext = name.match(/\.(.+?[^/])$/);

                        $(tr)
                            .attr('data-bolt-browse-name', name)
                            .attr('data-bolt-browse-ext', ext ? ext[1] : '');
                    });

                    // Set up event handler
                    modal.header
                        .on('click.bolt', '[data-fbrowser-chdir]', function (evt) {
                            evt.preventDefault();
                            self._url = $(this).data('fbrowser-chdir');
                            self._browse();
                        });
                    modal.body
                        .on('click.bolt', '[data-fbrowser-chdir]', function (evt) {
                            evt.preventDefault();
                            self._url = $(this).data('fbrowser-chdir');
                            self._browse();
                        })
                        .on('click.bolt', '[data-fbrowser-select]', function (evt) {
                            evt.preventDefault();
                            self._trigger('selected', null, {path: $(this).data('fbrowser-select')});
                            modal.close();
                        })
                        .on('click.bolt', '[aria-pressed]', function (evt) {
                            var activated = $(this).attr('aria-pressed') === 'false',
                                type = this.className.replace('toogle-', '');

                            $(this).attr('aria-pressed', activated ? 'true' : 'false');
                            modal.body.find('tbody.' + type).toggleClass('hidden', !activated);

                            if (evt.clientX > 0) {
                                this.blur();
                            }
                        })
                        .on('change', 'select[name="ext"]', function () {
                            self._filter(modal);
                        })
                        .keyup('input[name="filter"]', function () {
                            self._filter(modal);
                        })
                        .on('change', '[data-fbrowser-check]', function () {
                            var fileIndex = files.indexOf($(this).data('fbrowser-check'));
                            if (fileIndex > -1) {
                                files.splice(fileIndex, 1);
                            } else {
                                files.push($(this).data('fbrowser-check'));
                            }
                            console.log(files);
                        });
                    modal.footer
                        .on('click.bolt', '.toggle-all', function (evt) {
                            console.log('test');
                            evt.preventDefault();
                            modal.body.find('[data-fbrowser-check]').each(function() {
                                $(this).prop('checked', 'checked');
                                //files.push($(this).data('fbrowser-select'));
                            });
                        })
                        .on('click.bolt', '[data-add-checked]', function (evt) {
                            evt.preventDefault();
                        });
                }
            });
        },<commit_msg>Select all now works and add button reacts<commit_after>/**
 * @param {Object} $ - Global jQuery object
 * @param {Object} bolt - The Bolt module
 */
(function ($, bolt) {
    'use strict';

    /**
     * BUIC filebrowser widget.
     *
     * @license http://opensource.org/licenses/mit-license.php MIT License
     * @author rarila
     *
     * @class buicBrowser
     * @memberOf jQuery.widget.bolt
     */
    $.widget('bolt.buicBrowser', /** @lends jQuery.widget.bolt.buicBrowser.prototype */ {
        /**
         * Event reporting that a file was selected.
         *
         * @event jQuery.widget.bolt.buicBrowser#buicbrowserselected
         * @property {string} path - The path to the selected file
         */

        /**
         * Default options.
         *
         * @property {string} [url] - URL to browse
         */
        options: {
            namespace: '',
            path: '',
            multiselect: false
        },

        /**
         * The constructor of the filebrowser widget.
         *
         * @private
         */
        _create: function () {

            /**
             * The current url.
             *
             * @type {string}
             * @name _url
             * @memberOf jQuery.widget.bolt.buicBrowser.prototype
             * @private
             */
            this._url = bolt.conf('paths.async') + 'browse/' + this.options.namespace +
                            (this.options.path ? '/' + this.options.path : '');

            this._on({
                'click': function() {
                    this._browse();
                }
            });
        },

        /**
         * Browser directory on server.
         *
         * @private
         * @fires jQuery.widget.bolt.buicBrowser#buicbrowserselected
         */
        _browse: function () {
            var self = this,
                data = {},
                files = [],
                allChecked = false;

            $('body').buicModal({
                size: 'large',
                remote: {
                    url:  self._url,
                    data: data
                },
                loaded: function (evt, modal) {
                    
                    //Find the add selected button
                    var addSelectedBtn = $('#addMultipleFiles');
                    
                    // Set data structures
                    modal.body.find('.entry').each(function () {
                        var tr = $(this).closest('tr'),
                            name = $(this).text().trim(),
                            ext = name.match(/\.(.+?[^/])$/);

                        $(tr)
                            .attr('data-bolt-browse-name', name)
                            .attr('data-bolt-browse-ext', ext ? ext[1] : '');
                    });

                    // Set up event handler
                    modal.header
                        .on('click.bolt', '[data-fbrowser-chdir]', function (evt) {
                            evt.preventDefault();
                            self._url = $(this).data('fbrowser-chdir');
                            self._browse();
                        });
                    modal.body
                        .on('click.bolt', '[data-fbrowser-chdir]', function (evt) {
                            evt.preventDefault();
                            self._url = $(this).data('fbrowser-chdir');
                            self._browse();
                        })
                        .on('click.bolt', '[data-fbrowser-select]', function (evt) {
                            evt.preventDefault();
                            self._trigger('selected', null, {path: $(this).data('fbrowser-select')});
                            modal.close();
                        })
                        .on('click.bolt', '[aria-pressed]', function (evt) {
                            var activated = $(this).attr('aria-pressed') === 'false',
                                type = this.className.replace('toogle-', '');

                            $(this).attr('aria-pressed', activated ? 'true' : 'false');
                            modal.body.find('tbody.' + type).toggleClass('hidden', !activated);

                            if (evt.clientX > 0) {
                                this.blur();
                            }
                        })
                        .on('change', 'select[name="ext"]', function () {
                            self._filter(modal);
                        })
                        .keyup('input[name="filter"]', function () {
                            self._filter(modal);
                        })
                        .on('change', '[data-fbrowser-check]', function () {
                            var fileIndex = files.indexOf($(this).data('fbrowser-check'));
                            if (fileIndex > -1) {
                                files.splice(fileIndex, 1);
								allChecked = false;
								if (files.length === 0) {
                                    addSelectedBtn.removeClass('disabled');
								}
                            } else {
                                files.push($(this).data('fbrowser-check'));
								addSelectedBtn.removeClass('disabled');
                            }
                        });
                    modal.footer
                        .on('click.bolt', '.toggle-all', function (evt) {
                            evt.preventDefault();
							if (!allChecked) {
								modal.body.find('[data-fbrowser-check]').each(function() {
									$(this).prop('checked', true);
									files.push($(this).data('fbrowser-check'));
								});
								allChecked = true;
								addSelectedBtn.removeClass('disabled');
							} else {
								modal.body.find('[data-fbrowser-check]').each(function() {
									$(this).prop('checked', false);
								});
								files.length = 0;
								allChecked = false;
								addSelectedBtn.addClass('disabled');
							}
                        })
                        .on('click.bolt', '[data-add-checked]', function (evt) {
                            evt.preventDefault();
                        });
                }
            });
        },
{'fraction_non_alphanumeric': 0.13519656536745517, 'fraction_numerical': 0.0008418217021634817, 'mean_word_length': 0.9568440125185307, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1771842', 'n_tokens_mistral': 3037, 'n_tokens_neox': 2764, 'n_words': 488}