<commit_before>/**
 * Module to render the consolidated files view. Reads addon configurrations and
 * initializes an HGrid.
 */
this.FileBrowser = (function($, HGrid, bootbox) {
    var tpl = HGrid.Fmt.tpl;

    // Can't use microtemplate because microtemplate escapes html
    // Necessary for rendering, e.g. the github branch picker
    HGrid.Col.Name.folderView = function(item) {
        return HGrid.Html.folderIcon + item.name;
    };

    HGrid.Col.ActionButtons.itemView = function() {
      var buttonDefs = [{
          text: '<i class="icon-download-alt icon-white"></i>',
          action: 'download',
          cssClass: 'btn btn-success btn-mini'
      }, {
          text: '<i class="icon-trash icon-white"></i>',
          action: 'delete',
          cssClass: 'btn btn-danger btn-mini'
      }];
      return HGrid.Fmt.buttons(buttonDefs);
    };

    HGrid.Col.ActionButtons.folderView = function() {
        var buttonDefs = [];
        if (this.options.uploads) {
          buttonDefs.push({
            text: '\<i class="icon-cloud-upload icon-white"></i>',
            action: 'upload',
            cssClass: 'btn btn-primary btn-mini'
          });
        }
        if (buttonDefs) {
          return HGrid.Fmt.buttons(buttonDefs);
        }
        return '';
    };


    // OSF-specific HGrid options common to all addons
    baseOptions = {
        columns: [
            HGrid.Col.Name,
            HGrid.Col.ActionButtons
        ],
        width: '100%',
        height: 700,
        fetchUrl: function(row) {
            return row.urls.fetch;
        },
        downloadUrl: function(row) {
            return row.urls.download;
        },
        deleteUrl: function(row) {
            return row.urls.delete;
        },
        onClickDelete: function(evt, row) {
            console.log(this);
            var self = this;
            // TODO: This text should be configurable by addon devs
            var msg = tpl('Are you sure you want to delete "{{name}}"?', row);
            var ajaxOptions = {
                error: function() {
                    bootbox.alert('There was a problem deleting your file. Please try again later.');
                }
            };
            bootbox.confirm(msg, function(confirmed) {
                if (confirmed) {
                    self.removeItem(row.id);
                    // Send request to delete file.
                    self.deleteFile(row, ajaxOptions);
                }
            });
            return this;
        },
        deleteMethod: 'delete',
        uploads: true,
        uploadUrl: function(row) {
            var cfgFunc = FileBrowser.getCfg(row, 'uploadUrl');
            if (cfgFunc) {
                return cfgFunc(row);
            }
            return row.urls.upload;
        },
        uploadAdded: function(file, row) {
            var cfgFunc = FileBrowser.getCfg(row, 'uploadAdded');
            if (cfgFunc) {
                return cfgFunc(file, row);
            }
        },
        uploadMethod: 'post',
        listeners: [
            // Go to file's detail page if name is clicked
            {
                on: 'click',
                selector: '.hg-item-content',
                callback: function(evt, row, grid) {
                    if (row) {
                        var viewUrl = grid.getByID(row.id).urls.view;
                        if (viewUrl) {
                            window.location.href = viewUrl;
                        }
                    }
                }
            }
        ]
    };
<commit_msg>Make sure row passed to uploadAdded has 'addon' property<commit_after>/**
 * Module to render the consolidated files view. Reads addon configurrations and
 * initializes an HGrid.
 */
this.FileBrowser = (function($, HGrid, bootbox) {
    var tpl = HGrid.Fmt.tpl;

    // Can't use microtemplate because microtemplate escapes html
    // Necessary for rendering, e.g. the github branch picker
    HGrid.Col.Name.folderView = function(item) {
        return HGrid.Html.folderIcon + item.name;
    };

    HGrid.Col.ActionButtons.itemView = function() {
      var buttonDefs = [{
          text: '<i class="icon-download-alt icon-white"></i>',
          action: 'download',
          cssClass: 'btn btn-success btn-mini'
      }, {
          text: '<i class="icon-trash icon-white"></i>',
          action: 'delete',
          cssClass: 'btn btn-danger btn-mini'
      }];
      return HGrid.Fmt.buttons(buttonDefs);
    };

    HGrid.Col.ActionButtons.folderView = function() {
        var buttonDefs = [];
        if (this.options.uploads) {
          buttonDefs.push({
            text: '<i class="icon-cloud-upload icon-white"></i>',
            action: 'upload',
            cssClass: 'btn btn-primary btn-mini'
          });
        }
        if (buttonDefs) {
          return HGrid.Fmt.buttons(buttonDefs);
        }
        return '';
    };


    // OSF-specific HGrid options common to all addons
    baseOptions = {
        columns: [
            HGrid.Col.Name,
            HGrid.Col.ActionButtons
        ],
        width: '100%',
        height: 700,
        fetchUrl: function(row) {
            return row.urls.fetch;
        },
        downloadUrl: function(row) {
            return row.urls.download;
        },
        deleteUrl: function(row) {
            return row.urls.delete;
        },
        onClickDelete: function(evt, row) {
            console.log(this);
            var self = this;
            // TODO: This text should be configurable by addon devs
            var msg = tpl('Are you sure you want to delete "{{name}}"?', row);
            var ajaxOptions = {
                error: function() {
                    bootbox.alert('There was a problem deleting your file. Please try again later.');
                }
            };
            bootbox.confirm(msg, function(confirmed) {
                if (confirmed) {
                    self.removeItem(row.id);
                    // Send request to delete file.
                    self.deleteFile(row, ajaxOptions);
                }
            });
            return this;
        },
        deleteMethod: 'delete',
        uploads: true,
        uploadUrl: function(row) {
            var cfgFunc = FileBrowser.getCfg(row, 'uploadUrl');
            if (cfgFunc) {
                return cfgFunc.call(this, row);
            }
            return row.urls.upload;
        },
        uploadAdded: function(file, row) {
            var parent = this.getByID(row.parentID);
            row.addon = parent.addon;
            var cfgFunc = FileBrowser.getCfg(row, 'uploadAdded');
            if (cfgFunc) {
                return cfgFunc.call(this, file, row);
            }
        },
        uploadMethod: 'post',
        listeners: [
            // Go to file's detail page if name is clicked
            {
                on: 'click',
                selector: '.hg-item-content',
                callback: function(evt, row, grid) {
                    if (row) {
                        var viewUrl = grid.getByID(row.id).urls.view;
                        if (viewUrl) {
                            window.location.href = viewUrl;
                        }
                    }
                }
            }
        ]
    };

{'fraction_non_alphanumeric': 0.11352093342484558, 'fraction_numerical': 0.0016472203157172271, 'mean_word_length': 1.3912044634066294, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6938557', 'n_tokens_mistral': 2024, 'n_tokens_neox': 1961, 'n_words': 475}