lemonldap-ng/lemonldap-ng-manager/site/htdocs/static/js/viewer.min.js
2019-08-21 15:55:22 +02:00

1 line
8.1 KiB
JavaScript

(function(){angular.module("llngViewer",["ui.tree","ui.bootstrap","llApp","ngCookies"]).controller("TreeCtrl",["$scope","$http","$location","$q","$uibModal","$translator","$cookies","$htmlParams",function(f,s,o,u,a,n,r,e){var l,c,d,g,t,m,p;if(f.links=window.links,f.menu=e.menu,f.menulinks=window.menulinks,f.staticPrefix=window.staticPrefix,f.formPrefix=window.formPrefix,f.availableLanguages=window.availableLanguages,f.waiting=!0,f.showM=!1,f.showT=!1,f.form="homeViewer",f.currentCfg={},f.viewPrefix=window.viewPrefix,f.allowDiff=window.allowDiff,f.message={},f.result="",f.translateTitle=function(e){return n.translateField(e,"title")},f.translateP=n.translateP,f.translate=n.translate,f.helpUrl="start.html#configuration",f.setShowHelp=function(e){var t;return null==e&&(e=!f.showH),f.showH=e,(t=new Date(Date.now())).setFullYear(t.getFullYear()+1),r.put("showhelp",e?"true":"false",{expires:t})},f.showH="false"!==r.get("showhelp"),null==f.showH&&f.setShowHelp(!0),m=function(e){var t,n;return t=e.status,n=e.statusLine,f.waiting=!1,403===t?f.message={title:"forbidden",message:"",items:[]}:401===t?(console.log("Authentication needed"),f.message={title:"authenticationNeeded",message:"__waitOrF5__",items:[]}):f.message=400===t?{title:"badRequest",message:n,items:[]}:0<t?{title:"badRequest",message:n,items:[]}:{title:"networkProblem",message:"",items:[]},f.showModal("message.html")},f.showModal=function(e,t){var n,r;return r=a.open({templateUrl:e,controller:"ModalInstanceCtrl",size:"lg",resolve:{elem:function(){return function(e){return f[e]}},set:function(){return function(e,t){return f[e]=t}},init:function(){return t}}}),n=u.defer(),r.result.then(function(e){return f.message={title:"",message:"",items:[]},n.resolve(e)},function(e){return f.message={title:"",message:"",items:[]},n.reject(e)}),n.promise},f.menuClick=function(e){if(e.popup)window.open(e.popup);else switch(e.action||(e.action=e.title),typeof e.action){case"function":e.action(f.currentNode,f);break;case"string":f[e.action]();break;default:console.log(typeof e.action)}return f.showM=!1},f.home=function(){return f.form="homeViewer",f.showM=!1},f.downloadConf=function(){return window.open(f.viewPrefix+f.currentCfg.cfgNum+"?full=1")},g=1,f._findContainer=function(){return f._findScopeContainer().$modelValue},f._findScopeContainer=function(){var e;for(e=f.currentScope;!e.$modelValue.type.match(/Container$/);)e=e.$parentNodeScope;return e},f._findScopeByKey=function(e){var t;for(t=f.currentScope;t.$modelValue.title!==e;)t=t.$parentNodeScope;return t},c=function(a){var e,i;return e=u.defer(),i=u.defer(),a._nodes?(d(a),e.resolve()):a.cnodes?l(a).then(function(){return e.resolve()}):a.nodes||a.data?e.resolve():f.getKey(a).then(function(){return e.resolve()}),e.promise.then(function(){var e,t,n,r,o;if(o=[],a.nodes)for(e=0,t=(r=a.nodes).length;e<t;e++)n=r[e],o.push(c(n));return u.all(o).then(function(){return i.resolve()})}),i.promise},f.down=function(){var e,t,n,r,o,a,i;for(g=f.currentNode.id,t=(o=f.currentScope.$parentNodeScope.$modelValue).nodes.length,e=n=0,r=(a=o.nodes).length;n<r;e=++n)a[e].id===g&&(t=e);return t<o.nodes.length-1&&(i=o.nodes[t],o.nodes[t]=o.nodes[t+1],o.nodes[t+1]=i),t},f.up=function(){var e,t,n,r,o,a,i;for(g=f.currentNode.id,t=-1,e=n=0,r=(a=(o=f.currentScope.$parentNodeScope.$modelValue).nodes).length;n<r;e=++n)a[e].id===g&&(t=e);return 0<t&&(i=o.nodes[t],o.nodes[t]=o.nodes[t-1],o.nodes[t-1]=i),t},f.inSelect=function(e){var t,n,r;for(t=0,n=(r=f.currentNode.select).length;t<n;t++)if(r[t].k===e)return!0;return!1},f.changeRuleTitle=function(e){return e.title=0<e.comment.length?e.comment:e.re},f.filters={},f.execFilters=function(e){var t,n,r;for(t in e=e||f,r=f.filters)if(n=r[t],f.filters.hasOwnProperty(t))return window.filterFunctions[t](e,u,n);return!1},f.stoggle=function(e){var t;return t=e.$modelValue,d(t),e.toggle()},d=function(e){var t,n,r,o,a,i,l,s,u,c,d;for(n=0,r=(u=["nodes","nodes_cond"]).length;n<r;n++)if(e["_"+(l=u[n])]){for(e[l]=[],i=0,o=(c=e["_"+l]).length;i<o;i++)t=c[i],e[l].push(t);delete e["_"+l]}if(e._nodes_filter){if(e.nodes)for(s=0,a=(d=e.nodes).length;s<a;s++)(l=d[s]).onChange=f.execFilters;return f.filters[e._nodes_filter]=e,f.execFilters()}},f.toggle=function(e){return e.toggle()},f.download=function(e){var t;return t=e.$modelValue,l(t)},l=function(a){var i;return(i=u.defer()).notify("Trying to get datas"),f.waiting=!0,s.get(""+window.viewPrefix+f.currentCfg.cfgNum+"/"+a.cnodes).then(function(e){var t,n,r,o;if(n=e.data)if(n.error)n.error.match(/setDefault$/)?(a.default?a.nodes=a.default.slice(0):a.nodes=[],delete a.cnodes,i.resolve("Set data to default value")):i.reject("Server return an error: "+n.error);else{for(delete a.cnodes,a.type||(a.type="keyTextContainer"),a.nodes=[],r=0,o=n.length;r<o;r++)(t=n[r]).template&&(t._nodes=templates(t.template,t.title)),a.nodes.push(t);i.resolve("OK")}else i.reject("Empty response from server");return f.waiting=!1},function(e){return m(e),i.reject("")}),i.promise},f.openCnode=function(e){return f.download(e).then(function(){return e.toggle()})},p=function(e){for(;!e.$modelValue.help&&e.$parentNodeScope;)e=e.$parentNodeScope;return f.helpUrl=e.$modelValue.help||"start.html#configuration"},f.displayForm=function(e){var t,n,r,o,a,i;if((a=e.$modelValue).cnodes&&f.download(e),a._nodes&&f.stoggle(e),f.currentNode=a,f.currentScope=e,t=a.type?a.type:"text",a.nodes||a._nodes||a.cnodes?f.form="text"!==t?t:"mini":(f.form=t,f.getKey(a)),a.type&&"simpleInputContainer"===a.type)for(n=0,r=(i=a.nodes).length;n<r;n++)o=i[n],f.getKey(o);return f.showT=!1,p(e)},f.keyWritable=function(e){var t;return!(!(t=e.$modelValue).type||!t.type.match(/^(?:s(?:aml(?:(?:ID|S)PMetaDataNod|Attribut)e|fExtra)|(?:(?:cmbMod|r)ul|authChoic)e|(?:virtualHos|keyTex)t|menu(?:App|Cat))$/))},f.getKey=function(n){var r,e,t,o,a,i,l;if(r=u.defer(),n.data)n.data.toString().match(/_Hidden_$/)&&(n.type="text",n.data="######"),r.resolve(n.data);else if(f.waiting=!0,n.get&&"object"==typeof n.get){for(n.data=[],l=[],e=t=0,o=(i=n.get).length;t<o;e=++t)a=i[e],n.data[e]={title:a,id:a},l.push(f.getKey(n.data[e]));u.all(l).then(function(){return r.resolve(n.data)},function(e){return r.reject(e.statusLine),f.waiting=!1})}else s.get(""+window.viewPrefix+f.currentCfg.cfgNum+"/"+(n.get?n.get:n.title)).then(function(e){var t;return(null===(t=e.data).value||t.error&&t.error.match(/setDefault$/))&&null!==n.default?n.data=n.default:n.data=t.value,n.data&&n.data.toString().match(/_Hidden_$/)&&(n.type="text",n.data="######"),n.type&&n.type.match(/^(bool|trool|boolOrExpr)$/)&&"string"==typeof n.data&&n.data.match(/^(?:-1|0|1)$/)&&(n.data=parseInt(n.data,10)),n.type&&n.type.match(/^int$/)?n.data=parseInt(n.data,10):n.type&&n.type.match(/^(saml(Service|Assertion)|blackWhiteList)$/)&&"object"!=typeof n.data&&(n.data=n.data.split(";")),f.waiting=!1,r.resolve(n.data)},function(e){return m(e),r.reject(e.status)});return r.promise},t=function(e,t,n){var r;return null===(r=t.match(new RegExp("#!?/view/(latest|[0-9]+)")))?o.path("/view/latest"):(console.log("Trying to get cfg number "+r[1]),f.getCfg(r[1]))},f.$on("$locationChangeSuccess",t),f.getCfg=function(n){return f.currentCfg.cfgNum!==n?s.get(""+window.viewPrefix+n).then(function(e){var t;return f.currentCfg=e.data,t=new Date(1e3*f.currentCfg.cfgDate),f.currentCfg.date=t.toLocaleString(),console.log("Metadatas of cfg "+n+" loaded"),o.path("/view/"+n),f.init()},function(e){return m(e).then(function(){return f.currentCfg.cfgNum=0,f.init()})}):f.waiting=!1},f.getLanguage=function(e){return f.lang=e,f.form="white",f.init(),f.showM=!1},f.init=function(){var t;return t=null,f.waiting=!0,f.data=[],f.confirmNeeded=!1,f.forceSave=!1,u.all([n.init(f.lang),s.get(window.staticPrefix+"struct.json").then(function(e){return t=e.data,console.log("Structure loaded")})]).then(function(){return console.log("Starting structure binding"),f.data=t,t=null,0!==f.currentCfg.cfgNum?setScopeVars(f):(f.message={title:"emptyConf",message:"__zeroConfExplanations__"},f.showModal("message.html")),f.form="homeViewer",f.waiting=!1},m),f.activeModule="viewer",f.myStyle={color:"#ffb84d"}},!o.path().match(new RegExp("^/view/(latest|[0-9]+)")))return console.log("Redirecting to /view/latest"),o.path("/view/latest")}])}).call(this);