Commit 7cbb6fa0 authored by Raph El's avatar Raph El
Browse files

Form : add all answers formObj

parent c1b0ea91
......@@ -5,6 +5,10 @@ var formObj = {
container : "#central-container" ,
forms :{},
el : {},
labels : {
answer : "dossier",
answers : "dossiers",
},
//filterSearch : {},
init : function(pInit = null){
mylog.log("fObj init",pInit);
......@@ -21,12 +25,15 @@ var formObj = {
initDefaults : function(pInit){},
initEvents : function(pInit){},
initViews : function(pInit){
if(location.hash.indexOf(hashUrlPage+".view.forms.form.")>=0){
if(location.hash.indexOf(hashUrlPage+".view.forms.form.dir")>=0){
var hashArray = location.hash.split('.');
this.urls.form(this, hashArray[4]);
}else if(location.hash.indexOf(hashUrlPage+".view.forms.answer.")>=0){
}else if(location.hash.indexOf(hashUrlPage+".view.forms.dir.answer.")>=0){
var hashArray = location.hash.split('.');
this.urls.answer(this, hashArray[4]);
}else if(location.hash.indexOf(hashUrlPage+".view.forms.dir.answers.form")>=0){
var hashArray = location.hash.split('.');
this.urls.answers(this, hashArray[6]);
} else{
this.urls.forms(this);
}
......@@ -41,7 +48,7 @@ var formObj = {
if(typeof data != "undefined" && data != null &&
data.forms != "undefined" && data.forms != null){
fObj.el = data.el;
fObj.views.forms(data.forms, fObj);
fObj.views.forms(fObj, data.forms);
}
history.replaceState(location.hash, "", hashUrlPage+".view.forms");
......@@ -51,7 +58,7 @@ var formObj = {
ajaxPost(fObj.container, baseUrl+'/survey/form/edit/id/'+id,
null,
function(){
history.replaceState(location.hash, "", hashUrlPage+".view.forms.form."+id);
history.replaceState(location.hash, "", hashUrlPage+".view.forms.dir.form."+id);
},"html");
},
answer : function(fObj, id, form){
......@@ -62,8 +69,18 @@ var formObj = {
ajaxPost(fObj.container, baseUrl+url,
null,
function(){
history.replaceState(location.hash, "", hashUrlPage+".view.forms.answer."+id);
history.replaceState(location.hash, "", hashUrlPage+".view.forms.dir.answer."+id);
},"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);
});
}
},
initFilters : function(){},
......@@ -73,7 +90,7 @@ var formObj = {
results : {},
search : {},
views : {
forms : function(forms,fObj){
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>'+
......@@ -89,18 +106,227 @@ var formObj = {
fObj.events.form(fObj);
},
form : function(id, form){
var str='<div class="panel panel-primary col-sm-6 col-xs-12" id="'+id+'Form">'+
'<div class="panel-heading">'+
'<h3 class="panel-title">'+form.name+'</h3>'+
'</div>'+
'<div class="panel-body">'+
var str='<div class="col-sm-6 col-xs-12" id="'+id+'Form">'+
'<div class="panel panel-primary">'+
'<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>'+
'<a href="javascript:;" class="pull-right editFormBtn" data-id="'+id+'">'+
'<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){
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>';
}
} else {
if(typeof form.canEditForm != "undefined" && form.canEditForm === true){
str += '<a href="javascript:;" data-id="'+id+'" class="btn btn-xs btn-primary config col-sm-12 bold">'+
'<i class="fa fa-pencil"></i> Build '+
'</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="#answer.index.id.'+id+'.mode.w" class="lbh margin-top-5 btn btn-open-answer">'+
'<i class="fa fa-sign-in"></i> Ouvrir'+
'</a>'+
'</div>'+
'</div>'+
'</div>';
});
str +='</div>';
$(fObj.container).html(str);
},
},
events : {
add : function(fObj){
$(fObj.container+' .createForm').off().click( function(){
dyFObj.openForm( fObj.dynForm.form(fObj) )
});
},
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(){
// ajaxPost(fObj.results.dom, baseUrl+"/survey/answer/views/",
// data,
// function(){
// fObj.results.events(fObj);
// });
// var data{
// allAnswers=results
// }
// if(Object.keys(results).length > 0){
// ajaxPost(fObj.results.dom, baseUrl+"/survey/answer/views/",
// data,
// function(){
// fObj.results.events(fObj);
// });
// }
});
$(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 : {},
......@@ -174,135 +400,4 @@ var formObj = {
}
}
}
};
formObj.views.form = function(id, form){
var str='<div class="col-sm-6 col-xs-12" id="'+id+'Form">'+
'<div class="panel panel-primary">'+
'<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>'+
'<a href="javascript:;" class="pull-right editFormBtn" data-id="'+id+'">'+
'<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){
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>';
}
} else {
if(typeof form.canEditForm != "undefined" && form.canEditForm === true){
str += '<a href="javascript:;" data-id="'+id+'" class="btn btn-xs btn-primary config col-sm-12 bold">'+
'<i class="fa fa-pencil"></i> Build '+
'</a>';
}
}
str += '</div>'+
'</div>'+
'</div>'+
'</div>';
return str ;
} ;
formObj.events.add = function(fObj){
$(fObj.container+' .createForm').off().click( function(){
dyFObj.openForm( fObj.dynForm.form(fObj) )
});
};
formObj.events.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(){
getAjax(fObj.container,
baseUrl+"/survey/answer/get/form/"+$(this).data("id"),function(){
},"html");
});
$(fObj.container+' .myAnswers').off().on("click",function(){
// ajaxPost(fObj.results.dom, baseUrl+"/survey/answer/views/",
// data,
// function(){
// fObj.results.events(fObj);
// });
// var data{
// allAnswers=results
// }
// if(Object.keys(results).length > 0){
// ajaxPost(fObj.results.dom, baseUrl+"/survey/answer/views/",
// data,
// function(){
// fObj.results.events(fObj);
// });
// }
});
$(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() {}
}
]
});
});
};
formObj.events.form(formObj);
formObj.events.add(formObj);
};
\ No newline at end of file
......@@ -15,12 +15,99 @@ class DirectoryAction extends CAction
//var_dump($params["form"]);exit;
$answers=Answer::globalAutocomplete($res["form"], $searchParams);
$answerList = Form::listForAdmin($answers["results"]) ;
foreach ($answerList as $key => $value) {
$globalLinks = [];
$gUids = [];
foreach ($answerList as $key => $ans) {
if(isset($res["form"]["mapping"])){
$answerList[$key]["mappingValues"]=Answer::getMappingValues($res["form"]["mapping"], $value);
$answerList[$key]["mappingValues"]=Answer::getMappingValues($res["form"]["mapping"], $ans);
}
$answerList[$key]["countComment"] = PHDB::count(Comment::COLLECTION, array("contextId"=>$key,"contextType"=>Form::ANSWER_COLLECTION));
$localLinks = [];
$uids = [];
$todo = 0;
$done = 0;
$tasksPerson = [];
// $imgAnsw=(isset($ans["profilMediumImageUrl"])) ? Yii::app()->createUrl($ans["profilMediumImageUrl"]) : Yii::app()->getModule( Yii::app()->params["module"]["parent"] )->getAssetsUrl()."/images/thumbnail-default.jpg";
if(!isset($ans["answers"])) {
$percent = 0;
} else {
$totalInputs = 0;
$answeredInputs = 0;
foreach ($res["forms"] as $fid => $f){
$totalInputs += count($f["inputs"]);
//echo "|".$f['id']."-fi=".count($f["inputs"]);
if( isset( $ans["answers"][$fid] ) ){
$answeredInputs += count( $ans["answers"][$fid] );
//echo "|".$f['id']."-ai=".count( $ans["answers"][$f['id']] )."<br/>";
}
//todo lists are on depense for the moment
//todo genereaclly not with a fixed input ID
if( isset( $ans["answers"][$fid]["depense"] ) ){
foreach ( $ans["answers"][$fid]["depense"] as $ix => $dep) {
if( isset( $dep["todo"] ) ){
foreach ($dep["todo"] as $ixx => $t) {
if(!isset($t["done"]) || $t["done"] == "0"){
$todo++;
$whos = (is_array($t["who"])) ? $t["who"] : explode(",",$t["who"]);
foreach ( $whos as $whoix => $who ) {
if( !isset( $tasksPerson[ $who ] ) )
$tasksPerson[ $who ] = [];
$tasksPerson[ $who ][] = $t["what"];
}
}
else
$done++;
}
}
}
}
}
if(isset($ans["links"])){
foreach ( $ans["links"] as $type => $ls ){
if(!isset($localLinks[$type]))
$localLinks[$type] = [];
if(!isset($globalLinks[$type]))
$globalLinks[$type] = [];
// if($type == "operators"){
// $lblstate = "Opérateur à valider";
// $statecol = "warning";
// foreach ($ls as $oid => $ov) {
// if($ov != "0"){
// $lblstate = "Opérateur OK";
// $statecol = "primary";
// }
// }
// }
foreach ($ls as $uid => $time) {
if(is_string($uid) && strlen($uid) == 24 && ctype_xdigit($uid)){
if(!in_array($uid, $localLinks[$type] ))
$localLinks[$type][] = $uid;
if(!in_array($uid, $uids ))
$uids[] = new MongoId( $uid );
if(!in_array($uid, $globalLinks[$type] ))
$globalLinks[$type][] = $uid;
if(!in_array($uid, $gUids ))
$gUids[] = new MongoId( $uid );
}
}
}
}
$percent = floor( $answeredInputs*100 / $totalInputs );
}
$answerList[$key]["percent"] = $percent;
$answerList[$key]["uids"] = $uids;
$answerList[$key]["todo"] = $todo;
$answerList[$key]["done"] = $done;
$answerList[$key]["tasksPerson"] = $tasksPerson;
}
if(isset($answers["count"]))
$res["count"]=$answers["count"];
$res["results"] = $answerList ;
......
......@@ -3,7 +3,7 @@ class GetAction extends CTKAction
{
//if $slug : getd all the forms for an element.slug
//if $id : opens the forms
public function run($form = null, $userId = null)
public function run($form = null, $userId = null, $tpl = null)
{
$controller=$this->getController();
......@@ -24,10 +24,12 @@ class GetAction extends CTKAction
$params["wizid"] = $form;
$tpl=(!empty($params["form"]["answersTpl"])) ? $params["form"]["answersTpl"] : 'survey.views.tpls.forms.cplx.answers';
if(empty($tpl))
$tpl=(!empty($params["form"]["answersTpl"])) ? $params["form"]["answersTpl"] : 'survey.views.tpls.forms.cplx.answers';
if(Yii::app()->request->isAjaxRequest)
if($tpl == "json"){
Rest::json($params);
} else if(Yii::app()->request->isAjaxRequest)
echo $controller->renderPartial( $tpl , $params, true);
else
echo $controller->render( $tpl , $params, true);
......
......@@ -163,8 +163,8 @@ class Form {
if(!empty($source)){
$queryForm=array("source.keys"=>array('$in'=>[$source]));
}
if(!empty($form)){
$queryForm=array("_id"=>new MongoId($form));
if(!empty($id)){
$queryForm=array("_id"=>new MongoId($id));
}
$res["form"]=PHDB::findOne( Form::COLLECTION, $queryForm );
$res["forms"] = [];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment