123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- import $ from 'jquery';
- import { Types } from '../types';
- import * as Models from '../ivprog_elements';
- import { LocalizedStrings } from '../../services/localizedStringsService';
- import * as GlobalsManagement from '../globals';
- import * as VariablesManagement from '../variables';
- import * as VariableValueMenu from './variable_value_menu';
- import * as VariableValueMenuManagement from './variable_value_menu';
- import * as CommandsManagement from '../commands';
- export function createFloatingCommand () {
- return $('<div class="ui attribution created_element"> <i class="ui icon small arrow left"></i> <span> x = 1 + 1 </span></div>');
- }
- export function renderCommand (command, function_obj) {
-
- var el = $('<div class="ui attribution command_container"> <i class="ui icon small arrow left command_drag"></i> <i class="ui icon times red button_remove_command"></i> <i class="ui icon redo alternate blue button_refresh_attribution"></i> <div class="var_attributed"></div> <span class="text_attr_receives">'+LocalizedStrings.getUI('text_receives')+'</span> '
- + '<div class="expression_elements"></div> </div>');
- el.data('command', command);
- VariableValueMenu.renderMenu(command, command.variable, el.find('.var_attributed'), function_obj);
- command.expression.push("(");
- command.expression.push(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, "1", null, null, true));
- command.expression.push(Models.ARITHMETIC_TYPES.plus);
- command.expression.push(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, window.program_obj.functions[0].variables_list[0], null,
- new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, new Models.Variable(Types.REAL, "variable_2", 1)), null, null, true));
- command.expression.push(")");
- command.expression.push(Models.ARITHMETIC_TYPES.minus);
- command.expression.push(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, "2", null, null, true));
-
- addHandlers(command, function_obj, el);
- renderExpression(command, function_obj, el);
- return el;
- }
- function renderExpression(command, function_obj, el) {
- var expression_div = el.find('.expression_elements');
- expression_div.text('');
-
- for (var i = 0; i < command.expression.length; i++) {
- if (command.expression[i].type) {
- var temp = $('<div class="expression_element"></div>');
- temp.data('ref_element', command.expression[i]);
- temp.data('ref_index', i);
- expression_div.append(temp);
- VariableValueMenu.renderMenu(command, command.expression[i], temp, function_obj);
- } else if (command.expression[i] == "(" || command.expression[i] == ")") {
- var temp = $('<div class="expression_element">'+command.expression[i]+'</div>');
- temp.data('ref_element', command.expression[i]);
- temp.data('ref_index', i);
- expression_div.append(temp);
- } else {
- var temp = '<div class="expression_element">';
- switch(command.expression[i]) {
- case Models.ARITHMETIC_TYPES.plus:
- temp += '+';
- break;
- case Models.ARITHMETIC_TYPES.minus:
- temp += '-';
- break;
- case Models.ARITHMETIC_TYPES.multiplication:
- temp += '*';
- break;
- case Models.ARITHMETIC_TYPES.division:
- temp += '/';
- break;
- case Models.ARITHMETIC_TYPES.module:
- temp += '%';
- break;
- }
- temp += '</div>';
- temp = $(temp);
- temp.data('ref_element', command.expression[i]);
- temp.data('ref_index', i);
- expression_div.append(temp);
- }
- }
- }
- function addHandlers (command, function_obj, attribution_dom) {
- attribution_dom.find('.button_remove_command').on('click', function() {
- if (CommandsManagement.removeCommand(command, function_obj, attribution_dom)) {
- attribution_dom.remove();
- }
- });
- attribution_dom.find('.button_refresh_attribution').on('click', function() {
- renderExpression(command, function_obj, attribution_dom);
- });
- }
- export function renderMenuOperations (command, ref_object, dom_object, menu_var_or_value, function_obj, variable_selected) {
-
- }
- function createExpressionAround (command, ref_object, dom_object, function_obj) {
- $('<span> ( </span>').insertBefore(dom_object);
- $('<span> ) </span>').insertAfter(dom_object);
- VariableValueMenu.renderMenu(command, new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true), dom_object, function_obj);
- }
|