(function(){

    var EDIT_SELECTOR = ".edit-role";

    var EditRoleDialog = Class.$extend({
        __init__:function(pk, teamSlug){
            this.pk = pk;
            this.teamSlug = teamSlug;
            this.hide = _.bind(this.hide, this);
            this.save = _.bind(this.save, this);
            this.show = _.bind(this.show, this);
        },
        loadInfo: function(){
            TeamsApiV2.member_role_info(
                this.teamSlug,
                this.pk,
                this.show);
        },
        show: function(res){
            this.el = ich.editRoleDialog(res);
            hideEdit = this.hide;
            $body = $('body');

            $('select option[value="' + res['current_role'] + '"]', this.el).attr('selected', 'selected');

            $body.append('<div class="well"></div>');
            $target = $('div.modal', $body.append(this.el));
            $target.show();
            $select = $('select', this.el);

            $('.chzn-select', this.el).chosen();
            $("a.action-save", this.el).click(this.save);
            $("a.action-close", this.el).click(function() {
                hideEdit($target);
            });

            $select.change(this.buildRestrictions);
            $select.trigger('change');

            $target.click(function(event){
                event.stopPropagation();
            });

            $('html').bind('click.modal', function() {
                hideEdit($target);
            });
        },
        buildRestrictions: function() {
            var val = $(this).val();
            var $lang = $('#language-restriction');
            var $proj = $('#project-restriction');

            if (val == 'manager') {
                $lang.show();
                $proj.show();
            } else if (val == 'contributor') {
                $lang.hide();
                $proj.hide();
            } else if (val == 'admin') {
                $lang.hide();
                $proj.show();
            }
        },
        save: function(e){
            e.preventDefault();
            var languages = $("select.langs", this.el) .val();
            var projects = $("select.projects", this.el) .val();
            var role = $("select.roles", this.el).val();
            TeamsApiV2.save_role(
                this.teamSlug,
                this.pk,
                role,
                projects,
                languages,
                this.hide);
            displayFeedbackMessage('Member saved.', 'success');
           return false;
        },
        hide:function(e){
            this.el.remove();
            $('div.well').remove();
            $('html').unbind('click.modal');
            return false;
        }
    });
    function onEditClicked(e){
        e.preventDefault();
        var pk = $(e.target).data("member-pk");
        var teamSlug = $(e.target).data("team-slug");
        var dialog = new EditRoleDialog(pk, teamSlug);
        dialog.loadInfo();
    }
    function bootstrapButton(el){
        $(el).click(function(e){
            onEditClicked(e);
            return false;
        });
    }

    $(EDIT_SELECTOR).each(function(i,o){
        bootstrapButton(o);
    });
})();

@@ -1660,24 +1660,137 @@
 riction');%0A%0A
+            var lang_count = $('option', $lang).length;%0A            var proj_count = $('option', $proj).length;%0A%0A
             
@@ -1824,24 +1824,42 @@
             
+ if (lang_count) %7B
  $lang.show(
@@ -1852,32 +1852,34 @@
  %7B $lang.show();
+ %7D
 %0A               
@@ -1870,32 +1870,50 @@
 %0A               
+ if (proj_count) %7B
  $proj.show();%0A 
@@ -1902,32 +1902,34 @@
  %7B $proj.show();
+ %7D
 %0A            %7D e
@@ -2102,24 +2102,42 @@
             
+ if (proj_count) %7B
  $proj.show(
@@ -2130,32 +2130,34 @@
  %7B $proj.show();
+ %7D
 %0A            %7D%0A 

Fix bug where showing project restrictions with no projects is possible.