Commit fae891f0 authored by Clément Damiens's avatar Clément Damiens
Browse files

commit full full full coInterface
parent 8e00d312
var CO3_TypeObj = class {
constructor(pRequeteAjax,pPHDB_Obj){
if(this.IsValidRequete(pRequeteAjax)){
this.params=this.MakeRequeteAjax(pRequeteAjax);
} else {
this.params=pPHDB_Obj||null;
}
}
PrepareRequeteAjax(pRequeteAjax){
pRequeteAjax["prepared"]=true;
return pRequeteAjax;
}
MakeRequeteAjax(pRequeteAjax){
if(this.IsValidRequete(pRequeteAjax)){
this.RequeteAjax=this.PrepareRequeteAjax(pRequeteAjax); //Stockage optional ?
let res = null;
//TODO : Requete AJAX
res = this.RequeteAjax["where"];
//renvoie obj
return res;
} else {
return null;
}
}
Count(){
if(this.IsDefined(this.params)){
return Object.keys(this.params).length;
}else{
return 0;
}
}
PreElementRenderHtml(pElementParams){
return this.OldshowResultsDirectoryHtml(pElementParams,null,null,null);
}
ElementRenderHtml(pElementParams){
let str = "";
str+="Objet";
return str;
}
PostElementRenderHtml(pElementStr){
return pElementStr;
}
RenderHtml(){
let str="";
for(let id in this.params){
if(this.IsDefined(this.params[id])){
str+=this.PostElementRenderHtml(this.ElementRenderHtml(this.PreElementRenderHtml(this.params[id])));
}
}
return str;
}
IsDefined(obj){
return ((typeof obj !=="undefined")&&(obj!=null)&&(obj!=""));
}
IsValidRequete(pRequeteAjax){
return this.IsDefined(pRequeteAjax);
}
SetCarousable(){
let first=true;
for(let id in this.params){
if(this.IsDefined(this.params[id])){
this.params[id].carousable=true;
if(first){
this.params[id].carousel_active=true;
first=false;
}
}
}
return this;
}
OldshowResultsDirectoryHtml( params, size, edit, viewMode){ //size == null || min || max
if ((typeof(params.id) == "undefined") && (typeof(params["_id"]) !== "undefined")) {
params.id = params['_id'];
} else if (typeof(params.id) == "undefined" && location.hash.indexOf("#interoperability") >= 0) {
params.id = Math.random();
params.type = "poi";
}
if((params["_id"]!=null) || (params.id!=null)){
params.size = size;
params.id = getObjectId(params);
mylog.log(params.id);
params.name = notEmpty(params.name) ? params.name : "";
params.description = notEmpty(params.shortDescription) ? params.shortDescription :
(notEmpty(params.message)) ? params.message :
(notEmpty(params.description)) ? params.description :
"";
var itemType="article";
//mapElements.push(params);
//alert("TYPE ----------- "+contentType+":"+params.name);
if(typeof edit != "undefined" && edit != false)
params.edit = edit;
if ( params.type && typeof typeObj.classifieds != "undefined" && $.inArray(params.type, typeObj.classifieds.subTypes )>=0 ) {
itemType = "classifieds";
} else if(typeof( typeObj[itemType] ) == "undefined") {
itemType="poi";
}
if( dyFInputs.get( itemType ) == null){
itemType="poi";
}
var typeIco = itemType;
if(directory.dirLog) mylog.warn("itemType",itemType,"typeIco",typeIco);
if(typeof params.typeOrga != "undefined")
typeIco = params.typeOrga;
if(typeof params.typeClassified != "undefined")
typeIco = params.typeClassified;
var obj = (dyFInputs.get(typeIco)) ? dyFInputs.get(typeIco) : typeObj["default"] ;
params.ico = "fa-"+obj.icon;
params.color = obj.color;
if(params.parentType){
if(directory.dirLog) mylog.log("params.parentType",params.parentType);
var parentObj = (dyFInputs.get(params.parentType)) ? dyFInputs.get(params.parentType) : typeObj["default"] ;
params.parentIcon = "fa-"+parentObj.icon;
params.parentColor = parentObj.color;
}
if((typeof searchObject.countType != "undefined" && searchObject.countType.length==1) && params.type == "classifieds" && typeof params.category != "undefined" && typeof modules[params.typeClassified] != "undefined"){
getIcoInModules=modules[params.typeClassified].categories;
params.ico = (typeof getIcoInModules.filters != "undefined" && typeof getIcoInModules.filters[params.category] != "undefined") ?
"fa-" + getIcoInModules.filters[params.category]["icon"] : "fa-bullhorn";
}
if(params.type=="poi"
&& typeof modules.poi != "undefined"
&& typeof modules.poi.categories != "undefined"
&& typeof modules.poi.categories.filters != "undefined"
&& typeof modules.poi.categories.filters[params.typePoi] != "undefined"
&& typeof modules.poi.categories.filters[params.typePoi].icon != "undefined")
params.ico="fa-"+modules.poi.categories.filters[params.typePoi].icon;
params.htmlIco ="<i class='fa "+ params.ico +" fa-2x bg-"+params.color+"'></i>";
params.useMinSize = typeof size != "undefined" && size == "min";
params.imgProfil = "";
if(!params.useMinSize){
params.imgProfil = "<i class='fa fa-image fa-2x'></i>";
params.imgMediumProfil = "<i class='fa fa-image fa-2x'></i>";
params.imgFullProfil = "<i class='fa fa-image fa-2x'></i>";
}
if("undefined" != typeof directory.costum && (directory.costum!=null)
&& typeof directory.costum.results != "undefined"
&& typeof directory.costum.results[params.type] != "undefined"
&& typeof directory.costum.results[params.type].defaultImg != "undefined")
{
params.imgMediumProfil= "<img class='img-responsive' onload='directory.checkImage(this);' src='"+assetPath+directory.costum.results[params.type].defaultImg+"'/>";
params.imgFullProfil= "<img class='img-responsive' onload='directory.checkImage(this);' src='"+assetPath+directory.costum.results[params.type].defaultImg+"'/>";
}
if("undefined" != typeof params.profilImageUrl && params.profilImageUrl != "")
params.imgFullProfil= "<img class='img-responsive' onload='directory.checkImage(this);' src='"+baseUrl+params.profilImageUrl+"'/>";
else if(this.getVideoThumb(params)!="")
params.imgFullProfil= "<img class='img-responsive' src='"+this.getVideoThumb(params)+"'/>";
if("undefined" != typeof params.profilMediumImageUrl && params.profilMediumImageUrl != "")
params.imgMediumProfil= "<img class='img-responsive' onload='directory.checkImage(this);' src='"+baseUrl+params.profilMediumImageUrl+"'/>";
else if(this.getVideoThumb(params)!="")
params.imgMediumProfil= "<img class='img-responsive' src='"+this.getVideoThumb(params)+"'/>";
if("undefined" != typeof params.profilThumbImageUrl && params.profilThumbImageUrl != "")
params.imgProfil= "<img class='shadow2' src='"+baseUrl+params.profilThumbImageUrl+"'/>";
else if(this.getVideoThumb(params)!="")
params.imgProfil= "<img class='shadow2' src='"+this.getVideoThumb(params)+"'/>";
params.imgBanner = "";
if(!params.useMinSize)
params.imgBanner = "<i class='fa fa-image fa-2x'></i>";
if (false && typeof params.addresses != "undefined" && params.addresses != null) {
$.each(params.addresses, function(key, val){
//console.log("second address", val);
var postalCode = val.address.postalCode ? val.address.postalCode : "";
var cityName = val.address.addressLocality ? val.address.addressLocality : "";
params.fullLocality += "<br>"+ postalCode + " " + cityName;
});
}
params.type = dyFInputs.get(itemType).col;
params.urlParent = (notEmpty(params.parentType) && notEmpty(params.parentId)) ?
'#page.type.'+params.parentType+'.id.' + params.parentId : "";
// var urlImg = "/upload/communecter/color.jpg";
// params.profilImageUrl = urlImg;
/*if(dyFInputs.get(itemType) &&
dyFInputs.get(itemType).col == "poi" &&
typeof params.medias != "undefined" && typeof params.medias[0].content.image != "undefined")
params.imgProfil= "<img class='img-responsive' src='"+params.medias[0].content.image+"'/>";
*/
params.insee = params.insee ? params.insee : "";
params.postalCode = "", params.city="",params.cityName="";
if (params.address != null) {
params.city = params.address.addressLocality;
params.postalCode = params.cp ? params.cp : params.address.postalCode ? params.address.postalCode : "";
params.cityName = params.address.addressLocality ? params.address.addressLocality : "";
}
params.fullLocality = params.postalCode + " " + params.cityName;
params.hash = '#page.type.'+params.type+'.id.' + params.id;
if(typeof params.slug != "undefined" && params.slug != "" && params.slug != null)
params.hash = "#@" + params.slug;
if(typeof networkJson != "undefined" && typeof networkJson.dataSrc != "undefined")
params.hash = params.source;
params.onclick = 'urlCtrl.loadByHash("' + params.url + '");';
if(params.type=="circuits")
params.hash = '#circuit.index.id.' + params.id;
params.onclick = 'urlCtrl.loadByHash("' + params.url + '");';
if( params.type == "poi" && params.source && ( (params.source.key!=null) && params.source.key.substring(0,7) == "convert")) {
var interop_type = getTypeInteropData(params.source.key);
params.type = "poi.interop."+interop_type;
}
// params.tags = "";
params.elTagsList = "";
var thisTags = "";
if(typeof params.tags != "undefined" && params.tags != null){
$.each(params.tags, function(key, value){
if(typeof value != "undefined" && value != "" && value != "undefined"){
var tagTrad = typeof tradCategory[value] != "undefined" ? tradCategory[value] : value;
thisTags += "<span class='badge bg-transparent text-red btn-tag tag' data-tag-value='"+slugify(value, true)+"' data-tag-label='"+tagTrad+"'>#" + tagTrad + "</span> ";
// mylog.log("sluggify", value, slugify(value, true));
params.elTagsList += slugify(value, true)+" ";
}
});
params.tagsLbl = thisTags;
}else{
params.tagsLbl = "";
}
params.elRolesList = "";
var thisRoles = "";
params.rolesLbl = "";
if(typeof params.rolesLink != "undefined" && params.rolesLink != null){
thisRoles += "<small class='letter-blue'><b>"+trad.roleroles+" :</b> ";
thisRoles += params.rolesLink.join(", ");
$.each(params.rolesLink, function(key, value){
if(typeof value != "undefined" && value != "" && value != "undefined")
params.elRolesList += slugify(value)+" ";
});
thisRoles += "</small>";
params.rolesLbl = thisRoles;
}
params.updated = (params.updatedLbl!="") ? params.updatedLbl : null;
if((params.tobeactivated!=null) && params.tobeactivated == true){
params.isInviting = true ;
}
}
return params;
}
getVideoThumb(params){
if("undefined" != typeof params.medias && params.medias.length>0){
for(let i=0;i<params.medias.length;i++){
if("undefined" != typeof params.medias[i].content.image && params.medias[i].content.image!="")
return params.medias[i].content.image;
}
}
return "";
}
}
......@@ -50,42 +50,6 @@ function checkPoll(){
countPoll++;
}
}
function setLanguage(lang){
$.cookie('lang', lang, { expires: 365, path: "/" });
//toastr.success(trad.changelanguageprocessing);
//window.reloadurlCtrl.loadByHash(location.hash);
if(userId != ""){
param={
name : "language",
value : lang,
pk : userId
};
$.ajax({
type: "POST",
url: baseUrl+"/"+moduleId+"/element/updatefields/type/citoyens",
data: param,
dataType: "json",
success: function(data){
if(data.result){
toastr.success(data.msg);
location.reload();
/*if(formInMap == true){
$(".locationEl"+ index).remove();
dyFInputs.locationObj.elementLocation = null;
dyFInputs.locationObj.elementLocations.splice(ix,1);
//TODO check if this center then apply on first
//$(".locationEl"+dyFInputs.locationObj.countLocation).remove();
}
else
urlCtrl.loadByHash(location.hash);*/
}
}
});
}else{
location.reload();
}
}
var watchThis = null;
function bindRightClicks() {
$.contextMenu({
......@@ -256,7 +220,7 @@ DropDown.prototype = {
return this.index;
}
}
/* DEPRACATED [06/05/2019] TODO : clean if not used
function openModal(key,collection,id,tpl,savePath,isSub){
$.ajax({
type: "POST",
......@@ -276,7 +240,8 @@ function openModal(key,collection,id,tpl,savePath,isSub){
dataType: "json"
});
}
*/
/* DEPRACATED [06/05/2019] TODO : clean if not used
function updateField(type,id,name,value,reload, useToastr){
$.ajax({
......@@ -295,7 +260,7 @@ function updateField(type,id,name,value,reload, useToastr){
},
dataType: "json"
});
}
}*/
function addslashes(str) {
// discuss at: http://phpjs.org/functions/addslashes/
// original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
......@@ -367,6 +332,7 @@ function initSequence(){
initT = null;
}
/* DEPRACATED [06/05/2019] TODO : clean if not used
function showEvent(id){
$("#"+id).click(function(){
if($("#"+id).prop("checked"))
......@@ -374,321 +340,331 @@ function showEvent(id){
else
$("#"+id+"What").addClass("hidden");
});
}
}*/
//In this javascript file you can find a bunk of functional functions
//Calling Actions in ajax. Can be used easily on views
/*function connectPerson(connectUserId, callback)
{
mylog.log("connect Person");
$.ajax({
type: "POST",
url: baseUrl+"/"+moduleId+'/person/follows',
dataType : "json",
data : {
connectUserId : connectUserId,
function loadSettings(hash){
$("#modal-settings").show();
var url = "settings/index";
if(typeof hash != "undefined" && hash.indexOf("page") >= 0){
hashT=hash.split(".");
url += "/page/"+hashT[2];
if(hash.indexOf("to") >= 0){
url += "/to/"+hashT[4];
}
})
.done(function (data) {
$.unblockUI();
if (data && data.result) {
var name = $("#newInvite #ficheName").text();
toastr.success('You are now following '+name);
if (typeof callback == "function") callback(data.invitedUser);
} else {
$.unblockUI();
toastr.error('Something Went Wrong !');
}
showLoader('#modal-settings');
ajaxPost('#modal-settings', baseUrl+'/'+moduleId+'/'+url,
null,
function(){},"html");
}
var CoAllReadyLoad = false;
var coInterface = {
init : function(){
coInterface.scrollTo(".main-container");
coInterface.bindResizeEvent();
coInterface.initHtmlPosition();
// Active button to get dynform
coInterface.bindButtonOpenForm();
coInterface.bindLBHLinks();
//jQuery for page scrolling feature - requires jQuery Easing plugin
// This button can be used to get scroll to the container indicated in href
$('.page-scroll a').bind('click', function(event) {
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: ($($anchor.attr('href')).offset().top - 50)
}, 1250, 'easeInOutExpo');
event.preventDefault();
});
}
// jQuery for page scrolling feature - requires jQuery Easing plugin
$('.btn-scroll').bind('click', function(event) {
var target = $(this).data('targetid');
coInterface.scrollTo(target);
event.preventDefault();
});
// Highlight the top nav as scrolling occurs
// Closes the Responsive Menu on Menu Item Click
$('.navbar-collapse ul li a').click(function(){
$('.navbar-toggle:visible').click();
});
$(".openModalSelectCreate").click(function(){
$("#selectCreate").modal("show");
showFloopDrawer(false);
showNotif(false);
});
function disconnectTo(parentType,parentId,childId,childType,connectType, callback, linkOption, msg) {
var messageBox = (notNull(msg)) ? msg : trad["removeconnection"+connectType];
$(".disconnectBtnIcon").removeClass("fa-unlink").addClass("fa-spinner fa-spin");
var formData = {
"childId" : childId,
"childType" : childType,
"parentType" : parentType,
"parentId" : parentId,
"connectType" : connectType,
};
if(typeof linkOption != "undefined" && linkOption)
formData.linkOption=linkOption;
bootbox.dialog({
onEscape: function() {
$(".disconnectBtnIcon").removeClass("fa-spinner fa-spin").addClass("fa-unlink");
},
message: '<div class="row"> ' +
'<div class="col-md-12"> ' +
'<span>'+messageBox+' ?</span> ' +
'</div></div>',
buttons: {
success: {
label: "Ok",
className: "btn-primary",
callback: function () {
$.ajax({
type: "POST",
url: baseUrl+"/"+moduleId+"/link/disconnect",
data : formData,
dataType: "json",
success: function(data){
if ( data && data.result ) {
typeConnect=(formData.parentType== "citoyens") ? "people" : formData.parentType;
idConnect=formData.parentId;
if(formData.parentId==userId){
typeConnect=(formData.childType== "citoyens") ? "people" : formData.childType;
idConnect=formData.childId;
//Floopdrawer is a div containing all links user did
$(".btn-open-floopdrawer").click(function(){
showNotif(false);
$("#dropdown-user").removeClass("open");
showFloopDrawer(true);
});
$("#floopDrawerDirectory").mouseleave(function(){
showFloopDrawer(false);
});
}
removeFloopEntity(idConnect, typeConnect);
toastr.success("Le lien a été supprimé avec succès");
if (typeof callback == "function")
callback();
// 2 events for notifications
$('.btn-menu-notif').click(function(){
if($('#notificationPanelSearch').is(":visible"))
showNotif(false);
else
urlCtrl.loadByHash(location.hash);
} else {
toastr.error("You leave succesfully");
}
}
showNotif();
});
}
},
cancel: {
label: trad["cancel"],
className: "btn-secondary",
callback: function() {
$(".disconnectBtnIcon").removeClass("fa-spinner fa-spin").addClass("fa-unlink");
}
}
}
$("#notificationPanelSearch").mouseleave(function(){
showNotif(false);
});
};
// Javascript function used to validate a link between parent and child (ex : member, admin...)
function validateConnection(parentType, parentId, childId, childType, linkOption, callback) {
var formData = {
"childId" : childId,
"childType" : childType,
"parentType" : parentType,
"parentId" : parentId,
"linkOption" : linkOption,
};
$(".btn-show-mainmenu").click(function(){
showFloopDrawer(false);
showNotif(false);
$("#dropdown-dda, .dropdownApps-menuTop").removeClass("open");
if($("#dropdown-user").hasClass("open"))
$("#dropdown-user").removeClass("open");
else
$("#dropdown-user").addClass("open");
//clearTimeout(timerCloseDropdownUser);
});
$(".dropdownApps").click(function(){
showFloopDrawer(false);
showNotif(false);
$("#dropdown-user, #dropdown-dda").removeClass("open");
if($(".dropdownApps-menuTop").hasClass("open"))
$(".dropdownApps-menuTop").removeClass("open");
else
$(".dropdownApps-menuTop").addClass("open");
});
$(".dropdownApps-menuTop").mouseleave(function(){
setTimeout(function(){
if(!$(".dropdownApps-menuTop").is(":hover"))
$(".dropdownApps-menuTop").removeClass("open");
}, 200);
});
$(".btn-dashboard-dda").click(function(){
showFloopDrawer(false);
showNotif(false);
dashboard.loadDashboardDDA();
$("#dropdown-user, .dropdownApps-menuTop").removeClass("open");
$("#dropdown-dda").addClass("open");
});
$.ajax({
type: "POST",
url: baseUrl+"/"+moduleId+"/link/validate",
data: formData,
dataType: "json",
success: function(data) {
if (data.result) {
if (typeof callback == "function")
callback(parentType, parentId, childId, childType, linkOption);
else{
toastr.success(data.msg);
urlCtrl.loadByHash(location.hash);