<commit_before>function updateMaterialList(oldList, newList) {
    oldList.length = 0;

    for (var i in newList) if (newList[i]) {
        oldList.push(newList[i]);
    }
}


type("AddMaterialDialog", ["ExclusivePopupWithButtons"], {

    _drawButtons: function() {

        var self = this;

        var buttonDiv = Html.div({},
            Widget.button(command(function() {
                self._upload();
            }, "Create Resource")));

        return buttonDiv;
    },



    _iFrameLoaded : function(iframeId) {

        var doc;

        if (Browser.IE) {
            // *sigh*
            doc = document.frames[iframeId].document;
        } else {
            doc = $E(iframeId).dom.contentDocument;
        }

        // textContent would be more appropriate, but IE...
        try {
            var res = Json.read(doc.body.innerHTML);
        } catch(e) {
            IndicoUtil.errorReport({'code':'0', 'message':$T('Unexpected exception')});
            return;
        }

        var self = this;

        if (res.status == "ERROR") {
            IndicoUtil.errorReport({
                code: '0',
                requestInfo: {},
                message: res.info });
        } else {
            this.onUpload(res.info);
            // Firefox will keep "loading" if the iframe is destroyed
            // right now. Let's wait a bit.
            setTimeout(
                function() {
                    self.close();
                }, 100);
        }
    },

    /*
     * Draws a pane that switches between a URL input and a file upload dialog.
     *
     * pm - A parameter manager
     * locationSelector - the locationSelector that will 'control' the pane
     */
    _drawResourcePathPane: function(locationSelector) {

        var file = Html.input('file', {name: 'file'});
        var urlBox = Html.edit({name: 'url'});
        var toPDFCheckbox = Html.checkbox({style: {verticalAlign: 'middle'}}, true);
        toPDFCheckbox.dom.name = 'topdf';

        var self = this;

        var resourcePathPane = new Chooser(
            new Lookup({
                'local':  function() {
                    self.pm.remove(urlBox);
                    return Html.div({},
                                    self.pm.add(file, 'text'),
                                    Html.div({style:{marginTop: '5px'}},
                                             toPDFCheckbox,
                                             Html.label({style: {verticalAlign: 'middle'}, className: 'emphasis'}
                                                        , $T("Convert to PDF (when applicable)")))
                                   );
                },
                'remote': function() {
                    self.pm.remove(file);
                    setTimeout(function() { urlBox.dom.focus(); }, 200);
                    return Html.div({},
                                    Html.label('popUpLabel', $T("URL")),
                                    self.pm.add(urlBox, 'url'),
                                    Html.div("smallGrey", $T("Example: http://www.example.com/YourPDFFile.pdf")));
                }
            }));


        // whenever the user selects a different location,
        // change between an http link field and an upload box.
        // This could be done simply with:
        // $B(resourcePathPane, locationSelector);
        // but we need to change the focus too, so let's use an observer

        locationSelector.observe(function(value) {
            // switch to the appropriate panel
            resourcePathPane.set(value);

            // set the focus
            if (value == 'local') {
                file.dom.focus();
            } else {
                urlBox.dom.focus();
            }
        });

        // change the upload type that will be sent in the request
        // (bind it with the selection box)
        $B(this.uploadType,
           locationSelector,
           {
               toSource: function(value) {
                   // unused;
               },
               toTarget: function(value) {
                   return value=='local'?'file':'link';
               }
           });

        // default is 'local' (local file)
        locationSelector.set('local');

        return resourcePathPane;

    },

    _parentText: function(args) {
        var text = null;

        if (args.subContId) {
            text = $T("Same people as parent Subcontribution");
        } else if (args.contribId) {
            text = $T("Same people as parent Contribution");
        } else if (args.sessionId) {
            text = $T("Same people as parent Session");
        } else if (args.confId) {
            text = $T("Same people as parent Conference");
        } else if (args.categId) {
            text = $T("Same people as parent Category");
        }

        text = Html.span({}, text, " ",
                         Html.unescaped.span({className: 'strongRed', style: {fontStyle: 'italic'}}," ",
                                   Protection.ParentRestrictionMessages[args.parentProtected?1:-1]));

        return text;
    },

    _findTypeName: function(id) {
        for (var i in this.types) {
            if (this.types[i][0] == id) {
                return this.types[i][1];
            }
        }
        return id;
    },

    _drawProtectionPane: function(value) {

        var text = null;
        var entry = this.list.get(value);
        var selector = null;

        if (value == '') {
            return Html.div({});

        } else if (exists(entry)) {

            // if the material is already in the tree, protection inheritance must
            // be resolved

            this.creationMode = 'resource';

            text = Html.span({}, $T("You're adding a resource to the existing material type"), " ", Html.span({style:{fontWeight: 'bold'}}, entry.get('title')), ". ", $T("Please specify who will be able to access it:"));

            // if the material is set to inherit from the parent, display it properly
            // and set the inherited protection accordingly
            var protection = Protection.resolveProtection(
                entry.get('protection'),
                entry.get('protectedOwner')?1:-1);

            var inheritanceText = Html.unescaped.span({className: 'strongRed', style: {fontStyle: 'italic'}},
                Protection.ParentRestrictionMessages[protection]);


            selector = new RadioFieldWidget([
                ['inherit', Html.span({}, $T("Same people as the parent material type ")+"\""+entry.get('title')+"\" ", inheritanceText)],<commit_msg>[FIX] Improve "other" material type field<commit_after>function updateMaterialList(oldList, newList) {
    oldList.length = 0;

    for (var i in newList) if (newList[i]) {
        oldList.push(newList[i]);
    }
}


type("AddMaterialDialog", ["ExclusivePopupWithButtons"], {

    _drawButtons: function() {

        var self = this;

        var buttonDiv = Html.div({},
            Widget.button(command(function() {
                self._upload();
            }, "Create Resource")));

        return buttonDiv;
    },



    _iFrameLoaded : function(iframeId) {

        var doc;

        if (Browser.IE) {
            // *sigh*
            doc = document.frames[iframeId].document;
        } else {
            doc = $E(iframeId).dom.contentDocument;
        }

        // textContent would be more appropriate, but IE...
        try {
            var res = Json.read(doc.body.innerHTML);
        } catch(e) {
            IndicoUtil.errorReport({'code':'0', 'message':$T('Unexpected exception')});
            return;
        }

        var self = this;

        if (res.status == "ERROR") {
            IndicoUtil.errorReport({
                code: '0',
                requestInfo: {},
                message: res.info });
        } else {
            this.onUpload(res.info);
            // Firefox will keep "loading" if the iframe is destroyed
            // right now. Let's wait a bit.
            setTimeout(
                function() {
                    self.close();
                }, 100);
        }
    },

    /*
     * Draws a pane that switches between a URL input and a file upload dialog.
     *
     * pm - A parameter manager
     * locationSelector - the locationSelector that will 'control' the pane
     */
    _drawResourcePathPane: function(locationSelector) {

        var file = Html.input('file', {name: 'file'});
        var urlBox = Html.edit({name: 'url'});
        var toPDFCheckbox = Html.checkbox({style: {verticalAlign: 'middle'}}, true);
        toPDFCheckbox.dom.name = 'topdf';

        var self = this;

        var resourcePathPane = new Chooser(
            new Lookup({
                'local':  function() {
                    self.pm.remove(urlBox);
                    return Html.div({},
                                    self.pm.add(file, 'text'),
                                    Html.div({style:{marginTop: '5px'}},
                                             toPDFCheckbox,
                                             Html.label({style: {verticalAlign: 'middle'}, className: 'emphasis'}
                                                        , $T("Convert to PDF (when applicable)")))
                                   );
                },
                'remote': function() {
                    self.pm.remove(file);
                    setTimeout(function() { urlBox.dom.focus(); }, 200);
                    return Html.div({},
                                    Html.label('popUpLabel', $T("URL")),
                                    self.pm.add(urlBox, 'url'),
                                    Html.div("smallGrey", $T("Example: http://www.example.com/YourPDFFile.pdf")));
                }
            }));


        // whenever the user selects a different location,
        // change between an http link field and an upload box.
        // This could be done simply with:
        // $B(resourcePathPane, locationSelector);
        // but we need to change the focus too, so let's use an observer

        locationSelector.observe(function(value) {
            // switch to the appropriate panel
            resourcePathPane.set(value);

            // set the focus
            if (value == 'local') {
                file.dom.focus();
            } else {
                urlBox.dom.focus();
            }
        });

        // change the upload type that will be sent in the request
        // (bind it with the selection box)
        $B(this.uploadType,
           locationSelector,
           {
               toSource: function(value) {
                   // unused;
               },
               toTarget: function(value) {
                   return value=='local'?'file':'link';
               }
           });

        // default is 'local' (local file)
        locationSelector.set('local');

        return resourcePathPane;

    },

    _parentText: function(args) {
        var text = null;

        if (args.subContId) {
            text = $T("Same people as parent Subcontribution");
        } else if (args.contribId) {
            text = $T("Same people as parent Contribution");
        } else if (args.sessionId) {
            text = $T("Same people as parent Session");
        } else if (args.confId) {
            text = $T("Same people as parent Conference");
        } else if (args.categId) {
            text = $T("Same people as parent Category");
        }

        text = Html.span({}, text, " ",
                         Html.unescaped.span({className: 'strongRed', style: {fontStyle: 'italic'}}," ",
                                   Protection.ParentRestrictionMessages[args.parentProtected?1:-1]));

        return text;
    },

    _findTypeName: function(id) {
        for (var i in this.types) {
            if (this.types[i][0] == id) {
                return this.types[i][1];
            }
        }
        return id;
    },

    _drawProtectionPane: function(value) {

        var text = null;
        var entry = this.list.get(value) || this.list.get(value.toLowerCase());
        var selector = null;

        if (value == '') {
            return Html.div({});

        } else if (exists(entry)) {

            // if the material is already in the tree, protection inheritance must
            // be resolved

            this.creationMode = 'resource';

            text = Html.span({}, $T("You're adding a resource to the existing material type"), " ", Html.span({style:{fontWeight: 'bold'}}, entry.get('title')), ". ", $T("Please specify who will be able to access it:"));

            // if the material is set to inherit from the parent, display it properly
            // and set the inherited protection accordingly
            var protection = Protection.resolveProtection(
                entry.get('protection'),
                entry.get('protectedOwner')?1:-1);

            var inheritanceText = Html.unescaped.span({className: 'strongRed', style: {fontStyle: 'italic'}},
                Protection.ParentRestrictionMessages[protection]);


            selector = new RadioFieldWidget([
                ['inherit', Html.span({}, $T("Same people as the parent material type ")+"\""+entry.get('title')+"\" ", inheritanceText)],
{'fraction_non_alphanumeric': 0.1242848539596507, 'fraction_numerical': 0.002408912978018669, 'mean_word_length': 1.4873619172439618, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6098522', 'n_tokens_mistral': 3530, 'n_tokens_neox': 3341, 'n_words': 891}