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

sommom

parent 36310bfa
<?php if($answer){
?>
<div class="form-group">
<table class="table table-bordered table-hover directoryTable" id="<?php echo $kunik?>">
<?php
$editBtnL = (!isset($answers)) ? " <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='".$el["_id"]."' data-collection='".Yii::app()->session["costum"]["contextType"]."' data-path='costum.form.params.".$kunik."' class='previewTpl edit".$kunik."Params btn btn-xs btn-danger'><i class='fa fa-cog'></i> </a>" : "";
$paramsData = [];
$properties = [
"pointGPS" => [
"label" => "Point GPS",
"placeholder" => "Point GPS",
"inputType" => "formLocality",
"rules" => [ "required" => true ]
],
"location" => [
"inputType" => "location",
"rules" => [ "required" => true ]
],
];
$propertiesParams = [
"labels"=>[],
"placeholders"=>[],
];
foreach ($properties as $k => $v) {
if( isset($v["label"])){
if( isset(Yii::app()->session["costum"]["form"]["params"][$kunik]["labels"][$k]) )
$properties[$k]["label"] = Yii::app()->session["costum"]["form"]["params"][$kunik]["labels"][$k];
$propertiesParams["labels"][$k] = $properties[$k]["label"];
}
if( isset($v["placeholder"])){
if(isset(Yii::app()->session["costum"]["form"]["params"][$kunik]["placeholders"][$k]) )
$properties[$k]["placeholder"] = Yii::app()->session["costum"]["form"]["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["label"])){
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) {
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[$i]);
}
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" => "answers.".$kunik.".".$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
}
},
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>" : "";
$editParamsBtn = ($canEdit) ? " <a href='javascript:;' data-id='".$el["_id"]."' data-collection='".Yii::app()->session["costum"]["contextType"]."' data-path='costum.form.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 = [
"role" => [
"Organisme impliqué dans le suivi, l’encadrement de l’activité d’observation" => "Organisme impliqué dans le suivi, l’encadrement de l’activité d’observation",
"Organisme impliqué dans la pratique de l’activité d’observation : Opérateur en mer, opérateur aérien" => "Organisme impliqué dans la pratique de l’activité d’observation : Opérateur en mer, opérateur aérien",
"Organisme impliqué dans la science et la recherche sur l’activité d’observation" => "Organisme impliqué dans la science et la recherche sur l’activité d’observation",
"Organisme impliqué dans l’éducation et la sensibilisation sur l’activité d’observation" => "Organisme impliqué dans l’éducation et la sensibilisation sur l’activité d’observation"
],
"statut" => [
"Service représentant de l’Etat" => "Service représentant de l’Etat",
"Collectivité" => "Collectivité",
"Syndicat, fédération, représentant d’acteurs de la mer" => "Syndicat, fédération, représentant d’acteurs de la mer",
"Structure privée commerciale" => "Structure privée commerciale",
"Association de sport et loisir" => "Association de sport et loisir",
"Association environnementale" => "Association environnementale",
"Institut de recherche" => "Institut de recherche",
"Autre" => "Autre"
]
];
if( isset(Yii::app()->session["costum"]["form"]["params"][$kunik]["statut"]) )
$paramsData["statut"] = Yii::app()->session["costum"]["form"]["params"][$kunik]["statut"];
$properties = [
"intitule" => [
"label" => "Nom de l’organisme",
"placeholder" => "Intitulé",
"inputType" => "text",
"rules" => [ "required" => true ]
],
"role" => [
"label" => "Rôles",
"placeholder" => "Choisir parmis les rôles de la liste",
"inputType" => "selectMultiple",
"noOrder" => true,
"options" => $paramsData["role"],
"rules" => [ "required" => true ]
],
"statut" => [
"label" => "Statut",
"placeholder" => "Statut",
"inputType" => "select",
"noOrder" => true,
"options" => $paramsData["statut"],
"rules" => [ "required" => true ]
],
"pointGPS" => [
"label" => "Point GPS",
"placeholder" => "Point GPS",
"inputType" => "formLocality",
"rules" => [ "required" => true ]
],
"location" => [
"inputType" => "location",
"rules" => [ "required" => true ]
],
];
$propertiesParams = [
"labels"=>[],
"placeholders"=>[],
];
foreach ($properties as $k => $v) {
if( isset($v["label"])){
if( isset(Yii::app()->session["costum"]["form"]["params"][$kunik]["labels"][$k]) )
$properties[$k]["label"] = Yii::app()->session["costum"]["form"]["params"][$kunik]["labels"][$k];
$propertiesParams["labels"][$k] = $properties[$k]["label"];
}
if( isset($v["placeholder"])){
if(isset(Yii::app()->session["costum"]["form"]["params"][$kunik]["placeholders"][$k]) )
$properties[$k]["placeholder"] = Yii::app()->session["costum"]["form"]["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["label"])){
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) {
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[$i]);
}
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" => "answers.".$kunik.".".$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
},
statut : {
inputType : "array",
label : "Liste des roles",
value : sectionDyf.<?php echo $kunik ?>ParamsData.role
},
},
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"));