!function(){var e,t;e=this,t=function(e){"use strict";function t(e,t,s){t in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s}function s(e,t,s){if(t.has(e))return s;throw new TypeError("attempted to get private field on non-instance")}function l(e,t){var s=e;if(t.has(s))throw new TypeError("Cannot initialize the same private elements twice on an object");t.add(e)}var n,a,i;let o=Spina.spina((t(i=class extends Spina.BaseModel{enable(){return new Promise((e,s)=>{this.save({enabled:!0},{wait:!0,error:(e,t)=>{this.set({canEnable:!t.errorRsp.needs_reload,loadError:t.errorRsp.load_error,loadable:!1}),s(new Error(t.errorText))},success:()=>e()})})}disable(){return new Promise((e,t)=>{this.save({enabled:!1},{wait:!0,error:e=>t(new Error(e.errorText)),success:()=>e()})})}toJSON(){return{enabled:this.get("enabled")}}parse(e){var t=(e=void 0!==e.stat?e.extension:e).class_name,s=e.links["admin-configure"],l=e.links["admin-database"];return this.url=""+this.collection.url+t+"/",{author:e.author,authorURL:e.author_url,canDisable:e.can_disable,canEnable:e.can_enable,configURL:s?s.href:null,dbURL:l?l.href:null,enabled:e.enabled,id:t,loadError:e.load_error,loadable:e.loadable,name:e.name,summary:e.summary,version:e.version}}sync(e,t,a){return Backbone.sync.call(this,e,t,_.defaults({contentType:"application/x-www-form-urlencoded",data:t.toJSON(),processData:!0,error:(t,e,s)=>{let l,n;try{l=$.parseJSON(t.responseText),n=l.err.msg}catch(e){n="HTTP "+t.status+" "+t.statusText,l={canEnable:!1,loadError:n}}_.isFunction(a.error)&&(t.errorText=n,t.errorRsp=l,a.error(t,e,s))}},a))}},"defaults",{author:null,authorURL:null,configURL:null,dbURL:null,enabled:!1,loadError:null,loadable:!0,name:null,summary:null,version:null}),i=i))||i,r=Spina.spina((t(i=class extends Spina.BaseCollection{parse(e){return e.extensions}},"model",o),i=i))||i,d=Spina.spina((t(i=class extends Spina.BaseModel{initialize(){this.installedExtensions=new r,this.installedExtensions.url=this.get("apiRoot")}load(){this.trigger("loading"),this.installedExtensions.fetch({success:()=>this.trigger("loaded")})}},"defaults",{apiRoot:null}),i=i))||i,c=Spina.spina((n=new WeakSet,a=new WeakSet,t(i=class extends Djblets.ConfigFormsListItem{constructor(){super(...arguments),l(this,a),l(this,n)}initialize(){super.initialize(0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}),s(this,n,u).call(this),s(this,a,h).call(this),this.listenTo(this.get("extension"),"change:loadable change:loadError change:enabled",()=>{s(this,a,h).call(this),s(this,n,u).call(this)})}},"defaults",{extension:null}),i=i))||i;function u(){var e,t=this.get("extension"),s=[];t.get("loadable")?t.get("enabled")?(e=t.get("configURL"),(t=t.get("dbURL"))&&s.push({id:"database",label:gettext("Database"),url:t}),e&&s.push({id:"configure",label:gettext("Configure"),primary:!0,url:e}),s.push({danger:!0,id:"disable",label:gettext("Disable")})):s.push({id:"enable",label:gettext("Enable"),primary:!0}):s.push({id:"reload",label:gettext("Reload")}),this.setActions(s)}function h(){var e=this.get("extension");let t;t=e.get("loadable")?e.get("enabled")?"enabled":"disabled":"error",this.set("itemState",t)}let b=Spina.spina((t(i=class extends Djblets.ConfigFormsTableItemView{getRenderContext(){return this.model.get("extension").attributes}_onDisableClicked(){return this.model.get("extension").disable().catch(e=>{alert(interpolate(gettext("Failed to disable the extension: %(value1)s."),{value1:e.message},!0))})}_onEnableClicked(){return this.model.get("extension").enable().catch(e=>{alert(interpolate(gettext("Failed to enable the extension: %(value1)s."),{value1:e.message},!0))})}_onReloadClicked(){return new Promise(()=>this.model.trigger("needsReload"))}},"className","djblets-c-extension-item djblets-c-config-forms-list__item"),t(i,"actionHandlers",{disable:"_onDisableClicked",enable:"_onEnableClicked",reload:"_onReloadClicked"}),t(i,"template",_.template(`<td class="djblets-c-config-forms-list__item-main">
 <div class="djblets-c-extension-item__header">
  <h3 class="djblets-c-extension-item__name"><%- name %></h3>
  <span class="djblets-c-extension-item__version"><%- version %></span>
  <div class="djblets-c-extension-item__author">
   <% if (authorURL) { %>
    <a href="<%- authorURL %>"><%- author %></a>
   <% } else { %>
    <%- author %>
   <% } %>
  </div>
 </div>
 <p class="djblets-c-extension-item__description">
  <%- summary %>
 </p>
 <% if (!loadable) { %>
  <pre class="djblets-c-extension-item__load-error"><%-
    loadError %></pre>
 <% } %>
</td>
<td class="djblets-c-config-forms-list__item-state"></td>
<td></td>`)),i=i))||i,m=Spina.spina((t(i=class extends Spina.BaseView{initialize(){this.list=new Djblets.ConfigFormsList({},{collection:new Djblets.ConfigFormsListItems([],{model:c})})}onInitialRender(){var e=this.model;const t=this.list;this.listView=new Djblets.ConfigFormsTableView({ItemView:b,el:this.$(".djblets-c-config-forms-list"),model:t}),this.listView.render().$el.removeAttr("aria-busy").addClass("-all-items-are-multiline"),this.listenTo(e,"loading",()=>t.collection.reset()),this.listenTo(e,"loaded",this._onLoaded),e.load()}_onLoaded(){const t=this.list.collection;this.model.installedExtensions.each(e=>{e=t.add({extension:e});this.listenTo(e,"needsReload",this._reloadFull)})}_reloadFull(){this.el.submit()}},"events",{"click .djblets-c-extensions__reload":"_reloadFull"}),i=i))||i;e.ExtensionManager=d,e.ExtensionManagerView=m},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Djblets=e.Djblets||{})}.call(this);
