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

Merge branch 'development' of https://gitlab.adullact.net/pixelhumain/survey into development

parents ecb61a39 5b28888d
......@@ -10,6 +10,64 @@ var answerObject={
}
},"html");
},
mailConfig : {
inputs : {},
setContactList: function(obj){
str='<span class="col-xs-12 bold">Email</span> ' +
'<input type="text" id="contact-email" class="col-xs-12" value="" placeholder="Entrer un email"/>';
if(typeof obj.selectOptByGroup != "undefined"){
str='<span class="col-xs-12 bold no-padding">Sélectionner les contacts dans la liste suivante</span> ';
str+='<div class="col-xs-12 no-padding checkboxAnswerContact">';
$.each(obj.selectOptByGroup, function(e,v){
if(Object.keys(v).length > 0){
str+="<span class='col-xs-12 no-padding'><i class='fa fa-caret-down'></i> "+obj.selectContact[e]+" :</span>";
$.each(v, function(id, data){
img= (notEmpty(data.profilThumbImageUrl)) ? baseUrl + data.profilThumbImageUrl : modules.co2.url + "/images/thumb/default_"+data.collection+".png";
str+="<div class='population-elt-finder contact-id-"+id+" col-xs-12' data-value='"+id+"' data-collection='"+data.collection+"'>"+
'<div class="checkbox-content pull-left">'+
'<label>'+
'<input type="checkbox" class="check-population-finder checkbox-info" data-collection="'+data.collection+'" data-value="'+id+'">'+
'<span class="cr"><i class="cr-icon fa fa-check"></i></span>'+
'</label>'+
'</div>'+
"<div class='element-finder element-finder-"+id+"'>"+
'<img src="'+ img+'" class="thumb-send-to pull-left img-circle" height="40" width="40">'+
'<span class="info-contact pull-left margin-left-20">' +
'<span class="name-element text-dark text-bold" data-id="'+id+'">' + data.name + '</span>'+
'<br/>'+
'<span class="type-element text-light pull-left">' + trad[data.collection]+ '</span>'+
'</span>' +
"</div>"+
"</div>";
});
}
});
str+="</div>";
}
return str;
},
setObject:function(obj){
ansName=(typeof answerValues.mappingValues != "undefined" && typeof answerValues.mappingValues.name != "undefined") ? answerValues.mappingValues.name : "";
str='<input type="text" id="object-email" class="col-xs-12" value="Notification sur votre dossier "'+ansName+'">';
if(typeof obj.object != "undefined"){
if(typeof obj.object== "string")
str+='<input type="text" id="object-email" class="col-xs-12" value="'+obj.object+'"/>';
else if(typeof obj.object== "array"){
str+='<select id="object-email" path="links.operators" style="width:100%;" placeholder="Sélectionner un objet dans la liste">';
$.each(obj.object, function(e, v){
str+="<option value='"+v+"'>"+v+"</option>";
});
str+="</select>";
}
}
return str;
},
defaultMessage:function(obj){
if(typeof obj.message != "undefined") return obj.message;
else return "";
}
},
mailTo : {
subject: "Votre candidature a été validée",
validation : function(id, step){
......@@ -43,8 +101,8 @@ var answerObject={
return "La réponse demande d'être approfondi";
},
defaultRedirect : function(elt, id){
urlMail=(notNull(costum)) ?
return "<a href='"+baseUrl+"#answer.index.id."+id+"' target='_blank'>Retrouvez la page "+elt.name+" en cliquant sur ce lien</a>";
//urlMail=(notNull(costum)) ?
//return "<a href='"+baseUrl+"#answer.index.id."+id+"' target='_blank'>Retrouvez la page "+elt.name+" en cliquant sur ce lien</a>";
},
defaultMessage : function(elt, type, id){
var nameContact=(typeof elt.creator != "undefined" && elt.creator.name) ? elt.creator.name : "";
......
......@@ -16,6 +16,8 @@ class ApiController extends CommunecterController {
public function actions() {
return array(
'form' => 'survey.controllers.actions.form.GetAction',
'answers' => 'survey.controllers.actions.answer.GetAction',
);
}
......
......@@ -7,20 +7,21 @@ class NewAction extends CAction
$params = array();
if(!empty($id) && !empty($type)){
$params["forms"] = PHDB::find(Form::COLLECTION,
array("parent.".$id ),
array("name") ) ;
[ "parent.".$id => ['$exists'=>1] ],
[ "name" ] ) ;
} else if( !empty($this->getController()->costum) ){
$params["forms"] = PHDB::find(Form::COLLECTION,
array('$and' => array(
array("active" => true),
array("parent.".$this->getController()->costum["contextId"] => array('$exists' => 1))
// array('$or' => array(
// array("parent.".$this->getController()->costum["contextId"] => array('$exists' => 1) ),
// array("source.keys" => array('$in' => array($this->getController()->costum["slug"]) ) )
// ) )
)),
array("name") ) ;
[ '$and' => [
["active" => true],
["parent.".$this->getController()->costum["contextId"] => ['$exists' => 1]
// array('$or' => array(
// array("parent.".$this->getController()->costum["contextId"] => array('$exists' => 1) ),
// array("source.keys" => array('$in' => array($this->getController()->costum["slug"]) ) )
// ) )
]]], ["name"] ) ;
}
//var_dump($this->getController()->costum); exit;
$tpl= "survey.views.tpls.views.new";
echo $this->getController()->renderPartial($tpl,$params );
......
......@@ -5,14 +5,24 @@ class SendAction extends CAction {
public function run($id, $tpl="validation", $step=null) {
$controller=$this->getController();
$msg=null;
$infos=array();
if(isset($_POST["tpl"]))
$tpl=$_POST["tpl"];
if(isset($_POST["step"]))
$step=$_POST["step"];
// ALL infos
if(isset($_POST["tplObject"]))
$infos["tplObject"]=$_POST["tplObject"];
if(isset($_POST["html"]))
$infos["html"]=$_POST["html"];
if(isset($_POST["msg"]))
$msg=$_POST["msg"];
$infos["msg"]=$_POST["msg"];
if(isset($_POST["tplMail"]))
$infos["emails"]=$_POST["tplMail"];
if(isset($_POST["listContact"]))
$infos["community"]=$_POST["listContact"];
$mailParams=Answer::mailProcess($id, $tpl, $step, $msg);
$mailParams=Answer::mailProcess($id, $tpl, $step, $infos);
Rest::json(array("result"=>true, "msg"=>"Ok : webhook handdled"));
}
}
\ No newline at end of file
......@@ -179,6 +179,18 @@
"placeholder" : "",
"info" : "",
"type" : "tpls.forms.costum.deal.stepOperateur"
},
"deal14" : {
"label" : "Contacter les auteurs de ce dossier",
"buttonLabel" : "Envoyer un email",
"accessRoles" : [
"financeur"
],
"selectContact" : {
"answered" : "Demandeur(s)",
"operators" : "Opérateur(s)"
},
"type" : "tpls.forms.cplx.mailContact"
}
}
}
......
......@@ -302,24 +302,53 @@ class Answer{
public static function mailProcess($id, $tpl, $step, $infos){
$costum = CacheHelper::getCostum();
$answer=self::getById($id);
$mailsCommunity=self::getCommunityToNotify($answer);
$mailsCommunity=array();
if(isset($infos["emails"]) && !empty($infos["emails"])){
foreach($infos["emails"] as $v){
array_push($mailsCommunity, Element::getElementByWhere(Person::COLLECTION, array("email"=>$v),array("email","name","slug") ) );
}
}
if(isset($infos["community"]) && !empty($infos["community"])){
$mailsCommunity=array();
foreach($infos["community"] as $k => $v){
if($v["type"]==Person::COLLECTION){
array_push($mailsCommunity, Element::getElementById($k, Person::COLLECTION, null, array("email","name","slug") ));
}else{
$community=Element::getCommunityByTypeAndId(Organization::COLLECTION, $k,Person::COLLECTION, "isAdmin");
foreach($community as $e => $val){
array_push($mailsCommunity, Element::getElementById($e, Person::COLLECTION, null, array("email","name","slug") ));
}
}
}
}
if(empty($mailsCommunity))
$mailsCommunity=self::getCommunityToNotify($answer);
$answer["mappingValues"]=array();
$form=Form::getByIdMongo($answer["form"]);
if(isset($form["mapping"]))
$answer["mappingValues"]=self::getMappingValues($form["mapping"], $answer);
$nameAnsw=(isset($answer["mappingValues"]["name"])) ? $answer["mappingValues"]["name"] : "";
$objMail="[".Mail::getAppName()."] ".Yii::t("mail",self::$mailConfig[$tpl]["subject"], array("{what}"=>$nameAnsw));
if(isset($infos["tplObject"]))
$objMail="[".Mail::getAppName()."] ".$infos["tplObject"];
foreach($mailsCommunity as $c){
$params = array (
"type" => Cron::TYPE_MAIL,
"tpl"=>self::$mailConfig[$tpl]["tpl"],
"subject" => "[".Mail::getAppName()."] ".Yii::t("mail",self::$mailConfig[$tpl]["subject"], array("{what}"=>$nameAnsw)),
"subject" => $objMail,
"from"=>Yii::app()->params['adminEmail'],
"to" => $c["email"],
"tplParams" => array( "user"=> $c ,
"title" => Mail::getAppName() ,
"answer" => $answer,
"form"=>$form,
"msg"=>@$infos));
"msg"=>@$infos));
if(isset($infos["msg"]))
$params["tplParams"]["msg"]=$infos["msg"];
if(isset($infos["html"]))
$params["tplParams"]["html"]=$infos["html"];
$params=Mail::getCustomMail($params);
Mail::schedule($params);
}
......
......@@ -642,7 +642,7 @@ class Form {
$res = array("render"=>"co2.views.default.unTpl", "msg"=>Yii::t("project", "Source Copy doesn't exist."),"icon"=>"fa-lock");
return $res;
}
public static function canFormAccess($rules, $formParents=null){
public static function canAccess($rules, $formParents=null){
//WARNING la c'est ce qui est lier à l'user du costum connecté
if(Authorisation::isInterfaceAdmin())
return true;
......@@ -690,7 +690,7 @@ class Form {
if(isset($form["rules"])){
foreach ($form["subForms"] as $k => $value) {
if(isset($form["rules"][$value])){
if(!self::canFormAccess($form["rules"][$value], $form["parent"])){
if(!self::canAccess($form["rules"][$value], $form["parent"])){
array_splice($params["parentForm"]["subForms"], $k, -1);
}
}
......
......@@ -9,6 +9,10 @@ $cssJS = array(
'/plugins/to-markdown/to-markdown.js'
);
HtmlHelper::registerCssAndScriptsFiles($cssJS, Yii::app()->request->baseUrl);
HtmlHelper::registerCssAndScriptsFiles(array(
'/js/answer.js',
), Yii::app()->getModule( Survey::MODULE )->getAssetsUrl() );
$poiList = array();
if(isset($this->costum["contextType"]) && isset($this->costum["contextId"])){
......
......@@ -3,7 +3,7 @@
// role is financer or operater
if( $mode != "pdf" ){
if(Form::canFormAccess(['roles'=>["Financeur","Opérateur"] ])){
if(Form::canAccess(['roles'=>["Financeur","Opérateur"] ])){
$isFinanceur=false;
if(Authorisation::isInterfaceAdmin())
$isFinanceur=true;
......@@ -222,8 +222,11 @@ if( $mode != "pdf" ){
}
};
$(this).fadeOut();
mylog.log("save step save",ctxTpl);
validateForStep3();
dataHelper.path2Value( ctxTpl, function(params) {
mylog.log("save step save",ctxTpl);
validateForStep3();
});
});
......@@ -306,8 +309,7 @@ if( $mode != "pdf" ){
});
function validateForStep3(){
dataHelper.path2Value( ctxTpl, function(params) {
ctxTpl = {
ctxTpl = {
id : "<?php echo (string)$answer['_id'] ?>",
collection : "answers",
path : "step",
......@@ -327,7 +329,7 @@ if( $mode != "pdf" ){
}
);
} );
} );
// } );
}
</script>
......
......@@ -342,4 +342,4 @@ function closePrioModalRel (){
}
?>
\ No newline at end of file
?>
......@@ -65,6 +65,8 @@ if( $mode != "pdf" && ( $canAdminAnswer === true || $canEdit === true ) )
}
}
}
} else if($i == "group" && isset($paramsData["group"][$a[$i]])){
$tds .= $paramsData["group"][$a[$i]];
}
else if(isset($a[$i]))
$tds .= $a[$i];
......
......@@ -30,7 +30,6 @@ $editBtnL = "";
$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>" : "";
$paramsData = [
"financerTypeList" => Ctenat::$financerTypeList,
"limitRoles" =>["Financeur"],
......
<?php $inputsObj=$form["inputs"][$key];
if(!isset($inputsObj["canAccess"]) || Form::canAccess($inputsObj["canAccess"])){ ?>
<div class="contactFormEmail col-xs-12 no-padding margin-bottom-20">
<br/><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo @$inputsObj["label"] ?></h4>
<?php if(isset($inputsObj["info"])){ ?>
<span class="italic">
<?php echo $inputsObj["info"] ?>
</span>
<?php } ?>
<button class="btn btn-success contactMail" data-key="<?php echo $key ?>">
<?php echo $inputsObj["buttonLabel"] ?>
</button>
</div>
<!-- check on select answer + add default obj + add default content-->
<?php if(isset($inputsObj["formAdmin"])){ ?>
<?php }else if (isset($inputsObj["selectContact"])){
$inputsObj["selectOptByGroup"]=array();
foreach($inputsObj["selectContact"] as $k => $v){
$inputsObj["selectOptByGroup"][$k]=array();
if(isset($answer["links"][$k])){
$typeElt=($k=="answered") ? Person::COLLECTION : Organization::COLLECTION;
foreach($answer["links"][$k] as $e => $st){
$idCol=($k=="answered") ? $st : $e;
$elt=Element::getElementById($idCol, $typeElt, null, array("name","slug", "profilThumbImageUrl"));
$elt["collection"]=$typeElt;
$inputsObj["selectOptByGroup"][$k][$idCol]=$elt;
}
}
}
//$inputsObj["selectOptByGroup"]=$selectOptByGroup;
} ?>
<script type="text/javascript">
//if(typeof answerMailConfig =="undefined") var answerMailConfig={};
//var answerObject.mailConfig.inputs[<?php echo $key ?>]=new Object;
answerObject.mailConfig.inputs["<?php echo $key; ?>"]=<?php echo json_encode($inputsObj); ?>;
var answerValues=<?php echo json_encode($answer); ?>;
jQuery(document).ready(function() {
$(".contactMail").off().on("click", function(){
inputsMailConfig=answerObject.mailConfig.inputs[$(this).data("key")];
bootbox.dialog({
onEscape: function() {},
message: '<div id="send-mail-answer" class="row"> ' +
'<div class="col-xs-12"> ' +
answerObject.mailConfig.setContactList(inputsMailConfig)+
//'<input type="text" id="contact-email" class="col-xs-12" value="'+aObj.mailTo.initMail(elt)+'"/>'+
'</div>'+
'<div class="col-xs-12"> ' +
'<span class="col-xs-12 bold no-padding">Object</span> ' +
answerObject.mailConfig.setObject(inputsMailConfig)+
'</div>'+
'<div class="col-xs-12"> ' +
'<span class="col-xs-12 bold no-padding">Message</span> ' +
'<textarea id="message-email" class="col-xs-12 text-dark" style="min-height:250px;" placeholder="Ecrivez votre message">'+answerObject.mailConfig.defaultMessage(inputsMailConfig)+'</textarea>'+
'</div>'+
'</div>',
buttons: {
success: {
label: "Ok",
className: "btn-primary",
callback: function () {
errorMsg={
msg : "Veuillez écrire un message",
object : "Veuillez renseigner un objet",
contact : "Veuillez saisir un destinataire"
}
var msg="";
if(notEmpty($("#send-mail-answer #message-email").val()))
msg="<span style='white-space: pre-line;'>"+$("#send-mail-answer #message-email").val()+"<br/></span>";
//var email
else {
toastr.error(errorMsg.msg);return false;
}
if(!notEmpty($("#send-mail-answer #object-email").val())){
toastr.error(errorMsg.object);return false;
}
var params={
tpl : "default",
tplObject : $("#send-mail-answer #object-email").val(),
html: msg
};
if($("#send-mail-answer #contact-email").length > 0)
params.tplMail=$("#send-mail-answer #contact-email").val();
if($("#send-mail-answer .checkboxAnswerContact").length > 0){
listContact={};
$("#send-mail-answer .checkboxAnswerContact input[type='checkbox']:checked").each(function(){
listContact[$(this).data("value")] = { type : $(this).data("collection")};
});
params.listContact=listContact;
}
if((typeof params.listContact != "undefined" && Object.keys(params.listContact).length > 0) || (typeof params.tplMail != "undefined" && notEmpty(params.tplMail))){
ajaxPost(
null,
baseUrl+"/survey/answer/sendmail/tpl/default/id/"+answerObj._id.$id,
params,
function(data){
toastr.success("Le mail a été envoyé avec succès");
}
);
}else{ toastr.error(errorMsg.contact);return false; }
//aObj.mailTo.sendMail(aObj, elt, type, id);
}
},
cancel: {
label: trad["cancel"],
className: "btn-secondary",
callback: function() {}
}
}
});
});
});
</script>
<?php } ?>
\ No newline at end of file
<?php
if( $mode != "pdf" ){
//if( Form::canFormAccess( ['roles'=>["Financeur"] ], @$parentForm["parent"]) ){
//if( Form::canAccess( ['roles'=>["Financeur"] ], @$parentForm["parent"]) ){
if( !empty($canAdminAnswer) && $canAdminAnswer === true ){
if( isset($form['id']) )
{
$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 = [
"limitRoles" =>["Financeur"]
"canValidRoles" =>["Financeur"],
"canRequestRoles" =>["Opérateur"],
];
if( isset($parentForm["params"][$kunik]) ) {
if( isset($parentForm["params"][$kunik]["limitRoles"]) )
$paramsData["financersList"] = $parentForm["params"][$kunik]["limitRoles"];
if( isset($parentForm["params"][$kunik]["canValidRoles"]) )
$paramsData["canValidRoles"] = $parentForm["params"][$kunik]["canValidRoles"];
if( isset($parentForm["params"][$kunik]["canRequestRoles"]) )
$paramsData["canRequestRoles"] = $parentForm["params"][$kunik]["canRequestRoles"];
}
?>
......@@ -27,7 +30,7 @@ if( $mode != "pdf" ){
</td>
</tr>
<?php
if( isset( $answer["validation"][ $form['id'] ] ) ){ ?>
if( isset( $answer["validation"][ $form['id'] ]["valid"] ) && in_array($answer["validation"][$form['id']]["valid"], ["valid","validReserve"] ) ){ ?>
<tr>
<td colspan='2' align="center">
<button id="generateCopil2" class="generateCopil btn btn-primary" data-id="<?php echo (string)$answer["_id"] ?>" data-date="<?php echo date("Y-m-d") ?>" data-title="Compte Rendu de la réunion de finalisation" data-key="copilReunionFinalisation">Générer le dossier validé</button>
......@@ -49,6 +52,9 @@ if( $mode != "pdf" ){
} else if( $answer["validation"][$form['id']]["valid"] == "validReserve" ){
$color = "warning";
$lbl = "Validé avec réserves";
}else if( $answer["validation"][$form['id']]["valid"] == "request" ){
$color = "default";
$lbl = "Demande de Validation";
}
}
......@@ -81,12 +87,35 @@ if( $mode != "pdf" ){
} ?>
<?php
} ?>
<tr>
<td colspan='2' class="text-center" >
<a href="javascript:;" data-type="<?php echo $form['id'] ?>" class="validEdit btn btn-primary">Valider cette action</a>
</td>
</tr>
}
?>
<tr>
<td colspan='2' class="text-center" >
<?php
// var_dump(Yii::app()->session["costum"][$el['costum']['slug']]["hasRoles"][0]);
// var_dump($paramsData['canValidRoles']);
if( (!isset($answer["validation"][$form['id']]) || (isset( $answer["validation"][ $form['id'] ]["valid"] ) && $answer["validation"][ $form['id'] ]["valid"] == "notValid")) &&
isset( Yii::app()->session["costum"][$el['costum']['slug']]["hasRoles"][0]) &&
in_array(Yii::app()->session["costum"][$el['costum']['slug']]["hasRoles"][0], $paramsData['canRequestRoles']) )
echo '<a href="javascript:;" data-type="'.$form['id'].'" class="requestValid btn btn-primary">Étape terminé , Demander la Validation</a>';
else if( isset( $answer["validation"][ $form['id'] ]["valid"] ) &&
$answer["validation"][ $form['id'] ]["valid"] == "request" &&
isset( Yii::app()->session["costum"][$el['costum']['slug']]["hasRoles"][0] ) &&
in_array(Yii::app()->session["costum"][$el['costum']['slug']]["hasRoles"][0], $paramsData['canValidRoles']) )
echo '<a href="javascript:;" data-type="'.$form['id'].'" class="validEdit btn btn-primary">Valider cette Étape</a>';
else {
if(isset( $answer["validation"][ $form['id'] ] ) &&
$answer["validation"][ $form['id'] ]["valid"] == "request")
echo "Étape en cours de validation ";
else
echo "Étape en cours de traitement";
}
?>
</td>
</tr>
</tbody>
</table>
......@@ -111,10 +140,28 @@ if( $mode != "pdf" ){
"title" : "<?php echo $kunik ?> config",
"icon" : "fa-cog",
"properties" : {
limitRoles : {
useValidationRoles : {
inputType : "checkboxSimple",
label : "Utiliser des Role de validation",
subLabel : "Permet de définir des demandes et de validations",
params : {
onText : "Oui",
offText : "Non",
onLabel : "Oui",
offLabel : "Non",
labelText : "Obligatoire"
},
checked : false
},
canValidRoles : {
inputType : "array",
label : "Liste des roles qui pourront valider cette étape",
values : sectionDyf.<?php echo $kunik ?>ParamsData.canValidRoles
},
canRequestRoles : {
inputType : "array",
label : "Liste des roles qui pourront valider cette étape",
values : sectionDyf.<?php echo $kunik ?>ParamsData.limitRoles
values : sectionDyf.<?php echo $kunik ?>ParamsData.canRequestRoles
}
},
save : function () {
......@@ -204,6 +251,15 @@ if( $mode != "pdf" ){
};
mylog.log("save step save",ctxTpl);
dataHelper.path2Value( ctxTpl, function(params) {
ajaxPost(
null,
baseUrl+"/survey/answer/sendmail/id/<?php echo (string)$answer['_id'] ?>",
{ step : step },
function(data){
toastr.success("Un mail a été envoyé à toutes les parties prenantes afin de les notifier");
urlCtrl.loadByHash(location.hash);
}
);
urlCtrl.loadByHash(location.hash);
} );
} else
......@@ -217,7 +273,15 @@ if( $mode != "pdf" ){
inputType : "custom",
html:"<p></p>",
},
valid : {
valid : dyFInputs.inputHidden(),
description : dyFInputs.textarea( tradDynForm["description"], "..." ),
form : dyFInputs.inputHidden()
}
}
};
$('.validEdit').off().on("click", function() {