diff --git a/assets/css/pages/settings/sections/privacy.css b/assets/css/pages/settings/sections/privacy.css index b56fb3a0..e0f8a310 100644 --- a/assets/css/pages/settings/sections/privacy.css +++ b/assets/css/pages/settings/sections/privacy.css @@ -4,6 +4,10 @@ * @author Pierre HUBERT */ +.box-export-account-data-settings .btn { + float: right; +} + .box-delete-account-settings .btn { float: right; } \ No newline at end of file diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 65fad7e1..10032dad 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -468,6 +468,26 @@ var ComunicWeb = { //TODO : implement }, + /** + * Account export + */ + export: { + + /** + * UI controller + */ + ui: { + //TODO : implement + }, + + /** + * Worker + */ + worker: { + //TODO: implement + }, + }, + }, /** diff --git a/assets/js/components/account/export/ui.js b/assets/js/components/account/export/ui.js new file mode 100644 index 00000000..a03a723b --- /dev/null +++ b/assets/js/components/account/export/ui.js @@ -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: " + message + "", "danger"); + modalBody.appendChild(msg); + } +} \ No newline at end of file diff --git a/assets/js/components/account/export/worker.js b/assets/js/components/account/export/worker.js new file mode 100644 index 00000000..c78bb296 --- /dev/null +++ b/assets/js/components/account/export/worker.js @@ -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"); + } + +} \ No newline at end of file diff --git a/assets/js/components/account/interface.js b/assets/js/components/account/interface.js index b3b97d31..52ee3bbc 100644 --- a/assets/js/components/account/interface.js +++ b/assets/js/components/account/interface.js @@ -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 * diff --git a/assets/js/components/settings/helper.js b/assets/js/components/settings/helper.js index 1138b1d3..dc58abb0 100644 --- a/assets/js/components/settings/helper.js +++ b/assets/js/components/settings/helper.js @@ -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); + }); + } + } \ No newline at end of file diff --git a/assets/js/pages/settings/sections/privacy.js b/assets/js/pages/settings/sections/privacy.js index 379f5c1e..45b0424a 100644 --- a/assets/js/pages/settings/sections/privacy.js +++ b/assets/js/pages/settings/sections/privacy.js @@ -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 diff --git a/system/config/dev.config.php b/system/config/dev.config.php index c7c32ba4..dceb27f0 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -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",