<commit_before>
//### board_view_list

Template.board_view_list.card_list = function() {
    var cards = Cards.find({_id: {$in: this.cards}});
    return sort_by_ids(cards, this.cards);
}

Template.board_view_list.show_new_card_form = function() {
    return Session.equals('show_new_card_form', this._id);
}

Template.board_view_list.can_edit = function() {
    var opts = Session.get('current_view_options');
    var board = Boards.findOne({uri: opts.board_uri, members: Meteor.userId()});
    return board;
}

Template.board_view_list.events({
    /**
     * When user clicks to add a new card
     */
    'click .newcard' : function (event, template) {
        Session.set('show_new_card_form', this._id);
    },

    /**
     * When user clicks to remove a list
     */
    'click .close.remove_list': function (event, template) {
        Meteor.call('removeList', {list_id: this._id}, function (error) {
            if (error) {
                alert("error removing the list, sorry");
            }
        });
    }
});

//### board_new_list

Template.board_new_list.events({
    /**
     * When user click to create the list, send the petition to the server,
     * create the list, and show it
     */
    'click .save' : function (event, template) {
        var name = template.find("#listname").value;
        if (name.length > 0 && name.length < 140) {
            Session.set("modal_form_errors", "");
            var opts = Session.get('current_view_options');

            Meteor.call('createList', {
                    board_uri: opts.board_uri,
                    name: name,
                }, function (error) {
                    if (error) {
                        alert("error creating the list, sorry");
                    }
                });
<commit_msg>adding support for lists drag & drop<commit_after>
//### board_view_list

Template.board_view_list.card_list = function() {
    var cards = Cards.find({_id: {$in: this.cards}});
    return sort_by_ids(cards, this.cards);
}

Template.board_view_list.show_new_card_form = function() {
    return Session.equals('show_new_card_form', this._id);
}

Template.board_view_list.can_edit = function() {
    var opts = Session.get('current_view_options');
    var board = Boards.findOne({uri: opts.board_uri, members: Meteor.userId()});
    return board;
}

Template.board_view_list.events({
    /**
     * When user clicks to add a new card
     */
    'click .newcard' : function (event, template) {
        Session.set('show_new_card_form', this._id);
    },

    /**
     * When user clicks to remove a list
     */
    'click .close.remove_list': function (event, template) {
        Meteor.call('removeList', {list_id: this._id}, function (error) {
            if (error) {
                alert("error removing the list, sorry");
            }
        });
    }
});

// drag & drop

function makeListDraggable(el) {
    $(el).draggable({
        //containment: ".board",
        handle: ".header",
        cursor: "move",
        start: dragListStart,
        stop: dragListStop,
        helper: dragListHelper
    });
}

function makeListDroppable(el) {
    $(el).droppable({
        over: function(e, ui) {
            var o1 = ui.draggable;
            if (o1.hasClass("task")) {
                $(this).find(".cards").prepend(o1);
            } else {
                var o2 = $(this);
                if (o2.offset().left < o1.offset().left) {
                    o1.insertBefore(o2);
                } else {
                    o1.insertAfter(o2);
                }
            }
        },
        tolerance: "pointer"
    });

    $(el).find(".header").droppable({
        over: function(e, ui) {
            var o1 = ui.draggable;
            if (o1.hasClass("task")) {
                $(this).parent().find(".cards").prepend(o1);
            }
        }
    });
}

function dragListHelper(e) {
    var helper = $(this).clone();
    helper.addClass("dragging");
    helper.width($(this).width());
    return helper;
}

function dragListStart(e, ui) {
    $(this).addClass("dragging-freeze");
}

function dragListStop(e, ui) {
    $(this).removeClass("dragging-freeze");
    // save list order
    var listing = $(".list:not(.dragging)").map(function(i, l) {
        return l.id.substr("board_list_".length);
    });
    var opts = Session.get('current_view_options');
    Boards.update({uri: opts.board_uri}, {$set: {lists: listing.toArray()}});
}

Template.board_view_list.rendered = function () {
    makeListDraggable(this.firstNode);
    makeListDroppable(this.firstNode);
}

//### board_new_list

Template.board_new_list.events({
    /**
     * When user click to create the list, send the petition to the server,
     * create the list, and show it
     */
    'click .save' : function (event, template) {
        var name = template.find("#listname").value;
        if (name.length > 0 && name.length < 140) {
            Session.set("modal_form_errors", "");
            var opts = Session.get('current_view_options');

            Meteor.call('createList', {
                    board_uri: opts.board_uri,
                    name: name,
                }, function (error) {
                    if (error) {
                        alert("error creating the list, sorry");
                    }
                });

{'fraction_non_alphanumeric': 0.14573147799924785, 'fraction_numerical': 0.003948852952237684, 'mean_word_length': 2.083478260869565, 'pattern_counts': {'":': 0, '<': 6, '<?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': '5431553', 'n_tokens_mistral': 1647, 'n_tokens_neox': 1601, 'n_words': 338}