Ian
Ian

Reputation: 466

Form in dashlet query

I have been trying to get a form in an Aukai dashlet to work for over a week now. It was realativly easy to get it to appear on the dashboard but nothing I have done has resulted in any this being sent to the server!

Has anyone or know of anyone that has a form fully working in a Dashlet?

Mine will not read from the OPtionsService (does not fill the dropdown of a select) nor post to any topic on submit, just sits there and does nothing. I can see the events in the debug window but on chrome and firefox debug view there is no network activity and server does nothing.

dashlet get js

model.jsonModel = {
    rootNodeId: args.htmlid,
    pubSubScope: instance.object.id,
    bodyHeight: "400px",
    services: [
        {   name: "alfresco/services/LoggingService",
            config: {
                loggingPreferences:{
                    enabled: true,
                    all: true
                }
            }
        },
        "alfresco/services/OptionsService"
    ],
    widgets: [
        {
            name: "alfresco/dashlets/Dashlet",
            config: {
                title: "My Messages",
                bodyHeight: args.height || null,
                componentId: instance.object.id,
                widgetsForTitleBarActions: [
                    {
                        id: "MESSAGING_DASHLET_ACTIONS",
                        name: "alfresco/html/Label",
                        config: {
                            label: "Title-bar actions"
                        }
                    }
                ],
                widgetsForToolbar: [
                    {
                        id: "MESSAGING_DASHLET_TOOLBAR",
                        name: "alfresco/html/Label",
                        config: {
                            label: "Toolbar"
                        }
                    }
                ],
                widgetsForBody: [
                    {
                        id: "HELLO_DASHLET_VERTICAL_LAYOUT",
                        name: "alfresco/layout/VerticalWidgets",
                        config: {
                            widgetWidth: "350px",
                            widgets: [
                                { name: "alfresco/forms/Form",
                                    config: {
                                        showOkButton: true,
                                        okButtonLabel: "Send",
                                        showCancelButton: false,
                                        okButtonPublishTopic: "PUBLISH_TOPIC_MESSAGE",
                                        okButtonPublishGlobal: true,
                                        widgets: [{
                                            name: "alfresco/forms/controls/TinyMCE",
                                            config: {
                                                fieldId: "MESSAGE_TEXT",
                                                name: "message",
                                                label: "Message",
                                                widgetWidth: 200
                                            }
                                        },
                                        {
                                            name: "alfresco/forms/controls/Select",
                                            config: {
                                                fieldId: "RECIPENT",
                                                name: "recipient",
                                                label: "Send to",
                                                optionsConfig:{
                                                    publishTopic: "ALF_GET_FORM_CONTROL_OPTIONS",
                                                    publishPayload: {
                                                        url: url.context + "/proxy/alfresco/api/people",
                                                        itemsAttribute: "people",
                                                        labelAttribute: "firstName",
                                                        valueAttribute: "userName"
                                                    }
                                                }
                                           }
                                        }]
                                    }
                                }
                            ]
                        }
                    },
                    {
                        name: "alfresco/logging/DebugLog",
                    }
                ]
            }
        }
    ]
};

dashlet get html ftl

<@markup id="widgets">
    <@processJsonModel group="share-dashlets" rootModule="alfresco/core/Page"/>
</@>

<@markup id="html">
<div id="${args.htmlid?html}"></div>
</@>

dashlet get desc xml

<webscript>
    <shortname>Dashlet</shortname>
    <description>An Aikau dashlet</description>
    <family>dashlet</family>
    <url>/dashlets/messaging</url>
</webscript>

Upvotes: 0

Views: 160

Answers (1)

I slightly modified your code to fetch the users and displaying ina dropdown. Let me try with Option Service and will update you. Created a new function getUserList and called /api/people to get the data and displayed in the dropdown.

Hope this helps you now.

enter image description here

model.jsonModel = {
    rootNodeId: args.htmlid,
    pubSubScope: instance.object.id,
    bodyHeight: "400px",
    services: [
        {   name: "alfresco/services/LoggingService",
            config: {
                loggingPreferences:{
                    enabled: false,
                    all: true
                }
            }
        },
        "alfresco/services/OptionsService"
    ],
    widgets: [
        {
            name: "alfresco/dashlets/Dashlet",
            config: {
                title: "My Messages",
                bodyHeight: args.height || null,
                componentId: instance.object.id,
                widgetsForTitleBarActions: [
                    {
                        id: "MESSAGING_DASHLET_ACTIONS",
                        name: "alfresco/html/Label",
                        config: {
                            label: "Title-bar actions"
                        }
                    }
                ],
                widgetsForToolbar: [
                    {
                        id: "MESSAGING_DASHLET_TOOLBAR",
                        name: "alfresco/html/Label",
                        config: {
                            label: "Toolbar"
                        }
                    }
                ],
                widgetsForBody: [
                    {
                        id: "HELLO_DASHLET_VERTICAL_LAYOUT",
                        name: "alfresco/layout/VerticalWidgets",
                        config: {
                            widgetWidth: "350px",
                            widgets: [
                                { name: "alfresco/forms/Form",
                                    config: {
                                        showOkButton: true,
                                        okButtonLabel: "Send",
                                        showCancelButton: false,
                                        okButtonPublishTopic: "PUBLISH_TOPIC_MESSAGE",
                                        okButtonPublishGlobal: true,
                                        widgets: [{
                                            name: "alfresco/forms/controls/TinyMCE",
                                            config: {
                                                fieldId: "MESSAGE_TEXT",
                                                name: "message",
                                                label: "Message",
                                                widgetWidth: 200
                                            }
                                        },                                        
                                        {
                                            name: "alfresco/forms/controls/Select",
                                            config: {                                                
                                                fieldId: "RECIPENT",
                                                name: "recipient",
                                                label: "Send to",
                                                optionsConfig: {
                                                    fixed: getUsersList()
                                                },
                                                requirementConfig: {
                                                    initialValue: true
                                                }
                                            }
                                        }

                                        ]
                                    }
                                }
                            ]
                        }
                    },
                    {
                        name: "alfresco/logging/DebugLog",
                    }
                ]
            }
        }
    ]
};

function getUsersList() {
    try {
        var result = remote.call("/api/people?sortBy=fullName&dir=asc");
        var userList = [];
        if (result.status == status.STATUS_OK) {
            var rawData = JSON.parse(result);
            if (rawData && rawData.people) {
                var dummyPerson = {
                    label: "Select Recipient",
                    value: " ",
                    selected: true
                };
                userList.push(dummyPerson);
                for (var x = 0; x < rawData.people.length; x++) {
                    var item = rawData.people[x];
                    if (item.firstName != null && item.firstName != "" && item.userName.indexOf("@") == -1 && item.enabled == true) {
                        var displayName = item.firstName + " " + item.lastName;
                        var person = {
                            label: displayName,
                            value: item.userName
                        };
                        userList.push(person);
                    }
                }
            }
        } else {
            throw new Error("Unable to fetch User List " + result.status);
        }
        return userList;
    } catch(err) {
        throw new Error(err);
    }
}

Upvotes: 1

Related Questions