Sorry for the question formulation, didn't really know how to explain my problem simply.
I created a plugin for the Redmine platform where the user can synchronise his Dropbox account with the documents tab on Redmine, everything is working fine but I have a little problem.
When the user click on the synchronise
link, I would like to display a little message in my view to notify him that the work has started. Moreover, it would be great if a little popup shows up to let the user choose if he really wants to do the synchronisation because it might take a while.
I tried a few things:
First, I wrote my link_to
like this:
<%= link_to 'Synchronise', {:controller => "projectusers", :action => "dropbox_sync", :id => p, :project_id => @project.identifier}, :class => "icon icon-reload", :confirm => "Are you sure you want to .. bla bla" %>
This is great but I do not know how to display a message in my view directly after the user accepts the synchronisation, is there a way to do that?
Second, I used some Javascript. I wrote a little script like this at the beginning of my view:
<script>
function displayMessage()
{
alert("Sync is about to start blabla);
$('#syncStarted').show();
}
</script>
Then a little hidden paragraph:
<p id="syncStarted", style="display:none"><strong><font color="green">Synchronisation has started, please wait...</font></strong></p>
And I call my function like this:
<%= link_to 'Synchronise', {:controller => "projectusers", :action => "dropbox_sync", :id => p, :project_id => @project.identifier}, :class => "icon icon-reload", :onclick => "displayMessage()" %>
I know this is not a really good Ruby/Rails way to implement JS and that my html is pretty obsolete (CSS would be much better), but it's working pretty well. The only problem with this is that the user has no choice, if he clicks on the link, the sync will start even if he closes the popup by clicking the cross.
Maybe could you help me to find the better way to do that, I think the use of the :confirm
parameter is better but I could not find how to add a little notification on my page after the user confirms the action.
I'm working with Rails v3.2.16.
Thanks