<commit_before>/* This file is part of Indico.
 * Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
 *
 * Indico is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 *
 * Indico is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Indico; if not, see <http://www.gnu.org/licenses/>.
 */

 (function(global) {
    'use strict';

    global.initMenuSortable = function initMenuSortable() {
        // ui.sender seems broken (returns null) so we keep track of the sortable who sent the item manually...
        var _sender = null;
        /*
         *.sortable('cancel') is also broken thus we need to keep track of the validity of an update manually as well.
         * See 'beforeStop' for a more detailed explanation.
         */
        var _invalidUpdate = false;

        function _canDrop(evt, ui) {
            if (_sender[0] === ui.placeholder.parent()[0]) { // entry moved within the same list
                return true;
            }
            if (!ui.item.hasClass('nestable')) {
                return false;
            }

            var parent = ui.placeholder.closest('.menu-entry').parent();
            // valid cross-list drag if the target list is the root one or if the target list can have nested entries
            return parent[0] === undefined || parent.hasClass('allow-nested');
        }

        // delete existing sortable before recreating them
        $('.menu-entries.ui-sortable').sortable('destroy');

        $('.menu-entries').sortable({
            handle: '.drag-handle',
            placeholder: 'menu-entry-placeholder',
            axis: 'y',
            connectWith: '.connect-menu',
            start: function(evt, ui) {
                _sender = $(this);
                if (ui.item.hasClass('nestable')) {
                    // The list only has the placeholder and the entry being dragged. It should look like an empty list.
                    if (_sender.children().not('.menu-entry-placeholder').length === 1) {
                        _sender.addClass('empty');
                    }
                    // Show empty children list which accept children
                    $('.menu-entries > .allow-nested > .menu-entry > .menu-entries.empty').addClass('expand')
                        .parent('.menu-entry')
                            .addClass('with-children');
                    ui.item.find('> .menu-entry > .menu-entries.empty').removeClass('expand')
                        .parent('.menu-entry')
                            .removeClass('with-children');
                }
            },
            beforeStop: function(evt, ui) {
                /*
                 * In the case of an invalid update we need to cancel the move. But .sortable('cancel') fails internally
                 * when called from here so we keep track of whether the move is valid, check in 'update' if can update
                 * and then cancel the move in 'stop' if needed.
                 */
                _invalidUpdate = !_canDrop(evt, ui);
            },
            stop: function(evt, ui) {
                // mandatory clean-up
                $('menu-entries').removeClass('hide-placeholder');
                if (ui.item.hasClass('nestable')) {
                    $('.menu-entries > .allow-nested > .menu-entry > .menu-entries.empty').removeClass('expand')
                        .parent('.menu-entry')
                            .removeClass('with-children');
                }

                // Check if move is valid
                if (_invalidUpdate) {
                    // This can only happen if a nested user-submitted entry is dropped on an invalid target list, which
                    // shouldn't happen as internal nested list are not connected with the other lists.
                    $(this).sortable('cancel');

                } else {
                    if (ui.item.hasClass('nestable')) {
                        // remove .empty from parent list and .nestable from parent entry
                        ui.item.closest('.menu-entries')
                            .removeClass('empty')
                            .parent('.menu-entry')
                                .addClass('with-children')
                                .parent()<commit_msg>Fix lack of placeholders in specific cases<commit_after>/* This file is part of Indico.
 * Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
 *
 * Indico is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 *
 * Indico is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Indico; if not, see <http://www.gnu.org/licenses/>.
 */

 (function(global) {
    'use strict';

    global.initMenuSortable = function initMenuSortable() {
        // ui.sender seems broken (returns null) so we keep track of the sortable who sent the item manually...
        var _sender = null;
        /*
         *.sortable('cancel') is also broken thus we need to keep track of the validity of an update manually as well.
         * See 'beforeStop' for a more detailed explanation.
         */
        var _invalidUpdate = false;

        function _canDrop(evt, ui) {
            if (_sender[0] === ui.placeholder.parent()[0]) { // entry moved within the same list
                return true;
            }
            if (!ui.item.hasClass('nestable')) {
                return false;
            }

            var parent = ui.placeholder.closest('.menu-entry').parent();
            // valid cross-list drag if the target list is the root one or if the target list can have nested entries
            return parent[0] === undefined || parent.hasClass('allow-nested');
        }

        // delete existing sortable before recreating them
        $('.menu-entries.ui-sortable').sortable('destroy');

        $('.menu-entries').sortable({
            handle: '.drag-handle',
            placeholder: 'menu-entry-placeholder',
            axis: 'y',
            connectWith: '.connect-menu',
            start: function(evt, ui) {
                _sender = $(this);
                if (ui.item.hasClass('nestable')) {
                    // The list only has the placeholder and the entry being dragged. It should look like an empty list.
                    if (_sender.children().not('.menu-entry-placeholder').length === 1) {
                        _sender.addClass('empty');
                    }
                    // Show empty children list which accept children
                    $('.menu-entries > .allow-nested > .menu-entry > .menu-entries.empty').addClass('expand')
                        .parent('.menu-entry')
                            .addClass('with-children');
                    ui.item.find('> .menu-entry > .menu-entries.empty').removeClass('expand')
                        .parent('.menu-entry')
                            .removeClass('with-children');
                }
            },
            beforeStop: function(evt, ui) {
                /*
                 * In the case of an invalid update we need to cancel the move. But .sortable('cancel') fails internally
                 * when called from here so we keep track of whether the move is valid, check in 'update' if can update
                 * and then cancel the move in 'stop' if needed.
                 */
                _invalidUpdate = !_canDrop(evt, ui);
            },
            stop: function(evt, ui) {
                // mandatory clean-up
                $('.menu-entries').removeClass('hide-placeholder');
                if (ui.item.hasClass('nestable')) {
                    $('.menu-entries > .allow-nested > .menu-entry > .menu-entries.empty').removeClass('expand')
                        .parent('.menu-entry')
                            .removeClass('with-children');
                }

                // Check if move is valid
                if (_invalidUpdate) {
                    // This can only happen if a nested user-submitted entry is dropped on an invalid target list, which
                    // shouldn't happen as internal nested list are not connected with the other lists.
                    $(this).sortable('cancel');

                } else {
                    if (ui.item.hasClass('nestable')) {
                        // remove .empty from parent list and .nestable from parent entry
                        ui.item.closest('.menu-entries')
                            .removeClass('empty')
                            .parent('.menu-entry')
                                .addClass('with-children')
                                .parent()
{'fraction_non_alphanumeric': 0.10369978858350952, 'fraction_numerical': 0.0027484143763213532, 'mean_word_length': 1.6034672537149146, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1207163', 'n_tokens_mistral': 2268, 'n_tokens_neox': 2163, 'n_words': 801}