/* Unit de funções JavaScript para Módulos EAD 2014 Server Informática */ Number.prototype.toHHMMSS = function () { var seconds = Math.floor(this), hours = Math.floor(seconds / 3600); seconds -= hours*3600; var minutes = Math.floor(seconds / 60); seconds -= minutes*60; if (hours < 10) {hours = "0"+hours;} if (minutes < 10) {minutes = "0"+minutes;} if (seconds < 10) {seconds = "0"+seconds;} return hours+':'+minutes+':'+seconds; } function Timer(){ var isStarted = false; var interval = 1000; // 1 seg var counter = 0; var clock = null; var incremental = true; var output = null; var displayText = ''; var stopOnZero = true; var onZero = null; var onTimerInterval = 10000; // 10 seg var onTimer = null; var onTimerClock = null; var stopAt = -1; // Cronometro para quando Counter for maior ou menor (depende se é incremental ou decremental) var onStop = null; // evento a ser disparado quando counter chegar a variavel stopAt this.stopClock = function() { if (isStarted) { clearInterval(clock); clearInterval(onTimer); isStarted = false; } } var stopClock = this.stopClock; // Método privado para acessar função que interrompeo timer this.incClock = function() { var stop; if (incremental) { counter++; stop = counter >= stopAt; } else { counter--; stop = counter <= stopAt; } if (output != null) { output.innerHTML = displayText + counter.toHHMMSS(); } if (stop) { stopClock(); if (onStop != null && onStop != undefined) { onStop(); } return; } } this.startClock = function() { if (!isStarted) { clock = setInterval(this.incClock, interval); onTimerClock = setInterval(this.onTimer, onTimerInterval); isStarted = true; } } this.setDisplayText = function(text) { displayText = text; } this.setIncrementalMode = function(){ incremental = true; } this.setDecrementalMode = function() { incremental = false; } this.setCounter = function(x) { counter = x; } this.setOutput = function(y){ output = y; } this.getCounter = function(){ return counter; } this.onTimer = null this.setStopAt = function(x){ stopAt = x; } this.setOnStop = function(fn) { onStop = fn; } } function startProva(counter){ var timer = new Timer(); timer.setCounter(counter); timer.setDecrementalMode(); timer.setDisplayText('Tempo disponivel: '); timer.setOutput(document.getElementById('eadTimer')); timer.setStopAt(0); timer.setOnStop(TestTimeTimeOut); timer.onTimer = function(){ jqueryAJAX('Prova/UpdateTime', 'available-time=' + timer.getCounter() + '&codigomodulo=' + $("#codigomodulo").text, false, 'json'); }; timer.startClock(); } function setSalvarProvaVisibility() { var doSetSalvarProvaVisibility = function(s){ if (s == null || s == undefined) { return; } var obj = JSON.parse(s); if (obj.SalvarProvaVisible) { setVisibility('menuBottom', 'visible'); } else { setVisibility('menuBottom', 'hidden'); } } Ajax('', '/bshop/getModoLayoutFromPreset', 'Preset=' + Preset + '&ReportName=' + ReportName + "&A=1", null, 0, DoSetModoLayout, false, true, null, true); } function checkBtnFinalizarProvaVisibility(sessionID){ setBtnFinalizarProvaVisibility = function(obj, str, jqXHR){ if (obj.AllQuestionsAnswered) { $("#menuBottom").show(); } else { $("#menuBottom").hide(); } }; jqueryAJAX("Prova/TodasPerguntasPreenchidas?SessionID="+sessionID, $("#FormProva"), true, "json", setBtnFinalizarProvaVisibility); } function jqueryAJAX(requestAddress, customData, toSerialize, returnType, successCallback, errorCallBack, completeCallback) { var d = null; if (toSerialize) { d = customData.serialize(); } else { d = customData; } var request = $.ajax({ url: requestAddress, type: "GET", data: d, dataType: returnType, cache: false, success: successCallback, complete: completeCallback, error: errorCallBack }); } function TestTimeTimeOut() { alert("Seu tempo para realizar este teste esgotou. \nAs questões respondidas serão salvas e você será redirecionado à página inicial." ); $("#menuBottom").show(); $("#salvarProva").click(); }