Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Refresh a Gadget with onclick function

Ariel Rosa September 23, 2014

Hello guys,

I need a way to refresh the whole gadget with an onclick button on the gadget screen, is that even possible?

I tried things like:  <a onclick="gadget.showView(true);" class="refreshbutton">Refresh</a>

But got no results.

Are there any other functions I can use to solve that or any other ways to do it?

Thanks in advance. 

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Dmitry Miroshnichenko
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 24, 2014

Yes! You can try to use this code in gadgets\yourgadget.xml
You can see example sources on https://github.com/DmitryMiroshnichenko/jira-mailru-a1-plantasks-gadget-plugin/blob/master/src/main/resources/gadgets/a1-plantasks.xml

view: {
                            enableReload: true,
                        	onResizeAdjustHeight: true,
                            
							template: function(args) {
                                var gadget = this;
                                gadget.getView().html(args.restresult.html);
                                
								
								// reload function
								function reloadGadget()
                                {
									  if (document.activeElement.tagName == "IFRAME")
									  {
										document.getElementById(document.activeElement.id).contentWindow.location.reload(true);
									  }
									   else
									   {
										window.location.reload(true);
									   }
                                }
								// reloading after user change
                                jQuery("[name='a1-plantasks-all-users']").change(function () {
                                	reportUser = jQuery("[name='a1-plantasks-all-users']").val();
                                    jQuery.cookie('a1_report_user', reportUser, { expires: 2 });
                                	reloadGadget();
                                });
								// reloading after project change
                                jQuery("#tg-project-selector").change(function () {
                                	selectedProject = jQuery("#tg-project-selector :selected").val();
                                    jQuery.cookie('tg_selected_project', selectedProject, { expires: 365 });
                                	reloadGadget();
                                });
								
								// reloading on click
                                jQuery("#a1-plantasks-show-my-dash").click(function () {
                                    jQuery.cookie('a1_report_user', '', { expires: 2 })
                                	reloadGadget();
                                });
Ariel Rosa September 24, 2014

Hi Dmitry, I've putter the 'window.location.reload(true);' directly in the onclick and it worked really well, thanks a bunch for the help! :D

Dmitry Miroshnichenko
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 24, 2014

No problem:) Those iframe's make life harder)))

TAGS
AUG Leaders

Atlassian Community Events