comparison test_create/test_core.js @ 505:cf55f9ee9446 Dev_main

Test create drag and drop active. Auto-builds on page HTML from specification.
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Thu, 11 Feb 2016 12:06:54 +0000
parents f8920367ec32
children 1dbc6d3e6fb5
comparison
equal deleted inserted replaced
504:f8920367ec32 505:cf55f9ee9446
197 this.dragArea = document.createElement("div"); 197 this.dragArea = document.createElement("div");
198 this.dragArea.className = "drag-area"; 198 this.dragArea.className = "drag-area";
199 this.dragArea.id = "project-drop"; 199 this.dragArea.id = "project-drop";
200 this.content.appendChild(this.dragArea); 200 this.content.appendChild(this.dragArea);
201 201
202 this.dragArea.addEventListener('dragenter',function(e){ 202 this.dragArea.addEventListener('dragover',function(e){
203 e.stopPropagation(); 203 e.stopPropagation();
204 e.preventDefault(); 204 e.preventDefault();
205 e.dataTransfer.dropEffect = 'copy'; 205 e.dataTransfer.dropEffect = 'copy';
206 e.currentTarget.className = "drag-area drag-over"; 206 e.currentTarget.className = "drag-area drag-over";
207 }); 207 });
216 this.dragArea.addEventListener('drop',function(e){ 216 this.dragArea.addEventListener('drop',function(e){
217 e.stopPropagation(); 217 e.stopPropagation();
218 e.preventDefault(); 218 e.preventDefault();
219 e.currentTarget.className = "drag-area drag-dropped"; 219 e.currentTarget.className = "drag-area drag-dropped";
220 var files = e.dataTransfer.files[0]; 220 var files = e.dataTransfer.files[0];
221 221 var reader = new FileReader();
222 reader.onload = function(decoded) {
223 var parse = new DOMParser();
224 specification.decode(parse.parseFromString(decoded.target.result,'text/xml'));
225 popupObject.hide();
226 convert.convert(document.getElementById('content'));
227 }
228 reader.readAsText(files);
222 }); 229 });
223 230
224 231
225 this.continue = function() 232 this.continue = function()
226 { 233 {
986 } 993 }
987 } 994 }
988 this.addPage.root.textContent = "Add Page"; 995 this.addPage.root.textContent = "Add Page";
989 this.addPage.root.addEventListener("click",this.addPage,false); 996 this.addPage.root.addEventListener("click",this.addPage,false);
990 this.injectDOM.appendChild(this.addPage.root); 997 this.injectDOM.appendChild(this.addPage.root);
998
999 // Build each page
1000 for (var page of specification.pages)
1001 {
1002 var newPage = new this.pageNode(this,page);
1003 this.injectDOM.appendChild(newPage.rootDOM);
1004 this.pages.push(newPage);
1005 }
991 } 1006 }
992 1007
993 this.interfaceNode = function(parent,rootObject) 1008 this.interfaceNode = function(parent,rootObject)
994 { 1009 {
995 this.rootDOM; 1010 this.rootDOM;
1276 case "statement": 1291 case "statement":
1277 this.titleDOM.textContent = "Statement"; 1292 this.titleDOM.textContent = "Statement";
1278 this.rootDOM.removeChild(this.attributeDOM); 1293 this.rootDOM.removeChild(this.attributeDOM);
1279 break; 1294 break;
1280 case "question": 1295 case "question":
1296 this.titleDOM.textContent = "Question";
1281 var id = convert.convertAttributeToDOM(this.specification.id,specification.schema.getAllElementsByName("id")[0]); 1297 var id = convert.convertAttributeToDOM(this.specification.id,specification.schema.getAllElementsByName("id")[0]);
1282 var mandatory = convert.convertAttributeToDOM(this.specification.mandatory,specification.schema.getAllElementsByName("id")[0]); 1298 var mandatory = convert.convertAttributeToDOM(this.specification.mandatory,specification.schema.getAllElementsByName("mandatory")[0]);
1283 var boxsize = convert.convertAttributeToDOM(this.specification.mandatory,specification.schema.getAllElementsByName("boxsize")[0]); 1299 var boxsize = convert.convertAttributeToDOM(this.specification.mandatory,specification.schema.getAllElementsByName("boxsize")[0]);
1300 this.attributeDOM.appendChild(id.holder);
1301 this.attributes.push(id);
1302 this.attributeDOM.appendChild(mandatory.holder);
1303 this.attributes.push(mandatory);
1304 this.attributeDOM.appendChild(boxsize.holder);
1305 this.attributes.push(boxsize);
1284 break; 1306 break;
1307 case "checkbox":
1308 this.titleDOM.textContent = "Checkbox";
1309 var id = convert.convertAttributeToDOM(this.specification.id,specification.schema.getAllElementsByName("id")[0]);
1310 this.attributeDOM.appendChild(id.holder);
1311 this.attributes.push(id);
1312 case "radio":
1313 this.titleDOM.textContent = "Radio";
1314 var id = convert.convertAttributeToDOM(this.specification.id,specification.schema.getAllElementsByName("id")[0]);
1315 this.attributeDOM.appendChild(id.holder);
1316 this.attributes.push(id);
1285 } 1317 }
1286 1318
1287 this.editNode = { 1319 this.editNode = {
1288 root: document.createElement("button"), 1320 root: document.createElement("button"),
1289 parent: this, 1321 parent: this,
1541 this.rootDOM.appendChild(this.childrenDOM); 1573 this.rootDOM.appendChild(this.childrenDOM);
1542 this.rootDOM.appendChild(this.buttonDOM); 1574 this.rootDOM.appendChild(this.buttonDOM);
1543 1575
1544 } 1576 }
1545 1577
1578 // Build the components
1579 for (var elements of this.specification.audioElements)
1580 {
1581 var audioElementDOM = new this.audioElementNode(this,elements);
1582 this.children.push(audioElementDOM);
1583 this.childrenDOM.appendChild(audioElementDOM.rootDOM);
1584 }
1585
1546 this.addInterface = { 1586 this.addInterface = {
1547 root: document.createElement("button"), 1587 root: document.createElement("button"),
1548 parent: this, 1588 parent: this,
1549 handleEvent: function() { 1589 handleEvent: function() {
1550 var InterfaceObj = new specification.interfaceNode(); 1590 var InterfaceObj = new specification.interfaceNode();