Mercurial > hg > webaudioevaluationtool
comparison core.js @ 1026:f13b6efc4513
Feature #1208: Added radio box option to page 'commentQuestion'. Also commentQuestion nodes are now common to core.js.
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Mon, 08 Jun 2015 11:00:15 +0100 |
parents | 75302b775a4d |
children | 4e9ab4f92f20 |
comparison
equal
deleted
inserted
replaced
1025:a90495a060de | 1026:f13b6efc4513 |
---|---|
1195 this.id = xml.id; | 1195 this.id = xml.id; |
1196 this.parent = parent; | 1196 this.parent = parent; |
1197 }; | 1197 }; |
1198 | 1198 |
1199 this.commentQuestionNode = function(xml) { | 1199 this.commentQuestionNode = function(xml) { |
1200 this.childOption = function(element) { | |
1201 this.type = 'option'; | |
1202 this.name = element.getAttribute('name'); | |
1203 this.text = element.textContent; | |
1204 }; | |
1200 this.id = xml.id; | 1205 this.id = xml.id; |
1201 if (xml.getAttribute('mandatory') == 'true') {this.mandatory = true;} | 1206 if (xml.getAttribute('mandatory') == 'true') {this.mandatory = true;} |
1202 else {this.mandatory = false;} | 1207 else {this.mandatory = false;} |
1203 this.question = xml.textContent; | 1208 this.type = xml.getAttribute('type'); |
1209 if (this.type == undefined) {this.type = 'text';} | |
1210 switch (this.type) { | |
1211 case 'text': | |
1212 this.question = xml.textContent; | |
1213 break; | |
1214 case 'radio': | |
1215 var child = xml.firstElementChild; | |
1216 this.options = []; | |
1217 while (child != undefined) { | |
1218 if (child.nodeName == 'statement' && this.statement == undefined) { | |
1219 this.statement = child.textContent; | |
1220 } else if (child.nodeName == 'option') { | |
1221 this.options.push(new this.childOption(child)); | |
1222 } | |
1223 child = child.nextElementSibling; | |
1224 } | |
1225 } | |
1204 }; | 1226 }; |
1205 | 1227 |
1206 this.id = xml.id; | 1228 this.id = xml.id; |
1207 this.hostURL = xml.getAttribute('hostURL'); | 1229 this.hostURL = xml.getAttribute('hostURL'); |
1208 this.sampleRate = xml.getAttribute('sampleRate'); | 1230 this.sampleRate = xml.getAttribute('sampleRate'); |
1254 // For example, APE returns the slider position normalised in a <value> tag. | 1276 // For example, APE returns the slider position normalised in a <value> tag. |
1255 this.interfaceObjects = []; | 1277 this.interfaceObjects = []; |
1256 this.interfaceObject = function(){}; | 1278 this.interfaceObject = function(){}; |
1257 | 1279 |
1258 this.commentBoxes = []; | 1280 this.commentBoxes = []; |
1259 this.commentBox = function(audioObject) { | 1281 this.elementCommentBox = function(audioObject) { |
1260 var element = audioObject.specification; | 1282 var element = audioObject.specification; |
1261 this.audioObject = audioObject; | 1283 this.audioObject = audioObject; |
1262 this.id = audioObject.id; | 1284 this.id = audioObject.id; |
1263 var audioHolderObject = audioObject.specification.parent; | 1285 var audioHolderObject = audioObject.specification.parent; |
1264 // Create document objects to hold the comment boxes | 1286 // Create document objects to hold the comment boxes |
1292 } | 1314 } |
1293 return root; | 1315 return root; |
1294 }; | 1316 }; |
1295 }; | 1317 }; |
1296 | 1318 |
1319 this.commentQuestions = []; | |
1320 | |
1321 this.commentBox = function(commentQuestion) { | |
1322 this.specification = commentQuestion; | |
1323 // Create document objects to hold the comment boxes | |
1324 this.holder = document.createElement('div'); | |
1325 this.holder.className = 'comment-div'; | |
1326 // Create a string next to each comment asking for a comment | |
1327 this.string = document.createElement('span'); | |
1328 this.string.innerHTML = commentQuestion.question; | |
1329 // Create the HTML5 comment box 'textarea' | |
1330 this.textArea = document.createElement('textarea'); | |
1331 this.textArea.rows = '4'; | |
1332 this.textArea.cols = '100'; | |
1333 this.textArea.className = 'trackComment'; | |
1334 var br = document.createElement('br'); | |
1335 // Add to the holder. | |
1336 this.holder.appendChild(this.string); | |
1337 this.holder.appendChild(br); | |
1338 this.holder.appendChild(this.textArea); | |
1339 | |
1340 this.exportXMLDOM = function() { | |
1341 var root = document.createElement('comment'); | |
1342 root.id = this.specification.id; | |
1343 root.setAttribute('type',this.specification.type); | |
1344 root.textContent = this.textArea.value; | |
1345 return root; | |
1346 }; | |
1347 }; | |
1348 | |
1349 this.radioBox = function(commentQuestion) { | |
1350 this.specification = commentQuestion; | |
1351 // Create document objects to hold the comment boxes | |
1352 this.holder = document.createElement('div'); | |
1353 this.holder.className = 'comment-div'; | |
1354 // Create a string next to each comment asking for a comment | |
1355 this.string = document.createElement('span'); | |
1356 this.string.innerHTML = commentQuestion.statement; | |
1357 var br = document.createElement('br'); | |
1358 // Add to the holder. | |
1359 this.holder.appendChild(this.string); | |
1360 this.holder.appendChild(br); | |
1361 this.options = []; | |
1362 this.inputs = document.createElement('div'); | |
1363 this.span = document.createElement('div'); | |
1364 this.inputs.align = 'center'; | |
1365 this.inputs.style.marginLeft = '12px'; | |
1366 this.span.style.marginLeft = '12px'; | |
1367 this.span.align = 'center'; | |
1368 this.span.style.marginTop = '15px'; | |
1369 | |
1370 var optCount = commentQuestion.options.length; | |
1371 var spanMargin = Math.floor(((600-(optCount*100))/(optCount))/2)+'px'; | |
1372 console.log(spanMargin); | |
1373 for (var i=0; i<optCount; i++) | |
1374 { | |
1375 var div = document.createElement('div'); | |
1376 div.style.width = '100px'; | |
1377 div.style.float = 'left'; | |
1378 div.style.marginRight = spanMargin; | |
1379 div.style.marginLeft = spanMargin; | |
1380 var input = document.createElement('input'); | |
1381 input.type = 'radio'; | |
1382 input.name = commentQuestion.id; | |
1383 input.setAttribute('setvalue',commentQuestion.options[i].name); | |
1384 input.className = 'comment-radio'; | |
1385 div.appendChild(input); | |
1386 this.inputs.appendChild(div); | |
1387 | |
1388 | |
1389 div = document.createElement('div'); | |
1390 div.style.width = '100px'; | |
1391 div.style.float = 'left'; | |
1392 div.style.marginRight = spanMargin; | |
1393 div.style.marginLeft = spanMargin; | |
1394 div.align = 'center'; | |
1395 var span = document.createElement('span'); | |
1396 span.textContent = commentQuestion.options[i].text; | |
1397 span.className = 'comment-radio-span'; | |
1398 div.appendChild(span); | |
1399 this.span.appendChild(div); | |
1400 this.options.push(input); | |
1401 } | |
1402 this.holder.appendChild(this.span); | |
1403 this.holder.appendChild(this.inputs); | |
1404 | |
1405 this.exportXMLDOM = function() { | |
1406 var root = document.createElement('comment'); | |
1407 root.id = this.specification.id; | |
1408 root.setAttribute('type',this.specification.type); | |
1409 var question = document.createElement('question'); | |
1410 question.textContent = this.string.textContent; | |
1411 var response = document.createElement('response'); | |
1412 var i=0; | |
1413 while(this.options[i].checked == false) { | |
1414 i++; | |
1415 if (i >= this.options.length) { | |
1416 break; | |
1417 } | |
1418 } | |
1419 if (i >= this.options.length) { | |
1420 response.textContent = 'null'; | |
1421 } else { | |
1422 response.textContent = this.options[i].getAttribute('setvalue'); | |
1423 response.setAttribute('number',i); | |
1424 } | |
1425 root.appendChild(question); | |
1426 root.appendChild(response); | |
1427 return root; | |
1428 }; | |
1429 }; | |
1430 | |
1431 | |
1297 this.createCommentBox = function(audioObject) { | 1432 this.createCommentBox = function(audioObject) { |
1298 var node = new this.commentBox(audioObject); | 1433 var node = new this.elementCommentBox(audioObject); |
1299 this.commentBoxes.push(node); | 1434 this.commentBoxes.push(node); |
1300 audioObject.commentDOM = node; | 1435 audioObject.commentDOM = node; |
1301 return node; | 1436 return node; |
1302 }; | 1437 }; |
1303 | 1438 |
1314 if (sort) {interfaceContext.sortCommentBoxes();} | 1449 if (sort) {interfaceContext.sortCommentBoxes();} |
1315 for (var i=0; i<interfaceContext.commentBoxes.length; i++) { | 1450 for (var i=0; i<interfaceContext.commentBoxes.length; i++) { |
1316 inject.appendChild(this.commentBoxes[i].trackComment); | 1451 inject.appendChild(this.commentBoxes[i].trackComment); |
1317 } | 1452 } |
1318 }; | 1453 }; |
1319 } | 1454 |
1320 | 1455 this.createCommentQuestion = function(element) { |
1456 var node; | |
1457 if (element.type == 'text') { | |
1458 node = new this.commentBox(element); | |
1459 } else if (element.type == 'radio') { | |
1460 node = new this.radioBox(element); | |
1461 } | |
1462 this.commentQuestions.push(node); | |
1463 return node; | |
1464 }; | |
1465 } | |
1466 |