<commit_before>var $ = require('jquery');
var $osf = require('osfHelpers');
var bootbox = require('bootbox');
require('../vendor/bower_components/slickgrid/lib/jquery.event.drag-2.2.js');
var m = require('mithril');
var Treebeard = require('treebeard');
require('../css/fangorn.css');


function resolveToggle(item) {
        var toggleMinus = m('i.icon-minus', ' '),
            togglePlus = m('i.icon-plus', ' ');

        if (item.children.length > 0) {
            if (item.open) {
                return toggleMinus;
            }
            return togglePlus;
        }
        item.open = true;
        return '';
    }

function resolveIcon(item) {
    if (item.children.length > 0) {
        if (item.open) {
            return m("i.icon.icon-folder-open", " ");
        }
        return m("i.icon.icon-folder-close", " ");
    }
}

function expandOnLoad() {
    var tb = this;
    for (var i = 0; i < tb.treeData.children.length; i++) {
        var parent = tb.treeData.children[i];
        tb.updateFolder(null, parent);
        expandChildren(tb, parent.children);
    }
}

function expandChildren(tb, children) {
    for (var i = 0; i < children.length; i++) {
        var child = children[i];
        if (child.data.kind !== 'event') {
            for (var j = 0; j < child.children.length; j++) {
                if (child.children[j].data.notificationType !== "adopt_parent") {
                    tb.updateFolder(null, child);
                }
                if (child.children.length > 0) {
                    expandChildren(tb, child.children);
                }
            }
        }
    }
}

function subscribe(id, event, notification_type) {
    var payload = {
                'id': id,
                'event': event,
                'notification_type': notification_type
    };
    $osf.postJSON(
        '/api/v1/settings/subscribe/',
        payload
    ).fail(function() {
        bootbox.alert('Could not update notification preferences.')
    });<commit_msg>Fix expansion of nested folders<commit_after>var $ = require('jquery');
var $osf = require('osfHelpers');
var bootbox = require('bootbox');
require('../vendor/bower_components/slickgrid/lib/jquery.event.drag-2.2.js');
var m = require('mithril');
var Treebeard = require('treebeard');
require('../css/fangorn.css');


function resolveToggle(item) {
        var toggleMinus = m('i.icon-minus', ' '),
            togglePlus = m('i.icon-plus', ' ');

        if (item.children.length > 0) {
            if (item.open) {
                return toggleMinus;
            }
            return togglePlus;
        }
        item.open = true;
        return '';
    }

function resolveIcon(item) {
    if (item.children.length > 0) {
        if (item.open) {
            return m("i.icon.icon-folder-open", " ");
        }
        return m("i.icon.icon-folder-close", " ");
    }
}

function expandOnLoad() {
    var tb = this;
    for (var i = 0; i < tb.treeData.children.length; i++) {
        var parent = tb.treeData.children[i];
        tb.updateFolder(null, parent);
        expandChildren(tb, parent.children);
    }
}

function expandChildren(tb, children) {
    var openParent = false;
    for (var i = 0; i < children.length; i++) {
        var child = children[i];
        var parent = children[i].parent();
        if (child.data.kind === 'event' && child.data.notificationType !== "adopt_parent") {
            openParent = true;
        }
        if (child.children.length > 0) {
            expandChildren(tb, child.children);
        }
    }
    if (openParent) {
        openAncestors(tb, children[0]);
    }
}

function openAncestors (tb, item) {
    var parent = item.parent();
    if(parent && parent.id > 0) {
        tb.updateFolder(null, parent);
        openAncestors(tb, parent);
    }
}

function subscribe(id, event, notification_type) {
    var payload = {
                'id': id,
                'event': event,
                'notification_type': notification_type
    };
    $osf.postJSON(
        '/api/v1/settings/subscribe/',
        payload
    ).fail(function() {
        bootbox.alert('Could not update notification preferences.')
    });
{'fraction_non_alphanumeric': 0.1518135959644487, 'fraction_numerical': 0.004564016334374249, 'mean_word_length': 2.002162941600577, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, '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': '3218645', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1262, 'n_words': 258}