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

open dynform builder

parent dd56ce83
...@@ -72,35 +72,40 @@ class Form { ...@@ -72,35 +72,40 @@ class Form {
"text" => "texte simple", "text" => "texte simple",
"textarea" => "textarea", "textarea" => "textarea",
"markdown" => "markdown", "markdown" => "markdown",
"wysiwyg" => "wysiwyg", "finder" => "finder",
"checkbox" => "checkbox",
//"wysiwyg" => "wysiwyg",
//"checkbox" => "checkbox",
"checkboxSimple" => "checkboxSimple", "checkboxSimple" => "checkboxSimple",
"radio" => "radio", "radio" => "radio",
"select" => "select", "select" => "select",
"selectMultiple" => "selectMultiple", "selectMultiple" => "selectMultiple",
"formLocality" => "formLocality", "formLocality" => "formLocality",
"location" => "location",
"uploader" => "uploader", "uploader" => "uploader",
"folder" => "folder", //"folder" => "folder",
"finder" => "finder",
"lists" => "lists", "lists" => "lists",
"scope" => "scope", "tags" => "tags",
//2 "scope" => "scope",
"password" => "password", //"password" => "password",
"openingHours" => "openingHours", //"openingHours" => "openingHours",
"hidden" => "hidden", "hidden" => "hidden",
"timestamp" => "timestamp", //"timestamp" => "timestamp",
"colorpicker" => "colorpicker", "colorpicker" => "colorpicker",
"date" => "date", "date" => "date",
"datetime" => "datetime", "datetime" => "datetime",
"time" => "time", "time" => "time",
"link" => "link", //"link" => "link",
"captcha" => "captcha", //"captcha" => "captcha",
"tagList" => "tagList", //"tagList" => "tagList",
"location" => "location",
"postalcode" => "postalcode", //2 "postalcode" => "postalcode",
"arrayForm" => "arrayForm", // "arrayForm" => "arrayForm",
"array" => "array", "array" => "array",
"properties" => "properties" "properties" => "properties"
]; ];
......
...@@ -60,7 +60,7 @@ if($mode != "r" && $mode != "pdf"){ ...@@ -60,7 +60,7 @@ if($mode != "r" && $mode != "pdf"){
//Edit Input //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>". "<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 //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>"; " <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>
...@@ -116,7 +116,35 @@ $(document).ready(function() { ...@@ -116,7 +116,35 @@ $(document).ready(function() {
} }
}, },
properties : { properties : {
label : { label : "Titre de la Question au sous Formulaire" }, 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,#ajaxFormModal .onTexttext, #ajaxFormModal .offTexttext, #ajaxFormModal .initValuecheckboxSimple, #ajaxFormModal .labelKeytext, #ajaxFormModal .labelValuetext").addClass("hide");
if( $.inArray( $(this).val(), [ "select","finder","radio","tags"] ) >= 0 )
$("#ajaxFormModal .listarray").removeClass("hide");
if( $(this).val() == "finder" )
$("#ajaxFormModal .finderTypesselect, #ajaxFormModal .multiplecheckboxSimple, #ajaxFormModal .openSearchcheckboxSimple, #ajaxFormModal .invitecheckboxSimple").removeClass("hide");
if($.inArray( $(this).val(), [ "textarea","tags"] )>=0)
$("#ajaxFormModal .maxlengthtext").removeClass("hide");
if($(this).val() == "checkboxSimple" )
$( "#ajaxFormModal .onTexttext, #ajaxFormModal .offTexttext, #ajaxFormModal .initValuecheckboxSimple" ).removeClass("hide");
if( $(this).val() == "properties" )
$( "#ajaxFormModal .labelKeytext, #ajaxFormModal .labelValuetext" ).removeClass("hide");
})
}
},
label : { label : "Titre de la Question",rules : {required : true} },
subLabel : { label : "Texte sous la la Question" },
placeholder : { label : "Texte dans la Question" }, placeholder : { label : "Texte dans la Question" },
info : { info : {
inputType : "textarea", inputType : "textarea",
...@@ -137,7 +165,7 @@ $(document).ready(function() { ...@@ -137,7 +165,7 @@ $(document).ready(function() {
//config inputs activate later by type //config inputs activate later by type
finderTypes : { initType : {
inputType : "select", inputType : "select",
label : "Les types possible du finder", label : "Les types possible du finder",
placeholder : "types d'éléments", placeholder : "types d'éléments",
...@@ -204,84 +232,133 @@ $(document).ready(function() { ...@@ -204,84 +232,133 @@ $(document).ready(function() {
topClass : "hide" topClass : "hide"
}, },
//"rules" : {"required":true,"maxlength" : 200}, //"rules" : {"required":true,"maxlength" : 200},
onText : { label : "Texte de la Valeur Oui", inputType : "text", topClass : "hide" },
offText : { label : "Texte de la Valeur Non", inputType : "text", topClass : "hide" },
initValue : {
inputType : "checkboxSimple",
label : "Valeur d'ouverture",
subLabel : "Valeur d'ouverture",
params : {
onText : "Oui",offText : "Non",onLabel : "Oui",offLabel : "Non",labelText : "Valeur d'ouverture"
},
checked : true,
topClass : "hide"
},
labelKey : { label : "Label pour la clef", inputType : "text", topClass : "hide" },
labelValue : { label : "Label pour la valeur", inputType : "text", topClass : "hide" }
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 = {}; tplCtx.value = {};
tplCtx.value.label = formData.label; tplCtx.value.label = formData.label;
tplCtx.value.inputType = formData.inputType; tplCtx.value.inputType = formData.inputType;
if(formData.subLabel)
tplCtx.value.subLabel = formData.subLabel;
if(formData.info) if(formData.info)
tplCtx.value.info = formData.info; tplCtx.value.info = formData.info;
if(formData.placeholder) if(formData.placeholder)
tplCtx.value.placeholder = formData.placeholder; tplCtx.value.placeholder = formData.placeholder;
if(formData.required ) { if(formData.required ) {
tplCtx.value.rules = {}; tplCtx.value.rules = {};
tplCtx.value.rules.required = formData.required; tplCtx.value.rules.required = formData.required;
} }
//alert(tplCtx.value.inputType); //alert(tplCtx.value.inputType);
if( $.inArray( tplCtx.value.inputType , [ "select"] )>=0 ) {
// TYPE SELECT && RADIO
// ****************************
if( $.inArray( tplCtx.value.inputType , [ "select","radio"] )>=0 ) {
tplCtx.value.options = {}; tplCtx.value.options = {};
//alert(tplCtx.value["list[]"].length); //alert(tplCtx.value["list[]"].length);
$.each( formData["list[]"], function(i,v) { $.each( formData["list[]"], function(i,v) {
tplCtx.value.options[ slugify(v) ] = v; tplCtx.value.options[ slugify(v) ] = v;
} ); } );
} }
if( $.inArray( tplCtx.value.inputType , [ "finder"] )>=0 ) { // TYPE TAGS and ARRAY
tplCtx.value.roles = formData["list[]"]; // ****************************
if( $.inArray( tplCtx.value.inputType , [ "tags", "array" ] ) >=0 ){
tplCtx.value.values = [];
if(formData["list[]"]){
$.each( formData["list[]"], function(i,v) {
tplCtx.value.values.push(v);
} );
}
}
// TYPE FINDER
// ****************************
if( tplCtx.value.inputType == "finder" ) {
if(notNull(formData["list[]"]))
tplCtx.value.roles = ($.isArray(formData["list[]"])) ? formData["list[]"] : [formData["list[]"] ];
tplCtx.value.initType = [ "persons", "organizations","projects", "events"];
if(notNull(formData["finderTypes"])){
tplCtx.value.initType = ($.isArray(formData.finderTypes)) ? formData.finderTypes : [formData.finderTypes ];
}
tplCtx.value.multiple = parseBool( formData.multiple );
tplCtx.value.invite = parseBool( formData.invite );
tplCtx.value.openSearch = parseBool( formData.openSearch );
} }
if( $.inArray( tplCtx.value.inputType , [ "textarea"] )>=0 && $("#ajaxFormModal #maxlength").val() != "" ) {
if(typeof tplCtx.value.rules != "undefined") // TYPE TEXTAREA
tplCtx.value.rules = {}; // ****************************
tplCtx.value.rules.maxlength = $("#ajaxFormModal #maxlength").val(); if( $.inArray( tplCtx.value.inputType , [ "textarea","tags"] )>=0 && $("#ajaxFormModal #maxlength").val() != "" ) {
if(tplCtx.value.inputType == "textarea"){
if(typeof tplCtx.value.rules != "undefined")
tplCtx.value.rules = {};
tplCtx.value.rules.maxlength = $("#ajaxFormModal #maxlength").val();
}
else if (tplCtx.value.inputType == "tags"){
// TYPE TAGS
// ****************************
tplCtx.value.minimumInputLength = ($("#ajaxFormModal #maxlength").val() != "") ? $("#ajaxFormModal #maxlength").val() : 3
}
} }
// TYPE CHECKBOX
// ****************************
if( tplCtx.value.inputType == "checkboxSimple" ){
tplCtx.value.params = {
onText : formData.onText,
offText : formData.offText,
onLabel : formData.onText,
offLabel : formData.offText,
labelText : formData.label
};
tplCtx.value.checked = parseBool(formData.initValue);
}
if( tplCtx.value.inputType == "array" )
tplCtx.value.value = [""];
if( tplCtx.value.inputType == "properties" ){
tplCtx.value.values = {"",""};
tplCtx.value.labelKey = formData.labelKey;
tplCtx.value.labelValue = formData.labelValue;
}
// TYPE FORMLOCATION
// ****************************
// TYPE IMAGE
// ****************************
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);
// } ); } );
// } }
} }
} }
...@@ -309,35 +386,44 @@ $(document).ready(function() { ...@@ -309,35 +386,44 @@ $(document).ready(function() {
tplCtx.id = $(this).data("id"); tplCtx.id = $(this).data("id");
tplCtx.collection = $(this).data("collection"); tplCtx.collection = $(this).data("collection");
smallMenu.open( $("#form-buildDynform<?php echo $dynForm["id"]?>").html(),"bootbox",null,function() { smallMenu.open( $("#form-buildDynform<?php echo $dynForm["id"]?>").html(),"bootbox",null,function() {
$(".addInputDynform_<?php echo $dynForm["id"]?>").off().click(function() { $(".addInputDynform_<?php echo $dynForm["id"]?>").off().click(function() {
tplCtx.path = "inputs.q<?php echo "_".time()."_".count( $properties ); ?>"; tplCtx.path = "inputs.q<?php echo "_".time()."_".count( $properties ); ?>";
mylog.log("addInput tplCtx",tplCtx); mylog.log("addInput tplCtx",tplCtx);
dyFObj.openForm( sectionDyf.newDFInput<?php echo $dynForm["id"]?> ); dyFObj.openForm( sectionDyf.newDFInput<?php echo $dynForm["id"]?> );
}); });
$(".editDynformInput").off().on("click",function() {
tplCtx.id = "<?php echo $dynForm["_id"]?>";
tplCtx.collection = "<?php echo Form::COLLECTION;?>";
tplCtx.path = $(this).data("path");
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)
if($('li#input'+tplCtx.inputId).hasClass('bg-red')){
dataHelper.path2Value( tplCtx, function(params) {
$('li#input'+tplCtx.inputId).slideUp();//urlCtrl.loadByHash(location.hash);
} );
} else
$('li#input'+tplCtx.inputId).addClass('bg-red');
});
}); });
//on pourrait utiliser DF directement en changeant les btn save et ajoutant edit et suppr //on pourrait utiliser DF directement en changeant les btn save et ajoutant edit et suppr
//dyFObj.openForm( sectionDyf.<?php echo $kunik ?>,null, <?php echo $kunik ?>Data[$(this).data("key")],null,null,"build"); //dyFObj.openForm( sectionDyf.<?php echo $kunik ?>,null, <?php echo $kunik ?>Data[$(this).data("key")],null,null,"build");
}); });
$(".editDynformInput").off().on("click",function() {
tplCtx.id = "<?php echo $dynForm["_id"]?>";
tplCtx.collection = "<?php echo Form::COLLECTION;?>";
tplCtx.path = $(this).data("path");
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