Commit fff33c76 authored by Raph El's avatar Raph El
Browse files

Form : amélioration validation form

parent 6b9474f3
...@@ -40,7 +40,10 @@ class IndexAction extends CAction ...@@ -40,7 +40,10 @@ class IndexAction extends CAction
$canEditAnswer = false; $canEditAnswer = false;
$canSeeAnswer = false; $canSeeAnswer = false;
if(empty($mode) || ( $mode != "w" && $mode != "r" ) )
if( empty($mode) || ( $mode != "w" && $mode != "r" ) ||
( !empty($answer["validated"]) && $answer["validated"] == true) )
$mode = "r"; $mode = "r";
if(!empty(Yii::app()->session['userId'])){ if(!empty(Yii::app()->session['userId'])){
......
<?php <?php
class ValidateAction extends CAction class ValidateAction extends CAction
{ {
public function run($id=null, $type=null , $tpl=null) public function run()
{ {
//$controller = $this->getController();
$params = $_POST;
$res = Answer::validate($_POST); $params["controller"] = $this->getController();
Rest::json($_POST); $res = Answer::validate($params);
Rest::json($res);
} }
} }
"organizations" : [
{
"from" : "aressForm1.multitextvalidationaressForm110",
"to" : "name"
},
{
"from" : "aressForm1.multitextvalidationaressForm111",
"to" : "sigle"
},
{
"from" : "aressForm1.multitextvalidationaressForm112",
"to" : "siren"
},
{
"from" : "aressForm1.multitextvalidationaressForm19",
"to" : "email"
},
{
"from" : "aressForm1.multitextvalidationaressForm113",
"to" : "WALDEC_RNA
"
},
{
"from" : "aressForm1.multitextvalidationaressForm113",
"to" : "siren"
}
]
\ No newline at end of file
...@@ -368,8 +368,12 @@ class Answer{ ...@@ -368,8 +368,12 @@ class Answer{
public static function validate($params){ public static function validate($params){
$costum = CacheHelper::getCostum(); $costum = CacheHelper::getCostum();
$set = array(); $set = array();
$res = array('result' => false, "msg" => "Erreur");
if(!empty($params["answerId"]))
$answer = PHDB::findOneById(Answer::COLLECTION, $params["answerId"]);
if(!empty($params["validated"]) && $params["validated"] === true) if(!empty($answer)){
if(!empty($params["input"]["validated"]) && ( $params["input"]["validated"] === true || $params["input"]["validated"] === "true" ) )
$set["validated"] = true; $set["validated"] = true;
if(!empty($params["input"]["generateElement"])){ if(!empty($params["input"]["generateElement"])){
...@@ -391,8 +395,26 @@ class Answer{ ...@@ -391,8 +395,26 @@ class Answer{
} }
$import['infoCreateData'] = $mapping; $import['infoCreateData'] = $mapping;
$import['typeElement'] = $type; $import['typeElement'] = $type;
//Rest::json($import); exit;
$resImport = Import::previewData($import, true, true, true); $resImport = Import::previewData($import, true, true, true);
Rest::json($resImport); exit; //Rest::json($resImport); exit;
foreach ($resImport["elementsObj"] as $keyElt => $elt) {
$elt = Import::checkElement($elt, $type);
if(!empty($elt["msgError"]))
unset($elt["msgError"]);
$elt["collection"] = $type;
$elt["key"] = $type;
if(Costum::isSameFunction("generateElementBeforeSave")){
$elt = Costum::sameFunction("generateElementBeforeSave", $elt);
}
$save = Element::save($elt);
//Rest::json($save); exit;
Link::connect($save["id"], $type, $params["answerId"], Answer::COLLECTION, Yii::app()->session["userId"], "answers",false,false,false,false);
Link::connect($params["answerId"], Answer::COLLECTION, $save["id"], $type, Yii::app()->session["userId"], $type,false,false,false,false);
}
$res = array('result' => true, "msg" => "Valider");
//Rest::json($resImport); exit;
} }
} }
...@@ -409,6 +431,12 @@ class Answer{ ...@@ -409,6 +431,12 @@ class Answer{
$res = array('result' => true, "msg" => "Valider"); $res = array('result' => true, "msg" => "Valider");
} }
if($res["result"] === true){
$res["html"] = $params["controller"]->renderPartial('survey.views.tpls.forms.finish', $res, true);
}
}
return $res; return $res;
} }
......
<?php <?php
if($mode != "pdf"){ if($mode != "pdf"){
var_dump($input); //var_dump($input);
?> ?>
<div class=""> <div class="">
<label for="validation<?php echo $kunik ?>"><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn ?></h4></label> <label for="validation<?php echo $kunik ?>"><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn ?></h4></label>
...@@ -17,7 +17,6 @@ if($mode != "pdf"){ ...@@ -17,7 +17,6 @@ if($mode != "pdf"){
$("#question<?php echo $key ?> #validation<?php echo $kunik ?>").off().click(function(){ $("#question<?php echo $key ?> #validation<?php echo $kunik ?>").off().click(function(){
var paramsValidate = { var paramsValidate = {
answerId : answerId, answerId : answerId,
answer : answerObj.answers,
input : paramsInput input : paramsInput
}; };
...@@ -27,6 +26,8 @@ if($mode != "pdf"){ ...@@ -27,6 +26,8 @@ if($mode != "pdf"){
paramsValidate, paramsValidate,
function(data){ function(data){
toastr.success("Le formulaire à été soumis"); toastr.success("Le formulaire à été soumis");
if(typeof data.html != "undefined")
$("#customHeader").html(data.html);
}, },
function(data){ function(data){
toastr.error("Un soucis est apparue. Contacter l'administrateur"); toastr.error("Un soucis est apparue. Contacter l'administrateur");
......
<div class="col-xs-12 text-center padding-20 margin-top-10">
<h4>Félicitation!!! Vous avez terminé le formulaire.</h4>
<br/>
<h4>Celui-ci sera traité dans les plus bref délai.</h4>
</div>
\ No newline at end of file
...@@ -145,7 +145,7 @@ if(isset($this->costum["cms"]["color1"])) ...@@ -145,7 +145,7 @@ if(isset($this->costum["cms"]["color1"]))
<div class="col-xs-12 margin-top-20"> <div class="col-xs-12 margin-top-20">
<?php <?php
$wizardUid = (String) $form["_id"]; $wizardUid = (String) $form["_id"];
if($canEdit === true && $mode != "fa"){ if($canEdit === true && $mode != "fa" && empty($answer["validated"]) ){
$nameMode = "mode read"; $nameMode = "mode read";
if($mode == "w") if($mode == "w")
$nameMode = "mode write"; $nameMode = "mode write";
......
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