Does Alfresco Share provide any mecanism for Inter Dashlet Communication? - share

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 ?

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.

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.

Related

Dynamically loading content through Groovy server page upon form submit

I have a Groovy project (vanilla; no Grails) with an index.gsp that takes form input from the user and sends it in a POST request to a Groovy script. The form is set up like this:
<form action="somewhere" method="POST" enctype="multipart/form-data">
// some other inputs
<input type="submit"/>
</form>
Is there any way (ideally not using Javascript) to dynamically load content on the same page after the user submits? Redirecting to another GSP might also work. Just something simple, like a string containing whatever the user typed. It seems like Grails has plenty of options, but unfortunately I can't use it.
As you mentioned, Grails is capable of doing what you need without any complex code. Since you can't use it, you will have to use JQuery(Javascript) to make an AJAX call. AJAX is the he only way that I know to achive that.
Just make an AJAX call to your groovy script. JQuery.ajax has a success function to be called if the request succeeds. You can use it to update a hidden dive after the form. This success function has the data returned from the server as an argument, that data could be the string containing whatever the user typed. In that case just add the data to the hidden div and then make that div visible.
function onSucceed(data) {
$('#hiddenDivToUpdate').text(data);
$('#hiddenDivToUpdate').show();
}
You can learn about JQuery.ajax() in this link AJAX

Call javascript function on AutoHotKet

I have requirement to send information to third party tool and fetch some information from this tool using autohotkey.
but i am facing informaiton into textbox and try to fire button click event .
I have used this code to fill the textbox and fire button click event but not able for fire this because textbox event not fired as mention in below code..
pwb.document.getElementsByTagName("input")["rio-search"].focus()
pwb.document.getElementsByTagName("input")["rio-search"].value := startelemnet
fullvalue :=pwb.document.getElementsByTagName("input")["rio-search"].value
Sleep, 500
pwb.document.getElementsByTagName("input")["rio-search"].value := fullvalue
pwb.document.getElementsByTagName("input")["rio-search"].focus()
wbs.document.parentWindow.showOptions()
wbs.document.parentWindow.execScript("showOptions()")
pwb.document.querySelector("button[type=submit]").Click()
but i am try to call the javascript mehtod on textbox focus in autohotkey but not able to call :
<input type="text" id="rio-search" ng-model="$root.keywords" ng-focus="showOptions()" ng-blur="hideOptions()" class="form-control ng-valid ng-touched ng-dirty ng-valid-parse" placeholder="Search">
Please provide me the solution for this.
Have you even defined pwb and wbs?
Since your website seems to use angularJS, make sure you wait until the site is actually completely generated.
Also, it is likely not a function, but a method of the angular $scope.
So your js code might have to look somewhat like this:
var scope = angular.element($("#outer")).scope();
scope.showOptions()
But the method might expect some kind of "this" or similar of the input element. So I have no idea if this would work.
You might also wanna check:
xx.document.InvokeScript("functionName");

Field and Form Validation with ember.js

I've integrated Boronine's excellent field validation code for ember.js from jsfiddle. While that is wonderful, I still need to perform form level validation, to ensure that when the user submits the form, everything is okay.
What's the best way to do that? Is there a way that I can mark a field as having been validated, so that the form handler can simply walk the fields to see what has been validated or not?
MP.SignUpFormView = Em.View.extend({
submitLogin:function (event) {
// walk through object fields to perform validation here, but how?!
}
});
Edit:
For clarity, I am using Handlebars and binding, not trying to walk DOM objects or the like.
The pattern you're trying to use makes sense in applications that follow a document-scripting pattern, which Ember does not. You can force this work, but you'll find each next step in the application will get harder and harder.
In Ember display is backed by data objects so form fields in an Ember application are bound to a property on some object and as changes are made, the values are updated immediately. You don't even really need a <form> except maybe for styling.
When a user wants to take some action on this object (like persisting it to a server) the application's current state will answer the question "what happens when a user wants to take this action right now?" A user clicking a button here doesn't mean "now serialize the data in the form and do something" it means "I'm done changing the properties of this object and would like to do something else in the application now."
Your handlebars template would look something like this:
{{view Ember.Textfield valueBinding="name"}}
{{view Ember.Textfield valueBinding="age"}}
<button {{action save content}}>Save</button>
And a possible state in your application where this can be handled
Ember.Route.extend({
save: function(router, event){
if (event.context.validate()){
router.transitionTo('someNewState')
}
}
})

How to add a contact form to a static web site?

I have a mostly "static" web site with no server-side code and just a little JavaScript. Now I would like to add a contact form. I do not care how I get the contact form data (so just writing this data to a text file in the server will be ok).
What is the simplest solution for this problem? How do people usually handle this?
I believe I can add some server-side code (PHP or something) to handle the form (and write the form data to a file, for instance) but I would prefer a client-side solution.
Use an external tool, they are commonly referred to as "formmailer". You basically submit the form to their server, and they send the form contents via mail to you.
If you don't want that, you have to do something server-sided: Storing data on the server, without having a server side program that accepts the data from the client, is just not possible.
You could install CouchDB and interface that from Javascript :) Everyone could use that then, too :)
The most easy PHP script that stores POST data on your harddisk:
<?php file_put_contents('/path/to/file', serialize($_POST) . "\n", FILE_APPEND); ?>
You can use Google Drive and create form with required fields. and embed code (which will be iframe) in your static web page.
You will be able to get submitted data in spreadsheet.
You can use qontacto . it is a free contact form you can add to any website. it forwards you the messages.
I set up the fwdform service for this exact need.
Just two simple steps to get your form forwarded to your email.
1.Register
Make an HTTP POST request to register your email.
$ curl --data "email=<your_email>" https://fwdform.herokuapp.com/register
Token: 780a8c9b-dc2d-4258-83af-4deefe446dee
2. Set up your form
<form action="https://fwdform.herokuapp.com/user/<token>" method="post">
Email: <input type="text" name="name"><br>
Name: <input type="text" name="email"><br>
Message: <textarea name="message" cols="40" rows="5"></textarea>
<input type="submit" value="Send Message">
</form>
With a couple of extra seconds you can spin up your own instance on Heroku.

How to clear the form when the user doesn't provide valid username/password

I designed a form as follows:
User Name: _______________
Password: _______________
Login
I also use jQuery Form Plugin to submit the form to the server side.
It will return if the server script finds some errors. The data returned by server is in JSON format. I would like to know how I can reset the user name + password when I know the username/password is invalid in a decent way.
In other words, I can manually use jQuery to empty the username/password field if the returned result indicates a failure. In fact, I am looking for a decent way built in Form Plugin or sth else that can do this part me for automatically. The only thing I have to do is to set a flag so that if the submission is failed, then the form will be resetted.
Thank you
You cam simply do:
$('#form_id').reset();
I don't think you need a plugin for such simple task. You simply call above code based on the response.
Run this.form.reset() when a form button (e.g. Reset) is being pressed.
e.g.
<form>
...
<input type="button" value="Reset!" onclick="this.form.reset();">
</form>