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

tweak step save

parent 0e7ea975
......@@ -4,12 +4,10 @@ if($canEditForm === true){
if(isset($form["subForms"]))
$subFormIds = array_merge( $subFormIds, $form["subForms"] );
?>
<div class="col-xs-12 padding-10 text-center bg-info">
<div class="col-xs-12 padding-10 text-center" style="background-color: #eee">
<h4>Admin Form</h4>
<a href='javascript:;' data-id='<?php echo (String)$form["_id"]; ?>' class="configBtn btn btn-danger bold">
<i class='fa fa-cogs'></i> CONFIG
</a>
<a href='javascript:;' data-id='<?php echo (String)$form["_id"]; ?>' class="configBtn btn btn-danger bold"><i class='fa fa-cogs'></i> CONFIG </a>
<a href='javascript:;' data-id='<?php echo (String)$form["_id"]; ?>' class='addStepBtn btn btn-danger bold'> <i class='fa fa-plus'></i> Ajouter une étape </a>
</div>
......@@ -21,6 +19,7 @@ if($canEditForm === true){
var tplCtx = {};
var form = <?php echo (!empty($form)) ? json_encode( $form ) : "null"; ?>;
var subForms = <?php echo json_encode($subFormIds)?>;
jQuery(document).ready(function() {
mylog.log("render","/modules/costum/views/tpls/forms/cplx/answers.php");
$('.configBtn').off().on("click",function() {
......@@ -28,6 +27,11 @@ jQuery(document).ready(function() {
mylog.log( "configBtn", tplCtx.id );
dyFObj.openForm( oformParams, null, form )
});
$('.addStepBtn').off().on("click",function() {
tplCtx.id = $(this).data("id");
mylog.log( "addStepBtn", tplCtx.id );
dyFObj.openForm( addStepParams, null, form )
});
});
var oformParams = {
jsonSchema : {
......@@ -42,12 +46,6 @@ var oformParams = {
params : { onText : "Oui", offText : "Non", onLabel : "Oui", offLabel : "Non",
labelText : "Activé"},
checked : false },
subForms : {
inputType : "array",
label : "Nommé chaque étape de votre questionnaire",
//subLabel : "Vous remplirez les question de chaques étapes par la suite",
value : []
},
private : {
inputType : "checkboxSimple",
label : "Privé",
......@@ -92,13 +90,8 @@ var oformParams = {
labelText : "Réponse Affichés"},
checked : true },
},
beforeBuild : function(){
dyFObj.setMongoId('forms',function(){
uploadObj.gotoUrl = '#page.type.forms.id.'+uploadObj.id;
});
},
save : function (formData) {
//mylog.log('save tplCtx formData', formData)
mylog.log('oformParams save tplCtx formData', formData)
tplCtx.collection = "forms";
tplCtx.path = "allToRoot";
tplCtx.value = {};
......@@ -107,37 +100,10 @@ var oformParams = {
tplCtx.value[k] = getPairsObj('.'+k+val.inputType);
else if(val.inputType == "array"){
tplCtx.value[k] = getArray('.'+k+val.inputType);
if(k=="subForms"){
var cx = subForms.length;
$.each(tplCtx.value[k],function(ix,fName) {
mylog.log("check sub Form",fName, "<?php echo $el["slug"] ?>"+cx);
if($.inArray(fName, subForms) < 0 ){
var newFormId = "<?php echo $el["slug"] ?>"+cx;
tplCtx.value[k][ix] = newFormId;
var newForm = {
collection : "forms",
value : {
id : newFormId,
name : fName,
type : "openForm",
inputs : {}
}
};
dataHelper.path2Value( newForm, function() {
mylog.log("created new sub Form",newFormId);
} );
cx++;
}
})
}
}
else
tplCtx.value[k] = $("#"+k).val();
mylog.log("value",'.'+k+val.inputType,tplCtx.value[k]);
mylog.log("oformParams value",'.'+k+val.inputType,tplCtx.value[k]);
});
mylog.log("oformParams save tplCtx",tplCtx);
......@@ -154,4 +120,66 @@ var oformParams = {
}
};
var addStepParams = {
jsonSchema : {
title : "Ajouter une étape",
description : "Un formulaire peut contenir une ou plusieurs étape, chacun peut etre considérée comme un sous formulaire",
icon : "fa-wpforms",
properties : {
subForms : {
inputType : "array",
label : "Nommé chaque étape de votre questionnaire",
//subLabel : "Vous remplirez les question de chaques étapes par la suite",
value : []
}
},
save : function (formData) {
mylog.log('addStepParams save tplCtx formData', formData)
tplCtx.collection = "forms";
tplCtx.path = "subForms";
tplCtx.value = [];
var now = new Date();
var cx = ""+now.getDate() + (now.getMonth()+1) + now.getFullYear()+"_"+now.getHours()+now.getMinutes();
$.each( formData.subForms, function(ix,fName) {
mylog.log("addStepParams check sub Form",fName, "<?php echo $el["slug"] ?>"+cx);
if($.inArray(fName, subForms) < 0 ){
var newFormId = "<?php echo $el["slug"] ?>"+cx;
tplCtx.value.push(newFormId);
var newForm = {
collection : "forms",
value : {
id : newFormId,
name : fName,
type : "openForm",
inputs : {}
}
};
dataHelper.path2Value( newForm, function() {
mylog.log("addStepParams created new sub Form",newFormId);
} );
} else
tplCtx.value.push(newFormId);
})
mylog.log("addStepParams save tplCtx",tplCtx);
if(typeof tplCtx.value == "undefined")
toastr.error('value cannot be empty!');
else {
dataHelper.path2Value( tplCtx, function(params) {
urlCtrl.loadByHash(location.hash);
} );
}
}
}
};
</script>
\ No newline at end of file
......@@ -181,7 +181,8 @@ if( isset($form["subForms"]) && count($form["subForms"]) > 1 ) {
} else {
echo "<div class='col-xs-12 text-center'>";
echo '<br/><h4 class="text-red text-center">ce formulaire est encore vide</h4>';
echo "<a href='javascript:;' data-id='".(String)$form["_id"]."' class='configBtn btn btn-danger bold'> <i class='fa fa-cogs'></i> CONFIGUREZ LE ICI </a>";
echo "<br/><br/><a href='javascript:;' data-id='".(String)$form["_id"]."' class='addStepBtn btn btn-danger bold'> <i class='fa fa-cogs'></i> Ajouter un formulaire </a>";
echo "<br/><br/><i class='fa fa-5x fa-wpforms'></i>";
echo "</div>";
} ?>
</div>
\ No newline at end of file
Supports Markdown
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