03-13-2015 01:28 AM
03-16-2015 09:23 AM
03-16-2015 01:17 PM
03-17-2015 04:54 AM
You should make custom control for form field where you will call Alfresco webscript.
This webscript should return information that you want to display in section.
03-18-2015 07:03 AM
protected Map<String, Object> executeImpl(WebScriptRequest req,
Status status, Cache cache) {
String typeOfLibrary = req.getParameter("retrieve");
if (typeOfLibrary == null || "".equals(typeOfLibrary)) {
status.setCode(Status.STATUS_BAD_REQUEST);
status.setRedirect(true);
status.setMessage("Please provide typeofLibrary");
logger.debug("Please provide typeofLibrary");
return null;
}
else if (!("Product Library".equals(typeOfLibrary)) && !("Image Library".equals(typeOfLibrary))) {
status.setCode(Status.STATUS_BAD_REQUEST);
status.setRedirect(true);
status.setMessage("Please provide valid typeofLibrary");
logger.debug("Please provide valid typeofLibrary");
return null;
}
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
String queryStrings = "";
if (("Product Library".equals(typeOfLibrary))) {
queryStrings = "PATH:\"/app:company_home/st:sites/cm:retail-channels-product-management/cm:documentLibrary/cm:Product_x0020_Library/*\"";
}
else if(("Image Library".equals(typeOfLibrary))){
queryStrings = "PATH:\"/app:company_home/st:sites/cm:retail-channels-product-management/cm:documentLibrary/cm:Image_x0020_Library/*\"";
}
ResultSet rs1 = serviceRegistry.getSearchService().query(storeRef, SearchService.LANGUAGE_LUCENE, queryStrings);
Map<String, Object> model = new HashMap<>();
List<String> productLibraryList = new ArrayList<>();
try {
if(rs1 != null && rs1.length() != 0) {
FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
for (int i = 0; i < rs1.length(); i++) {
NodeRef rsNodeRef = rs1.getNodeRef(i);
String productTypeFolder = fileFolderService.getFileInfo(rsNodeRef).getName();
productLibraryList.add(productTypeFolder);
logger.info("The ProductTypeFolder Name is :"+productTypeFolder);
}
}
}
finally {
rs1.close();
}
if(!productLibraryList.isEmpty()){
model.put("isEmpty", false);
model.put("libraryList", productLibraryList);
}
else{
model.put("isEmpty", true);
model.put("libraryList", null);
}
return model;
}
<webscript>
<shortname>Retrieves the Library List of the type of library passed.</shortname>
<description>Retrieves the Library List of the type of library passed.</description>
<family>Harland Clarke WebScripts</family>
<url>/retrieve-library-list?retrieve={typeOfLibrary}</url>
<format default="json">extension</format>
<authentication>admin</authentication>
</webscript>
<#if isEmpty> []
<#else>
{"libraryList":{<#list libraryList as listItem>
"${listItem}"<#if listItem_has_next>,</#if>
</#list>}}
</#if>
<div class="form-field">
<script type="text/javascript">//<![CDATA[
YAHOO.util.Event.onAvailable("${fieldHtmlId}_assign", function(){
new selectAuthor("${fieldHtmlId}");
});
function selectAuthor(currentValueHtmlId) {
this.currentValueHtmlId = currentValueHtmlId;
var selectAuthors = Dom.get(this.currentValueHtmlId);
this.register = function () {
// Call webscript
Alfresco.util.Ajax.jsonGet({
url: "http://localhost:8080/alfresco/service/retrieve-library-list?retrieve=Product%20Library",
successCallback: {
fn: this.updateOptions,
scope: this
},
failureCallback: {
fn: function () {
},
scope: this
}
});
};
// Add options into <select>
this.updateOptions = function (res) {
var result = Alfresco.util.parseJSON(res.serverResponse.responseText);
if (result.libraryList.length > 0) {
var people = result.libraryList;
selectAuthors.options[selectAuthors.options.length] = new Option("", "", true, true);
for (var i in people) {
var option = new Option(people, people);
selectAuthors.options[selectAuthors.options.length] = option;
}
}
};
this.register();
}
//]]></script>
<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>
</div>
03-18-2015 07:51 AM
@Override
public void execute(WebScriptRequest req,
WebScriptResponse res) throws IOException {
String typeOfLibrary = req.getParameter("retrieve");
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
String queryStrings = "";
if (("Product Library".equals(typeOfLibrary))) {
queryStrings = "PATH:\"/app:company_home/st:sites/cm:retail-channels-product-management/cm:documentLibrary/cm:Product_x0020_Library/*\"";
}
else if(("Image Library".equals(typeOfLibrary))){
queryStrings = "PATH:\"/app:company_home/st:sites/cm:retail-channels-product-management/cm:documentLibrary/cm:Image_x0020_Library/*\"";
}
ResultSet rs1 = serviceRegistry.getSearchService().query(storeRef, SearchService.LANGUAGE_LUCENE, queryStrings);
List<String> productLibraryList = new ArrayList<>();
try {
if(rs1 != null && rs1.length() != 0) {
FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
for (int i = 0; i < rs1.length(); i++) {
NodeRef rsNodeRef = rs1.getNodeRef(i);
String productTypeFolder = fileFolderService.getFileInfo(rsNodeRef).getName();
productLibraryList.add(productTypeFolder);
logger.info("The ProductTypeFolder Name is :"+productTypeFolder);
}
}
}
finally {
rs1.close();
}
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("libraryList", productLibraryList);
} catch (JSONException e) {
logger.error("Error occured while creating Json Object."+e.getMessage());
}
String jsonString = jsonObject.toString();
res.getWriter().write(jsonString);
}
03-18-2015 08:11 AM
{
"libList":
[
"Banner Small",
"Banner Large"
]
}
<#if isEmpty> []
<#else>
{"libraryList":[
<#list libraryList as listItem>
"${listItem}"<#if listItem_has_next>,</#if>
</#list>
]
}
</#if>
03-18-2015 01:04 PM
{"libraryList":["Banner Small","Buiness Vertical","Banner Medium","Business Accessories","Banner Large"]}
03-19-2015 05:11 AM
03-17-2015 07:33 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.