watermelon avatar watermelon committed c4e998d

improved console.* and throw * messages(now they tell us where they are)
implemented logout

Comments (0)

Files changed (10)

src/main/client/comm/Communicator.js

 				var mime_type = "text/bookmaak."+file_type+".crypt";
 				break;
 			default:
-				throw "unknown file_type.";
+				throw "bookmaak.comm.Communicator.retrieveFile: unknown file_type.";
 		}
 		
-		console.debug("Trying to retrieve "+file_type+" file of '"+login+"'");
-		console.debug("MIME-Type: "+mime_type);
+		console.debug("bookmaak.comm.Communicator.retrieveFile: Trying to retrieve "+file_type+" file of '"+login+"'");
+		console.debug("bookmaak.comm.Communicator.retrieveFile: MIME-Type: "+mime_type);
 		jQuery.ajax({
 			url: server_url + login + '/' + file_type,
 			type: "GET",
 				//TODO check response mime type...
 				switch(jqXHR.status) {
 					case 404://NOT FOUND
-						console.info("Status: "+jqXHR.status+" - Failed to retrieved "+file_type+" file of '"+login+"', it odes not exist!");
+						console.info("bookmaak.comm.Communicator.retrieveFile: Status: "+jqXHR.status+" - Failed to retrieved "+file_type+" file of '"+login+"', it odes not exist!");
 						callback({	success: false,
 									type: textStatus,
 									msg: file_type+" file of "+login+" not found."
 								}, null);
 						break;
 					case 200://OK
-						console.info("Status: "+jqXHR.status+" - Successfully retrieved "+file_type+" file of '"+login+"'!");
+						console.info("bookmaak.comm.Communicator.retrieveFile: Status: "+jqXHR.status+" - Successfully retrieved "+file_type+" file of '"+login+"'!");
 						callback({	success: true,
 									type: textStatus,
 									msg: "Successfully retrieved "+file_type+" file of "+login+"."
 								}, new bookmaak.domain.File(file_type, jqXHR.responseText));
 						break;
 					default:
-						console.error("Status: "+jqXHR.status+" - Unexpected error!");
+						console.error("bookmaak.comm.Communicator.retrieveFile: Status: "+jqXHR.status+" - Unexpected error!");
 						callback({	success: false,
 									type: textStatus,
 									msg: "Failed to retrieve "+file_type+" file of "+login
 				var mime_type = "text/bookmaak."+file.type+".crypt";
 				break;
 			default:
-				throw "unknown file.type.";
+				throw "bookmaak.comm.Communicator.sendFile: unknown file.type.";
 		}
 		
-		console.debug("Trying to send "+file.type+" file of '"+login+"'");
-		console.debug("MIME-Type: "+mime_type);
+		console.debug("bookmaak.comm.Communicator.sendFile: Trying to send "+file.type+" file of '"+login+"'");
+		console.debug("bookmaak.comm.Communicator.sendFile: MIME-Type: "+mime_type);
 		jQuery.ajax({
 			url: server_url + login + '/' + file.type,
 			type: "PUT",
 				
 				switch(jqXHR.status) {
 					case 201://CREATED
-						console.info("Status: "+jqXHR.status+" - Successfully sent "+file.type+" file of '"+login+"'!");
+						console.info("bookmaak.comm.Communicator.sendFile: Status: "+jqXHR.status+" - Successfully sent "+file.type+" file of '"+login+"'!");
 						callback({	success: true,
 									type: textStatus,
 									msg: "Successfully sent "+file.type+" file of "+login+"."
 								});
 						break;
 					case 406://NOT ACCEPTABLE because of mime-type
-						console.info("Status: "+jqXHR.status+" - Failed to send "+file.type+" file of '"+login+"', invalid MIME-Type!");
+						console.info("bookmaak.comm.Communicator.sendFile: Status: "+jqXHR.status+" - Failed to send "+file.type+" file of '"+login+"', invalid MIME-Type!");
 						callback({	success: false,
 									type: textStatus,
 									msg: "The server did not accept the file because of a wrong mime-type."
 								});
 						break;
 					case 507://INSUFFICIENT STORAGE
-						console.info("Status: "+jqXHR.status+" - Failed to send "+file.type+" file of '"+login+"', insufficient storage!");
+						console.info("bookmaak.comm.Communicator.sendFile: Status: "+jqXHR.status+" - Failed to send "+file.type+" file of '"+login+"', insufficient storage!");
 						callback({	success: false,
 									type: textStatus,
 									msg: "The server did not accept the file because of insufficient storage."
 								});
 						break;
 					default:
-						console.error("Status: "+jqXHR.status+" - Unexpected error!");
+						console.error("bookmaak.comm.Communicator.sendFile: Status: "+jqXHR.status+" - Unexpected error!");
 						callback({	success: false,
 									type: "request failed",
 									msg: "Failed to send "+file.type+" file of "+login

src/main/client/controller/Controller.js

 
 
 
-
+//These class variables represent the state of the controller
 /**
  * bookmaak.controller.Controller.server_url -> String
  * 
- * the url to the server... it is only set when the user is "connected".
+ * the url to the server... it is only set when the client is "connected".
  **/
 bookmaak.controller.Controller.server_url = "";
 
-
 /**
  * bookmaak.controller.Controller.login_name -> String
  * 
- * the user that is logged in.
+ * the user that is logged in... it is only set when a user is logged in
  **/
 bookmaak.controller.Controller.login_name = "";
 
 /**
  * bookmaak.controller.Controller.communicator -> Communicator
  * 
- * the logged in user's communicator to the server
+ * the logged in user's communicator to the server... it is only set when a user is logged in
  **/
 bookmaak.controller.Controller.communicator = null;
 
+
+
+
+
 /**
  * bookmaak.controller.Controller.rng -> SecureRandom
  * 
 
 
 
+
+
+
 /**
  * bookmaak.controller.Controller.connect(String, Function)
  * 
 bookmaak.controller.Controller.disconnect = function() {
 	
 	console.debug("bookmaak.controller.Controller.disconnect: logging out...");
-	bookmaak.controller.Controller.login_name = "";
-	bookmaak.controller.Controller.communicator = null;
+	bookmaak.controller.Controller.logout();
 	
 	console.debug("bookmaak.controller.Controller.disconnect: closing connection...");
 	bookmaak.controller.Controller.server_url = "";
 	console.debug("bookmaak.controller.Controller.login: Initializing user's communicator...");
 	bookmaak.controller.Controller.
 	communicator = new bookmaak.comm.
-						Communicator(
-							login,
-							bookmaak.controller.Controller.server_url);
+		Communicator(login, bookmaak.controller.Controller.server_url);
 	
 	//retrieve user file
 	console.debug("bookmaak.controller.Controller.login: Trying to retrieve the user file...");
-	bookmaak.controller.Controller.
-	communicator.retrieveFile(
+	bookmaak.controller.Controller.communicator.retrieveFile(
 		bookmaak.controller.FILE_TYPE.USER,
 		function(result, file) {
 //		{	success: Boolean, true on success, else false
 		else {
 			console.error("bookmaak.controller.Controller.login: Failed to retrieved user file!");
 			console.error("bookmaak.controller.Controller.login: Error type: "+result.type+" Msg:"+result.msg);
-			//TODO maybe disconnect... if servers fault
+			//TODO maybe disconnect... if servers fault..define an handle result.type
 		}
 		callback(result.success);
 	});
 };
 
+
+
+/**
+ * bookmaak.controller.Controller.logout()
+ *
+ * Log out the current user...
+ **/
+bookmaak.controller.Controller.logout = function() {
+	
+	console.debug("bookmaak.controller.Controller.logout: logging out user...");
+	bookmaak.controller.Controller.login_name = "";
+	bookmaak.controller.Controller.communicator = null;
+};
+

src/main/client/crypto/UserCrypto.js

 	/**
 	 * bookmaak.crypto.UserCrypto#encryptUserFile(File) -> File
 	 *
-	 * brauchen wir derzeit nicht... erst wenn wir den symmetrischen schl�ssel
-	 * �ndern wollen
+	 * brauchen wir derzeit nicht... erst wenn wir den symmetrischen schlüssel
+	 * ändern wollen
 	 *
 	 * **plain_file** the plain file.
 	 **/
 		var type = plain_file.type;
 		
 		if(type != bookmaak.controller.FILE_TYPE.USER)
-			throw "plain_file is undefined or of wrong type";
+			throw "bookmaak.crypto.UserCrypto.encryptUserFile: plain_file is undefined or of wrong type";
 		
 		var data_decrypted = plain_file.data;
 		

src/main/client/ui/connect_presenter.js

 		console.log("bookmaak.ui.onClickConnect: server url fixed:"+_server_url);
 		
 		//try to contact server
+		console.debug("bookmaak.ui.onClickConnect: connecting to "+_server_url+"...");
 		bookmaak.controller.Controller.connect(_server_url, function(connection) {
 			
 			if(connection.success){
  **/
 bookmaak.ui.onClickDisconnect = function() {
 	
+	console.debug("bookmaak.ui.onClickDisconnect: disconnecting from "+bookmaak.controller.Controller.server_url+"...");
 	bookmaak.controller.Controller.disconnect();
 	
 	showConnectViewDisconnected();

src/main/client/ui/index_presenter.js

 		case bookmaak.ui.MESSAGE_TYPE.NOTICE:
 			elem = ".noticebox";
 			break;
-		default: throw new Error("BOOKMAAK: Semantic error in bookmaak.ui.printMessage");
+		default: throw new Error("bookmaak.ui.printMessage: Semantical error!");
 	}
 	
 	//set message
 		case CONNECT_VIEW_ID://well that one is not a real view... more a widget
 			break;
 		default:
-			throw "damn i dont know that view, back should not be visible...";
+			throw new Error("bookmaak.ui.onClickBack: Semantical error!");
 		}
 	}
 	

src/main/client/ui/login_presenter.js

 		
 		var login = _login;
 		
-		bookmaak.controller.Controller.
-		login(login, function(success) {
+		console.debug("bookmaak.ui.onClickLogin: loggin in...");
+		bookmaak.controller.Controller.login(login, function(success) {
 			
 			if(success) {
 				

src/main/client/ui/manage_account_presenter.js

 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 //
 
-
+//TODO this should be a "widget" like connect_view
 /**
  * bookmaak.ui.onClickManageBookmarks()
  * 
  **/
 bookmaak.ui.onClickLogout = function() {
 	
-	showManageAccountView("#man_opt_logout");
+	var last_login = bookmaak.controller.Controller.login_name;
+	
+	console.debug("bookmaak.ui.onClickLogout: loggin out...");
+	bookmaak.controller.Controller.logout();
+	
+	showLoginView(last_login);
 };
 
 function showManageAccountView(option_to_show) {
 		case "#man_opt_import_export":
 		case "#man_opt_change_account":
 		case "#man_opt_delete_account":
-		case "#man_opt_logout":
 			jQuery(option_to_show).show();
 			break;
 		default:

src/main/client/ui/manage_account_view.jade

         | TODO delete account
         | do you really want to do that?
         
-    div#man_opt_logout.man_opt_option.hidden
-      p
-        | TODO logout
         

src/main/client/ui/register_presenter.js

 		
 		//check if usernamen yet exists
 		if(login_is_valid) {
-			console.log("bookmaak.controller.userExists("+_login+")");
+			console.log("bookmaak.ui.onClickDoRegister: bookmaak.controller.userExists("+_login+")");
 			bookmaak.controller.userExists(_login, function(result) {
 				
-				console.debug("result:");console.debug(result);
+				console.debug("bookmaak.ui.onClickDoRegister: result:");console.debug(result);
 				
 				if(!bookmaak.util.isDefined(result.exists))	//error occurred
 					error = true;
 				else										//does not exist
 					login_exists = false;
 				
-				console.log("login exists: "+login_exists);
+				console.log("bookmaak.ui.onClickDoRegister: login exists: "+login_exists);
 				
 				//do register
 				if(login_is_valid && !login_exists
 	}
 	catch(err) {
 		console.error(err);
-		throw new Error("BOOKMAAK: There is something wrong with the input fields...");
+		throw new Error("bookmaak.ui.onClickDoRegister: There is something wrong with the input fields...");
 	}
 };
 

src/main/client/util/Settings.js

 			var key = _key;
 			break;
 		default:
-			throw "illegal key.";
+			throw "bookmaak.util.addSetting: illegal key.";
 	}
 	
 	//check _type
 			var type = _type;
 			break;
 		default:
-			throw "illegal type.";
+			throw "bookmaak.util.addSetting: illegal type.";
 	}
 	
 	var value = _value;
 			var key = _key;
 			break;
 		default:
-			throw "illegal key.";
+			throw "bookmaak.util.getSetting: illegal key.";
 	}
 	
 	//check _type
 			var type = _type;
 			break;
 		default:
-			throw "illegal type.";
+			throw "bookmaak.util.getSetting: illegal type.";
 	}
 	
 	return getSetting(type, key+"_"+login);
 			var key = _key;
 			break;
 		default:
-			throw "illegal key.";
+			throw "bookmaak.util.removeSetting: illegal key.";
 	}
 	
 	//check _type
 			var type = _type;
 			break;
 		default:
-			throw "illegal type.";
+			throw "bookmaak.util.removeSetting: illegal type.";
 	}
 	
 	//remove the key
 	var prefixed_key = key_prefix + "_" + key;
 	var serialized_value = JSON.stringify(value);
 	
-	console.log("trying to add key: "+prefixed_key+" value: "+serialized_value);
+	console.log("addSetting: trying to add key: "+prefixed_key+" value: "+serialized_value);
 	
 	try {
 		
 		//send to localstore
 		localStorage.setItem(prefixed_key, serialized_value);
-		console.log("successfully stored key");
+		console.log("addSetting: successfully stored key");
 		return true;
 	}
 	catch(e) {//QuotaExceededError
 		
-		console.log("failed to store key");
+		console.log("addSetting: failed to store key");
 		return false;
 	}
 }
 	
 	var prefixed_key = key_prefix + "_" + key;
 	
-	console.log("trying to get key: "+prefixed_key);
+	console.log("getSetting: trying to get key: "+prefixed_key);
 	
 	//get from localstore
 	var serialized_value = localStorage.getItem(prefixed_key);
 	
-	console.log("got value: "+serialized_value);
-	console.log("got value: "+JSON.pares(serialized_value));
+	console.log("getSetting: got value: "+serialized_value);
+	console.log("getSetting: got value: "+JSON.pares(serialized_value));
 	
 	if(serialized_value == null)
 		return true;
 	
 	var prefixed_key = key_prefix + "_" + key;
 	
-	console.log("removing key: "+prefixed_key);
+	console.log("removeSetting: removing key: "+prefixed_key);
 	
 	//delete from localstore
 	localStorage.removeItem(prefixed_key);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.