<commit_before>define(["github/adioo/bind/v0.2.0/bind", "github/adioo/events/v0.1.0/events", "/jquery.js"], function(Bind, Events) {

    function List(module) {

        var self;
        var config;
        var container;
        var template;

        function processConfig(config) {
            config.template.binds = config.template.binds || [];

            config.options = config.options || {};

            config.options.sort = config.options.sort || {};

            var optClasses = config.options.classes || {}
            optClasses.item = optClasses.item || "item";
            optClasses.selected = optClasses.selected || "selected";
            config.options.classes = optClasses;

            return config;
        }

        function init(conf) {

            // initialize the globals
            self = this;
            config = processConfig(conf);
            if (config.container) {
                container = $(config.container, module.dom);
            } else {
                container = module.dom;
            }
            template = $(config.template.value, module.dom);

            // **************************************
            // generate general binds from the config
            var binds = [];

            for (var i in config.controls) {
                switch (i) {
                    case "add":
                        binds.push({
                            target: config.controls[i],
                            context: ".controls",
                            on: [{
                                name: "click",
                                emit: "requestNewItem"
                            }]
                        });
                        break;
                    case "delete":
                        binds.push({
                            target: config.controls[i],
                            context: ".controls",
                            on: [{
                                name: "click",
                                handler: "removeSelected"
                            }]
                        });
                        break;
                }
            }

            // run the internal binds
            for (var i in binds) {
                Bind.call(self, binds[i]);
            }

            // run the binds
            for (var i in config.binds) {
                Bind.call(self, config.binds[i]);
            }

            Events.call(self, config);

            if (config.options.autofetch) {
                self.read({}, { sort: config.options.sort });
            }
        }

        function render(item) {
            switch (config.template.type) {
                case "selector":
                    renderSelector.call(self, item);
                case "html":
                    // TODO
                case "url":
                    // TODO
            }
        }

        function renderSelector(item) {
            var newItem = $(template).clone();
            newItem
                .removeClass("template")
                .addClass(config.options.classes.item)
                .appendTo(container)
                .show();

            for (var i in config.template.binds) {
                var bindObj = config.template.binds[i];
                bindObj.context = newItem;
                Bind.call(self, bindObj, item);
            }
        }

        function clearList() {
            $("." + config.options.classes.item, container).remove();
        }

        // ********************************
        // Public functions ***************
        // ********************************

        function read(filter, options) {

            clearList();

            var data = {
                filter: filter,
                options: options
            }

            self.link(config.crud.read, { data: data }, function(err, data) {

                if (err) { return; }

                if (!data || !(data.length > 0)) {
                    return;
                }

                for (var i in data) {
                    render.call(self, data[i]);
                }

                var autoselect = config.options.autoselect;
                switch (autoselect) {
                    case "first":
                        selectItem(data[0]);
                        break;
                    case "last":
                        selectItem(data[data.length - 1]);
                        break;
                    default:
                        if (typeof autoselect === "number") {
                            selectItem(data[autoselect]);
                        }
                }
            });
        }

        function createItem(itemData) {
            self.link(config.crud.create, { data: itemData }, function(err, data) {
                if (err) { return; }
                render.call(self, data);
            });
        }

        function removeItem(itemData) {
            self.link(config.crud.delete, { data: { id: itemData.id } }, function(err, data) {
                if (err) { return; }
                $("#" + itemData.id).remove();
            });
        }

        function removeSelected() {
            var ids = [];
            var selectedClass = config.options.classes.selected;
            $("." + selectedClass, container).each(function() {
                ids.push($(this).attr("id"));
            });

            self.link(config.crud.delete, { data: { ids: ids } }, function(err, data) {
                if (err) { return; }
                $("." + selectedClass, container).remove();
            });
        }

        function selectItem(dataItem) {

            if (!dataItem) {
                return;
            }

            var selectedClass = config.options.classes.selected;

            switch (config.options.selection) {

                case "single":<commit_msg>Added confirmation event option on delete to trigger a possible modal dialor or similar<commit_after>define(["github/adioo/bind/v0.2.0/bind", "github/adioo/events/v0.1.0/events", "/jquery.js"], function(Bind, Events) {

    function List(module) {

        var self;
        var config;
        var container;
        var template;

        function processConfig(config) {
            config.template.binds = config.template.binds || [];

            config.options = config.options || {};

            config.options.sort = config.options.sort || {};

            var optClasses = config.options.classes || {}
            optClasses.item = optClasses.item || "item";
            optClasses.selected = optClasses.selected || "selected";
            config.options.classes = optClasses;

            return config;
        }

        function init(conf) {

            // initialize the globals
            self = this;
            config = processConfig(conf);
            if (config.container) {
                container = $(config.container, module.dom);
            } else {
                container = module.dom;
            }
            template = $(config.template.value, module.dom);

            // **************************************
            // generate general binds from the config
            var binds = [];

            for (var i in config.controls) {
                switch (i) {
                    case "add":
                        binds.push({
                            target: config.controls[i],
                            context: ".controls",
                            on: [{
                                name: "click",
                                emit: "requestNewItem"
                            }]
                        });
                        break;
                    case "delete":
                        binds.push({
                            target: config.controls[i],
                            context: ".controls",
                            on: [{
                                name: "click",
                                handler: "removeSelected"
                            }]
                        });
                        break;
                }
            }

            // run the internal binds
            for (var i in binds) {
                Bind.call(self, binds[i]);
            }

            // run the binds
            for (var i in config.binds) {
                Bind.call(self, config.binds[i]);
            }

            Events.call(self, config);

            if (config.options.autofetch) {
                self.read({}, { sort: config.options.sort });
            }
        }

        function render(item) {
            switch (config.template.type) {
                case "selector":
                    renderSelector.call(self, item);
                case "html":
                    // TODO
                case "url":
                    // TODO
            }
        }

        function renderSelector(item) {
            var newItem = $(template).clone();
            newItem
                .removeClass("template")
                .addClass(config.options.classes.item)
                .appendTo(container)
                .show();

            for (var i in config.template.binds) {
                var bindObj = config.template.binds[i];
                bindObj.context = newItem;
                Bind.call(self, bindObj, item);
            }
        }

        function clearList() {
            $("." + config.options.classes.item, container).remove();
        }

        // ********************************
        // Public functions ***************
        // ********************************

        function read(filter, options) {

            clearList();

            var data = {
                filter: filter,
                options: options
            }

            self.link(config.crud.read, { data: data }, function(err, data) {

                if (err) { return; }

                if (!data || !(data.length > 0)) {
                    return;
                }

                for (var i in data) {
                    render.call(self, data[i]);
                }

                var autoselect = config.options.autoselect;
                switch (autoselect) {
                    case "first":
                        selectItem(data[0]);
                        break;
                    case "last":
                        selectItem(data[data.length - 1]);
                        break;
                    default:
                        if (typeof autoselect === "number") {
                            selectItem(data[autoselect]);
                        }
                }
            });
        }

        function createItem(itemData) {
            self.link(config.crud.create, { data: itemData }, function(err, data) {
                if (err) { return; }
                render.call(self, data);
            });
        }

        function _sendRemove(itemData) {
            self.link(config.crud.delete, { data: { id: itemData.id } }, function(err, data) {
                if (err) { return; }
                $("#" + itemData.id).remove();
            });
        }

        function removeItem(itemData) {
            if (!config.options.deleteConfirmation) {
                _sendRemove(itemData);
                return;
            }

            self.emit("requestRemoveItem", itemData, function(err, confirmation) {
                if (confirmation) {
                    _sendRemove(itemData);
                }
            });
        }

        function removeSelected() {
            var ids = [];
            var selectedClass = config.options.classes.selected;
            $("." + selectedClass, container).each(function() {
                ids.push($(this).attr("id"));
            });

            self.link(config.crud.delete, { data: { ids: ids } }, function(err, data) {
                if (err) { return; }
                $("." + selectedClass, container).remove();
            });
        }

        function selectItem(dataItem) {

            if (!dataItem) {
                return;
            }

            var selectedClass = config.options.classes.selected;

            switch (config.options.selection) {

                case "single":
{'fraction_non_alphanumeric': 0.12782139352306182, 'fraction_numerical': 0.0014720314033366045, 'mean_word_length': 1.0354527296937417, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 5, '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': '7157516', 'n_tokens_mistral': 2990, 'n_tokens_neox': 2764, 'n_words': 575}