Commits

watermelon committed 114c5b1

fixed delete bug, partially fixed focus on inputs

Comments (0)

Files changed (5)

src/main/client/controller/Controller.js

 
 
 /**
- * bookmaak.dao.cotroller.Controller.deleteBookmark(Bookmark)
+ * bookmaak.dao.cotroller.Controller.deleteBookmark(Number)
  * 
- * **bookmark** the bookmark to delete
+ * **bookmark_id** the id of the bookmark to delete
  **/
-bookmaak.controller.Controller.deleteBookmark = function(bookmark) {
+bookmaak.controller.Controller.deleteBookmark = function(bookmark_id) {
 	
-	console.debug("bookmaak.dao.cotroller.Controller.deleteBookmark: deleting...");
-	console.debug(bookmark);
+	console.debug("bookmaak.dao.cotroller.Controller.deleteBookmark: deleting bookmark with id "+bookmark_id+"...");
 	
-	bookmaak.controller.Controller.bookmark_dao.deleteBookmark(bookmark);
+	bookmaak.controller.Controller.bookmark_dao.deleteBookmark_by_id(bookmark_id);
 	
 	bookmaak.controller.Controller.bookmark_dao.commit();
 	

src/main/client/dao/BookmarkDao.js

 	
 	//the in-memory bookmark store
 	var bookmarks = new Array();
-	var max_id = -1;
+	
+	//the used and free(again) ids
+	var ids = {
+		max_id: -1,
+		free_again: new Array()
+	};
+	
+	/**
+	 * Returns an id for a new bookmark, either a free again or a new one.
+	 **/
+	function getNewBookmarkId() {
+		
+		if(ids.free_again.length > 0) {
+			
+			return ids.free_again.pop();
+		}
+		else {
+			
+			return ++ids.max_id;
+		}
+	}
+	
+	/**
+	 * Marks an id as free again for use on new bookmarks.
+	 **/
+	function freeBookmarkId(id) {
+		
+		return ids.free_again.push(id);
+	}
+	
+	
 	
 	//fetch all bookmarks
 	fetchBookmarks();
 				return false;
 		}
 		
+		//find an id
+		var new_id = getNewBookmarkId();
+		
 		var new_bm = new bookmaak.domain.Bookmark(
-				max_id++, 
+				new_id, 
 				bm_data.title, 
 				bm_data.url, 
 				bm_data.tags, 
 	 **/
 	this.deleteBookmark = function(bm) {
 		
+		return this.deleteBookmark_by_id(bm.getId());
+	};
+	
+	
+	/**
+	 * bookmaak.dao.BookmarkDao#deleteBookmark_by_id(Number) -> Boolean
+	 *
+	 * Deletes the bookmark specified **id**.
+	 *
+	 * **id** the id of the bookmark<br/>
+	 * returns Boolean true on success, else false.
+	 **/
+	this.deleteBookmark_by_id = function(id) {
+		
 		for(var i = 0; i < bookmarks.length; i++) {
 			
-			if(bookmarks[i].getId() === bm.getId()) {
+			if(bookmarks[i].getId() === id) {
 				
+				freeBookmarkId(bookmarks[i].getId());
 				bookmarks.splice(i, 1);
+				
 				return true;
 			}
 		}
 						console.log("bookmaak.dao.BookmarkDao.fetchBookmarks: File content plain: v");
 						console.log(bookmarks_file_plain_data);
 						
+						ids.max_id = -1;//remember the max
+						var taken_ids = new Array();
 						var links = bookmarks_file_plain_data.links;
 						for(var i = 0; i < links.length; i++) {
 							
 							var link = links[i];
+							
+							taken_ids.push(link.id);
+							if(ids.max_id <= link.id)//calculate the max
+								ids.max_id = link.id;
+							
 							bookmarks.
 								push(new bookmaak.domain.
 									Bookmark(
 											link.tags, link.metas));
 						}
 						
-						max_id = links.length - 1;
+						console.log("max_id: "+ids.max_id);
+						
+						//we check all ids up to max_id
+						for(var i = 0; i <= ids.max_id; i++) {
+							if(taken_ids.indexOf(i) == -1)//if its not there,
+								ids.free_again.push(i);//we add it
+						}
+						
+						console.log("bookmaak.dao.BookmarkDao.fetchBookmarks: taken v");
+						console.log(taken_ids);
+						
+						console.log("bookmaak.dao.BookmarkDao.fetchBookmarks: free agains v");
+						console.log(ids.free_again);
 					}
 					else {
 						console.log("bookmaak.dao.BookmarkDao.fetchBookmarks: You have no bookmarks yet!");

src/main/client/ui/login_presenter.js

 	//show view
 	jQuery("#login_view").fadeIn();
 	
-	jQuery("#login").focus();
+	jQuery("#logged_out_login").focus();
 }
 
 

src/main/client/ui/manage_account_presenter.js

 	jQuery(".man_opt_option").hide();
 	switch(option_to_show) {
 		case "#man_opt_manage_bookmarks":
+			jQuery("#search_field").focus();//TODO there is still a bug... does not get called on every view
 		case "#man_opt_import_export":
 		case "#man_opt_change_account":
 		case "#man_opt_delete_account":

src/main/client/ui/manage_bookmarks_presenter.js

 /**
  * bookmaak.ui.onClickDeleteBookmark(Number)
  * 
- * Removes the bookmark specified by **index**.
+ * Removes the bookmark specified by **bookmark_id**.
  * 
- * **index** the index
+ * **bookmark_id** the id of the bookmark
  **/
-bookmaak.ui.onClickDeleteBookmark = function(index) {
+bookmaak.ui.onClickDeleteBookmark = function(bookmark_id) {
 	
-	console.log("onClickDeleteBookmark(index = "+index+")");
+	console.log("onClickDeleteBookmark(bookmark_id = "+bookmark_id+")");
 	console.debug(bookmaak.controller.Controller.last_search_result);
-	//get the bookmark thats meant to be deleted
-	var bookmark_to_delete = bookmaak.controller.Controller.last_search_result[index];
 	
-	//call the controller to delete it
-	bookmaak.controller.Controller.deleteBookmark(bookmark_to_delete);
+	//call the controller to delete the bookmark
+	bookmaak.controller.Controller.deleteBookmark(bookmark_id);
 	
 	bookmaak.ui.refreshSearchResult();
 };
 /**
  * bookmaak.ui.onClickEditBookmark(Number)
  * 
- * Shows a view to edit the bookmark specified by **index**.
+ * Shows a view to edit the bookmark specified by **bookmark_id**.
  * 
- * **index** the index of the last_search_result
+ * **bookmark_id** the id of the bookmark
  **/
 bookmaak.ui.onClickEditBookmark = function(index) {
 	
 	console.log("onClickEditBookmark(index = "+index+")");
 	
-	//get the bookmark to be edited
-	var bookmark_to_edit = bookmaak.controller.Controller.last_search_result[index];
-
 	//TODO show component... perhaps componentize the new bookmark controls
 	//TODO show edit view
 };
 		var bookmark = result[i];
 		
 		jQuery("#bookmarks").append(
-			'<li id="'+i+'" class="bookmark">' +
+			'<li id="'+bookmark.getId()+'" class="bookmark">' +
 				'<input class="selectlink" type="checkbox" />' +
 				'<a class="link" href="'+bookmark.getUrl()+'">'+bookmark.getTitle()+'</a>' +
-				createBookmark_buttonsFor(i) +
+				createBookmark_buttonsFor(bookmark.getId()) +
 				'<br/>' +
 				'<strong>tags:</strong><span class="tags">'+bookmark.getTags().toString()+'</span>' +
 				'<br/>' +