Skip to content
Snippets Groups Projects
Commit e9e17215 authored by S.Listl's avatar S.Listl
Browse files

ViewTemplateData_lib

parent dce203a9
No related branches found
No related tags found
No related merge requests found
/**
* Object to make the creation of a JSON for the Dynamic Form component simpler
* Object to make the creation of a JSON for the Dynamic Form component simpler.
*
* @example
*
* var form = new DynamicFormDefinition()
* .addField("title", "Title", null, null, true)
* .addField("productcode", "Product code")
* .addField("purchasedate", "Purchase date", "DATE")
* .addField("amount", "Amount", "NUMBER", 1);
*
* if (!vars.get("$field.DESCRIPTION"))
* form.addField("description", "Description", "LONG_TEXT");
*
* result.string(form.toString()); //.toString() would also be called implicitly so it could be omitted
*
* @param {String} [pFormDefinition] an already existing form JSON as string
*/
......@@ -12,7 +25,16 @@ function DynamicFormDefinition (pFormDefinition)
this.fields = [];
}
DynamicFormDefinition.prototype.addField = function (pId, pName, pContentType, pMandatory, pReadOnly, pIsReadable)
/**
* @param {String} pId unique ID of the field
* @param {String} pName title of the field
* @param {String} [pContentType] content type
* @param {String} [pValue] preset value
* @param {boolean} [pMandatory=false] mandatory
* @param {boolean} [pReadOnly=false] readOnly
* @param {boolean} [pIsReadable=true] readable
*/
DynamicFormDefinition.prototype.addField = function (pId, pName, pContentType, pValue, pMandatory, pReadOnly, pIsReadable)
{
//TODO: check if id is unique
this.fields.push({
......@@ -21,24 +43,40 @@ DynamicFormDefinition.prototype.addField = function (pId, pName, pContentType, p
contentType : pContentType || "TEXT",
isReadable : pIsReadable || true,
isWritable : !pReadOnly,
isRequired : pMandatory || false
isRequired : pMandatory || false,
value : pValue === undefined ? null : pValue
});
return this;
}
/**
*
*/
DynamicFormDefinition.prototype.removeField = function (pId)
{
var index = this.indexOfField(pId);
if (index != -1)
this.fields.splice(index, 1);
return this;
}
/**
*
*/
DynamicFormDefinition.prototype.indexOfField = function (pId)
{
for (let i = 0, l = this.fields.length; i < l; i++)
{
if (this.fields[i].id == pId)
{
this.fields.splice(i, 1);
return this;
}
return i;
}
return this;
return -1;
}
/**
*
*/
DynamicFormDefinition.prototype.toString = function ()
{
return JSON.stringify(this.fields);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment