Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

delete-button: FineUploader mode UI elements, start of server-side DE…

…LETE handler, TODO: finish server-side DELETE handler & publish example, consider using ajax requestor in xhr upload handler, code cleanup, testing
  • Loading branch information...
commit 7d7dccba450bcf9e1b4857559b0cd2f15c0ba319 1 parent fd2054f
@rnicholus rnicholus authored
View
2  WEB-INF/web.xml
@@ -13,7 +13,7 @@
<servlet-mapping>
<servlet-name>UploadReceiver</servlet-name>
- <url-pattern>/upload/receiver</url-pattern>
+ <url-pattern>/upload/receiver/*</url-pattern>
</servlet-mapping>
</web-app>
View
6 client/js/ajax.requestor.js
@@ -58,11 +58,15 @@ qq.AjaxRequestor = function(o) {
method = options.method,
url = options.endpoint + "/" + requestState[id].param;
+ options.onSend(id);
+
requestState[id].xhr = xhr;
xhr.onreadystatechange = getReadyStateChangeHandler(id);
- setHeaders(id);
+
xhr.open(method, url, true);
+ setHeaders(id);
+
log('Sending ' + method + " request for " + id);
xhr.send();
View
17 client/js/uploader.basic.js
@@ -308,7 +308,7 @@ qq.FineUploaderBasic.prototype = {
}
});
},
- _createDeleteHander: function() {
+ _createDeleteHandler: function() {
var self = this;
return new qq.AjaxRequestor({
@@ -325,7 +325,7 @@ qq.FineUploaderBasic.prototype = {
},
onComplete: function(id, xhr, isError) {
self._onDeleteComplete(id, xhr, isError);
- self._options.onDeleteComplete(id, xhr, isError);
+ self._options.callbacks.onDeleteComplete(id, xhr, isError);
}
});
@@ -364,11 +364,16 @@ qq.FineUploaderBasic.prototype = {
this._storedFileIds.splice(storedFileIndex, 1);
}
},
- _onDelete: function(fileId) {
- //TODO
- },
+ _onDelete: function(fileId) {},
_onDeleteComplete: function(fileId, xhr, isError) {
- //TODO
+ var filename = this._handler.getName(fileId);
+
+ if (isError) {
+ this.log("Delete request for '" + filename + "' has failed.", "error");
+ }
+ else {
+ this.log("Delete request for '" + filename + "' has succeeded.");
+ }
},
_removeFromFilesInProgress: function(id) {
var index = qq.indexOf(this._filesInProgress, id);
View
56 client/js/uploader.js
@@ -308,7 +308,7 @@ qq.extend(qq.FineUploader.prototype, {
qq(this._find(item, 'spinner')).hide();
if (result.success){
- this._showDeleteLink(item);
+ this._showDeleteLink(id);
qq(item).addClass(this._classes.success);
if (this._classes.successIcon) {
this._find(item, 'finished').style.display = "inline-block";
@@ -329,8 +329,7 @@ qq.extend(qq.FineUploader.prototype, {
_onUpload: function(id, fileName){
qq.FineUploaderBasic.prototype._onUpload.apply(this, arguments);
- var item = this.getItemByFileId(id);
- this._showSpinner(item);
+ this._showSpinner(id);
},
_onBeforeAutoRetry: function(id) {
var item, progressBar, cancelLink, failTextEl, retryNumForDisplay, maxAuto, retryNote;
@@ -365,7 +364,7 @@ qq.extend(qq.FineUploader.prototype, {
this._find(item, 'progressBar').style.width = 0;
qq(item).removeClass(this._classes.fail);
qq(this._find(item, 'statusText')).clearText();
- this._showSpinner(item);
+ this._showSpinner(id);
this._showCancelLink(item);
return true;
}
@@ -380,7 +379,7 @@ qq.extend(qq.FineUploader.prototype, {
this._showDeleteConfirm(fileId);
}
else {
- this._deleteHandler.send(fileId, {uuid: uuid});
+ this._sendDeleteRequest(fileId);
}
}
}
@@ -389,6 +388,33 @@ qq.extend(qq.FineUploader.prototype, {
return false;
}
},
+ _onDeleteComplete: function(fileId, xhr, isError) {
+ qq.FineUploaderBasic.prototype._onDeleteComplete.apply(this, arguments);
+
+ var item = this.getItemByFileId(fileId),
+ spinnerEl = this._find(item, 'spinner'),
+ statusTextEl = this._find(item, 'statusText');
+
+ qq(spinnerEl).hide();
+
+ if (isError) {
+ qq(statusTextEl).setText(this._options.deleteFile.deletingFailedText);
+ this._showDeleteLink(fileId);
+ }
+ else {
+ this._removeFileItem(fileId);
+ }
+ },
+ _sendDeleteRequest: function(fileId) {
+ var item = this.getItemByFileId(fileId),
+ deleteLink = this._find(item, 'deleteButton'),
+ statusTextEl = this._find(item, 'statusText');
+
+ qq(deleteLink).hide();
+ this._showSpinner(fileId);
+ qq(statusTextEl).setText(this._options.deleteFile.deletingStatusText);
+ this._deleteHandler.send(fileId, this.getUuid(fileId));
+ },
_showDeleteConfirm: function(fileId) {
var fileName = this._handler.getName(fileId),
confirmMessage = this._options.deleteFile.confirmMessage.replace(/\{filename\}/g, fileName),
@@ -396,7 +422,7 @@ qq.extend(qq.FineUploader.prototype, {
self = this;
this._options.showConfirm(confirmMessage, function() {
- self._deleteHandler.send(fileId, {uuid: uuid});
+ self._sendDeleteRequest(fileId);
});
},
_addToList: function(id, fileName){
@@ -496,20 +522,24 @@ qq.extend(qq.FineUploader.prototype, {
_showTooltip: function(item, text) {
item.title = text;
},
- _showSpinner: function(item) {
- var spinnerEl = this._find(item, 'spinner');
+ _showSpinner: function(id) {
+ var item = this.getItemByFileId(id),
+ spinnerEl = this._find(item, 'spinner');
+
spinnerEl.style.display = "inline-block";
},
_showCancelLink: function(item) {
if (!this._options.disableCancelForFormUploads || qq.isXhrUploadSupported()) {
var cancelLink = this._find(item, 'cancel');
- cancelLink.style.display = 'inline';
+
+ qq(cancelLink).css({display: 'inline'});
}
},
- _showDeleteLink: function(item) {
- //TODO create an option to control visibility of this button
- var deleteLink = this._find(item, 'deleteButton');
- deleteLink.style.display = 'inline';
+ _showDeleteLink: function(fileId) {
+ var item = this.getItemByFileId(fileId),
+ deleteLink = this._find(item, 'deleteButton');
+
+ qq(deleteLink).css({display: 'inline'});
},
_error: function(code, fileName){
var message = qq.FineUploaderBasic.prototype._error.apply(this, arguments);
View
11 test/fineuploader/UploadReceiver.java
@@ -20,7 +20,7 @@
private static String CONTENT_TYPE = "text/plain";
private static String CONTENT_LENGTH = "Content-Length";
- private static int RESPONSE_CODE = 200;
+ private static int SUCCESS_RESPONSE_CODE = 200;
final Logger log = LoggerFactory.getLogger(UploadReceiver.class);
@@ -32,6 +32,13 @@ public void init() throws ServletException
}
@Override
+ public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException
+ {
+ //TODO
+ resp.setStatus(SUCCESS_RESPONSE_CODE);
+ }
+
+ @Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException
{
RequestParser requestParser;
@@ -39,7 +46,7 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOEx
try
{
resp.setContentType(CONTENT_TYPE);
- resp.setStatus(RESPONSE_CODE);
+ resp.setStatus(SUCCESS_RESPONSE_CODE);
if (ServletFileUpload.isMultipartContent(req))
{
View
5 test/js/uploader-demo-jquery.js
@@ -35,6 +35,11 @@ $(document).ready(function() {
retry: {
enableAuto: true,
showButton: true
+ },
+ deleteFile: {
+ enabled: true,
+ endpoint: '/upload/receiver',
+ forceConfirm: true
}
})
.on('error', errorHandler)
Please sign in to comment.
Something went wrong with that request. Please try again.