Send request to get all account data

This commit is contained in:
Pierre 2018-05-13 16:52:19 +02:00
parent e9b6df8536
commit f447f30c6c
8 changed files with 312 additions and 0 deletions

View File

@ -4,6 +4,10 @@
* @author Pierre HUBERT
*/
.box-export-account-data-settings .btn {
float: right;
}
.box-delete-account-settings .btn {
float: right;
}

View File

@ -468,6 +468,26 @@ var ComunicWeb = {
//TODO : implement
},
/**
* Account export
*/
export: {
/**
* UI controller
*/
ui: {
//TODO : implement
},
/**
* Worker
*/
worker: {
//TODO: implement
},
},
},
/**

View File

@ -0,0 +1,90 @@
/**
* Account export UI controller
*
* @author Pierre HUBERT
*/
ComunicWeb.components.account.export.ui = {
/**
* Account export modal information
*/
_exportModal: {},
/**
* Request account export
*
* @param {String} password The password of the user
*/
requestExport: function(password){
//Reset modal information
this._exportModal = {};
//Create the modal
this._exportModal = ComunicWeb.common.messages.createDialogSkeleton({
title: "Exporting data"
});
var modal = this._exportModal.modal;
$(modal).modal("show");
//Add message
createElem2({
appendTo: this._exportModal.modalBody,
type: "p",
innerHTML: "Please do not close this window while we create your archive..."
});
//Add progress bar
var progressContainer = createElem2({
appendTo: this._exportModal.modalBody,
type: "div",
class: "progress progress-xs progress-striped active"
});
this._exportModal.progress = createElem2({
appendTo: progressContainer,
type: "div",
class: "progress-bar progress-bar-success"
});
this.updateProgress(1);
//Create close modal function
var closeModal = function(){
$(modal).modal('hide');
emptyElem(modal);
remove();
}
this._exportModal.close = closeModal;
this._exportModal.closeModal.onclick = closeModal;
this._exportModal.cancelButton.onclick = closeModal;
//Start the worker
ComunicWeb.components.account.export.worker.start(password);
},
/**
* Update the progress of the creation of the archive
*
* @param {Number} progress The new percentage to apply
*/
updateProgress: function(progress){
this._exportModal.progress.style.width = progress + "%";
},
/**
* Display an error that prevent the success of the operation
*
* @param {String} message The message of the error
*/
exportFatalError: function(message){
//Get modal body
var modalBody = this._exportModal.modalBody;
emptyElem(modalBody);
//Display the error message
var msg = ComunicWeb.common.messages.createCalloutElem("Could not export your data", "An error occurred while trying to export your data: <i>" + message + "</i>", "danger");
modalBody.appendChild(msg);
}
}

View File

@ -0,0 +1,42 @@
/**
* Account data export worker
*
* @author Pierre HUBERT
*/
ComunicWeb.components.account.export.worker = {
/**
* Start account export
*
* @param {String} password The password of the user
*/
start: function(password){
//Get all user text data from the interface
ComunicWeb.components.account.interface.exportData(password, function(result){
//Check for errors
if(result.error){
return ComunicWeb.components.account.export.ui.exportFatalError("Could not get text data! Please check your password...");
}
//Update progress
ComunicWeb.components.account.export.ui.updateProgress(10);
//Parse data
ComunicWeb.components.account.export.worker.parse(data);
});
},
/**
* Parse account text data
*
* @param {Object} data Text data about the account
*/
parse: function(data){
alert("Parse text data");
}
}

View File

@ -31,6 +31,20 @@ ComunicWeb.components.account.interface = {
},
/**
* Request the export of all the data of the user
*
* @param {String} password The password of the user
* @param {function} callback
*/
exportData: function(password, callback){
var apiURI = "account/export_data";
var params = {
password: password
};
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
},
/**
* Request the deletion of the account
*

View File

@ -119,4 +119,81 @@ ComunicWeb.components.settings.helper = {
},
/**
* Request full account data export
*/
requestAccountDataExport: function(){
//Prompt user password
var dialog = ComunicWeb.common.messages.createDialogSkeleton({
type: "primary",
title: "Export personnal data"
});
$(dialog.modal).modal("show");
//Create modal close function
var closeModal = function(){
$(dialog.modal).modal("hide");
emptyElem(dialog.modal);
dialog.modal.remove();
};
dialog.cancelButton.addEventListener("click", closeModal);
dialog.closeModal.addEventListener("click", closeModal);
//Set dialog body
var passwordForm = createElem2({
appendTo: dialog.modalBody,
type: "div"
});
createElem2({
appendTo: passwordForm,
type: "p",
innerHTML: "We need your password to continue."
});
//Create pasword input group
var inputGroup = createElem2({
appendTo: passwordForm,
type: "div",
class: "input-group input-group-sm"
});
//Create password input
var passwordInput = createElem2({
appendTo: inputGroup,
type: "input",
class: "form-control",
elemType: "password"
});
//Create input group
var inputGroupContainer = createElem2({
appendTo: inputGroup,
type: "span",
class: "input-group-btn"
});
//Add submit button
var submitButton = createElem2({
appendTo: inputGroupContainer,
type: "button",
class: "btn btn-primary",
innerHTML: "Submit"
});
submitButton.addEventListener("click", function(e){
//Check given password
var password = passwordInput.value;
if(password.length < 4)
return notify("Please check given password !", "danger");
closeModal();
//Export personnal data
ComunicWeb.components.account.export.ui.requestExport(password);
});
}
}

View File

@ -14,10 +14,71 @@ ComunicWeb.pages.settings.sections.privacy = {
*/
open: function(args, target){
//Export data box
this.showExportDataBox(target);
//Delete account box
this.showDeleteAccountBox(target);
},
/**
* Show export personnal data box
*
* @param {HTMLElement} target The target for the box
*/
showExportDataBox: function(target){
//Create a box
var box = createElem2({
appendTo: target,
type: "div",
class: "box box-primary box-export-account-data-settings"
});
//Add box header
var boxHead = createElem2({
appendTo: box,
type: "div",
class: "box-header",
});
var boxTitle = createElem2({
appendTo: boxHead,
type: "h3",
class: "box-title",
innerHTML: "Export account data"
});
//Create box body
var boxBody = createElem2({
appendTo: box,
type: "div",
class: "box-body"
});
//Add a notice
createElem2({
appendTo: boxBody,
type: "p",
innerHTML: "You can export all the data of your account from here."
});
//Add delete account button
var exportAccountDataBtn = createElem2({
appendTo: boxBody,
type: "div",
class: "btn btn-primary",
innerHTML: "Export account data"
});
exportAccountDataBtn.addEventListener("click", function(e){
//Request account deletion
ComunicWeb.components.settings.helper.requestAccountDataExport();
});
},
/**
* Display delete account box

View File

@ -257,6 +257,10 @@ class Dev {
//Account component
"js/components/account/interface.js",
//Account export
"js/components/account/export/ui.js",
"js/components/account/export/worker.js",
//Mail caching
"js/components/mailCaching.js",