lemonldap-ng/lemonldap-ng-manager/site/htdocs/static/js/viewer.min.js

1 line
8.2 KiB
JavaScript

(function(){angular.module("llngViewer",["ui.tree","ui.bootstrap","llApp","ngCookies"]).controller("TreeCtrl",["$scope","$http","$location","$q","$uibModal","$translator","$cookies","$htmlParams",function(f,u,r,c,a,n,o,e){var l,s,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),o.put("showhelp",e?"true":"false",{expires:t})},f.showH="false"!==o.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,o;return o=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=c.defer(),o.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},s=function(a){var e,i;return e=c.defer(),i=c.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,o,r;if(r=[],a.nodes)for(e=0,t=(o=a.nodes).length;e<t;e++)n=o[e],r.push(s(n));return c.all(r).then(function(){return i.resolve()})}),i.promise},f.down=function(){var e,t,n,o,r,a,i;for(g=f.currentNode.id,t=(r=f.currentScope.$parentNodeScope.$modelValue).nodes.length,e=n=0,o=(a=r.nodes).length;n<o;e=++n)a[e].id===g&&(t=e);return t<r.nodes.length-1&&(i=r.nodes[t],r.nodes[t]=r.nodes[t+1],r.nodes[t+1]=i),t},f.up=function(){var e,t,n,o,r,a,i;for(g=f.currentNode.id,t=-1,e=n=0,o=(a=(r=f.currentScope.$parentNodeScope.$modelValue).nodes).length;n<o;e=++n)a[e].id===g&&(t=e);return 0<t&&(i=r.nodes[t],r.nodes[t]=r.nodes[t-1],r.nodes[t-1]=i),t},f.inSelect=function(e){var t,n,o;for(t=0,n=(o=f.currentNode.select).length;t<n;t++)if(o[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,o;for(t in e=e||f,o=f.filters)if(n=o[t],f.filters.hasOwnProperty(t))return window.filterFunctions[t](e,c,n);return!1},f.stoggle=function(e){var t;return t=e.$modelValue,d(t),e.toggle()},d=function(e){var t,n,o,r,a,i,l,s,u,c,d;for(n=0,o=(u=["nodes","nodes_cond"]).length;n<o;n++)if(e["_"+(l=u[n])]){for(e[l]=[],i=0,r=(c=e["_"+l]).length;i<r;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,e;return(i=c.defer()).notify("Trying to get datas"),f.waiting=!0,console.log("Trying to get key "+a.cnodes),e=encodeURI(a.cnodes),u.get(""+window.confPrefix+f.currentCfg.cfgNum+"/"+e).then(function(e){var t,n,o,r;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=[],o=0,r=n.length;o<r;o++)(t=n[o]).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,o,r,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,o=(i=a.nodes).length;n<o;n++)r=i[n],f.getKey(r);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 o,e,t,r,a,i,l,s;if(o=c.defer(),n.data)n.data.toString().match(/_Hidden_$/)&&(n.type="text",n.data="######"),o.resolve(n.data);else if(f.waiting=!0,n.get&&"object"==typeof n.get){for(n.data=[],l=[],e=t=0,r=(i=n.get).length;t<r;e=++t)a=i[e],n.data[e]={title:a,id:a},l.push(f.getKey(n.data[e]));c.all(l).then(function(){return o.resolve(n.data)},function(e){return o.reject(e.statusLine),f.waiting=!1})}else s="",n.get?(console.log("Trying to get key "+n.get),s=encodeURI(n.get)):console.log("Trying to get title "+n.title),u.get(""+window.confPrefix+f.currentCfg.cfgNum+"/"+(n.get?s: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,o.resolve(n.data)},function(e){return m(e),o.reject(e.status)});return o.promise},t=function(e,t,n){var o;return null===(o=t.match(new RegExp("#!?/view/(latest|[0-9]+)")))?r.path("/view/latest"):(console.log("Trying to get cfg number "+o[1]),f.getCfg(o[1]))},f.$on("$locationChangeSuccess",t),f.getCfg=function(n){return f.currentCfg.cfgNum!==n?u.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"),r.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,c.all([n.init(f.lang),u.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"}},!r.path().match(new RegExp("^/view/(latest|[0-9]+)")))return console.log("Redirecting to /view/latest"),r.path("/view/latest")}])}).call(this);