<commit_before>/**
 * Created by leniglo on 04/01/16.
 */

Template.modals.events({
    'click #change_picture_apply': function (e) {
        e.preventDefault();
        var id = $cg_pic.find('input[name="_id"]').val();
        var picture = $cg_pic.find('input[name="pic"]').val();

        Show.update({_id: id}, {$set: {pic: picture}}, function (err, res) {
            if (err)
                alert(err);
            if (res > 0)
                $cg_pic.modal('hide');
        });
    },
    'click #change_link_apply': function (e) {
        e.preventDefault();
        var id = $cg_link.find('input[name="_id"]').val();
        var link = $cg_link.find('input[name="link"]').val();

        Show.update({_id: id}, {$set: {link: link}}, function (err, res) {
            if (err)
                alert(err);
            if (res > 0)
                $cg_link.modal('hide');
        });
    },
    'click #confirmChangeBackground': function (e) {
        e.preventDefault();
        var input = $md_chg_back.find('input').val();
        if (Meteor.userId() != null) {
            Meteor.call('changeUserBackground', input, function (error, result) {
                if (result) {
                    $md_chg_back.modal('hide');
                }
            });
        }
    },
    'click #resetChangeBackground': function (e) {
        e.preventDefault();
        if (Meteor.userId()) {
            Meteor.call('changeUserBackground', null, function (error, result) {
                if (result) {
                    $md_chg_back.modal('hide');
                }
            });
        }
    },
    'click #import_json': function (event) {
        event.preventDefault();
        var json = $md_imp_exp.find("textarea").val();
        try {
            var obj = JSON.parse(json);
        } catch (error) {
            $("#modal_import_export").modal('hide');
            alert("Don't try to trick us !\nJSON isn't well formatted.\n" + error.toString());
            return false;
        }
        var animes = obj.animes;
        var series = obj.series;
        var count = 0;
        animes.forEach(function (elem) {
            var test = Show.findOne({$and: [{name: elem.name}, {owner: Meteor.userId()}]});
            if (test) {
                if (test.updatedAt === null || elem.updatedAt > test.updatedAt) {
                    Show.update({name: elem.name}, {
                        $set: {
                            type: 'anime',
                            pic: elem.pic,
                            status: elem.status,
                            season: elem.season,
                            episode: elem.episode,
                            link: elem.link,
                            commentary: elem.commentary,
                            owner: Meteor.userId()()
                        }
                    }, function () {
                        ++count;
                    });
                }
            } else {
                Show.insert({
                    type: 'anime',
                    name: elem.name,
                    status: elem.status,
                    season: elem.season,
                    episode: elem.episode,
                    pic: elem.pic,
                    link: elem.link,
                    commentary: elem.commentary,
                    owner: Meteor.userId(),
                    createdAt: elem.createdAt
                });
                ++count;
            }
        });
        series.forEach(function (elem) {
            var test = Show.findOne({$and: [{name: elem.name}, {owner: Meteor.userId()}]});
            if (test) {
                if (test.updatedAt === null || elem.updatedAt > test.updatedAt) {
                    Show.update({name: elem.name}, {
                        $set: {
                            type: 'serie',
                            pic: elem.pic,
                            status: elem.status,
                            season: elem.season,
                            episode: elem.episode,
                            link: elem.link,
                            commentary: elem.commentary,
                            owner: Meteor.userId()()
                        }
                    }, function () {
                        ++count;
                    });
                }
            } else {
                Show.insert({<commit_msg>Fixed a bug on the import of data.<commit_after>/**
 * Created by leniglo on 04/01/16.
 */

Template.modals.events({
    'click #change_picture_apply': function (e) {
        e.preventDefault();
        var id = $cg_pic.find('input[name="_id"]').val();
        var picture = $cg_pic.find('input[name="pic"]').val();

        Show.update({_id: id}, {$set: {pic: picture}}, function (err, res) {
            if (err)
                alert(err);
            if (res > 0)
                $cg_pic.modal('hide');
        });
    },
    'click #change_link_apply': function (e) {
        e.preventDefault();
        var id = $cg_link.find('input[name="_id"]').val();
        var link = $cg_link.find('input[name="link"]').val();

        Show.update({_id: id}, {$set: {link: link}}, function (err, res) {
            if (err)
                alert(err);
            if (res > 0)
                $cg_link.modal('hide');
        });
    },
    'click #confirmChangeBackground': function (e) {
        e.preventDefault();
        var input = $md_chg_back.find('input').val();
        if (Meteor.userId() != null) {
            Meteor.call('changeUserBackground', input, function (error, result) {
                if (result) {
                    $md_chg_back.modal('hide');
                }
            });
        }
    },
    'click #resetChangeBackground': function (e) {
        e.preventDefault();
        if (Meteor.userId()) {
            Meteor.call('changeUserBackground', null, function (error, result) {
                if (result) {
                    $md_chg_back.modal('hide');
                }
            });
        }
    },
    'click #import_json': function (event) {
        event.preventDefault();
        var json = $md_imp_exp.find("textarea").val();
        try {
            var obj = JSON.parse(json);
        } catch (error) {
            $("#modal_import_export").modal('hide');
            alert("Don't try to trick us !\nJSON isn't well formatted.\n" + error.toString());
            return false;
        }
        var animes = obj.animes;
        var series = obj.series;
        var count = 0;
        animes.forEach(function (elem) {
            var test = Show.findOne({
                $and: [
                    {name: elem.name},
                    {type: 'serie'},
                    {active: true},
                    {owner: Meteor.userId()}
                ]
            });
            if (test) {
                if (test.updatedAt === null || elem.updatedAt > test.updatedAt) {
                    Show.update({name: elem.name}, {
                        $set: {
                            type: 'anime',
                            pic: elem.pic,
                            status: elem.status,
                            season: elem.season,
                            episode: elem.episode,
                            link: elem.link,
                            commentary: elem.commentary,
                        }
                    }, function () {
                        ++count;
                    });
                }
            } else {
                Show.insert({
                    type: 'anime',
                    name: elem.name,
                    status: elem.status,
                    season: elem.season,
                    episode: elem.episode,
                    pic: elem.pic,
                    link: elem.link,
                    commentary: elem.commentary,
                    createdAt: elem.createdAt
                });
                ++count;
            }
        });
        series.forEach(function (elem) {
            var test = Show.findOne({
                $and: [
                    {name: elem.name},
                    {type: 'serie'},
                    {active: true},
                    {owner: Meteor.userId()}
                ]
            });
            if (test) {
                if (test.updatedAt === null || elem.updatedAt > test.updatedAt) {
                    Show.update({name: elem.name}, {
                        $set: {
                            type: 'serie',
                            pic: elem.pic,
                            status: elem.status,
                            season: elem.season,
                            episode: elem.episode,
                            link: elem.link,
                            commentary: elem.commentary,
                            owner: Meteor.userId()()
                        }
                    }, function () {
                        ++count;
                    });
                }
            } else {
                Show.insert({
{'fraction_non_alphanumeric': 0.13157310849789217, 'fraction_numerical': 0.0019968937208786333, 'mean_word_length': 1.044681333635745, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2940687', 'n_tokens_mistral': 2381, 'n_tokens_neox': 2283, 'n_words': 468}