cancel
Showing results for 
Search instead for 
Did you mean: 

Calling forms from dashlets?

zbennett
Champ in-the-making
Champ in-the-making
Hi all,

My end-goal is to create a dashlet that displays certain sites in a hierarchy through the use of custom aspects.  My partner is working on the dashlet's appearance, while I'm creating and managing the custom aspects.  So far we're doing pretty well - the dashlet is well underway and I have a decent grasp on creating custom aspects.  I'm having a really difficult time understanding the Forms Engine, though.

I have a lot more to learn before I start creating custom forms, but in the meantime, we want to make our dashlet display a form that already exists.  For example, I'm trying to create a proof of concept that will display the doclib-simple-metadata form for a hard-coded node when the user clicks a button in the dashlet.

The Firebug console shows the following when I click Edit Metadata on a particular folder in the document library:
GET http://192.168.100.38/share/service/components/form?itemKind=node&itemId=workspace://SpacesStore/525...

Any input would be most appreciated!  Right now I'm just stabbing around in the dark and hoping that I hit something!

PS - I'm willing to change my proof of concept if anyone has suggestions.  I just want a working example of a dashlet that displays a form, in a modal pop-up window, using the Forms Engine.
13 REPLIES 13

Yes I include it.
The probleme is this internal error in "simple-dialog.js", and I need to be sure if my js is correct and able to display my popUp.
The most examples I see build the form from "doBeforeFormValidation" method, but I want to build it from my calling templateUrl.
Thanks,

zbennett
Champ in-the-making
Champ in-the-making
So I've been playing around with forms that already exist, such as doclib-common and doclib-simple-metadata.  I can display these forms in the simple-dialog from my dashlet, but I keep getting a nasty error when I try to display a custom form.

My project has changed a little bit - now I'm just trying to create folders in the Data Dictionary with custom properties. To account for the custom properties, I created a model type called eagleSmiley Tongueroject, with a parent type of cm:folder.  Whenever I try to display a form to create a new eagleSmiley Tongueroject node, I get the following error:
Internal Form Error: form with id of 'page_x002e_component-2-1_x002e_user_x007e_zbennett_x007e_dashboard-myDialog-form' could not be located, ensure the form is created after the form element is available.
I can't figure out what is causing the error - my code works fine when I set itemId to "cm:folder" instead of "eagleSmiley Tongueroject".

My code:

   // Test Code
   function runTest()
   {   
      
      var destination = "workspace://SpacesStore/7373e717-212e-4bf7-979f-3680f7c52b53";
      
      // Intercept before dialog show - not functional yet!
      var doBeforeDialogShow = function my_doBeforeDialogShow(p_form, p_dialog)
      {
         Alfresco.util.populateHTML(
            [ p_dialog.id + "-dialogHeader", "My Header" ]
         );
      };
      
      var templateUrl = YAHOO.lang.substitute(Alfresco.constants.URL_SERVICECONTEXT + "components/form?itemKind={itemKind}&itemId={itemId}&destination={destination}&mode={mode}&submitType={submitType}&showCancelButton=true",
      {
         itemKind: "type",
         itemId: "eagle:project",
         //itemId: "cm:folder",
         destination: destination,
         mode: "create",
         submitType: "json"
      });
      
      // Using Forms Service, so always create new instance
      var myDialog = new Alfresco.module.SimpleDialog("${args.htmlid}-myDialog");
      
      myDialog.setOptions(
      {
         width: "40em",
         templateUrl: templateUrl,
         actionUrl: null,
         destroyOnHide: true,
         doBeforeDialogShow:
         {
            fn: doBeforeDialogShow,
            scope: this
         },
         onSuccess:
         {
            fn: function myDialog_success(response)
            {
               Alfresco.util.PopupManager.displayMessage(
               {
                  text: "Success!"
               });
            },
            scope: this
         },
         onFailure:
         {
            fn: function myDialog_failure(response)
            {
               if (response)
               {
                  Alfresco.util.PopupManager.displayMessage(
                  {
                     text: "Failed to complete task."
                  });
               }
               else
               {
                  Alfresco.util.PopupManager.displayMessage(
                  {
                     text: "Failed to communicate with server…or something"
                  });
               }
            },
            scope: this
         }
      }).show();
   

Like I said, if I comment 'itemId: "eagleSmiley Tongueroject",' and uncomment '//itemId: "cm:folder",' then the form displays just fine, but for a new cm:folder instead of a new eagleSmiley Tongueroject (obviously).

For my custom model-type, I created eagle-model.xml and eagle-model-context.xml, and I added the form configuration to share-config-custom.xml. My definitions are as follows.

eagle-model.xml
<?xml version="1.0" encoding="UTF-8"?>

<model name="eagle:hiearchy" xmlns="http://www.alfresco.org/model/dictionary/1.0">
   
   <description>Eagle Hierarchy</description>
   <author>Zach Bennett</author>
   <version>1.0</version>

   <!– Imports are required to allow references to definitions in other models –>
   <imports>
        <!– Import Alfresco Dictionary Definitions –>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <!– Import Alfresco Content Domain Model Definitions –>
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
   </imports>
  
   <namespaces>
      <namespace uri="eagle.hiearchy" prefix="eagle"/>
   </namespaces>

   <!– Type and Aspect definitions go here –>
   <types>
      <type name="eagle:project">
         <title>Eagle Project Folder</title>
         <parent>cm:folder</parent>
         <properties>
            <property name="cm:name">
               <type>d:text</type>
            </property>
            <property name="cm:title">
               <type>d:text</type>
            </property>
            <property name="cm:description">
               <type>d:text</type>
            </property>
            <property name="eagle:status">
               <type>d:text</type>
            </property>
            <property name="eagle:projectorid">
               <type>d:text</type>
            </property>
            <property name="eagle:startDate">
               <type>d:datetime</type>
            </property>
            <property name="eagle:endDate">
               <type>d:datetime</type>
            </property>
         </properties>
      </type>
    </types>

</model>

eagle-model-context.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

    <!– Registration of new models –>
    <bean id="extension.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
        <property name="models">
            <list>
                <value>alfresco/extension/eagle-model.xml</value>
            </list>
        </property>
    </bean>

</beans>

and finally, my form configuration in share-config-custom.xml
   <!– eagle:project type (creating nodes) –>
   <config evaluator="model-type" condition="eagle:project">
      <forms>
         <!– Document Library Common form –>
         <form>
            <field-visibility>
               <show id="cm:name" />
               <show id="cm:title" force="true" />
               <show id="cm:description" force="true" />
               <show id="eagle:status" />
               <show id="eagle:projectorid" />
               <show id="eagle:startDate" />
               <show id="eagle:endDate" />
            </field-visibility>
            <appearance>
               <field id="cm:title">
                  <control template="/org/alfresco/components/form/controls/textfield.ftl" />
               </field>
               <field id="cm:name">
                  <control template="/org/alfresco/components/form/controls/textfield.ftl" />
               </field>
               <field id="cm:description">
                  <control template="/org/alfresco/components/form/controls/textarea.ftl" />
               </field>
               <field id="eagle:status">
                  <control template="/org/alfresco/components/form/controls/textfield.ftl" />
               </field>
               <field id="eagle:projectorid">
                  <control template="/org/alfresco/components/form/controls/textfield.ftl" />
               </field>
               <field id="eagle:startDate">
                  <control template="/org/alfresco/components/form/controls/date.ftl" />
               </field>
               <field id="eagle:endDate">
                  <control template="/org/alfresco/components/form/controls/date.ftl" />
               </field>
            </appearance>
         </form>
      </forms>
   </config>

Any thoughts on what is preventing my dialog element from being created?

zbennett
Champ in-the-making
Champ in-the-making
I just found a lovely error in my logs that could shine some light on this, but I'm still trying to figure out what to do about it.

ERROR [scripts.forms.FormUIGet] org.alfresco.service.namespace.NamespaceException: Namespace prefix eagle is not mapped to a namespace URI

I suspect that mapping the "eagle" prefix to a namespace URI will be a step in the right direction. I'm off to discover how to do that right now!

taiko3615
Champ in-the-making
Champ in-the-making
Hi zbennett 🙂

Do you have a working example of your first proof of concept? (because I want to do something similar)

Thanks !