| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890 |
- $(document).ready(function()
- {
- /* Set action to up when in last actions. */
- $(".moreActions").click(function()
- {
- var height = $(this).offset().top - $('#actionListTable').offset().top + $(this).parent().parent().height() + $(this).next(".dropdown-menu").height();
- var maxHeight = $('#actionListTable').parent().css('max-height').replace("px", "");
- if(height > maxHeight)
- {
- $(this).next(".dropdown-menu").addClass('dropup');
- }
- });
- $(document).on('hide.zui.modal', '#triggerModal.layout-modal', function()
- {
- var action = $(this).data('action');
- $('#actionList tr[data-action=' + action + '] .select-action' ).click();
- });
- $('#actionList').on('sort.sortable', function(e, data)
- {
- $.post(createLink('workflowaction', 'sort'), data.orders, function(response)
- {
- if(response.result == 'success')
- {
- return location.reload();
- }
- else
- {
- bootbox.alert(response.message);
- }
- }, 'json');
- });
- $('#actionList .select-action').click(function()
- {
- $('#actionList tr.checked').removeClass('checked row-check-begin row-check-end');
- var $tr = $(this).parents('tr').addClass('checked row-check-begin row-check-end');
- var data = $tr.data();
- $('#previewArea .panel-heading').html('<strong>' + data.name + '</strong>');
- if(data.buildin && data.extensiontype != 'override')
- {
- $('.layout-buildin-tip').show();
- $('.layout-empty-tip').hide();
- $('.layout-no-tip').hide();
- $('.layout-preview').hide();
- }
- else if(data.open != 'none')
- {
- if(data.virtual)
- {
- var nextModule = data.action.substring(0, data.action.lastIndexOf('_'));
- var nextAction = data.action.substring(data.action.lastIndexOf('_') + 1);
- var previewLink = createLink('workflowaction', 'ajaxPreview', 'module=' + nextModule + '&action=' + nextAction);
- }
- else
- {
- var previewLink = createLink('workflowaction', 'ajaxPreview', 'module=' + window.moduleName + '&action=' + data.action);
- }
- $('#previewArea .layout-preview').load(previewLink, function(response)
- {
- if(!response)
- {
- var setLayoutLink = createLink('workflowlayout', 'admin', 'module=' + window.moduleName + '&action=' + data.action);
- var setLayoutButton = "<a href='" + setLayoutLink + "' class='btn btn-secondary setLayout' data-toggle='modal'>" + window.setLayout + '</a>';
- $('.layout-buildin-tip').hide();
- $('.layout-empty-tip').find('.setLayout').remove();
- $('.layout-empty-tip').append(setLayoutButton).show();
- $('.layout-no-tip').hide();
- $('.layout-preview').hide();
- return false;
- }
- $('.preview-content .chosen').chosen();
- $('.example-text-holder').each(function()
- {
- $(this).attr('data-size', Math.floor(Math.random() * 8) + 2);
- });
- $('.btn-group').fixInputGroup();
- });
- $('.layout-buildin-tip').hide();
- $('.layout-empty-tip').hide();
- $('.layout-no-tip').hide();
- $('.layout-preview').show();
- }
- else
- {
- $('.layout-buildin-tip').hide();
- $('.layout-empty-tip').hide();
- $('.layout-no-tip').show();
- $('.layout-preview').hide();
- }
- });
- $('#actionList .select-action:first').click();
- /* Action */
- $(document).on('change', '#actionTable #type', function()
- {
- $('#batchMode').parents('tr').toggle($(this).val() == 'batch');
- $('#position, #show').parents('tr').toggle($(this).val() == 'single');
- $('#open option[value=modal]').toggle($(this).val() == 'single');
- if($(this).val() == 'batch' && $('#open').val() == 'modal')
- {
- $('#open').val('normal');
- }
- });
- /* Condition */
- $(document).on('change', '#conditionTable #conditionType', function()
- {
- $('.sqlTR').toggle($(this).val() == 'sql');
- $('.dataTR').toggle($(this).val() == 'data');
- });
- $(document).on('click', '#conditionTable .addCondition', function()
- {
- $(this).parents('tr').after(window.itemRow.replace(/KEY/g, window.conditionKey));
- $(this).parents('tr').next().find('[name*=field]').chosen();
- window.conditionKey++;
- });
- $(document).on('click', '#conditionTable .delCondition', function()
- {
- $(this).parents('tr').remove();
- });
- $(document).on('change', '#conditionTable [name*=field]', function()
- {
- var $tr = $(this).parents('tr');
- var key = $tr.data('key');
- var name = window.btoa(encodeURI('param[' + key + ']'));
- var link = createLink('workflowfield', 'ajaxGetFieldControl', 'module=' + window.moduleName + '&field=' + $(this).val() + '&value=&elementName=' + name);
- $tr.find('#paramTD').load(link, function()
- {
- $tr.find('select.chosen').chosen();
- $tr.find('.form-date').datetimepicker(dateOptions);
- $tr.find('.form-datetime').datetimepicker(datetimeOptions);
- initSelect($tr.find('#paramTD .picker-select'));
- });
- });
- /* Linkage */
- $(document).on('change', '#linkageTable [name^=source]', function()
- {
- processField();
- var $tr = $(this).parents('tr');
- var $td = $tr.find('td.value');
- var field = $(this).find('option:selected').val();
- var $value = $(this).parents('tr').find('[name^=value]');
- var value = $value.val();
- var name = $value.attr('name');
- var id = $value.attr('id');
- value = window.btoa(encodeURI(value));
- name = window.btoa(encodeURI(name));
- $td.load(createLink('workflowfield', 'ajaxGetFieldControl', 'module=' + window.moduleName + '&field=' + field + '&value=' + value + '&elementName=' + name + '&elementID=' + id), function()
- {
- $td.find('select.chosen').chosen();
- $tr.find('.form-date').datetimepicker(dateOptions);
- $tr.find('.form-datetime').datetimepicker(datetimeOptions);
- initSelect($td.find('.picker-select'));
- });
- });
- $(document).on('click', '#linkageTable .addTarget', function()
- {
- var $rowspan = parseInt($('th.target').attr('rowspan'));
- $rowspan++;
- $('th.target').attr('rowspan', $rowspan);
- $(this).parents('tr').after(window.targetRow.replace(/KEY/g, window.targetIndex));
- $(this).parents('tr').next().find('.chosen').chosen();
- window.targetIndex++;
- processField();
- })
- $(document).on('click', '#linkageTable .delTarget', function()
- {
- if($('.delTarget').length == 1)
- {
- $(this).parents('tr').find('input,select').val('');
- $(this).parents('tr').find('.chosen').trigger('chosen:updated');
- return false;
- }
- var rowspan = parseInt($('th.target').attr('rowspan'));
- rowspan--;
- if($(this).parents('tr').find('th').length)
- {
- $(this).parents('tr').next().prepend(window.th.replace(/ROWSPAN/g, rowspan));
- }
- else
- {
- $('th.target').attr('rowspan', rowspan);
- }
- $(this).parents('tr').remove();
- processField();
- })
- $(document).on('change', '#linkageTable [name^=target]', function()
- {
- processField();
- });
- $(document).on('change', '#linkageTable [name^=source], #linkageTable [name^=operator], #linkageTable [name^=value]', function()
- {
- $('#sourceLabel').remove();
- });
- $(document).on('change', '#linkageTable [name^=target], #linkageTable [name^=status]', function()
- {
- $('#targetLabel').remove();
- });
- /* Verification */
- $(document).on('change', '#verificationTable [name*=\\[field\\]], #verificationTable [name*=paramType]', function()
- {
- var $tr = $(this).closest('tr');
- var $td = $tr.find('.paramTD');
- var $paramType = $tr.find('[name*=paramType]');
- var module = window.moduleName;
- var key = $tr.data('key');
- var name = 'param[' + key + ']';
- if($tr.hasClass('dataTR')) name = 'verifications[param][' + key + ']';
- loadParam($tr, $td, $paramType, module, name);
- });
- $(document).on('click', '#verificationTable .addVerification, #verificationTable .addVar', function()
- {
- var $tr = $(this).parents('tr');
- if($(this).hasClass('addVar'))
- {
- $tr.after(window.varRow.replace(/KEY/g, window.verificationVarKey));
- window.verificationVarKey++;
- }
- else if($(this).hasClass('addVerification'))
- {
- $tr.after(window.verificationRow.replace(/KEY/g, window.verificationDataKey));
- window.verificationDataKey++;
- }
- $tr.next().find('.chosen').chosen();
- });
- $(document).on('click', '#verificationTable .delVerification, #verificationTable .delVar', function()
- {
- if($(this).hasClass('delVar'))
- {
- $('#sql').val($('#sql').val().replace("'$" + $(this).parents('tr').find('#varName').val() + "'", ''));
- if($('.delVar').size() == 1)
- {
- $(this).parents('tr').find('input,select').val('').find('.chosen').trigger('chosen:updated');
- $(this).parents('tr').find('.chosen-single span').html('');
- return;
- }
- }
- $(this).parents('tr').remove();
- });
- $(document).on('change', '#verificationTable [name*=varName]', function()
- {
- if($(this).val() != '') $('#sql').val($('#sql').val() + "'$" + $(this).val() + "'");
- });
- /* Hook */
- $(document).on('change', '.hookForm #conditionType', function()
- {
- $('.sqlTR').toggle($(this).val() == 'sql');
- $('.dataTR').toggle($(this).val() == 'data');
- });
- $(document).on('change', '.hookForm #action, .hookForm #table', function()
- {
- $('.fieldTR').toggle($('#action').val() != 'delete');
- if($('#action').val() == 'insert')
- {
- $('.whereTR').hide().find('input,select').attr('disabled', 'disabled');
- }
- else
- {
- $('.whereTR').show().find('input,select').removeAttr('disabled');
- }
- if($(this).attr('id') == 'table')
- {
- var link = createLink('workflowhook', 'ajaxGetTableFields', 'table=' + $(this).val());
- $('.field').load(link, function()
- {
- $('.field').trigger('chosen:updated');
- });
- }
- loadTarget();
- });
- $(document).on('click', '.hookForm .toggleCondition', function()
- {
- var val = $('#condition').val() == 1 ? 0 : 1;
- $('#condition').val(val);
- $('#conditionDIV').toggle();
- });
- $(document).on('change', '.hookForm [name*=\\[field\\]], .hookForm [name*=paramType]', function()
- {
- var $tr = $(this).closest('tr');
- var $td = $tr.find('.paramTD');
- var $paramType = $tr.find('[name*=paramType]');
- var module = $('#table').val();
- var key = $tr.data('key');
- var name = 'param[' + key + ']';
- if($tr.hasClass('dataTR')) module = window.moduleName;
- if($tr.hasClass('dataTR')) name = 'conditions[param][' + key + ']';
- if($tr.hasClass('fieldTR')) name = 'fields[param][' + key + ']';
- if($tr.hasClass('whereTR')) name = 'wheres[param][' + key + ']';
- loadParam($tr, $td, $paramType, module, name);
- });
- $(document).on('click', '.hookForm .addVar, .hookForm .addCondition, .hookForm .addField, .hookForm .addWhere', function()
- {
- var $tr = $(this).parents('tr');
- if($(this).hasClass('addVar'))
- {
- $tr.after(window.varRow.replace(/KEY/g, window.hookVarKey));
- window.hookVarKey++;
- }
- else if($(this).hasClass('addCondition'))
- {
- $tr.after(window.conditionRow.replace(/KEY/g, window.hookDataKey));
- window.hookDataKey++;
- }
- else if($(this).hasClass('addField'))
- {
- $tr.after(window.fieldRow.replace(/KEY/g, window.hookFieldKey));
- window.hookFieldKey++;
- var link = createLink('workflowhook', 'ajaxGetTableFields', 'table=' + $('#table').val());
- $tr.next('tr').find('.field').load(link, function()
- {
- $(this).trigger('chosen:updated');
- });
- }
- else if($(this).hasClass('addWhere'))
- {
- $tr.after(window.whereRow.replace(/KEY/g, window.hookWhereKey));
- window.hookWhereKey++;
- var link = createLink('workflowhook', 'ajaxGetTableFields', 'table=' + $('#table').val());
- $tr.next('tr').find('.field').load(link, function()
- {
- $(this).trigger('chosen:updated');
- });
- }
- $tr.next().find('.chosen').chosen();
- $tr.next().find('#param_chosen').hide();
- });
- $(document).on('click', '.hookForm .delVar, .hookForm .delCondition, .hookForm .delField, .hookForm .delWhere', function()
- {
- if($(this).hasClass('delVar'))
- {
- $('#sql').val($('#sql').val().replace("'$" + $(this).parents('tr').find('#varName').val() + "'", ''));
- if($('.delVar').size() == 1)
- {
- $(this).parents('tr').find('input,select').val('').find('.chosen').trigger('chosen:updated');
- $(this).parents('tr').find('.chosen-single span').html('');
- return;
- }
- }
- $(this).parents('tr').remove();
- });
- $(document).on('change', '.hookForm [name*=varName]', function()
- {
- if($(this).val() != '') $('#sql').val($('#sql').val() + "'$" + $(this).val() + "'");
- });
- $panelHeadingHeight = $('.panel-heading').outerHeight(true);
- $panelMarginBottom = $('.panel').css('margin-bottom').replace('px', '');
- $editorNavHeight = $('#editorNav').outerHeight(true);
- $editorMenuHeight = $('#editorMenu').outerHeight();
- $spaceHeight = $('.space.space-sm').outerHeight(true);
- $maxHeight = $(window).height() - $panelHeadingHeight - $panelMarginBottom - $editorNavHeight - $editorMenuHeight - $spaceHeight;
- $('.panel-body').css('max-height', $maxHeight + 'px');
- $(document).on('click', '.addBlock', function()
- {
- $(this).parents('li').after($('.blockData').html().replace(/blockKey/g, window.blockKey));
- window.blockKey++;
- return false;
- });
- $(document).on('click', '.addTab', function()
- {
- if($(this).parents('li').find('ul').length > 0)
- {
- $(this).parents('li').find('ul').append($('.tabData').html().replace(/tabKey/g, window.tabKey));
- }
- else
- {
- $(this).parents('li').append("<ul class='tabList'>" + $('.tabData').html().replace(/tabKey/g, window.tabKey) + "</ul>");
- }
- window.tabKey++;
- return false;
- });
- $(document).on('click', '.removeBlock', function()
- {
- if($(this).parents('ul').children('li').length > 1)
- {
- $(this).parents('li').remove();
- }
- else
- {
- $(this).parents('li').find('input').val('');
- }
- });
- $(document).on('click', '.removeTab', function()
- {
- if($(this).parents('ul.tabList').children('li').length > 1)
- {
- $(this).parents('li.tab').remove();
- }
- else
- {
- $(this).parents('ul.tabList').remove();
- }
- });
- $(document).on('click', '#blockForm .form-actions .btn', function()
- {
- $('[name^=key]').each(function(index) {$(this).val(index); });
- $('[name^=parent]').each(function(index)
- {
- $(this).val($(this).parents('li').find('[name^=key]').val());
- });
- $('#blockForm').submit();
- });
- $.setAjaxForm('#blockForm', function(response)
- {
- if(response.result == 'success')
- {
- setTimeout(function()
- {
- var modal = $('#triggerModal');
- modal.load(modal.attr('ref'), function(){$(this).find('.modal-dialog').css('width', $(this).data('width')); $.zui.ajustModalPosition()})
- }, 1200);
- }
- });
- });
- /**
- * Make sure each field be selected only once.
- *
- * @access public
- * @return void
- */
- function processField()
- {
- $('#linkageTable [name^=source]').each(function()
- {
- var $this = $(this);
- var selected = $this.val();
- $this.empty().append($('#fieldTemplate').html());
- $('#linkageTable [name^=source]').not(this).each(function()
- {
- var next = $(this).val();
- if(next != 0) $this.find('option[value=' + next + ']').remove();
- });
- $('#linkageTable [name^=target]').each(function()
- {
- var next = $(this).val();
- if(next != 0) $this.find('option[value=' + next + ']').remove();
- });
- $this.val(selected).trigger('chosen:updated');
- });
- $('#linkageTable [name^=target]').each(function()
- {
- var $this = $(this);
- var selected = $this.val();
- $this.empty().append($('#fieldTemplate').html());
- $('#linkageTable [name^=target]').not(this).each(function()
- {
- var next = $(this).val();
- if(next != 0) $this.find('option[value=' + next + ']').remove();
- });
- $('#linkageTable [name^=source]').each(function()
- {
- var next = $(this).val();
- if(next != 0) $this.find('option[value=' + next + ']').remove();
- });
- $this.val(selected).trigger('chosen:updated');
- });
- }
- var dateOptions =
- {
- language: config.clientLang,
- weekStart: 1,
- todayBtn: 1,
- autoclose: 1,
- todayHighlight: 1,
- startView: 2,
- minView: 2,
- forceParse: 0,
- format: 'yyyy-mm-dd'
- };
- var datetimeOptions =
- {
- language: config.clientLang,
- weekStart: 1,
- todayBtn: 1,
- autoclose: 1,
- todayHighlight: 1,
- startView: 2,
- forceParse: 0,
- showMeridian: 1,
- format: 'yyyy-mm-dd hh:ii'
- };
- function loadParam($tr, $td, $paramType, module, name)
- {
- var paramType = $paramType.val();
- var value = $td.find('.paramValue').length == 1 ? $td.find('.paramValue').val() : '';
- switch(paramType)
- {
- case 'today':
- case 'now':
- case 'actor':
- case 'currentDept':
- case 'deptManager':
- $td.html("<input type='text' name='" + name + "' value='" + $paramType.find('option:selected').text() + "' class='form-control' disabled><input type='hidden' name='" + name + "' value='" + paramType + "'>");
- break;
- case 'form':
- case 'record':
- var paramFields = paramType + 'Fields';
- $td.html(window[paramFields].replace(/NAME/g, name));
- $td.find('[name*=param]').val(value);
- $td.find('.chosen').chosen();
- break;
- case 'formula':
- var id = name.replace(/\[/g, '').replace(/\]/g, '');
- $td.html("<input type='hidden' name='" + name + "' id='" + id + "' value='" + value + "'><a href='javascript:;' class='set-expression'>" + window.formulaLang.set + '</a>');
- break;
- default:
- if(paramType == 'custom')
- {
- var field = $tr.find('[name*=field]').val();
- if(!field)
- {
- $td.html("<input type='text' name='" + name + "' value='" + value + "' class='form-control'>");
- }
- else
- {
- var field = $tr.find('[name*=field]').val();
- if(!field) return false;
- name = window.btoa(encodeURI(name));
- value = window.btoa(encodeURI(value));
- var link = createLink('workflowfield', 'ajaxGetFieldControl', 'module=' + module + '&field=' + field + '&value=' + value + '&elementName=' + name + '&elementID=&groupID=' + flowGroup);
- $td.load(link, function()
- {
- $td.find('.chosen').chosen();
- $td.find('.form-date').datetimepicker(dateOptions);
- $td.find('.form-datetime').datetimepicker(datetimeOptions);
- initSelect($td.find('.picker-select'));
- });
- }
- }
- else
- {
- name = window.btoa(encodeURI(name));
- value = window.btoa(encodeURI(value));
- var link = createLink('workflowfield', 'ajaxGetParamOptions', 'paramType=' + paramType + '&value=' + value + '&elementName=' + name);
- $td.load(link, function()
- {
- $td.find('.chosen').chosen();
- $td.find('.form-date').datetimepicker(dateOptions);
- $td.find('.form-datetime').datetimepicker(datetimeOptions);
- initSelect($td.find('.picker-select'));
- });
- }
- }
- }
- $(function()
- {
- $(document).on('click', '.hookForm .btn-expression', function()
- {
- var text = $(this).html();
- var data = $(this).data();
- var type = $(this).data('type');
- $('.hookForm #expressionDIV .expression').append("<span class='item-expression item-" + type + "'>" + text + "</span>");
- window.expression.push(data);
- removeErrorLabel();
- });
- $(document).on('click', '.hookForm .clear-last', function()
- {
- $('.hookForm #expressionDIV .expression .item-expression:last').remove();
- window.expression.pop();
- removeErrorLabel();
- });
- $(document).on('click', '.hookForm .clear-all', function()
- {
- $('.hookForm #expressionDIV .expression .item-expression').remove();
- window.expression.length = 0;
- removeErrorLabel();
- });
- $(document).on('click', '.hookForm .save-expression', function()
- {
- let hasError = checkExpression();
- if(!hasError)
- {
- let key = $('.hookForm #expressionDIV').attr('data-key');
- $('.hookForm .fieldTR[data-key=' + key + '] .paramTD [name*=param]').val(JSON.stringify(window.expression));
- $('.hookForm #expressionDIV').hide();
- $('.hookForm #hookDIV').show();
- $('.hookForm #conditionDIV').toggle($('#condition').val() == 1);
- }
- });
- $(document).on('click', '.hookForm .cancel-expression', function()
- {
- removeErrorLabel();
- $('.hookForm #expressionDIV').hide();
- $('.hookForm #hookDIV').show();
- $('.hookForm #conditionDIV').toggle($('.hookForm #condition').val() == 1);
- });
- $(document).on('click', '.hookForm .set-expression', function()
- {
- var $tr = $(this).parents('tr');
- initExpression($tr);
- $('.hookForm #expressionLabel').remove();
- $('.hookForm #expressionDIV').show();
- $('.hookForm #conditionDIV, .hookForm #hookDIV').hide();
- });
- })
- function loadTarget()
- {
- var action = $('.hookForm #action').val();
- var table = $('.hookForm #table').val();
- $('.hookForm #expressionDIV .target-detail .detail-content .dynamic-target').remove();
- if(action == 'update' && table != window.moduleName)
- {
- $.get(createLink('workflowhook', 'ajaxGetNumberFields', 'table=' + table), function(fields)
- {
- $('.hookForm #expressionDIV .target-detail .detail-content').prepend(fields);
- });
- }
- }
- function initExpression($tr)
- {
- let key = $tr.data('key');
- let field = $tr.find('.field option:selected').text();
- let name = field == '' ? window.formulaLang.common : field;
- let expression = $tr.find('.paramTD [name*=param]').val();
- $('.hookForm #expressionDIV').attr('data-key', key);
- $('.hookForm #expressionDIV .expression .item-name').html(name);
- $('.hookForm #expressionDIV .expression .item-expression').remove();
- if(expression)
- {
- window.expression = JSON.parse(expression);
- for(var i in window.expression)
- {
- let current = window.expression[i];
- let text = current.text;
- if(current.type == 'target')
- {
- if(current.function)
- {
- text = window.formulaLang.functions[current.function].replace('%s', window.modules[current.module]).replace('%s', window.moduleFields[current.module][current.field]);
- }
- else
- {
- text = window.modules[current.module] + '_' + window.moduleFields[current.module][current.field];
- }
- }
- $('.hookForm #expressionDIV .expression').append("<span class='item-expression item-" + current.type + "'>" + text + "</span>");
- }
- }
- else
- {
- window.expression.length = 0;
- }
- }
- function checkExpression()
- {
- if(window.expression.length == 0)
- {
- appendErrorLabel(window.formulaLang.error.empty);
- return true;
- }
- else
- {
- let fakeExpression = [];
- for(var i in window.expression)
- {
- let current = window.expression[i];
- if(current.type == 'target') fakeExpression.push(current.field);
- if(current.type == 'operator') fakeExpression.push(current.operator);
- if(current.type == 'number') fakeExpression.push(current.value);
- }
- fakeExpression = fakeExpression.join('');
- try
- {
- math.parse(fakeExpression);
- }
- catch(error)
- {
- appendErrorLabel(window.formulaLang.error.error);
- return true;
- }
- let error = false;
- let length = window.expression.length;
- for(var i in window.expression)
- {
- i = parseInt(i);
- let current = window.expression[i];
- let prev = '';
- let next = '';
- if(i > 0) prev = window.expression[i - 1];
- if(i < length -1) next = window.expression[i + 1];
- switch(current.type)
- {
- case 'target' :
- if(prev != '' && (prev.type != 'operator' || prev.operator == ')'))
- {
- error = true;
- break;
- }
- if(next != '' && (next.type != 'operator' || next.operator == '('))
- {
- error = true;
- break;
- }
- break;
- case 'number' :
- if(current.value == '.')
- {
- if(prev == '' || prev.type != 'number' || prev.value == '.')
- {
- error = true;
- break;
- }
- if(next == '' || next.type != 'number' || next.value == '.')
- {
- error = true;
- break;
- }
- }
- else
- {
- if(prev != '' && (prev.type == 'target' || (prev.type == 'operator' && prev.operator == ')')))
- {
- error = true;
- break;
- }
- if(next != '' && (next.type == 'target' || (next.type == 'operator' && next.operator == '(')))
- {
- error = true;
- break;
- }
- }
- break;
- case 'operator' :
- switch(current.operator)
- {
- case '(' :
- if(prev != '' && (prev.type != 'operator' || prev.operator == ')'))
- {
- error = true;
- break;
- }
- if(next == '' || (next.type == 'number' && next.value == '.') || (next.type == 'operator' && next.operator != '('))
- {
- error = true;
- break;
- }
- break;
- case ')' :
- if(prev == '' || (prev.type == 'number' && prev.value == '.') || (prev.type == 'operator' && prev.operator != ')'))
- {
- error = true;
- break;
- }
- if(next != '' && (next.type != 'operator' || next.operator == '('))
- {
- error = true;
- break;
- }
- break;
- default :
- if(prev == '' || (prev.type == 'operaor' && prev.operator != ')') || (prev.type == 'number' && prev.value == '.'))
- {
- error = true;
- break;
- }
- if(next == '' || (next.type == 'operaor' && next.operator != '(') || (next.type == 'number' && next.value == '.'))
- {
- error = true;
- break;
- }
- }
- break;
- }
- if(error)
- {
- appendErrorLabel(window.formulaLang.error.error);
- return true;
- }
- }
- return false;
- }
- }
- function appendErrorLabel(message)
- {
- removeErrorLabel();
- $('.hookForm #expressionDIV .expression').css('border-color', '#953B39').after("<span id='expressionLabel' for='expression' class='text-error red'>" + message + '</span>');
- $('.hookForm').parents('.modal-body').scrollTop(0);
- }
- function removeErrorLabel()
- {
- $('.hookForm #expressionDIV .expression').css('border-color', '').next('#expressionLabel').remove();
- }
|