comment.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // iVProg - www.usp.br/line/ivprog
  2. // LInE - Free Education, Private Data
  3. import { LocalizedStrings } from '../../services/localizedStringsService';
  4. import * as VariableValueMenu from './variable_value_menu';
  5. import * as CommandsManagement from '../commands';
  6. export function createFloatingCommand () {
  7. return $(
  8. '<div class="ui comment created_element"> <i class="ui icon small quote left"></i> <span class="span_comment_text" "> ' +
  9. LocalizedStrings.getUI("text_comment") +
  10. ' </span></div>'
  11. );
  12. }
  13. export function renderCommand (command, function_obj) {
  14. var el = $(
  15. '<div class="ui comment command_container"> ' +
  16. '<i class="ui icon small quote left command_drag"></i> ' +
  17. '<i class="ui icon times red button_remove_command"></i> ' +
  18. '<div class="var_value_menu_div"></div> <div class="div_comment_text">' +
  19. '</div> </div>' + "\n"
  20. );
  21. el.data('command', command);
  22. addHandlers(command, function_obj, el);
  23. renderTextComment(command, function_obj, el);
  24. return el;
  25. }
  26. function renderTextComment (command, function_obj, el) {
  27. //x VariableValueMenu.renderMenu(command, command.comment_text, el.find('.var_value_menu_div'), function_obj, 20);
  28. let commentText = "";
  29. if (command.comment_text) {
  30. if (typeof command.comment_text === "object") {
  31. commentText = command.comment_text.content || command.comment_text.value || "";
  32. } else if (typeof command.comment_text === "string") {
  33. commentText = command.comment_text;
  34. }
  35. }
  36. if (!commentText) {
  37. commentText = command.value || command.comment || command._text || "";
  38. }
  39. if (commentText) {
  40. el.find(".var_value_menu_div").hide();
  41. el.find(".div_comment_text").text(commentText).show();
  42. } else {
  43. el.find(".var_value_menu_div").hide();
  44. el.find(".div_comment_text").text(LocalizedStrings.getUI("text_comment")).show();
  45. }
  46. }
  47. function addHandlers (command, function_obj, comment_dom) {
  48. comment_dom.find('.button_remove_command').on('click', function() {
  49. if (CommandsManagement.removeCommand(command, function_obj, comment_dom)) {
  50. comment_dom.fadeOut(400, function() {
  51. comment_dom.remove();
  52. });
  53. }
  54. });
  55. }