Commit ece0dec8 authored by Anatole Rakotoson's avatar Anatole Rakotoson
Browse files

Merge branch 'qa' of https://gitlab.adullact.net/pixelhumain/survey into qa

parents 30fad596 981ecf55
var answerObject={
delete : function(id, callB){
getAjax("",baseUrl+"/survey/co/delete/id/"+id,function(){
if(notNull(callB))
callB();
else{
toastr.success("La candidature a été supprimée avec succès");
$("#allAnswersList .ansline"+id).remove();
}
},"html");
},
mailConfig : {
inputs : {},
setContactList: function(obj){
str='<span class="col-xs-12 bold">Email</span> ' +
'<input type="text" id="contact-email" class="col-xs-12" value="" placeholder="Entrer un email"/>';
if(typeof obj.selectOptByGroup != "undefined"){
str='<span class="col-xs-12 bold no-padding">Sélectionner les contacts dans la liste suivante</span> ';
str+='<div class="col-xs-12 no-padding checkboxAnswerContact">';
$.each(obj.selectOptByGroup, function(e,v){
if(Object.keys(v).length > 0){
str+="<span class='col-xs-12 no-padding'><i class='fa fa-caret-down'></i> "+obj.selectContact[e]+" :</span>";
$.each(v, function(id, data){
img= (notEmpty(data.profilThumbImageUrl)) ? baseUrl + data.profilThumbImageUrl : modules.co2.url + "/images/thumb/default_"+data.collection+".png";
str+="<div class='population-elt-finder contact-id-"+id+" col-xs-12' data-value='"+id+"' data-collection='"+data.collection+"'>"+
'<div class="checkbox-content pull-left">'+
'<label>'+
'<input type="checkbox" class="check-population-finder checkbox-info" data-collection="'+data.collection+'" data-value="'+id+'">'+
'<span class="cr"><i class="cr-icon fa fa-check"></i></span>'+
'</label>'+
'</div>'+
"<div class='element-finder element-finder-"+id+"'>"+
'<img src="'+ img+'" class="thumb-send-to pull-left img-circle" height="40" width="40">'+
'<span class="info-contact pull-left margin-left-20">' +
'<span class="name-element text-dark text-bold" data-id="'+id+'">' + data.name + '</span>'+
'<br/>'+
'<span class="type-element text-light pull-left">' + trad[data.collection]+ '</span>'+
'</span>' +
"</div>"+
"</div>";
});
}
});
str+="</div>";
}
return str;
},
setObject:function(obj){
ansName=(typeof answerValues.mappingValues != "undefined" && typeof answerValues.mappingValues.name != "undefined") ? answerValues.mappingValues.name : "";
str='<input type="text" id="object-email" class="col-xs-12" value="Notification sur votre dossier "'+ansName+'">';
if(typeof obj.object != "undefined"){
if(typeof obj.object== "string")
str+='<input type="text" id="object-email" class="col-xs-12" value="'+obj.object+'"/>';
else if(typeof obj.object== "array"){
str+='<select id="object-email" path="links.operators" style="width:100%;" placeholder="Sélectionner un objet dans la liste">';
$.each(obj.object, function(e, v){
str+="<option value='"+v+"'>"+v+"</option>";
});
str+="</select>";
}
}
return str;
},
defaultMessage:function(obj){
if(typeof obj.message != "undefined") return obj.message;
else return "";
}
},
mailTo : {
subject: "Votre candidature a été validée",
validation : function(id, step){
var msg="<span style='white-space: pre-line;'>"+$("#send-mail-admin #message-email").text()+"<br/></span>"+
aObj.mailTo.defaultRedirect(elt, type, id);
var params={
tplMail : $("#send-mail-admin #contact-email").val(),
tpl : "basic",
tplObject : answerObject.mailTo.subject,
html: msg
};
ajaxPost(
null,
baseUrl+"/survey/answer/mail/validation/",
params,
function(data){
toastr.success("Le mail a été envoyé avec succès");
}
);
},
initMessage : true,
initObject : true,
initMail: function(elt){
if(typeof elt.creator != "undefined" && elt.creator.email)
return elt.creator.email;
else
return "";
},
defaultObject : function(elt){
return "La réponse demande d'être approfondi";
},
defaultRedirect : function(elt, id){
//urlMail=(notNull(costum)) ?
//return "<a href='"+baseUrl+"#answer.index.id."+id+"' target='_blank'>Retrouvez la page "+elt.name+" en cliquant sur ce lien</a>";
},
defaultMessage : function(elt, type, id){
var nameContact=(typeof elt.creator != "undefined" && elt.creator.name) ? elt.creator.name : "";
var str="Bonjour"+((notEmpty(nameContact)) ? " "+nameContact : "")+",\n"+
"Le contenu que vous avez publié demande d'être approfindi : \n"+
" - Référencer l'adresse\n"+
" - Ajouter la description, des mots clés, une image\n"+
" - Les dates ne sont pas cohérentes\n"+
"Encore un petit effort et vos points seront attribués";
return str;
},
bootbox : function(aObj, elt, type, id){
bootbox.dialog({
onEscape: function() {},
message: '<div id="send-mail-admin" class="row"> ' +
'<div class="col-xs-12"> ' +
'<span>Email</span> ' +
'<input type="text" id="contact-email" class="col-xs-12" value="'+aObj.mailTo.initMail(elt)+'"/>'+
'</div>'+
'<div class="col-xs-12"> ' +
'<span>Object</span> ' +
'<input type="text" id="object-email" class="col-xs-12" value="'+aObj.mailTo.defaultObject(elt)+'"/>'+
'</div>'+
'<div class="col-xs-12"> ' +
'<span>Message</span> ' +
'<textarea id="message-email" class="col-xs-12 text-dark" style="min-height:250px;">'+aObj.mailTo.defaultMessage(elt, type, id)+'</textarea>'+
'</div>'+
'</div>',
buttons: {
success: {
label: "Ok",
className: "btn-primary",
callback: function () {
aObj.mailTo.sendMail(aObj, elt, type, id);
}
},
cancel: {
label: trad["cancel"],
className: "btn-secondary",
callback: function() {}
}
}
});
},
validate : function(aObj, elt, type, id){
}
}
}
\ No newline at end of file
var answerObject={
delete : function(id, callB){
getAjax("",baseUrl+"/survey/co/delete/id/"+id,function(){
if(notNull(callB))
callB();
else{
toastr.success("La candidature a été supprimée avec succès");
$("#allAnswersList .ansline"+id).remove();
}
},"html");
}
}
\ No newline at end of file
// TO INIT AJOUTER DANS PARAMS CONFIG app.#search
// >> "filters":"co2.views.app.filters.search",
var formObj = {
container : "#central-container" ,
forms :{},
el : {},
labels : {
answer : "dossier",
answers : "dossiers",
},
//filterSearch : {},
init : function(pInit = null){
mylog.log("fObj init",pInit);
//Init variable
var copyFilters = jQuery.extend(true, {}, formObj);
copyFilters.initVar(pInit);
return copyFilters;
},
initVar : function(pInit){
// this.filterSearch = searchObj.init(this.paramsFilter);
// this.filterSearch.header.init(this.filterSearch);
},
initDefaults : function(pInit){},
initEvents : function(pInit){},
initViews : function(pInit){
if(location.hash.indexOf(hashUrlPage+".view.forms.dir.form")>=0){
var hashArray = location.hash.split('.');
this.urls.form(this, hashArray[5]);
}else if(location.hash.indexOf(hashUrlPage+".view.forms.dir.answer.")>=0){
var hashArray = location.hash.split('.');
this.urls.answer(this, hashArray[5]);
}else if(location.hash.indexOf(hashUrlPage+".view.forms.dir.answers.form")>=0){
var hashArray = location.hash.split('.');
this.urls.answers(this, hashArray[6]);
}else if(location.hash.indexOf(hashUrlPage+".view.forms.dir.myAnswers.form")>=0){
var hashArray = location.hash.split('.');
this.urls.answers(this, hashArray[6]);
} else{
this.urls.forms(this);
}
},
urls : {
forms : function(fObj){
ajaxPost('#central-container', baseUrl+'/survey/form/get/slug/'+contextData.slug+'/tpl/json',
null,
function(data){
var str = "";
mylog.log("pageProfil.views.forms ajaxPost data", data);
if(typeof data != "undefined" && data != null &&
data.forms != "undefined" && data.forms != null){
fObj.el = data.el;
fObj.views.forms(fObj, data.forms);
}
history.replaceState(location.hash, "", hashUrlPage+".view.forms");
},"html");
},
form : function(fObj, id){
ajaxPost(fObj.container, baseUrl+'/survey/form/edit/id/'+id,
null,
function(){
history.replaceState(location.hash, "", hashUrlPage+".view.forms.dir.form."+id);
},"html");
},
answer : function(fObj, id, form, mode){
mylog.log("fObj.urls.answer", fObj, id, form);
var url = '/survey/answer/index/id/'+id;
if(typeof form != "undefined" && form != null)
url += '/form/'+form;
if(typeof mode != "undefined" && mode != null)
url += '/mode/'+mode;
ajaxPost(fObj.container, baseUrl+url,
null,
function(){
history.replaceState(location.hash, "", hashUrlPage+".view.forms.dir.answer."+answerId);
},"html");
},
answers : function(fObj, form){
mylog.log("formObj.urls.answers", fObj, form);
ajaxPost( null,
baseUrl+"/survey/answer/directory/form/"+form,
null,
function(data){
history.replaceState(location.hash, "", hashUrlPage+".view.forms.dir.answers.form."+form);
fObj.views.answers(fObj, data.results);
});
},
myAnswers : function(fObj, form){
mylog.log("formObj.urls.myAnswers", fObj, form);
var params = {
userId : userId
}
ajaxPost( null,
baseUrl+"/survey/answer/directory/form/"+form,
params,
function(data){
history.replaceState(location.hash, "", hashUrlPage+".view.forms.dir.myAnswers.form."+form);
fObj.views.answers(fObj, data.results);
});
},
observatory : function(fObj, form){
mylog.log("formObj.urls.observatory", fObj, form);
var params = {
userId : userId
}
getAjax("#central-container", baseUrl+"/costum/sommom/dashboard/form/"+form,
function(data){
history.replaceState(location.hash, "", hashUrlPage+".view.forms.dir.observatory.form."+form);
},"html");
}
},
// initFilters : function(){},
// pagination : {},
// scroll : {},
// header : {},
// results : {},
// search : {},
views : {
forms : function(fObj, forms){
var str = '';
str += '<div class="col-md-12 col-sm-12 col-xs-12 labelTitleDir margin-bottom-15">'+
'<i class="fa fa-file-text-o fa-2x margin-right-10"></i>'+
'<i class="fa fa-angle-down"></i>'+Object.keys(forms).length+
'<b>Forms</b>'+
'<a href="javascript:;" class="createForm btn btn-sm btn-link bg-green-k pull-right "><i class="fa fa-plus"></i> Nouveau Formulaire</a>'+
'</div>';
fObj.forms = forms;
$.each(forms, function(idF, valForm){
str += fObj.views.form(idF, valForm);
});
$(fObj.container).html(str);
fObj.events.form(fObj);
fObj.events.add(fObj);
},
form : function(id, form){
mylog.log("formProfil.views.form", id, form);
var panelColor = "panel-primary";
var formCostum = false;
var urlCostum = "";
if( typeof form.source != "undefined" &&
typeof form.source.insertOrign != "undefined" &&
form.source.insertOrign == "costum"){
panelColor = "panel-success";
formCostum = true;
urlCostum = baseUrl+'/costum/co/index/id/'+form.source.key
}
form.active = (form.active === true || form.active === "true");
var str='<div class="col-sm-6 col-xs-12" id="'+id+'Form">'+
'<div class="panel '+panelColor+'">'+
'<div class="panel-heading">'+
'<h3 class="panel-title">'+form.name;
if(typeof form.canEditForm != "undefined" && form.canEditForm === true){
str += '<a href="javascript:;" class="pull-right deleteFormBtn" data-id="'+id+'">'+
'<i class="fa fa-trash text-red"></i></a>';
if(formCostum == true){
str += '<a href="'+urlCostum+'#form.edit.id.'+id+'" target="_blanc" class="pull-right">'+
'<i class="fa fa-pencil text-dark"></i>'+
'</a>';
} else {
str += '<a href="javascript:;" data-id="'+id+'" class="pull-right config">'+
'<i class="fa fa-pencil text-dark"></i>'+
'</a>';
}
}
str += '</h3>';
str += '</div>'+
'<div class="panel-body ">';
if(typeof form.active != "undefined" && (form.active === true))
str += '<span class="label label-success">Activé</span>';
else
str += '<span class="label label-danger">Pas activé</span>';
str += '<div class="col-xs-12">';
str += '<a href="javascript:;" data-id="'+id+'" class="myAnswers btn btn-xs btn-primary col-sm-12 bold">'+
'<i class="fa fa-pencil"></i> My answers '+
'</a>';
if(typeof form.active != "undefined" && form.active === true){
// if(formCostum == true){
// str += '<a href="'+urlCostum+'#answer.index.id.new.form.'+id+'" target="_blanc" class="btn btn-xs btn-primary col-sm-12 bold">'+
// '<i class="fa fa-file-text-o"></i> Application Form '+
// '</a>';
// } else {
str += '<a href="javascript:;" data-id="'+id+'" class=" application btn btn-xs btn-primary col-sm-12 bold">'+
'<i class="fa fa-file-text-o"></i> Application Form '+
'</a>';
//}
if(typeof form.canEditForm != "undefined" && form.canEditForm === true){
str += '<a href="javascript:;" data-id="'+id+'" class="allAnswers btn btn-xs btn-primary col-sm-12 bold">'+
'<i class="fa fa-pencil"></i> All Answers '+
'</a>';
}
}
if(form.hasObservatory)
str += '<a href="javascript:;" data-id="'+id+'" class="observatory btn btn-xs btn-primary col-sm-12 bold">'+
'<i class="fa fa-piechart"></i> Observatoire '+
'</a>';
str += '</div>'+
'</div>'+
'</div>'+
'</div>';
return str ;
},
answers : function(fObj, answers){
//mylog.log("formProfil.views.answers");
var str = '';
var ct = 0;
var globalLinks = [];
var gUids = [];
var lbl = "";
if(typeof answers != "undefined" && answers != null && Object.keys(answers).length > 0 )
str +='<div id="allAnswersContainer" class="col-xs-12 no-padding">';
$.each(answers, function(id, ans){
//mylog.log("formProfil.views.answers each", id, ans);
ct++;
lbl = fObj.labels.answers+" "+ct;
var address = "<i class='fa fa-map-marker'></i> ";
var nameProp= "inconnu";
var descrTravaux= "Aucune";
if(typeof ans.mappingValues != "undefined" && ans.mappingValues != null ){
if(typeof ans.mappingValues.name != "undefined")
lbl=ans.mappingValues.name;
address+= (typeof ans.mappingValues.address != "undefined" && ans.mappingValues.address != null) ? ans.mappingValues.address[0]["name"] : " adresse non renseignée";
if(typeof ans.mappingValues.description != "undefined" && ans.mappingValues.description != null) descrTravaux = ans.mappingValues.description;
if(typeof ans.mappingValues.creatorName != "undefined" && ans.mappingValues.creatorName != null) nameProp = ans.mappingValues.creatorName;
}
var lblp = (typeof ans.answers == "undefined" || ans.answers == null ) ? "no answer" : ans.percent+"%";
var percol = "danger";
var statecol = "danger";
var lblstate = "Pas d'opérateur";
var step = "ouvert";
var icon = "folder-open-o";
var imgAnsw=( ( typeof ans.profilMediumImageUrl != "undefined") ? baseUrl + ans.profilMediumImageUrl : modules.co2.url +"/images/thumbnail-default.jpg" );
var liBg = ( ( ans.todo > 0 ) ? "style='background-color:lightGreen'" : "" );
if( ans.percent > 50 )
percol = "warning";
if( ans.percent > 75 )
percol = "success";
str += '<div class="answerLi col-xs-12 no-padding margin-bottom-10" '+liBg+' >'+
'<div class="col-xs-4">'+
'<img src="'+imgAnsw+'" class="img-responsive margin-auto">'+
'</div>'+
'<div class="col-xs-8 container-infos">'+
'<div class="col-xs-12 no-padding">'+
'<h3 class="margin-top-5 titleAnsw"> '+lbl +'</h3>'+
'</div>'+
'<span class="info-answ bold text-dark">'+address +'</span><br/>'+
'<span class="info-answ bold">'+
'<i class="fa fa-calendar"></i> '+
moment(ans.created).local().locale("fr").format("DD/MM/YYYY HH:mm")+
'</span>';
if ( typeof ans.updated != "undefined" ){
str += ' <span class="info-answ bold">'+
'<i class="fa fa-edit"></i> '+
moment(ans.updated).local().locale("fr").format("DD/MM/YYYY HH:mm")+
'</span>';
}
str += ' <span class="info-answ col-xs-12 no-padding">'+
'<b>Déposé par :</b> '+nameProp +'</span>'+
'<span class="info-answ col-xs-12 no-padding">'+
'<b>Description :</b> '+descrTravaux +'</span>'+
'<span class="info-answ">'+
'<i class="fa fa-'+icon +'"></i> '+step +'</span>'+
'<br/>'+
'<span class="label label-'+percol +'">'+
'<i class="fa fa-pencil-square-o"></i> '+lblp +' </span>'+
'<span class="label label-'+statecol +' margin-left-5">'+
'<i class="fa fa-black-tie"></i> '+lblstate +' </span>'+
'<br/>';
if ( ans.percent != 0 && ans.uids.length > 0) {
if ( ans.tasksPerson.length > 0 ) {
str += '<a href="javascript:;" data-id="'+id+'" class="answerTasksBtn btn btn-xs btn-default">'+
'<i class="fa fa-cogs "></i>Tasks '+
'<span class="margin-5 label label-primary">'+
'<i class="fa fa-square-o"></i> '+todo +
'</span> <span class="margin-5 label label-success">'+
'<i class="fa fa-check-square-o"></i> '+done +' </span>'+
'</a>';
}
}
str += '<div class="col-xs-12 no-padding">'+
'<a href="javascript:;" data-id="'+id+'" data-mode="r" class="btnAnswer lbh margin-top-5 btn btn-open-answer">'+
'<i class="fa fa-sign-in"></i> Lire'+
'</a>';
if(typeof ans.canEdit == "boolean" && ans.canEdit === true){
str += '<a href="javascript:;" data-id="'+id+'" data-mode="w" class="btnAnswer lbh margin-top-5 btn btn-open-answer">'+
'<i class="fa fa-sign-in"></i> Modifer'+
'</a>';
}
str += '</div>'+
'</div>'+
'</div>';
});
str +='</div>';
$(fObj.container).html(str);
fObj.events.answers(fObj);
}
},
events : {
add : function(fObj){
$(fObj.container+' .createForm').off().click( function(){
dyFObj.openForm( fObj.dynForm.form(fObj) )
});
},
answers : function(fObj){
$(fObj.container+' .btnAnswer').off().on("click",function(){
fObj.urls.answer(fObj, $(this).data("id"), null, $(this).data("mode"));
});
},
form : function(fObj){
$(fObj.container+' .application').off().on("click",function(){
fObj.urls.answer(fObj, "new", $(this).data("id"));
});
$(fObj.container+' .allAnswers').off().on("click",function(){
mylog.log("formObj.events.form .allAnswers", $(this).data("id"));
fObj.urls.answers(fObj, $(this).data("id"));
});
$(fObj.container+' .myAnswers').off().on("click",function(){
fObj.urls.myAnswers(fObj, $(this).data("id"));
});
$(fObj.container+' .observatory').off().on("click",function(){
fObj.urls.observatory(fObj, $(this).data("id"));
});
$(fObj.container+' .config').off().on("click",function(){
var idForm = $(this).data("id");
fObj.urls.form(fObj, idForm);
});
// $(fObj.container+' .editFormBtn').off().click( function(){
// dyFObj.openForm( fObj.dynForm.form(fObj) , null, fObj.forms[$(this).data("id")] )
// });
$(fObj.container+' .deleteFormBtn').off().click( function(){
var idF = $(this).data("id");
bootbox.dialog({
title: "Confirmez la suppression",
message: "<span class='text-red bold'><i class='fa fa-warning'></i> Cette action sera irréversible</span>",
buttons: [
{
label: "Ok",
className: "btn btn-primary pull-left",
callback: function() {
getAjax("",baseUrl+"/survey/form/delete/id/"+idF,function(res){
if(res.result)
toastr.success(res.msg);
else
toastr.error(res.msg);
urlCtrl.loadByHash(location.hash);
},"html");
}
},
{
label: "Annuler",
className: "btn btn-default pull-left",
callback: function() {}
}
]
});
});
}
},
manage:{},
actions : {},
dynForm : {
form : function(fObj) {
return {
jsonSchema : {
title : "Créer un Questionnaire",
description : "Tout est possible, faut juste poser les bonnes questions",
icon : "fa-question",
properties : {
name : { label : "Nom du formulaire"},
what : {
label : "Nom d'une Réponse, à quoi correspondent les réponses ?",
placeholder:"Proposition, Dossiers, Projets..."
},
image : dyFInputs.image(),
formid : {
inputType : "hidden",
value: fObj.el.slug+Object.keys(fObj.forms).length
},
parent : {
inputType : "finder",
label : tradDynForm.whoiscarrytheproject,
multiple : true,
rules : { required : true, lengthMin:[1, "parent"]},
initType: ["organizations", "projects"],
openSearch :true
},
image : dyFInputs.image(),
// tpl : {
// inputType : "hidden",
// value:"survey.views.tpls.forms.formWizard"
// },
// answersTpl : {
// inputType : "hidden",
// value:"survey.views.tpls.forms.answers"
//}