(function(){

    var EDIT_SELECTOR = ".edit-role";

    var EditRoleDialog = Class.$extend({
        __init__:function(pk, username, teamSlug){
            this.pk = pk;
            this.username = username;
            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){
            res['username'] = this.username;
            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');

            var lang_count = $('option', $lang).length;
            var proj_count = $('option', $proj).length;

            if (val == 'manager') {
                if (lang_count) { $lang.show(); }
                if (proj_count) { $proj.show(); }
            } else if (val == 'contributor') {
                $lang.hide();
                $proj.hide();
            } else if (val == 'admin') {
                $lang.hide();
                if (proj_count) { $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);
            return false;
        },
        hide:function(e){
            this.el.remove();
            $('div.well').remove();
            $('html').unbind('click.modal');
            if (window.roleSavedURL) {
                window.location = window.roleSavedURL;
            }
            return false;
        }
    });
    function onEditClicked(e){
        e.preventDefault();
        var pk = $(e.target).data("member-pk");
        var username = $(e.target).data("member-username");
        var teamSlug = $(e.target).data("team-slug");
        var dialog = new EditRoleDialog(pk, username, teamSlug);
        dialog.loadInfo();
    }
    function bootstrapButton(el){
        $(el).click(function(e){
            onEditClicked(e);
            return false;
        });
    }

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

@@ -31,17 +31,17 @@
 ECTOR = 
-%22
+'
 .edit-ro
@@ -42,17 +42,17 @@
 dit-role
-%22
+'
 ;%0A%0A    v
@@ -281,32 +281,103 @@
 is.hide, this);%0A
+            this.hideAndRedirect = _.bind(this.hideAndRedirect, this);%0A
             this
@@ -1173,33 +1173,33 @@
 ;%0A            $(
-%22
+'
 a.action-save%22, 
@@ -1195,17 +1195,17 @@
 ion-save
-%22
+'
 , this.e
@@ -1239,17 +1239,17 @@
       $(
-%22
+'
 a.action
@@ -1254,17 +1254,17 @@
 on-close
-%22
+'
 , this.e
@@ -2415,25 +2415,25 @@
 nguages = $(
-%22
+'
 select.langs
@@ -2432,17 +2432,17 @@
 ct.langs
-%22
+'
 , this.e
@@ -2477,25 +2477,25 @@
 rojects = $(
-%22
+'
 select.proje
@@ -2497,17 +2497,17 @@
 projects
-%22
+'
 , this.e
@@ -2542,17 +2542,17 @@
 ole = $(
-%22
+'
 select.r
@@ -2555,17 +2555,17 @@
 ct.roles
-%22
+'
 , this.e
@@ -2764,16 +2764,27 @@
 his.hide
+AndRedirect
 );%0A     
@@ -2828,16 +2828,17 @@
    hide:
+ 
 function
@@ -2949,24 +2949,211 @@
 ck.modal');%0A
+            return false;%0A        %7D,%0A        hideAndRedirect: function(e) %7B%0A            this.el.remove();%0A            $('div.well').remove();%0A            $('html').unbind('click.modal');%0A
             
@@ -3296,38 +3296,80 @@
 %7D);%0A
+%0A
     
-function onEditClicked(e)%7B
+$('a.edit-role').click(function(e) %7B%0A        console.log(e.target);
 %0A   
@@ -3423,25 +3423,25 @@
 arget).data(
-%22
+'
 member-pk%22);
@@ -3437,17 +3437,17 @@
 ember-pk
-%22
+'
 );%0A     
@@ -3481,17 +3481,17 @@
 t).data(
-%22
+'
 member-u
@@ -3497,17 +3497,17 @@
 username
-%22
+'
 );%0A     
@@ -3541,17 +3541,17 @@
 t).data(
-%22
+'
 team-slu
@@ -3551,17 +3551,17 @@
 eam-slug
-%22
+'
 );%0A     
@@ -3655,219 +3655,24 @@
     
-%7D%0A    function bootstrapButton(el)%7B%0A        $(el).click(function(e)%7B%0A            onEditClicked(e);%0A            return false;%0A        %7D);%0A    %7D%0A%0A    $(EDIT_SELECTOR).each(function(i,o)%7B%0A        bootstrapButton(o)
+    return false
 ;%0A  

Fix bugs with role-modal hide, remove overly verbose code.