comment.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import $ from 'jquery';
  2. import { Types } from '../types';
  3. import * as Models from '../ivprog_elements';
  4. import { LocalizedStrings } from '../../services/localizedStringsService';
  5. import * as GlobalsManagement from '../globals';
  6. import * as VariablesManagement from '../variables';
  7. import * as VariableValueMenu from './variable_value_menu';
  8. import * as CommandsManagement from '../commands';
  9. export function createFloatingCommand () {
  10. return $('<div class="ui comment created_element"> <i class="ui icon small quote left"></i> <span class="span_comment_text" "> '+LocalizedStrings.getUI('text_comment')+' </span></div>');
  11. }
  12. export function renderCommand (command, function_obj) {
  13. var el = $('<div class="ui comment command_container"> <i class="ui icon small quote left"></i> <i class="ui icon times red button_remove_command"></i> <div class="var_value_menu_div"></div> <div class="div_comment_text">'+command.comment_text.content+'</div> </div>');
  14. el.data('command', command);
  15. addHandlers(command, function_obj, el);
  16. return el;
  17. }
  18. function addHandlers (command, function_obj, comment_dom) {
  19. comment_dom.find('.button_remove_command').on('click', function() {
  20. if (CommandsManagement.removeCommand(command, function_obj, comment_dom)) {
  21. comment_dom.remove();
  22. }
  23. });
  24. comment_dom.find('.div_comment_text').on('click', function() {
  25. comment_dom.find('.div_comment_text').text('');
  26. VariableValueMenu.renderMenu(command, command.comment_text, comment_dom.find('.var_value_menu_div'), function_obj, 20);
  27. comment_dom.find('.width-dynamic').val(command.comment_text.content);
  28. comment_dom.find('.width-dynamic').focusout(function() {
  29. if ($(this).val().trim()) {
  30. command.comment_text.content = $(this).val().trim();
  31. }
  32. comment_dom.find('.div_comment_text').text(command.comment_text.content);
  33. $(this).remove();
  34. });
  35. comment_dom.find('.width-dynamic').on('keydown', function(e) {
  36. var code = e.keyCode || e.which;
  37. if(code == 13) {
  38. if ($(this).val().trim()) {
  39. command.comment_text.content = $(this).val().trim();
  40. }
  41. comment_dom.find('.div_comment_text').text(command.comment_text.content);
  42. $(this).remove();
  43. }
  44. if(code == 27) {
  45. comment_dom.find('.div_comment_text').text(command.comment_text.content);
  46. $(this).remove();
  47. }
  48. });
  49. });
  50. }