comparison core.js @ 1209:943b0ba7ec83

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 0e49d874ba97
children 845047ed3814
comparison
equal deleted inserted replaced
1208:08f6b58b7c20 1209:943b0ba7ec83
2358 this.insertPoint = document.getElementById("topLevelBody"); 2358 this.insertPoint = document.getElementById("topLevelBody");
2359 2359
2360 this.newPage = function(audioHolderObject,store) 2360 this.newPage = function(audioHolderObject,store)
2361 { 2361 {
2362 audioEngineContext.newTestPage(audioHolderObject,store); 2362 audioEngineContext.newTestPage(audioHolderObject,store);
2363 interfaceContext.deleteCommentBoxes(); 2363 interfaceContext.commentBoxes.deleteCommentBoxes();
2364 interfaceContext.deleteCommentQuestions(); 2364 interfaceContext.deleteCommentQuestions();
2365 loadTest(audioHolderObject,store); 2365 loadTest(audioHolderObject,store);
2366 }; 2366 };
2367 2367
2368 // Bounded by interface!! 2368 // Bounded by interface!!
2406 node.appendChild(userAgent); 2406 node.appendChild(userAgent);
2407 node.appendChild(screen); 2407 node.appendChild(screen);
2408 return node; 2408 return node;
2409 }; 2409 };
2410 2410
2411 this.commentBoxes = []; 2411 this.commentBoxes = new function() {
2412 this.elementCommentBox = function(audioObject) { 2412 this.boxes = [];
2413 var element = audioObject.specification; 2413 this.injectPoint = null;
2414 this.audioObject = audioObject; 2414 this.elementCommentBox = function(audioObject) {
2415 this.id = audioObject.id; 2415 var element = audioObject.specification;
2416 var audioHolderObject = audioObject.specification.parent; 2416 this.audioObject = audioObject;
2417 // Create document objects to hold the comment boxes 2417 this.id = audioObject.id;
2418 this.trackComment = document.createElement('div'); 2418 var audioHolderObject = audioObject.specification.parent;
2419 this.trackComment.className = 'comment-div'; 2419 // Create document objects to hold the comment boxes
2420 this.trackComment.id = 'comment-div-'+audioObject.id; 2420 this.trackComment = document.createElement('div');
2421 // Create a string next to each comment asking for a comment 2421 this.trackComment.className = 'comment-div';
2422 this.trackString = document.createElement('span'); 2422 this.trackComment.id = 'comment-div-'+audioObject.id;
2423 this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.interfaceDOM.getPresentedId(); 2423 // Create a string next to each comment asking for a comment
2424 // Create the HTML5 comment box 'textarea' 2424 this.trackString = document.createElement('span');
2425 this.trackCommentBox = document.createElement('textarea'); 2425 this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.interfaceDOM.getPresentedId();
2426 this.trackCommentBox.rows = '4'; 2426 // Create the HTML5 comment box 'textarea'
2427 this.trackCommentBox.cols = '100'; 2427 this.trackCommentBox = document.createElement('textarea');
2428 this.trackCommentBox.name = 'trackComment'+audioObject.id; 2428 this.trackCommentBox.rows = '4';
2429 this.trackCommentBox.className = 'trackComment'; 2429 this.trackCommentBox.cols = '100';
2430 var br = document.createElement('br'); 2430 this.trackCommentBox.name = 'trackComment'+audioObject.id;
2431 // Add to the holder. 2431 this.trackCommentBox.className = 'trackComment';
2432 this.trackComment.appendChild(this.trackString); 2432 var br = document.createElement('br');
2433 this.trackComment.appendChild(br); 2433 // Add to the holder.
2434 this.trackComment.appendChild(this.trackCommentBox); 2434 this.trackComment.appendChild(this.trackString);
2435 2435 this.trackComment.appendChild(br);
2436 this.exportXMLDOM = function() { 2436 this.trackComment.appendChild(this.trackCommentBox);
2437 var root = document.createElement('comment'); 2437
2438 var question = document.createElement('question'); 2438 this.exportXMLDOM = function() {
2439 question.textContent = this.trackString.textContent; 2439 var root = document.createElement('comment');
2440 var response = document.createElement('response'); 2440 var question = document.createElement('question');
2441 response.textContent = this.trackCommentBox.value; 2441 question.textContent = this.trackString.textContent;
2442 console.log("Comment frag-"+this.id+": "+response.textContent); 2442 var response = document.createElement('response');
2443 root.appendChild(question); 2443 response.textContent = this.trackCommentBox.value;
2444 root.appendChild(response); 2444 console.log("Comment frag-"+this.id+": "+response.textContent);
2445 return root; 2445 root.appendChild(question);
2446 }; 2446 root.appendChild(response);
2447 this.resize = function() 2447 return root;
2448 { 2448 };
2449 var boxwidth = (window.innerWidth-100)/2; 2449 this.resize = function()
2450 if (boxwidth >= 600) 2450 {
2451 { 2451 var boxwidth = (window.innerWidth-100)/2;
2452 boxwidth = 600; 2452 if (boxwidth >= 600)
2453 } 2453 {
2454 else if (boxwidth < 400) 2454 boxwidth = 600;
2455 { 2455 }
2456 boxwidth = 400; 2456 else if (boxwidth < 400)
2457 } 2457 {
2458 this.trackComment.style.width = boxwidth+"px"; 2458 boxwidth = 400;
2459 this.trackCommentBox.style.width = boxwidth-6+"px"; 2459 }
2460 }; 2460 this.trackComment.style.width = boxwidth+"px";
2461 this.resize(); 2461 this.trackCommentBox.style.width = boxwidth-6+"px";
2462 }; 2462 };
2463 this.resize();
2464 };
2465 this.createCommentBox = function(audioObject) {
2466 var node = new this.elementCommentBox(audioObject);
2467 this.boxes.push(node);
2468 audioObject.commentDOM = node;
2469 return node;
2470 };
2471 this.sortCommentBoxes = function() {
2472 this.boxes.sort(function(a,b){return a.id - b.id;});
2473 };
2474
2475 this.showCommentBoxes = function(inject, sort) {
2476 this.injectPoint = inject;
2477 if (sort) {this.sortCommentBoxes();}
2478 for (var box of this.boxes) {
2479 inject.appendChild(box.trackComment);
2480 }
2481 };
2482
2483 this.deleteCommentBoxes = function() {
2484 if (this.injectPoint != null) {
2485 for (var box of this.boxes) {
2486 this.injectPoint.removeChild(box.trackComment);
2487 }
2488 this.injectPoint = null;
2489 }
2490 this.boxes = [];
2491 };
2492 }
2463 2493
2464 this.commentQuestions = []; 2494 this.commentQuestions = [];
2465 2495
2466 this.commentBox = function(commentQuestion) { 2496 this.commentBox = function(commentQuestion) {
2467 this.specification = commentQuestion; 2497 this.specification = commentQuestion;
2725 text.style.marginRight = spanMargin; 2755 text.style.marginRight = spanMargin;
2726 text.style.marginLeft = spanMargin; 2756 text.style.marginLeft = spanMargin;
2727 } 2757 }
2728 }; 2758 };
2729 this.resize(); 2759 this.resize();
2730 };
2731
2732 this.createCommentBox = function(audioObject) {
2733 var node = new this.elementCommentBox(audioObject);
2734 this.commentBoxes.push(node);
2735 audioObject.commentDOM = node;
2736 return node;
2737 };
2738
2739 this.sortCommentBoxes = function() {
2740 this.commentBoxes.sort(function(a,b){return a.id - b.id;});
2741 };
2742
2743 this.showCommentBoxes = function(inject, sort) {
2744 if (sort) {interfaceContext.sortCommentBoxes();}
2745 for (var box of interfaceContext.commentBoxes) {
2746 inject.appendChild(box.trackComment);
2747 }
2748 };
2749
2750 this.deleteCommentBoxes = function() {
2751 this.commentBoxes = [];
2752 }; 2760 };
2753 2761
2754 this.createCommentQuestion = function(element) { 2762 this.createCommentQuestion = function(element) {
2755 var node; 2763 var node;
2756 if (element.type == 'question') { 2764 if (element.type == 'question') {