<commit_before>/**
 * Model, Collection and View for Imagelist.
 */

var ImageModel = Backbone.Model.extend({

    defaults: {
        id: null,
        filename: null,
        title: "Untitled image",
        order: 1
    },

    initialize: function () {
    }

});

var Imagelist = Backbone.Collection.extend({

    model: ImageModel,

    comparator: function (image) {
        return image.get('order');
    },

    setOrder: function (id, order, title) {
        _.each(this.models, function (item) {
            if (item.get('id') === id) {
                item.set('order', order);
                item.set('title', title);
            }
        });
    }

});

var ImagelistHolder = Backbone.View.extend({

    initialize: function (id) {
        this.list = new Imagelist();
        var prelist = $('#' + this.id).val();
        if (prelist !== "") {
            prelist = $.parseJSON($('#' + this.id).val());
            _.each(prelist, function (item) {
                var image = new ImageModel({
                    filename: item.filename,
                    title: item.title,
                    id: this.list.length
                });
                this.list.add(image);
            }, this);
        }
        this.render();
        this.bindEvents();
    },

    render: function () {
        this.list.sort();

        var list = $('#imagelist-' + this.id + ' .list'),
            data = list.data('list'),
            index = 0;

        list.html('');
        var pathExp = /\\<PATH\>/g,
            fnameExp = /\\<FNAME\>/g;
        _.each(this.list.models, function (image) {
            image.set('id', index++);

            var element = $(data.item.
                replace('<ID>', image.get('id')).
                replace('<VAL>', _.escape(image.get('title'))).
                replace(pathExp, bolt.paths.bolt).
                replace(fnameExp, image.get('filename')));

            element.find('.thumbnail-link').magnificPopup({type: 'image'});

            list.append(element);
        });
        if (this.list.models.length === 0) {
            list.append(data.empty);
        }
        this.serialize();
    },

    add: function (filename, title) {
        var image = new ImageModel({
            filename: filename,
            title: title,
            id: this.list.length
        });

        this.list.add(image);
        this.render();
    },

    remove: function (id, dontRender) {
        var done = false;
        _.each(this.list.models, function (item) {
            if ((!done) && (item.get('id') === id)) {
                this.list.remove(item);<commit_msg>Simplify and correct placeholder replacement<commit_after>/**
 * Model, Collection and View for Imagelist.
 */

var ImageModel = Backbone.Model.extend({

    defaults: {
        id: null,
        filename: null,
        title: "Untitled image",
        order: 1
    },

    initialize: function () {
    }

});

var Imagelist = Backbone.Collection.extend({

    model: ImageModel,

    comparator: function (image) {
        return image.get('order');
    },

    setOrder: function (id, order, title) {
        _.each(this.models, function (item) {
            if (item.get('id') === id) {
                item.set('order', order);
                item.set('title', title);
            }
        });
    }

});

var ImagelistHolder = Backbone.View.extend({

    initialize: function (id) {
        this.list = new Imagelist();
        var prelist = $('#' + this.id).val();
        if (prelist !== "") {
            prelist = $.parseJSON($('#' + this.id).val());
            _.each(prelist, function (item) {
                var image = new ImageModel({
                    filename: item.filename,
                    title: item.title,
                    id: this.list.length
                });
                this.list.add(image);
            }, this);
        }
        this.render();
        this.bindEvents();
    },

    render: function () {
        this.list.sort();

        var list = $('#imagelist-' + this.id + ' .list'),
            data = list.data('list'),
            index = 0;

        list.html('');
        _.each(this.list.models, function (image) {
            image.set('id', index++);

            var element = $(data.item.
                replace(/<ID>/g, image.get('id')).
                replace(/<VAL>/g, _.escape(image.get('title'))).
                replace(/<PATH>/g, bolt.paths.bolt).
                replace(/<FNAME>/g, image.get('filename')));

            element.find('.thumbnail-link').magnificPopup({type: 'image'});

            list.append(element);
        });
        if (this.list.models.length === 0) {
            list.append(data.empty);
        }
        this.serialize();
    },

    add: function (filename, title) {
        var image = new ImageModel({
            filename: filename,
            title: title,
            id: this.list.length
        });

        this.list.add(image);
        this.render();
    },

    remove: function (id, dontRender) {
        var done = false;
        _.each(this.list.models, function (item) {
            if ((!done) && (item.get('id') === id)) {
                this.list.remove(item);
{'fraction_non_alphanumeric': 0.16336728810301748, 'fraction_numerical': 0.0011531808571977706, 'mean_word_length': 1.5434995112414467, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4490009', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1471, 'n_words': 306}