/* file: learning.js
 * authors: H. Bouakaz, S. van Vliet, S. de Jong & E. Werkema
 * date: 25/3/2016
 * version 1.2
 *
 * Description:
 * Main script for initiating the learning app.
 */

define(['jquery', 'bootstrap', 'app/config', 'app/database', 'app/messages', 'app/question', 'app/timer','app/database'], function ($, bootstrap, config, db, messages, question, timer,db) {
  timer.startTimer(".timer", config.constant("TIME_LIMIT"));
  var waitingForEnter = false;

  // Disable autocomplete that provides suggestions when typing words
  $('input').attr('autocomplete', 'off');
//when the page is loaded we get the datasetId from the page url and load the dataset from the databese
  $(document).ready(function() {
    var url =   window.location.href
    var datasetId = url.substring(url.indexOf('?')+1);
    var datasetItems = db.getQuery("getDatasetItems",[datasetId]);
    question.initialise(datasetItems);
  	question.show();
  });

  // Temporary hint button
  $("#hintButton").click(function() {
    if (question.hint()!=="")
      messages.showHint(question.hint());
  });

  // Read the user input when the Enter key is pressed and evaluate it.
  // Then show the next question.
  $(document).bind("keypress", function (e) {
  	if (e.keyCode == config.key("ENTER")) {
      if (waitingForEnter) {
        nextQuestion();
      } else {
        $( "#answer" ).prop("disabled", true);
        question.checkAnswer();
        waitingForEnter = true;
        timeout = setTimeout(nextQuestion, config.constant("FEEDBACK_DELAY"));
      }
  	}
  });

  function nextQuestion() {
    clearTimeout(timeout);
    timer.clearCountdown();
    messages.clear();
    $( "#answer" ).prop("disabled", false);
    $( "#answer" ).val( "" );
    $( "#answer" ).focus();
    question.show();
    waitingForEnter = false;
  }
});

@@ -468,23 +468,30 @@
 se;%0A
+  
 %0A  
-// D
+function d
 isable
- a
+A
 utoc
@@ -501,95 +501,356 @@
 lete
- that provides suggestions when typing words%0A
+() %7B%0A    $('input').attr('autocomplete', 'off');%0A  %7D%0A  %0A  function nextQuestion() %7B%0A    clearTimeout(timeout);%0A    timer.clearCountdown();%0A    messages.clear();%0A    $( %22#answer%22 ).prop(%22disabled%22, false);%0A 
   
+ 
 $(
-'input').attr('autocomplete', 'off');%0A
+ %22#answer%22 ).val( %22%22 );%0A    $( %22#answer%22 ).focus();%0A    question.show();%0A    waitingForEnter = false;%0A  %7D%0A%0A  disableAutocomplete();%0A  %0A  
 //wh
@@ -1826,270 +1826,8 @@
  %7D);
-%0A%0A  function nextQuestion() %7B%0A    clearTimeout(timeout);%0A    timer.clearCountdown();%0A    messages.clear();%0A    $( %22#answer%22 ).prop(%22disabled%22, false);%0A    $( %22#answer%22 ).val( %22%22 );%0A    $( %22#answer%22 ).focus();%0A    question.show();%0A    waitingForEnter = false;%0A  %7D
 %0A%7D);

Put disableAutocomplete into function