source: Dev/branches/Cartis/Tiles preview/js/dashboardScripts.js @ 296

Last change on this file since 296 was 296, checked in by cartis, 13 years ago

klaar voor testing

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