{"size": 1591, "ext": "js", "max_stars_repo_path": "packages/girder/plugins/user_quota/girder_user_quota/web_client/views/extendView.js", "max_stars_repo_name": "ShenQianwithC/HistomicsTK", "max_stars_repo_stars_event_min_datetime": "2019-11-14T18:13:26.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-14T18:13:26.000Z", "max_issues_repo_path": "packages/girder/plugins/user_quota/girder_user_quota/web_client/views/extendView.js", "max_issues_repo_name": "ShenQianwithC/HistomicsTK", "max_issues_repo_issues_event_min_datetime": "2018-11-15T19:52:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T21:56:22.000Z", "max_forks_repo_path": "packages/girder/plugins/user_quota/girder_user_quota/web_client/views/extendView.js", "max_forks_repo_name": "ShenQianwithC/HistomicsTK", "max_forks_repo_forks_event_min_datetime": "2018-05-21T19:45:19.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-08T19:53:07.000Z"}
{"max_stars_count": 1, "max_issues_count": 3, "max_forks_count": 3, "avg_line_length": 31.1960784314, "max_line_length": 84, "alphanum_fraction": 0.5813953488}
import $ from 'jquery';

import { AccessType } from 'girder/constants';
import { getCurrentUser } from 'girder/auth';
import { wrap } from 'girder/utilities/PluginUtils';

import QuotaPoliciesWidget from './QuotaPoliciesWidget';

function extendView(View, Template, modelType) {
    var eventSelector = 'click .g-' + modelType + '-policies';
    View.prototype.events[eventSelector] = 'editPolicies';

    var _initialize = View.prototype.initialize;
    View.prototype.initialize = function (settings) {
        this.quota = ((settings || {}).dialog === 'quota');
        _initialize.apply(this, arguments);
    };

    wrap(View, 'render', function (render) {
        var el, settings;
        /* Add the quota menu item to the resource menu as needed */
        render.call(this);
        el = $('.g-' + modelType + '-header a.g-delete-' + modelType).closest('li');
        settings = {
            AccessType: AccessType,
            currentUser: getCurrentUser()
        };
        settings[modelType] = this.model;
        el.before(Template(settings));
        if (this.quota) {
            this.quota = null;
            this.editPolicies();
        }
    });

    View.prototype.editPolicies = function () {
        var widget = new QuotaPoliciesWidget({
            el: $('#g-dialog-container'),
            model: this.model,
            modelType: modelType,
            parentView: this
        }).on('g:saved', function () {
            this.render();
        }, this).on('g:hidden', function () {
            widget.destroy();
        });
    };
}

export default extendView;
