EVOLUTION-MANAGER
Edit File: config-forms.min.2a4510690ae8.js
(function(){window.Djblets=window.Djblets||{};Djblets.Config={};Djblets.Config.ListItems=Backbone.Collection.extend({initialize:function(models,options){this.options=options},fetch:function(options){this.trigger("fetching");Backbone.Collection.prototype.fetch.call(this,options)}});Djblets.Config.ListItem=Backbone.Model.extend({defaults:{text:null,editURL:null,showRemove:false,canRemove:true,loading:false,removeLabel:gettext("Remove")},initialize:function(options){options=options||{};this.actions=options.actions||[];if(this.get("showRemove")){this.actions.push({id:"delete",label:this.get("removeLabel"),danger:true,enabled:this.get("canRemove")})}}});Djblets.Config.List=Backbone.Model.extend();Djblets.Config.ListItemView=Backbone.View.extend({tagName:"li",className:"config-forms-list-item",iconBaseClassName:"djblets-icon",actionHandlers:{},template:_.template(["<% if (editURL) { %>",'<a href="<%- editURL %>"><%- text %></a>',"<% } else { %>","<%- text %>","<% } %>"].join("")),initialize:function(){this.listenTo(this.model,"actionsChanged",this.render);this.listenTo(this.model,"request",this.showSpinner);this.listenTo(this.model,"sync",this.hideSpinner);this.listenTo(this.model,"destroy",this.remove);this.$spinnerParent=null;this.$spinner=null},render:function(){this.$el.empty().append(this.template(this.model.attributes));this.addActions(this.getActionsParent());return this},remove:function(){this.$el.fadeOut("normal",_.bind(Backbone.View.prototype.remove,this))},getActionsParent:function(){return this.$el},showSpinner:function(){if(this.$spinner){return}this.$spinner=$("<span/>").addClass("fa fa-spinner fa-pulse config-forms-list-item-spinner").prependTo(this.$spinnerParent).hide().css("visibility","visible").fadeIn()},hideSpinner:function(){if(!this.$spinner){return}this.$spinner.fadeOut("slow",_.bind(function(){this.$spinner.remove();this.$spinner=null},this))},addActions:function($parentEl){var $actions=$("<span/>").addClass("config-forms-list-item-actions");_.each(this.model.actions,function(action){var $action=this._buildActionEl(action).appendTo($actions);if(action.children){if(action.label){$action.append(" ▾")}$action.click(_.bind(function(){_.defer(_.bind(this._showActionDropdown,this,action,$action))},this))}},this);this.$spinnerParent=$actions;$actions.prependTo($parentEl)},_showActionDropdown:function(action,$action){var actionPos=$action.position(),$pane=$("<ul/>").css("position","absolute").addClass("action-menu").click(function(e){e.stopPropagation()}),winWidth=$(window).width(),actionLeft=actionPos.left+$action.getExtents("m","l"),paneWidth;_.each(action.children,function(childAction){$("<li/>").addClass("config-forms-list-action-row-"+childAction.id).append(this._buildActionEl(childAction)).appendTo($pane)},this);this.trigger("actionMenuPopUp",{action:action,$action:$action,$menu:$pane});$pane.appendTo($action.parent());paneWidth=$pane.width();$pane.move($action.offset().left+paneWidth>winWidth?actionLeft+$action.innerWidth()-paneWidth:actionLeft,actionPos.top+$action.outerHeight(),"absolute");$(document).one("click",_.bind(function(){this.trigger("actionMenuPopDown",{action:action,$action:$action,$menu:$pane});$pane.remove()},this))},_buildActionEl:function(action){var actionHandlerName=action.enabled!==false?this.actionHandlers[action.id]:null,isCheckbox=action.type==="checkbox",isRadio=action.type==="radio",actionHandler,inputID,$action,$label,$result;if(isCheckbox||isRadio){inputID=_.uniqueId("action_"+action.type);$action=$("<input/>").attr({name:action.name,type:action.type,id:inputID});$label=$("<label/>").attr("for",inputID).text(action.label);if(action.id){$label.addClass("config-forms-list-action-label-"+action.id)}$result=$("<span/>").append($action).append($label);if(action.propName){if(isCheckbox){$action.bindProperty("checked",this.model,action.propName)}else if(isRadio){$action.bindProperty("checked",this.model,action.propName,{radioValue:action.radioValue})}}if(action.enabledPropName){$action.bindProperty("disabled",this.model,action.enabledPropName,{inverse:action.enabledPropInverse!==true})}if(actionHandlerName){actionHandler=_.debounce(_.bind(this[actionHandlerName],this),50,true);$action.change(actionHandler);if(isRadio&&action.dispatchOnClick){$action.click(actionHandler)}}}else{$action=$result=$('<a class="btn"/>').text(action.label||"");if(action.iconName){$action.append($("<span/>").addClass(this.iconBaseClassName).addClass(this.iconBaseClassName+"-"+action.iconName))}if(actionHandlerName){$action.click(_.bind(this[actionHandlerName],this))}}if(action.id){$action.addClass("config-forms-list-action-"+action.id)}if(action.danger){$action.addClass("danger")}if(action.enabled===false){$action.prop("disabled",true);$result.addClass("disabled")}return $result}});Djblets.Config.ListView=Backbone.View.extend({tagName:"ul",className:"config-forms-list",defaultItemView:Djblets.Config.ListItemView,initialize:function(options){var collection=this.model.collection;options=options||{};this.ItemView=options.ItemView||this.defaultItemView;this.views=[];this.animateItems=!!options.animateItems;this.once("rendered",function(){this.listenTo(collection,"add",this._addItem);this.listenTo(collection,"remove",this._removeItem);this.listenTo(collection,"reset",this._renderItems)},this)},getBody:function(){return this.$el},render:function(){this.$listBody=this.getBody();this._renderItems();this.trigger("rendered");return this},_addItem:function(item,collection,options){var view=new this.ItemView({model:item}),animateItem=options&&options.animate!==false;view.render();if(this.animateItems&&animateItem){view.$el.fadeIn()}this.$listBody.append(view.$el);this.views.push(view)},_removeItem:function(item,collection,options){var animateItem=options&&options.animate!==false,view=_.find(this.views,function(view){return view.model===item});if(view){this.views=_.without(this.views,view);if(this.animateItems&&animateItem){view.$el.fadeOut(function(){view.remove()})}else{view.remove()}}},_renderItems:function(){this.views.forEach(function(view){view.remove()});this.views=[];this.$listBody.empty();this.model.collection.each(function(item){this._addItem(item,item.collection,{animate:false})},this)}});Djblets.Config.PagesView=Backbone.View.extend({initialize:function(){this.router=new Backbone.Router({routes:{":pageID":"page"}});this.listenTo(this.router,"route:page",this._onPageChanged);this._$activeNav=null;this._$activePage=null;this._preserveMessages=true},render:function(){this._$pageNavs=this.$(".config-forms-side-nav li");this._$pages=this.$(".config-forms-page-content > .page");this._$activeNav=this._$pageNavs.eq(0).addClass("active");this._$activePage=this._$pages.eq(0).addClass("active");Backbone.history.start({root:window.location});return this},_onPageChanged:function(pageID){this._$activeNav.removeClass("active");this._$activePage.removeClass("active");this._$activePage=$("#page_"+pageID);if(this._$activePage.length===0){this.router.navigate(this._$pageNavs.find("a").attr("href").substr(1),{trigger:true,replace:true})}else{this._$activeNav=this._$pageNavs.filter(":has(a[href=#"+pageID+"])").addClass("active");this._$activePage.addClass("active");if(!this._preserveMessages){$("#messages").remove()}this._preserveMessages=false}}});Djblets.Config.TableItemView=Djblets.Config.ListItemView.extend({tagName:"tr",template:_.template(["<td>","<% if (editURL) { %>",'<a href="<%- editURL %>"><%- text %></a>',"<% } else { %>","<%- text %>","<% } %>","</td>"].join("")),getActionsParent:function(){return this.$("td:last")}});Djblets.Config.TableView=Djblets.Config.ListView.extend({tagName:"table",defaultItemView:Djblets.Config.TableItemView,render:function(){var $body=this.getBody();if($body.length===0){this.$el.append("<tbody/>")}return Djblets.Config.ListView.prototype.render.call(this)},getBody:function(){return this.$("tbody")}})}).call(this);