Search code examples
alfrescofreemarker

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?


Solution

  • 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.