Commit 7e008672 authored by Tibor Katelbach's avatar Tibor Katelbach
Browse files

dynform builder

parent cd1afa57
...@@ -53,9 +53,14 @@ if($mode != "r" && $mode != "pdf"){ ...@@ -53,9 +53,14 @@ if($mode != "r" && $mode != "pdf"){
<ul id="dynformUl"> <ul id="dynformUl">
<?php <?php
//var_dump($properties); //var_dump($properties);
//echo "<li> open dyn form _id >".$dynForm["_id"]."</li>";
foreach ( $properties as $k => $inp ) { foreach ( $properties as $k => $inp ) {
echo "<li> > ". echo "<li id='input".$kunik.$k."'> > ".
$inp["label"]."<span class='miniTxt'>( ".$inp["type"]." )</span> <a href='javascript:;' data-path='inputs.".$k."' class='pull-right btn btn-xs btn-primary editDynformInput' ><i class='fa fa-pencil'></i></a> <a href='javascript:;' data-path='inputs.".$k."' data-collection='forms' data-id='".$dynForm["_id"]."' class='deleteLine pull-right btn btn-xs btn-danger' ><i class='fa fa-trash'></i></a><li>"; $inp["label"]."<span class='miniTxt'>( ".@$inp["inputType"]." ) ".@$inp["placeholder"]." </span> ".
//Edit Input
"<a href='javascript:;' data-path='inputs.".$k."' class='pull-right btn btn-xs btn-primary editDynformInput' ><i class='fa fa-pencil'></i></a>".
//Delete Input
" <a href='javascript:;' data-path='inputs.".$k."' data-inputId='".$kunik.$k."' class='deleteInput pull-right btn btn-xs btn-danger' ><i class='fa fa-trash'></i></a><li>";
} ?> } ?>
<li class='text-center'> <li class='text-center'>
<a href='javascript:;' data-id='<?php echo $dynForm["_id"]?>' data-collection='<?php echo Form::COLLECTION?>' data-path='inputs' class='addInputDynform_<?php echo $dynForm["id"]?> btn btn-primary' ><i class="fa fa-plus"></i> Ajouter une Question au formulaire </a> <a href='javascript:;' data-id='<?php echo $dynForm["_id"]?>' data-collection='<?php echo Form::COLLECTION?>' data-path='inputs' class='addInputDynform_<?php echo $dynForm["id"]?> btn btn-primary' ><i class="fa fa-plus"></i> Ajouter une Question au formulaire </a>
...@@ -106,7 +111,9 @@ $(document).ready(function() { ...@@ -106,7 +111,9 @@ $(document).ready(function() {
icon : "fa-plus", icon : "fa-plus",
text : "lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum ", text : "lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum ",
onLoads : { onLoads : {
onload : function () { bb.modal('hide') } onload : function () {
bb.modal('hide');
}
}, },
properties : { properties : {
label : { label : "Titre de la Question au sous Formulaire" }, label : { label : "Titre de la Question au sous Formulaire" },
...@@ -114,28 +121,167 @@ $(document).ready(function() { ...@@ -114,28 +121,167 @@ $(document).ready(function() {
info : { info : {
inputType : "textarea", inputType : "textarea",
label : "Information complémentaire sur la Question" }, label : "Information complémentaire sur la Question" },
type : { label : "Type de cette question", required : {
inputType : "select", inputType : "checkboxSimple",
options : <?php echo json_encode(Form::$dynformInputTypes); ?>, label : "Obligatoire",
value : "text" } subLabel : "Ce champs est obligatoire",
params : {
onText : "Oui",
offText : "Non",
onLabel : "Oui",
offLabel : "Non",
labelText : "Obligatoire"
},
checked : false
},
//config inputs activate later by type
finderTypes : {
inputType : "select",
label : "Les types possible du finder",
placeholder : "types d'éléments",
options : {
"persons" : "Personnes",
"organizations":"Organisations",
"projects":"Projets",
"events":"Evennements",
},
topClass : "hide"
},
multiple : {
inputType : "checkboxSimple",
label : "Multiple",
subLabel : "Configuré le Finder",
params : {
onText : "Oui",
offText : "Non",
onLabel : "Oui",
offLabel : "Non",
labelText : "Multiple"
},
checked : true,
topClass : "hide"
},
openSearch : {
inputType : "checkboxSimple",
label : "Chercher Partout",
subLabel : "Configuré le Finder",
params : {
onText : "Oui",
offText : "Non",
onLabel : "Oui",
offLabel : "Non",
labelText : "Chercher Partout"
},
checked : true,
topClass : "hide"
},
invite : {
inputType : "checkboxSimple",
label : "Invité",
subLabel : "Configuré le Finder",
params : {
onText : "Oui",
offText : "Non",
onLabel : "Oui",
offLabel : "Non",
labelText : "Invité"
},
checked : true,
topClass : "hide"
},
list : {
placeholder : "Liste des options | roles",
label : "Liste des options pour les select et role pour les finders",
inputType : "array",
topClass : "hide",
value : []
},
maxlength : {
label : "Limiter le texte",
inputType : "text",
topClass : "hide"
},
//"rules" : {"required":true,"maxlength" : 200},
inputType : {
label : "Type de cette question",
inputType : "select",
options : <?php echo json_encode(Form::$dynformInputTypes); ?>,
value : "text" ,
init:function(){
$("#ajaxFormModal #inputType").on( "change", function(){
$("#ajaxFormModal .listarray,.multiplecheckboxSimple, #ajaxFormModal .openSearchcheckboxSimple, #ajaxFormModal .invitecheckboxSimple,#ajaxFormModal .maxlengthtext").addClass("hide");
if($.inArray( $(this).val(), [ "select","finder"] )>=0)
$("#ajaxFormModal .listarray").removeClass("hide");
if($.inArray( $(this).val(), [ "finder"] )>=0){
$("#ajaxFormModal .finderTypesselect, #ajaxFormModal .multiplecheckboxSimple, #ajaxFormModal .openSearchcheckboxSimple, #ajaxFormModal .invitecheckboxSimple").removeClass("hide");
}
if($.inArray( $(this).val(), [ "textarea"] )>=0){
$("#ajaxFormModal .maxlengthtext").removeClass("hide");
}
// "multiple" : true,
// "invite" : true,
// "openSearch" : true
// "type" : [
// "persons"
// ],
// "roles" : [
// "Elu"
// ],
})
}
}
}, },
save : function (formData) { save : function (formData) {
mylog.log('save tplCtx formData', formData) mylog.log('save tplCtx formData', formData)
delete formData.collection ; delete formData.collection ;
delete formData.id ; delete formData.id ;
tplCtx.value = formData; tplCtx.value = {};
tplCtx.value.label = formData.label;
tplCtx.value.inputType = formData.inputType;
if(formData.info)
tplCtx.value.info = formData.info;
if(formData.placeholder)
tplCtx.value.placeholder = formData.placeholder;
if(formData.required ) {
tplCtx.value.rules = {};
tplCtx.value.rules.required = formData.required;
}
//alert(tplCtx.value.inputType);
if( $.inArray( tplCtx.value.inputType , [ "select"] )>=0 ) {
tplCtx.value.options = {};
//alert(tplCtx.value["list[]"].length);
$.each( formData["list[]"], function(i,v) {
tplCtx.value.options[ slugify(v) ] = v;
} );
}
if( $.inArray( tplCtx.value.inputType , [ "finder"] )>=0 ) {
tplCtx.value.roles = formData["list[]"];
}
if( $.inArray( tplCtx.value.inputType , [ "textarea"] )>=0 && $("#ajaxFormModal #maxlength").val() != "" ) {
if(typeof tplCtx.value.rules != "undefined")
tplCtx.value.rules = {};
tplCtx.value.rules.maxlength = $("#ajaxFormModal #maxlength").val();
}
mylog.log("save tplCtx",tplCtx); mylog.log("save tplCtx",tplCtx);
if(typeof tplCtx.value == "undefined") // if(typeof tplCtx.value == "undefined")
toastr.error('value cannot be empty!'); // toastr.error('value cannot be empty!');
else { // else {
dataHelper.path2Value( tplCtx, function(params) { // dataHelper.path2Value( tplCtx, function(params) {
urlCtrl.loadByHash(location.hash); // urlCtrl.loadByHash(location.hash);
} ); // } );
} // }
} }
} }
...@@ -181,6 +327,17 @@ $(document).ready(function() { ...@@ -181,6 +327,17 @@ $(document).ready(function() {
dyFObj.openForm( sectionDyf.<?php echo $kunik ?>,null, <?php echo $kunik ?>Data[$(this).data("key")]); dyFObj.openForm( sectionDyf.<?php echo $kunik ?>,null, <?php echo $kunik ?>Data[$(this).data("key")]);
}); });
$(".deleteInput").off().on("click",function() {
tplCtx.id = "<?php echo $dynForm["_id"]?>";
tplCtx.collection = "<?php echo Form::COLLECTION;?>";
tplCtx.path = $(this).data("path");
tplCtx.inputId = $(this).data("inputId");
tplCtx.value = null;
mylog.log('deleteInput tplCtx', tplCtx)
dataHelper.path2Value( tplCtx, function(params) {
$('#'+tplCtx.inputId).slideUp();//urlCtrl.loadByHash(location.hash);
} );
});
......
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