Skip to content
Snippets Groups Projects
Unverified Commit 52e60b56 authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

cc

parent aebdec0f
No related branches found
No related tags found
No related merge requests found
/*global Vue */
/*global ActiveStorage, Vue */
Vue.DirectUploadController = function DirectUploadController (input, file, url) {
'use strict';
this.input = input;
this.file = file;
this.url = url;
this.directUpload = new ActiveStorage.DirectUpload(this.file, this.url, this)
this.dispatch("initialize");
}
this.directUpload = new ActiveStorage.DirectUpload(this.file, this.url, this);
this.dispatch('initialize');
};
Vue.DirectUploadController.prototype.start = function (callback) {
'use strict';
this.directUpload.create(function (error, blob) {
this.dispatch("end");
this.dispatch('end');
if (error) {
console.log(error);
console.error(error);
} else {
callback(blob);
}
}.bind(this));
}
};
Vue.DirectUploadController.prototype.uploadRequestDidProgress = function (event) {
'use strict';
var progress = event.loaded / event.total * 100
var progress = event.loaded / event.total * 100;
if (progress) {
this.dispatch("progress", { "progress": progress });
this.dispatch('progress', { 'progress': progress });
}
}
};
Vue.DirectUploadController.prototype.dispatch = function (name, detail) {
var event = document.createEvent("Event"),
'use strict';
var event = document.createEvent('Event'),
eventName = 'direct-upload:' + name,
eventDetail = detail || {},
disabled = this.input.disabled;
detail = detail || {};
detail.file = this.file;
detail.id = this.directUpload.id;
eventDetail.file = this.file;
eventDetail.id = this.directUpload.id;
event.initEvent(eventName, true, true);
event.detail = detail;
event.detail = eventDetail;
this.input.disabled = false;
this.input.dispatchEvent(event);
this.input.disabled = disabled;
return event;
}
};
// DirectUpload delegate
Vue.DirectUploadController.prototype.directUploadWillStoreFileWithXHR = function (xhr) {
'use strict';
xhr.upload.addEventListener("progress", this.uploadRequestDidProgress.bind(this));
}
\ No newline at end of file
xhr.upload.addEventListener('progress', this.uploadRequestDidProgress.bind(this));
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment