forked from andrewgleave/CouchDBAttachmentUploader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cordova.plugin.couchdb-attachment-upload.js
39 lines (34 loc) · 1.37 KB
/
cordova.plugin.couchdb-attachment-upload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* Cordova CouchDB Attachment Uploader Plugin
* Copyright 2011 Red Robot Studios Ltd. All rights reserved.
* Based on Matt Kane's File Upload Plugin
*/
var CouchDBAttachmentUploader = function() {}
CouchDBAttachmentUploader.prototype.upload = function(filepath, couchURI, docID, docRevision, success, failure, options) {
var key = 'f' + this.callbackIdx++;
window.plugins.CouchDBAttachmentUploader.callbackMap[key] = {
success: function(result) {
if( result.error ) {
failure(result.error);
} else {
success(result);
};
delete window.plugins.CouchDBAttachmentUploader.callbackMap[key]
},
failure: function(result) {
failure(result);
delete window.plugins.CouchDBAttachmentUploader.callbackMap[key]
}
}
var callback = 'window.plugins.CouchDBAttachmentUploader.callbackMap.' + key;
return cordova.exec('CouchDBAttachmentUploader.upload', filepath, couchURI, docID,
docRevision, callback + '.success', callback + '.failure', options);
}
CouchDBAttachmentUploader.prototype.callbackMap = {};
CouchDBAttachmentUploader.prototype.callbackIdx = 0;
cordova.addConstructor(function() {
if(!window.plugins) {
window.plugins = {};
}
window.plugins.CouchDBAttachmentUploader = new CouchDBAttachmentUploader();
});