accurator/commit

Restored navigation on item page.

authorChris Dijkshoorn
Thu Mar 24 17:26:51 2016 +0100
committerChris Dijkshoorn
Thu Mar 24 17:26:51 2016 +0100
commit66f89e76b3473b55a53e92af2cd8f373d4d9166a
treed88ca1d9013b5bdeb9d87402c33092692b2c7cb8
parent6956cc612a2dd5a31026d793aef7a2751d0138de
Diff style: patch stat
diff --git a/api/accurator.pl b/api/accurator.pl
index 618193a..7c265f0 100644
--- a/api/accurator.pl
+++ b/api/accurator.pl
@@ -470,6 +470,7 @@ html({|html(ImageUrl)||
 <script type="text/javascript" src="js/lib/bloodhound.js"></script>
 <script type="text/javascript" src="js/lib/typeahead.js"></script>
 <script type="text/javascript" src="js/lib/annotorious.min.js"></script>
+<script type="text/javascript" src="js/components/path.js"></script>
 <script type="text/javascript" src="js/components/deniche-plugin.js"></script>
 <script type="text/javascript" src="js/components/utilities.js"></script>
 <script type="text/javascript" src="js/components/annotations.js"></script>
diff --git a/web/js/components/path.js b/web/js/components/path.js
index 54e75d7..ae3a6dd 100644
--- a/web/js/components/path.js
+++ b/web/js/components/path.js
@@ -14,7 +14,7 @@ function Path(path, parentId, query) {
 
 Path.prototype.init = function(query) {
     this.node = this.html();
-    if (query) ? this.query = query : this.query = "query";
+    query ? this.query = query : this.query = "query";
     if (typeof this.path === 'string' || this.path instanceof String) {
         this.addTitle();
     }
@@ -46,7 +46,9 @@ Path.prototype.enrich = function() {
     var _path = this;
 
     // no need for enriching if we have a title
-    if (typeof this.path === 'string' || this.path instanceof String) return;
+    if (typeof this.path === 'string' || this.path instanceof String) {
+        return $.Deferred().resolve().promise();
+    }
 
 	return $.ajax({type: "POST",
 		url: "metadata",
diff --git a/web/js/item.js b/web/js/item.js
index 1abb2a6..52c5c7c 100644
--- a/web/js/item.js
+++ b/web/js/item.js
@@ -80,7 +80,7 @@ function itemInit() {
 			// Only show path when cluster is available TODO: remove ugly check for undefined
 			if((localStorage.getItem("uris") !== null) &&
 				(localStorage.getItem("uris") !== "undefined")) {
-				addNavigation();
+				addNavigation(uri);
 			}
 
 			addButtonEvents(user);
@@ -124,18 +124,16 @@ function events(user, labels) {
 	});
 }
 
-function addNavigation() {
+function addNavigation(uri) {
 	var uris =  JSON.parse(localStorage.getItem("uris"));
-	var path =  JSON.parse(localStorage.getItem("path"));
-
-	console.log(uris, path);
-	//TODO: restore path functionallity after making it an object
-	// query = localStorage.getItem("query");
-	// var cluster = JSON.parse(localStorage.getItem("currentCluster"));
-	// console.log("cluster", cluster);
-	// $("#path").append(pathHtmlElements(cluster.path));
-	// unfoldPathEvent("#path", cluster.path);
-	// addNavigationButtonEvents();
+	var pathArray =  JSON.parse(localStorage.getItem("path"));
+	var path = new Path(pathArray, itemDivPath);
+
+	path.enrich()
+	.then(function() {
+		$("#itemDivPath").append(path.node);
+		addNavigationButtonEvents(uris, uri);
+	});
 }
 
 function addButtonEvents(user) {
@@ -155,26 +153,22 @@ function addButtonEvents(user) {
 	});
 }
 
-function addNavigationButtonEvents() {
-	var index = parseInt(localStorage.getItem("itemIndex"));
-	var cluster = JSON.parse(localStorage.getItem("currentCluster"));
-	var items = cluster.items;
+function addNavigationButtonEvents(uris, uri) {
+	var index = uris.indexOf(uri);
 
-	if(index === 0) {
+	if (index === 0) {
 		$("#itemBtnPrevious").attr("disabled", "disabled");
 	} else {
 		$("#itemBtnPrevious").click(function() {
-			localStorage.setItem("itemIndex", index - 1);
-			document.location.href = "annotate.html?uri=" + items[index -1].uri;
+			document.location.href = "item.html?uri=" + uris[index -1];
 		});
 	}
 
-	if(index === items.length-1) {
+	if(index === uris.length-1) {
 		$("#itemBtnNext").attr("disabled", "disabled");
 	} else {
 		$("#itemBtnNext").click(function() {
-			localStorage.setItem("itemIndex", index + 1);
-			document.location.href = "annotate.html?uri=" + items[index + 1].uri;
+			document.location.href = "item.html?uri=" + uris[index + 1];
 		});
 	}
 }