1 line
4.8 KiB
JavaScript
1 line
4.8 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","$uibModal",function(m,d,g,h,k,e){m.links=links;m.menulinks=menulinks;m.staticPrefix=staticPrefix;m.scriptname=scriptname;m.formPrefix=formPrefix;m.availableLanguages=availableLanguages;m.waiting=true;m.showM=false;m.showT=true;m.showForm=false;m.data=[];m.form={};m.formPost={};m.currentScope=null;m.currentNotification=null;m.menu=c;m.translateP=d.translateP;m.translate=d.translate;m.translateTitle=function(n){return d.translateField(n,"title")};m.menuClick=function(n){if(n.popup){window.open(n.popup)}else{if(!n.action){n.action=n.title}switch(typeof n.action){case"function":n.action(m.currentNode,m);break;case"string":m[n.action]();break;default:console.log(typeof n.action)}}m.showM=false};m.markAsDone=function(){m.waiting=true;k.put(scriptname+"notifications/"+m.type+"/"+m.currentNotification.uid+"_"+m.currentNotification.reference,{done:1}).success(function(n){m.currentNotification=null;m.currentScope.remove();m.waiting=false}).error(function(n,o){m.currentNotification=null;m.currentScope.remove();m.waiting=false})};m.deleteNotification=function(){m.waiting=true;k["delete"](scriptname+"notifications/"+m.type+"/"+m.currentNotification.done).success(function(n){m.currentNotification=null;m.currentScope.remove();m.waiting=false}).error(function(n,o){m.currentNotification=null;m.currentScope.remove();m.waiting=false})};m.stoggle=function(n){var o=n.$modelValue;if(o.nodes.length==0){m.updateTree(o.value,o.nodes,o.level,o.query)}n.toggle()};m.notifDate=function(n){if(n!==null){if(n.match(/(\d{4})-(\d{2})-(\d{2})/)){n=n.substr(0,4)+n.substr(5,2)+n.substr(8,2)}var o=new Date(n.substr(0,4),n.substr(4,2)-1,n.substr(6,2));return o.toLocaleDateString()}return""};m.getLanguage=function(n){m.lang=n;m.form="white";m.init();m.showM=false};var i=function(p,o,q){var r=o.match(/#\/(\w+)/);if(r===null){m.type="actives"}else{m.type=r[1]}if(m.type=="new"){m.displayCreateForm()}else{m.showForm=false;m.init()}};m.$on("$locationChangeSuccess",i);var l=0;m.updateTree=function(q,o,r,n){m.waiting=true;var p=a[r](q,n);k.get(scriptname+"notifications/"+m.type+"?"+p).success(function(s){if(s.result){s.values.forEach(function(t){l++;t.id="node"+l;if(r<a.length-1){t.nodes=[];t.level=r+1;t.query=p}o.push(t)})}m.waiting=false}).error(function(s,t){m.waiting=false})};m.displayNotification=function(n){m.waiting=true;m.currentScope=n;var o=n.$modelValue;var p=o.notification;if(m.type=="actives"){p=o.uid+"_"+o.reference}k.get(scriptname+"notifications/"+m.type+"/"+p).success(function(q){m.currentNotification={uid:o.uid,reference:o.reference,condition:o.condition};if(m.type=="actives"){m.currentNotification.notifications=q.notifications}else{m.currentNotification.done=q.done}m.waiting=false}).error(function(q,r){m.waiting=false});m.showT=false};m.showModal=function(o,q){var n=e.open({templateUrl:o,controller:"ModalInstanceCtrl",size:"lg",resolve:{elem:function(){return function(r){return m[r]}},set:function(){return function(t,r){m[t]=r}},init:function(){return q}}});var p=h.defer();n.result.then(function(r){m.message={title:"",message:"",};p.resolve(r)},function(r){m.message={title:"",message:"",};p.reject(r)});return n.result};m.save=function(){if(m.form.uid&&m.form.reference&&m.form.xml&&m.form.date){m.waiting=true;m.formPost.uid=m.form.uid;m.formPost.date=f(m.form.date);m.formPost.reference=m.form.reference;m.formPost.condition=m.form.condition;m.formPost.xml=m.form.xml;k.post("notifications/actives",m.formPost).success(function(n){m.form={};if(n.result==1){m.message={title:"notificationCreated"};m.showModal("alert.html")}else{m.message={title:"notificationNotCreated",message:n.error};m.showModal("alert.html")}m.waiting=false}).error(function(n,o){m.message={title:"notificationNotCreated",message:n.error};m.showModal("alert.html");m.waiting=false})}else{m.message={title:"incompleteForm"};m.showModal("alert.html")}};m.init=function(){var n;m.waiting=true;m.data=[];h.all([d.init(m.lang),m.updateTree("",m.data,0)]).then(function(){m.waiting=false},function(o,p){m.waiting=false})};m.displayCreateForm=function(){m.waiting=true;d.init(m.lang).then(function(){m.currentNotification=null;m.showForm=true;m.data=[];m.waiting=false;m.form.date=new Date()})};var j=g.path().match(/^\/(\w+)/);m.type=j?j[1]:"actives";m.popupopen=function(){m.popup.opened=true};m.popup={opened:false};var f=function(q){var p=q.getFullYear();var r=q.getMonth()+1;if(r<10){r="0"+r}var o=q.getDate();if(o<10){o="0"+o}var n=p+"-"+r+"-"+o;return n}}])})(); |