-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageUpload.js
74 lines (60 loc) · 2.28 KB
/
ImageUpload.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
dojo.provide("unc.ImageUpload");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require('dojo.io.iframe');
dojo.require("dojox.form.FileInput");
dojo.declare("unc.ImageUpload", [ dijit._Widget, dijit._Templated ], {
templatePath: dojo.moduleUrl('unc', 'ImageUpload.html'),
widgetsInTemplate: true,
postCreate: function() {
this.inherited(arguments);
this.connect(this.at_confirm, 'onClick', this.uploadConfirmed);
this.connect(this.at_cancel, 'onClick', this.theCloseFunction);
},
uploadConfirmed: function() {
console.log('upload func start');
var form = dojo.byId('upload_form');
if (!form.file.value) {
return;
}
var fileName = dojo.byId('file').value;
console.log("fileName:", fileName);
console.log("form:", form);
var tags = form.tags.value.replace(/^\s+|\s+$/g, '');
if (tags.length === 0) {
return;
}
var uploadComplete = dojo.hitch(this, function() {
this.theCloseFunction();
});
var def = uow.getDatabase({
database: 'Media',
collection: 'Image',
mode: 'c' });
def.addCallback(function(db) {
db.upload({
form: form,
load: function(data, ioArgs) {
console.log('load', data);
//dojo.byId('messages').innerHTML = dojo.toJson(data);
console.log("Upload has been confirmed!");
uploadComplete();
},
error: function(msg, ioArgs) {
console.log('error', msg);
//dojo.byId('messages').innerHTML = msg;
}
});
});
def.addErrback(function(msg) {
console.log('upload failed');
});
console.log('upload func end');
},
//just an empty wrapper that gets called on a successful upload and to connect a kill-dialog call
//this is because for some reason i can't connect to a function call in the nested dialog thing
theCloseFunction: function() {
console.log('close function');
dojo.publish('close uploader', []);
}
});