commands_sidebar.js 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  1. import $ from 'jquery';
  2. import { Types } from './types';
  3. import * as Models from './ivprog_elements_sidebar';
  4. import { LocalizedStrings } from './../services/localizedStringsService';
  5. import * as GlobalsManagement from './globals';
  6. import * as VariablesManagement from './variables';
  7. import * as CommentsManagement from './commands/comment';
  8. import * as ReadersManagement from './commands/reader';
  9. import * as WritersManagement from './commands/writer';
  10. import * as AttributionsManagement from './commands/attribution';
  11. import * as IftruesManagement from './commands/iftrue';
  12. import * as RepeatNtimesManagement from './commands/repeatNtimes';
  13. import * as WhiletruesManagement from './commands/whiletrue';
  14. import * as DowhiletruesManagement from './commands/dowhiletrue';
  15. import * as SwitchesManagement from './commands/switch';
  16. import * as FunctioncallsManagement from './commands/functioncall';
  17. import * as VariableValueMenuManagement from './commands/variable_value_menu';
  18. import * as BreaksManagement from './commands/break';
  19. import * as ReturnsManagement from './commands/return';
  20. import { VariableValueMenu } from './ivprog_elements_sidebar';
  21. var has_element_created_draged = false;
  22. var which_element_is_draged = null;
  23. export function removeCommand (command, function_obj, dom_obj) {
  24. console.log('debugging removeCommand');
  25. console.log('command');
  26. console.log(command);
  27. console.log('function_obj');
  28. console.log(function_obj);
  29. console.log('dom_obj');
  30. console.log(dom_obj);
  31. if (function_obj.commands.indexOf(command) > -1) {
  32. function_obj.commands.splice(function_obj.commands.indexOf(command), 1);
  33. return true;
  34. }
  35. // Utilize dois parantNode, pois o primeiro é o div de comandos
  36. try {
  37. if (dom_obj.parent().parent().data('command').commands_block.indexOf(command) > -1) {
  38. dom_obj.parent().parent().data('command').commands_block.splice
  39. (dom_obj.parent().parent().data('command').commands_block.indexOf(command), 1);
  40. return true;
  41. }
  42. } catch (err) {}
  43. try {
  44. if (dom_obj.parent().parent().data('command').type == Models.COMMAND_TYPES.iftrue) {
  45. if (dom_obj.parent().parent().data('command').commands_else.indexOf(command) > -1) {
  46. dom_obj.parent().parent().data('command').commands_else.splice
  47. (dom_obj.parent().parent().data('command').commands_else.indexOf(command), 1);
  48. return true;
  49. }
  50. }
  51. } catch (err) {}
  52. console.log('veja: ');
  53. console.log(dom_obj.parent());
  54. if (dom_obj.parent().data('switchcase')) {
  55. console.log("o que encontrei: ");
  56. console.log(dom_obj.parent().data('switchcase'));
  57. dom_obj.parent().data('switchcase').commands_block.splice(dom_obj.parent().data('switchcase').commands_block.indexOf(command), 1);
  58. return true;
  59. }
  60. return false;
  61. }
  62. export function createFloatingCommand (function_obj, function_container, command_type, mouse_event) {
  63. var floatingObject;
  64. switch (command_type) {
  65. case Models.COMMAND_TYPES.break:
  66. floatingObject = BreaksManagement.createFloatingCommand();
  67. break;
  68. case Models.COMMAND_TYPES.comment:
  69. floatingObject = CommentsManagement.createFloatingCommand();
  70. break;
  71. case Models.COMMAND_TYPES.reader:
  72. floatingObject = ReadersManagement.createFloatingCommand();
  73. break;
  74. case Models.COMMAND_TYPES.writer:
  75. floatingObject = WritersManagement.createFloatingCommand();
  76. break;
  77. case Models.COMMAND_TYPES.attribution:
  78. floatingObject = AttributionsManagement.createFloatingCommand();
  79. break;
  80. case Models.COMMAND_TYPES.iftrue:
  81. floatingObject = IftruesManagement.createFloatingCommand();
  82. break;
  83. case Models.COMMAND_TYPES.repeatNtimes:
  84. floatingObject = RepeatNtimesManagement.createFloatingCommand();
  85. break;
  86. case Models.COMMAND_TYPES.whiletrue:
  87. floatingObject = WhiletruesManagement.createFloatingCommand();
  88. break;
  89. case Models.COMMAND_TYPES.dowhiletrue:
  90. floatingObject = DowhiletruesManagement.createFloatingCommand();
  91. break;
  92. case Models.COMMAND_TYPES.switch:
  93. floatingObject = SwitchesManagement.createFloatingCommand();
  94. break;
  95. case Models.COMMAND_TYPES.functioncall:
  96. floatingObject = FunctioncallsManagement.createFloatingCommand();
  97. break;
  98. case Models.COMMAND_TYPES.return:
  99. floatingObject = ReturnsManagement.createFloatingCommand();
  100. break;
  101. }
  102. floatingObject.draggable().appendTo("body");
  103. floatingObject.mouseup(function(evt) {
  104. manageCommand(function_obj, function_container, evt, command_type);
  105. });
  106. floatingObject.css("position", "absolute");
  107. mouse_event.type = "mousedown.draggable";
  108. mouse_event.target = floatingObject[0];
  109. floatingObject.css("left", mouse_event.pageX - 15);
  110. floatingObject.css("top", mouse_event.pageY - 15);
  111. floatingObject.trigger(mouse_event);
  112. }
  113. // before_after_inside: 1 -> before, 2 -> after, 3 -> inside
  114. export function renderCommand (command, element_reference, before_after_inside, function_obj) {
  115. var createdElement;
  116. switch (command.type) {
  117. case Models.COMMAND_TYPES.comment:
  118. createdElement = CommentsManagement.renderCommand(command, function_obj);
  119. break;
  120. case Models.COMMAND_TYPES.break:
  121. createdElement = BreaksManagement.renderCommand(command, function_obj);
  122. break;
  123. case Models.COMMAND_TYPES.reader:
  124. createdElement = ReadersManagement.renderCommand(command, function_obj);
  125. break;
  126. case Models.COMMAND_TYPES.writer:
  127. createdElement = WritersManagement.renderCommand(command, function_obj);
  128. break;
  129. case Models.COMMAND_TYPES.attribution:
  130. createdElement = AttributionsManagement.renderCommand(command, function_obj);
  131. break;
  132. case Models.COMMAND_TYPES.functioncall:
  133. createdElement = FunctioncallsManagement.renderCommand(command, function_obj);
  134. break;
  135. case Models.COMMAND_TYPES.iftrue:
  136. createdElement = IftruesManagement.renderCommand(command, function_obj);
  137. break;
  138. case Models.COMMAND_TYPES.repeatNtimes:
  139. createdElement = RepeatNtimesManagement.renderCommand(command, function_obj);
  140. break;
  141. case Models.COMMAND_TYPES.whiletrue:
  142. createdElement = WhiletruesManagement.renderCommand(command, function_obj);
  143. break;
  144. case Models.COMMAND_TYPES.dowhiletrue:
  145. createdElement = DowhiletruesManagement.renderCommand(command, function_obj);
  146. break;
  147. case Models.COMMAND_TYPES.switch:
  148. createdElement = SwitchesManagement.renderCommand(command, function_obj);
  149. break;
  150. case Models.COMMAND_TYPES.return:
  151. createdElement = ReturnsManagement.renderCommand(command, function_obj);
  152. break;
  153. }
  154. switch (before_after_inside) {
  155. case 1:
  156. createdElement.insertBefore(element_reference);
  157. break;
  158. case 2:
  159. createdElement.insertAfter(element_reference);
  160. break;
  161. case 3:
  162. element_reference.append(createdElement);
  163. break;
  164. }
  165. }
  166. export function genericCreateCommand (command_type) {
  167. switch (command_type) {
  168. case Models.COMMAND_TYPES.break:
  169. return new Models.Break();
  170. case Models.COMMAND_TYPES.comment:
  171. return new Models.Comment(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_value, LocalizedStrings.getUI('text_comment'), null, null, false));
  172. case Models.COMMAND_TYPES.reader:
  173. return new Models.Reader(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_variable, null, null, null, false));
  174. case Models.COMMAND_TYPES.writer:
  175. return new Models.Writer([new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true)]);
  176. case Models.COMMAND_TYPES.attribution:
  177. return new Models.Attribution(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_variable, null, null, null, false),
  178. []);
  179. case Models.COMMAND_TYPES.functioncall:
  180. return new Models.FunctionCall(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_function, null, null, null, false), null);
  181. case Models.COMMAND_TYPES.iftrue:
  182. return new Models.IfTrue(new Models.ConditionalExpression(null), null, null);
  183. case Models.COMMAND_TYPES.repeatNtimes:
  184. return new Models.RepeatNTimes(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_variable, null, null, null, false),
  185. new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_variable, null, null, null, false),
  186. null, new Models.ConditionalExpression(null), null, null);
  187. case Models.COMMAND_TYPES.whiletrue:
  188. return new Models.WhileTrue(new Models.ConditionalExpression(null), null);
  189. case Models.COMMAND_TYPES.dowhiletrue:
  190. return new Models.DoWhileTrue(new Models.ConditionalExpression(null), null);
  191. case Models.COMMAND_TYPES.switch:
  192. var sc = [new Models.SwitchCase(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true))];
  193. return new Models.Switch(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.variable_and_function, null, null, null, true), sc);
  194. case Models.COMMAND_TYPES.return:
  195. return new Models.Return(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true));
  196. }
  197. }
  198. function preCreateCommand(command_type, function_called) {
  199. if (function_called == null)
  200. return genericCreateCommand(command_type);
  201. else if (command_type == 'functioncall') {
  202. if (function_called.return_type != Types.VOID) {
  203. var var_menu = new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true);
  204. var_menu.function_called = function_called;
  205. var exp = new Models.ExpressionElement(Models.EXPRESSION_ELEMENTS.op_exp, [Models.ARITHMETIC_TYPES.none,
  206. var_menu]);
  207. exp.function_called = function_called;
  208. return new Models.Attribution(new Models.VariableValueMenu(
  209. VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_variable, null, null, null, false),[exp]);
  210. }
  211. var varM = new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_function, null, null, null, false);
  212. varM.function_called = function_called;
  213. var parameters = [];
  214. for (var i = 0; i < function_called.parameters_list.length; i++) {
  215. parameters.push(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true));
  216. }
  217. var functionCall = new Models.FunctionCall(varM, parameters);
  218. return functionCall;
  219. }
  220. }
  221. function manageCommand(function_obj, function_container, event, command_type, function_called) {
  222. $(".created_element").each(function (index) {
  223. $(this).remove();
  224. });
  225. var el = $(document.elementFromPoint(event.clientX, event.clientY));
  226. console.log('soltou no: ');
  227. console.log(el);
  228. console.log(el.data('fun'));
  229. // Primeiro verificar se ele soltou no espaço da função correta:
  230. var hier = el.parentsUntil(".all_functions");
  231. var esta_correto = false;
  232. var esta_na_div_correta = false;
  233. if (el.hasClass("commands_list_div")) {
  234. esta_na_div_correta = true;
  235. }
  236. for (var i = 0; i < hier.length; i++) {
  237. var temp = $(hier[i]);
  238. if (temp.hasClass("commands_list_div")) {
  239. esta_na_div_correta = true;
  240. }
  241. if (temp.data('fun') == function_obj) {
  242. esta_correto = true;
  243. break;
  244. }
  245. }
  246. if (!esta_correto) {
  247. has_element_created_draged = false;
  248. which_element_is_draged = null;
  249. return;
  250. } else {
  251. if (!esta_na_div_correta) {
  252. has_element_created_draged = false;
  253. which_element_is_draged = null;
  254. return;
  255. }
  256. }
  257. // Agora é descobrir qual o escopo para adicionar o comando:
  258. // Se o elemento clicado possuir o atributo "fun", então, é direto na div dos comandos:
  259. if (typeof el.data('fun') !== 'undefined') {
  260. // Se a lista de comandos estiver vazia, então é o primeiro.
  261. // Portanto, ele deve soltar o elemento obrigatoriamente no objeto vazio
  262. if ((el.data('fun').commands == null) || (el.data('fun').commands.length == 0)) {
  263. // pode adicionar
  264. el.data('fun').commands = [];
  265. var new_cmd = preCreateCommand(command_type,function_called);
  266. el.data('fun').commands.push(new_cmd);
  267. renderCommand(new_cmd, $(function_container).find('.commands_list_div'), 3, function_obj);
  268. } else { // Entra nesse else, caso já existam outros comandos no bloco:
  269. findNearbyCommandToAddInFunctionScope(el, event, $(function_container).find('.commands_list_div'), function_obj, command_type, function_called);
  270. }
  271. } else {
  272. console.log("soltou em um comando");
  273. // descobrir em qual comando ele soltou:
  274. var hier_find = el.parentsUntil(".commands_list_div");
  275. var hierarquia_bottom_up = [];
  276. if (typeof el.data('command') !== 'undefined') {
  277. hierarquia_bottom_up.push(el.data('command'));
  278. }
  279. for (var i = 0; i < hier_find.length; i++) {
  280. if (typeof $(hier_find[i]).data('command') !== 'undefined') {
  281. hierarquia_bottom_up.push($(hier_find[i]).data('command'));
  282. }
  283. }
  284. console.log("comando em que soltou: ");
  285. console.log(hierarquia_bottom_up[0]);
  286. console.log("hierarquia de baixo para cima na árvore, de onde ele soltou: ");
  287. for (var i = 0; i < hierarquia_bottom_up.length; i++) {
  288. console.log(hierarquia_bottom_up[i]);
  289. }
  290. // Se for do tipo break, verificar se está no contexto correto:
  291. // Caso não esteja no contexto, apenas retorna sem dar continuidade:
  292. var is_correct_context = false;
  293. if (command_type == Models.COMMAND_TYPES.break) {
  294. for (var i = 0; i < hierarquia_bottom_up.length; i++) {
  295. if ((hierarquia_bottom_up[i].type == Models.COMMAND_TYPES.repeatNtimes)
  296. || (hierarquia_bottom_up[i].type == Models.COMMAND_TYPES.whiletrue)
  297. || (hierarquia_bottom_up[i].type == Models.COMMAND_TYPES.dowhiletrue)
  298. || (hierarquia_bottom_up[i].type == Models.COMMAND_TYPES.switch)) {
  299. is_correct_context = true;
  300. break;
  301. }
  302. }
  303. if (!is_correct_context) {
  304. console.error("Context not allowed to insert BREAK COMMAND!");
  305. return;
  306. }
  307. }
  308. // se a hierarquia possuir apenas um elemento, então está na raiz dos comandos:
  309. if (hierarquia_bottom_up.length == 1) {
  310. console.log('QQ1');
  311. var sub_elemento = false;
  312. for (var i = 0; i < hier_find.length; i++) {
  313. if (typeof $(hier_find[i]).data('command') !== 'undefined') {
  314. console.log('QQ2');
  315. findBeforeOrAfterCommandToAdd(hier_find[i], event, function_obj, command_type, function_called);
  316. sub_elemento = true;
  317. break;
  318. }
  319. }
  320. if (!sub_elemento) {
  321. console.log('QQ3');
  322. findBeforeOrAfterCommandToAdd(el[0], event, function_obj, command_type, function_called);
  323. }
  324. } else {
  325. console.log('QQ4');
  326. // caso exista mais de um elemento na hierarquia:
  327. if (typeof $(el).data('command') !== 'undefined') {
  328. console.log('QQ5');
  329. console.log("PPP1");
  330. insertCommandInBlockHierar(el[0], event, function_obj, command_type, hier_find, hierarquia_bottom_up, function_called);
  331. } else {
  332. console.log('QQ6');
  333. var sub_elemento = false;
  334. for (var i = 0; i < hier_find.length; i++) {
  335. if (typeof $(hier_find[i]).data('command') !== 'undefined') {
  336. console.log('QQ7');
  337. insertCommandInBlockHierar(hier_find[i], event, function_obj, command_type, hier_find, hierarquia_bottom_up, function_called);
  338. sub_elemento = true;
  339. break;
  340. }
  341. }
  342. }
  343. }
  344. }
  345. has_element_created_draged = false;
  346. which_element_is_draged = null;
  347. }
  348. function insertCommandInBlockHierar(el, event, function_obj, command_type, hier_dom, hier_obj, function_called = null) {
  349. var el_jq = $(el);
  350. var command_parent = el_jq.data('command');
  351. if ((el_jq.data('command').type == Models.COMMAND_TYPES.repeatNtimes) ||
  352. (el_jq.data('command').type == Models.COMMAND_TYPES.whiletrue) ||
  353. (el_jq.data('command').type == Models.COMMAND_TYPES.dowhiletrue) ||
  354. (el_jq.data('command').type == Models.COMMAND_TYPES.switch)) {
  355. console.log('QQ17');
  356. if ((el_jq.data('command').type == Models.COMMAND_TYPES.repeatNtimes) ||
  357. (el_jq.data('command').type == Models.COMMAND_TYPES.whiletrue) ||
  358. (el_jq.data('command').type == Models.COMMAND_TYPES.dowhiletrue)) {
  359. console.log('QQ18');
  360. // Se não tiver outro comando ainda no bloco, só adiciona:
  361. if (command_parent.commands_block == null || command_parent.commands_block.length == 0) {
  362. command_parent.commands_block = [];
  363. var recentComand = preCreateCommand(command_type, function_called);
  364. command_parent.commands_block.push(recentComand);
  365. renderCommand(recentComand, el_jq.find('.block_commands'), 3, function_obj);
  366. } else { // Se já tem algum comando no bloco:
  367. findNearbyCommandToAddInBlockScope(el, event, el, function_obj, command_type, command_parent, function_called);
  368. }
  369. } else {
  370. // QUANDO FOR BLOCO DO TIPO IF OU SWITCH/CASE:
  371. addCommandToSwitchCase(event, function_obj, command_type);
  372. }
  373. } else {
  374. console.log('QQ19');
  375. // entra neste bloco, se soltou o comando sobre outro comando dentro de um subbloco:
  376. findBeforeOrAfterCommandToAddInsertBlock(el, event, function_obj, command_type, function_called);
  377. }
  378. }
  379. function findNearbyCommandToAddInBlockScope(el, event, node_list_commands, function_obj, command_type, command_parent, function_called = null) {
  380. var all_sub = $(node_list_commands).find('div.command_container');
  381. var menor_distancia = 999999999;
  382. var elemento_menor_distancia = null;
  383. var antes = true;
  384. var t_bot;
  385. var t_top;
  386. // Descobrindo o elemento mais próximo:
  387. for (var i = 0; i < all_sub.length; i++) {
  388. t_top = all_sub[i].getBoundingClientRect().top;
  389. t_bot = all_sub[i].getBoundingClientRect().top + all_sub[i].getBoundingClientRect().height;
  390. if ((t_top - event.clientY) < menor_distancia) {
  391. menor_distancia = event.clientY - t_top;
  392. elemento_menor_distancia = all_sub[i];
  393. }
  394. }
  395. var borda_inferior = elemento_menor_distancia.parentNode.getBoundingClientRect().top + elemento_menor_distancia.parentNode.getBoundingClientRect().height;
  396. var recentComand = preCreateCommand(command_type,function_called);
  397. // Está mais próximo da borda de baixo, ou seja.. inserir por último:
  398. if ((borda_inferior - event.clientY) < menor_distancia) {
  399. command_parent.commands_block.push(recentComand);
  400. //
  401. renderCommand(recentComand, node_list_commands, 3, function_obj);
  402. } else {
  403. var index = command_parent.commands_block.indexOf($(elemento_menor_distancia).data('command'));
  404. if (index > -1) {
  405. command_parent.commands_block.splice(index, 0, recentComand);
  406. }
  407. renderCommand(recentComand, elemento_menor_distancia, 1, function_obj);
  408. }
  409. }
  410. function findBeforeOrAfterCommandToAddInsertBlock(el, event, function_obj, command_type, function_called = null) {
  411. var el_jq = $(el);
  412. var command_parent = $(el.parentNode.parentNode).data('command');
  413. var command_target = el_jq.data('command');
  414. var temp_parent = $(el.parentNode.parentNode);
  415. var is_in_else = false;
  416. if (!command_parent) {
  417. command_parent = el_jq.data('command');
  418. temp_parent = el_jq;
  419. var hier = el_jq.parentsUntil(".command_container");
  420. for (var i = 0; i < hier.length; i++) {
  421. var temp = $(hier[i]);
  422. if (typeof temp.data('else') != 'undefined') {
  423. is_in_else = true;
  424. }
  425. if (typeof temp.data('command') != 'undefined') {
  426. command_parent = temp.data('command');
  427. temp_parent = temp;
  428. }
  429. }
  430. }
  431. var hier = el_jq.parentsUntil(".command_container");
  432. for (var i = 0; i < hier.length; i++) {
  433. var temp = $(hier[i]);
  434. if (typeof temp.data('else') != 'undefined') {
  435. is_in_else = true;
  436. }
  437. }
  438. if (command_parent == command_target) {
  439. var hier = el_jq.parentsUntil(".command_container");
  440. for (var i = 0; i < hier.length; i++) {
  441. var temp = $(hier[i]);
  442. if (typeof temp.data('else') !== 'undefined') {
  443. is_in_else = true;
  444. break;
  445. }
  446. }
  447. }
  448. if ((command_parent.type != Models.COMMAND_TYPES.iftrue) && (command_parent.type != Models.COMMAND_TYPES.switch)) {
  449. var hier = temp_parent.parentsUntil(".all_cases_div");
  450. console.log("vou procurar!!");
  451. for (var i = 0; i < hier.length; i++) {
  452. console.log("estou vasculhando...");
  453. var temp = $(hier[i]);
  454. if (typeof temp.data('switchcase') !== 'undefined') {
  455. console.log("encontrei");
  456. command_parent = temp.data('switchcase');
  457. is_in_else = false;
  458. break;
  459. }
  460. }
  461. }
  462. console.log('debugging:');
  463. console.log('el_jq');
  464. console.log(el_jq);
  465. console.log('command_parent');
  466. console.log(command_parent);
  467. console.log('command_target');
  468. console.log(command_target);
  469. var menor_distancia = 999999999;
  470. var antes = true;
  471. var t_bot;
  472. var t_top;
  473. t_top = el.getBoundingClientRect().top;
  474. t_bot = el.getBoundingClientRect().top + el.getBoundingClientRect().height;
  475. var d_top = event.clientY - t_top; // distancia topo
  476. var d_bot = t_bot - event.clientY; // distancia baixo
  477. // Está mais próximo da borda de baixo, ou seja.. inserir por último:
  478. if (d_top < d_bot) {
  479. var recentComand = preCreateCommand(command_type,function_called);
  480. console.log('MMM1');
  481. if (is_in_else) {
  482. console.log('MMM2');
  483. if (command_parent == command_target) {
  484. console.log('MMM3');
  485. if (command_parent.commands_else == null || command_parent.commands_else.length == 0) {
  486. command_parent.commands_else = [];
  487. var recentComand = preCreateCommand(command_type,function_called);
  488. command_parent.commands_else.push(recentComand);
  489. renderCommand(recentComand, el_jq, 3, function_obj);
  490. } else { // Se já tem algum comando no bloco:
  491. findInBlockCorrectPlace(el_jq, event, function_obj, command_type, true, function_called);
  492. }
  493. return;
  494. }
  495. console.log('MMM7');
  496. var index = command_parent.commands_else.indexOf(command_target);
  497. if (index > -1) {
  498. command_parent.commands_else.splice(index, 0, recentComand);
  499. }
  500. renderCommand(recentComand, el, 1, function_obj);
  501. } else {
  502. console.log('MMM4');
  503. if (command_parent == command_target) {
  504. console.log('Nxxxx5');
  505. if (command_parent.commands_block == null || command_parent.commands_block.length == 0) {
  506. command_parent.commands_block = [];
  507. console.log('SSS4');
  508. var recentComand = preCreateCommand(command_type,function_called);
  509. command_parent.commands_block.push(recentComand);
  510. renderCommand(recentComand, el_jq, 3, function_obj);
  511. } else {
  512. console.log('SSS5');
  513. findInBlockCorrectPlace(el_jq, event, function_obj, command_type, false, function_called);
  514. }
  515. return;
  516. }
  517. console.log('MMM6');
  518. var index = command_parent.commands_block.indexOf(command_target);
  519. if (index > -1) {
  520. command_parent.commands_block.splice(index, 0, recentComand);
  521. }
  522. renderCommand(recentComand, el, 1, function_obj);
  523. }
  524. } else {
  525. console.log('XXX1');
  526. var recentComand = preCreateCommand(command_type,function_called);
  527. if (is_in_else) {
  528. if (command_parent == command_target) {
  529. console.log('MMM3');
  530. if (command_parent.commands_else == null || command_parent.commands_else.length == 0) {
  531. command_parent.commands_else = [];
  532. console.log('SSS1');
  533. var recentComand = preCreateCommand(command_type,function_called);
  534. command_parent.commands_else.push(recentComand);
  535. renderCommand(recentComand, el_jq, 3, function_obj);
  536. } else { // Se já tem algum comando no bloco:
  537. console.log('SSS2');
  538. findInBlockCorrectPlace(el_jq, event, function_obj, command_type, true, function_called);
  539. }
  540. return;
  541. }
  542. console.log('XXX2');
  543. var index = command_parent.commands_else.indexOf(command_target);
  544. if (index > -1) {
  545. command_parent.commands_else.splice((index + 1), 0, recentComand);
  546. }
  547. renderCommand(recentComand, el, 2, function_obj);
  548. } else {
  549. if (command_parent == command_target) {
  550. console.log('Nxxxx78');
  551. if (command_parent.commands_block == null || command_parent.commands_block.length == 0) {
  552. command_parent.commands_block = [];
  553. var recentComand = preCreateCommand(command_type,function_called);
  554. command_parent.commands_block.push(recentComand);
  555. console.log('SSS6');
  556. renderCommand(recentComand, el_jq, 3, function_obj);
  557. } else {
  558. console.log('SSS7');
  559. findInBlockCorrectPlace(el_jq, event, function_obj, command_type, false, function_called);
  560. }
  561. return;
  562. }
  563. console.log('XXX3');
  564. var index = command_parent.commands_block.indexOf(command_target);
  565. if (index > -1) {
  566. command_parent.commands_block.splice((index + 1), 0, recentComand);
  567. }
  568. renderCommand(recentComand, el, 2, function_obj);
  569. }
  570. }
  571. }
  572. function insertCommandInBlock(el, event, function_obj, command_type, function_called = 0) {
  573. var el_jq = $(el);
  574. var command_parent = el_jq.data('command');
  575. if ((el_jq.data('command').type == Models.COMMAND_TYPES.repeatNtimes) ||
  576. (el_jq.data('command').type == Models.COMMAND_TYPES.whiletrue) ||
  577. (el_jq.data('command').type == Models.COMMAND_TYPES.dowhiletrue)) {
  578. // Se não tiver outro comando ainda no bloco, só adiciona:
  579. if (command_parent.commands_block == null || command_parent.commands_block.length == 0) {
  580. command_parent.commands_block = [];
  581. var recentComand = preCreateCommand(command_type,function_called);
  582. command_parent.commands_block.push(recentComand);
  583. renderCommand(recentComand, el_jq.find('.block_commands'), 3, function_obj);
  584. } else { // Se já tem algum comando no bloco:
  585. findInBlockCorrectPlace(el, event, function_obj, command_type, false, function_called);
  586. }
  587. } else if (el_jq.data('command').type == Models.COMMAND_TYPES.iftrue) {
  588. console.log('QQ9');
  589. // no if ou no else?
  590. var correct_div = $(document.elementFromPoint(event.pageX, event.pageY));
  591. var is_in_if = true;
  592. if (correct_div.data('if')) {
  593. is_in_if = true;
  594. } else if (correct_div.data('else')) {
  595. is_in_if = false;
  596. } else {
  597. var hier = correct_div.parentsUntil(".command_container");
  598. for (var i = 0; i < hier.length; i++) {
  599. var temp = $(hier[i]);
  600. if (typeof temp.data('if') !== 'undefined') {
  601. is_in_if = true;
  602. break;
  603. }
  604. if (typeof temp.data('else') !== 'undefined') {
  605. is_in_if = false;
  606. break;
  607. }
  608. }
  609. }
  610. if (is_in_if) {
  611. if (command_parent.commands_block == null || command_parent.commands_block.length == 0) {
  612. command_parent.commands_block = [];
  613. var recentComand = preCreateCommand(command_type,function_called);
  614. command_parent.commands_block.push(recentComand);
  615. renderCommand(recentComand, el_jq.find('.commands_if'), 3, function_obj);
  616. } else { // Se já tem algum comando no bloco:
  617. findInBlockCorrectPlace(el_jq.find('.commands_if'), event, function_obj, command_type, false, function_called);
  618. }
  619. } else {
  620. if (command_parent.commands_else == null || command_parent.commands_else.length == 0) {
  621. command_parent.commands_else = [];
  622. var recentComand = preCreateCommand(command_type,function_called);
  623. command_parent.commands_else.push(recentComand);
  624. renderCommand(recentComand, el_jq.find('.commands_else'), 3, function_obj);
  625. } else { // Se já tem algum comando no bloco:
  626. findInBlockCorrectPlace(el_jq.find('.commands_else'), event, function_obj, command_type, true, function_called);
  627. }
  628. }
  629. } else { // é do tipo switch
  630. console.log("está tentando inserir em um switch que está na raiz!");
  631. addCommandToSwitchCase(event, function_obj, command_type);
  632. }
  633. }
  634. function addCommandToSwitchCase(event, function_obj, command_type) {
  635. var el = $(document.elementFromPoint(event.clientX, event.clientY));
  636. var which_case = el.data('switchcase');
  637. var case_div = el;
  638. if (!which_case) {
  639. var hier_find = el.parentsUntil(".all_cases_div");
  640. for (var i = 0; i < hier_find.length; i++) {
  641. if (typeof $(hier_find[i]).data('switchcase') !== 'undefined') {
  642. which_case = $(hier_find[i]).data('switchcase');
  643. case_div = $(hier_find[i]);
  644. break;
  645. }
  646. }
  647. }
  648. if (which_case.commands_block == null || which_case.commands_block.length < 1) {
  649. which_case.commands_block = [];
  650. var recentComand = preCreateCommand(command_type,function_called);
  651. which_case.commands_block.push(recentComand);
  652. renderCommand(recentComand, case_div.find('.case_commands_block'), 3, function_obj);
  653. } else {
  654. findInBlockCorrectPlaceInSwitchCase(which_case, case_div, event, function_obj, command_type, function_called);
  655. }
  656. }
  657. function findInBlockCorrectPlaceInSwitchCase(which_case, case_div, event, function_obj, command_type) {
  658. var all_sub = case_div.find('div.command_container');
  659. var menor_distancia = 999999999;
  660. var elemento_menor_distancia = null;
  661. var antes = true;
  662. var t_bot;
  663. var t_top;
  664. // Descobrindo o elemento mais próximo:
  665. for (var i = 0; i < all_sub.length; i++) {
  666. t_top = all_sub[i].getBoundingClientRect().top;
  667. t_bot = all_sub[i].getBoundingClientRect().top + all_sub[i].getBoundingClientRect().height;
  668. if ((t_top - event.clientY) < menor_distancia) {
  669. menor_distancia = event.clientY - t_top;
  670. elemento_menor_distancia = all_sub[i];
  671. }
  672. }
  673. var borda_inferior = elemento_menor_distancia.parentNode.getBoundingClientRect().top + elemento_menor_distancia.parentNode.getBoundingClientRect().height;
  674. // Está mais próximo da borda de baixo, ou seja.. inserir por último:
  675. if ((borda_inferior - event.clientY) < menor_distancia) {
  676. var recentComand = preCreateCommand(command_type,function_called);
  677. which_case.commands_block.push(recentComand);
  678. renderCommand(recentComand, $(case_div.find('.case_commands_block')[0]), 3, function_obj);
  679. } else {
  680. var recentComand = preCreateCommand(command_type,function_called);
  681. var index = which_case.commands_block.indexOf($(elemento_menor_distancia).data('command'));
  682. if (index > -1) {
  683. which_case.commands_block.splice(index, 0, recentComand);
  684. renderCommand(recentComand, elemento_menor_distancia, 1, function_obj);
  685. }
  686. }
  687. }
  688. function findInBlockCorrectPlace(el, event, function_obj, command_type, is_in_else = false, function_called = null) {
  689. var el_jq = $(el);
  690. var all_sub = el_jq.find('div.command_container');
  691. var menor_distancia = 999999999;
  692. var elemento_menor_distancia = null;
  693. var antes = true;
  694. var t_bot;
  695. var t_top;
  696. // Descobrindo o elemento mais próximo:
  697. for (var i = 0; i < all_sub.length; i++) {
  698. t_top = all_sub[i].getBoundingClientRect().top;
  699. t_bot = all_sub[i].getBoundingClientRect().top + all_sub[i].getBoundingClientRect().height;
  700. if ((t_top - event.clientY) < menor_distancia) {
  701. menor_distancia = event.clientY - t_top;
  702. elemento_menor_distancia = all_sub[i];
  703. }
  704. }
  705. var borda_inferior = elemento_menor_distancia.parentNode.getBoundingClientRect().top + elemento_menor_distancia.parentNode.getBoundingClientRect().height;
  706. console.log("menor_distancia: ");
  707. console.log(elemento_menor_distancia);
  708. // Está mais próximo da borda de baixo, ou seja.. inserir por último:
  709. if ((borda_inferior - event.clientY) < menor_distancia) {
  710. console.log('QQ11');
  711. var recentComand = preCreateCommand(command_type,function_called);
  712. var command_parent = el_jq.data('command');
  713. if (is_in_else) {
  714. console.log('QQ15');
  715. command_parent.commands_else.push(recentComand);
  716. console.log('el_jq');
  717. console.log(el_jq);
  718. console.log("$(el_jq.find('.commands_else')[0]):: ");
  719. console.log($(el_jq.find('.commands_else')[0]));
  720. renderCommand(recentComand, el_jq, 3, function_obj);
  721. } else {
  722. console.log('QQ16');
  723. command_parent.commands_block.push(recentComand);
  724. renderCommand(recentComand, $(el_jq.find('.block_commands')[0]), 3, function_obj);
  725. }
  726. } else {
  727. console.log('QQ12');
  728. var recentComand = preCreateCommand(command_type,function_called);
  729. var command_parent = el_jq.data('command');
  730. if (is_in_else) {
  731. var index = command_parent.commands_else.indexOf($(elemento_menor_distancia).data('command'));
  732. if (index > -1) {
  733. command_parent.commands_else.splice(index, 0, recentComand);
  734. renderCommand(recentComand, elemento_menor_distancia, 1, function_obj);
  735. }
  736. } else {
  737. var index = command_parent.commands_block.indexOf($(elemento_menor_distancia).data('command'));
  738. if (index > -1) {
  739. command_parent.commands_block.splice(index, 0, recentComand);
  740. renderCommand(recentComand, elemento_menor_distancia, 1, function_obj);
  741. }
  742. }
  743. }
  744. }
  745. function findBeforeOrAfterCommandToAdd(el, event, function_obj, command_type, function_called = null) {
  746. switch ($(el).data('command').type) {
  747. case Models.COMMAND_TYPES.iftrue:
  748. case Models.COMMAND_TYPES.switch:
  749. case Models.COMMAND_TYPES.repeatNtimes:
  750. case Models.COMMAND_TYPES.whiletrue:
  751. case Models.COMMAND_TYPES.dowhiletrue:
  752. insertCommandInBlock(el, event, function_obj, command_type, function_called);
  753. return;
  754. }
  755. var menor_distancia = 999999999;
  756. var antes = true;
  757. var t_bot;
  758. var t_top;
  759. t_top = el.getBoundingClientRect().top;
  760. t_bot = el.getBoundingClientRect().top + el.getBoundingClientRect().height;
  761. var d_top = event.clientY - t_top; // distancia topo
  762. var d_bot = t_bot - event.clientY; // distancia baixo
  763. // Está mais próximo da borda de baixo, ou seja.. inserir por último:
  764. if (d_top < d_bot) {
  765. var recentComand = preCreateCommand(command_type,function_called);
  766. var index = function_obj.commands.indexOf($(el).data('command'));
  767. if (index > -1) {
  768. function_obj.commands.splice(index, 0, recentComand);
  769. }
  770. renderCommand(recentComand, el, 1, function_obj);
  771. } else {
  772. var recentComand = preCreateCommand(command_type,function_called);
  773. var index = function_obj.commands.indexOf($(el).data('command'));
  774. if (index > -1) {
  775. function_obj.commands.splice((index + 1), 0, recentComand);
  776. }
  777. renderCommand(recentComand, el, 2, function_obj);
  778. }
  779. }
  780. function findNearbyCommandToAddInFunctionScope(el, event, node_list_commands, function_obj, command_type, function_called = null) {
  781. var all_sub = $(node_list_commands).find('div.command_container');
  782. var menor_distancia = 999999999;
  783. var elemento_menor_distancia = null;
  784. var antes = true;
  785. var t_bot;
  786. var t_top;
  787. // Descobrindo o elemento mais próximo:
  788. for (var i = 0; i < all_sub.length; i++) {
  789. t_top = all_sub[i].getBoundingClientRect().top;
  790. t_bot = all_sub[i].getBoundingClientRect().top + all_sub[i].getBoundingClientRect().height;
  791. if ((t_top - event.clientY) < menor_distancia) {
  792. menor_distancia = event.clientY - t_top;
  793. elemento_menor_distancia = all_sub[i];
  794. }
  795. }
  796. var borda_inferior = elemento_menor_distancia.parentNode.getBoundingClientRect().top + elemento_menor_distancia.parentNode.getBoundingClientRect().height;
  797. var recentComand = preCreateCommand(command_type,function_called);
  798. // Está mais próximo da borda de baixo, ou seja.. inserir por último:
  799. if ((borda_inferior - event.clientY) < menor_distancia) {
  800. function_obj.commands.push(recentComand);
  801. //
  802. renderCommand(recentComand, node_list_commands, 3, function_obj);
  803. } else {
  804. var index = function_obj.commands.indexOf($(elemento_menor_distancia).data('command'));
  805. if (index > -1) {
  806. function_obj.commands.splice(index, 0, recentComand);
  807. }
  808. renderCommand(recentComand, elemento_menor_distancia, 1, function_obj);
  809. }
  810. }
  811. //******************************************************
  812. //* DOUGLAS
  813. //******************************************************
  814. createFloatingCommand = function (function_obj, function_container, command_type, mouse_event) {
  815. var floatingObject;
  816. switch (command_type) {
  817. case Models.COMMAND_TYPES.break:
  818. floatingObject = BreaksManagement.createFloatingCommand();
  819. break;
  820. case Models.COMMAND_TYPES.comment:
  821. floatingObject = CommentsManagement.createFloatingCommand();
  822. break;
  823. case Models.COMMAND_TYPES.reader:
  824. floatingObject = ReadersManagement.createFloatingCommand();
  825. break;
  826. case Models.COMMAND_TYPES.writer:
  827. floatingObject = WritersManagement.createFloatingCommand();
  828. break;
  829. case Models.COMMAND_TYPES.attribution:
  830. floatingObject = AttributionsManagement.createFloatingCommand();
  831. break;
  832. case Models.COMMAND_TYPES.iftrue:
  833. floatingObject = IftruesManagement.createFloatingCommand();
  834. break;
  835. case Models.COMMAND_TYPES.repeatNtimes:
  836. floatingObject = RepeatNtimesManagement.createFloatingCommand();
  837. break;
  838. case Models.COMMAND_TYPES.whiletrue:
  839. floatingObject = WhiletruesManagement.createFloatingCommand();
  840. break;
  841. case Models.COMMAND_TYPES.dowhiletrue:
  842. floatingObject = DowhiletruesManagement.createFloatingCommand();
  843. break;
  844. case Models.COMMAND_TYPES.switch:
  845. floatingObject = SwitchesManagement.createFloatingCommand();
  846. break;
  847. case Models.COMMAND_TYPES.functioncall:
  848. floatingObject = FunctioncallsManagement.createFloatingCommand();
  849. break;
  850. }
  851. floatingObject.draggable().appendTo("body");
  852. floatingObject.on('dragstart', function (e) {
  853. console.log("TESTEEEEE");
  854. }).trigger('dragstart');
  855. floatingObject.mouseup(function (evt) {
  856. console.log('mouseup')
  857. $(".commands_list_div, .commands_list_div, .block_commands, .command_container").off('mouseenter mouseleave');
  858. manageCommand(function_obj, function_container, evt, command_type);
  859. });
  860. floatingObject.css("position", "absolute");
  861. mouse_event.type = "mousedown.draggable";
  862. mouse_event.target = floatingObject[0];
  863. floatingObject.css("left", mouse_event.pageX - 15);
  864. floatingObject.css("top", mouse_event.pageY - 15);
  865. floatingObject.trigger(mouse_event);
  866. }
  867. /*
  868. manageCommand = function(function_obj, function_container, event, command_type) {
  869. $( ".created_element" ).each(function( index ) {
  870. $(this).remove();
  871. });
  872. var el = $(document.elementFromPoint(event.clientX, event.clientY));
  873. console.log('soltou no: ');
  874. console.log(el);
  875. console.log(el.data('fun'));
  876. // Primeiro verificar se ele soltou no espaço da função correta:
  877. var hier = el.parentsUntil(".all_functions");
  878. var esta_correto = false;
  879. var esta_na_div_correta = false;
  880. if (el.hasClass("commands_list_div")) {
  881. esta_na_div_correta = true;
  882. }
  883. for (var i = 0; i < hier.length; i++) {
  884. var temp = $(hier[i]);
  885. if (temp.hasClass("commands_list_div")) {
  886. esta_na_div_correta = true;
  887. }
  888. if (temp.data('fun') == function_obj || function_obj == null) {
  889. function_obj = temp.data('fun');
  890. esta_correto = true;
  891. break;
  892. }
  893. }
  894. if (!esta_correto) {
  895. has_element_created_draged = false;
  896. which_element_is_draged = null;
  897. return;
  898. } else {
  899. if (!esta_na_div_correta) {
  900. has_element_created_draged = false;
  901. which_element_is_draged = null;
  902. return;
  903. }
  904. }
  905. // Agora é descobrir qual o escopo para adicionar o comando:
  906. // Se o elemento clicado possuir o atributo "fun", então, é direto na div dos comandos:
  907. if (typeof el.data('fun') !== 'undefined') {
  908. // Se a lista de comandos estiver vazia, então é o primeiro.
  909. // Portanto, ele deve soltar o elemento obrigatoriamente no objeto vazio
  910. if ((el.data('fun').commands == null) || (el.data('fun').commands.length == 0)) {
  911. // pode adicionar
  912. el.data('fun').commands = [];
  913. var new_cmd = genericCreateCommand(command_type);
  914. el.data('fun').commands.push(new_cmd);
  915. renderCommand(new_cmd, $(function_container).find('.commands_list_div'), 3, function_obj);
  916. } else { // Entra nesse else, caso já existam outros comandos no bloco:
  917. findNearbyCommandToAddInFunctionScope(el, event, $(function_container).find('.commands_list_div'), function_obj, command_type);
  918. }
  919. } else {
  920. console.log("soltou em um comando");
  921. // descobrir em qual comando ele soltou:
  922. var hier_find = el.parentsUntil(".commands_list_div");
  923. var hierarquia_bottom_up = [];
  924. if (typeof el.data('command') !== 'undefined') {
  925. hierarquia_bottom_up.push(el.data('command'));
  926. }
  927. for (var i = 0; i < hier_find.length; i++) {
  928. if (typeof $(hier_find[i]).data('command') !== 'undefined') {
  929. hierarquia_bottom_up.push($(hier_find[i]).data('command'));
  930. }
  931. }
  932. console.log("comando em que soltou: ");
  933. console.log(hierarquia_bottom_up[0]);
  934. console.log("hierarquia de baixo para cima na árvore, de onde ele soltou: ");
  935. for (var i = 0; i < hierarquia_bottom_up.length; i++) {
  936. console.log(hierarquia_bottom_up[i]);
  937. }
  938. // se a hierarquia possuir apenas um elemento, então está na raiz dos comandos:
  939. if (hierarquia_bottom_up.length == 1) {
  940. var sub_elemento = false;
  941. for (var i = 0; i < hier_find.length; i++) {
  942. if (typeof $(hier_find[i]).data('command') !== 'undefined') {
  943. findBeforeOrAfterCommandToAdd(hier_find[i], event, function_obj, command_type);
  944. sub_elemento = true;
  945. break;
  946. }
  947. }
  948. if (!sub_elemento) {
  949. findBeforeOrAfterCommandToAdd(el[0], event, function_obj, command_type);
  950. }
  951. } else {
  952. // caso exista mais de um elemento na hierarquia:
  953. if (typeof $(el).data('command') !== 'undefined') {
  954. console.log("PPP1");
  955. insertCommandInBlockHierar(el[0], event, function_obj, command_type, hier_find, hierarquia_bottom_up);
  956. } else {
  957. var sub_elemento = false;
  958. for (var i = 0; i < hier_find.length; i++) {
  959. if (typeof $(hier_find[i]).data('command') !== 'undefined') {
  960. insertCommandInBlockHierar(hier_find[i], event, function_obj, command_type, hier_find, hierarquia_bottom_up);
  961. sub_elemento = true;
  962. break;
  963. }
  964. }
  965. }
  966. }
  967. }
  968. has_element_created_draged = false;
  969. which_element_is_draged = null;
  970. }
  971. */
  972. export function prepareManageCommand(function_obj, function_container, evt, command_type, function_called = null) {
  973. manageCommand(function_obj, function_container, evt, command_type, function_called);
  974. }