1
0

iassign-integration-functions.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. // Função para ler parâmetros informados pelo iTarefa via URL
  2. // Apesar de não ser obrigatório, será muito útil para capturar os parâmetros
  3. function getParameterByName (name, defaultReturn = null) {
  4. var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
  5. return match ? decodeURIComponent(match[1].replace(/\+/g, ' ')) : defaultReturn;
  6. }
  7. // Criando um object com os parâmetros informados pelo iTarefa
  8. // Observe que para cada parâmetro, é realizada a chamada do método getParameterByName, implementado acima
  9. var iLMparameters = {
  10. iLM_PARAM_ServerToGetAnswerURL: getParameterByName("iLM_PARAM_ServerToGetAnswerURL"),
  11. iLM_PARAM_SendAnswer: getParameterByName("iLM_PARAM_SendAnswer"),
  12. iLM_PARAM_AssignmentURL: getParameterByName("iLM_PARAM_AssignmentURL"),
  13. iLM_PARAM_Assignment: getParameterByName("iLM_PARAM_Assignment"),
  14. iLM_PARAM_TeacherAutoEval: getParameterByName("iLM_PARAM_TeacherAutoEval"),
  15. lang: getParameterByName("lang", "pt")
  16. };
  17. // Set the lang parameter to the localStorage for easy access
  18. // and no dependency to the global scope, avoind future 'strict mode' problems
  19. //localStorage.setItem('ivprog.lang', iLMparameters.lang);
  20. // Função chamada pelo iTarefa quando o professor finaliza a criação da atividade
  21. // ou quando o aluno finaliza a resolução do exercício
  22. // O retorno é um JSON com os dados do exercício ou da resolução
  23. // Esse retorno será armazenado no banco de dados do Moodle, pelo iTarefa
  24. function getAnswer () {
  25. // Se o parâmetro "iLM_PARAM_SendAnswer" for false,
  26. // então trata-se de resolução de atividade
  27. if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  28. // Montar o retorno com a resposta do aluno
  29. var contentToSend = previousContent.split("\n::algorithm::")[0];
  30. contentToSend += '\n::algorithm::';
  31. if (settingsProgrammingTypes == "textual") {
  32. contentToSend += ivprogCore.CodeEditor.getCode();
  33. } else {
  34. contentToSend += JSON.stringify(window.program_obj, function(key, value) {
  35. if (key == 'dom_object') {
  36. return;
  37. }
  38. return value;
  39. });
  40. }
  41. contentToSend += '\n::logs::';
  42. contentToSend += getTrackingLogs();
  43. return contentToSend;
  44. } else {
  45. // Montar o retorno com a criação da atividade do professor
  46. var ret = ' { ' + prepareTestCases()
  47. + ',\n"settings_programming_type": \n' + JSON.stringify($('form[name="settings_programming_type"]').serializeArray())
  48. + ',\n"settings_data_types": \n' + JSON.stringify($('form[name="settings_data_types"]').serializeArray())
  49. + ',\n"settings_commands": \n' + JSON.stringify($('form[name="settings_commands"]').serializeArray())
  50. + ',\n"settings_functions": \n' + JSON.stringify($('form[name="settings_functions"]').serializeArray())
  51. + ',\n"settings_filter": \n' + JSON.stringify($('form[name="settings_filter"]').serializeArray())
  52. + ' } ';
  53. if ($("input[name='include_algo']").is(':checked')) {
  54. ret += '\n::algorithm::';
  55. ret += JSON.stringify(window.program_obj, function(key, value) {
  56. if (key == 'dom_object') {
  57. return;
  58. }
  59. return value;
  60. });
  61. }
  62. return ret;
  63. }
  64. }
  65. function prepareTestCases () {
  66. var ret = ' \n "testcases" : [ '
  67. var test_cases_array = $('form[name="test_cases"]').serializeArray();
  68. console.log(test_cases_array);
  69. for (var i = 0; i < test_cases_array.length; i = i + 2) {
  70. ret += '\n{ ';
  71. ret += '\n "input": [';
  72. var inps = test_cases_array[i].value.match(/[^\r\n]+/g);
  73. if (inps) {
  74. for (var j = 0; j < inps.length; j++) {
  75. ret += '"' + inps[j].trim() + '"';
  76. if ((j + 1) < inps.length) {
  77. ret += ', ';
  78. }
  79. }
  80. }
  81. ret += '], \n "output": [';
  82. var outs = test_cases_array[i+1].value.match(/[^\r\n]+/g);
  83. if (outs) {
  84. for (var j = 0; j < outs.length; j++) {
  85. ret += '"' + outs[j].trim() + '"';
  86. if ((j + 1) < outs.length) {
  87. ret += ', ';
  88. }
  89. }
  90. }
  91. ret += ']';
  92. ret += '\n}'
  93. if ((i + 2) < test_cases_array.length) {
  94. ret += ',';
  95. }
  96. }
  97. ret += '\n] ';
  98. return ret;
  99. }
  100. // Função chamada pelo iTarefa para receber a nota do aluno na atividade
  101. // O retorno é um valor entre 0.0 e 1.0
  102. function getEvaluation () {
  103. if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  104. // A chamada do método abaixo é obrigatória!
  105. // Observe que a chamada parte do iLM para o iTarefa
  106. //parent.getEvaluationCallback(window.studentGrade);
  107. var canRunAssessment = runCodeAssessment();
  108. if(canRunAssessment === -1) {
  109. parent.getEvaluationCallback(-1);
  110. }
  111. }
  112. }
  113. //var testCases = null
  114. var settingsDataTypes = null;
  115. var settingsCommands = null;
  116. var settingsFunctions = null;
  117. var settingsProgrammingTypes = null;
  118. var settingsFilter = null;
  119. var algorithm_in_ilm = null;
  120. var previousContent = null;
  121. // Função para que o iMA leia os dados da atividade fornecidos pelo iTarefa
  122. function getiLMContent () {
  123. // O parâmetro "iLM_PARAM_Assignment" fornece o URL do endereço que deve ser
  124. // requisitado via AJAX para a captura dos dados da atividade
  125. $.get(iLMparameters.iLM_PARAM_Assignment, function (data) {
  126. //professor invocou a avaliação automática dos exercícios do bloco
  127. if (iLMparameters.iLM_PARAM_TeacherAutoEval != null) {
  128. teacherAutoEval(data);
  129. //não deve exibir nenhuma interface...
  130. return;
  131. } else if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  132. // Aluno está trabalhando em alguma atividade:
  133. previousContent = data;
  134. prepareActivityToStudent(data);
  135. } else { // Professor está editando uma atividade:
  136. previousContent = data;
  137. prepareActivityToEdit(data);
  138. }
  139. window.block_render = false;
  140. renderAlgorithm();
  141. });
  142. }
  143. function prepareActivityToEdit (ilm_cont) {
  144. //var content = JSON.parse(ilm_cont.split('\n::algorithm::')[0]);
  145. // Ver arquivo js/util/iassignHelpers.js
  146. var content = ivprogCore.prepareActivityToStudentHelper(ilm_cont);
  147. var testCases = ivprogCore.getTestCases();
  148. settingsProgrammingTypes = content.settingsProgrammingType;
  149. settingsDataTypes = content.settingsDataTypes;
  150. settingsCommands = content.settingsCommands;
  151. settingsFunctions = content.settingsFunctions;
  152. settingsFilter = content.settingsFilter;
  153. for (var i = 0; i < testCases.length; i++) {
  154. addTestCase(testCases[i]);
  155. }
  156. if (content.algorithmInIlm != null) {
  157. algorithm_in_ilm = content.algorithmInIlm;
  158. $("input[name='include_algo']").prop('checked', true);
  159. includePreviousAlgorithm();
  160. renderAlgorithm();
  161. }
  162. ivprogTextualOrVisual();
  163. if (settingsFilter && settingsFilter[0]) {
  164. blockAllEditingOptions();
  165. }
  166. }
  167. function parsePreviousAlgorithm () {
  168. window.program_obj.functions = JSON.parse(algorithm_in_ilm).functions;
  169. window.program_obj.globals = JSON.parse(algorithm_in_ilm).globals;
  170. }
  171. function includePreviousAlgorithm () {
  172. if (settingsProgrammingTypes == "textual") {
  173. return;
  174. }
  175. parsePreviousAlgorithm();
  176. window.watchW.watch(window.program_obj.globals, function(){
  177. if (window.insertContext) {
  178. setTimeout(function(){ renderAlgorithm(); }, 300);
  179. window.insertContext = false;
  180. } else {
  181. renderAlgorithm();
  182. }
  183. }, 1);
  184. for (var i = 0; i < window.program_obj.functions.length; i ++) {
  185. window.watchW.watch(window.program_obj.functions[i].parameters_list, function(){
  186. if (window.insertContext) {
  187. setTimeout(function(){ renderAlgorithm(); }, 300);
  188. window.insertContext = false;
  189. } else {
  190. renderAlgorithm();
  191. }
  192. }, 1);
  193. window.watchW.watch(window.program_obj.functions[i].variables_list, function(){
  194. if (window.insertContext) {
  195. setTimeout(function(){ renderAlgorithm(); }, 300);
  196. window.insertContext = false;
  197. } else {
  198. renderAlgorithm();
  199. }
  200. }, 1);
  201. if (window.program_obj.functions[i].is_main) {
  202. window.program_obj.functions[i].name = LocalizedStrings.getUI("start");
  203. }
  204. }
  205. window.watchW.watch(window.program_obj.functions, function(){
  206. if (window.insertContext) {
  207. setTimeout(function(){ renderAlgorithm(); }, 300);
  208. window.insertContext = false;
  209. } else {
  210. renderAlgorithm();
  211. }
  212. }, 1);
  213. }
  214. function prepareActivityToStudent (ilm_cont) {
  215. // Ver arquivo js/util/iassignHelpers.js
  216. var content = ivprogCore.prepareActivityToStudentHelper(ilm_cont);
  217. // Casos de testes agora são delegados ao tratamento apropriado pela função acima
  218. // var testCases = content.testcases;
  219. settingsProgrammingTypes = content.settingsProgrammingType;
  220. settingsDataTypes = content.settingsDataTypes;
  221. settingsCommands = content.settingsCommands;
  222. settingsFunctions = content.settingsFunctions;
  223. settingsFilter = content.settingsFilter;
  224. if (content.algorithmInIlm != null) {
  225. algorithm_in_ilm = content.algorithmInIlm;
  226. includePreviousAlgorithm();
  227. }
  228. $('.assessment_button').removeClass('disabled');
  229. renderAlgorithm();
  230. ivprogTextualOrVisual();
  231. if (settingsFilter && settingsFilter[0]) {
  232. blockAllEditingOptions();
  233. }
  234. }
  235. // Função para organizar se para criação, visualização ou resolução de atividade
  236. function prepareEnvironment () {
  237. $('.div_to_body').click(function(e) {
  238. // trackingMatrix.push(adCoords(e, 1));
  239. ivprogCore.registerClick(e.pageX, e.pageY, e.target.classList['value']);
  240. });
  241. // Se iLM_PARAM_SendAnswer for false, então trata-se de resolução de atividade,
  242. // portanto, a "DIV" de resolução é liberada
  243. if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  244. //$('.resolucao').css("display","block");
  245. getiLMContent();
  246. // $('.div_to_body').mousemove(function(e) {
  247. // trackingMatrix.push(adCoords(e, 0));
  248. // });
  249. // $('.div_to_body').click(function(e) {
  250. // // trackingMatrix.push(adCoords(e, 1));
  251. // ivprogCore.registerClick(e.pageX, e.pageY, e.target.classList['value']);
  252. // });
  253. } else if (iLMparameters.iLM_PARAM_Assignment) {
  254. // Caso não esteja em modo de resolução de atividade, a visualização no momento
  255. // é para a elaboração de atividade:
  256. //$('.elaboracao').css("display","block");
  257. // Se possuir o parâmetro iLMparameters.iLM_PARAM_Assignment, o professor
  258. // está editando uma atividade:
  259. getiLMContent();
  260. } else {
  261. renderAlgorithm();
  262. }
  263. if ((iLMparameters.iLM_PARAM_AssignmentURL == "true") && (iLMparameters.iLM_PARAM_SendAnswer == "true")) {
  264. prepareActivityCreation();
  265. }
  266. }
  267. function blockAllEditingOptions () {
  268. if ((iLMparameters.iLM_PARAM_AssignmentURL == "true") && (iLMparameters.iLM_PARAM_SendAnswer == "true")) {
  269. return;
  270. }
  271. $('.add_global_button').addClass('disabled');
  272. $('.move_function').addClass('disabled');
  273. $('.add_function_button').addClass('disabled');
  274. $('.add_var_button_function .ui.icon.button.purple').addClass('disabled');
  275. $('.add_var_button_function').addClass('disabled');
  276. $('.menu_commands').addClass('disabled');
  277. $('.global_type').addClass('disabled');
  278. $('.editing_name_var').addClass('disabled');
  279. $('.span_value_variable').addClass('disabled');
  280. $('.remove_global').addClass('disabled');
  281. $('.ui.icon.ellipsis.vertical.inverted').addClass('disabled');
  282. $('.alternate_constant').addClass('disabled');
  283. $('.remove_variable').addClass('disabled');
  284. $('.add_global_matrix_column').addClass('disabled');
  285. $('.remove_global_matrix_column').addClass('disabled');
  286. $('.add_global_matrix_line').addClass('disabled');
  287. $('.remove_global_matrix_line').addClass('disabled');
  288. $('.add_global_vector_column').addClass('disabled');
  289. $('.remove_global_vector_column').addClass('disabled');
  290. $('.add_expression').addClass('disabled');
  291. $('.add_parentheses').addClass('disabled');
  292. $('.remove_function_button').addClass('disabled');
  293. $('.button_remove_command').addClass('disabled');
  294. $('.command_drag').addClass('disabled');
  295. $('.simple_add').addClass('disabled');
  296. $('.add_parameter_button').addClass('disabled');
  297. $('.parameter_div_edit').addClass('disabled');
  298. $('.function_name_div_updated').addClass('disabled');
  299. $('.value_rendered').addClass('disabled');
  300. $('.var_name').addClass('disabled');
  301. $('.variable_rendered').addClass('disabled');
  302. $('.dropdown').addClass('disabled');
  303. $('.remove_parameter').addClass('disabled');
  304. $('.ui.dropdown.global_type.disabled').css('opacity', '1');
  305. $('.ui.dropdown.variable_type.disabled').css('opacity', '1');
  306. $('.ui.dropdown.function_return.disabled').css('opacity', '1');
  307. $('.ui.dropdown.parameter_type.disabled').css('opacity', '1');
  308. ivprogCore.CodeEditor.disable(true);
  309. }
  310. function ivprogTextualOrVisual () {
  311. if (settingsProgrammingTypes) {
  312. if (settingsProgrammingTypes == "textual") {
  313. $('.ivprog_visual_panel').css('display', 'none');
  314. $('.ivprog_textual_panel').css('display', 'block');
  315. $('.ivprog_textual_panel').removeClass('loading');
  316. $('.visual_coding_button').removeClass('active');
  317. $('.textual_coding_button').addClass('active');
  318. $('.visual_coding_button').addClass('disabled');
  319. ivprogCore.CodeEditor.setCode(algorithm_in_ilm);
  320. ivprogCore.CodeEditor.disable(false);
  321. }
  322. if (settingsProgrammingTypes == "visual") {
  323. }
  324. }
  325. }
  326. function iassingIntegration () {
  327. // Disable by default...
  328. $('.assessment_button').addClass('disabled');
  329. prepareEnvironment();
  330. if (inIframe()) {
  331. orderIcons();
  332. orderWidth();
  333. }
  334. }
  335. // Função para preparar a interface para o professor criar atividade:
  336. function prepareActivityCreation () {
  337. $('.add_accordion').addClass('accordion');
  338. $('.default_visual_title').toggle();
  339. $('.default_visual_title').append('<span>'+LocalizedStrings.getUI('text_teacher_algorithm')+'</span>');
  340. $('.height_100').removeClass('height_100');
  341. $('.main_title').remove();
  342. $('.ui.accordion').addClass('styled');
  343. $('<div class="content_margin"></div>').insertBefore($('.add_accordion').find('.content').find('.div_to_body'));
  344. $('<div class="ui checkbox"><input type="checkbox" name="include_algo" class="include_algo" tabindex="0" class="hidden"><label>'+LocalizedStrings.getUI('text_teacher_algorithm_include')+'</label></div>').insertAfter('.content_margin');
  345. var cases_test_div = $('<div class="ui accordion styled"><div class="active title"><i class="dropdown icon"></i>'+LocalizedStrings.getUI('text_teacher_test_case')+'</div><div class="active content"></div></div>');
  346. cases_test_div.insertBefore('.accordion');
  347. var config_div = $('<div class="ui accordion styled"><div class="title"><i class="dropdown icon"></i>'+LocalizedStrings.getUI('text_teacher_config')+'</div><div class="content"></div></div>');
  348. config_div.insertAfter(cases_test_div);
  349. $('.ui.accordion').accordion();
  350. $('.ui.checkbox').checkbox();
  351. prepareTableSettings(config_div.find('.content'));
  352. prepareTableTestCases(cases_test_div.find('.content'));
  353. if (inIframe()) {
  354. $('.ui.styled.accordion').css('width', '96%');
  355. }
  356. }
  357. function prepareTableTestCases (div_el) {
  358. var table_el = '<form name="test_cases"><table class="ui blue table"><thead><tr><th width="30px">#</th><th>'+LocalizedStrings.getUI('text_teacher_test_case_input')+'</th><th>'+LocalizedStrings.getUI('text_teacher_test_case_output')+'</th><th width="80px">'+LocalizedStrings.getUI('text_teacher_test_case_actions')+'</th></tr></thead>'
  359. + '<tbody class="content_cases"></tbody></table></form>';
  360. div_el.append(table_el);
  361. div_el.append('<button class="ui teal labeled icon button button_add_case"><i class="plus icon"></i>'+LocalizedStrings.getUI('text_teacher_test_case_add')+'</button>');
  362. $('.button_add_case').on('click', function(e) {
  363. addTestCase();
  364. });
  365. }
  366. var hist = false;
  367. function addTestCase (test_case = null) {
  368. var new_row = null;
  369. if (test_case) {
  370. var text_row = '';
  371. text_row += '<tr><td class="counter"></td><td class="expandingArea"><textarea rows="'+test_case.input.length+'" name="input" class="text_area_input">';
  372. for (var i = 0; i < test_case.input.length; i ++) {
  373. text_row += test_case.input[i];
  374. if ((i + 1) < test_case.input.length) {
  375. text_row += '\n';
  376. }
  377. }
  378. text_row += '</textarea></td><td class="expandingArea"><textarea rows="'+test_case.output.length+'" name="output" class="text_area_output">';
  379. for (var i = 0; i < test_case.output.length; i ++) {
  380. text_row += test_case.output[i];
  381. if ((i + 1) < test_case.output.length) {
  382. text_row += '\n';
  383. }
  384. }
  385. text_row += '</textarea></td><td class="btn_actions"><div class="ui button_remove_case"><i class="red icon times large"></i></div></td></tr>';
  386. new_row = $(text_row);
  387. } else {
  388. new_row = $('<tr><td class="counter"></td><td class="expandingArea"><textarea rows="1" name="input" class="text_area_input"></textarea></td><td class="expandingArea"><textarea rows="1" name="output" class="text_area_output"></textarea></td><td class="btn_actions"><div class="ui button_remove_case"><i class="red icon times large"></i></div></td></tr>');
  389. }
  390. $('.content_cases').append(new_row);
  391. new_row.find('.button_remove_case').click(function(e) {
  392. new_row.remove();
  393. updateTestCaseCounter();
  394. });
  395. new_row.find('textarea').on('input', function(e) {
  396. var lines = $(this).val().split('\n').length;
  397. $(this).attr('rows', lines);
  398. });
  399. updateTestCaseCounter();
  400. $('.text_area_output').keydown(function(e) {
  401. var code = e.keyCode || e.which;
  402. if (code == 9 && $(this).closest("tr").is(":last-child")) {
  403. hist = true;
  404. addTestCase();
  405. }
  406. });
  407. if (test_case == null) {
  408. if (!hist) {
  409. $( ".content_cases tr:last" ).find('.text_area_input').focus();
  410. } else {
  411. hist = false;
  412. }
  413. }
  414. }
  415. function updateTestCaseCounter () {
  416. var i = 1;
  417. $( ".content_cases" ).find('tr').each(function() {
  418. $( this ).find('.counter').text(i);
  419. ++i;
  420. });
  421. }
  422. function prepareTableSettings (div_el) {
  423. div_el.append('<h4 class="ui header">'+LocalizedStrings.getUI('text_config_programming')+'</h4>');
  424. div_el.append('<form name="settings_programming_type"><div class="ui stackable five column grid">'
  425. +'<div class="column"><div class="ui radio"><input type="radio" name="programming_type" id="programming_textual" value="textual" tabindex="0" class="hidden small"><label for="programming_textual">'+LocalizedStrings.getUI('text_config_programming_textual')+'</label></div></div>'
  426. +'<div class="column"><div class="ui radio"><input type="radio" name="programming_type" id="programming_visual" value="visual" checked tabindex="0" class="hidden small"><label for="programming_visual">'+LocalizedStrings.getUI('text_config_programming_visual')+'</label></div></div>'
  427. +'</div></form>');
  428. div_el.append('<h4 class="ui header">'+LocalizedStrings.getUI('text_teacher_data_types')+'</h4>');
  429. div_el.append('<form name="settings_data_types"><div class="ui stackable five column grid">'
  430. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="integer_data_type" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('type_integer')+'</label></div></div>'
  431. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="real_data_type" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('type_real')+'</label></div></div>'
  432. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="text_data_type" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('type_text')+'</label></div></div>'
  433. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="boolean_data_type" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('type_boolean')+'</label></div></div>'
  434. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="void_data_type" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('type_void')+'</label></div></div>'
  435. +'</div></form>');
  436. div_el.append('<h4 class="ui header">'+LocalizedStrings.getUI('text_teacher_commands')+'</h4>');
  437. div_el.append('<form name="settings_commands"><div class="ui stackable three column grid">'
  438. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_read" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_read_var')+'</label></div></div>'
  439. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_write" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_write_var')+'</label></div></div>'
  440. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_comment" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_comment')+'</label></div></div>'
  441. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_attribution" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_attribution')+'</label></div></div>'
  442. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_functioncall" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_functioncall')+'</label></div></div>'
  443. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_iftrue" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_iftrue')+'</label></div></div>'
  444. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_repeatNtimes" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_repeatNtimes')+'</label></div></div>'
  445. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_while" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_whiletrue')+'</label></div></div>'
  446. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_dowhile" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_dowhiletrue')+'</label></div></div>'
  447. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="commands_switch" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_switch')+'</label></div></div>'
  448. +'</div></form>');
  449. div_el.append('<h4 class="ui header">'+LocalizedStrings.getUI('text_teacher_functions')+'</h4>');
  450. div_el.append('<form name="settings_functions"><div class="ui stackable one column grid">'
  451. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="functions_creation" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_teacher_create_functions')+'</label></div></div>'
  452. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="functions_move" checked tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_teacher_create_movement_functions')+'</label></div></div>'
  453. +'</div></form>');
  454. div_el.append('<h4 class="ui header">'+LocalizedStrings.getUI('text_teacher_filter')+'<i class="circular inverted teal question icon"></i></h4>');
  455. div_el.append('<form name="settings_filter"><div class="ui stackable one column grid">'
  456. +'<div class="column"><div class="ui checkbox"><input type="checkbox" name="filter_active" tabindex="0" class="hidden small"><label>'+LocalizedStrings.getUI('text_teacher_filter_active')+'</label></div></div>'
  457. +'</div></form>');
  458. $('.circular.inverted.teal.question.icon').popup({
  459. content : LocalizedStrings.getUI("text_teacher_filter_help"),
  460. delay: {
  461. show: 750,
  462. hide: 0
  463. }
  464. });
  465. $('.ui.checkbox').checkbox();
  466. }
  467. function getTrackingLogs () {
  468. return ivprogCore.getLogsAsString();
  469. // var ret = "";
  470. // for (var i = 0; i < trackingMatrix.length; ++i) {
  471. // ret += "\n" + trackingMatrix[i][0] + "," + trackingMatrix[i][1] + "," + trackingMatrix[i][2];
  472. // if (trackingMatrix[i][3] === 1) {
  473. // ret += ',' + trackingMatrix[i][3] + ',"' + trackingMatrix[i][4] + '"';
  474. // }
  475. // }
  476. // return ret;
  477. }
  478. // Tracking mouse movements
  479. // var trackingMatrix = [];
  480. /* function adCoords(e, code){
  481. var x = e.pageX;
  482. var y = e.pageY;
  483. if (code === 1) {
  484. return [new Date().getTime(), x, y, code, e.target.classList['value']];
  485. } else {
  486. return [x, y, code];
  487. }
  488. } */
  489. // $( document ).ready(function() {
  490. // if (inIframe()) {
  491. // orderIcons();
  492. // orderWidth();
  493. // }
  494. // renderAlgorithm();
  495. // });
  496. function orderWidth() {
  497. $('.ui.raised.container.segment.div_to_body').css('width', '100%');
  498. $('.ui.one.column.container.segment.ivprog_visual_panel').css('width', '100%');
  499. }
  500. function orderIcons() {
  501. $('.ui.one.column.doubling.stackable.grid.container').css('display', 'none');
  502. $('.only_in_frame').css('display', 'block');
  503. }
  504. function inIframe () {
  505. try {
  506. return window.self !== window.top;
  507. } catch (e) {
  508. return true;
  509. }
  510. }
  511. function full_screen() {
  512. // check if user allows full screen of elements. This can be enabled or disabled in browser config. By default its enabled.
  513. //its also used to check if browser supports full screen api.
  514. if("fullscreenEnabled" in document || "webkitFullscreenEnabled" in document || "mozFullScreenEnabled" in document || "msFullscreenEnabled" in document) {
  515. if(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled) {
  516. var element = document.getElementById("ui_main_div");
  517. //requestFullscreen is used to display an element in full screen mode.
  518. if("requestFullscreen" in element) {
  519. element.requestFullscreen();
  520. }
  521. else if ("webkitRequestFullscreen" in element) {
  522. element.webkitRequestFullscreen();
  523. }
  524. else if ("mozRequestFullScreen" in element) {
  525. element.mozRequestFullScreen();
  526. }
  527. else if ("msRequestFullscreen" in element) {
  528. element.msRequestFullscreen();
  529. }
  530. }
  531. } else {
  532. $('.expand_button').addClass('disabled');
  533. }
  534. }
  535. function teacherAutoEval (data) {
  536. $.get(iLMparameters.iLM_PARAM_TeacherAutoEval, function (originalData) {
  537. // Ver arquivo js/util/iassignHelpers.js
  538. var content = ivprogCore.prepareActivityToStudentHelper(data);
  539. // Casos de testes agora são delegados ao tratamento apropriado pela função acima
  540. // var testCases = content.testcases;
  541. settingsProgrammingTypes = content.settingsProgrammingType;
  542. settingsDataTypes = content.settingsDataTypes;
  543. settingsCommands = content.settingsCommands;
  544. settingsFunctions = content.settingsFunctions;
  545. settingsFilter = content.settingsFilter;
  546. if (content.algorithmInIlm != null) {
  547. algorithm_in_ilm = content.algorithmInIlm;
  548. parsePreviousAlgorithm();
  549. ivprogCore.autoEval(originalData, parent.getEvaluationCallback);
  550. }
  551. ivprogTextualOrVisual();
  552. if (settingsFilter && settingsFilter[0]) {
  553. blockAllEditingOptions();
  554. }
  555. });
  556. }