comparison js/core.js @ 2711:898a6da5ff6c

Improved creation of comment-question boxes for radio and checkbox entries
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Thu, 30 Mar 2017 17:05:07 +0100
parents 2395223deef2
children eece6007daa5
comparison
equal deleted inserted replaced
2710:549e2f97a401 2711:898a6da5ff6c
2567 this.holder = document.createElement('div'); 2567 this.holder = document.createElement('div');
2568 this.holder.className = 'comment-div'; 2568 this.holder.className = 'comment-div';
2569 // Create a string next to each comment asking for a comment 2569 // Create a string next to each comment asking for a comment
2570 this.string = document.createElement('span'); 2570 this.string = document.createElement('span');
2571 this.string.innerHTML = commentQuestion.statement; 2571 this.string.innerHTML = commentQuestion.statement;
2572 var br = document.createElement('br');
2573 // Add to the holder. 2572 // Add to the holder.
2574 this.holder.appendChild(this.string); 2573 this.holder.appendChild(this.string);
2575 this.holder.appendChild(br);
2576 this.options = []; 2574 this.options = [];
2577 this.inputs = document.createElement('div'); 2575 this.inputs = document.createElement('div');
2578 this.span = document.createElement('div'); 2576 this.inputs.className = "comment-checkbox-inputs-holder";
2579 this.inputs.align = 'center';
2580 this.inputs.style.marginLeft = '12px';
2581 this.inputs.className = "comment-radio-inputs-holder";
2582 this.span.style.marginLeft = '12px';
2583 this.span.align = 'center';
2584 this.span.style.marginTop = '15px';
2585 this.span.className = "comment-radio-span-holder";
2586 2577
2587 var optCount = commentQuestion.options.length; 2578 var optCount = commentQuestion.options.length;
2588 commentQuestion.options.forEach(function (optNode) { 2579 for (var i = 0; i < optCount; i++) {
2589 var div = document.createElement('div'); 2580 var div = document.createElement('div');
2590 div.style.width = '80px'; 2581 div.className = "comment-checkbox-inputs-flex";
2591 div.style.float = 'left'; 2582
2583 var span = document.createElement('span');
2584 span.textContent = commentQuestion.options[i].text;
2585 span.className = 'comment-radio-span';
2586 div.appendChild(span);
2587
2592 var input = document.createElement('input'); 2588 var input = document.createElement('input');
2593 input.type = 'radio'; 2589 input.type = 'radio';
2594 input.name = commentQuestion.id; 2590 input.name = commentQuestion.id;
2595 input.setAttribute('setvalue', optNode.name); 2591 input.setAttribute('setvalue', commentQuestion.options[i].name);
2596 input.className = 'comment-radio'; 2592 input.className = 'comment-radio';
2597 div.appendChild(input); 2593 div.appendChild(input);
2594
2598 this.inputs.appendChild(div); 2595 this.inputs.appendChild(div);
2599
2600
2601 div = document.createElement('div');
2602 div.style.width = '80px';
2603 div.style.float = 'left';
2604 div.align = 'center';
2605 var span = document.createElement('span');
2606 span.textContent = optNode.text;
2607 span.className = 'comment-radio-span';
2608 div.appendChild(span);
2609 this.span.appendChild(div);
2610 this.options.push(input); 2596 this.options.push(input);
2611 }, this); 2597 }
2612 this.holder.appendChild(this.span);
2613 this.holder.appendChild(this.inputs); 2598 this.holder.appendChild(this.inputs);
2614 2599
2615 this.exportXMLDOM = function (storePoint) { 2600 this.exportXMLDOM = function (storePoint) {
2616 var root = storePoint.parent.document.createElement('comment'); 2601 var root = storePoint.parent.document.createElement('comment');
2617 root.id = this.specification.id; 2602 root.id = this.specification.id;
2645 boxwidth = 600; 2630 boxwidth = 600;
2646 } else if (boxwidth < 400) { 2631 } else if (boxwidth < 400) {
2647 boxwidth = 400; 2632 boxwidth = 400;
2648 } 2633 }
2649 this.holder.style.width = boxwidth + "px"; 2634 this.holder.style.width = boxwidth + "px";
2650 var text = this.holder.getElementsByClassName("comment-radio-span-holder")[0];
2651 var options = this.holder.getElementsByClassName("comment-radio-inputs-holder")[0];
2652 var optCount = options.childElementCount;
2653 var spanMargin = Math.floor(((boxwidth - 20 - (optCount * 80)) / (optCount)) / 2) + 'px';
2654 options = options.firstChild;
2655 text = text.firstChild;
2656 options.style.marginRight = spanMargin;
2657 options.style.marginLeft = spanMargin;
2658 text.style.marginRight = spanMargin;
2659 text.style.marginLeft = spanMargin;
2660 while (options = options.nextSibling) {
2661 text = text.nextSibling;
2662 options.style.marginRight = spanMargin;
2663 options.style.marginLeft = spanMargin;
2664 text.style.marginRight = spanMargin;
2665 text.style.marginLeft = spanMargin;
2666 }
2667 }; 2635 };
2668 this.resize(); 2636 this.resize();
2669 }; 2637 };
2670 2638
2671 this.checkboxBox = function (commentQuestion) { 2639 this.checkboxBox = function (commentQuestion) {
2674 this.holder = document.createElement('div'); 2642 this.holder = document.createElement('div');
2675 this.holder.className = 'comment-div'; 2643 this.holder.className = 'comment-div';
2676 // Create a string next to each comment asking for a comment 2644 // Create a string next to each comment asking for a comment
2677 this.string = document.createElement('span'); 2645 this.string = document.createElement('span');
2678 this.string.innerHTML = commentQuestion.statement; 2646 this.string.innerHTML = commentQuestion.statement;
2679 var br = document.createElement('br');
2680 // Add to the holder. 2647 // Add to the holder.
2681 this.holder.appendChild(this.string); 2648 this.holder.appendChild(this.string);
2682 this.holder.appendChild(br);
2683 this.options = []; 2649 this.options = [];
2684 this.inputs = document.createElement('div'); 2650 this.inputs = document.createElement('div');
2685 this.span = document.createElement('div');
2686 this.inputs.align = 'center';
2687 this.inputs.style.marginLeft = '12px';
2688 this.inputs.className = "comment-checkbox-inputs-holder"; 2651 this.inputs.className = "comment-checkbox-inputs-holder";
2689 this.span.style.marginLeft = '12px';
2690 this.span.align = 'center';
2691 this.span.style.marginTop = '15px';
2692 this.span.className = "comment-checkbox-span-holder";
2693 2652
2694 var optCount = commentQuestion.options.length; 2653 var optCount = commentQuestion.options.length;
2695 for (var i = 0; i < optCount; i++) { 2654 for (var i = 0; i < optCount; i++) {
2696 var div = document.createElement('div'); 2655 var div = document.createElement('div');
2697 div.style.width = '80px'; 2656 div.className = "comment-checkbox-inputs-flex";
2698 div.style.float = 'left'; 2657
2658 var span = document.createElement('span');
2659 span.textContent = commentQuestion.options[i].text;
2660 span.className = 'comment-radio-span';
2661 div.appendChild(span);
2662
2699 var input = document.createElement('input'); 2663 var input = document.createElement('input');
2700 input.type = 'checkbox'; 2664 input.type = 'checkbox';
2701 input.name = commentQuestion.id; 2665 input.name = commentQuestion.id;
2702 input.setAttribute('setvalue', commentQuestion.options[i].name); 2666 input.setAttribute('setvalue', commentQuestion.options[i].name);
2703 input.className = 'comment-radio'; 2667 input.className = 'comment-radio';
2704 div.appendChild(input); 2668 div.appendChild(input);
2669
2705 this.inputs.appendChild(div); 2670 this.inputs.appendChild(div);
2706
2707
2708 div = document.createElement('div');
2709 div.style.width = '80px';
2710 div.style.float = 'left';
2711 div.align = 'center';
2712 var span = document.createElement('span');
2713 span.textContent = commentQuestion.options[i].text;
2714 span.className = 'comment-radio-span';
2715 div.appendChild(span);
2716 this.span.appendChild(div);
2717 this.options.push(input); 2671 this.options.push(input);
2718 } 2672 }
2719 this.holder.appendChild(this.span);
2720 this.holder.appendChild(this.inputs); 2673 this.holder.appendChild(this.inputs);
2721 2674
2722 this.exportXMLDOM = function (storePoint) { 2675 this.exportXMLDOM = function (storePoint) {
2723 var root = storePoint.parent.document.createElement('comment'); 2676 var root = storePoint.parent.document.createElement('comment');
2724 root.id = this.specification.id; 2677 root.id = this.specification.id;
2743 boxwidth = 600; 2696 boxwidth = 600;
2744 } else if (boxwidth < 400) { 2697 } else if (boxwidth < 400) {
2745 boxwidth = 400; 2698 boxwidth = 400;
2746 } 2699 }
2747 this.holder.style.width = boxwidth + "px"; 2700 this.holder.style.width = boxwidth + "px";
2748 var text = this.holder.getElementsByClassName("comment-checkbox-span-holder")[0];
2749 var options = this.holder.getElementsByClassName("comment-checkbox-inputs-holder")[0];
2750 var optCount = options.childElementCount;
2751 var spanMargin = Math.floor(((boxwidth - 20 - (optCount * 80)) / (optCount)) / 2) + 'px';
2752 options = options.firstChild;
2753 text = text.firstChild;
2754 options.style.marginRight = spanMargin;
2755 options.style.marginLeft = spanMargin;
2756 text.style.marginRight = spanMargin;
2757 text.style.marginLeft = spanMargin;
2758 while (options = options.nextSibling) {
2759 text = text.nextSibling;
2760 options.style.marginRight = spanMargin;
2761 options.style.marginLeft = spanMargin;
2762 text.style.marginRight = spanMargin;
2763 text.style.marginLeft = spanMargin;
2764 }
2765 }; 2701 };
2766 this.resize(); 2702 this.resize();
2767 }; 2703 };
2768 2704
2769 this.sliderBox = function (commentQuestion) { 2705 this.sliderBox = function (commentQuestion) {
3024 this.slider.value = this.valueDB; 2960 this.slider.value = this.valueDB;
3025 2961
3026 if (event.stopPropagation) { 2962 if (event.stopPropagation) {
3027 event.stopPropagation(); 2963 event.stopPropagation();
3028 } 2964 }
3029 } 2965 };
3030 this.onmouseup = function () { 2966 this.onmouseup = function () {
3031 var storePoint = testState.currentStore.XMLDOM.getElementsByTagName('metric')[0].getAllElementsByName('volumeTracker'); 2967 var storePoint = testState.currentStore.XMLDOM.getElementsByTagName('metric')[0].getAllElementsByName('volumeTracker');
3032 if (storePoint.length === 0) { 2968 if (storePoint.length === 0) {
3033 storePoint = storage.document.createElement('metricresult'); 2969 storePoint = storage.document.createElement('metricresult');
3034 storePoint.setAttribute('name', 'volumeTracker'); 2970 storePoint.setAttribute('name', 'volumeTracker');
3039 var node = storage.document.createElement('movement'); 2975 var node = storage.document.createElement('movement');
3040 node.setAttribute('test-time', audioEngineContext.timer.getTestTime()); 2976 node.setAttribute('test-time', audioEngineContext.timer.getTestTime());
3041 node.setAttribute('volume', this.valueDB); 2977 node.setAttribute('volume', this.valueDB);
3042 node.setAttribute('format', 'dBFS'); 2978 node.setAttribute('format', 'dBFS');
3043 storePoint.appendChild(node); 2979 storePoint.appendChild(node);
3044 } 2980 };
3045 this.slider.addEventListener("mousemove", this); 2981 this.slider.addEventListener("mousemove", this);
3046 this.root.addEventListener("mouseup", this); 2982 this.root.addEventListener("mouseup", this);
3047 2983
3048 var title = document.createElement('div'); 2984 var title = document.createElement('div');
3049 title.innerHTML = '<span>Master Volume Control</span>'; 2985 title.innerHTML = '<span>Master Volume Control</span>';