changeset 2582:224842b28bf2

Completed merge of current spec with new nodes. Working example in AB_example. Gives console warnings.
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Mon, 31 Oct 2016 16:08:24 +0000
parents 01df891a3390
children 5f7c11fa5f83
files js/specification.js tests/examples/AB_example.xml
diffstat 2 files changed, 32 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/js/specification.js	Mon Oct 31 15:42:37 2016 +0000
+++ b/js/specification.js	Mon Oct 31 16:08:24 2016 +0000
@@ -195,7 +195,7 @@
 
         this.OptionNode = function (specification) {
             this.type = undefined;
-            this.schema = specification.schema.getAllElementsByName('surveyentry')[0];
+            this.schema = undefined;
             this.id = undefined;
             this.name = undefined;
             this.mandatory = undefined;
@@ -208,6 +208,7 @@
             this.conditions = [];
 
             this.decode = function (parent, child) {
+                this.schema = specification.schema.getAllElementsByName(child.nodeName)[0];
                 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
                 for (var i in attributeMap) {
                     if (isNaN(Number(i)) == true) {
@@ -226,6 +227,15 @@
                             break;
                     }
                 }
+                if (child.nodeName == 'surveyentry') {
+                    console.log("NOTE - Use of <surveyelement> is now deprecated. Whilst these will still work, newer nodes and tighter error checking will not be enforced");
+                    console.log("Please use the newer, type specifc nodes");
+                    if (!this.type) {
+                        throw ("Type not specified");
+                    }
+                } else {
+                    this.type = child.nodeName.split('survey')[1];
+                }
                 this.statement = child.getElementsByTagName('statement')[0].textContent;
                 if (this.type == "checkbox" || this.type == "radio") {
                     var children = child.getElementsByTagName('option');
@@ -242,6 +252,17 @@
                             });
                         }
                     }
+                } else if (this.type == "slider") {
+                    this.leftText = "";
+                    this.rightText = "";
+                    var minText = child.getElementsByTagName("minText");
+                    var maxText = child.getElementsByTagName("maxText");
+                    if (minText.length > 0) {
+                        this.leftText = minText[0].textContent;
+                    }
+                    if (maxText.length > 0) {
+                        this.rightText = maxText[0].textContent;
+                    }
                 }
                 var conditionElements = child.getElementsByTagName("conditional");
                 for (var i = 0; i < conditionElements.length; i++) {
@@ -341,11 +362,12 @@
             } else if (this.location == 'after') {
                 this.location = 'post';
             }
-            var children = xml.getAllElementsByTagName('surveyentry');
-            for (var i = 0; i < children.length; i++) {
+            var child = xml.firstElementChild
+            while (child) {
                 var node = new this.OptionNode(this.specification);
-                node.decode(parent, children[i]);
+                node.decode(parent, child);
                 this.options.push(node);
+                child = child.nextElementSibling;
             }
             if (this.options.length == 0) {
                 console.log("Empty survey node");
--- a/tests/examples/AB_example.xml	Mon Oct 31 15:42:37 2016 +0000
+++ b/tests/examples/AB_example.xml	Mon Oct 31 16:08:24 2016 +0000
@@ -2,20 +2,20 @@
     <waet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test-schema.xsd">
         <setup interface="AB" projectReturn="save.php" randomiseOrder='true' poolSize="2" loudness="-23" playOne="true">
             <survey location="before">
-                <surveyentry type="question" id="sessionId" mandatory="true">
+                <surveyquestion id="sessionId" mandatory="true">
                     <statement>Please enter your name.</statement>
-                </surveyentry>
-                <surveyentry type="checkbox" id="checkboxtest" mandatory="true">
+                </surveyquestion>
+                <surveycheckbox id="checkboxtest" mandatory="true">
                     <statement>Please select with which activities you have any experience (example checkbox question)</statement>
                     <option name="musician">Playing a musical instrument</option>
                     <option name="soundengineer">Recording or mixing audio</option>
                     <option name="developer">Developing audio software</option>
                     <option name="hwdesigner">Designing or building audio hardware</option>
                     <option name="researcher">Research in the field of audio</option>
-                </surveyentry>
-                <surveyentry type="statement" id="test-intro">
+                </surveycheckbox>
+                <surveystatement id="test-intro">
                     <statement>This is an example of an 'AB'-style test, with two pages, using the test stimuli in 'example_eval/'.</statement>
-                </surveyentry>
+                </surveystatement>
             </survey>
             <survey location="after">
                 <surveyentry type="question" id="location" mandatory="true" boxsize="large">