mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
- Refactored FormData class to remove unecessary API layer and fixed up fallout
- Renamed 'definition' webscript to 'formdefiniton' (no change to URL) - Simplified and improved formdefinition webscript JS/FTL git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14698 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
<#macro formDefJSON form>
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
{
|
||||
"data" :
|
||||
{
|
||||
"item" : "${form.data.item}",
|
||||
"submissionUrl" : "${form.data.submissionUrl}",
|
||||
"type" : "${form.data.type}",
|
||||
"definition" :
|
||||
{
|
||||
"fields" :
|
||||
[
|
||||
<#list form.data.definition.fields as field>
|
||||
{
|
||||
<#list field?keys as key>
|
||||
<#if field[key]?is_boolean>
|
||||
"${key}" : ${field[key]?string}<#if key_has_next>,</#if>
|
||||
<#elseif field[key]?is_sequence>
|
||||
"${key}" :
|
||||
[{
|
||||
<#list field[key] as q>
|
||||
"type" : "${q.type}"<#if q.params?exists>,
|
||||
"params" : {
|
||||
<#list q.params?keys as p>
|
||||
<#-- Render booleans without the inverted commas -->
|
||||
|
||||
<#-- Can I create a macro for boolean rendering? -->
|
||||
|
||||
<#if q.params[p]?is_boolean>
|
||||
"${p}" : ${q.params[p]}<#if p_has_next>,</#if>
|
||||
<#else>
|
||||
"${p}" : "${q.params[p]}"<#if p_has_next>,</#if>
|
||||
</#if>
|
||||
</#list>
|
||||
}
|
||||
</#if>
|
||||
</#list>
|
||||
}]<#if key_has_next>,</#if>
|
||||
<#else>
|
||||
<#if field[key]?starts_with("[")>
|
||||
"${key}" : ${field[key]}<#if key_has_next>,</#if>
|
||||
<#else>
|
||||
"${key}" : "${field[key]}"<#if key_has_next>,</#if>
|
||||
</#if>
|
||||
</#if>
|
||||
</#list>
|
||||
}<#if field_has_next>,</#if>
|
||||
</#list>
|
||||
]
|
||||
},
|
||||
"formData" :
|
||||
{
|
||||
<#list form.data.formData?keys as k>
|
||||
<#if form.data.formData[k]?is_boolean>
|
||||
<#-- Render boolean data without the surrounding inverted commas -->
|
||||
"${k}" : ${form.data.formData[k]?string}<#if k_has_next>,</#if>
|
||||
<#elseif form.data.formData[k]?is_number>
|
||||
<#-- Render number data without the surrounding inverted commas and no formatting -->
|
||||
"${k}" : ${form.data.formData[k]?c}<#if k_has_next>,</#if>
|
||||
<#else>
|
||||
<#-- All other data rendered with inverted commas -->
|
||||
"${k}" : "${form.data.formData[k]}"<#if k_has_next>,</#if>
|
||||
</#if>
|
||||
</#list>
|
||||
}
|
||||
}
|
||||
}
|
||||
</#escape>
|
||||
</#macro>
|
@@ -1,2 +0,0 @@
|
||||
<#import "definition.lib.ftl" as formDefLib/>
|
||||
<@formDefLib.formDefJSON form=form/>
|
@@ -25,7 +25,7 @@ function main()
|
||||
var repoFormData = new Packages.org.alfresco.repo.forms.FormData();
|
||||
for (var i = 0; i < formdata.fields.length; i++)
|
||||
{
|
||||
repoFormData.addData(formdata.fields[i].name, formdata.fields[i].value);
|
||||
repoFormData.addFieldData(formdata.fields[i].name, formdata.fields[i].value);
|
||||
}
|
||||
|
||||
formService.saveForm(itemKind, itemId, repoFormData);
|
||||
|
@@ -32,7 +32,7 @@ function main()
|
||||
for ( ; jsonKeys.hasNext(); )
|
||||
{
|
||||
var nextKey = jsonKeys.next();
|
||||
repoFormData.addData(nextKey, json.get(nextKey));
|
||||
repoFormData.addFieldData(nextKey, json.get(nextKey));
|
||||
}
|
||||
|
||||
try
|
||||
|
@@ -0,0 +1,76 @@
|
||||
<#macro formDefJSON form>
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
{
|
||||
"data" :
|
||||
{
|
||||
"item" : "${form.item}",
|
||||
"submissionUrl" : "${form.submissionUrl}",
|
||||
"type" : "${form.type}",
|
||||
"definition" :
|
||||
{
|
||||
"fields" :
|
||||
[
|
||||
<#list form.fields as field>
|
||||
{
|
||||
"name" : "${field.name}",
|
||||
"label" : "${field.label}",
|
||||
<#if field.description??>"description" : "${field.description}",</#if>
|
||||
"protectedField" : ${field.protectedField?string},
|
||||
<#if field.defaultValue??>"defaultValue" : "${field.defaultValue}",</#if>
|
||||
<#if field.group??>"group" : "${field.group}",</#if>
|
||||
<#if field.binding??>"binding" : "${field.binding}",</#if>
|
||||
"dataKeyName" : "${field.dataKeyName}",
|
||||
<#if field.dataType??>
|
||||
"type" : "property",
|
||||
"dataType" : "${field.dataType}",
|
||||
<#if field.dataTypeParameters??>"dataTypeParameters" :
|
||||
${field.dataTypeParameters},</#if>
|
||||
<#if field.constraints??>"constraints" :
|
||||
[{
|
||||
<#list field.constraints as cnstrnt>
|
||||
"type" : "${cnstrnt.type}"<#if cnstrnt.params??>,
|
||||
"params" :
|
||||
{
|
||||
<#list cnstrnt.params?keys as p>
|
||||
<#if cnstrnt.params[p]?is_boolean>
|
||||
"${p}" : ${cnstrnt.params[p]}<#if p_has_next>,</#if>
|
||||
<#else>
|
||||
"${p}" : "${cnstrnt.params[p]}"<#if p_has_next>,</#if>
|
||||
</#if>
|
||||
</#list>
|
||||
}
|
||||
</#if>
|
||||
</#list>
|
||||
}],</#if>
|
||||
"mandatory" : ${field.mandatory?string},
|
||||
"repeating" : ${field.repeating?string}
|
||||
<#else>
|
||||
"type" : "association",
|
||||
"endpointType" : "${field.endpointType}",
|
||||
"endpointDirection" : "${field.endpointDirection}",
|
||||
"endpointMandatory" : ${field.endpointMandatory?string},
|
||||
"endpointMany" : ${field.endpointMany?string}
|
||||
</#if>
|
||||
}<#if field_has_next>,</#if>
|
||||
</#list>
|
||||
]
|
||||
},
|
||||
"formData" :
|
||||
{
|
||||
<#list form.formData?keys as k>
|
||||
<#if form.formData[k]?is_boolean>
|
||||
<#-- Render boolean data without the surrounding inverted commas -->
|
||||
"${k}" : ${form.formData[k]?string}<#if k_has_next>,</#if>
|
||||
<#elseif form.formData[k]?is_number>
|
||||
<#-- Render number data without the surrounding inverted commas and no formatting -->
|
||||
"${k}" : ${form.formData[k]?c}<#if k_has_next>,</#if>
|
||||
<#else>
|
||||
<#-- All other data rendered with inverted commas -->
|
||||
"${k}" : "${form.formData[k]}"<#if k_has_next>,</#if>
|
||||
</#if>
|
||||
</#list>
|
||||
}
|
||||
}
|
||||
}
|
||||
</#escape>
|
||||
</#macro>
|
@@ -0,0 +1,2 @@
|
||||
<#import "formdefinition.lib.ftl" as formDefLib/>
|
||||
<@formDefLib.formDefJSON form=form/>
|
@@ -91,70 +91,42 @@ function main()
|
||||
return;
|
||||
}
|
||||
|
||||
var formModel = {};
|
||||
formModel.data = {};
|
||||
|
||||
formModel.data.item = formScriptObj.itemUrl;
|
||||
formModel.data.type = formScriptObj.itemType;
|
||||
formModel.data.submissionUrl = formScriptObj.submissionUrl;
|
||||
if (formScriptObj.submissionUrl === null)
|
||||
// ensure there is a submission url
|
||||
var submissionUrl = formScriptObj.submissionUrl;
|
||||
if (submissionUrl === null)
|
||||
{
|
||||
formModel.data.submissionUrl = '/api/' + itemKind + '/' + itemId + '/formprocessor';
|
||||
submissionUrl = '/api/' + itemKind + '/' + itemId + '/formprocessor';
|
||||
}
|
||||
|
||||
formModel.data.definition = {};
|
||||
formModel.data.definition.fields = [];
|
||||
|
||||
// We're explicitly listing the object fields of FieldDefinition.java and its subclasses here.
|
||||
// I don't see a way to get these dynamically at runtime.
|
||||
var supportedBaseFieldNames = ['name', 'label', 'description', 'binding',
|
||||
'defaultValue', 'dataKeyName', 'group', 'protectedField'];
|
||||
var supportedPropertyFieldNames = ['dataType', 'dataTypeParameters', 'mandatory',
|
||||
'repeating', 'constraints'];
|
||||
var supportedAssociationFieldNames = ['endpointType', 'endpointDirection',
|
||||
'endpointMandatory', 'endpointMany'];
|
||||
|
||||
var allSupportedFieldNames = supportedBaseFieldNames
|
||||
.concat(supportedPropertyFieldNames)
|
||||
.concat(supportedAssociationFieldNames);
|
||||
|
||||
var fieldDefs = formScriptObj.fieldDefinitions;
|
||||
for (var x = 0; x < fieldDefs.length; x++)
|
||||
// create form model
|
||||
var formModel =
|
||||
{
|
||||
var fieldDef = fieldDefs[x];
|
||||
var field = {};
|
||||
item : formScriptObj.itemUrl,
|
||||
submissionUrl: submissionUrl,
|
||||
type : formScriptObj.itemType,
|
||||
fields : formScriptObj.fieldDefinitions,
|
||||
formData : {}
|
||||
};
|
||||
|
||||
for (var i = 0; i < allSupportedFieldNames.length; i++)
|
||||
{
|
||||
var nextSupportedName = allSupportedFieldNames[i];
|
||||
var nextValue = fieldDef[nextSupportedName];
|
||||
|
||||
if (nextValue != null)
|
||||
{
|
||||
field[nextSupportedName] = nextValue;
|
||||
}
|
||||
}
|
||||
|
||||
field.type = (fieldDef.dataType != null) ? "property" : "association";
|
||||
formModel.data.definition.fields.push(field);
|
||||
}
|
||||
|
||||
formModel.data.formData = {};
|
||||
// populate the form data model
|
||||
for (var k in formScriptObj.formData.data)
|
||||
{
|
||||
var value = formScriptObj.formData.data[k].value;
|
||||
|
||||
if (value instanceof java.util.Date)
|
||||
{
|
||||
formModel.data.formData[k] = utils.toISO8601(value);
|
||||
formModel.formData[k] = utils.toISO8601(value);
|
||||
}
|
||||
// There is no need to handle java.util.List instances here as they are
|
||||
// returned from ScriptFormData.java as Strings
|
||||
else
|
||||
{
|
||||
formModel.data.formData[k] = value;
|
||||
formModel.formData[k] = value;
|
||||
}
|
||||
}
|
||||
|
||||
if (logger.isLoggingEnabled())
|
||||
logger.log("formModel = " + jsonUtils.toJSONString(formModel));
|
||||
|
||||
model.form = formModel;
|
||||
}
|
Reference in New Issue
Block a user