1
0

repeatNtimes.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import * as Models from '../ivprog_elements';
  2. import { LocalizedStrings } from '../../services/localizedStringsService';
  3. import * as CommandsManagement from '../commands';
  4. import * as ConditionalExpressionManagement from './conditional_expression';
  5. import * as VariableValueMenu from './variable_value_menu';
  6. import * as ContextualizedMenu from './contextualized_menu';
  7. import * as GenericExpressionManagement from './generic_expression';
  8. export function createFloatingCommand () {
  9. return $('<div class="ui repeatNtimes created_element"> <i class="ui icon small sync"></i> <span> repita_para i de 0 ate 10 passo 1 <br> </span></div>');
  10. }
  11. export function renderCommand (command, function_obj) {
  12. var ret = '<div class="ui repeatNtimes command_container"> <i class="ui icon small sync command_drag"></i> <i class="ui icon times red button_remove_command"></i> <div class="ui context_menu"></div> <span class="span_command_spec"> ' + LocalizedStrings.getUI('text_for') + ' </span> <div class="ui attribution_expression"><div class="ui variable_attribution"></div> <span class="text_receives span_command_spec" style="margin-left: 10px;margin-right: 20px;"></span> <div class="ui var_value_expression div_expression_st"></div> </div> <span class="span_command_spec separator_character" style="margin-left: 25px; margin-right: 15px;">ate</span> <div class="conditional_expression"></div> <div class="pass_button"></div> <div class="ui incrementation_field"><span class="text_inc_receives span_command_spec"></span> <div class="ui first_operand"></div><div class="ui operator"></div><div class="ui second_operand"></div></div> <span class="span_command_spec"> </span>';
  13. ret += '<div class="ui block_commands">';
  14. ret += '</div>';
  15. ret += '<span> </span>';
  16. ret += '</div>';
  17. var el = $(ret);
  18. el.data('command', command);
  19. el.find('.block_commands').data('command', command);
  20. addHandlers(command, function_obj, el);
  21. ContextualizedMenu.renderMenu(command, el.find('.context_menu'), function_obj, el);
  22. VariableValueMenu.renderMenu(command, command.var_attribution, el.find('.variable_attribution'), function_obj);
  23. //ConditionalExpressionManagement.renderExpression(command, command.expression2, function_obj, el.find('.conditional_expression'));
  24. VariableValueMenu.renderMenu(command, command.expression2, el.find('.conditional_expression'), function_obj);
  25. //GenericExpressionManagement.renderExpression(command, function_obj, el.find('.conditional_expression'), command.expression2);
  26. //VariableValueMenu.renderMenu(command, command.var_incrementation, el.find('.incrementation_variable'), function_obj);
  27. //angle double right
  28. if (!command.expression1) {
  29. command.expression1 = new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, "0", null, null, true);
  30. }
  31. el.find('.text_receives').text('de');
  32. VariableValueMenu.renderMenu(command, command.expression1, el.find('.var_value_expression'), function_obj);
  33. if (!command.expression3) {
  34. el.find('.pass_button').html('<button class="ui">passo <i class="ui icon angle double right"></i></button>');
  35. el.find('.pass_button').find('button').on('click', function() {
  36. togglePasso(command);
  37. });
  38. /*var exp = new Models.ExpressionElement(Models.EXPRESSION_ELEMENTS.exp_op_exp,
  39. [command.var_attribution,
  40. Models.ARITHMETIC_TYPES.plus,
  41. new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, "1", null, null, true)]);
  42. command.expression3 = exp;
  43. command.var_incrementation = command.var_attribution;*/
  44. } else {
  45. el.find('.pass_button').html('<button class="ui">passo <i class="ui icon angle double left"></i></button>');
  46. el.find('.pass_button').find('button').on('click', function() {
  47. togglePasso(command);
  48. });
  49. renderOperator(command, function_obj, el.find('.operator'), command.expression3, 1);
  50. VariableValueMenu.renderMenu(command, command.expression3.itens[2], el.find('.second_operand'), function_obj);
  51. }
  52. if (command.commands_block) {
  53. for (var j = 0; j < command.commands_block.length; j++) {
  54. CommandsManagement.renderCommand(command.commands_block[j], $(el.find('.block_commands')[0]), 3, function_obj);
  55. }
  56. }
  57. return el;
  58. }
  59. function togglePasso (command) {
  60. if (!command.expression3) {
  61. var exp = new Models.ExpressionElement(Models.EXPRESSION_ELEMENTS.exp_op_exp,
  62. [command.var_attribution,
  63. Models.ARITHMETIC_TYPES.plus,
  64. new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, "1", null, null, true)]);
  65. command.expression3 = exp;
  66. command.var_incrementation = command.var_attribution;
  67. } else {
  68. command.expression3 = null;
  69. }
  70. renderAlgorithm();
  71. }
  72. export function manageExpressionElements (command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element) {
  73. if (dom_object.hasClass('variable_attribution')) {
  74. if (!command.expression3) {
  75. var exp = new Models.ExpressionElement(Models.EXPRESSION_ELEMENTS.exp_op_exp,
  76. [command.var_attribution,
  77. Models.ARITHMETIC_TYPES.plus,
  78. new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, "1", null, null, true)]);
  79. command.expression3 = exp;
  80. command.var_incrementation = command.var_attribution;
  81. var cond_exp =
  82. new Models.ArithmeticExpression(
  83. command.var_attribution,
  84. new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true),
  85. Models.ARITHMETIC_COMPARISON.less_than);
  86. command.expression2.expression = cond_exp;
  87. }
  88. dom_object.parent().find('.text_receives').text('de');
  89. command.expression1 = new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, "0", null, null, true);
  90. dom_object.parent().find('.var_value_expression').empty();
  91. VariableValueMenu.renderMenu(command, command.expression1, dom_object.parent().find('.var_value_expression'), function_obj);
  92. renderAlgorithm();
  93. }
  94. if (dom_object.hasClass('incrementation_variable')) {
  95. dom_object.parent().find('.text_inc_receives').text('de');
  96. var exp = new Models.ExpressionElement(Models.EXPRESSION_ELEMENTS.exp_op_exp,
  97. [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true),
  98. Models.ARITHMETIC_TYPES.plus,
  99. new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)]);
  100. command.expression3 = exp;
  101. VariableValueMenu.renderMenu(command, command.expression3.itens[0], dom_object.parent().find('.first_operand'), function_obj);
  102. renderOperator(command, function_obj, dom_object.parent().find('.operator'), command.expression3, 1);
  103. VariableValueMenu.renderMenu(command, command.expression3.itens[2], dom_object.parent().find('.second_operand'), function_obj);
  104. }
  105. }
  106. export function manageClearExpressionElements (command, ref_object, dom_object, menu_var_or_value, function_obj, $selectedItem, expression_element) {
  107. if (dom_object.hasClass('variable_attribution')) {
  108. $(dom_object).parent().find('.text_receives').text('');
  109. command.expression1 = null;
  110. $(dom_object).parent().find('.var_value_expression').empty();
  111. }
  112. if (dom_object.hasClass('incrementation_variable')) {
  113. $(dom_object).parent().find('.text_inc_receives').text('');
  114. command.expression3 = null;
  115. $(dom_object).parent().find('.first_operand').empty();
  116. $(dom_object).parent().find('.operator').empty();
  117. $(dom_object).parent().find('.second_operand').empty();
  118. }
  119. }
  120. function addHandlers (command, function_obj, repeatNtimes_dom) {
  121. repeatNtimes_dom.find('.button_remove_command').on('click', function() {
  122. if (CommandsManagement.removeCommand(command, function_obj, repeatNtimes_dom)) {
  123. repeatNtimes_dom.fadeOut(400, function() {
  124. repeatNtimes_dom.remove();
  125. });
  126. }
  127. });
  128. }
  129. function renderOperator (command, function_obj, temp_op, expression_element, index_op) {
  130. var menu_operator = $('<div class="ui dropdown"><div class="text"></div></div>');
  131. menu_operator.dropdown({
  132. values: [
  133. {
  134. name : '+',
  135. value : Models.ARITHMETIC_TYPES.plus,
  136. selected : (expression_element.itens[index_op] == Models.ARITHMETIC_TYPES.plus)
  137. },
  138. {
  139. name : '-',
  140. value : Models.ARITHMETIC_TYPES.minus,
  141. selected : (expression_element.itens[index_op] == Models.ARITHMETIC_TYPES.minus)
  142. }
  143. ],
  144. onChange: function(value, text, $selectedItem) {
  145. expression_element.itens[index_op] = value;
  146. }
  147. });
  148. temp_op.append(menu_operator);
  149. }