1 line
4.0 KiB
JavaScript
1 line
4.0 KiB
JavaScript
(function(){var a=[function(d){return"groupBy=substr(uid,1)"},function(d){return"uid="+d+"*&groupBy=uid"},function(d){return"uid="+d}];var c={actives:[{title:"markAsDone",icon:"eye-close"}],done:[{title:"deleteNotification",icon:"trash"}],"new":[{title:"save",icon:"save"}],home:[]};var b=angular.module("llngNotificationsExplorer",["ui.tree","ui.bootstrap","llApp"]);b.controller("NotificationsExplorerCtrl",["$scope","$translator","$location","$q","$http",function(f,e,k,d,j){f.links=links;f.menulinks=menulinks;f.staticPrefix=staticPrefix;f.scriptname=scriptname;f.formPrefix=formPrefix;f.availableLanguages=availableLanguages;f.waiting=true;f.showM=false;f.showT=true;f.showForm=false;f.data=[];f.form={};f.currentScope=null;f.currentNotification=null;f.menu=c;f.translateP=e.translateP;f.translate=e.translate;f.translateTitle=function(l){return e.translateField(l,"title")};f.menuClick=function(l){if(l.popup){window.open(l.popup)}else{if(!l.action){l.action=l.title}switch(typeof l.action){case"function":l.action(f.currentNode,f);break;case"string":f[l.action]();break;default:console.log(typeof l.action)}}f.showM=false};f.markAsDone=function(){f.waiting=true;j.put(scriptname+"notifications/"+f.type+"/"+f.currentNotification.uid+"_"+f.currentNotification.reference,{done:1}).success(function(l){f.currentNotification=null;f.currentScope.remove();f.waiting=false}).error(function(l,m){f.currentNotification=null;f.currentScope.remove();f.waiting=false})};f.deleteNotification=function(){f.waiting=true;j["delete"](scriptname+"notifications/"+f.type+"/"+f.currentNotification.done).success(function(l){f.currentNotification=null;f.currentScope.remove();f.waiting=false}).error(function(l,m){f.currentNotification=null;f.currentScope.remove();f.waiting=false})};f.stoggle=function(l){var m=l.$modelValue;if(m.nodes.length==0){f.updateTree(m.value,m.nodes,m.level,m.query)}l.toggle()};f.notifDate=function(l){if(l!==null){var m=new Date(l.substr(0,4),l.substr(4,2)-1,l.substr(6,2));return m.toLocaleDateString()}return""};f.getLanguage=function(l){f.lang=l;f.form="white";f.init();f.showM=false};var h=function(m,l,o){var p=l.match(/#\/(\w+)/);if(p===null){f.type="actives"}else{f.type=p[1]}if(f.type=="new"){f.displayCreateForm()}else{f.showForm=false;f.init()}};f.$on("$locationChangeSuccess",h);var g=0;f.updateTree=function(o,m,p,l){f.waiting=true;var n=a[p](o,l);j.get(scriptname+"notifications/"+f.type+"?"+n).success(function(q){if(q.result){q.values.forEach(function(r){g++;r.id="node"+g;if(p<a.length-1){r.nodes=[];r.level=p+1;r.query=n}m.push(r)})}f.waiting=false}).error(function(q,r){f.waiting=false})};f.displayNotification=function(l){f.waiting=true;f.currentScope=l;var m=l.$modelValue;var n=m.notification;if(f.type=="actives"){n=m.uid+"_"+m.reference}j.get(scriptname+"notifications/"+f.type+"/"+n).success(function(o){f.currentNotification={uid:m.uid,reference:m.reference,condition:m.condition};if(f.type=="actives"){f.currentNotification.notifications=o.notifications}else{f.currentNotification.done=o.done}f.waiting=false}).error(function(o,p){f.waiting=false});f.showT=false};f.save=function(){if(f.form.uid&&f.form.reference&&f.form.xml&&f.form.date){f.waiting=true;var m=f.form.date.getFullYear();var n=f.form.date.getMonth()+1;if(n<10){n="0"+n}var l=f.form.date.getDate();if(l<10){l="0"+l}f.form.date=m+"-"+n+"-"+l;j.post("notifications/actives",f.form).success(function(o){f.form={};if(o.result==1){alert(e.translate("notificationCreated"))}else{alert(e.translateP("__notificationNotCreated__ ("+o.error+")"))}f.waiting=false}).error(function(o,p){f.waiting=false})}else{alert(e.translate("incompleteForm"))}};f.init=function(){var l;f.waiting=true;f.data=[];d.all([e.init(f.lang),f.updateTree("",f.data,0)]).then(function(){f.waiting=false},function(m,n){f.waiting=false})};f.displayCreateForm=function(){f.waiting=true;e.init(f.lang).then(function(){f.currentNotification=null;f.showForm=true;f.data=[];f.waiting=false;f.form.date=new Date()})};var i=k.path().match(/^\/(\w+)/);f.type=i?i[1]:"actives";f.popupopen=function(){f.popup.opened=true};f.popup={opened:false}}])})(); |