//Creado con Ardora - www.webardora.net
//bajo licencia Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)
//para otros usos contacte con el autor
var userN;var userName;var userGru;var userCur;var userType;allJobs=new Array();var zIndex=0;
$(document).ready(function() {document.addEventListener("touchstart",touchHandler,true);document.addEventListener("touchmove",touchHandler,true);document.addEventListener("touchend",touchHandler,true);document.addEventListener("touchcancel", touchHandler, true);createBar();getJob();
});
function make_draggable(elements) {elements.draggable({containment: "parent",start: function(e, ui) {ui.helper.css("z-index",++zIndex);},stop: function(e, ui) {}});}
function getJob() {$.ajax({data: {"action": "getJob"},type: "POST",dataType: "json",url: "php/ardoraPublic.php",success: function(data, textStatus, jqXHR) {
$("#ardoraAct").empty();var notes="";var vLeft=5;var vTop=5;sortResults(data,"tit",true);
if (data.length>0){allJobs=data;
for (i=0; i<data.length;i++){if (isLog){if (data[i]["usu"]==userN || userType=="profe" || userType=="admin"){
notes=notes+'<div class="marco">';}}
notes=notes+"<div id='note"+i.toString()+"' class='note' style='z-index:1; background-color:"+data[i]["cBa"]+"; border:1px solid "+data[i]["cBo"]+"';>";
notes=notes+"<div id='pal"+i.toString()+"' class='palabra'>"+data[i]["tit"]+"</div>"+"<div id='descri"+i.toString()+"' class='descri'>"+data[i]["des"]+"</div>"+
"<div id='aut"+i.toString()+"' class='author'>"+data[i]["dat"]+" - " +data[i]["usu"]+"</div>"+"</div>";
if (isLog){if (data[i]["usu"]==userN || userType=="profe" || userType=="admin"){notes=notes+'<div class="divNoteBut"><p id="del'+i.toString()+'" title="" class="butLe butNote">b</p><p id="edit'+i.toString()+'" title="" class="butLe butNote">P</p></div></div>';}}}
$("#ardoraAct").html(notes);for (i=0; i<data.length;i++){if (isLog){if (data[i]["usu"]==userN || userType=="profe" || userType=="admin"){$("#del"+i.toString()).on("touchstart click", function(e) {
idNote=$(this).attr("id").substring(3,10).trim();$("#modal-content").empty();$("#modal-content").css("width", "auto");$("#modal-content").css("height", "auto");
var newHtml = '<div id="modalTit">Delete</div>';newHtml = newHtml + '<div id="modalBody"><br>Do you really want to delete? <b>' + allJobs[idNote]["tit"] + '?</b><br><br> ';
newHtml = newHtml + '<div id="modalBar"><p id="cancelBut" class="butfont butLe red" title="">E</p><p id="delBut" class="butfont butRi green" title="">g</p></div></div>';
$("#modal-content").append(newHtml);$("#modal-content,#modal-background").toggleClass("active");$("#modal-background, #modal-close, #cancelBut").click(function() {$("#modal-content,#modal-background").toggleClass("active");});
$("#modal-content").draggable();$("#delBut").on("touchstart click", function(e) {delJob(allJobs[idNote]["usu"],allJobs[idNote]["tit"],allJobs[idNote]["dat"]);$("#modal-content,#modal-background").toggleClass("active");});});
$("#edit"+i.toString()).on("touchstart click", function(e) {idNote=$(this).attr("id").substring(4,10).trim();$("#modal-content").empty();$("#modal-content").css("height", "auto");$("#modal-content").css("width", "600px");
var newHtml = '<div id="modalTit">Add</div>';newHtml =newHtml+'<div id="area_form" ><form id="entraDatos" class="formLogin" name="entraDatos" method="post" action="" enctype="multipart/form-data">';
newHtml =newHtml+'<div id="traballos"><p>Insert the data</p></div>';
newHtml =newHtml+'<div id="datos_form"><label for="titulo">Name </label><input type="text" name="titulo" id="titulo" placeholder="" required value="'+allJobs[idNote]["tit"]+'" maxlength="30"/>';
newHtml =newHtml+'<div id="clear"></div>';newHtml =newHtml+'<label for="descri">Information  </label><input type="text" name="descricion" id="descricion" placeholder="" required value="'+allJobs[idNote]["des"]+'"/>';
newHtml =newHtml+'<div id="clear"></div>';
newHtml =newHtml+'<label for="colorBack">Background color</label><input type="color" value="'+allJobs[idNote]["cBa"]+'" name="back_color" id="back_color">';
newHtml =newHtml+'<label for="colorBorder">Border color</label><input type="color" value="'+allJobs[idNote]["cBo"]+'" name="border_color" id="border_color">';
newHtml =newHtml+'</div></form></div>';newHtml =newHtml+'<div id="clear"></div>';newHtml =newHtml+'<div id="clear"></div>';
newHtml = newHtml + '<div id="modalBar"><p id="editCancelBut" class="butfont butLe red" title="">E</p><p id="editExitB" class="butfont butRi green" title="">g</p></div></div>';
$("#modal-content").append(newHtml);$("#modal-content,#modal-background").toggleClass("active");$("#modal-content").draggable();
$("#editCancelBut").on("touchstart click", function(e) {$("#modal-content,#modal-background").toggleClass("active");})
$("#editExitB").on("touchstart click", function(e) {$("#alertDiv").remove();var input_Tit=$("#titulo").val();var input_Des=$("#descricion").val();
var input_cBack= $("#back_color").val();var input_cBorder= $("#border_color").val(); if (input_Tit.length>0){updateItem(allJobs[idNote]["tit"], allJobs[idNote]["usu"],input_Tit,input_Des,input_cBack,input_cBorder);getJob();$("#modal-content,#modal-background").toggleClass("active");}
else{ $("#datos_form").append("<div id='alertDiv'><p id=alertIco>a</p><p id='errorMen'>You must insert a text or a sentence</p></div>")}});});}}
var tmp;$(".note").each(function(){tmp = $(this).css("z-index");if(tmp>zIndex) zIndex = tmp;});make_draggable($(".note"));}
}}});}
function closeIFrame(){$("#modal-content,#modal-background").toggleClass("active");$.ajax({data: {"action": "login"},type: "GET",dataType: "json",async: false,url: "php/ardoraXML.php",
success: function(data, textStatus, jqXHR) {userN=data["usu"];userName=data["nom"];userGru=data["gru"];userCur=data["cur"];userType=data["typ"]}});
$("#loginBut").hide();isLog=true;$("#modal-content").removeClass("widthAuto").addClass("widthFix");getJob();}
function delJob(userJob,wordJob,dataJob) {if (userJob==userN || userType=="profe" || userType=="admin"){$.ajax({type: "POST",dataType: "json",async: false,url: "php/ardoraXML.php",data: {"action": "deleteItem","tit": wordJob,"nameUser": userJob,"dat":dataJob}});getJob();}}
function updateItem(oldItem, userJob, wordJob, comJob, col1Job,col2Job) {if (userJob==userN || userType=="profe" || userType=="admin"){$.ajax({type: "POST",dataType: "json",async: false,url: "php/ardoraXML.php",
data: {"action": "updateItem","oldItem": oldItem.trim(),"item": wordJob,"com": comJob,"cBack": col1Job,"cBorder": col2Job,"nameUser": userJob}});}}
function sortResults(vArray,prop,asc) {vArray=vArray.sort(function(a,b){var alc=a[prop].toLowerCase();var blc=b[prop].toLowerCase();
alc=alc.replace(/á/g,"a");blc=blc.replace(/á/g,"a");alc=alc.replace(/é/g,"e");blc=blc.replace(/é/g,"e");alc=alc.replace(/í/g,"i");blc=blc.replace(/í/g,"i");alc=alc.replace(/ó/g,"o");blc=blc.replace(/ó/g,"o");alc=alc.replace(/ú/g,"u");blc=blc.replace(/ú/g,"u");
alc=alc.replace(/ñ/g,"nzz");blc=blc.replace(/ñ/g,"nzz");alc=alc.replace(/ç/g,"czz");blc=blc.replace(/ç/g,"czz");
alc=alc.replace(/à/g,"a");blc=blc.replace(/à/g,"a");alc=alc.replace(/è/g,"e");blc=blc.replace(/è/g,"e");alc=alc.replace(/ì/g,"i");blc=blc.replace(/ì/g,"i");alc=alc.replace(/ò/g,"o");blc=blc.replace(/ò/g,"o");alc=alc.replace(/ù/g,"u");blc=blc.replace(/ù/g,"u");
alc=alc.replace(/â/g,"a");blc=blc.replace(/â/g,"a");alc=alc.replace(/ê/g,"e");blc=blc.replace(/ê/g,"e");alc=alc.replace(/î/g,"i");blc=blc.replace(/î/g,"i");alc=alc.replace(/ô/g,"o");blc=blc.replace(/ô/g,"o");alc=alc.replace(/û/g,"u");blc=blc.replace(/û/g,"u");
alc=alc.replace(/ë/g,"e");blc=blc.replace(/ë/g,"e");alc=alc.replace(/ï/g,"i");blc=blc.replace(/ï/g,"i");alc=alc.replace(/ü/g,"u");blc=blc.replace(/ü/g,"u");
alc=alc.replace(/ă/g,"a");blc=blc.replace(/ă/g,"a");
if (asc) return (alc>blc) ? 1 : ((alc<blc) ? -1 : 0);else return (blc>alc) ? 1 : ((blc < alc) ? -1 : 0);});}
function touchHandler(event) {
var touch = event.changedTouches[0];var simulatedEvent = document.createEvent("MouseEvent");
simulatedEvent.initMouseEvent({touchstart: "mousedown",touchmove: "mousemove",touchend: "mouseup"}[event.type], true, true, window, 1,touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null);
touch.target.dispatchEvent(simulatedEvent);event.preventDefault();};
