iassign-integration-functions.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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. runCodeAssessment();
  108. }
  109. }
  110. //var testCases = null
  111. var settingsDataTypes = null;
  112. var settingsCommands = null;
  113. var settingsFunctions = null;
  114. var settingsProgrammingTypes = null;
  115. var settingsFilter = null;
  116. var algorithm_in_ilm = null;
  117. var previousContent = null;
  118. // Função para que o iMA leia os dados da atividade fornecidos pelo iTarefa
  119. function getiLMContent () {
  120. // O parâmetro "iLM_PARAM_Assignment" fornece o URL do endereço que deve ser
  121. // requisitado via AJAX para a captura dos dados da atividade
  122. $.get(iLMparameters.iLM_PARAM_Assignment, function (data) {
  123. //professor invocou a avaliação automática dos exercícios do bloco
  124. if (iLMparameters.iLM_PARAM_TeacherAutoEval != null) {
  125. teacherAutoEval(data);
  126. //não deve exibir nenhuma interface...
  127. return;
  128. } else if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  129. // Aluno está trabalhando em alguma atividade:
  130. previousContent = data;
  131. prepareActivityToStudent(data);
  132. } else { // Professor está editando uma atividade:
  133. previousContent = data;
  134. prepareActivityToEdit(data);
  135. }
  136. window.block_render = false;
  137. renderAlgorithm();
  138. });
  139. }
  140. function prepareActivityToEdit (ilm_cont) {
  141. //var content = JSON.parse(ilm_cont.split('\n::algorithm::')[0]);
  142. // Ver arquivo js/util/iassignHelpers.js
  143. var content = ivprogCore.prepareActivityToStudentHelper(ilm_cont);
  144. var testCases = ivprogCore.getTestCases();
  145. settingsProgrammingTypes = content.settingsProgrammingType;
  146. settingsDataTypes = content.settingsDataTypes;
  147. settingsCommands = content.settingsCommands;
  148. settingsFunctions = content.settingsFunctions;
  149. settingsFilter = content.settingsFilter;
  150. for (var i = 0; i < testCases.length; i++) {
  151. addTestCase(testCases[i]);
  152. }
  153. if (content.algorithmInIlm != null) {
  154. algorithm_in_ilm = content.algorithmInIlm;
  155. $("input[name='include_algo']").prop('checked', true);
  156. includePreviousAlgorithm();
  157. renderAlgorithm();
  158. }
  159. ivprogTextualOrVisual();
  160. if (settingsFilter && settingsFilter[0]) {
  161. blockAllEditingOptions();
  162. }
  163. }
  164. function parsePreviousAlgorithm () {
  165. window.program_obj.functions = JSON.parse(algorithm_in_ilm).functions;
  166. window.program_obj.globals = JSON.parse(algorithm_in_ilm).globals;
  167. }
  168. function includePreviousAlgorithm () {
  169. if (settingsProgrammingTypes == "textual") {
  170. return;
  171. }
  172. parsePreviousAlgorithm();
  173. window.watchW.watch(window.program_obj.globals, function(){
  174. if (window.insertContext) {
  175. setTimeout(function(){ renderAlgorithm(); }, 300);
  176. window.insertContext = false;
  177. } else {
  178. renderAlgorithm();
  179. }
  180. }, 1);
  181. for (var i = 0; i < window.program_obj.functions.length; i ++) {
  182. window.watchW.watch(window.program_obj.functions[i].parameters_list, function(){
  183. if (window.insertContext) {
  184. setTimeout(function(){ renderAlgorithm(); }, 300);
  185. window.insertContext = false;
  186. } else {
  187. renderAlgorithm();
  188. }
  189. }, 1);
  190. window.watchW.watch(window.program_obj.functions[i].variables_list, function(){
  191. if (window.insertContext) {
  192. setTimeout(function(){ renderAlgorithm(); }, 300);
  193. window.insertContext = false;
  194. } else {
  195. renderAlgorithm();
  196. }
  197. }, 1);
  198. if (window.program_obj.functions[i].is_main) {
  199. window.program_obj.functions[i].name = LocalizedStrings.getUI("start");
  200. }
  201. }
  202. window.watchW.watch(window.program_obj.functions, function(){
  203. if (window.insertContext) {
  204. setTimeout(function(){ renderAlgorithm(); }, 300);
  205. window.insertContext = false;
  206. } else {
  207. renderAlgorithm();
  208. }
  209. }, 1);
  210. }
  211. function prepareActivityToStudent (ilm_cont) {
  212. // Ver arquivo js/util/iassignHelpers.js
  213. var content = ivprogCore.prepareActivityToStudentHelper(ilm_cont);
  214. // Casos de testes agora são delegados ao tratamento apropriado pela função acima
  215. // var testCases = content.testcases;
  216. settingsProgrammingTypes = content.settingsProgrammingType;
  217. settingsDataTypes = content.settingsDataTypes;
  218. settingsCommands = content.settingsCommands;
  219. settingsFunctions = content.settingsFunctions;
  220. settingsFilter = content.settingsFilter;
  221. if (content.algorithmInIlm != null) {
  222. algorithm_in_ilm = content.algorithmInIlm;
  223. includePreviousAlgorithm();
  224. }
  225. $('.assessment_button').removeClass('disabled');
  226. renderAlgorithm();
  227. ivprogTextualOrVisual();
  228. if (settingsFilter && settingsFilter[0]) {
  229. blockAllEditingOptions();
  230. }
  231. }
  232. // Função para organizar se para criação, visualização ou resolução de atividade
  233. function prepareEnvironment () {
  234. $('.div_to_body').click(function(e) {
  235. // trackingMatrix.push(adCoords(e, 1));
  236. ivprogCore.registerClick(e.pageX, e.pageY, e.target.classList['value']);
  237. });
  238. // Se iLM_PARAM_SendAnswer for false, então trata-se de resolução de atividade,
  239. // portanto, a "DIV" de resolução é liberada
  240. if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
  241. //$('.resolucao').css("display","block");
  242. getiLMContent();
  243. // $('.div_to_body').mousemove(function(e) {
  244. // trackingMatrix.push(adCoords(e, 0));
  245. // });
  246. // $('.div_to_body').click(function(e) {
  247. // // trackingMatrix.push(adCoords(e, 1));
  248. // ivprogCore.registerClick(e.pageX, e.pageY, e.target.classList['value']);
  249. // });
  250. } else if (iLMparameters.iLM_PARAM_Assignment) {
  251. // Caso não esteja em modo de resolução de atividade, a visualização no momento
  252. // é para a elaboração de atividade:
  253. //$('.elaboracao').css("display","block");
  254. // Se possuir o parâmetro iLMparameters.iLM_PARAM_Assignment, o professor
  255. // está editando uma atividade:
  256. getiLMContent();
  257. } else {
  258. renderAlgorithm();
  259. }
  260. if ((iLMparameters.iLM_PARAM_AssignmentURL == "true") && (iLMparameters.iLM_PARAM_SendAnswer == "true")) {
  261. prepareActivityCreation();
  262. }
  263. }
  264. function blockAllEditingOptions () {
  265. if ((iLMparameters.iLM_PARAM_AssignmentURL == "true") && (iLMparameters.iLM_PARAM_SendAnswer == "true")) {
  266. return;
  267. }
  268. $('.add_global_button').addClass('disabled');
  269. $('.move_function').addClass('disabled');
  270. $('.add_function_button').addClass('disabled');
  271. $('.add_var_button_function .ui.icon.button.purple').addClass('disabled');
  272. $('.add_var_button_function').addClass('disabled');
  273. $('.menu_commands').addClass('disabled');
  274. $('.global_type').addClass('disabled');
  275. $('.editing_name_var').addClass('disabled');
  276. $('.span_value_variable').addClass('disabled');
  277. $('.remove_global').addClass('disabled');
  278. $('.ui.icon.ellipsis.vertical.inverted').addClass('disabled');
  279. $('.alternate_constant').addClass('disabled');
  280. $('.remove_variable').addClass('disabled');
  281. $('.add_global_matrix_column').addClass('disabled');
  282. $('.remove_global_matrix_column').addClass('disabled');
  283. $('.add_global_matrix_line').addClass('disabled');
  284. $('.remove_global_matrix_line').addClass('disabled');
  285. $('.add_global_vector_column').addClass('disabled');
  286. $('.remove_global_vector_column').addClass('disabled');
  287. $('.add_expression').addClass('disabled');
  288. $('.add_parentheses').addClass('disabled');
  289. $('.remove_function_button').addClass('disabled');
  290. $('.button_remove_command').addClass('disabled');
  291. $('.command_drag').addClass('disabled');
  292. $('.simple_add').addClass('disabled');
  293. $('.add_parameter_button').addClass('disabled');
  294. $('.parameter_div_edit').addClass('disabled');
  295. $('.function_name_div_updated').addClass('disabled');
  296. $('.value_rendered').addClass('disabled');
  297. $('.var_name').addClass('disabled');
  298. $('.variable_rendered').addClass('disabled');
  299. $('.dropdown').addClass('disabled');
  300. $('.remove_parameter').addClass('disabled');
  301. $('.ui.dropdown.global_type.disabled').css('opacity', '1');
  302. $('.ui.dropdown.variable_type.disabled').css('opacity', '1');
  303. $('.ui.dropdown.function_return.disabled').css('opacity', '1');
  304. $('.ui.dropdown.parameter_type.disabled').css('opacity', '1');
  305. ivprogCore.CodeEditor.disable(true);
  306. }
  307. function ivprogTextualOrVisual () {
  308. if (settingsProgrammingTypes) {
  309. if (settingsProgrammingTypes == "textual") {
  310. $('.ivprog_visual_panel').css('display', 'none');
  311. $('.ivprog_textual_panel').css('display', 'block');
  312. $('.ivprog_textual_panel').removeClass('loading');
  313. $('.visual_coding_button').removeClass('active');
  314. $('.textual_coding_button').addClass('active');
  315. $('.visual_coding_button').addClass('disabled');
  316. ivprogCore.CodeEditor.setCode(algorithm_in_ilm);
  317. ivprogCore.CodeEditor.disable(false);
  318. }
  319. if (settingsProgrammingTypes == "visual") {
  320. }
  321. }
  322. }
  323. function iassingIntegration () {
  324. // Disable by default...
  325. $('.assessment_button').addClass('disabled');
  326. prepareEnvironment();
  327. if (inIframe()) {
  328. orderIcons();
  329. orderWidth();
  330. }
  331. }
  332. // Função para preparar a interface para o professor criar atividade:
  333. function prepareActivityCreation () {
  334. $('.add_accordion').addClass('accordion');
  335. $('.default_visual_title').toggle();
  336. $('.default_visual_title').append('<span>'+LocalizedStrings.getUI('text_teacher_algorithm')+'</span>');
  337. $('.height_100').removeClass('height_100');
  338. $('.main_title').remove();
  339. $('.ui.accordion').addClass('styled');
  340. $('<div class="content_margin"></div>').insertBefore($('.add_accordion').find('.content').find('.div_to_body'));
  341. $('<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');
  342. 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>');
  343. cases_test_div.insertBefore('.accordion');
  344. 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>');
  345. config_div.insertAfter(cases_test_div);
  346. $('.ui.accordion').accordion();
  347. $('.ui.checkbox').checkbox();
  348. prepareTableSettings(config_div.find('.content'));
  349. prepareTableTestCases(cases_test_div.find('.content'));
  350. if (inIframe()) {
  351. $('.ui.styled.accordion').css('width', '96%');
  352. }
  353. }
  354. function prepareTableTestCases (div_el) {
  355. 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>'
  356. + '<tbody class="content_cases"></tbody></table></form>';
  357. div_el.append(table_el);
  358. 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>');
  359. $('.button_add_case').on('click', function(e) {
  360. addTestCase();
  361. });
  362. }
  363. var hist = false;
  364. function addTestCase (test_case = null) {
  365. var new_row = null;
  366. if (test_case) {
  367. var text_row = '';
  368. text_row += '<tr><td class="counter"></td><td class="expandingArea"><textarea rows="'+test_case.input.length+'" name="input" class="text_area_input">';
  369. for (var i = 0; i < test_case.input.length; i ++) {
  370. text_row += test_case.input[i];
  371. if ((i + 1) < test_case.input.length) {
  372. text_row += '\n';
  373. }
  374. }
  375. text_row += '</textarea></td><td class="expandingArea"><textarea rows="'+test_case.output.length+'" name="output" class="text_area_output">';
  376. for (var i = 0; i < test_case.output.length; i ++) {
  377. text_row += test_case.output[i];
  378. if ((i + 1) < test_case.output.length) {
  379. text_row += '\n';
  380. }
  381. }
  382. text_row += '</textarea></td><td class="btn_actions"><div class="ui button_remove_case"><i class="red icon times large"></i></div></td></tr>';
  383. new_row = $(text_row);
  384. } else {
  385. 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>');
  386. }
  387. $('.content_cases').append(new_row);
  388. new_row.find('.button_remove_case').click(function(e) {
  389. new_row.remove();
  390. updateTestCaseCounter();
  391. });
  392. new_row.find('textarea').on('input', function(e) {
  393. var lines = $(this).val().split('\n').length;
  394. $(this).attr('rows', lines);
  395. });
  396. updateTestCaseCounter();
  397. $('.text_area_output').keydown(function(e) {
  398. var code = e.keyCode || e.which;
  399. if (code == 9 && $(this).closest("tr").is(":last-child")) {
  400. hist = true;
  401. addTestCase();
  402. }
  403. });
  404. if (test_case == null) {
  405. if (!hist) {
  406. $( ".content_cases tr:last" ).find('.text_area_input').focus();
  407. } else {
  408. hist = false;
  409. }
  410. }
  411. }
  412. function updateTestCaseCounter () {
  413. var i = 1;
  414. $( ".content_cases" ).find('tr').each(function() {
  415. $( this ).find('.counter').text(i);
  416. ++i;
  417. });
  418. }
  419. function prepareTableSettings (div_el) {
  420. div_el.append('<h4 class="ui header">'+LocalizedStrings.getUI('text_config_programming')+'</h4>');
  421. div_el.append('<form name="settings_programming_type"><div class="ui stackable five column grid">'
  422. +'<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>'
  423. +'<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>'
  424. +'</div></form>');
  425. div_el.append('<h4 class="ui header">'+LocalizedStrings.getUI('text_teacher_data_types')+'</h4>');
  426. div_el.append('<form name="settings_data_types"><div class="ui stackable five column grid">'
  427. +'<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>'
  428. +'<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>'
  429. +'<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>'
  430. +'<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>'
  431. +'<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>'
  432. +'</div></form>');
  433. div_el.append('<h4 class="ui header">'+LocalizedStrings.getUI('text_teacher_commands')+'</h4>');
  434. div_el.append('<form name="settings_commands"><div class="ui stackable three column grid">'
  435. +'<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>'
  436. +'<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>'
  437. +'<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>'
  438. +'<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>'
  439. +'<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>'
  440. +'<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>'
  441. +'<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>'
  442. +'<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>'
  443. +'<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>'
  444. +'<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>'
  445. +'</div></form>');
  446. div_el.append('<h4 class="ui header">'+LocalizedStrings.getUI('text_teacher_functions')+'</h4>');
  447. div_el.append('<form name="settings_functions"><div class="ui stackable one column grid">'
  448. +'<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>'
  449. +'<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>'
  450. +'</div></form>');
  451. div_el.append('<h4 class="ui header">'+LocalizedStrings.getUI('text_teacher_filter')+'<i class="circular inverted teal question icon"></i></h4>');
  452. div_el.append('<form name="settings_filter"><div class="ui stackable one column grid">'
  453. +'<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>'
  454. +'</div></form>');
  455. $('.circular.inverted.teal.question.icon').popup({
  456. content : LocalizedStrings.getUI("text_teacher_filter_help"),
  457. delay: {
  458. show: 750,
  459. hide: 0
  460. }
  461. });
  462. $('.ui.checkbox').checkbox();
  463. }
  464. function getTrackingLogs () {
  465. return ivprogCore.getLogsAsString();
  466. // var ret = "";
  467. // for (var i = 0; i < trackingMatrix.length; ++i) {
  468. // ret += "\n" + trackingMatrix[i][0] + "," + trackingMatrix[i][1] + "," + trackingMatrix[i][2];
  469. // if (trackingMatrix[i][3] === 1) {
  470. // ret += ',' + trackingMatrix[i][3] + ',"' + trackingMatrix[i][4] + '"';
  471. // }
  472. // }
  473. // return ret;
  474. }
  475. // Tracking mouse movements
  476. // var trackingMatrix = [];
  477. /* function adCoords(e, code){
  478. var x = e.pageX;
  479. var y = e.pageY;
  480. if (code === 1) {
  481. return [new Date().getTime(), x, y, code, e.target.classList['value']];
  482. } else {
  483. return [x, y, code];
  484. }
  485. } */
  486. // $( document ).ready(function() {
  487. // if (inIframe()) {
  488. // orderIcons();
  489. // orderWidth();
  490. // }
  491. // renderAlgorithm();
  492. // });
  493. function orderWidth() {
  494. $('.ui.raised.container.segment.div_to_body').css('width', '100%');
  495. $('.ui.one.column.container.segment.ivprog_visual_panel').css('width', '100%');
  496. }
  497. function orderIcons() {
  498. $('.ui.one.column.doubling.stackable.grid.container').css('display', 'none');
  499. $('.only_in_frame').css('display', 'block');
  500. }
  501. function inIframe () {
  502. try {
  503. return window.self !== window.top;
  504. } catch (e) {
  505. return true;
  506. }
  507. }
  508. function full_screen() {
  509. // check if user allows full screen of elements. This can be enabled or disabled in browser config. By default its enabled.
  510. //its also used to check if browser supports full screen api.
  511. if("fullscreenEnabled" in document || "webkitFullscreenEnabled" in document || "mozFullScreenEnabled" in document || "msFullscreenEnabled" in document) {
  512. if(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled) {
  513. var element = document.getElementById("ui_main_div");
  514. //requestFullscreen is used to display an element in full screen mode.
  515. if("requestFullscreen" in element) {
  516. element.requestFullscreen();
  517. }
  518. else if ("webkitRequestFullscreen" in element) {
  519. element.webkitRequestFullscreen();
  520. }
  521. else if ("mozRequestFullScreen" in element) {
  522. element.mozRequestFullScreen();
  523. }
  524. else if ("msRequestFullscreen" in element) {
  525. element.msRequestFullscreen();
  526. }
  527. }
  528. } else {
  529. $('.expand_button').addClass('disabled');
  530. }
  531. }
  532. function teacherAutoEval (data) {
  533. $.get(iLMparameters.iLM_PARAM_TeacherAutoEval, function (originalData) {
  534. // Ver arquivo js/util/iassignHelpers.js
  535. var content = ivprogCore.prepareActivityToStudentHelper(data);
  536. // Casos de testes agora são delegados ao tratamento apropriado pela função acima
  537. // var testCases = content.testcases;
  538. settingsProgrammingTypes = content.settingsProgrammingType;
  539. settingsDataTypes = content.settingsDataTypes;
  540. settingsCommands = content.settingsCommands;
  541. settingsFunctions = content.settingsFunctions;
  542. settingsFilter = content.settingsFilter;
  543. if (content.algorithmInIlm != null) {
  544. algorithm_in_ilm = content.algorithmInIlm;
  545. parsePreviousAlgorithm();
  546. ivprogCore.autoEval(originalData, parent.getEvaluationCallback);
  547. }
  548. ivprogTextualOrVisual();
  549. if (settingsFilter && settingsFilter[0]) {
  550. blockAllEditingOptions();
  551. }
  552. });
  553. }