Skip to content

Commit 3cc8b20

Browse files
author
Ray Nicholus
committed
#382 - add a setDeleteFileEndpoint API function for this feature that mirrors the behavior of the existing setEndpoint API function
1 parent 0a34e6c commit 3cc8b20

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

client/js/ajax.requester.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ qq.AjaxRequestor = function(o) {
1111
method: 'POST',
1212
maxConnections: 3,
1313
customHeaders: {},
14+
endpointStore: {},
15+
paramsStore: {},
1416
successfulResponseCodes: [200],
1517
demoMode: false,
1618
cors: {
@@ -68,8 +70,8 @@ qq.AjaxRequestor = function(o) {
6870

6971
options.onSend(id);
7072

71-
if (requestState[id].paramsStore.getParams) {
72-
params = requestState[id].paramsStore.getParams(id);
73+
if (options.paramsStore.getParams) {
74+
params = options.paramsStore.getParams(id);
7375
}
7476

7577
url = createUrl(id, params);
@@ -94,8 +96,12 @@ qq.AjaxRequestor = function(o) {
9496
}
9597

9698
function createUrl(id, params) {
97-
var method = getMethod(),
98-
endpoint = requestState[id].endpoint;
99+
var endpoint = options.endpointStore.getEndpoint(id),
100+
addToPath = requestState[id].addToPath;
101+
102+
if (addToPath !== undefined) {
103+
endpoint += "/" + addToPath;
104+
}
99105

100106
if (shouldParamsBeInQueryString && params) {
101107
return qq.obj2url(params, endpoint);
@@ -159,10 +165,9 @@ qq.AjaxRequestor = function(o) {
159165

160166

161167
return {
162-
send: function(id, endpoint, paramsStore) {
168+
send: function(id, addToPath) {
163169
requestState[id] = {
164-
paramsStore: paramsStore,
165-
endpoint: endpoint
170+
addToPath: addToPath
166171
};
167172

168173
var len = queue.push(id);

client/js/deletefile.ajax.requester.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ qq.DeleteFileAjaxRequestor = function(o) {
55

66
var requestor,
77
options = {
8-
endpoint: '/server/upload',
8+
endpointStore: {},
99
maxConnections: 3,
1010
customHeaders: {},
1111
paramsStore: {},
@@ -23,6 +23,8 @@ qq.DeleteFileAjaxRequestor = function(o) {
2323

2424
requestor = new qq.AjaxRequestor({
2525
method: 'DELETE',
26+
endpointStore: options.endpointStore,
27+
paramsStore: options.paramsStore,
2628
maxConnections: options.maxConnections,
2729
customHeaders: options.customHeaders,
2830
successfulResponseCodes: [200, 202, 204],
@@ -32,16 +34,10 @@ qq.DeleteFileAjaxRequestor = function(o) {
3234
onComplete: options.onDeleteComplete
3335
});
3436

35-
function createEndpoint(uuid) {
36-
return options.endpoint + "/" + uuid;
37-
}
38-
3937

4038
return {
4139
sendDelete: function(id, uuid) {
42-
var endpoint = createEndpoint(uuid);
43-
44-
requestor.send(id, endpoint, options.paramsStore);
40+
requestor.send(id, uuid);
4541
options.log("Submitted delete file request for " + id);
4642
}
4743
};

client/js/uploader.basic.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ qq.FineUploaderBasic = function(o){
116116
this._paramsStore = this._createParamsStore("request");
117117
this._deleteFileParamsStore = this._createParamsStore("deleteFile");
118118

119-
this._endpointStore = this._createEndpointStore();
119+
this._endpointStore = this._createEndpointStore("request");
120+
this._deleteFileEndpointStore = this._createEndpointStore("deleteFile");
120121

121122
this._handler = this._createUploadHandler();
122123
this._deleteHandler = this._createDeleteHandler();
@@ -245,6 +246,15 @@ qq.FineUploaderBasic.prototype = {
245246
deleteFile: function(fileId) {
246247
this._onSubmitDelete(fileId);
247248
},
249+
setDeleteFileEndpoint: function(endpoint, fileId) {
250+
/*jshint eqeqeq: true, eqnull: true*/
251+
if (fileId == null) {
252+
this._options.deleteFile.endpoint = endpoint;
253+
}
254+
else {
255+
this._deleteFileEndpointStore.setEndpoint(endpoint, fileId);
256+
}
257+
},
248258
_createUploadButton: function(element){
249259
var self = this;
250260

@@ -329,10 +339,10 @@ qq.FineUploaderBasic.prototype = {
329339
var self = this;
330340

331341
return new qq.DeleteFileAjaxRequestor({
332-
endpoint: this._options.deleteFile.endpoint,
333342
maxConnections: this._options.deleteFile.maxConnections,
334343
customHeaders: this._options.deleteFile.customHeaders,
335344
paramsStore: this._deleteFileParamsStore,
345+
endpointStore: this._deleteFileEndpointStore,
336346
demoMode: this._options.demoMode,
337347
cors: this._options.cors,
338348
log: function(str, level) {
@@ -706,7 +716,7 @@ qq.FineUploaderBasic.prototype = {
706716
}
707717
};
708718
},
709-
_createEndpointStore: function() {
719+
_createEndpointStore: function(type) {
710720
var endpointStore = {},
711721
self = this;
712722

@@ -721,7 +731,7 @@ qq.FineUploaderBasic.prototype = {
721731
return endpointStore[fileId];
722732
}
723733

724-
return self._options.request.endpoint;
734+
return self._options[type].endpoint;
725735
},
726736

727737
remove: function(fileId) {

readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,7 @@ if the user agent does not support the File API.
12081208
or if the user agent does not support the File API. For more info on the `File` object, please see [the entry in the W3C spec](http://www.w3.org/TR/FileAPI/#dfn-file).
12091209
* `deleteFile(fileId)` - This allows you to programmatically order Fine Uploader to send a DELETE request for a specific file.
12101210
Fine Uploader actually uses the API call internally when a user clicks the delete link in FineUploader mode.
1211+
* `setDeleteFileEndpoint(String endpointPath, [optional] Number fileId)` - Same as the `setEndpoint` function except this applies only to the `deleteFile` option endpoint(s).
12111212
* `getUuid(fileId)` - Retrieves the UUID associated with a file, given a current session file ID.
12121213
12131214
<br/>

0 commit comments

Comments
 (0)