|
|
|
@ -44,10 +44,12 @@ class FipamoAdminAPI {
|
|
|
|
|
/**
|
|
|
|
|
* @constructor
|
|
|
|
|
* @param {string} baseURL - url of site; uses local when empty
|
|
|
|
|
* @param {object} progressBar - element to be used to display upload progress
|
|
|
|
|
*/
|
|
|
|
|
constructor(baseURL = null) {
|
|
|
|
|
constructor(baseURL = null, progressBar = null) {
|
|
|
|
|
this.percentComplete = 0; //for later
|
|
|
|
|
this.baseURL = null;
|
|
|
|
|
this.progressBar = progressBar;
|
|
|
|
|
this.status = false;
|
|
|
|
|
if (baseURL) this.baseURL = baseURL;
|
|
|
|
|
//asks server if a session is active
|
|
|
|
@ -367,7 +369,9 @@ class FipamoAdminAPI {
|
|
|
|
|
var self = this;
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
|
request.upload.onprogress = self.handleLoadProgress;
|
|
|
|
|
request.upload.addEventListener("progress", (e) =>
|
|
|
|
|
self.handleLoadProgress(e, self.progressBar)
|
|
|
|
|
);
|
|
|
|
|
request.open(requestType, requestURL, true);
|
|
|
|
|
request.onload = () => {
|
|
|
|
|
if (request.status == 200) {
|
|
|
|
@ -416,9 +420,12 @@ class FipamoAdminAPI {
|
|
|
|
|
//--------------------------
|
|
|
|
|
// event handlers
|
|
|
|
|
//--------------------------
|
|
|
|
|
handleLoadProgress(e) {
|
|
|
|
|
this.percentComplete = Math.ceil((e.loaded / e.total) * 100);
|
|
|
|
|
//pass element to display request progress
|
|
|
|
|
handleLoadProgress(e, progressBar) {
|
|
|
|
|
let percent = Math.ceil((e.loaded / e.total) * 100);
|
|
|
|
|
//if a progress bar element is present, talk to it
|
|
|
|
|
if (progressBar != null) {
|
|
|
|
|
progressBar.style.width = percent + "%";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|