<commit_before>/**
 * NodeMenu is a UI Element containing options for AbstractNode elements
 *
 * @class NodeMenu
 * @constructor
 * @param {Array} data Contains objects corresponding to different menu items
 *
 {
 [
    {
        'name' : the name of the menu item,
        'label' : the text label above this menu option,
        'type' : the type of form input. (eg. 'radio', 'date-picker', 'text', 'textarea', 'disease-picker', 'select'),
        'values' : [
                    {'actual' : actual value of the option, 'displayed' : the way the option will be seen in the menu} ...
                    ]
    }, ...
 ]
 }
 
 Note: when an item is specified as "inactive" it is completely removed from the menu; when it
       is specified as "disabled" it is greyed-out and does not allow selection, but is still visible.
 */
NodeMenu = Class.create({
    initialize : function(data, tabs, otherCSSClass) {
        //console.log("nodeMenu initialize");
        this.canvas = editor.getWorkspace().canvas || $('body');
        var cssClass = 'menu-box';
        if (otherCSSClass) cssClass += " " + otherCSSClass;
        this.menuBox = new Element('div', {'class' : cssClass});

        this.closeButton = new Element('span', {'class' : 'close-button'}).update('×');
        this.menuBox.insert({'top': this.closeButton});
        this.closeButton.observe('click', this.hide.bindAsEventListener(this));

        this.form = new Element('form', {'method' : 'get', 'action' : '', 'class': 'tabs-content'});

        this.tabs = {};
        this.tabHeaders = {};
        if (tabs && tabs.length > 0) {
            this.tabTop = new Element('dl', {'class':'tabs'});
            for (var i = 0; i < tabs.length; i++) {
                var tabName = tabs[i];
                var activeClass = (i == 0) ? "active" : "";
                this.tabs[tabName] = new Element('div', {'id': 'tab_' + tabName, 'class': 'content ' + activeClass});
                this.form.insert(this.tabs[tabName]);

                this.tabHeaders[tabName] = new Element('dd', {"class": activeClass}).insert("<a>" + tabName + "</a>");
                var _this = this;
                var switchTab = function(tabName) {
                    return function() {
                        for (var tab in _this.tabs) {
                            if (_this.tabs.hasOwnProperty(tab)) {
                                if (tab != tabName) {
                                    _this.tabs[tab].className = "content";
                                    _this.tabHeaders[tab].className = "";
                                } else {
                                    _this.tabs[tab].className = "content active";
                                    _this.tabHeaders[tab].className = "active";
                                }
                            }
                        }
                        _this.reposition();
                    }
                }
                this.tabHeaders[tabName].observe('click', switchTab(tabName));
                this.tabTop.insert(this.tabHeaders[tabName]);
            }
            var div = new Element('div', {'class': 'tabholder'}).insert(this.tabTop).insert(this.form);
            this.menuBox.insert({'bottom' : div});
        } else {
            this.singleTab = new Element('div', {'class': 'tabholder'}).insert(this.form);
            this.menuBox.insert({'bottom' : this.singleTab});
            this.closeButton.addClassName("close-button-old");
            this.form.addClassName("content");
        }

        this.fieldMap = {};
        // Generate fields
        var _this = this;
        data.each(function(d) {
            if (typeof (_this._generateField[d.type]) == 'function') {
                var insertLocation = _this.form;
                if (d.tab && _this.tabs.hasOwnProperty(d.tab)) {
                    insertLocation = _this.tabs[d.tab];
                }
                insertLocation.insert(_this._generateField[d.type].call(_this, d));
            }
        });

        // Insert in document
        this.hide();
        editor.getWorkspace().getWorkArea().insert(this.menuBox);

        this._onClickOutside = this._onClickOutside.bindAsEventListener(this);

        // Attach pickers and suggest widgets
        this._generatePickersAndSuggests();

        // Update disorder colors
        this._updateDisorderColor = function(id, color) {
          this.menuBox.select('.field-disorders li input[value="' + id + '"]').each(function(item) {
             var colorBubble = item.up('li').down('.disorder-color');
             if (!colorBubble) {
               colorBubble = new Element('span', {'class' : 'disorder-color'});
               item.up('li').insert({top : colorBubble});
             }
             colorBubble.setStyle({background : color});
          });
        }.bind(this);
        document.observe('disorder:color', function(event) {
           if (!event.memo || !event.memo.id || !event.memo.color) {
             return;
           }
           _this._updateDisorderColor(event.memo.id, event.memo.color);
        });
        //this._setFieldValue['disease-picker'].bind(this);

        // Update gene colors
        this._updateGeneColor = function(id, color) {
          this.menuBox.select('.field-candidate_genes li input[value="' + id + '"]').each(function(item) {
             var colorBubble = item.up('li').down('.disorder-color');
             if (!colorBubble) {
               colorBubble = new Element('span', {'class' : 'disorder-color'});
               item.up('li').insert({top : colorBubble});
             }
             colorBubble.setStyle({background : color});
          });
        }.bind(this);<commit_msg>[misc] Fix pedigree editor menu not displaying disorder colors (introduced in 78a798d)<commit_after>/**
 * NodeMenu is a UI Element containing options for AbstractNode elements
 *
 * @class NodeMenu
 * @constructor
 * @param {Array} data Contains objects corresponding to different menu items
 *
 {
 [
    {
        'name' : the name of the menu item,
        'label' : the text label above this menu option,
        'type' : the type of form input. (eg. 'radio', 'date-picker', 'text', 'textarea', 'disease-picker', 'select'),
        'values' : [
                    {'actual' : actual value of the option, 'displayed' : the way the option will be seen in the menu} ...
                    ]
    }, ...
 ]
 }
 
 Note: when an item is specified as "inactive" it is completely removed from the menu; when it
       is specified as "disabled" it is greyed-out and does not allow selection, but is still visible.
 */
NodeMenu = Class.create({
    initialize : function(data, tabs, otherCSSClass) {
        //console.log("nodeMenu initialize");
        this.canvas = editor.getWorkspace().canvas || $('body');
        var cssClass = 'menu-box';
        if (otherCSSClass) cssClass += " " + otherCSSClass;
        this.menuBox = new Element('div', {'class' : cssClass});

        this.closeButton = new Element('span', {'class' : 'close-button'}).update('×');
        this.menuBox.insert({'top': this.closeButton});
        this.closeButton.observe('click', this.hide.bindAsEventListener(this));

        this.form = new Element('form', {'method' : 'get', 'action' : '', 'class': 'tabs-content'});

        this.tabs = {};
        this.tabHeaders = {};
        if (tabs && tabs.length > 0) {
            this.tabTop = new Element('dl', {'class':'tabs'});
            for (var i = 0; i < tabs.length; i++) {
                var tabName = tabs[i];
                var activeClass = (i == 0) ? "active" : "";
                this.tabs[tabName] = new Element('div', {'id': 'tab_' + tabName, 'class': 'content ' + activeClass});
                this.form.insert(this.tabs[tabName]);

                this.tabHeaders[tabName] = new Element('dd', {"class": activeClass}).insert("<a>" + tabName + "</a>");
                var _this = this;
                var switchTab = function(tabName) {
                    return function() {
                        for (var tab in _this.tabs) {
                            if (_this.tabs.hasOwnProperty(tab)) {
                                if (tab != tabName) {
                                    _this.tabs[tab].className = "content";
                                    _this.tabHeaders[tab].className = "";
                                } else {
                                    _this.tabs[tab].className = "content active";
                                    _this.tabHeaders[tab].className = "active";
                                }
                            }
                        }
                        _this.reposition();
                    }
                }
                this.tabHeaders[tabName].observe('click', switchTab(tabName));
                this.tabTop.insert(this.tabHeaders[tabName]);
            }
            var div = new Element('div', {'class': 'tabholder'}).insert(this.tabTop).insert(this.form);
            this.menuBox.insert({'bottom' : div});
        } else {
            this.singleTab = new Element('div', {'class': 'tabholder'}).insert(this.form);
            this.menuBox.insert({'bottom' : this.singleTab});
            this.closeButton.addClassName("close-button-old");
            this.form.addClassName("content");
        }

        this.fieldMap = {};
        // Generate fields
        var _this = this;
        data.each(function(d) {
            if (typeof (_this._generateField[d.type]) == 'function') {
                var insertLocation = _this.form;
                if (d.tab && _this.tabs.hasOwnProperty(d.tab)) {
                    insertLocation = _this.tabs[d.tab];
                }
                insertLocation.insert(_this._generateField[d.type].call(_this, d));
            }
        });

        // Insert in document
        this.hide();
        editor.getWorkspace().getWorkArea().insert(this.menuBox);

        this._onClickOutside = this._onClickOutside.bindAsEventListener(this);

        // Attach pickers and suggest widgets
        this._generatePickersAndSuggests();

        // Update disorder colors
        this._updateDisorderColor = function(id, color) {
          this.menuBox.select('.field-disorders li input[value="' + id + '"]').each(function(item) {
             var colorBubble = item.up('li').down('.abnormality-color');
             if (!colorBubble) {
               colorBubble = new Element('span', {'class' : 'abnormality-color'});
               item.up('li').insert({top : colorBubble});
             }
             colorBubble.setStyle({background : color});
          });
        }.bind(this);
        document.observe('disorder:color', function(event) {
           if (!event.memo || !event.memo.id || !event.memo.color) {
             return;
           }
           _this._updateDisorderColor(event.memo.id, event.memo.color);
        });
        //this._setFieldValue['disease-picker'].bind(this);

        // Update gene colors
        this._updateGeneColor = function(id, color) {
          this.menuBox.select('.field-candidate_genes li input[value="' + id + '"]').each(function(item) {
             var colorBubble = item.up('li').down('.abnormality-color');
             if (!colorBubble) {
               colorBubble = new Element('span', {'class' : 'abnormality-color'});
               item.up('li').insert({top : colorBubble});
             }
             colorBubble.setStyle({background : color});
          });
        }.bind(this);
{'fraction_non_alphanumeric': 0.1458496305953933, 'fraction_numerical': 0.0009561060408518036, 'mean_word_length': 1.7900096993210475, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5109114', 'n_tokens_mistral': 3169, 'n_tokens_neox': 3040, 'n_words': 670}