Commit 8235754a authored by Clément Damiens's avatar Clément Damiens

Merge branch 'qa'

parents bac03c2a 0d0ef292
...@@ -43,7 +43,7 @@ class NewAction extends CAction ...@@ -43,7 +43,7 @@ class NewAction extends CAction
"keys" => array($costum["slug"]), "keys" => array($costum["slug"]),
"insertOrign" => "costum") ; "insertOrign" => "costum") ;
} }
PHDB::insert( self::ANSWER_COLLECTION, $answer); PHDB::insert( Form::ANSWER_COLLECTION, $answer);
$res = array( "result" => true, $res = array( "result" => true,
"answer" => $answer ); "answer" => $answer );
} catch (CTKException $e){ } catch (CTKException $e){
......
...@@ -109,7 +109,7 @@ $cle = $key ; ...@@ -109,7 +109,7 @@ $cle = $key ;
$value = (!empty($answers)) ? " value='".$answers."' " : ""; $value = (!empty($answers)) ? " value='".$answers."' " : "";
$inpClass = " saveOneByOne"; $inpClass = " saveOneByOne";
$editParamsBtn = ($canEditForm) ? " <a href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='costum.form.params.".$kunik."' class='previewTpl edit".$kunik."Params btn btn-xs btn-danger'><i class='fa fa-cog'></i> </a>" : ""; $editParamsBtn = ($canEditForm) ? " <a href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='params.".$kunik."' class='previewTpl edit".$kunik."Params btn btn-xs btn-danger'><i class='fa fa-cog'></i> </a>" : "";
...@@ -239,7 +239,7 @@ if($mode == "r") ...@@ -239,7 +239,7 @@ if($mode == "r")
{ {
echo " <a href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='costum.form.params.".$kunik."' class='previewTpl paramsonebtn editone".$kunik."Params".$ix." '><i class='fa fa-cog'></i> </a>"; echo " <a href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='params.".$kunik."' class='previewTpl paramsonebtn editone".$kunik."Params".$ix." '><i class='fa fa-cog'></i> </a>";
...@@ -251,7 +251,7 @@ if($mode == "r") ...@@ -251,7 +251,7 @@ if($mode == "r")
{ {
if($value == "cplx") if($value == "cplx")
{ {
echo " <a alt='placeholder' href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='costum.form.params.".$kunik."' class='previewTpl paramsonebtnP editonep".$kunik."Params".$ix." '><i class='fa fa-pencil'></i> </a>"; echo " <a alt='placeholder' href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='params.".$kunik."' class='previewTpl paramsonebtnP editonep".$kunik."Params".$ix." '><i class='fa fa-pencil'></i> </a>";
} }
} }
} }
...@@ -382,7 +382,7 @@ if($mode == "r") ...@@ -382,7 +382,7 @@ if($mode == "r")
{ {
echo " <a href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='costum.form.params.".$kunik."' class='previewTpl paramsonebtn editone".$kunik."Params".$ix." '><i class='fa fa-cog'></i> </a>"; echo " <a href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='params.".$kunik."' class='previewTpl paramsonebtn editone".$kunik."Params".$ix." '><i class='fa fa-cog'></i> </a>";
...@@ -394,7 +394,7 @@ if($mode == "r") ...@@ -394,7 +394,7 @@ if($mode == "r")
{ {
if($value == "cplx") if($value == "cplx")
{ {
echo " <a alt='placeholder' href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='costum.form.params.".$kunik."' class='previewTpl paramsonebtnP editonep".$kunik."Params".$ix." '><i class='fa fa-pencil'></i> </a>"; echo " <a alt='placeholder' href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='params.".$kunik."' class='previewTpl paramsonebtnP editonep".$kunik."Params".$ix." '><i class='fa fa-pencil'></i> </a>";
} }
} }
} }
......
...@@ -169,7 +169,7 @@ $paramsData = [ ...@@ -169,7 +169,7 @@ $paramsData = [
"text" => "texte", "text" => "texte",
"number" => "Nombre", "number" => "Nombre",
"email" => "adresse mail", "email" => "adresse mail",
"unique" => [ "siret" ] "unique" => "Siret"
] ]
]; ];
...@@ -213,7 +213,7 @@ if($mode == "r"){ ?> ...@@ -213,7 +213,7 @@ if($mode == "r"){ ?>
if($canEditForm){ if($canEditForm){
echo " <a href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='costum.form.params.".$kunik."' class='previewTpl paramsonebtn edit".$kunik."ParamsMt '><i class='fa fa-cog' style='padding: 4px;'></i> </a>"; echo " <a href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='params.".$kunik."' class='previewTpl paramsonebtn edit".$kunik."ParamsMt '><i class='fa fa-cog' style='padding: 4px;'></i> </a>";
} }
?> ?>
...@@ -297,13 +297,32 @@ if($mode == "r"){ ?> ...@@ -297,13 +297,32 @@ if($mode == "r"){ ?>
$(this).parent().addClass('true-validate'); $(this).parent().addClass('true-validate');
} }
answer.path = "answers."+$(this).data("form")+"."+$(this).data("id"); if($(this).attr('type') == 'unique' ) {
answer.collection = "answers" ; ajaxPost(null, baseUrl+"/co2/search/globalautocomplete", {"searchType" : ["organizations"], "filters": { "siret" : [$(this).val()] }},
answer.id = "<?php echo $answer["_id"]; ?>"; function (data){
answer.value = $(this).val(); if (Object.entries(data.results).length === 0){
dataHelper.path2Value(answer , function(params) { answer.path = "answers."+$(this).data("form")+"."+$(this).data("id");
//toastr.success('saved'); answer.collection = "answers" ;
}); answer.id = "<?php echo $answer["_id"]; ?>";
answer.value = $(this).val();
dataHelper.path2Value(answer , function(params) {
//toastr.success('saved');
});
} else {
toastr.error('cette organisation existe déjà');
}
}
);
} else {
answer.path = "answers."+$(this).data("form")+"."+$(this).data("id");
answer.collection = "answers" ;
answer.id = "<?php echo $answer["_id"]; ?>";
answer.value = $(this).val();
dataHelper.path2Value(answer , function(params) {
//toastr.success('saved');
});
}
} }
}) })
}); });
...@@ -339,8 +358,6 @@ if($mode == "r"){ ?> ...@@ -339,8 +358,6 @@ if($mode == "r"){ ?>
$(thisAlert).removeClass('alert-validate'); $(thisAlert).removeClass('alert-validate');
} }
</script> </script>
<?php } ?> <?php } ?>
......
<?php if($answer){ <?php if($answer){
?> ?>
<div class="form-group"> <div class="form-group">
<table class="table table-bordered table-hover directoryTable" id="<?php echo $kunik?>">
<?php
$editBtnL = ($canAnswer) ? " <a href='javascript:;' data-id='".$answer["_id"]."' data-collection='".Form::ANSWER_COLLECTION."' data-path='".$answerPath."' class='add".$kunik." btn btn-default'><i class='fa fa-plus'></i> Ajouter une ligne </a>" : "";
$editParamsBtn = ($canEdit) ? " <a href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='params.".$kunik."' class='previewTpl edit".$kunik."Params btn btn-xs btn-danger'><i class='fa fa-cog'></i> </a>" : ""; <?php
$editBtnL = ($canEdit and $mode != "r" and $mode != "pdf") ? " <a href='javascript:;' data-id='".$answer["_id"]."' data-collection='".Form::ANSWER_COLLECTION."' data-path='".$answerPath."' class='add".$kunik." btn btn-default'><i class='fa fa-plus'></i> Ajouter une ligne </a>" : "";
$editParamsBtn = ($canEditForm and $mode != "r" || $mode != "pdf") ? " <a href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='params.".$kunik."' class='previewTpl edit".$kunik."Params btn btn-xs btn-danger'><i class='fa fa-cog'></i> </a>" : "";
$a = []; $a = [];
...@@ -97,9 +96,12 @@ ...@@ -97,9 +96,12 @@
?> ?>
<?php if( $mode != "pdf" ){ ?>
<table class="table table-bordered table-hover directoryTable" id="<?php echo $kunik?>">
<thead> <thead>
<tr> <tr>
<td colspan='<?php echo count( $properties)+2?>' ><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn.$editParamsBtn.$editBtnL?></h4> <td colspan="<?php if( $mode != "r"){ echo count( $properties)+2 ; } else { echo count( $properties) ;} ?>" ><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn.$editParamsBtn.$editBtnL?></h4>
<?php echo $info ?> <?php echo $info ?>
</td> </td>
</tr> </tr>
...@@ -115,7 +117,9 @@ ...@@ -115,7 +117,9 @@
echo "<th>".$inp["placeholder"]."</th>"; echo "<th>".$inp["placeholder"]."</th>";
} }
} ?> } ?>
<th></th> <?php if( $mode != "r" ){ ?>
<th></th>
<?php } ?>
</tr> </tr>
<tr></tr> <tr></tr>
<?php } ?> <?php } ?>
...@@ -152,19 +156,21 @@ ...@@ -152,19 +156,21 @@
} }
} }
?> ?>
<td style="white-space: normal;"> <?php if( $mode != "r"){?>
<?php <td style="white-space: normal;">
$this->renderPartial( "survey.views.tpls.forms.cplx.editDeleteLineBtn" , [ <?php
"canEdit"=>($canEdit || $canAnswer), $this->renderPartial( "survey.views.tpls.forms.cplx.editDeleteLineBtn" , [
"id" => $answer["_id"], "canEdit"=>($canEdit),
"collection" => Form::ANSWER_COLLECTION, "id" => $answer["_id"],
"q" => $q, "collection" => Form::ANSWER_COLLECTION,
"path" => $answerPath.$q, "q" => $q,
"keyTpl"=>$kunik "path" => $answerPath.$q,
] ); ?> "keyTpl"=>$kunik
] ); ?>
<a href="javascript:;" class="btn btn-xs btn-primary openAnswersComment" onclick="commentObj.openPreview('answers','<?php echo $answer["_id"]?>','<?php echo $answer["_id"].$key.$q ?>', '<?php echo @$a['step'] ?>')"><?php echo PHDB::count(Comment::COLLECTION, array("contextId"=>$answer["_id"],"contextType"=>"answers", "path"=>$answer["_id"].$key.$q))?> <i class='fa fa-commenting'></i></a>
</td> <a href="javascript:;" class="btn btn-xs btn-primary openAnswersComment" onclick="commentObj.openPreview('answers','<?php echo $answer["_id"]?>','<?php echo $answer["_id"].$key.$q ?>', '<?php echo @$a['step'] ?>')"><?php echo PHDB::count(Comment::COLLECTION, array("contextId"=>$answer["_id"],"contextType"=>"answers", "path"=>$answer["_id"].$key.$q))?> <i class='fa fa-commenting'></i></a>
</td>
<?php } ?>
<?php <?php
$ct++; $ct++;
echo "</tr>"; echo "</tr>";
...@@ -174,7 +180,77 @@ ...@@ -174,7 +180,77 @@
?> ?>
</tbody> </tbody>
</table> </table>
<?php
} else {
?>
<div>
<label>
<h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn.$editParamsBtn.$editBtnL?></h4>
<?php echo $info ?>
</label>
</div>
<table class="table table-bordered table-hover directoryTable" id="<?php echo $kunik?>">
<thead>
<tr>
<?php
if( count($answers)>0 ){
foreach ($properties as $i => $inp) {
if (isset($inp["placeholder"])){
echo "<th>".$inp["placeholder"]."</th>";
}
} ?>
<?php } ?>
</tr>
</thead>
<tbody class="directoryLines">
<?php
if(isset($answers)){
foreach ($answers as $q => $a) {
echo "<tr id='".$kunik.$q."' class='".$kunik."Line'>";
foreach ($properties as $i => $inp) {
if($i == "location"){
} else {
echo "<td>";
if(isset($a[$i])) {
if($i == "pointGPS"){
//$nameM = $a["localisation"];
$lat = $a["pointGPS"]["latitude"];
$lon = $a["pointGPS"]["longitude"];
echo $a["pointGPS"]["latitude"]." / ".$a["pointGPS"]["longitude"];
//echo implode(",", $a["pointGPS"]);
echo '<span class="pull-right" style= "margin-right : 5px;"><a id="showActeurLocation" href="javascript:;" onclick=""><i class="fa fa-map-o" aria-hidden="true"></i></a></span>';
}
else if(is_array($a[$i])){
echo implode(",", $a["port"]);
}
else{
echo $a[$i];
}
}
echo "</td>";
}
}
echo "</tr>";
}
}
?>
</tbody>
</table>
<?php } ?>
</div> </div>
<?php if( $mode != "pdf"){?>
<script type="text/javascript"> <script type="text/javascript">
var <?php echo $kunik ?>Data = <?php echo json_encode( (isset($answers)) ? $answers : null ); ?>; var <?php echo $kunik ?>Data = <?php echo json_encode( (isset($answers)) ? $answers : null ); ?>;
...@@ -317,6 +393,4 @@ ...@@ -317,6 +393,4 @@
}); });
</script> </script>
<?php } else { <?php } } ?>
//echo "<h4 class='text-red'>CALENDAR works with existing answers</h4>"; \ No newline at end of file
} ?>
\ No newline at end of file
<?php if($answer){ <?php if($answer){
?> ?>
<div class="form-group"> <div class="form-group">
<table class="table table-bordered table-hover directoryTable" id="<?php echo $kunik?>">
<?php <?php
$editBtnL = ($canAnswer) ? " <a href='javascript:;' data-id='".$answer["_id"]."' data-collection='".Form::ANSWER_COLLECTION."' data-path='".$answerPath."' class='add".$kunik." btn btn-default'><i class='fa fa-plus'></i> Ajouter une ligne </a> <a href='javascript:;' data-id='".$answer["_id"]."' data-collection='answers' data-path='answers.sommomForm1.sommomForm122.' class='addorganismesommomForm122 btn btn-default'><i class='fa fa-plus'></i> Ajouter un organisme </a>'" : ""; $editBtnL = ($canEdit and $mode != "r" and $mode != "pdf") ? " <a href='javascript:;' data-id='".$answer["_id"]."' data-collection='".Form::ANSWER_COLLECTION."' data-path='".$answerPath."' class='add".$kunik." btn btn-default'><i class='fa fa-plus'></i> Ajouter une ligne </a>" : "";
$editParamsBtn = ($canEditForm and $mode != "r" || $mode != "pdf") ? " <a href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='params.".$kunik."' class='previewTpl edit".$kunik."Params btn btn-xs btn-danger'><i class='fa fa-cog'></i> </a>" : "";
$editParamsBtn = ($canEdit) ? " <a href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='params.".$kunik."' class='previewTpl edit".$kunik."Params btn btn-xs btn-danger'><i class='fa fa-cog'></i> </a>" : "";
$paramsData = [ $paramsData = [
"statut" => [ "statut" => [
...@@ -114,10 +113,12 @@ ...@@ -114,10 +113,12 @@
} }
?> ?>
<?php if( $mode != "pdf" ){ ?>
<table class="table table-bordered table-hover directoryTable" id="<?php echo $kunik?>">
<thead> <thead>
<tr> <tr>
<td colspan='<?php echo count( $properties)+2?>' ><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn.$editParamsBtn.$editBtnL?></h4> <td colspan="<?php if( $mode != "r"){ echo count( $properties)+2 ; } else { echo count( $properties) ;} ?>" ><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn.$editParamsBtn.$editBtnL?></h4>
<?php echo $info ?> <?php echo $info ?>
</td> </td>
</tr> </tr>
...@@ -135,7 +136,9 @@ ...@@ -135,7 +136,9 @@
} }
} }
} ?> } ?>
<th></th> <?php if( $mode != "r" ){ ?>
<th></th>
<?php } ?>
</tr> </tr>
<tr></tr> <tr></tr>
<?php } ?> <?php } ?>
...@@ -175,19 +178,21 @@ ...@@ -175,19 +178,21 @@
} }
?> ?>
<td style="white-space: normal;"> <?php if( $mode != "r"){?>
<?php <td style="white-space: normal;">
$this->renderPartial( "survey.views.tpls.forms.cplx.editDeleteLineBtn" , [ <?php
"canEdit"=>($canEdit || $canAnswer), $this->renderPartial( "survey.views.tpls.forms.cplx.editDeleteLineBtn" , [
"id" => $answer["_id"], "canEdit"=>($canEdit),
"collection" => Form::ANSWER_COLLECTION, "id" => $answer["_id"],
"q" => $q, "collection" => Form::ANSWER_COLLECTION,
"path" => $answerPath.$q, "q" => $q,
"keyTpl"=>$kunik "path" => $answerPath.$q,
] ); ?> "keyTpl"=>$kunik
] ); ?>
<a href="javascript:;" class="btn btn-xs btn-primary openAnswersComment" onclick="commentObj.openPreview('answers','<?php echo $answer["_id"]?>','<?php echo $answer["_id"].$key.$q ?>', '<?php echo @$a['step'] ?>')"><?php echo PHDB::count(Comment::COLLECTION, array("contextId"=>$answer["_id"],"contextType"=>"answers", "path"=>$answer["_id"].$key.$q))?> <i class='fa fa-commenting'></i></a>
</td> <a href="javascript:;" class="btn btn-xs btn-primary openAnswersComment" onclick="commentObj.openPreview('answers','<?php echo $answer["_id"]?>','<?php echo $answer["_id"].$key.$q ?>', '<?php echo @$a['step'] ?>')"><?php echo PHDB::count(Comment::COLLECTION, array("contextId"=>$answer["_id"],"contextType"=>"answers", "path"=>$answer["_id"].$key.$q))?> <i class='fa fa-commenting'></i></a>
</td>
<?php } ?>
<?php <?php
$ct++; $ct++;
echo "</tr>"; echo "</tr>";
...@@ -197,7 +202,87 @@ ...@@ -197,7 +202,87 @@
?> ?>
</tbody> </tbody>
</table> </table>
<?php
} else {
?>
<div>
<label>
<h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn.$editParamsBtn.$editBtnL?></h4>
<?php echo $info ?>
</label>
</div>
<table class="table table-bordered table-hover directoryTable" id="<?php echo $kunik?>">
<thead>
<?php
if( count($answers)>0 ){ ?>
<tr>
<?php
foreach ($properties as $i => $inp) {
if(isset($inp["label"])){
if(isset($inp["label"])){
echo "<th>".$inp["label"]."</th>";
}
}
} ?>
</tr>
<?php } ?>
</thead>
<tbody class="directoryLines">
<?php
$ct = 0;
if(isset($answers)){
foreach ($answers as $q => $a) {
echo "<tr id='".$kunik.$q."' class='".$kunik."Line'>";
foreach ($properties as $i => $inp) {
if($i == "location"){
} else {
echo "<td>";
if(isset($a[$i])) {
if($i == "coord"){
$lat = $a["coord"]["latitude"];
$lon = $a["coord"]["longitude"];
echo $a["coord"]["latitude"]." / ".$a["coord"]["longitude"];
//echo implode(",", $a["coord"]);
echo '<span class="pull-right" style= "margin-right : 5px;"><a id="showActeurLocation" href="javascript:;" onclick=""><i class="fa fa-map-o" aria-hidden="true"></i></a></span>';
}
else if(is_array($a[$i])){
echo implode(",", $a[$i]);
}
else if($i == "site") {
echo "<a href='".$a[$i]."'>".$a[$i]."</a>";
}
else{
echo $a[$i];
}
}
echo "</td>";
}
}
echo "</tr>";
}
}
?>
</tbody>
</table>
<?php } ?>
</div> </div>
<?php if( $mode != "pdf"){?>
<script type="text/javascript"> <script type="text/javascript">
var <?php echo $kunik ?>Data = <?php echo json_encode( (isset($answers)) ? $answers : null ); ?>; var <?php echo $kunik ?>Data = <?php echo json_encode( (isset($answers)) ? $answers : null ); ?>;
...@@ -333,6 +418,4 @@ ...@@ -333,6 +418,4 @@
}); });
</script> </script>
<?php } else { <?php } } ?>
//echo "<h4 class='text-red'>CALENDAR works with existing answers</h4>"; \ No newline at end of file
} ?>
\ No newline at end of file
{
"_id" : ObjectId("5e4fbf0041e01ff668c90f2f"),
"id" : "sommomForm1",
"type" : "openForm",
"name" : "TERRITOIRE – DESCRIPTION GENERALE",
"inputs" : {
"sommomForm120" : {
"label" : "Nom du territoire",
"placeholder" : "",
"info" : "Quel est le territoire décrit ? (territoire français d'outre-mer ou métropolitain)",
"type" : "tpls.forms.text",
"position" : "1"
},
"sommomForm121" : {
"label" : "Nombre d'îles",
"placeholder" : "",
"info" : "Combien d'îles composent le territoire décrit ?",
"type" : "tpls.forms.text",
"position" : "2"
},
"sommomForm128" : {
"label" : "Geeolocalisation du territoire",
"placeholder" : "",
"info" : "",
"type" : "tpls.forms.sommom.mapterritoire",
"position" : "3"
},
"sommomForm19" : {
"label" : "Photo",
"placeholder" : "",
"info" : "",
"type" : "tpls.forms.uploader",
"uploader" : {
"docType" : "file",
"paste" : true,
"itemLimit" : 1
},
"position" : "4"
},
"sommomForm122" : {
"label" : "Organisme de ce territoire",
"placeholder" : "",
"info" : "Organisme de ce territoire",
"type" : "tpls.forms.sommom.organisme",
"position" : "5"
},
"sommomForm11" : {
"label" : "Espace géographique du territoire",
"placeholder" : "",
"info" : "Généralités",
"type" : "tpls.forms.sommom.geographie",