Commit edc10c9d authored by Clément Damiens's avatar Clément Damiens

nav in survey & refactor survey clean
parent 4d81e322
<?php class AnswerController extends CommunecterController {
protected function beforeAction($action) {
//parent::initPage();
return parent::beforeAction($action);
}
public function actions()
{
return array(
'new' => 'survey.controllers.answer.NewAction',
'index' => 'survey.controllers.answer.IndexAction',
'all'=>'survey.controllers.answer.AllAction'
);
}
}
......@@ -18,8 +18,9 @@ class CoController extends CommunecterController {
public function actions()
{
return array(
'init' => 'survey.controllers.actions.openForm.InitAction',
'index' => 'survey.controllers.actions.IndexAction',
'init' => 'survey.controllers.actions.InitAction',
'form' => 'survey.controllers.actions.FormAction',
'forms' => 'survey.controllers.actions.FormsAction',
......
<?php class FormController extends CommunecterController {
protected function beforeAction($action) {
//parent::initPage();
return parent::beforeAction($action);
}
public function actions()
{
return array(
'create' => 'survey.controllers.openForm.CreateAction',
'edit'=> 'survey.controllers.openForm.EditAction',
);
}
}
<?php
class IndexAction extends CAction
{
public function run($id=null, $answer=null, $tpl=null)
{
$this->getController()->layout = "//layouts/empty";
$params = ["canEdit" => true];
// if( isset($test) ){
// $params["tpl"]=$id;
//}
if(!empty($id)){
$params["answerId"]=$id;
}
$params = Form::getDataForAnswer($params);
$tpl=(!empty($tpl)) ? $tpl : "survey.views.tpls.forms.formWizard";
echo $this->getController()->renderPartial($tpl,$params );
}
}
\ No newline at end of file
<?php
class InitAction extends CAction
class NewAction extends CAction
{
public function run($id=null, $tpl=null)
{
$this->getController()->layout = "//layouts/empty";
$params = ["canEdit" => true];
if( isset($test) ){
$params["tpl"]=$id;
// $params["test"]=$test;
}
$params = array(
"canEdit" => true,
"answerId"=>"new"
);
if( isset($test) ){
$params["tpl"]=$id;
}
$params = Form::getDataForAnswer($params);
$tpl=(!empty($tpl)) ? $tpl : "costum.views.custom.co.formWizard";
echo $this->getController()->renderPartial($tpl,$params );
}
......
<?php
class InitAction extends CAction
{
public function run($id=null, $answer=null, $tpl=null)
{
$this->getController()->layout = "//layouts/empty";
$params = ["canEdit" => true];
if( isset($test) ){
$params["tpl"]=$id;
}
if(!empty($anwserId)){
$params["answerId"]=$answer;
}
$params = Form::getDataForAnswer($params);
$tpl=(!empty($tpl)) ? $tpl : "costum.views.custom.co.formWizard";
echo $this->getController()->renderPartial($tpl,$params );
}
}
\ No newline at end of file
......@@ -632,11 +632,27 @@ class Form {
if(isset(Yii::app()->session['costum']["hasOpenForm"])){
if(isset(Yii::app()->session['costum']["isMultiForms"])){
$params["formList"] = Yii::app()->session["costum"]["form"]["ids"];
$params["formId"] = implode("|", $params["formList"]);
$answerId=null;
$answer=null;
$generateAnswer = false;
if(isset($_GET['answer']))
$answerId=$_GET['answer'];
else if(isset($params["answerId"]))
$answerId=$params["answerId"];
//var_dump($answerId);
if(!empty($answerId) && $answerId !="new")
$answer = self::getAnswerById($answerId);
//var_dump($answer);exit;
if(!empty($answer)){
$params["formList"] = explode("|", $answer["formId"]);
$params["formId"] = $answer["formId"];
}else if(isset(Yii::app()->session["costum"]["form"])){
$params["formList"] = Yii::app()->session["costum"]["form"]["ids"];
$params["formId"] = implode("|", $params["formList"]);
}
//when inputs are interdependant on other inputs
$budgetInputList = [];
$allforms = [];
......@@ -674,9 +690,11 @@ class Form {
// $answer = ( isset(Yii::app()->session["costum"]["form"]["canModifyAnswer"]) && isset($_GET['answer'])) ? PHDB::findOne( Form::ANSWER_COLLECTION,[ "_id" => new MongoId($_GET['answer']) ] ) : null;
$answer = ( isset($_GET['answer'])) ? PHDB::findOne( Form::ANSWER_COLLECTION,[ "_id" => new MongoId($_GET['answer']) ] ) : null;
if(!isset($params["el"]) && !empty($answer) && isset($answer["parentSlug"]))
$params["el"]=Slug::getElementBySlug($answer["parentSlug"])["el"];
$showForm = true;
$generateAnswer = false;
$myAnswers = PHDB::find( Form::ANSWER_COLLECTION,[
"formId" => $params["formId"],
"parentSlug" => $params["el"]["slug"],
......@@ -684,89 +702,69 @@ class Form {
if(
!isset(Yii::app()->session["costum"]["form"]["oneAnswerPerPerson"]) ||
count($myAnswers) == 0
)
{
//si ya qu'une réponse et on la charge directe
if(count($myAnswers) == 1 )
$answer = $myAnswers[ array_keys($myAnswers)[0] ];
else {
//sinon on cherche la reponse incomplete
foreach ($myAnswers as $id => $ans)
{
//chercher les reponse incomplete
//var_dump(isset( $ans["answers"] ) );
if(!isset( $ans["answers"]) && $answer == null )
$answer = $ans;
}
}
if( $answer == null && count( $myAnswers ) > 1 && !$canEdit )
$showForm = false;
//si aucune reponse existe
//et qu'on a des input complexe alors on génere une answer
if( !isset($_GET['answer']) && $answer == null )
{
if(isset($params["formList"])){
$generateAnswer = true;
}
else if(isset($form["inputs"])){
foreach ($form["inputs"] as $key => $inp)
{
if( stripos( $inp["type"] , "tpls.forms.cplx" ) !== false )
$generateAnswer = true;
}
}
}
if( isset($_GET['answer']) && $_GET['answer'] == "new" )
$generateAnswer = true;
//on pré genere un anwser que quand il n'y en pas
//pour permettre le save onBlur , ou s'il y a des cplx forms
//il ne peut y avoir qu'un seul answer en cours simultanement
///TODO purger ANSwers via CRON
if( $generateAnswer )
{
//var_dump("create new" );
$ans = [
"formId" => $params["formId"],
"user" => Yii::app()->session["userId"],
"parentSlug" => $params["el"]["slug"],
"created" => time()
];
if(isset($params["formList"]))
$ans["formList"] = count($params["formList"]);
PHDB::insert(Form::ANSWER_COLLECTION, $ans);
$answer = PHDB::findOne( Form::ANSWER_COLLECTION, [ "_id" => new MongoId($ans["_id"]) ] );
}
// var_dump($params["el"]["slug"] );
// var_dump($params["formId"] );
// var_dump($answer );
// var_dump(Yii::app()->getRequest()->getQuery('answer'));
// exit;
$params["answer"] = $answer;
$params["showForm"] = $showForm;
$params["allAnswers"] = PHDB::find( Form::ANSWER_COLLECTION,[
if(!isset(Yii::app()->session["costum"]["form"]["oneAnswerPerPerson"]) || count($myAnswers) == 0){
//si ya qu'une réponse et on la charge directe
if(count($myAnswers) == 1 )
$answer = $myAnswers[ array_keys($myAnswers)[0] ];
else {
//sinon on cherche la reponse incomplete
foreach ($myAnswers as $id => $ans)
{
//chercher les reponse incomplete
if(!isset( $ans["answers"]) && $answer == null )
$answer = $ans;
}
}
if( $answer == null && count( $myAnswers ) > 1 && !$canEdit )
$showForm = false;
//si aucune reponse existe
//et qu'on a des input complexe alors on génere une answer
if( !isset($_GET['answer']) && $answer == null ){
if(isset($params["formList"])){
$generateAnswer = true;
}
else if(isset($form["inputs"])){
foreach ($form["inputs"] as $key => $inp)
{
if( stripos( $inp["type"] , "tpls.forms.cplx" ) !== false )
$generateAnswer = true;
}
}
}
if( isset($answerId) && $answerId == "new" )
$generateAnswer = true;
//on pré genere un anwser que quand il n'y en pas
//pour permettre le save onBlur , ou s'il y a des cplx forms
//il ne peut y avoir qu'un seul answer en cours simultanement
///TODO purger ANSwers via CRON
if( $generateAnswer ){
$ans = [
"formId" => $params["formId"],
"user" => Yii::app()->session["userId"],
"parentSlug" => $params["el"]["slug"],
"created" => time()
];
if(isset($params["formList"]))
$ans["formList"] = count($params["formList"]);
PHDB::insert(Form::ANSWER_COLLECTION, $ans);
$answer = PHDB::findOne( Form::ANSWER_COLLECTION, [ "_id" => new MongoId($ans["_id"]) ] );
}
$params["answer"] = $answer;
$params["showForm"] = $showForm;
$params["allAnswers"] = PHDB::find( Form::ANSWER_COLLECTION,[
"formId" => $params["formId"],
"parentSlug" => $params["el"]["slug"] ] );
//var_dump($params["el"]["slug"]);exit;
//var_dump($params["allAnswers"]);exit;
} else {
echo "<h4 class='text-center text-red'><i class='fa fa-warning'></i> Une seul réponse n'est possible.</h4>";
echo "<a class='btn btn-primary' href='/costum/co/index/slug/".$el["slug"]."/answer/".$myAnswers[0]."'>Votre réponse</a>";
}
}
return $params;
}
......
<?php
if( !isset( $el["costum"]["slug"] ) || (isset( $el["costum"]["slug"]) && $el["costum"]["slug"] != $tpl ) )
$test=$tpl;
if( isset($test) || $canEdit )
{
?>
<script type="text/javascript">
//contains all dynform definitions for complexe inputs
//it also carries sub dynforms, when an input needs extra parameters to
var sectionDyf = {};
var tplCtx = {};
var DFdata = {
'tpl' : '<?php echo $tpl ?>',
"id" : "<?php echo Yii::app()->session["costum"]["contextId"] ?>"
};
costum.col = "<?php echo Yii::app()->session["costum"]["contextType"] ?>";
costum.ctrl = "<?php echo Element::getControlerByCollection(Yii::app()->session["costum"]["contextType"]) ?>";
var configDynForm = <?php echo json_encode(Yii::app()->session['costum']['dynForm']); ?>;
var tplsList = <?php echo json_encode((isset(Yii::app()->session['costum']['tpls'])) ? Yii::app()->session['costum']['tpls']:null); ?>;
function saveThisTpl (slug) {
data = {
collection : costum.contextType,
id : costum.contextId,
path : "costum.slug",
value : '<?php echo $tpl ?>'
}
mylog.log(".saveThisTpl","data",data);
// http://127.0.0.1/costum/co/index/slug/administration-opal/test/campagne#
dataHelper.path2Value( data, function(params) {
var s = location.href;
var a = s.split('/');
s = s.replace(a[a.length-2] + '/', '');
s = s.replace(a[a.length-1], '');
location.href = s;
} );
}
function previewTpl () {
$('#acceptAndAdmin,.editBtn,.editQuestion,.addQuestion,.deleteLine, .previewTpl').fadeOut();
}
jQuery(document).ready(function() {
mylog.log("render","/modules/costum/views/tpls/acceptAndAdmin.php");
$(".editBtn").off().on("click",function() {
var activeForm = {
"jsonSchema" : {
"title" : "Template config",
"type" : "object",
"properties" : {
}
}
};
if(configDynForm.jsonSchema.properties[ $(this).data("key") ])
activeForm.jsonSchema.properties[ $(this).data("key") ] = configDynForm.jsonSchema.properties[ $(this).data("key") ];
else
activeForm.jsonSchema.properties[ $(this).data("key") ] = { label : $(this).data("label") };
if($(this).data("label"))
activeForm.jsonSchema.properties[ $(this).data("key") ].label = $(this).data("label");
if($(this).data("type")){
activeForm.jsonSchema.properties[ $(this).data("key") ].inputType = $(this).data("type");
if($(this).data("type") == "textarea" && $(this).data("markdown") )
activeForm.jsonSchema.properties[ $(this).data("key") ].markdown = true;
}
tplCtx.id = contextData.id;
tplCtx.collection = contextData.type;
tplCtx.key = $(this).data("key");
tplCtx.path = $(this).data("path");
activeForm.jsonSchema.save = function () {
tplCtx.value = $( "#"+tplCtx.key ).val();
//alert("#"+tplCtx.key+" : "+$( "#"+tplCtx.key ).val());
console.log("activeForm save tplCtx",tplCtx);
if(typeof tplCtx.value == "undefined")
toastr.error('value cannot be empty!');
else {
dataHelper.path2Value( tplCtx, function(params) {
$("#ajax-modal").modal('hide');
location.reload();
} );
}
}
dyFObj.openForm( activeForm );
});
$('.deleteLine').off().click( function(){
formId = $(this).data("id");
key = $(this).data("key");
pathLine = $(this).data("path");
collection = $(this).data("collection");
bootbox.dialog({
title: "Confirmez la suppression",
message: "<span class='text-red bold'><i class='fa fa-warning'></i> Cette action sera irréversible</span>",
buttons: [
{
label: "Ok",
className: "btn btn-primary pull-left",
callback: function() {
var formQ = {
value:null,
collection : collection,
id : formId,
path : pathLine
};
dataHelper.path2Value( formQ , function(params) {
$("#"+key).remove();
//location.reload();
} );
}
},
{
label: "Annuler",
className: "btn btn-default pull-left",
callback: function() {}
}
]
});
});
$(".editTpl").off().on("click",function() {
var activeForm = {
"jsonSchema" : {
"title" : "Edit Question config",
"type" : "object",
"properties" : {}
}
};
$.each( formTpls [ $(this).data("key") ] , function(k,val) {
console.log("formTpls",k,val);
activeForm.jsonSchema.properties[ k ] = {
label : k,
value : val
};
});
console.log("formTpls activeForm.jsonSchema.properties",activeForm.jsonSchema.properties);
tplCtx.id = $(this).data("id");
tplCtx.key = $(this).data("key");
tplCtx.collection = $(this).data("collection");
tplCtx.path = $(this).data("path");
activeForm.jsonSchema.save = function () {
tplCtx.value = {};
$.each( formTpls [ tplCtx.key ] , function(k,val) {
tplCtx.value[k] = $("#"+k).val();
});
//alert("#"+tplCtx.key+" : "+$( "#"+tplCtx.key ).val());
console.log("save tplCtx",tplCtx);
if(typeof tplCtx.value == "undefined")
toastr.error('value cannot be empty!');
else {
dataHelper.path2Value( tplCtx, function(params) {
$("#ajax-modal").modal('hide');
location.reload();
} );
}
}
dyFObj.openForm( activeForm );
});
$(".addTpl").off().on("click",function() {
var tplCtx = {};
var activeForm = {
"jsonSchema" : {
"title" : "Ajouter une section",
"type" : "object",
"properties" : {
type : { label : "Choisir le template",
inputType : "select",
options : {
"blockevent" : "Les blocs d'évènements",
"eventCarousel" : "Les évènements en carousel",
"blockwithimg" : "Un bloc avec un texte et une image",
"communityblock" : "Les blocs communautés",
"communityCaroussel" : "Communauté en carousel",
"news" : "L'actualité"
},
value : "text" }
}
}
};
tplCtx.id = $(this).data("id");
tplCtx.key = $(this).data("key");
tplCtx.collection = $(this).data("collection");
activeForm.jsonSchema.save = function () {
tplCtx.path = "costum.tpls."+$("#type").val();
tplCtx.value = {
defaultcolor : "white"
};
console.log("activeForm save tplCtx",tplCtx);
if(typeof tplCtx.value == "undefined")
toastr.error('value cannot be empty!');
else {
dataHelper.path2Value( tplCtx, function(params) {
$("#ajax-modal").modal('hide');
location.reload();
} );
}
}
dyFObj.openForm( activeForm );
});
});
</script>
<div class="alert alert-danger text-center" id="acceptAndAdmin" >
<?php //echo Yii::app()->session["costum"]["contextId"]."<br/>" ?>
<?php //echo Yii::app()->session["costum"]["contextType"]."<br/>" ?>
<?php //echo Yii::app()->session["costum"]["contextSlug"]."<br/>" ?>
<?php //var_dump(Yii::app()->session["costum"]) ?>
<?php if(isset($test) ){ ?>
<strong>Hey!</strong> Is this what you want ?
<a href="javascript:;" onclick=" saveThisTpl('<?php echo $tpl ?>') " class="btn btn-danger"> Save This Template</a> <a href="/costum/co/index/slug/<?php echo $slug ?>/test/costumBuilder" class="btn btn-default"> Try another Template </a>
<?php } else if(isset(Yii::app()->session['costum']["dynForm"])) {
?>
<!-- <strong>Configure</strong> your Costum Template <a href="/costum/co/config/slug/<?php //echo $slug ?>" class="btn btn-danger"><i class="fa fa-pencil"></i> here </a> -->
<a class="btn btn-default" href="javascript:previewTpl();"><i class="fa fa-eye"></i> Preview</a>
<a class="btn btn-default" href="#@<?= Yii::app()->session["costum"]["contextSlug"] ?>" data-hash="#page.type.<?= Yii::app()->session["costum"]["contextType"] ?>.id.<?= Yii::app()->session["costum"]["contextId"] ?>" target="_blank"><i class="fa fa-id-card-o" aria-hidden="true"></i>
Element </a>
<?php echo $this->renderPartial("costum.views.tpls.blocCss", array("canEdit" => $canEdit)); ?>
<?php echo $this->renderPartial("costum.views.tpls.blocApp", array("canEdit" => $canEdit)); ?>
<?php } else { ?>
<strong>hey petit pixel</strong> rajoute une balise dynform sur ton template pour le rendre editable.
<?php } ?>
</div>
<?php } ?>
\ No newline at end of file
<style type="text/css">
#allAnswersList{ list-style: none }
#allAnswersList li{ padding:5px; border-bottom: 1px solid #ccc; }
</style>
<div class="col-xs-12 text-center">
<a href="javascript:;" class='btn btn- btn-default' id="showAnswerBtn"><i class="fa fa-bars"></i> Les <?php echo $what ?></a>
<a href="#dashboard" class='lbh btn btn-default'><i class="fa fa-area-chart"></i> Observatoire Global</a>
<a href="#community" class='lbh btn btn-default'><i class="fa fa-group"></i> Communauté</a>
<a href="/costum/co/index/slug/<?php echo $el["slug"] ?>/answer/new" class='btn btn-primary' id="showAnswerBtn"><i class="fa fa-plus"></i> Ajouter <?php echo $what ?></a>
</div>
<div id="allAnswersContainer" class="hide col-xs-12 col-lg-offset-2 col-lg-8 margin-top-20">
<ul id="allAnswersList">
<?php
$lbl = $what." ";
$ct = 0;
if(!empty($allAnswers)){
foreach ($allAnswers as $k => $ans) {
$ct++;
?>
<li class="answerLi col-xs-12" >