Commit e1ecdbc2 authored by Tibor Katelbach's avatar Tibor Katelbach
Browse files

Merge remote-tracking branch 'origin/development' into development

parents 6088d7ee 4a98a6fe
......@@ -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 : "";
......
......@@ -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
//parent form
{
"parent" : {
"5eaa96df539f2224608b456a" : {
"type" : "organizations",
"name": "DEAL A H "
}
}
"parent" : Ne pas oublié de rattacher le parent,
"hasStepValidations" : 1,
"id" : "dealForm",
"source" : {
......@@ -184,6 +179,18 @@
"placeholder" : "",
"info" : "",
"type" : "tpls.forms.costum.deal.stepOperateur"
},
"deal14" : {
"label" : "Contacter les auteurs de ce dossier",
"buttonLabel" : "Envoyer un email",
"canAccess" : [
"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);
}
......
......@@ -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"])){
......
<?php
if($mode != "pdf" && ( !isset($inputsObj["canAccess"]) || Form::canAccess($inputsObj["canAccess"]) ) ) {
$inputsObj=$form["inputs"][$key];
?>
<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"])){
}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
......@@ -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"])){
......
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