[259] | 1 | dbSelectionInfoTimeout = null; |
---|
| 2 | var currentlySelected = { |
---|
| 3 | titles: [], |
---|
| 4 | uids: [], |
---|
| 5 | type: null |
---|
| 6 | } |
---|
| 7 | |
---|
| 8 | var shoppingCart = { |
---|
| 9 | contents: { |
---|
| 10 | titles: [], |
---|
| 11 | uids: [], |
---|
| 12 | types: [] |
---|
| 13 | } |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | var graphSelection = { |
---|
| 17 | graphType: null, |
---|
| 18 | graphData: null, |
---|
| 19 | dataAvailable: false |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | var mockupData = { |
---|
| 23 | muData1: [1,2,3,4,5,6], //pie charts |
---|
| 24 | muData2: [[1,2,3],[4,5,6]], //bar charts |
---|
| 25 | muData3: [[1,2],[3,4],[5,6]] //radar charts |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | var dummyDatabase = { |
---|
| 29 | instances: new Array( |
---|
| 30 | { |
---|
[290] | 31 | title: "Participant gender", |
---|
| 32 | creator: "Jules duGrand", |
---|
[259] | 33 | date: "25-5-2012", |
---|
[290] | 34 | description: "The gender of the respondent, wording #1." |
---|
[259] | 35 | }, |
---|
| 36 | { |
---|
[290] | 37 | title: "Participant age", |
---|
| 38 | creator: "Jules duGrand", |
---|
| 39 | date: "25-5-2012", |
---|
| 40 | description: "N/a" |
---|
| 41 | }, |
---|
| 42 | { |
---|
| 43 | title: "Game experience", |
---|
| 44 | creator: "Peer van Neer", |
---|
| 45 | date: "25-5-2012", |
---|
| 46 | description: "Respondents experience with analog and video games." |
---|
| 47 | }, |
---|
| 48 | { |
---|
| 49 | title: "Current position within RWS", |
---|
| 50 | creator: "Peer van Neer", |
---|
| 51 | date: "26-5-2012", |
---|
| 52 | description: "Respondent fills in own description of position or job title during the session." |
---|
| 53 | }, |
---|
| 54 | { |
---|
| 55 | title: "Job experience at employer", |
---|
| 56 | creator: "Ellemiek Bosman", |
---|
| 57 | date: "25-5-2012", |
---|
| 58 | description: "Respondent fills in own time working at current company. May not be 100% accurate!" |
---|
[259] | 59 | } |
---|
| 60 | |
---|
| 61 | ), |
---|
| 62 | gameData: new Array( |
---|
| 63 | { |
---|
[290] | 64 | title: "Veerkracht game session #1", |
---|
| 65 | creator: "Ellemiek Bosman", |
---|
| 66 | date: "25-5-2012", |
---|
| 67 | description: "First play session. Users go into game without instructions." |
---|
[259] | 68 | }, |
---|
| 69 | { |
---|
[290] | 70 | title: "Veerkracht game session #2", |
---|
| 71 | creator: "Ellemiek Bosman", |
---|
| 72 | date: "25-5-2012", |
---|
| 73 | description: "Second play session. Users have played game before and received feedback on their results." |
---|
[259] | 74 | } |
---|
| 75 | ) |
---|
| 76 | }; |
---|
| 77 | |
---|
| 78 | (function() { |
---|
| 79 | var el = ge("dbSessionInstancesList"); |
---|
| 80 | for (var n = 0; n < dummyDatabase.instances.length; n++) { |
---|
| 81 | var opt = ce("option"); |
---|
| 82 | opt.value = n; |
---|
| 83 | opt.innerHTML = dummyDatabase.instances[n].title; |
---|
| 84 | el.appendChild(opt); |
---|
| 85 | } |
---|
| 86 | el = ge("dbGamedataList"); |
---|
| 87 | for (var n = 0; n < dummyDatabase.gameData.length; n++) { |
---|
| 88 | var opt = ce("option"); |
---|
| 89 | opt.value = n; |
---|
| 90 | opt.innerHTML = dummyDatabase.gameData[n].title; |
---|
| 91 | el.appendChild(opt); |
---|
| 92 | } |
---|
| 93 | })(); |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | function infoPanelTimeout(event) { |
---|
| 99 | // If no event, crash. |
---|
| 100 | if (event == undefined || event == null) return; |
---|
| 101 | // Cancel previous timeout if present. |
---|
| 102 | if (dbSelectionInfoTimeout) { |
---|
| 103 | window.clearTimeout(dbSelectionInfoTimeout); |
---|
| 104 | } |
---|
| 105 | // Gather parameters about event. |
---|
| 106 | var dbSelectionInfoTime = 250; |
---|
| 107 | var selectBox = event.target; |
---|
| 108 | var values = getMultipleListValue(selectBox).values; |
---|
| 109 | var titles = getMultipleListValue(selectBox).titles; |
---|
| 110 | var uid = values[values.length-1]; |
---|
| 111 | var type; |
---|
| 112 | switch (selectBox.id) { |
---|
| 113 | case "dbSessionInstancesList": |
---|
| 114 | // This should be session instance, not session. Testing purpose only. |
---|
| 115 | type = "Session"; |
---|
| 116 | break; |
---|
| 117 | case "dbGamedataList": |
---|
| 118 | // This is obviously not the real type, change before committing |
---|
| 119 | type = "Application"; |
---|
| 120 | break; |
---|
| 121 | default: |
---|
| 122 | alert("No valid type passed!"); |
---|
| 123 | break; |
---|
| 124 | } |
---|
| 125 | currentlySelected.uids = values; |
---|
| 126 | currentlySelected.titles = titles; |
---|
| 127 | currentlySelected.type = type; |
---|
| 128 | // Set timeout of 500ms, then execute ajaxInfoRequest with previously gathered parameters. |
---|
| 129 | //dbSelectionInfoTimeout = window.setTimeout(ajaxInfoRequest, dbSelectionInfoTime, uid, ge("dbInfoPanelContent"), type); |
---|
| 130 | dbSelectionInfoTimeout = window.setTimeout(getInfo, dbSelectionInfoTime, type, uid); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | function getInfo(type, uid) { |
---|
| 134 | var infoPanelContent = ge("dbInfoPanelContent"); |
---|
| 135 | var data; |
---|
| 136 | switch (type.toLowerCase()) { |
---|
| 137 | case "session": |
---|
| 138 | data = dummyDatabase.instances[uid]; |
---|
| 139 | break; |
---|
| 140 | case "application": |
---|
| 141 | data = dummyDatabase.gameData[uid]; |
---|
| 142 | break; |
---|
| 143 | default: |
---|
| 144 | alert("Lol nope!"); |
---|
| 145 | break; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | resultString = ""; |
---|
| 149 | resultString += "Title:<br/>"+data.title+".<br/><br/>"; |
---|
| 150 | resultString += "Creator:<br/>"+data.creator+".<br/><br/>"; |
---|
| 151 | resultString += "Date:<br/>"+data.date+".<br/><br/>"; |
---|
| 152 | resultString += "Description:<br/>"+data.description+".<br/><br/>"; |
---|
| 153 | |
---|
| 154 | |
---|
| 155 | infoPanelContent.innerHTML = resultString; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | function getMultipleListValue(element) { |
---|
| 159 | // Get multiple values from multiple select box |
---|
| 160 | //TODO: |
---|
| 161 | var result = { |
---|
| 162 | values: [], |
---|
| 163 | titles: [] |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | for (var i = 0; i < element.options.length; i++) { |
---|
| 167 | if (element.options[i].selected == true) { |
---|
| 168 | result.values.push(element.options[i].value); |
---|
| 169 | result.titles.push(element.options[i].text); |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | return result; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | function addDataToList() { |
---|
| 176 | // Take selected objects and add to shopping cart |
---|
| 177 | // set element |
---|
| 178 | var element; |
---|
| 179 | switch (currentlySelected.type){ |
---|
| 180 | case "Session": |
---|
| 181 | element = ge("dbSessionInstancesList"); |
---|
| 182 | break; |
---|
| 183 | case "Application": |
---|
| 184 | element = ge("dbGamedataList"); |
---|
| 185 | break; |
---|
| 186 | default: |
---|
| 187 | // ??? |
---|
| 188 | break; |
---|
| 189 | } |
---|
| 190 | var uid; |
---|
| 191 | while (uid = currentlySelected.uids.pop()) { |
---|
| 192 | // Add to shopping cart |
---|
| 193 | shoppingCart.contents.uids.push(uid); |
---|
| 194 | shoppingCart.contents.titles.push(currentlySelected.titles.pop()); |
---|
| 195 | shoppingCart.contents.types.push(currentlySelected.type); |
---|
| 196 | |
---|
| 197 | // Remove option from list |
---|
| 198 | for (var i = 0; i < element.options.length; i++) { |
---|
| 199 | if (element.options[i].value == uid) { |
---|
| 200 | element.remove(i); |
---|
| 201 | break; |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | // Then add display of shopping cart contents |
---|
| 207 | drawShoppingCart(); |
---|
| 208 | ge("dbInfoPanelContent").innerHTML = ""; |
---|
| 209 | |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | function removeFromList(event) { |
---|
| 213 | if (event == null || event == undefined) return; |
---|
| 214 | |
---|
| 215 | var id = event.target.parentNode.id; |
---|
| 216 | var uid = id.split("shoppingCartItem")[1]; |
---|
| 217 | // find index, remove from object |
---|
| 218 | var indexInCart = shoppingCart.contents.uids.indexOf(uid); |
---|
| 219 | var tempTitle = shoppingCart.contents.titles[indexInCart]; |
---|
| 220 | var cn = confirm("Are you sure you want to remove: "+tempTitle+"?"); |
---|
| 221 | if (cn == false) return; |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | shoppingCart.contents.uids.splice(indexInCart, 1); |
---|
| 225 | var title = shoppingCart.contents.titles.splice(indexInCart, 1)[0]; |
---|
| 226 | var type = shoppingCart.contents.types.splice(indexInCart, 1)[0]; |
---|
| 227 | //Then replace element back into relevant list |
---|
| 228 | // First set element |
---|
| 229 | |
---|
| 230 | var element; |
---|
| 231 | switch (type){ |
---|
| 232 | case "Session": |
---|
| 233 | element = ge("dbSessionInstancesList"); |
---|
| 234 | break; |
---|
| 235 | case "Application": |
---|
| 236 | element = ge("dbGamedataList"); |
---|
| 237 | break; |
---|
| 238 | default: |
---|
| 239 | // ??? |
---|
| 240 | break; |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | var option = ce("option"); |
---|
| 244 | option.value = uid; |
---|
| 245 | option.text = title; |
---|
| 246 | element.add(option,null); |
---|
| 247 | |
---|
| 248 | |
---|
| 249 | |
---|
| 250 | // Lastly, refresh |
---|
| 251 | drawShoppingCart(); |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | function drawShoppingCart() { |
---|
| 255 | var scElement = ge("shoppingCartContent"); |
---|
| 256 | scElement.innerHTML = ""; |
---|
| 257 | for (var i = 0; i < shoppingCart.contents.uids.length; i++) { |
---|
| 258 | var newLine = ce("div"); |
---|
| 259 | newLine.className = "shoppingCartItem"; |
---|
| 260 | newLine.id = "shoppingCartItem"+shoppingCart.contents.uids[i]; |
---|
| 261 | var icon = ce("image"); |
---|
[261] | 262 | icon.src = "images/ui/DeleteIcon.png"; |
---|
[259] | 263 | $(icon).css("float", "right"); |
---|
| 264 | icon.addEventListener("click", function(event){ |
---|
| 265 | // TODO: Actually write this function |
---|
| 266 | removeFromList(event); |
---|
| 267 | }, false); |
---|
| 268 | var titleField = ce("text"); |
---|
| 269 | titleField.innerHTML = shoppingCart.contents.titles[i]; |
---|
| 270 | newLine.appendChild(titleField); |
---|
| 271 | newLine.appendChild(icon); |
---|
| 272 | scElement.appendChild(newLine); |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | // reset type after empty |
---|
| 276 | currentlySelected.type = null; |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | function configureDashboard() { |
---|
[278] | 280 | mockup.api.loadPage("graphSelection", false); |
---|
[259] | 281 | } |
---|
| 282 | |
---|
| 283 | //function goto dashboard |
---|
| 284 | function gotoDashboard() { |
---|
| 285 | var data = JSON.stringify(doorstuurData); |
---|
| 286 | var form = ce("form"); |
---|
| 287 | //changed to dashboardGraphSelection.php |
---|
| 288 | form.action = "dashboardOverview.php"; |
---|
| 289 | form.method = "POST"; |
---|
| 290 | var input = ce("input"); |
---|
| 291 | input.type = "hidden"; |
---|
| 292 | input.name = "doorstuurData"; |
---|
| 293 | input.value = data; |
---|
| 294 | form.appendChild(input); |
---|
| 295 | form.submit(); |
---|
| 296 | //alert("Graph type is now: "+graphSelection); |
---|
| 297 | |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | function changeGraphType(type) { |
---|
| 301 | // If different graph type, clear canvas 1. |
---|
| 302 | |
---|
| 303 | switch (type.toLowerCase()){ |
---|
| 304 | case "bar": |
---|
| 305 | graphSelection.graphType = "Bar"; |
---|
| 306 | break; |
---|
| 307 | case "radar": |
---|
| 308 | graphSelection.graphType = "Radar"; |
---|
| 309 | break |
---|
| 310 | case "pie": |
---|
| 311 | graphSelection.graphType = "Pie"; |
---|
| 312 | break; |
---|
| 313 | default: |
---|
| 314 | break; |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | |
---|
| 318 | var data = formatGraphData(); |
---|
| 319 | drawGraph('chart1', 450, 200, graphSelection.graphType, data); |
---|
| 320 | |
---|
| 321 | // alert("Graph type is now: "+graphSelection.graphType); |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | function formatGraphData() { |
---|
| 325 | /* |
---|
| 326 | * if (data.available == false) { |
---|
| 327 | * graphSelection.dataAvailable = false; |
---|
| 328 | * insertStandardPlaceholderData(); |
---|
| 329 | * } |
---|
| 330 | * else { |
---|
| 331 | * FormatDataCorrectly(); |
---|
| 332 | * } |
---|
| 333 | */ |
---|
| 334 | // temporary!!!; |
---|
| 335 | graphSelection.graphData = mockupData.muData1; |
---|
| 336 | return mockupData.muData1; |
---|
| 337 | |
---|
| 338 | //alert("Data is now being formatted"); |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | function drawGraph(name, sizeX, sizeY, type, data) { |
---|
| 342 | //delete old graph |
---|
| 343 | |
---|
| 344 | var oldGraph = ge("chart1"); |
---|
| 345 | if (oldGraph) oldGraph.parentNode.removeChild(oldGraph); |
---|
| 346 | |
---|
| 347 | var canvas = ce("canvas"); |
---|
| 348 | canvas.id = name; |
---|
| 349 | canvas.width = sizeX; |
---|
| 350 | canvas.height = sizeY; |
---|
| 351 | var parentElement = ge("graphDisplay"); |
---|
| 352 | parentElement.appendChild(canvas); |
---|
| 353 | |
---|
| 354 | //js calls |
---|
| 355 | var chart1; |
---|
| 356 | switch (type) { |
---|
| 357 | case "Bar": |
---|
| 358 | chart1 = new RGraph.Bar(name, data); |
---|
| 359 | break; |
---|
| 360 | case "Pie": |
---|
| 361 | chart1 = new RGraph.Pie(name, data); |
---|
| 362 | break; |
---|
| 363 | case "Radar": |
---|
| 364 | chart1 = new RGraph.Radar(name, data); |
---|
| 365 | break; |
---|
| 366 | default: |
---|
| 367 | break; |
---|
| 368 | } |
---|
| 369 | |
---|
| 370 | //chart1.Set('chart.background.barcolor1', 'white'); |
---|
| 371 | // chart1.Set('chart.background.barcolor2', 'white'); |
---|
| 372 | chart1.Set('chart.labels', ['1st', '2nd', '3rd', '4th', '5th', '6th']); |
---|
| 373 | //chart1.Set('chart.key', ['Aapjes', 'Hertjes']); |
---|
| 374 | //chart1.Set('chart.key.position.y', 35); |
---|
| 375 | //chart1.Set('chart.key.position', 'gutter'); |
---|
| 376 | //chart1.Set('chart.key.background', 'rgb(255,255,255)'); |
---|
| 377 | chart1.Set('chart.colors', ['#77f', '#7f7']); |
---|
| 378 | chart1.Set('chart.shadow', true); |
---|
| 379 | chart1.Set('chart.shadow.blur', 15); |
---|
| 380 | chart1.Set('chart.shadow.offsetx', 0); |
---|
| 381 | chart1.Set('chart.shadow.offsety', 0); |
---|
| 382 | chart1.Set('chart.shadow.color', '#aaa'); |
---|
| 383 | chart1.Set('chart.yaxispos', 'right'); |
---|
| 384 | chart1.Set('chart.strokestyle', 'rgba(0,0,0,0)'); |
---|
| 385 | chart1.Set('chart.gutter.left', 5); |
---|
| 386 | chart1.Set('chart.gutter.right', 45); |
---|
| 387 | chart1.Draw(); |
---|
| 388 | |
---|
| 389 | } |
---|
| 390 | |
---|
| 391 | var doorstuurData = { |
---|
| 392 | graphs: [], |
---|
| 393 | count: null |
---|
| 394 | } |
---|
| 395 | |
---|
| 396 | function addToDashboard() { |
---|
| 397 | doorstuurData.graphs.push(["graph"+doorstuurData.count+1, 450, 200, graphSelection.graphType, graphSelection.graphData]); |
---|
| 398 | doorstuurData.count++; |
---|
| 399 | } |
---|
[278] | 400 | |
---|