accurator/commit

Added check whether form is already shown, resolves #240

authorChris Dijkshoorn
Wed Apr 6 16:39:03 2016 +0200
committerChris Dijkshoorn
Wed Apr 6 16:39:03 2016 +0200
commit477d51f9347b764cf1bca91b6bb921d157c470ec
tree3ef880114c1c30cb879b303777289bf7010dd108
parent1c2d58a8c49c6347238954aebca74bbace6afe6c
Diff style: patch stat
diff --git a/api/accurator.pl b/api/accurator.pl
index 741cf27..988845e 100644
--- a/api/accurator.pl
+++ b/api/accurator.pl
@@ -348,7 +348,8 @@ get_parameters_user_info(Request, Options) :-
     http_parameters(Request,
         [attribute(Attribute,
 			[description('Attribute for which values are retrieved'),
-			 optional(false)]),
+			 optional(false),
+			 oneof(form_personal_shown, form_internet_shown)]),
 		 user(User,
 			[description('User for which values are retrieved'),
 			 default(LoggedinUser)])]),
diff --git a/web/js/components/utilities.js b/web/js/components/utilities.js
index 4f3a944..5ee825e 100644
--- a/web/js/components/utilities.js
+++ b/web/js/components/utilities.js
@@ -238,6 +238,26 @@ function alertMessage(title, text, type) {
 					$.el.p(text)))));
 }
 
+function showForm(type, questions, locale) {
+	var formShown = type + "_shown";
+
+	get_user_info(formShown)
+	.then(function(info) {
+		// show form if not shown before
+		if (!info[formShown]) {
+			var form = new Form(type, questions, locale);
+
+			form.addText().then(function() {
+				var setInfo = {};
+
+				$("#eventsDiv").prepend(form.node);
+				setInfo[formShown] = true;
+				save_user_info(setInfo);
+			});
+		}
+	});
+}
+
 function populateNavbar(userName, linkList, locale) {
 	// only popluate navbar when no experiment is running
 	if(typeof experiment === "undefined" || experiment === "none") {
diff --git a/web/js/item.js b/web/js/item.js
index 4f97623..1037fc1 100644
--- a/web/js/item.js
+++ b/web/js/item.js
@@ -116,44 +116,32 @@ function initLabels(labelData) {
 function events(user, locale, labels) {
 	return $.getJSON("annotations", {uri:user, type:"user"})
 	.then(function(annotations) {
-		console.log(annotations.length);
 		if (annotations.length === 0) {
 			alertMessage(labels.itemHdrFirst, labels.itemTxtFirst, 'success');
 		}
 
-		if (annotations.length === 26) {
-			console.log("get info");
-			get_user_info("form_peronal_shown")
-			.then(function(info) {
-				console.log("check whether to show form", info.form_peronal_shown);
-				if (!info.form_peronal_shown) {
-					console.log("should show form");
-				}
-			});
-
-			var formPersonal = new Form(
-				"formPersonal",
-				["country", "language", "education", "gender", "birthDate"],
+		if (annotations.length === 5) {
+			showForm(
+				"form_peronal",
+				["country",
+				"language",
+				"education",
+				"gender",
+				"birthDate"],
 				locale
 			);
-
-			formPersonal.addText().then(function() {
-				$("#eventsDiv").prepend(formPersonal.node);
-				save_user_info({"form_peronal_shown": true});
-			});
 		}
 
 		if (annotations.length === 10) {
-			var formInternet = new Form(
-				"formInternet",
-				["socialNetwork", "taggingSites", "taggingExperience", "mail", "mailCheck"],
+			showForm(
+				"form_internet",
+				["socialNetwork",
+				"taggingSites",
+				"taggingExperience",
+				"mail",
+				"mailCheck"],
 				locale
 			);
-
-			formInternet.addText().then(function() {
-				$("#eventsDiv").prepend(formInternet.node);
-				save_user_info({"form_internet_shown": true});
-			});
 		}
 	});
 }