7

I am trying to figure out how to perform some inter dashlet communication with Alfresco Share. Here a simple use case:

We do have 2 dashlets, let's call them A and B. I want to be able to fill in a field "name" (let's say with value "Toto") in A and click on submit button. After clicking on submit button in A. B should be updated with greeting like " Good Morning Toto".

Thank you for you answers.

Thanks for your answer. Can you elaborate a bit regarding "let dashlet_b.get.html.ftl post something to dashlet_a.post.html.ftl" ?

In dashlet_b.get.html.ftl you have something like that I guess :

<form id="..." action="" method="POST">
     <input  id="name" type="text" name="name" value=""/>
     <input type="submit" id="send" value="Send" /></form>

When you submit the form it's gonna look for dashlet_b.post.js right ? How do you actually tell to send the form to dashlet_a.post.js ?

Karl Estop
  • 71
  • 3
  • Are you still looking for another answer? To answer your updated question for the target webscript:
    but this will only post data to the server and not update you dashlet A in the browser.
    – Florian Nov 29 '11 at 21:16

2 Answers2

7

To create these dynamic dashlets it is not enough to use the server side dashlet webscript. You need javascript logic in the browser to notify the other dashlet of changes. This is how Alfresco usually does that:

Browser Javascript Dashlet A:

YAHOO.Bubbling.fire("interDashletMessage",
{
    message: "Hello World."
});

Browser Javascript Dashlet B:

YAHOO.Bubbling.on("interDashletMessage", function(layer, args) {
    var message = args[1].message;
    alert(message); // or write it to the dashlets HTML content
});

This will send the message from dashlet A to dashlet B using a custom event called "interDashletMessage".

If your dashlet B only displays a few messages it could be enough to send the data over using the events. If it is more complex your dashlet A needs to post it's data to the repository first, then trigger the "refresh" event and have dashlet B refresh it's content from the repository. This will involve multiple webscripts you may need to write.

Florian
  • 1,281
  • 7
  • 17
0

That's quite simple I guess.

Each Dashlet is in fact a webscript. So you can have multiple webscript for different usage. Like I've got dashlet_a.get.html.ftl and dashlet_a.post.html.ftl. In fact these two are the same webscript, one just acts on a post and the other on get.

So what you could do, is let dashlet_b.get.html.ftl post something to dashlet_a.post.html.ftl. Hence you are submitting value(s) from b to a.

The next step is to refresh dashlet_a, one way is to do a full page refresh, but that's not nice. Whats better is the following: In dashlet_a.post.html.ftl you just set through YUI/JQuery the value of the field which is defined in dashlet_a.get.html.ftl.

Take a look how the default configurable dashlet do it, like the webview. If you put something in the config, the value directly is shown.

Tahir Malik
  • 6,623
  • 15
  • 22