Skip to content

Commit

Permalink
Controls for default value & parent
Browse files Browse the repository at this point in the history
  • Loading branch information
angelborroy-ks committed Oct 18, 2017
1 parent bd5f7d3 commit 50b11cf
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 10 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Fixed deployment of web resources in the file-mapping.properties

## Version 3.0.0

AMP artifacts ready-to-deploy available at [3.0.0](https://github.com/keensoft/alfresco-datalist-constraints/releases/tag/3.0.0)
AMP artifacts ready-to-deploy available at [3.1.0](https://github.com/keensoft/alfresco-datalist-constraints/releases/tag/3.1.0)

It can be defined the same DataList ID to be applied locally inside a Site, overriding global `Dictionary` datalist values. When using for advanced search, new `search` parameter has been added for FTL control in order to mix all values from local sites and `Dictionary` sites.

Expand All @@ -80,3 +80,7 @@ From Sample 2 Site > Values = 1,2
```

>> Sample custom model and Share form definition are being provided at folder `datalist-sample`
## Version 3.1.0

Added controls for default value and parent selection
2 changes: 1 addition & 1 deletion datalist-model-repo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>es.keensoft</groupId>
<artifactId>datalist-model-repo</artifactId>
<version>3.0.0</version>
<version>3.1.0</version>
<name>datalist-model-repo Repository AMP project</name>
<packaging>amp</packaging>
<description>Manages the lifecycle of the site-props-repo Repository AMP (Alfresco Module Package)</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,34 @@ public void execute(WebScriptRequest request, WebScriptResponse response) throws
String targetedDataListName = request.getExtensionPath();

// 1. search = sites + dictionary
// 2. siteId = if exists(site) ? site : dictionary
// 3. ...... = dictionary
// 2. nodeRef = site (if belongs to one)
// 3. siteId = if exists(site) ? site : dictionary
// 4. ...... = dictionary

List<SiteInfo> sites = new ArrayList<SiteInfo>();

String search = request.getParameter("search");
String siteId = request.getParameter("siteId");
String nodeRef = request.getParameter("nodeRef");

if (search != null && search.toLowerCase().equals("true")) {

sites.addAll(getSitesDataList(targetedDataListName));

} else {
String siteId = request.getParameter("siteId");

if (nodeRef != null) {
SiteInfo siteInfo = siteService.getSite(new NodeRef(nodeRef));
if (siteInfo != null) {
siteId = siteInfo.getShortName();
}
}
if (siteId != null && existsDatalist(siteId, targetedDataListName)) {
sites.add(siteService.getSite(siteId));
} else {
sites = siteService.listSites(null, DATALIST_PRESET);
}

}

JSONArray objProcess = new JSONArray();
Expand All @@ -72,7 +86,7 @@ public void execute(WebScriptRequest request, WebScriptResponse response) throws
Map<String, String> values = new HashMap<String, String>();

for (SiteInfo site : sites) {

NodeRef dataListContainer = SiteServiceImpl.getSiteContainer(site.getShortName(), DATALIST_CONTAINER_ID, true, siteService, transactionService, taggingService);
List<ChildAssociationRef> dataListsNodes = nodeService.getChildAssocs(dataListContainer);

Expand Down Expand Up @@ -115,9 +129,9 @@ public void execute(WebScriptRequest request, WebScriptResponse response) throws
Map<String, String> sortedValues = sortByComparator(values);
for (Map.Entry<String, String> entry : sortedValues.entrySet()) {
JSONObject obj = new JSONObject();
obj.put(JSON_CODE, entry.getKey());
obj.put(JSON_VALUE, entry.getValue());
objProcess.put(obj);
obj.put(JSON_CODE, entry.getKey());
obj.put(JSON_VALUE, entry.getValue());
objProcess.put(obj);
}
}

Expand Down
2 changes: 1 addition & 1 deletion datalist-model-share/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>es.keensoft</groupId>
<artifactId>datalist-model-share</artifactId>
<version>3.0.0</version>
<version>3.1.0</version>
<name>site-props-share AMP project</name>
<packaging>amp</packaging>
<description>Manages the lifecycle of the site-props-share AMP (Alfresco Module Package)</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<#include "/org/alfresco/components/form/controls/common/utils.inc.ftl" />

<#if field.control.params.optionSeparator??>
<#assign optionSeparator=field.control.params.optionSeparator>
<#else>
<#assign optionSeparator=",">
</#if>
<#if field.control.params.labelSeparator??>
<#assign labelSeparator=field.control.params.labelSeparator>
<#else>
<#assign labelSeparator="|">
</#if>

<#assign fieldValue=field.value>

<#if fieldValue?string == "" && field.control.params.defaultValueContextProperty??>
<#if context.properties[field.control.params.defaultValueContextProperty]??>
<#assign fieldValue = context.properties[field.control.params.defaultValueContextProperty]>
<#elseif args[field.control.params.defaultValueContextProperty]??>
<#assign fieldValue = args[field.control.params.defaultValueContextProperty]>
</#if>
</#if>

<#if field.control.params.defaultValue??>
<#assign defaultValue=field.control.params.defaultValue>
</#if>

<div class="form-field">
<#if form.mode == "view">
<div class="viewmode-field">
<#if field.mandatory && !(fieldValue?is_number) && fieldValue?string == "">
<span class="incomplete-warning"><img src="${url.context}/res/components/form/images/warning-16.png" title="${msg("form.field.incomplete")}" /><span>
</#if>
<span class="viewmode-label">${field.label?html}:</span>
<#if fieldValue?string == "">
<#assign valueToShow=msg("form.control.novalue")>
<#else>
<#assign valueToShow=fieldValue>
<#if field.control.params.options?? && field.control.params.options != "">
<#list field.control.params.options?split(optionSeparator) as nameValue>
<#if nameValue?index_of(labelSeparator) == -1>
<#if nameValue == fieldValue?string || (fieldValue?is_number && fieldValue?c == nameValue)>
<#assign valueToShow=nameValue>
<#break>
</#if>
<#else>
<#assign choice=nameValue?split(labelSeparator)>
<#if choice[0] == fieldValue?string || (fieldValue?is_number && fieldValue?c == choice[0])>
<#assign valueToShow=msgValue(choice[1])>
<#break>
</#if>
</#if>
</#list>
</#if>
</#if>
<span class="viewmode-value">${valueToShow?html}</span>
</div>
<#else>
<label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
<select id="${fieldHtmlId}" name="${field.name}" tabindex="0"
<#if field.description??>title="${field.description}"</#if>
<#if field.control.params.size??>size="${field.control.params.size}"</#if>
<#if field.control.params.styleClass??>class="${field.control.params.styleClass}"</#if>
<#if field.control.params.style??>style="${field.control.params.style}"</#if>
<#if field.disabled && !(field.control.params.forceEditable?? && field.control.params.forceEditable == "true")>disabled="true"</#if>>
</select>
</#if>
</div>

<script type="text/javascript">//<![CDATA[
YAHOO.util.Event.onContentReady("${fieldHtmlId}", function ()
{
<#if field.control.params.search?? && field.control.params.search == "true">
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?search=true&"+ (new Date().getTime());
<#elseif page?? && page.url.templateArgs.site??>
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?siteId=${page.url.templateArgs.site!""}&"+ (new Date().getTime());
<#elseif args?? && args.destination??>
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?nodeRef=${args.destination!""}&"+ (new Date().getTime());
<#elseif page?? && page.url.args.nodeRef??>
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?nodeRef=${page.url.args.nodeRef!""}&"+ (new Date().getTime());
<#else>
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?"+ (new Date().getTime());
</#if>
Alfresco.util.Ajax.jsonGet({
url: encodeURI(Alfresco.constants.PROXY_URI + linkTemplate),
successCallback:
{
fn: function loadWebscript_successCallback(response, config)
{
var obj = eval('(' + response.serverResponse.responseText + ')');
if (obj)
{
for (i = 0; i < obj.length; i++) {
var newOption = document.createElement('option');
newOption.value = obj[i].code;
newOption.text = obj[i].value;
YAHOO.util.Dom.get("${fieldHtmlId}").options.add(newOption);
if(obj[i].code == "${defaultValue?string}")
{
YAHOO.util.Dom.get("${fieldHtmlId}").options[i].selected = "selected";
}
}
}
}
}
});
}, this);
//]]></script>
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ function fillOptions${field.id}(selectId, value) {
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?search=true&"+ (new Date().getTime());
<#elseif page?? && page.url.templateArgs.site??>
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?siteId=${page.url.templateArgs.site!""}&"+ (new Date().getTime());
<#elseif args?? && args.destination??>
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?nodeRef=${args.destination!""}&"+ (new Date().getTime());
<#elseif page?? && page.url.args.nodeRef??>
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?nodeRef=${page.url.args.nodeRef!""}&"+ (new Date().getTime());
<#else>
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?"+ (new Date().getTime());
</#if>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<#include "/org/alfresco/components/form/controls/common/utils.inc.ftl" />

<#--
This control will hide the dependent controls injected via the
control parameters in the form config by hiding the div {field.name}-control
-->
<#assign hideProperties=field.control.params.hideProperties>


<#assign hideOnValue=field.control.params.hideOnValue>

<#if field.control.params.optionSeparator??>
<#assign optionSeparator=field.control.params.optionSeparator>
<#else>
<#assign optionSeparator=",">
</#if>
<#if field.control.params.labelSeparator??>
<#assign labelSeparator=field.control.params.labelSeparator>
<#else>
<#assign labelSeparator="|">
</#if>

<#assign fieldValue=field.value>

<#if fieldValue?string == "" && field.control.params.defaultValueContextProperty??>
<#if context.properties[field.control.params.defaultValueContextProperty]??>
<#assign fieldValue = context.properties[field.control.params.defaultValueContextProperty]>
<#elseif args[field.control.params.defaultValueContextProperty]??>
<#assign fieldValue = args[field.control.params.defaultValueContextProperty]>
</#if>
</#if>

<#if fieldValue?string == "${hideOnValue}">
<#assign hide=true>
<#else>
<#assign hide=false>
</#if>


<div class="form-field">
<#if form.mode == "view">
<div class="viewmode-field">
<#if field.mandatory && !(fieldValue?is_number) && fieldValue?string == "">
<span class="incomplete-warning"><img src="${url.context}/res/components/form/images/warning-16.png" title="${msg("form.field.incomplete")}" /><span>
</#if>
<span class="viewmode-label">${field.label?html}:</span>
<#if fieldValue?string == "">
<#assign valueToShow=msg("form.control.novalue")>
<#else>
<#assign valueToShow=fieldValue>
<#if field.control.params.options?? && field.control.params.options != "">
<#list field.control.params.options?split(optionSeparator) as nameValue>
<#if nameValue?index_of(labelSeparator) == -1>
<#if nameValue == fieldValue?string || (fieldValue?is_number && fieldValue?c == nameValue)>
<#assign valueToShow=nameValue>
<#break>
</#if>
<#else>
<#assign choice=nameValue?split(labelSeparator)>
<#if choice[0] == fieldValue?string || (fieldValue?is_number && fieldValue?c == choice[0])>
<#assign valueToShow=msgValue(choice[1])>
<#break>
</#if>
</#if>
</#list>
</#if>
</#if>
<span class="viewmode-value">${valueToShow?html}</span>
</div>
<#else>
<label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
<select id="${fieldHtmlId}" name="${field.name}" tabindex="0" onchange="checkValue()"
<#if field.description??>title="${field.description}"</#if>
<#if field.control.params.size??>size="${field.control.params.size}"</#if>
<#if field.control.params.styleClass??>class="${field.control.params.styleClass}"</#if>
<#if field.control.params.style??>style="${field.control.params.style}"</#if>
<#if field.disabled && !(field.control.params.forceEditable?? && field.control.params.forceEditable == "true")>disabled="true"</#if>>
</select>
<input id="${fieldHtmlId}-entry-tohide" type="hidden" name="-" value="${hideProperties}" />
</#if>
</div>

<script type="text/javascript">//<![CDATA[
YAHOO.util.Event.onContentReady("${fieldHtmlId}", function ()
{
<#if field.control.params.search?? && field.control.params.search == "true">
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?search=true&"+ (new Date().getTime());
<#elseif page?? && page.url.templateArgs.site??>
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?siteId=${page.url.templateArgs.site!""}&"+ (new Date().getTime());
<#elseif args?? && args.destination??>
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?nodeRef=${args.destination!""}&"+ (new Date().getTime());
<#elseif page?? && page.url.args.nodeRef??>
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?nodeRef=${page.url.args.nodeRef!""}&"+ (new Date().getTime());
<#else>
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?"+ (new Date().getTime());
</#if>
Alfresco.util.Ajax.jsonGet({
url: encodeURI(Alfresco.constants.PROXY_URI + linkTemplate),
successCallback:
{
fn: function loadWebscript_successCallback(response, config)
{
var obj = eval('(' + response.serverResponse.responseText + ')');
if (obj)
{
for (i = 0; i < obj.length; i++) {
var newOption = document.createElement('option');
newOption.value = obj[i].code;
newOption.text = obj[i].value;
YAHOO.util.Dom.get("${fieldHtmlId}").options.add(newOption);
}
// Current value
var sp = document.getElementById("${fieldHtmlId}");
sp.value = "${field.value}";
<#if hide>
ENIModel.Util.HideDependentControls("${fieldHtmlId}", "${args.htmlid}");
</#if>
}
}
}
});
}, this);
function checkValue() {
var value = document.getElementById("${fieldHtmlId}").value
if(value == "${hideOnValue}")
{
ENIModel.Util.HideDependentControls("${fieldHtmlId}", "${args.htmlid}");
}
else
{
ENIModel.Util.DisplayDependentControls("${fieldHtmlId}", "${args.htmlid}");
}
}
//]]></script>
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ YAHOO.util.Event.onContentReady("${fieldHtmlId}", function ()
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?search=true&"+ (new Date().getTime());
<#elseif page?? && page.url.templateArgs.site??>
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?siteId=${page.url.templateArgs.site!""}&"+ (new Date().getTime());
<#elseif args?? && args.destination??>
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?nodeRef=${args.destination!""}&"+ (new Date().getTime());
<#elseif page?? && page.url.args.nodeRef??>
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?nodeRef=${page.url.args.nodeRef!""}&"+ (new Date().getTime());
<#else>
var linkTemplate="/keensoft/datalist/${field.control.params.itemType}?"+ (new Date().getTime());
</#if>
Expand Down

0 comments on commit 50b11cf

Please sign in to comment.