Commit 901faf89 authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

Added error validation in available plugin downloading.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4165 b35dd754-fafc-0310-a699-88a17e54d16e
parent 90b143b8
......@@ -1906,6 +1906,8 @@ plugin.available.auto.update.currently = Auto-update is currently
plugin.available.auto.update.currently.disabled = disabled
plugin.available.click.here = Click here
plugin.available.change = to change the auto-update settings.
plugin.available.cancel.redirect = Leaving this page will cause all downloads to cancel. Leave anyway?
plugin.available.error.downloading = Unable to download plugin(s). Please try again.
# Server bytes statistics
......
/**
* $Revision$
* $Date$
*
* Copyright (C) 1999-2005 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.wildfire.update;
/**
* Simple data model to handle success/failure of downloads using AJAX.
*/
public class DownloadStatus {
private int hashCode;
private String url;
private boolean successfull;
public int getHashCode() {
return hashCode;
}
public void setHashCode(int hashCode) {
this.hashCode = hashCode;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public boolean isSuccessfull() {
return successfull;
}
public void setSuccessfull(boolean successfull) {
this.successfull = successfull;
}
}
......@@ -44,12 +44,21 @@ public class PluginDownloadManager {
* @param hashCode the matching hashcode of the <code>AvailablePlugin</code>.
* @return the hashCode.
*/
public int installPlugin(String url, int hashCode) {
public DownloadStatus installPlugin(String url, int hashCode) {
UpdateManager updateManager = XMPPServer.getInstance().getUpdateManager();
updateManager.downloadPlugin(url);
boolean worked = updateManager.downloadPlugin(url);
final DownloadStatus status = new DownloadStatus();
status.setHashCode(hashCode);
status.setSuccessfull(worked);
status.setUrl(url);
return hashCode;
/**
* mj bmmmmmmmmmmmmmmmmmmmmv cvvbv vvvv .nnnnn vvvvvvvvv
* @author Nate DeMoro
*/
return status;
}
}
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr10.dtd">
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr10.dtd">
<dwr>
<allow>
......@@ -13,6 +13,7 @@
<param name="class" value="org.jivesoftware.wildfire.update.PluginDownloadManager"/>
</create>
<convert converter="bean" match="org.jivesoftware.wildfire.update.Update"/>
<convert converter="bean" match="org.jivesoftware.wildfire.update.AvailablePlugin"/>
<convert converter="bean" match="org.jivesoftware.wildfire.update.AvailablePlugin"/>
<convert converter="bean" match="org.jivesoftware.wildfire.update.DownloadStatus"/>
</allow>
</dwr>
......@@ -146,20 +146,38 @@
<script src="dwr/util.js" type="text/javascript"></script>
<script src="dwr/interface/downloader.js" type="text/javascript"></script>
<script type="text/javascript">
var downloading;
function downloadPlugin(url, id) {
downloading = true;
document.getElementById(id + "-image").innerHTML = '<img src="images/working-16x16.gif" border="0"/>';
document.getElementById(id).style.background = "#FFFFF7";
setTimeout("startDownload('"+url+"','"+id+"')", 5000);
setTimeout("startDownload('" + url + "','" + id + "')", 5000);
}
function startDownload(url, id) {
downloader.installPlugin(downloadComplete, url, id);
}
function startDownload(url, id){
downloader.installPlugin(downloadComplete, url, id);
function downloadComplete(status) {
downloading = false;
if (!status.successfull) {
document.getElementById(status.hashCode + "-image").innerHTML = '<img src="images/add-16x16.gif" border="0"/>';
document.getElementById(status.hashCode).style.background = "#FFFFFF";
document.getElementById("errorMessage").style.display = '';
document.getElementById(status.hashCode).style.display = '';
document.getElementById(status.hashCode + "-row").style.display = 'none';
setTimeout("closeErrorMessage()", 5000);
}
else {
document.getElementById(status.hashCode).style.display = 'none';
document.getElementById(status.hashCode + "-row").style.display = '';
setTimeout("fadeIt('" + status.hashCode + "')", 3000);
}
}
function downloadComplete(id) {
document.getElementById(id).style.display = 'none';
document.getElementById(id + "-row").style.display = '';
setTimeout("fadeIt('" + id + "')", 3000);
function closeErrorMessage(){
Effect.Fade("errorMessage");
}
function fadeIt(id) {
......@@ -167,10 +185,26 @@
}
DWREngine.setErrorHandler(handleError);
DWREngine.setErrorHandler(handleError);
function handleError(error) {
}
// Handle leaving of page validation.
window.onbeforeunload = function (evt) {
if (!downloading) {
return;
}
var message = '<fmt:message key="plugin.available.cancel.redirect" />';
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
}
function handleError(error){
}
</script>
</head>
......@@ -200,8 +234,9 @@
<% } else {%>
<div id="errorMessage" class="error" style="display:none;">
<fmt:message key="plugin.available.error.downloading" />
</div>
<div class="light-gray-border" style="padding:10px;">
......@@ -288,8 +323,8 @@
<%
%>
<span id="<%= plugin.hashCode() %>-image"><a href="javascript:downloadPlugin('<%=updateURL%>', '<%= plugin.hashCode()%>')"><img src="images/add-16x16.gif" width="16" height="16" border="0"
alt="<fmt:message key="plugin.available.download" />"></a></span>
<a href="javascript:downloadPlugin('<%=updateURL%>', '<%= plugin.hashCode()%>')"><span id="<%= plugin.hashCode() %>-image"><img src="images/add-16x16.gif" width="16" height="16" border="0"
alt="<fmt:message key="plugin.available.download" />"></span></a>
<% } %>
</td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment