mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 04:04:20 +00:00 
			
		
		
		
	Send request to get all account data
This commit is contained in:
		
							
								
								
									
										90
									
								
								assets/js/components/account/export/ui.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								assets/js/components/account/export/ui.js
									
									
									
									
									
										Normal 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);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										42
									
								
								assets/js/components/account/export/worker.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								assets/js/components/account/export/worker.js
									
									
									
									
									
										Normal 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");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user