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

1 line
6.3 KiB
JavaScript

(function(){var c,m,g;g=[function(t){return"groupBy=substr(uid,1)"},function(t){return"uid="+t+"*&groupBy=uid"},function(t){return"uid="+t}],m=function(t,e,n){return console.log("overScheme => level",e,"over",n),1===e&&t.length>n?"uid="+t+"*&groupBy=substr(uid,"+(e+n+1)+")":null},c={actives:[{title:"markAsDone",icon:"check"}],done:[{title:"deleteNotification",icon:"trash"}],new:[{title:"save",icon:"save"}],home:[]},angular.module("llngNotificationsExplorer",["ui.tree","ui.bootstrap","llApp"]).controller("NotificationsExplorerCtrl",["$scope","$translator","$location","$q","$http","$uibModal",function(f,e,t,o,i,r){var d,n,a;return f.links=links,f.menulinks=menulinks,f.staticPrefix=staticPrefix,f.scriptname=scriptname,f.formPrefix=formPrefix,f.availableLanguages=availableLanguages,f.waiting=!0,f.showM=!1,f.showT=!0,f.showForm=!1,f.data=[],f.form={},f.formPost={},f.currentScope=null,f.currentNotification=null,f.menu=c,f.translateP=e.translateP,f.translate=e.translate,f.translateTitle=function(t){return e.translateField(t,"title")},f.menuClick=function(t){if(t.popup)window.open(t.popup);else switch(t.action||(t.action=t.title),typeof t.action){case"function":t.action(f.currentNode,f);break;case"string":f[t.action]();break;default:console.log(typeof t.action)}return f.showM=!1},f.markAsDone=function(){return f.waiting=!0,i.put(scriptname+"notifications/"+f.type+"/"+f.currentNotification.uid+"_"+f.currentNotification.reference,{done:1}).then(function(t){return f.currentNotification=null,f.currentScope.remove(),f.message={title:"notificationDeleted"},f.showModal("alert.html"),f.waiting=!1,f.init()},function(t){return f.message={title:"notificationNotDeleted",message:t.statusText},f.showModal("alert.html"),f.waiting=!1,f.init()})},f.deleteNotification=function(){return f.waiting=!0,i.delete(scriptname+"notifications/"+f.type+"/"+f.currentNotification.uid+"_"+f.currentNotification.reference+"_"+f.currentNotification.done).then(function(t){return f.currentNotification=null,f.currentScope.remove(),f.message={title:"notificationPurged"},f.showModal("alert.html"),f.waiting=!1,f.init()},function(t){return f.message={title:"notificationNotPurged",message:t.statusText},f.showModal("alert.html"),f.waiting=!1,f.init()})},f.stoggle=function(t){var e;return 0===(e=t.$modelValue).nodes.length&&f.updateTree(e.value,e.nodes,e.level,e.over,e.query,e.count),t.toggle()},f.notifDate=function(t){return null!=t?(t.match(/(\d{4})-(\d{2})-(\d{2})/)&&(t=t.substr(0,4)+t.substr(5,2)+t.substr(8,2)),new Date(t.substr(0,4),t.substr(4,2)-1,t.substr(6,2)).toLocaleDateString()):""},f.getLanguage=function(t){return f.lang=t,f.form.date?f.form.date=new Date:f.form="white",f.init(),f.showM=!1},f.$on("$locationChangeSuccess",function(t,e,n){var i;return i=e.match(/#!?\/(\w+)/),f.type=null!=i?i[1]:"actives","new"===f.type?f.displayCreateForm():(f.showForm=!1,f.init())}),d=0,f.updateTree=function(a,c,u,l,t,e){var s,n;if(f.waiting=!0,s=g[u](a,t),25<e&&(n=m(a,u,l))?(l++,s=n,u-=1):l=0,"done"!==f.type&&"actives"!==f.type||i.get(scriptname+"notifications/"+f.type+"?"+s).then(function(t){var e,n,i,o,r;if((e=t.data).result){for(n=0,i=(r=e.values).length;n<i;n++)o=r[n],d++,o.id="node"+d,u<g.length-1&&(o.nodes=[],o.level=u+1,o.query=s,o.over=l),c.push(o);""===a&&(f.total=e.total)}return f.waiting=!1},function(t){return f.waiting=!1}),console.log("Selection",f.type),f.activesStyle={color:"#777"},f.doneStyle={color:"#777"},f.newStyle={color:"#777"},"actives"===f.type&&(f.activesStyle={color:"#333"}),"done"===f.type)return f.doneStyle={color:"#333"}},f.displayNotification=function(t){var n,e;return f.waiting=!0,f.currentScope=t,e=(n=t.$modelValue).notification.replace(/#/g,"_"),"actives"===f.type&&(e=n.uid+"_"+n.reference),i.get(scriptname+"notifications/"+f.type+"/"+e).then(function(e){var t;f.currentNotification={uid:n.uid,reference:n.reference,condition:n.condition},"done"===f.type&&(f.currentNotification.done=e.data.done);try{console.log("Try to parse a JSON formated notification..."),t=JSON.parse(e.data.notifications),f.currentNotification.date=f.notifDate(t.date),f.currentNotification.text=t.text,f.currentNotification.title=t.title,f.currentNotification.subtitle=t.subtitle,f.currentNotification.check=t.check}catch(t){t,console.log("Unable to parse JSON"),f.currentNotification.notifications=e.data.notifications}return f.waiting=!1},function(t){return f.waiting=!1}),f.showT=!1},f.showModal=function(t,e){var n,i;return i=r.open({templateUrl:t,controller:"ModalInstanceCtrl",size:"lg",resolve:{elem:function(){return function(t){return f[t]}},set:function(){return function(t,e){return f[t]=e}},init:function(){return e}}}),n=o.defer(),i.result.then(function(t){return f.message={title:"",message:""},n.resolve(t)},function(t){return f.message={title:"",message:""},n.reject(t)})},f.save=function(){return f.form.uid&&f.form.reference&&f.form.xml?(f.waiting=!0,f.formPost.uid=f.form.uid,f.form.date&&(f.formPost.date=a(f.form.date)),f.formPost.reference=f.form.reference,f.formPost.condition=f.form.condition,f.formPost.xml=f.form.xml,i.post("notifications/actives",f.formPost).then(function(t){var e;return e=t.data,f.form={},1===e.result?f.message={title:"notificationCreated"}:f.message={title:"notificationNotCreated",message:e.error},f.showModal("alert.html"),f.waiting=!1,f.form.date=new Date},function(t){return f.message={title:"notificationNotCreated",message:t.statusText},f.showModal("alert.html"),f.waiting=!1,f.form.date=new Date})):(f.message={title:"incompleteForm"},f.showModal("alert.html")),f.form.date=new Date},f.init=function(){return f.waiting=!0,f.showM=!1,f.showT=!1,f.data=[],f.currentScope=null,f.currentNotification=null,o.all([e.init(f.lang),f.updateTree("",f.data,0,0)]).then(function(){return f.waiting=!1},function(t){return f.waiting=!1}),f.activeModule="notifications",f.myStyle={color:"#ffb84d"}},f.displayCreateForm=function(){return f.activesStyle={color:"#777"},f.doneStyle={color:"#777"},f.newStyle={color:"#333"},f.waiting=!0,e.init(f.lang).then(function(){return f.currentNotification=null,f.showForm=!0,f.data=[],f.waiting=!1,f.form.date=new Date})},n=t.path().match(/^\/(\w+)/),f.type=n?n[1]:"actives",f.popupopen=function(){return f.popup.opened=!0},f.dateOptions={startingDay:1,minDate:new Date},f.popup={opened:!1},a=function(t){var e,n,i;return i=t.getFullYear(),(n=t.getMonth()+1)<10&&(n="0"+n),(e=t.getDate())<10&&(e="0"+e),i+"-"+n+"-"+e}}])}).call(this);