summaryrefslogtreecommitdiff
path: root/themes/okadmin/public/js/upload.js
diff options
context:
space:
mode:
Diffstat (limited to 'themes/okadmin/public/js/upload.js')
-rw-r--r--themes/okadmin/public/js/upload.js36
1 files changed, 29 insertions, 7 deletions
diff --git a/themes/okadmin/public/js/upload.js b/themes/okadmin/public/js/upload.js
index 6149424..44a34b5 100644
--- a/themes/okadmin/public/js/upload.js
+++ b/themes/okadmin/public/js/upload.js
@@ -1,8 +1,9 @@
var OKUpload = function(){
- this.action = this.imageAction = "/_services/s3/image"
- this.videoAction = "/_services/s3/video"
- this.audioAction = "/_services/s3/audio"
+ this.config = $("#uploadConfig").data()
+ this.imageAction = "/_services/s3/image"
+ this.videoAction = "/_services/s3/video"
+ this.audioAction = "/_services/s3/audio"
}
OKUpload.prototype.bind = function(rapper){
var uploader = this
@@ -42,29 +43,47 @@ OKUpload.prototype.handleFileSelect = function(e) {
var files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
for (var i = 0, f; f = files[i]; i++) {
- if ( ! f.type.match('image.*') && ! f.type.match('video.*') ) {
- continue;
- }
this.upload(f)
}
}
+OKUpload.prototype.largeFileError = function(file, maxSize) {
+ var your_bytes = bytesToString(file.size)
+ var max_bytes = bytesToString(maxSize)
+ alert("Sorry, your file is too big.\n\n" + file.name + "\n\nYour file: " + your_bytes + "\nMax size: " + max_bytes)
+ function bytesToString (n) {
+ if (n < 1024) return n + " bytes"
+ n /= 1024
+ if (n < 1024) return n.toFixed(1) + " kb"
+ n /= 1024
+ if (n < 1024) return n.toFixed(1) + " mb"
+ }
+}
OKUpload.prototype.upload = function(f){
var field, action
if ( f.type.match('video.*') ) {
+ if (this.config.videoMaxbytes && f.size > this.config.videoMaxbytes) {
+ return this.largeFileError(f, this.config.videoMaxbytes)
+ }
field = 'video'
action = this.videoAction
}
else if ( f.type.match('audio.*') ) {
+ if (this.config.audioMaxbytes && f.size > this.config.audioMaxbytes) {
+ return this.largeFileError(f, this.config.audioMaxbytes)
+ }
field = 'audio'
action = this.audioAction
}
else {
+ if (this.config.imageMaxbytes && f.size > this.config.imageMaxbytes) {
+ return this.largeFileError(f, this.config.imageMaxbytes)
+ }
field = 'image'
action = this.imageAction || this.action
}
-
+
this.xhrCount += 1
this.$progress.addClass("loading")
@@ -109,11 +128,13 @@ OKUpload.prototype.upload = function(f){
console.log(arguments, request)
}
function transferError (data) {
+ console.log("Transfer error")
this.loadCount += 1
this.hideUploadBars()
console.log(arguments)
}
function transferAbort (data) {
+ console.log("Transfer aborted")
this.loadCount += 1
this.hideUploadBars()
console.log(arguments)
@@ -147,6 +168,7 @@ OKUpload.prototype.success = function(data){
return
}
var url = data[0].extra.Location.replace(/%2F/, '\/')
+ console.log(url)
this.parse(url)
}
OKUpload.prototype.add = function(media){