Commit 58e3ddfa authored by Tibor Katelbach's avatar Tibor Katelbach
Browse files

ajout de sommom dans dev

parent 2d5aeabf
......@@ -68,6 +68,13 @@ var oformParams = {
inputType : "date",
label : "Date de fin"
},
anyOnewithLinkCanAnswer : {
inputType : "checkboxSimple",
label : "Partage par lien",
subLabel : "Tout ceux qui ont le lien pourront répondre",
params : { onText : "Oui",offText : "Non",onLabel : "Oui",offLabel : "Non",
labelText : "Réponse unique"},
checked : true },
oneAnswerPerPers: {
inputType : "checkboxSimple",
label : "Bloquer à une réponse par personne",
......
......@@ -22,9 +22,9 @@ $showClass = ($this->module->id == "survey" && Yii::app()->controller->id == "an
foreach ($allAnswers as $k => $ans) {
$ct++;
$lbl = $what." ".$ct;
if(isset(Yii::app()->session["costum"]["form"]["title"]))
if(isset($parentForm["title"]))
{
$titlePath = explode( ".", Yii::app()->session["costum"]["form"]["title"] );
$titlePath = explode( ".", $parentForm["title"] );
if(isset($ans["answers"][$titlePath[0]][$titlePath[1]]))
$lbl = $ans["answers"][$titlePath[0]][$titlePath[1]];
}
......
......@@ -54,7 +54,7 @@ if( isset( $form["inputs"] ) ){ ?>
$dragNDrop = ($canEditForm) ? "dragNDrop" : "" ;
echo "<ul class='questionList ".$dragNDrop."'>";
foreach ( $form["inputs"] as $key => $input) {
$canAnswer = Yii::app()->session["userId"] == $answer["user"] || $parentForm["anyOnewithLinkCanAnswer"];
$editQuestionBtn = ($canEditForm) ? " <a class='btn btn-xs btn-danger editQuestion' href='javascript:;' data-form='".$form["id"]."' data-id='".$form["_id"]."' data-collection='".Form::COLLECTION."' data-key='".$key."' data-path='inputs.".$key."'><i class='fa fa-pencil'></i></a>".
" <a class='btn btn-xs btn-danger deleteLine' href='javascript:;' data-id='".$form["_id"]."' data-collection='".Form::COLLECTION."' data-key='question".$key."' data-path='inputs.".$key."'><i class='fa fa-trash'></i></a>" : "";
......@@ -108,6 +108,7 @@ if( isset( $form["inputs"] ) ){ ?>
"mode" => $mode,
"canEdit" => $canEdit,
"canEditForm" => @$canEditForm,
"canAnswer" => $canAnswer,
"editQuestionBtn" => @$editQuestionBtn,
"saveOneByOne" => $saveOneByOne,
"wizard" => (isset($wizard) && $wizard == true) ,
......
<?php if($answer){
?>
<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>" : "";
$a = [];
if(isset($answer["answers"]["sommomForm1"])){
if(is_array($answer["answers"]["sommomForm1"])){
foreach ($answer["answers"]["sommomForm1"] as $i => $inp) {
if(is_array($inp)){
foreach ($inp as $line) {
if(isset($line["portName"])){
$a += array($line["portName"] => $line["portName"]);
}
}
}
}
}
}
$paramsData = [
"statut" => [
"Collectivité (commune, département, région…)" => "Collectivité (commune, département, région…)",
"Service représentant de l’Etat (DEAL, affaires maritimes, préfectures…)" => "Service représentant de l’Etat (DEAL, affaires maritimes, préfectures…)",
"Association environnementale" => "Association environnementale",
"Association de sport et loisir " => "Association de sport et loisir ",
"Syndicats, fédérations, représentants d’acteurs de la mer (FFESSM…)" => "Syndicats, fédérations, représentants d’acteurs de la mer (FFESSM…)",
"Structure privée commerciale" => "Structure privée commerciale",
"Institut de recherche (IRD, Ifremer,...)" => "Institut de recherche (IRD, Ifremer,...)",
"Autre" => "Autre"
]
];
if( isset($parentForm["params"][$kunik]["statut"]) )
$paramsData["statut"] = $parentForm["params"][$kunik]["statut"];
$properties = [
"intituleact" => [
"label" => "Nom de la structure",
"placeholder" => "Nom de la structure",
"inputType" => "text",
"rules" => [ "required" => true ]
],
"statut" => [
"label" => "Statut",
"placeholder" => "Statut",
"inputType" => "select",
"noOrder" => true,
"options" => $paramsData["statut"],
"rules" => [ "required" => true ]
],
"navire" => [
"label" => "Nombre de navires ou appareils",
"placeholder" => "Nombre de navires ou appareils",
"inputType" => "text",
"rules" => [ "required" => true ]
],
"port" => [
"label" => "Port d’exploitation de l’activité",
"placeholder" => "Port d’exploitation de l’activité",
"inputType" => "selectMultiple",
"options" => $a,
"rules" => [ "required" => true ]
]
];
$propertiesParams = [
"labels"=>[],
"placeholders"=>[],
];
foreach ($properties as $k => $v) {
if( isset($v["label"])){
if( isset($parentForm["params"][$kunik]["labels"][$k]) )
$properties[$k]["label"] = $parentForm["params"][$kunik]["labels"][$k];
$propertiesParams["labels"][$k] = $properties[$k]["label"];
}
if( isset($v["placeholder"])){
if(isset($parentForm["params"][$kunik]["placeholders"][$k]) )
$properties[$k]["placeholder"] = $parentForm["params"][$kunik]["placeholders"][$k];
$propertiesParams["placeholders"][$k] = $properties[$k]["placeholder"];
}
}
?>
<thead>
<tr>
<td colspan='<?php echo count( $properties)+2?>' ><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn.$editParamsBtn.$editBtnL?></h4>
<?php echo $info ?>
</td>
</tr>
<?php
if( count($answers)>0 ){ ?>
<tr>
</th>
<?php
foreach ($properties as $i => $inp) {
if (isset($inp["placeholder"])){
echo "<th>".$inp["placeholder"]."</th>";
}
} ?>
<th></th>
</tr>
<tr></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 == "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>";
}
}
?>
<td style="white-space: normal;">
<?php
$this->renderPartial( "survey.views.tpls.forms.cplx.editDeleteLineBtn" , [
"canEdit"=>($canEdit || $canAnswer),
"id" => $answer["_id"],
"collection" => Form::ANSWER_COLLECTION,
"q" => $q,
"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>
<?php
$ct++;
echo "</tr>";
}
}
?>
</tbody>
</table>
</div>
<script type="text/javascript">
var <?php echo $kunik ?>Data = <?php echo json_encode( (isset($answers)) ? $answers : null ); ?>;
sectionDyf.<?php echo $kunik ?>ParamsData = <?php echo json_encode( $paramsData ); ?>;
sectionDyf.<?php echo $kunik ?>ParamsProperty = {
labels : <?php echo json_encode( $propertiesParams["labels"] ); ?>,
placeholders : <?php echo json_encode( $propertiesParams["placeholders"] ); ?>
};
$(document).ready(function() {
sectionDyf.<?php echo $kunik ?> = {
"jsonSchema" : {
"title" : "Les acteurs de l’encadrement de l’activité",
"icon" : "fa-globe",
"text" : "Décrire ici les principaux postes de dépenses : à quoi correspondent les coûts ? <br/>Préciser ce qui relève des dépenses de fonctionnement et des dépenses d’investissement.<br/>Les coûts doivent être en <b>hors taxe</b>.",
"properties" : <?php echo json_encode( $properties ); ?>,
save : function () {
var today = new Date();
tplCtx.value = { date : today.getDate() + '/' + (today.getMonth()+1) + '/' + today.getFullYear() };
$.each( sectionDyf.<?php echo $kunik ?>.jsonSchema.properties , function(k,val) {
if(val.inputType == "properties")
tplCtx.value[k] = getPairsObj('.'+k+val.inputType);
else if(val.inputType == "array")
tplCtx.value[k] = getArray('.'+k+val.inputType);
else if(val.inputType == "formLocality")
tplCtx.value[k] = getArray('.'+k+val.inputType);
else
tplCtx.value[k] = $("#"+k).val();
});
mylog.log("save tplCtx",tplCtx);
if(typeof tplCtx.value == "undefined")
toastr.error('value cannot be empty!');
else {
dataHelper.path2Value( tplCtx, function(params) {
$("#ajax-modal").html("<div class='text-center'><i class='fa fa-spin fa-spinner'></i></div>");//$("#ajax-modal").modal('hide');
location.reload();
} );
}
}
}
};
sectionDyf.<?php echo $kunik ?>Params = {
"jsonSchema" : {
"title" : "<?php echo $kunik ?> config",
"description" : "Liste de question possible",
"icon" : "fa-cog",
"properties" : {
labels : {
inputType : "properties",
labelKey : "Clef",
labelValue : "Libellé du champs",
label : "Modifier les libélés des Questions",
values : sectionDyf.<?php echo $kunik ?>ParamsProperty.labels
},
placeholders : {
inputType : "properties",
labelKey : "Clef",
labelValue : "Texte dans le champs",
label : "Modifier les textes à l'interieur du champs de saisie",
values : sectionDyf.<?php echo $kunik ?>ParamsProperty.placeholders
},
statut : {
inputType : "array",
label : "Liste des statuts",
value : sectionDyf.<?php echo $kunik ?>ParamsData.statut
},
},
save : function (formData) {
mylog.log("save tplCtx formData",formData);
tplCtx.value = {};
$.each( sectionDyf.<?php echo $kunik ?>Params.jsonSchema.properties , function(k,val) {
if(val.inputType == "properties")
tplCtx.value[k] = getPairsObj('.'+k+val.inputType);
else if(val.inputType == "array")
tplCtx.value[k] = getArray('.'+k+val.inputType);
else
tplCtx.value[k] = $("#"+k).val();
mylog.log("value",'.'+k+val.inputType,tplCtx.value[k]);
});
if(typeof formData != "undefined" && typeof formData.geo != "undefined"){
tplCtx.value["pointGPS"] = formData.geo;
tplCtx.value["address"] = formData.address;
tplCtx.value["geo"] = formData.geo;
tplCtx.value["geoPosition"] = formData.geoPosition;
if(typeof formData.addresses != "undefined")
tplCtx.value["addresses"] = formData.addresses;
}
mylog.log("save tplCtx",tplCtx);
if(typeof tplCtx.value == "undefined")
toastr.error('value cannot be empty!');
else {
dataHelper.path2Value( tplCtx, function(params) {
$("#ajax-modal").html("<div class='text-center'><i class='fa fa-spin fa-spinner'></i></div>");
location.reload();
} );
}
}
}
};
mylog.log("render","/modules/costum/views/tpls/forms/<?php echo $kunik ?>.php");
//adds a line into answer
$(".add<?php echo $kunik ?>").off().on("click",function() {
tplCtx.id = $(this).data("id");
tplCtx.collection = $(this).data("collection");
tplCtx.path = $(this).data("path")+((notNull(<?php echo $kunik ?>Data) ? <?php echo $kunik ?>Data.length : "0"));
dyFObj.openForm( sectionDyf.<?php echo $kunik ?> );
});
$(".edit<?php echo $kunik ?>").off().on("click",function() {
tplCtx.id = $(this).data("id");
tplCtx.collection = $(this).data("collection");
tplCtx.path = $(this).data("path");
dyFObj.openForm( sectionDyf.<?php echo $kunik ?>,null, <?php echo $kunik ?>Data[$(this).data("key")]);
});
$(".edit<?php echo $kunik ?>Params").off().on("click",function() {
tplCtx.id = $(this).data("id");
tplCtx.collection = $(this).data("collection");
tplCtx.path = $(this).data("path");
//if no params config on the element.costum.form.params.<?php echo $kunik ?>
//then we load default values available in forms.inputs.<?php echo $kunik ?>xxx.params
//mylog.log(".editParams",sectionDyf.<?php echo $kunik ?>Params,calData);
dyFObj.openForm( sectionDyf.<?php echo $kunik ?>Params,null, sectionDyf.<?php echo $kunik ?>ParamsData);
});
});
</script>
<?php } else {
//echo "<h4 class='text-red'>CALENDAR works with existing answers</h4>";
} ?>
\ No newline at end of file
<?php if($answer){
?>
<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> <a href='javascript:;' data-id='5e5e2470681c3376298b456b' data-collection='answers' data-path='answers.sommomForm1.sommomForm122.' class='addorganismesommomForm122 btn btn-default'><i class='fa fa-plus'></i> Ajouter un organisme </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 = [
"statut" => [
"Parc national" => "Parc national",
"Parc naturel régional" => "Parc naturel régional",
"Réserve naturelle," => "Réserve naturelle,",
"Aires de protection de biotope" => "Aires de protection de biotope",
"Site Natura 2000" => "Site Natura 2000",
"Parc naturel marin" => "Parc naturel marin",
"Autre" => "Autre"
]
];
$l = PHDB::findOne(Lists::COLLECTION, array('name' => 'cetaces'));
$cetacesArray = [];
$i=0;
foreach ($l['list'] as $in => $inp) {
if(isset($inp["nomVernaculaire"])){
$cetacesArray += [$inp["nomVernaculaire"] => $inp["nomVernaculaire"]];
} else {
$cetacesArray += [$inp["nomValide"] => $inp["nomValide"]];
}
$i++;
}
$a=[];
if(isset($answer["answers"]["sommomForm1"])){
foreach ($answer["answers"]["sommomForm1"] as $k => $v) {
if(is_array($v)){
foreach ($v as $key => $value) {
if(isset($value["intitule"])) {
$a += array($value["intitule"] => $value["intitule"]);
}
}
}
}
}
$properties = [
"intitule" => [
"label" => "Nom de l’aire marine protégée",
"placeholder" => "Intitulé",
"inputType" => "text",
"rules" => [ "required" => true ]
],
"type" => [
"label" => "Type",
"placeholder" => "Type",
"inputType" => "select",
"noOrder" => true,
"options" => $paramsData["statut"],
"rules" => [ "required" => true ]
],
"superficie" => [
"label" => "Superficie",
"placeholder" => "hectares",
"inputType" => "text",
"rules" => [ "required" => false ]
],
"localisation" => [
"label" => "Localisation",
"placeholder" => "Point GPS",
"inputType" => "formLocality",
"rules" => [ "required" => false ]
],
"location" => [
"inputType" => "location",
"rules" => [ "required" => false ]
],
"organisme" => [
"label" => "Organisme associé",
"placeholder" => "Sélectionner l’organisme de gestion",
"inputType" => "selectMultiple",
"options" => $a,
"rules" => [ "required" => true ]
],
"site" => [
"label" => "Site internet de référence pour consultation",
"placeholder" => "Site internet",
"inputType" => "text",
"rules" => [ "required" => false ]
]
];
$propertiesParams = [
"labels"=>[],
"placeholders"=>[],
];
foreach ($properties as $k => $v) {
if( isset($v["label"])){
if( isset($parentForm["params"][$kunik]["labels"][$k]) )
$properties[$k]["label"] = $parentForm["params"][$kunik]["labels"][$k];
$propertiesParams["labels"][$k] = $properties[$k]["label"];
}
if( isset($v["placeholder"])){
if(isset($parentForm["params"][$kunik]["placeholders"][$k]) )
$properties[$k]["placeholder"] = $parentForm["params"][$kunik]["placeholders"][$k];
$propertiesParams["placeholders"][$k] = $properties[$k]["placeholder"];
}
}
?>
<thead>
<tr>
<td colspan='<?php echo count( $properties)+2?>' ><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn.$editParamsBtn.$editBtnL?></h4>
<?php echo $info ?>
</td>
</tr>
<?php
if( count($answers)>0 ){ ?>
<tr>
</th>
<?php
foreach ($properties as $i => $inp) {
echo "<th>".$inp["label"]."</th>";
} ?>
<th></th>
</tr>
<tr></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) {
echo "<td>";
if(isset($a[$i])) {
if(is_array($a[$i])){
echo implode(",",$a["especeCible"]);
} else {
if($i == "site") {
echo "<a href='".$a[$i]."'>".$a[$i]."</a>";
}
else {
echo $a[$i];
}
}
}
echo "</td>";
}
?>
<td style="white-space: normal;">
<?php
$this->renderPartial( "survey.views.tpls.forms.cplx.editDeleteLineBtn" , [
"canEdit"=>($canEdit || $canAnswer),
"id" => $answer["_id"],
"collection" => Form::ANSWER_COLLECTION,
"q" => $q,
"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>
<?php
$ct++;
echo "</tr>";
}
}
?>
</tbody>
</table>
</div>
<script type="text/javascript">
var <?php echo $kunik ?>Data = <?php echo json_encode( (isset($answers)) ? $answers : null ); ?>;
sectionDyf.<?php echo $kunik ?>ParamsData = <?php echo json_encode( $paramsData ); ?>;
sectionDyf.<?php echo $kunik ?>ParamsProperty = {
labels : <?php echo json_encode( $propertiesParams["labels"] ); ?>,
placeholders : <?php echo json_encode( $propertiesParams["placeholders"] ); ?>
};
$(document).ready(function() {
sectionDyf.<?php echo $kunik ?> = {
"jsonSchema" : {
"title" : "Aire marine protégée",
"icon" : "fa-globe",
"text" : "",
"properties" : <?php echo json_encode( $properties ); ?>,
save : function () {
var today = new Date();