how to add a form to a page in alfresco

I defined the form in the share-config-custom.xml configuration file and I have a home.ftl page. How can I associate a form definition in the configuration file with the home.ftl page?

Upvotes: 1

Views: 257

Answers (2)

Oussama Werfelli
Oussama Werfelli

Reputation: 513

You can retrieve configured form by the /components/form webscript, so you can use a javascript controller to inject your form in your page as mentioned in the previous answer by @vikash or you can use Spring surf to create the page, for that you can check Alfresco documentation Surf Pages.

In the definition page, make /components/form as url and url parameters as properties, as mentioned in the following example

<?xml version="1.0" encoding="UTF-8"?>
<component>
    <url>/components/form</url>
     <properties>
        <itemKind>type</itemKind>
        <itemId>contentType</itemId>
        <mode>edit</mode>
        <formUI>true</formUI>
        <submitType>json</submitType>
        <showCaption>true</showCaption>
        <showCancelButton>true</showCancelButton>
     </properties>
</component>

If you want to get a form for a configured type you should make type in itemKind and type name in itemId (cm:xxx)

Upvotes: 1

Vikash Patel
Vikash Patel

Reputation: 1348

You can open the share form using content-type To open form

function render(htmlPageId) {
var contentType = "content_type";
    var formHtmlId = htmlPageId+ "-metadata-form";
    var url = YAHOO.lang
            .substitute(
                    "{serviceContext}components/form"
                            + "?itemKind=type&itemId={itemId}&mode=create&submitType=json"
                            + "&formId={formId}&showCancelButton=true&htmlid={htmlid}"
                            + "&destination={destination}&siteId={siteId}&containerId={containerId}&uploadDirectory={uploadDirectory}",
                    {
                        serviceContext : Alfresco.constants.URL_SERVICECONTEXT,
                        itemId : contentType,
                        itemKind : "model",
                        formId : "upload-folder",
                        destination : "workspace://SpacesStore/e9d60c89-823a-4e3e-abb2-522e59a09d0f",
                        siteId : "production",
                        containerId : "documentLibrary",
                        uploadDirectory : "/GM",
                        htmlid : formHtmlId
                    });

    Alfresco.util.Ajax.request({
        url : url,
        responseContentType : "html",
        execScripts : true,
        successCallback : {
            fn : function(response) {
                var formNode = YAHOO.util.Dom.get(formHtmlId);
                formNode.innerHTML = response.serverResponse.responseText;

            },
            scope : this
        },
        failureCallback : {
            fn : function(response) {
                Alfresco.logger.debug("onContentTypeChange failureCallback",
                        arguments);
            },
            scope : this
        }
    });
}

Pass your content type here in - contentType which type of form you wanted to open.

and

var formNode = YAHOO.util.Dom.get(formHtmlId);
 formNode.innerHTML = response.serverResponse.responseText;

formHtmlId is the id of your html component like

<div id="${el}-renderForm" onload="render(htmlID)">
</div>

pass your current htmlId in this funtion.

Upvotes: 0

Related Questions