Commit 9f944568 authored by Raph El's avatar Raph El

Form : update for co

parent 553ea577
......@@ -55,10 +55,11 @@ var formObj = {
},"html");
},
answer : function(fObj, id, form){
mylog.log("fObj.urls.answer", fObj, id, form);
var url = '/survey/answer/index/id/'+id;
if(typeof form != "undefined" && form != null)
url += '/form/'+form;
ajaxPost(fObj.container, baseUrl+'/survey/answer/index/id/'+id,
ajaxPost(fObj.container, baseUrl+url,
null,
function(){
history.replaceState(location.hash, "", hashUrlPage+".view.forms.answer."+id);
......@@ -196,26 +197,30 @@ formObj.views.form = function(id, form){
else
str += '<span class="label label-danger">Pas activé</span>';
str += "<br/>";
if(typeof form.active != "undefined" && form.active === true){
str += '<a href="javascript:;" data-id="'+id+'" class=" apply btn btn-xs btn-primary col-sm-12 bold">'+
'<i class="fa fa-file-text-o"></i> Apply '+
str += '<div class="col-xs-12">';
str += '<a href="javascript:;" data-id="'+id+'" class="myAnswers btn btn-xs btn-primary col-sm-12 bold">'+
'<i class="fa fa-pencil"></i> My answers '+
'</a>';
if(typeof form.active != "undefined" && form.active === true){
str += '<a href="javascript:;" data-id="'+id+'" class=" application btn btn-xs btn-primary col-sm-12 bold">'+
'<i class="fa fa-file-text-o"></i> Application Form '+
'</a>';
if(typeof form.canEditForm != "undefined" && form.canEditForm === true){
str += '<a href="#form.edit.id.'+id+'" class="btn btn-xs btn-primary col-sm-12 bold">'+
'<i class="fa fa-pencil"></i> Answers '+
'</a>';
}
} else {
if(typeof form.canEditForm != "undefined" && form.canEditForm === true){
str += '<a href="javascript:;" data-id="'+id+'" class="btn btn-xs btn-primary config col-sm-12 bold">'+
'<i class="fa fa-pencil"></i> CONSTRUIRE '+
'</a>';
if(typeof form.canEditForm != "undefined" && form.canEditForm === true){
str += '<a href="javascript:;" data-id="'+id+'" class="allAnswers btn btn-xs btn-primary col-sm-12 bold">'+
'<i class="fa fa-pencil"></i> All Answers '+
'</a>';
}
} else {
if(typeof form.canEditForm != "undefined" && form.canEditForm === true){
str += '<a href="javascript:;" data-id="'+id+'" class="btn btn-xs btn-primary config col-sm-12 bold">'+
'<i class="fa fa-pencil"></i> Build '+
'</a>';
}
}
}
str += '</div>'+
str += '</div>'+
'</div>'+
'</div>'+
'</div>';
return str ;
......@@ -230,15 +235,37 @@ formObj.events.add = function(fObj){
};
formObj.events.form = function(fObj){
$(fObj.container+' .apply').off().on("click",function(){
$(fObj.container+' .application').off().on("click",function(){
fObj.urls.answer(fObj, "new", $(this).data("id"));
// ajaxPost(fObj.container, baseUrl+'/survey/answer/index/id/new/form/'+$(this).data("id"),
// null,
});
$(fObj.container+' .allAnswers').off().on("click",function(){
getAjax(fObj.container,
baseUrl+"/survey/answer/get/form/"+$(this).data("id"),function(){
},"html");
});
$(fObj.container+' .myAnswers').off().on("click",function(){
// ajaxPost(fObj.results.dom, baseUrl+"/survey/answer/views/",
// data,
// function(){
// },"html");
// fObj.results.events(fObj);
// });
// var data{
// allAnswers=results
// }
// if(Object.keys(results).length > 0){
// ajaxPost(fObj.results.dom, baseUrl+"/survey/answer/views/",
// data,
// function(){
// fObj.results.events(fObj);
// });
// }
});
$(fObj.container+' .config').off().on("click",function(){
var idForm = $(this).data("id");
fObj.urls.form(fObj, idForm);
......
......@@ -3,30 +3,20 @@ class GetAction extends CTKAction
{
//if $slug : getd all the forms for an element.slug
//if $id : opens the forms
public function run($form)
public function run($form = null, $userId = null)
{
$controller=$this->getController();
$controller->layout = "//layouts/empty";
$tpl=(!empty($params["parentForm"]["answersTpl"])) ? $params["parentForm"]["answersTpl"] : 'survey.views.tpls.forms.cplx.answers';
$controller->layout = "//layouts/empty";
$params = [];
$params["form"] = PHDB::findOne( Form::COLLECTION, [ "_id"=>new MongoId($form) ] );
//var_dump($params["form"]);exit;
$params["forms"] = [];
foreach ($params["formList"] as $ix => $formId) {
foreach ($params["form"]["subForms"] as $ix => $formId) {
$f = PHDB::findOne(Form::COLLECTION, ["id"=>$formId]);
$params["forms"][$formId] = $f;
}
$params["what"] = (isset($params["form"]["what"])) ? $params["form"]["what"] : "réponses";
$el = Slug::getElementBySlug( $params["form"]["parentSlug"] );
$params['el'] = $el["el"];
//ce code ne marchera pas pour deux formulaire identaique , d'un meme slug
//TODO utiliser le parntForm Id en plus
// $params["allAnswers"] = PHDB::find( Form::ANSWER_COLLECTION, ["formId"=>implode('|', $params["form"]["subForms"]) , "parentSlug" => $params["form"]["parentSlug"]] );
$params['el'] = Form::getFirstParentForm($params["form"]);
$params["allAnswers"] = PHDB::find( Answer::COLLECTION, ["form"=> $form] );
$params['canEdit'] = ( isset(Yii::app()->session["userId"]) && isset($el["type"]) && isset($el["id"]) ) ?
Authorisation::canEditItem(Yii::app()->session["userId"],$el["type"], $el["id"])
......@@ -34,6 +24,9 @@ class GetAction extends CTKAction
$params["wizid"] = $form;
$tpl=(!empty($params["form"]["answersTpl"])) ? $params["form"]["answersTpl"] : 'survey.views.tpls.forms.cplx.answers';
if(Yii::app()->request->isAjaxRequest)
echo $controller->renderPartial( $tpl , $params, true);
else
......
......@@ -51,7 +51,14 @@ if( isset($parentForm["params"][$kunik]) ) {
$paramsData["amounts"] = $parentForm["params"][$kunik]["amounts"];
}
$communityLinks = Element::getCommunityByTypeAndId($this->costum["contextType"],$this->costum["contextId"]);
$communityLinks = array();
if(!empty($form["parent"])){
foreach ($form["parent"] as $key => $value) {
$cl= Element::getCommunityByTypeAndId($key,$value["type"]);
if(!empty($cl))
$communityLinks = array_merge($communityLinks, $cl);
}
}
$organizations = Link::groupFindByType( Organization::COLLECTION,$communityLinks,["name","links"] );
$orgs = [];
......@@ -288,9 +295,9 @@ if( isset($parentForm["params"]["financement"]["tpl"])){
?>
<script type="text/javascript">
if(typeof costum.lists == "undefined")
if(typeof costum != "undefined" && costum != null && typeof costum.lists == "undefined")
costum.lists = {};
if(typeof costum.lists == "undefined")
if(typeof costum != "undefined" && costum != null && typeof costum.lists == "undefined")
costum.lists.budgetInputList = <?php echo json_encode( Yii::app()->session["budgetInputList"] ); ?>;
//costum.lists.financerTypeList = <?php //echo json_encode(Ctenat::$financerTypeList); ?>;
costum.lists.workerList = <?php echo json_encode($orgs); ?>;
......
......@@ -8,7 +8,14 @@
$editParamsBtn = ($canEdit) ? " <a href='javascript:;' data-id='".$el["_id"]."' data-collection='".$this->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>" : "";
$communityLinks = Element::getCommunityByTypeAndId($this->costum["contextType"],$this->costum["contextId"]);
$communityLinks = array();
if(!empty($form["parent"])){
foreach ($form["parent"] as $key => $value) {
$cl= Element::getCommunityByTypeAndId($key,$value["type"]);
if(!empty($cl))
$communityLinks = array_merge($communityLinks, $cl);
}
}
$persons = Link::groupFindByType( Person::COLLECTION,$communityLinks,["name","links"] );
$organizations = Link::groupFindByType( Organization::COLLECTION,$communityLinks,["name","links"] );
$financers = array_merge( $persons, $organizations );
......
......@@ -49,8 +49,15 @@ if( isset($parentForm["params"][$kunik]) ) {
if( isset($parentForm["params"][$kunik]["openFinancing"]) )
$paramsData["openFinancing"] = $parentForm["params"][$kunik]["openFinancing"];
}
$communityLinks = array();
if(!empty($form["parent"])){
foreach ($form["parent"] as $key => $value) {
$cl= Element::getCommunityByTypeAndId($key,$value["type"]);
if(!empty($cl))
$communityLinks = array_merge($communityLinks, $cl);
}
}
$communityLinks = Element::getCommunityByTypeAndId($this->costum["contextType"],$this->costum["contextId"]);
$organizations = Link::groupFindByType( Organization::COLLECTION,$communityLinks,["name","links"] );
$orgs = [];
......
......@@ -66,7 +66,14 @@ if( isset($parentForm["params"][$kunik]["limitRoles"]) )
if( isset($parentForm["params"][$kunik]["budgetCopy"]) )
$paramsData["budgetCopy"] = $parentForm["params"][$kunik]["budgetCopy"];
$communityLinks = Element::getCommunityByTypeAndId($this->costum["contextType"],$this->costum["contextId"]);
$communityLinks = array();
if(!empty($form["parent"])){
foreach ($form["parent"] as $key => $value) {
$cl= Element::getCommunityByTypeAndId($key,$value["type"]);
if(!empty($cl))
$communityLinks = array_merge($communityLinks, $cl);
}
}
$organizations = Link::groupFindByType( Organization::COLLECTION,$communityLinks,["name","links"] );
$orgs = [];
......
......@@ -158,7 +158,7 @@ if(isset($this->costum["cms"]["color1"]))
"what" => "dossiers",
"wizid"=> $wizardUid
];
echo $this->renderPartial($this->costum["form"]["answersTpl"],$params);
echo $this->renderPartial($parentForm["answersTpl"],$params);
}
if( $mode == "fa" && $canEditForm === true ){
......
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