commands_sidebar.js 41 KB

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