(function(){(function(){var GroupMembershipItem,GroupMembershipItemView,SiteGroupsView;GroupMembershipItem=Djblets.Config.ListItem.extend({defaults:_.defaults({localSiteName:null,displayName:null,groupName:null,joined:false,showRemove:false,url:null},Djblets.Config.ListItem.prototype.defaults),initialize:function(){var name=this.get("name"),localSiteName=this.get("localSiteName");Djblets.Config.ListItem.prototype.initialize.call(this);this.set({text:name,editURL:this.get("url")});this.group=new RB.ReviewGroup({id:this.get("reviewGroupID"),name:name,localSitePrefix:localSiteName?"s/"+localSiteName+"/":""});this.on("change:joined",this._updateActions,this);this._updateActions()},joinGroup:function(){this.group.addUser(RB.UserSession.instance.get("username"),{success:function(){this.set("joined",true)}},this)},leaveGroup:function(){this.group.removeUser(RB.UserSession.instance.get("username"),{success:function(){this.set("joined",false)}},this)},_updateActions:function(){if(this.get("joined")){this.actions=[{id:"leave",label:gettext("Leave")}]}else{this.actions=[{id:"join",label:gettext("Join")}]}this.trigger("actionsChanged")}});GroupMembershipItemView=Djblets.Config.ListItemView.extend({actionHandlers:{join:"_onJoinClicked",leave:"_onLeaveClicked"},template:_.template(['<span class="config-group-name">',' <a href="<%- editURL %>"><%- text %></a>',"</span>",'<span class="config-group-display-name"><%- displayName %></span>'].join("")),_onJoinClicked:function(){this.model.joinGroup()},_onLeaveClicked:function(){this.model.leaveGroup()}});SiteGroupsView=Backbone.View.extend({template:_.template(["<% if (name) { %>"," <h3><%- name %></h3>","<% } %>",'<div class="groups" />'].join("")),initialize:function(options){this.name=options.name;this.collection=new RB.FilteredCollection(null,{collection:new Backbone.Collection(options.groups,{model:GroupMembershipItem})});this.groupList=new Djblets.Config.List({},{collection:this.collection})},render:function(){this._listView=new Djblets.Config.ListView({ItemView:GroupMembershipItemView,model:this.groupList});this.$el.html(this.template({name:this.name}));this._listView.render();this._listView.$el.addClass("box-recessed").appendTo(this.$(".groups"));return this},filterBy:function(name){this.collection.setFilters({name:name});this.$el.setVisible(this.collection.length>0)}});RB.JoinedGroupsView=Backbone.View.extend({template:_.template(['<div class="search">',' <span class="rb-icon rb-icon-search-dark"></span>',' <input type="text" />',"</div>",'<div class="group-lists" />'].join("")),events:{"keyup .search input":"_onGroupSearchChanged","change .search input":"_onGroupSearchChanged"},initialize:function(options){this.groups=options.groups;this._$listsContainer=null;this._$search=null;this._searchText=null;this._groupViews=[]},render:function(){this.$el.html(this.template());this._$listsContainer=this.$(".group-lists");this._$search=this.$(".search input");_.each(this.groups,function(groups,localSiteName){var view;if(groups.length>0){view=new SiteGroupsView({name:localSiteName,groups:groups});view.$el.appendTo(this._$listsContainer);view.render();this._groupViews.push(view)}},this);return this},_onGroupSearchChanged:function(){var text=this._$search.val();if(text!==this._searchText){this._searchText=text;_.each(this._groupViews,function(groupView){groupView.filterBy(this._searchText)},this)}}})})()}).call(this);