function htmlEntities(str) { return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); } class NodeLinks{ constructor(elLinks){ // is APIobj["links"] this.elLinks=elLinks; this.lookup={ "documents":"Documenti", "transactions":"Contabilità", "questions":"Domande", "events":"Eventi", "feedbacks":"Feedbacks" } } computeHTML(){ if(!this.elLinks) return ""; this.html='"; return this.html; } } class Tags{ constructor(tags){ this.tags=tags; } computeHTML(){ if(this.tags!=null&&this.tags.length>0){ this.html+="

Tag

"; this.tags.forEach(element => { this.html+='

'+htmlEntities(element)+'

'; }); } } } function eurSet(eur) { } class ElementPreviewList{ constructor(){ this.k2it={ "planned": "Previsto il", "executed": "Effettuato il", "amount": "Importo", "title": "Titolo", "shortDescription": "Descrizione breve", "htmlDescription": "Testo in html", "createdDate": "Data di creazione", "publishedDate": "Data di pubblicazione", "lastEditedDate": "Data di ultima modifica", "thumbnailUrl": "Url anteprima", "documentUrl": "Url documento", "startDate": "Data inizio", "endDate": "Data fine", "participants": "Partecipanti", "isAssembly": "Tipo", "publishResultsDate": "Data pubblicazione dei risultati", "questionTitle": "Titolo domanda", "questionText": "Domanda", "answerTitle": "Titolo risposta", "answerText": "Risposta", "askDate": "Data richiesta", "answerDate": "Data risposta", "asker": "Richiedente", "replier": "Rispondente" }; } itLookup(key){ return this.k2it[key]?this.k2it[key]:key; } itLookupPairDict(dict,key){ return { "value":dict[key]?dict[key]:"", "name":this.itLookup(key) }; } textGen(title,value){ if(value && title){ return "

"+htmlEntities(title)+"


"+htmlEntities(value)+"

"; } return ""; } listgen(title,values=[],colors=[],uids=[]){ var html=""; if(title && values.length>0){ html+="

"+htmlEntities(title)+"


"; for (let i = 0; i < values.length; i++) { if(!values[i]) continue; var color=colors[i]? colors[i]: (colors[0] ? colors[0] : "white"); var a=""; if(uids[i]) a=''; html+=a+''+htmlEntities(values[i])+''; } return html; } } conditonalTextGen(title,bool,yes,no=""){ return this.textGen(title,bool?yes:no); } boolGen(title,value){ var res= value?"Sì":"No"; var color= value?"green":"red"; return this.listgen(title,[res],[color],[]); } thumbnailGen(url,MAXheight=200,MAXwidth=200,alt="thumbnail"){ return ''+htmlEntities(alt)+''; } tagsgen(title,values=[],colors=[]){ var html=""; if(title && values.length>0){ html+="

"+htmlEntities(title)+"


"; for (let i = 0; i < values.length; i++) { if(!values[i]) continue; var color=colors[i]? colors[i]: (colors[0] ? colors[0] : "black"); var a=''; html+=a+''+htmlEntities(values[i])+''; } return html; } } generateLi(type,array){ var tLihtml="",t; switch (type) { case "document": array.forEach(element => { tLihtml+='
  • \n'; tLihtml+="

    "+htmlEntities(element["title"])+"

    "; tLihtml+="

    "; tLihtml+=" "+this.thumbnailGen(element["thumbnailUrl"],200,200,element["title"])+""; tLihtml+="

    "; tLihtml+="

    "+htmlEntities(element["shortDescription"])+"

    "; tLihtml+="

    "; tLihtml+= ""+this.listgen("Formato",[ element["format"]["type"],element["format"]["description"] ],[element["format"]["uiColor"]] )+""; tLihtml+="

    "; t=this.itLookupPairDict(element,"publishedDate"); tLihtml+=" "+this.textGen(t["name"],(new TimeFormatter(t["value"])).compute("LLLL") )+""; tLihtml+="

    "; tLihtml+= ""+this.tagsgen("Tag",element["tags"])+""; tLihtml+="

    "; var nl=new NodeLinks(element["links"]); tLihtml+= nl.computeHTML(); tLihtml+='
  • '; }); break; case "event": array.forEach(element => { tLihtml+='
  • \n'; tLihtml+="

    "+htmlEntities(element["title"])+"

    "; tLihtml+="

    "; tLihtml+=" "+this.thumbnailGen(element["thumbnailUrl"],200,200,element["title"])+""; tLihtml+="

    "; tLihtml+="

    "+htmlEntities(element["shortDescription"])+"

    "; tLihtml+="

    "; tLihtml+= this.conditonalTextGen(" ",element["isAssembly"],"È un assemblea"); tLihtml+="

    "; t=this.itLookupPairDict(element,"startDate"); tLihtml+=" "+this.textGen(t["name"],(new TimeFormatter(t["value"])).compute("LLLL") )+""; tLihtml+="

    "; t=this.itLookupPairDict(element,"endDate"); tLihtml+=" "+this.textGen(t["name"],(new TimeFormatter(t["value"])).compute("LLLL") )+""; tLihtml+="

    "; tLihtml+= " "+this.listgen("Partecipanti",element["participants"])+""; tLihtml+="

    "; t=this.itLookupPairDict(element,"publishedDate"); tLihtml+=" "+this.textGen(t["name"],(new TimeFormatter(t["value"])).compute("LLLL") )+""; tLihtml+="

    "; tLihtml+= " "+this.tagsgen("Tag",element["tags"])+""; tLihtml+="

    "; var nl=new NodeLinks(element["links"]); tLihtml+= nl.computeHTML(); tLihtml+='
  • '; }); break; case "feedback": array.forEach(element => { tLihtml+='
  • \n'; tLihtml+="

    "+htmlEntities(element["title"])+"

    "; tLihtml+="

    "; tLihtml+="

    "; tLihtml+=" "+this.thumbnailGen(element["thumbnailUrl"],200,200,element["title"])+""; tLihtml+="

    "; tLihtml+="

    "+htmlEntities(element["shortDescription"])+"

    "; tLihtml+="

    "; tLihtml+="

    "; t=this.itLookupPairDict(element,"startDate"); tLihtml+=" "+this.textGen(t["name"],(new TimeFormatter(t["value"])).compute("LLLL") )+""; tLihtml+="

    "; t=this.itLookupPairDict(element,"endDate"); tLihtml+=" "+this.textGen(t["name"],(new TimeFormatter(t["value"])).compute("LLLL") )+""; tLihtml+="

    "; t=this.itLookupPairDict(element,"publishResultsDate"); tLihtml+=" "+this.textGen(t["name"],(new TimeFormatter(t["value"])).compute("LLLL") )+""; tLihtml+="

    "; this.itLookupPairDict(element,"publishedDate") tLihtml+=" "+this.textGen(t["name"],(new TimeFormatter(t["value"])).compute("LLLL") )+""; tLihtml+="

    "; tLihtml+= " "+this.tagsgen("Tag",element["tags"])+""; var nl=new NodeLinks(element["links"]); tLihtml+= nl.computeHTML(); tLihtml+='
  • '; }); break; case "question": array.forEach(element => { tLihtml+='
  • \n'; tLihtml+="

    "+htmlEntities(element["questionTitle"])+"

    "; tLihtml+="

    "; tLihtml+="

    "; tLihtml+=" "+this.thumbnailGen(element["thumbnailUrl"],200,200,element["title"])+""; tLihtml+="

    "; t=this.itLookupPairDict(element,"publishedDate") tLihtml+=" "+this.textGen(t["name"],(new TimeFormatter(t["value"])).compute("LLLL") )+""; tLihtml+="

    "; tLihtml+= " "+this.tagsgen("Tag",element["tags"])+""; var nl=new NodeLinks(element["links"]); tLihtml+= nl.computeHTML(); tLihtml+='
  • '; }); break; case "transaction": array.forEach(element => { tLihtml+=''; tLihtml+=" "+this.thumbnailGen(element["thumbnailUrl"],200,200,element["title"])+""; t=this.itLookupPairDict(element,"title"); tLihtml+=" "+this.textGen(" ",t["value"])+""; t=this.itLookupPairDict(element,"planned") tLihtml+=" "+this.textGen(" ",(new TimeFormatter(t["value"])).compute("LLLL") )+""; t=this.itLookupPairDict(element,"executed") tLihtml+=" "+this.textGen(" ",(new TimeFormatter(t["value"])).compute("LLLL") )+""; tLihtml+=""+eurS(element["amount"])+""; tLihtml+=" "+this.textGen(" ",t["value"])+""; t=this.itLookupPairDict(element,"shortDescription"); tLihtml+=" "+this.textGen(" ",t["value"])+""; t=this.itLookupPairDict(element,"publishedDate") tLihtml+=" "+this.textGen(" ",(new TimeFormatter(t["value"])).compute("LLLL") )+""; tLihtml+= " "+this.tagsgen(" ",element["tags"])+""; tLihtml+= 'link'; tLihtml+""; /*var nl=new NodeLinks(element["links"]); tLihtml+= nl.computeHTML();*/ tLihtml+=''; }); break; } return tLihtml; } } class TimeFormatter{ constructor(timeString=null){ if(timeString) this.m=moment(timeString); else this.m=moment(); if(this.m.locale()!="it") this.m.locale("it",null); } compute(format){ return this.m.format(format); } } class APIfetch{ constructor(epl){ this.epl=epl; } fetchDocs(start=false,end=false){ $.post("api/view/documents/all/",{"start":start,"end":end}, function(data){ this.renderDocs(data); }.bind(this),"json"); } fetchEvents(start=false,end=false){ $.post("api/view/events/all/",{"start":start,"end":end}, function(data){ this.renderEvents(data); }.bind(this),"json"); } fetchFeedbacks(start=false,end=false){ $.post("api/view/feedbacks/all/",{"start":start,"end":end}, function(data){ this.renderFeedbacks(data); }.bind(this),"json"); } fetchQuestions(start=false,end=false){ $.post("api/view/questions/all/",{"start":start,"end":end}, function(data){ this.renderQuestions(data); }.bind(this),"json"); } fetchTransactions(start=false,end=false){ $.post("api/view/transactions/all/",{"start":start,"end":end}, function(data){ this.renderTransactions(data); }.bind(this),"json"); } renderTransactions(data){ var a= (new ElementPreviewList()).generateLi("transaction",data["data"]); console.log(a); $("#accountingList").html(a); $("#accountingList").enhanceWithin(); $("#accountingList").listview('refresh'); } renderFeedbacks(data){ var a= (new ElementPreviewList()).generateLi("feedback",data["data"]); $("#feedbacksList").html(a); $("#feedbacksList").enhanceWithin(); $("#feedbacksList").listview('refresh'); } renderQuestions(data){ var a= (new ElementPreviewList()).generateLi("question",data["data"]); $("#questionsList").html(a); $("#questionsList").enhanceWithin(); $("#questionsList").listview('refresh'); } renderDocs(data){ var a= (new ElementPreviewList()).generateLi("document",data["data"]); $("#documentsList").html(a); $("#documentsList").enhanceWithin(); $("#documentsList").listview('refresh'); } renderEvents(data){ var a= (new ElementPreviewList()).generateLi("event",data["data"]); $("#eventsList").html(a); $("#eventsList").enhanceWithin(); $("#eventsList").listview('refresh'); } } function eurS(val){ if(val==0) return "

    €"+formatMoney(val,2,",","'")+"

    "; if(val<0) return "

    €"+formatMoney(val,2,",","'")+"

    "; return "

    €"+formatMoney(val,2,",","'")+"

    "; } function formatMoney(number, decPlaces, decSep, thouSep) { decPlaces = isNaN(decPlaces = Math.abs(decPlaces)) ? 2 : decPlaces, decSep = typeof decSep === "undefined" ? "." : decSep; thouSep = typeof thouSep === "undefined" ? "," : thouSep; var sign = number < 0 ? "-" : ""; var i = String(parseInt(number = Math.abs(Number(number) || 0).toFixed(decPlaces))); var j = (j = i.length) > 3 ? j % 3 : 0; return sign + (j ? i.substr(0, j) + thouSep : "") + i.substr(j).replace(/(\decSep{3})(?=\decSep)/g, "$1" + thouSep) + (decPlaces ? decSep + Math.abs(number - i).toFixed(decPlaces).slice(2) : ""); } function searchE(listArr,key){ for (let i = 0; i < listArr.length; i++) { var e = listArr[i]; if(e["name"]==key) return e["value"]; } } var epl= new ElementPreviewList(); var api= new APIfetch(epl); api.fetchDocs(); api.fetchEvents(); api.fetchFeedbacks(); api.fetchQuestions(); api.fetchTransactions(); var start,end; $(document).delegate("form[data-act=search]","submit",function(){ var data=$(this).serializeArray(); start=searchE(data,"start")? searchE(data,"start"):"false"; end=searchE(data,"end")? searchE(data,"start") :"false"; switch(searchE(data,"search")){ case "events": api.fetchEvents(start,end); break; case "documents": api.fetchDocs(start,end); break; case "feedbacks": api.fetchFeedbacks(start,end); break; case "questions": api.fetchQuestions(start,end); break; case "transactions": api.fetchTransactions(start,end); break; } return false; }); function onKonamiCode(cb) { var input = ''; var key = '38384040373937396665'; document.addEventListener('keydown', function (e) { input += ("" + e.keyCode); if (input === key) { return cb(); } if (!key.indexOf(input)) return; input = ("" + e.keyCode); }); } onKonamiCode(function () { window.open('https://www.youtube.com/watch?v=9YG9INjO91Y', '_blank'); });