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

open dynform builder

parent dd56ce83
......@@ -72,35 +72,40 @@ class Form {
"text" => "texte simple",
"textarea" => "textarea",
"markdown" => "markdown",
"wysiwyg" => "wysiwyg",
"checkbox" => "checkbox",
"finder" => "finder",
//"wysiwyg" => "wysiwyg",
//"checkbox" => "checkbox",
"checkboxSimple" => "checkboxSimple",
"radio" => "radio",
"select" => "select",
"selectMultiple" => "selectMultiple",
"formLocality" => "formLocality",
"location" => "location",
"uploader" => "uploader",
"folder" => "folder",
"finder" => "finder",
//"folder" => "folder",
"lists" => "lists",
"scope" => "scope",
"tags" => "tags",
//2 "scope" => "scope",
"password" => "password",
"openingHours" => "openingHours",
//"password" => "password",
//"openingHours" => "openingHours",
"hidden" => "hidden",
"timestamp" => "timestamp",
//"timestamp" => "timestamp",
"colorpicker" => "colorpicker",
"date" => "date",
"datetime" => "datetime",
"time" => "time",
"link" => "link",
"captcha" => "captcha",
"tagList" => "tagList",
"location" => "location",
"postalcode" => "postalcode",
"arrayForm" => "arrayForm",
//"link" => "link",
//"captcha" => "captcha",
//"tagList" => "tagList",
//2 "postalcode" => "postalcode",
// "arrayForm" => "arrayForm",
"array" => "array",
"properties" => "properties"
];
......
......@@ -60,7 +60,7 @@ if($mode != "r" && $mode != "pdf"){
//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>";
" <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'>
<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() {
}
},
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" },
info : {
inputType : "textarea",
......@@ -137,7 +165,7 @@ $(document).ready(function() {
//config inputs activate later by type
finderTypes : {
initType : {
inputType : "select",
label : "Les types possible du finder",
placeholder : "types d'éléments",
......@@ -204,84 +232,133 @@ $(document).ready(function() {
topClass : "hide"
},
//"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) {
mylog.log('save tplCtx formData', formData)
delete formData.collection ;
delete formData.id ;
tplCtx.value = {};
tplCtx.value.label = formData.label;
tplCtx.value.inputType = formData.inputType;
if(formData.subLabel)
tplCtx.value.subLabel = formData.subLabel;
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 ) {
// TYPE SELECT && RADIO
// ****************************
if( $.inArray( tplCtx.value.inputType , [ "select","radio"] )>=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[]"];
// TYPE TAGS and ARRAY
// ****************************
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 ];
}
if( $.inArray( tplCtx.value.inputType , [ "textarea"] )>=0 && $("#ajaxFormModal #maxlength").val() != "" ) {
tplCtx.value.multiple = parseBool( formData.multiple );
tplCtx.value.invite = parseBool( formData.invite );
tplCtx.value.openSearch = parseBool( formData.openSearch );
}
// TYPE TEXTAREA
// ****************************
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);
// if(typeof tplCtx.value == "undefined")
// toastr.error('value cannot be empty!');
// else {
// dataHelper.path2Value( tplCtx, function(params) {
// urlCtrl.loadByHash(location.hash);
// } );
// }
if(typeof tplCtx.value == "undefined")
toastr.error('value cannot be empty!');
else {
dataHelper.path2Value( tplCtx, function(params) {
urlCtrl.loadByHash(location.hash);
} );
}
}
}
......@@ -309,15 +386,11 @@ $(document).ready(function() {
tplCtx.id = $(this).data("id");
tplCtx.collection = $(this).data("collection");
smallMenu.open( $("#form-buildDynform<?php echo $dynForm["id"]?>").html(),"bootbox",null,function() {
$(".addInputDynform_<?php echo $dynForm["id"]?>").off().click(function() {
tplCtx.path = "inputs.q<?php echo "_".time()."_".count( $properties ); ?>";
mylog.log("addInput tplCtx",tplCtx);
dyFObj.openForm( sectionDyf.newDFInput<?php echo $dynForm["id"]?> );
});
});
//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");
});
$(".editDynformInput").off().on("click",function() {
......@@ -331,14 +404,27 @@ $(document).ready(function() {
tplCtx.id = "<?php echo $dynForm["_id"]?>";
tplCtx.collection = "<?php echo Form::COLLECTION;?>";
tplCtx.path = $(this).data("path");
tplCtx.inputId = $(this).data("inputId");
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) {
$('#'+tplCtx.inputId).slideUp();//urlCtrl.loadByHash(location.hash);
$('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
//dyFObj.openForm( sectionDyf.<?php echo $kunik ?>,null, <?php echo $kunik ?>Data[$(this).data("key")],null,null,"build");
});
......
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