changeset 550:aa55372146a0 Dev_main

Bug #1624 fix: New comment box management node in InterfaceContext.
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Tue, 23 Feb 2016 10:49:48 +0000
parents 3898754d5428
children 5cd12e23b195
files core.js interfaces/AB.js interfaces/ape.js interfaces/discrete.js interfaces/horizontal-sliders.js interfaces/mushra.js
diffstat 6 files changed, 93 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/core.js	Mon Feb 22 21:39:38 2016 +0000
+++ b/core.js	Tue Feb 23 10:49:48 2016 +0000
@@ -2360,7 +2360,7 @@
 	this.newPage = function(audioHolderObject,store)
 	{
 		audioEngineContext.newTestPage(audioHolderObject,store);
-		interfaceContext.deleteCommentBoxes();
+		interfaceContext.commentBoxes.deleteCommentBoxes();
 		interfaceContext.deleteCommentQuestions();
 		loadTest(audioHolderObject,store);
 	};
@@ -2408,58 +2408,88 @@
 		return node;
 	};
 	
-	this.commentBoxes = [];
-	this.elementCommentBox = function(audioObject) {
-		var element = audioObject.specification;
-		this.audioObject = audioObject;
-		this.id = audioObject.id;
-		var audioHolderObject = audioObject.specification.parent;
-		// Create document objects to hold the comment boxes
-		this.trackComment = document.createElement('div');
-		this.trackComment.className = 'comment-div';
-		this.trackComment.id = 'comment-div-'+audioObject.id;
-		// Create a string next to each comment asking for a comment
-		this.trackString = document.createElement('span');
-		this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.interfaceDOM.getPresentedId();
-		// Create the HTML5 comment box 'textarea'
-		this.trackCommentBox = document.createElement('textarea');
-		this.trackCommentBox.rows = '4';
-		this.trackCommentBox.cols = '100';
-		this.trackCommentBox.name = 'trackComment'+audioObject.id;
-		this.trackCommentBox.className = 'trackComment';
-		var br = document.createElement('br');
-		// Add to the holder.
-		this.trackComment.appendChild(this.trackString);
-		this.trackComment.appendChild(br);
-		this.trackComment.appendChild(this.trackCommentBox);
-		
-		this.exportXMLDOM = function() {
-			var root = document.createElement('comment');
-            var question = document.createElement('question');
-            question.textContent = this.trackString.textContent;
-            var response = document.createElement('response');
-            response.textContent = this.trackCommentBox.value;
-            console.log("Comment frag-"+this.id+": "+response.textContent);
-            root.appendChild(question);
-            root.appendChild(response);
-			return root;
-		};
-		this.resize = function()
-		{
-			var boxwidth = (window.innerWidth-100)/2;
-			if (boxwidth >= 600)
-			{
-				boxwidth = 600;
-			}
-			else if (boxwidth < 400)
-			{
-				boxwidth = 400;
-			}
-			this.trackComment.style.width = boxwidth+"px";
-			this.trackCommentBox.style.width = boxwidth-6+"px";
-		};
-		this.resize();
-	};
+	this.commentBoxes = new function() {
+        this.boxes = [];
+        this.injectPoint = null;
+        this.elementCommentBox = function(audioObject) {
+            var element = audioObject.specification;
+            this.audioObject = audioObject;
+            this.id = audioObject.id;
+            var audioHolderObject = audioObject.specification.parent;
+            // Create document objects to hold the comment boxes
+            this.trackComment = document.createElement('div');
+            this.trackComment.className = 'comment-div';
+            this.trackComment.id = 'comment-div-'+audioObject.id;
+            // Create a string next to each comment asking for a comment
+            this.trackString = document.createElement('span');
+            this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.interfaceDOM.getPresentedId();
+            // Create the HTML5 comment box 'textarea'
+            this.trackCommentBox = document.createElement('textarea');
+            this.trackCommentBox.rows = '4';
+            this.trackCommentBox.cols = '100';
+            this.trackCommentBox.name = 'trackComment'+audioObject.id;
+            this.trackCommentBox.className = 'trackComment';
+            var br = document.createElement('br');
+            // Add to the holder.
+            this.trackComment.appendChild(this.trackString);
+            this.trackComment.appendChild(br);
+            this.trackComment.appendChild(this.trackCommentBox);
+
+            this.exportXMLDOM = function() {
+                var root = document.createElement('comment');
+                var question = document.createElement('question');
+                question.textContent = this.trackString.textContent;
+                var response = document.createElement('response');
+                response.textContent = this.trackCommentBox.value;
+                console.log("Comment frag-"+this.id+": "+response.textContent);
+                root.appendChild(question);
+                root.appendChild(response);
+                return root;
+            };
+            this.resize = function()
+            {
+                var boxwidth = (window.innerWidth-100)/2;
+                if (boxwidth >= 600)
+                {
+                    boxwidth = 600;
+                }
+                else if (boxwidth < 400)
+                {
+                    boxwidth = 400;
+                }
+                this.trackComment.style.width = boxwidth+"px";
+                this.trackCommentBox.style.width = boxwidth-6+"px";
+            };
+            this.resize();
+        };
+        this.createCommentBox = function(audioObject) {
+            var node = new this.elementCommentBox(audioObject);
+            this.boxes.push(node);
+            audioObject.commentDOM = node;
+            return node;
+        };
+        this.sortCommentBoxes = function() {
+            this.boxes.sort(function(a,b){return a.id - b.id;});
+        };
+
+        this.showCommentBoxes = function(inject, sort) {
+            this.injectPoint = inject;
+            if (sort) {this.sortCommentBoxes();}
+            for (var box of this.boxes) {
+                inject.appendChild(box.trackComment);
+            }
+        };
+
+        this.deleteCommentBoxes = function() {
+            if (this.injectPoint != null) {
+                for (var box of this.boxes) {
+                    this.injectPoint.removeChild(box.trackComment);
+                }
+                this.injectPoint = null;
+            }
+            this.boxes = [];
+        };
+    }
 	
 	this.commentQuestions = [];
 	
@@ -2728,28 +2758,6 @@
 		};
 		this.resize();
 	};
-
-	this.createCommentBox = function(audioObject) {
-		var node = new this.elementCommentBox(audioObject);
-		this.commentBoxes.push(node);
-		audioObject.commentDOM = node;
-		return node;
-	};
-	
-	this.sortCommentBoxes = function() {
-		this.commentBoxes.sort(function(a,b){return a.id - b.id;});
-	};
-	
-	this.showCommentBoxes = function(inject, sort) {
-		if (sort) {interfaceContext.sortCommentBoxes();}
-		for (var box of interfaceContext.commentBoxes) {
-			inject.appendChild(box.trackComment);
-		}
-	};
-	
-	this.deleteCommentBoxes = function() {
-		this.commentBoxes = [];
-	};
 	
 	this.createCommentQuestion = function(element) {
 		var node;
--- a/interfaces/AB.js	Mon Feb 22 21:39:38 2016 +0000
+++ b/interfaces/AB.js	Tue Feb 23 10:49:48 2016 +0000
@@ -158,9 +158,9 @@
         // Generate one comment box per presented page
         for (var element of audioEngineContext.audioObjects)
         {
-            interfaceContext.createCommentBox(element);
+            interfaceContext.commentBoxes.createCommentBox(element);
         }
-        interfaceContext.showCommentBoxes(commentHolder,true);
+        interfaceContext.commentBoxes.showCommentBoxes(commentHolder,true);
     }
 	resizeWindow(null);
 }
--- a/interfaces/ape.js	Mon Feb 22 21:39:38 2016 +0000
+++ b/interfaces/ape.js	Tue Feb 23 10:49:48 2016 +0000
@@ -356,7 +356,7 @@
 			// Create a slider per track
 			var sliderNode = new sliderObject(audioObject,interfaceObj);
 			audioObject.bindInterface(sliderNode);
-            interfaceContext.createCommentBox(audioObject);
+            interfaceContext.commentBoxes.createCommentBox(audioObject);
 		}
 	});
 	
@@ -433,7 +433,7 @@
 	
 	
 	if (audioHolderObject.showElementComments) {
-		interfaceContext.showCommentBoxes(feedbackHolder,true);
+		interfaceContext.commentBoxes.showCommentBoxes(feedbackHolder,true);
 	}
 	
 	$(audioHolderObject.commentQuestions).each(function(index,element) {
--- a/interfaces/discrete.js	Mon Feb 22 21:39:38 2016 +0000
+++ b/interfaces/discrete.js	Tue Feb 23 10:49:48 2016 +0000
@@ -201,7 +201,7 @@
 			var sliderObj = new discreteObject(audioObject,label,interfaceScales);
 			sliderBox.appendChild(sliderObj.holder);
 			audioObject.bindInterface(sliderObj);
-            interfaceContext.createCommentBox(audioObject);
+            interfaceContext.commentBoxes.createCommentBox(audioObject);
 			label += 1;
 		}
         
@@ -209,7 +209,7 @@
 	
     if (page.showElementComments)
     {
-        interfaceContext.showCommentBoxes(feedbackHolder,true);
+        interfaceContext.commentBoxes.showCommentBoxes(feedbackHolder,true);
     }
     
 	// Auto-align
--- a/interfaces/horizontal-sliders.js	Mon Feb 22 21:39:38 2016 +0000
+++ b/interfaces/horizontal-sliders.js	Tue Feb 23 10:49:48 2016 +0000
@@ -210,14 +210,14 @@
 			}
 			sliderBox.appendChild(sliderObj.holder);
 			audioObject.bindInterface(sliderObj);
-            interfaceContext.createCommentBox(audioObject);
+            interfaceContext.commentBoxes.createCommentBox(audioObject);
 			label += 1;
 		}
         
 	});
 	if (page.showElementComments)
     {
-        interfaceContext.showCommentBoxes(feedbackHolder,true);
+        interfaceContext.commentBoxes.showCommentBoxes(feedbackHolder,true);
     }
 	// Auto-align
 	resizeWindow(null);
--- a/interfaces/mushra.js	Mon Feb 22 21:39:38 2016 +0000
+++ b/interfaces/mushra.js	Tue Feb 23 10:49:48 2016 +0000
@@ -208,14 +208,14 @@
 			}
 			sliderBox.appendChild(sliderObj.holder);
 			audioObject.bindInterface(sliderObj);
-            interfaceContext.createCommentBox(audioObject);
+            interfaceContext.commentBoxes.createCommentBox(audioObject);
 			label += 1;
 		}
         
 	});
     
     if (audioHolderObject.showElementComments) {
-		interfaceContext.showCommentBoxes(feedbackHolder,true);
+		interfaceContext.commentBoxes.showCommentBoxes(feedbackHolder,true);
 	}
 	
 	$(audioHolderObject.commentQuestions).each(function(index,element) {