How to use util.getOperator method in chai

Best JavaScript code snippet using chai

DefineConditionPanel-dbg.js

Source:DefineConditionPanel-dbg.js Github

copy

Full Screen

1/*!2 * OpenUI53 * (c) Copyright 2009-2021 SAP SE or an SAP affiliate company.4 * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.5 */6sap.ui.define([7 'sap/ui/core/Control',8 'sap/ui/base/ManagedObjectObserver',9 'sap/base/util/merge',10 'sap/base/util/deepEqual',11 'sap/ui/mdc/condition/Condition',12 'sap/ui/mdc/condition/FilterOperatorUtil',13 'sap/ui/mdc/condition/Operator',14 'sap/ui/mdc/field/ConditionType',15 'sap/ui/mdc/enum/EditMode',16 'sap/ui/mdc/enum/FieldDisplay',17 'sap/ui/mdc/enum/BaseType',18 'sap/ui/mdc/enum/ConditionValidated',19 'sap/ui/mdc/Field',20 'sap/ui/mdc/field/ListFieldHelp',21 'sap/ui/mdc/field/ListFieldHelpItem',22 'sap/ui/model/base/ManagedObjectModel',23 'sap/ui/model/json/JSONModel',24 'sap/ui/model/resource/ResourceModel',25 'sap/ui/model/type/String',26 'sap/ui/core/library',27 'sap/ui/core/InvisibleText',28 'sap/ui/core/ListItem',29 'sap/ui/layout/Grid',30 'sap/ui/layout/GridData',31 'sap/m/library',32 'sap/m/ScrollContainer',33 'sap/m/Button',34 'sap/m/Panel',35 'sap/base/Log'36], function(37 Control,38 ManagedObjectObserver,39 merge,40 deepEqual,41 Condition,42 FilterOperatorUtil,43 Operator,44 ConditionType,45 EditMode,46 FieldDisplay,47 BaseType,48 ConditionValidated,49 Field,50 ListFieldHelp,51 ListFieldHelpItem,52 ManagedObjectModel,53 JSONModel,54 ResourceModel,55 StringType,56 coreLibrary,57 InvisibleText,58 ListItem,59 Grid,60 GridData,61 mLibrary,62 ScrollContainer,63 Button,64 Panel,65 Log66 ) {67 "use strict";68 // translation utils69 var oMessageBundle = sap.ui.getCore().getLibraryResourceBundle("sap.ui.mdc");70 sap.ui.getCore().attachLocalizationChanged(function() {71 oMessageBundle = sap.ui.getCore().getLibraryResourceBundle("sap.ui.mdc");72 });73 var ButtonType = mLibrary.ButtonType;74 var ValueState = coreLibrary.ValueState;75 /**76 * Constructor for a new <code>DefineConditionPanel</code>.77 *78 * @param {string} [sId] ID for the new control, generated automatically if no ID is given79 * @param {object} [mSettings] Initial settings for the new control80 *81 * @class82 * A <code>DefineConditionPanel</code> control is used inside the <code>ValueHelpPanel</code> control to enter different types83 * of conditions.84 *85 * @extends sap.ui.core.Control86 *87 * @author SAP SE88 * @version 1.96.489 *90 * @constructor91 * @alias sap.ui.mdc.field.DefineConditionPanel92 * @since 1.58.093 * @abstract94 *95 * @private96 * @ui5-restricted sap.ui.mdc.field.ValueHelpPanel, sap.ui.mdc.field.ConditionFieldHelp97 */98 var DefineConditionPanel = Control.extend("sap.ui.mdc.field.DefineConditionPanel", {99 metadata: {100 library: "sap.ui.mdc",101 properties: {102 /**103 * Sets the conditions that represent the selected values of the help.104 *105 * @since 1.62.0106 */107 conditions: {108 type: "object[]",109 group: "Data",110 defaultValue: [],111 byValue: true112 },113 // TODO: better way to pass MaxConditions, Operators, ...114 /**115 * The <code>formatOptions</code> for the <code>ConditionType</code> used to format tokens.116 *117 * @since 1.62.0118 */119 formatOptions: {120 type: "object",121 defaultValue: {}122 },123 /**124 * The <code>label</code> for the <code>DefineConditionPanel</code> used as panel headerText.125 *126 * @since 1.84.0127 */128 label: {129 type: "string",130 defaultValue: ""131 },132 /**133 * If set, there has been no invalid user input.134 *135 * <b>Note:</b> This property must not be set from outside. It is a property because that way it can be bound to the136 * <code>ManagedObjectModel</code> of the calling field help and automatically update it.137 *138 * @since 1.87.0139 */140 inputOK: {141 type: "boolean",142 defaultValue: true143 }144 },145 aggregations: {146 /**147 * Optional content that can be rendered.148 *149 * <b>Note:</b> Bind the value-holding property of the control to <code>'$field>/conditions'</code>150 * using <code>sap.ui.mdc.field.ConditionsType</code> as type.151 *152 * If the control needs to show multiple conditions, bind its aggregation to </code>'$field>/conditions'</code>.153 * Bind the item controls value-holding property using <code>sap.ui.mdc.field.ConditionType</code> as type.154 *155 * <b>Warning:</b> Only controls allowed in a </code>Form</code> are allowed to be used for this optional content.156 * Other controls might break the layout.157 * This means the <code>sap.ui.core.IFormContent</code> interface needs to be implemented by these controls.158 */159 _content: {160 type: "sap.ui.core.Control",161 multiple: false,162 visibility: "hidden"163 }164 },165 events: {166 /**167 * Event is fired if the user processes a condition. (Not known if changed.)168 */169 conditionProcessed: {}170 }171 },172 _oManagedObjectModel: null,173 renderer:{174 apiVersion: 2,175 render: function(oRm, oControl){176 oRm.openStart("section", oControl);177 oRm.class("sapUiMdcDefineConditionPanel");178 oRm.openEnd();179 oRm.renderControl(oControl.getAggregation("_content"));180 oRm.close("section");181 }182 },183 init: function() {184 sap.ui.getCore().getMessageManager().registerObject(this, true);185 Control.prototype.init.apply(this, arguments);186 this._oManagedObjectModel = new ManagedObjectModel(this);187 this._oObserver = new ManagedObjectObserver(_observeChanges.bind(this));188 this._oObserver.observe(this, {189 properties: ["conditions", "formatOptions"]190 });191 _createInnerControls.call(this);192 this.setModel(this._oManagedObjectModel, "$this");193 this.setModel(this._oManagedObjectModel, "$condition"); // TODO: better solution to have 2 bindingContexts on one control194 },195 exit: function() {196 sap.ui.getCore().getMessageManager().unregisterObject(this, true);197 this._oObserver.disconnect();198 this._oObserver = undefined;199 if (this._sConditionsTimer) {200 clearTimeout(this._sConditionsTimer);201 this._sConditionsTimer = null;202 }203 if (this._oDefaultType) {204 this._oDefaultType.destroy();205 delete this._oDefaultType;206 }207 this._oManagedObjectModel.destroy();208 delete this._oManagedObjectModel;209 },210 byId: function(sId) {211 return sap.ui.getCore().byId(this.getId() + "--" + sId);212 },213 onBeforeRendering: function() {214 if (!this.getModel("$i18n")) {215 // if ResourceModel not provided from outside create own one216 this.setModel(new ResourceModel({ bundleName: "sap/ui/mdc/messagebundle", async: false }), "$i18n");217 }218 if (this.getConditions().length === 0) {219 // as observer must not be called in the initial case220 this.updateDefineConditions();221 }222 },223 removeCondition: function(oEvent) {224 var oSource = oEvent.oSource;225 var oBindingContext = oSource.getBindingContext("$this");226 var aConditions = this.getConditions();227 var sPath = oBindingContext.getPath();228 var aMatch = sPath.match(/^.*\/(\d+)\/$/);229 var iIndex;230 if (aMatch) {231 iIndex = parseInt(aMatch[1]);232 }233 if (iIndex > 0 && aConditions.length - 1 === iIndex) {234 this._bFocusLastRemoveBtn = true; // as remove-Button will disappear and focus should set on the last row remove button235 }236 // try to reset valueState and value of value Fields inside the removed row237 var oGrid = this.byId("conditions");238 var aGridContent = oGrid.getContent();239 var iRow = 0;240 for (var i = 0; i < aGridContent.length && iRow <= iIndex; i++) {241 var oField = aGridContent[i];242 if (iRow === iIndex && oField instanceof Field && oField.hasOwnProperty("_iValueIndex")) {243 if (oField._bParseError) { // TODO: better was to find out parsing error244 oField.setValue(null); // to remove invalid value from parsing245 }246 }247 if (oField instanceof Button && oField.getId().endsWith("-removeBtnLarge")) {248 iRow++;249 }250 }251 aConditions.splice(iIndex, 1);252 this.setProperty("conditions", aConditions, true); // do not invalidate whole DefineConditionPanel253 this.fireConditionProcessed();254 },255 addCondition: function(oEvent) {256 var aConditions = this.getConditions();257 var oFormatOptions = this.getFormatOptions();258 var iMaxConditions = oFormatOptions.maxConditions;259 if (iMaxConditions === -1 || aConditions.length < iMaxConditions) {260 // create a new dummy condition for a new condition on the UI - must be removed later if not used or filled correct261 this.addDummyCondition(aConditions.length + 1);262 if (this.getConditions().length === iMaxConditions) {263 this._bFocusLastCondition = true; // as add-Button will disappear and focus should stay in DefineConditionPanel264 }265 }266 },267 addDummyCondition: function(index) {268 var aOperators = _getOperators.call(this);269 var oOperator = _getDefaultOperator.call(this);270 var sOperator = oOperator.name;271 var oCondition = Condition.createCondition(sOperator, oOperator.valueDefaults ? oOperator.valueDefaults : [], undefined, undefined, ConditionValidated.NotValidated);272 // mark the condition as initial and not modified by the user273 oCondition.isInitial = true;274 FilterOperatorUtil.updateConditionValues(oCondition);275 FilterOperatorUtil.checkConditionsEmpty(oCondition, aOperators);276 var aConditions = this.getConditions();277 if (index !== undefined) {278 aConditions.splice(index, 0, oCondition);279 } else {280 aConditions.push(oCondition);281 }282 this.setProperty("conditions", aConditions, true); // do not invalidate whole DefineConditionPanel283 },284 updateDefineConditions: function() {285 var aConditions = this.getConditions().filter(function(oCondition) {286 var oOperator = FilterOperatorUtil.getOperator(oCondition.operator);287 return oCondition.validated !== ConditionValidated.Validated || oOperator.exclude;288 });289 _addStaticText.call(this, aConditions, true, false);290 if (aConditions.length === 0) {291 this.addDummyCondition();292 }293 },294 // called when the user has change the value of the condition field295 onChange: function(oEvent) {296 var aOperators = _getOperators.call(this);297 var aConditions = this.getConditions();298 FilterOperatorUtil.checkConditionsEmpty(aConditions, aOperators);299 FilterOperatorUtil.updateConditionsValues(aConditions, aOperators);300 if (oEvent) {301 // remove isInitial when the user modified the value and the codndition is not Empty302 aConditions.forEach(function(oCondition) {303 if (!oCondition.isEmpty) {304 delete oCondition.isInitial;305 }306 });307 }308 this.setProperty("conditions", aConditions, true); // do not invalidate whole DefineConditionPanel309 },310 onSelectChange: function(oEvent) {311 var oField = oEvent.getSource();312 var sKey = oField.getValue();313 var sOldKey = oField._sOldKey;314 var oOperator = FilterOperatorUtil.getOperator(sKey); // operator must exist as List is created from valid operators315 var oOperatorOld = sOldKey && FilterOperatorUtil.getOperator(sOldKey);316 if (oOperator && oOperatorOld) {317 var bUpdate = false;318 var oCondition = oField.getBindingContext("$this").getObject();319 var aConditions = this.getConditions();320 var iIndex = FilterOperatorUtil.indexOfCondition(oCondition, aConditions);321 if (!deepEqual(oOperator.valueTypes[0], oOperatorOld.valueTypes[0]) && oOperator.valueTypes[0] !== Operator.ValueType.Static ) {322 // type changed -> remove entered value (only if changed by user in Select)323 // As Static text updated on condition change, don't delete it here.324 if (iIndex >= 0) {325 oCondition = aConditions[iIndex]; // to get right instance326 oCondition.values.forEach(function(value, index) {327 if (value !== null) {328 if ((oOperator.valueTypes[index] === Operator.ValueType.Self && oOperatorOld.valueTypes[index] === Operator.ValueType.SelfNoParse) ||329 (oOperator.valueTypes[index] === Operator.ValueType.SelfNoParse && oOperatorOld.valueTypes[index] === Operator.ValueType.Self)) {330 // as for Decimal values the type might change we need to format and parse again331 var oType = _getFieldType.call(this, oOperator.name, index);332 var oTypeOld = _getFieldType.call(this, oOperatorOld.name, index);333 var sValue = oTypeOld.formatValue(oCondition.values[index], "string");334 var vValue = oType.parseValue(sValue, "string");335 if (vValue !== oCondition.values[index]) {336 oCondition.values[index] = oType.parseValue(sValue, "string");337 bUpdate = true;338 }339 } else {340 oCondition.values[index] = null;341 bUpdate = true;342 }343 }344 }.bind(this));345 }346 }347 if (iIndex >= 0 && oOperator.valueDefaults) {348 // sets the default values for the operator back to default, if the condition is inital or the value is null349 oCondition = aConditions[iIndex];350 oCondition.values.forEach(function(value, index) {351 if ((oCondition.isInitial && value !== oOperator.valueDefaults[index]) || (value === null)) {352 // set the default value and mark the condition as initial353 oCondition.values[index] = oOperator.valueDefaults[index];354 oCondition.isInitial = true;355 bUpdate = true;356 }357 });358 }359 if (!oOperator.valueTypes[1] && oOperatorOld.valueTypes[1]) {360 // switch from BT to EQ -> remove second value even if filled361 if (iIndex >= 0) {362 oCondition = aConditions[iIndex]; // to get right instance363 if (oCondition.values.length > 1 && oCondition.values[1]) {364 oCondition.values = oCondition.values.slice(0, 1);365 bUpdate = true;366 }367 }368 }369 if (bUpdate) {370 FilterOperatorUtil.checkConditionsEmpty(oCondition, _getOperators.call(this));371 this.setProperty("conditions", aConditions, true); // do not invalidate whole DefineConditionPanel372 }373 }374 delete oField._sOldKey;375 },376 onPaste: function(oEvent) {377 var sOriginalText;378 var oSource = oEvent.srcControl;379 var oFormatOptions = this.getFormatOptions();380 var iMaxConditions = oFormatOptions.hasOwnProperty("maxConditions") ? oFormatOptions.maxConditions : -1;381 var sConditionPath = oSource.getBindingContext("$condition").getPath(); // Path to condition of the active control382 var iIndex = parseInt(sConditionPath.split("/")[2]); // index of current condition - to remove before adding new ones383 // for the purpose to copy from column in excel and paste in MultiInput/MultiComboBox384 if (window.clipboardData) {385 //IE386 sOriginalText = window.clipboardData.getData("Text");387 } else {388 // Chrome, Firefox, Safari389 sOriginalText = oEvent.originalEvent.clipboardData.getData('text/plain');390 }391 var aSeparatedText = sOriginalText.split(/\r\n|\r|\n/g);392 if (aSeparatedText && aSeparatedText.length > 1) {393 setTimeout(function() {394 var oFormatOptions = merge({}, this.getFormatOptions());395 delete oFormatOptions.fieldHelpID;396 delete oFormatOptions.conditionModelName;397 oFormatOptions.maxConditions = 1;398 oFormatOptions.display = FieldDisplay.Value;399 //oFormatOptions.valueType = this._getFieldType.call(this, oOperator.name, 0); //TODO using the _getFieldType for better support of types400 var oConditionType = new ConditionType(oFormatOptions);401 var iLength = aSeparatedText.length;402 var aConditions = this.getConditions();403 for (var i = 0; i < iLength; i++) {404 if (aSeparatedText[i]) {405 var sValue = aSeparatedText[i].trim();406 var aValues = sValue.split(/\t/g); // if two values exist, use it as Between and create a "a...z" value407 if (aValues.length == 2 && aValues[0] && aValues[1]) {408 var oOperator = FilterOperatorUtil.getOperator("BT");409 sValue = oOperator.tokenFormat;410 for (var j = 0; j < 2; j++) {411 sValue = sValue.replace(new RegExp("\\{" + j + "\\}", "g"), aValues[j]);412 }413 }414 try {415 var oCondition = oConditionType.parseValue(sValue, "string");416 oConditionType.validateValue(oCondition);417 if (aConditions.length > iIndex) {418 // overwrite existing condition419 aConditions.splice(iIndex, 1, oCondition);420 } else {421 // add new condition422 aConditions.push(oCondition);423 }424 iIndex++;425 } catch (error) {426 Log.error("Paste handling", "the pasted value '" + sValue + "' could not be handled! " + error.message);427 }428 }429 }430 if (iMaxConditions >= 0 && aConditions.length > iMaxConditions) {431 aConditions.splice(iMaxConditions, aConditions.length - iMaxConditions);432 }433 if (oSource.setDOMValue) {434 oSource.setDOMValue(""); // otherwise binding update will be ignored435 }436 FilterOperatorUtil.checkConditionsEmpty(aConditions);437 this.setProperty("conditions", aConditions, true); // do not invalidate whole DefineConditionPanel438 this.fireConditionProcessed();439 }.bind(this), 0);440 }441 },442 cleanUp: function() {443 // of Dialog is closed all error messages and invalid input should be removed to be clean on reopening444 var oGrid = this.byId("conditions");445 var aGridContent = oGrid.getContent();446 for (var i = 0; i < aGridContent.length; i++) {447 var oField = aGridContent[i];448 if (oField instanceof Field && oField.hasOwnProperty("_iValueIndex")) {449 if (oField._bParseError) { // TODO: better was to find out parsing error450 oField.setValue(); // to remove invalid value from parsing451 }452 }453 }454 this.setProperty("inputOK", true, true); // do not invalidate whole DefineConditionPanel455 }456 });457 function _observeChanges(oChanges) {458 if (oChanges.name === "value") {459 // operator changed -> update controls460 _operatorChanged.call(this, oChanges.object, oChanges.current, oChanges.old);461 }462 if (oChanges.name === "formatOptions") {463 // type or maxConditions might changed -> resume ListBinding464 var aConditions = this.getConditions();465 var oOperators = oChanges.current && oChanges.current.operators;466 var oOperatorsOld = oChanges.old && oChanges.old.operators;467 var bOperatorModelUpdated = false;468 if (!deepEqual(oOperators, oOperatorsOld)) {469 // operators changed470 bOperatorModelUpdated = true;471 _updateOperatorModel.call(this);472 }473 var sType = oChanges.current && oChanges.current.valueType && oChanges.current.valueType.getMetadata().getName();474 var sTypeOld = oChanges.old && oChanges.old.valueType && oChanges.old.valueType.getMetadata().getName();475 if (sType !== sTypeOld && aConditions.length > 0) {476 // operators might be changed if type changed477 if (!bOperatorModelUpdated) { // don't do twice478 _updateOperatorModel.call(this);479 }480 this._bUpdateType = true;481 _renderConditions.call(this);482 this._bUpdateType = false;483 _addStaticText.call(this, aConditions, true, true); // static text might changed if type changed484 }485 }486 if (oChanges.name === "conditions") {487 if (this._sConditionsTimer) {488 clearTimeout(this._sConditionsTimer);489 this._sConditionsTimer = null;490 }491 this._sConditionsTimer = setTimeout(function () {492 // on multiple changes (dummy row, static text...) perform only one update493 this._sConditionsTimer = null;494 this.updateDefineConditions();495 _renderConditions.call(this);496 }.bind(this), 0);497 }498 }499 function _operatorChanged(oField, sKey, sOldKey) {500 oField._sOldKey = sOldKey; // to know in change event501 var iIndex = 0;502 // if type of operator changed -> remove binding and create it new later on503 if (sKey && sOldKey) {504 var oOperator = FilterOperatorUtil.getOperator(sKey);505 var oOperatorOld = FilterOperatorUtil.getOperator(sOldKey);506 var oGrid = oField.getParent();507 var oValue0Field;508 var oValue1Field;509 iIndex = oGrid.indexOfContent(oField);510 // find fields and initialize error state511 oValue0Field = oGrid.getContent()[iIndex + 2];512 if (oValue0Field && oValue0Field.hasOwnProperty("_iValueIndex") && oValue0Field._iValueIndex === 0) {513 if (oValue0Field instanceof Field && !oValue0Field._bParseError) { // TODO: better was to find out parsing error // TODO: handle custom controls514 // if Field is in parsing error state, don't remove error515 oValue0Field.setValueState(ValueState.None);516 oValue0Field.setValueStateText();517 }518 oValue1Field = oGrid.getContent()[iIndex + 3]; // second field only exists if first field exist519 if (oValue1Field && oValue1Field.hasOwnProperty("_iValueIndex") && oValue1Field._iValueIndex === 1) {520 if (oValue1Field instanceof Field && !oValue1Field._bParseError) { // TODO: better was to find out parsing error // TODO: handle custom controls521 // if Field is in parsing error state, don't remove error522 oValue1Field.setValueState(ValueState.None);523 oValue1Field.setValueStateText();524 }525 } else {526 oValue1Field = undefined;527 }528 } else {529 oValue0Field = undefined;530 }531 if (oOperator.createControl || oOperatorOld.createControl) {532 // custom control used -> needs to be created new533 if (oValue0Field) {534 oValue0Field.destroy();535 }536 if (oValue1Field) {537 oValue1Field.destroy();538 }539 } else {540 if (oValue0Field && oOperator.valueTypes[0] !== oOperatorOld.valueTypes[0]) {541 oValue0Field.unbindProperty("value");542 }543 if (oValue1Field && oOperator.valueTypes[1] !== oOperatorOld.valueTypes[1] && oOperatorOld.valueTypes[1]) { // 2nd Field only exist if there was a valueType defined544 oValue1Field.unbindProperty("value");545 }546 }547 }548 if (!sKey) { // TODO: remove? Because cannot longer happen as Field don't allow empty input because of used data type constraints549 // key must not be empty550 var oCondition = oField.getBindingContext("$this").getObject();551 if (oCondition) { // condition might be deleted before Field instance is deleted552 var aConditions = this.getConditions();553 iIndex = FilterOperatorUtil.indexOfCondition(oCondition, aConditions);554 if (iIndex >= 0) {555 oCondition = aConditions[iIndex]; // to get right instance556 oCondition.operator = sOldKey;557 this.setProperty("conditions", aConditions, true); // do not invalidate whole DefineConditionPanel558 }559 }560 }561 // as additinalValue is not updated automatically if operator is set from outside just take it from OperatorModel562 var aOperatorsData = this.oOperatorModel.getData();563 var sDescription;564 for (var i = 0; i < aOperatorsData.length; i++) {565 var oOperatorData = aOperatorsData[i];566 if (oOperatorData.key === sKey) {567 sDescription = oOperatorData.text;568 break;569 }570 }571 oField.setAdditionalValue(sDescription);572 this.onChange();573 }574 function _createControl(oCondition, iIndex, sId, oBindingContext) {575 var oOperator = FilterOperatorUtil.getOperator(oCondition.operator);576 if (!oOperator || !oOperator.valueTypes[iIndex]) {577 return null; // TODO: exception?578 }579 var oNullableType = _getFieldType.call(this, oOperator.name, iIndex);580 var oValueBindingContext = this._oManagedObjectModel.getContext(oBindingContext.getPath() + "values/" + iIndex + "/");581 var oControl;582 if (oOperator.createControl) {583 oControl = oOperator.createControl(oNullableType, "$this>", iIndex, sId); // the returned control can be null, in this case the default Field will be used584 }585 if (!oControl) {586 oControl = new Field(sId, {587 delegate: _getDelegate.call(this),588 value: { path: "$this>", type: oNullableType, mode: 'TwoWay', targetType: 'raw' },589 editMode: {path: "$condition>operator", formatter: _getEditModeFromOperator},590 width: "100%"591 });592 }593 if (oControl.getMetadata().hasProperty("placeholder")) {594 if (iIndex === 0) {595 oControl.bindProperty("placeholder", {path: "$condition>operator", formatter: _getPlaceholder1ForOperator});596 } else { // from Field cannot switch placeholder597 oControl.bindProperty("placeholder", {path: "$condition>operator", formatter: _getPlaceholder2ForOperator});598 }599 }600 oControl._iValueIndex = iIndex; // to find it for update601 if (oControl.attachChange) { // custom control might not have a change event602 oControl.attachChange(this.onChange.bind(this));603 }604 oControl.onpaste = this.onPaste.bind(this);605 oControl.setLayoutData(new GridData({span: {path: "$condition>", formatter: _getSpanForValue.bind(this)}}));606 oControl.setBindingContext(oValueBindingContext, "$this");607 oControl.setBindingContext(oBindingContext, "$condition");608 // add fieldGroup to validate Condition only after both Fields are entered.609 oControl.setFieldGroupIds([oBindingContext.getPath()]); // use path to have a ID for every condition610 return oControl;611 }612 function _getFieldType(sOperator, iIndex) {613 var oDataType = _getType.call(this);614 var oOperator = FilterOperatorUtil.getOperator(sOperator);615 if (oOperator.valueTypes[iIndex] && [Operator.ValueType.Self, Operator.ValueType.Static].indexOf(oOperator.valueTypes[iIndex]) === -1) {616 oDataType = oOperator._createLocalType(oOperator.valueTypes[iIndex], oDataType);617 }618 var bStaticText = false;619 if (oOperator.valueTypes[iIndex] === Operator.ValueType.Static) {620 bStaticText = true;621 oDataType = _getDefaultType.call(this);622 }623 var sType = bStaticText ? BaseType.String : _getBaseType.call(this, oDataType);624 var oNullableType;625 switch (sType) {626 case BaseType.Numeric:627 var oFormatOptions = oDataType.getFormatOptions();628 if (oFormatOptions && oFormatOptions.hasOwnProperty("emptyString") && oFormatOptions.emptyString === null) {629 // given type can be used630 oNullableType = oDataType;631 } else {632 // "clone" type and make nullable633 oNullableType = _createNullableType(oDataType, { emptyString: null });634 }635 break;636 case BaseType.Date:637 case BaseType.Time:638 case BaseType.DateTime:639 oNullableType = oDataType;640 break;641 //TODO: how to handle unit fields?642 default:643 if (oDataType.getConstraints() && oDataType.getConstraints().hasOwnProperty("nullable") && oDataType.getConstraints().nullable === false) {644 // "clone" type and make nullable645 oNullableType = _createNullableType(oDataType);646 if (oDataType._bCreatedByOperator) {647 oNullableType = oOperator._createLocalType(oOperator.valueTypes[iIndex], oDataType);648 }649 } else {650 oNullableType = oDataType; // use given type or default string type651 }652 break;653 }654 return oNullableType;655 }656 function _createNullableType(oType, oNewFormatOprtions, oNewConstraints) {657 var Type = sap.ui.require(oType.getMetadata().getName().replace(/\./g, "/")); // type is already loaded because instance is provided658 var oFormatOptions = merge(oType.getFormatOptions(), oNewFormatOprtions || {});659 var oConstraints = merge(oType.getConstraints(), oNewConstraints || {});660 if (oConstraints.hasOwnProperty("nullable") && oConstraints.nullable === false) {661 oConstraints.nullable = true; // make nullable662 }663 //TODO oConstraints like maximum are not used inside the Double type664 return new Type(oFormatOptions, oConstraints);665 }666 function _getDefaultOperator() {667 var aOperators = _getOperators.call(this);668 var oOperator;669 var sOperatorName = this.getFormatOptions().defaultOperatorName;670 if (sOperatorName) {671 oOperator = FilterOperatorUtil.getOperator(sOperatorName);672 } else {673 var oType = _getType.call(this);674 var sType = _getBaseType.call(this, oType);675 oOperator = FilterOperatorUtil.getDefaultOperator(sType);676 }677 if (oOperator && aOperators.indexOf(oOperator.name) < 0) {678 // default operator not valid -> cannot use -> use first include-operator which requires some values679 for (var i = 0; i < aOperators.length; i++) {680 oOperator = FilterOperatorUtil.getOperator(aOperators[i]);681 if (oOperator.exclude || !oOperator.hasRequiredValues()) {682 oOperator = undefined;683 } else {684 break;685 }686 }687 }688 if (!oOperator) {689 // in case no operator was found, use the first operator690 oOperator = FilterOperatorUtil.getOperator(aOperators[0]);691 }692 return oOperator;693 }694 function _getOperators() {695 var oFormatOptions = this.getFormatOptions();696 var aOperators = oFormatOptions && oFormatOptions.operators;697 if (!aOperators || aOperators.length === 0) {698 // TODO: better default699 aOperators = FilterOperatorUtil.getOperatorsForType(BaseType.String);700 }701 return aOperators;702 }703 function _hasMultipleOperatorGroups() {704 var firstGroupId;705 var aOperators = _getOperators.call(this);706 for (var i = 0; i < aOperators.length; i++) {707 var sOperator = aOperators[i];708 var oOperator = FilterOperatorUtil.getOperator(sOperator);709 if (!firstGroupId) {710 firstGroupId = oOperator.group.id;711 } else if (firstGroupId !== oOperator.group.id) {712 return true;713 }714 }715 return false;716 }717 function _updateOperatorModel() {718 if (!this.oOperatorModel) {719 return;720 }721 var oType = _getType.call(this);722 // assert(oOperatorConfig == null, "oOperatorConfig does not exist - no operators for Select control can be added");723 var aOperators = _getOperators.call(this);724 var aOperatorsData = [];725 var bHasMultipleGroups = _hasMultipleOperatorGroups.call(this);726 var sFieldHelpId = this.getId() + "--rowSelect-help";727 var oListFieldHelp = sap.ui.getCore().byId(sFieldHelpId);728 var oTemplate;729 if (bHasMultipleGroups) {730 oTemplate = new ListFieldHelpItem({key: "{om>key}", text: "{om>text}", additionalText: "{om>additionalText}", groupKey: "{om>groupId}", groupText: "{om>groupText}"});731 } else {732 oTemplate = new ListItem({key: "{om>key}", text: "{om>text}", additionalText: "{om>additionalText}"});733 }734 oListFieldHelp.bindAggregation("items", { path: 'om>/', templateShareable: false, template: oTemplate});735 for (var i = 0; i < aOperators.length; i++) {736 var sOperator = aOperators[i];737 var oOperator = FilterOperatorUtil.getOperator(sOperator);738 if (!oOperator || (oOperator.showInSuggest !== undefined && oOperator.showInSuggest == false)) {739 continue;740 }741 // try to load the operator longText which is type dependent742 var sTxtKey = oOperator.textKey || "operators." + oOperator.name + ".longText";743 var sText = oOperator.getTypeText(sTxtKey, _getBaseType.call(this, oType).toLowerCase());744 if (sText === sTxtKey) {745 // when the returned text is the key, a type dependent longText does not exist and we use the default longText for the operator746 sText = oOperator.longText;747 }748 //Update the additionalInfo text for the operator749 var sAdditionalText = oOperator.additionalInfo;750 if (sAdditionalText === undefined) {751 if (sAdditionalText !== "" && oOperator.formatRange) {752 sAdditionalText = oOperator.formatRange( oOperator._getRange(undefined, oType), oType);753 } else if (!bHasMultipleGroups) {754 sAdditionalText = oOperator.group.text;755 }756 }757 aOperatorsData.push({758 key: oOperator.name,759 text: sText,760 additionalText: sAdditionalText,761 groupId: oOperator.group.id,762 groupText: oOperator.group.text763 });764 }765 this.oOperatorModel.setData(aOperatorsData);766 }767 function _getType() {768 var oFormatOptions = this.getFormatOptions();769 var oType = oFormatOptions && oFormatOptions.valueType;770 if (!oType) {771 oType = _getDefaultType.call(this);772 }773 return oType;774 }775 function _getDefaultType() {776 if (!this._oDefaultType) {777 this._oDefaultType = new StringType();778 }779 return this._oDefaultType;780 }781 function _getBaseType(oType) {782 var sType = oType.getMetadata().getName();783 var oFormatOptions = oType.getFormatOptions();784 var oConstraints = oType.getConstraints();785 var oDelegate = this.getFormatOptions().delegate;786 var oPayload = this.getFormatOptions().payload;787 var sBaseType = oDelegate ? oDelegate.getTypeUtil(oPayload).getBaseType(sType, oFormatOptions, oConstraints) : BaseType.String; // if not configured use string788 if (sBaseType === BaseType.Unit) {789 sBaseType = BaseType.Numeric;790 }791 return sBaseType;792 }793 function _getDelegate() {794 var oFormatOptions = this.getFormatOptions();795 var sName = oFormatOptions.delegateName || "sap/ui/mdc/field/FieldBaseDelegate";796 var oPayload = oFormatOptions.payload;797 return {name: sName, payload: oPayload};798 }799 function _addStaticText(aConditions, bUpdateBinding, bTypeChange) {800 // for static operators add static text as value to render text control801 var oDataType = _getType.call(this);802 var aUpdate = [];803 var i = 0;804 for (i = 0; i < aConditions.length; i++) {805 var oCondition = aConditions[i];806 var oOperator = FilterOperatorUtil.getOperator(oCondition.operator);807 if (oOperator && oOperator.valueTypes[0] === Operator.ValueType.Static && (oCondition.values.length === 0 || bTypeChange)) {808 // if type changed the text needs to be new formatted (setting of type and conditions might be async.)809 if (oOperator.getStaticText) {810 var sText = oOperator.getStaticText(oDataType);811 if (oCondition.values.length > 0) {812 oCondition.values[0] = sText;813 } else {814 oCondition.values.push(sText);815 }816 aUpdate.push(i);817 }818 }819 }820 if (aUpdate.length > 0) {821 this.setProperty("conditions", aConditions, true); // do not invalidate whole DefineConditionPanel822 }823 }824 function _createInnerControls() {825 var oInvisibleOperatorText = new InvisibleText(this.getId() + "--ivtOperator", {text: "{$i18n>valuehelp.DEFINECONDITIONS_OPERATORLABEL}"});826 var oPanel = new Panel({headerText: "{$this>/label}",827 expanded: true,828 height: "100%",829 backgroundDesign: "Transparent"}830 ).addStyleClass("sapMdcDefineconditionPanel");831 oPanel.addDependent(832 new ListFieldHelp(this.getId() + "--rowSelect-help", {833 filterList: false,834 useFirstMatch: true835 })836 );837 var oGrid = new Grid(this.getId() + "--conditions", {838 width: "100%",839 hSpacing: 0,840 vSpacing: 0,841 containerQuery: true}842 ).addStyleClass("sapUiMdcDefineConditionGrid");843 _createRow.call(this, undefined, oGrid, 0, null, 0); // create dummy row844 oPanel.addContent(oInvisibleOperatorText);845 oPanel.addContent(oGrid);846 var oAddBtn = new Button(this.getId() + "--addBtn", {847 press: this.addCondition.bind(this),848 type: ButtonType.Default,849 text: "{$i18n>valuehelp.DEFINECONDITIONS_ADDCONDITION}",850 layoutData: new GridData({851 span: "XL2 L3 M3 S3",852 indent: "XL9 L8 M8 S7",853 linebreak: true,854 visibleS: {path: "$this>/conditions", formatter: _getAddButtonVisible.bind(this)},855 visibleM: {path: "$this>/conditions", formatter: _getAddButtonVisible.bind(this)},856 visibleL: {path: "$this>/conditions", formatter: _getAddButtonVisible.bind(this)},857 visibleXL: {path: "$this>/conditions", formatter: _getAddButtonVisible.bind(this)}})}858 );859 oGrid.addContent(oAddBtn);860 oGrid.attachValidateFieldGroup(_validateFieldGroup, this); // to validate conditions with more than one field861 this.setAggregation("_content", oPanel);862 }863 function _getAddButtonVisible(aConditions) {864 var oFormatOptions = this.getFormatOptions();865 var iMaxConditions = oFormatOptions.hasOwnProperty("maxConditions") ? oFormatOptions.maxConditions : -1;866 return iMaxConditions === -1 || aConditions.length < iMaxConditions;867 }868 function _getRemoveButtonVisible(aConditions) {869 var oFormatOptions = this.getFormatOptions();870 var iMaxConditions = oFormatOptions.hasOwnProperty("maxConditions") ? oFormatOptions.maxConditions : -1;871 // only on case of maxCondition==1 the Remove icons should be invisible872 return iMaxConditions !== 1;873 }874 function _renderConditions() {875 var aConditions = this.getConditions();876 var oGrid = this.byId("conditions");877 var aGridContent;878 var iRow = -1;879 var iIndex = 0;880 for (var i = 0; i < aConditions.length; i++) {881 var oCondition = aConditions[i];882 var oOperator = FilterOperatorUtil.getOperator(oCondition.operator);883 if (oCondition.validated !== ConditionValidated.Validated || oOperator.exclude) {884 // show only validated conditions885 var oBindingContext = this._oManagedObjectModel.getContext("/conditions/" + i + "/");886 iRow++;887 if (!this.oOperatorModel) {888 // init operatorModel if first row is created (needed to check operator)889 this.oOperatorModel = new JSONModel();890 this.setModel(this.oOperatorModel, "om");891 _updateOperatorModel.call(this);892 }893 aGridContent = oGrid.getContent(); // to have current content894 if (aGridContent[iIndex] && aGridContent[iIndex].isA("sap.ui.mdc.Field")) {895 // row already exists -> update it896 iIndex = _updateRow.call(this, oCondition, oGrid, iIndex, oBindingContext, iRow);897 } else {898 // reate new row899 iIndex = _createRow.call(this, oCondition, oGrid, iIndex, oBindingContext, iRow);900 }901 }902 }903 // remove unused rows904 aGridContent = oGrid.getContent();905 while (aGridContent[iIndex] && aGridContent[iIndex] !== this.byId("addBtn")) {906 aGridContent[iIndex].destroy();907 iIndex++;908 }909 if (this._bFocusLastCondition) {910 // focus last condition after it is rendered911 aGridContent[0].focus();912 this._bFocusLastCondition = false;913 }914 if (this._bFocusLastRemoveBtn) {915 // focus the remove-Button of the last condition row916 iIndex = _getGridIndexOfLastRowWithVisibleElement.call(this, ["-removeBtnLarge", "-removeBtnSmall"]);917 aGridContent[iIndex].focus();918 this._bFocusLastRemoveBtn = false;919 }920 }921 function _getGridIndexOfLastRowWithVisibleElement(aIdEndsWith) {922 var oGrid = this.byId("conditions");923 var aElements = oGrid.getContent();924 var n = aElements.length - 1;925 if (!Array.isArray(aIdEndsWith)) {926 aIdEndsWith = [aIdEndsWith];927 }928 var i = 0;929 var sSearch = aIdEndsWith[i];930 while (n >= 0 && sSearch !== undefined) {931 var oElement = aElements[n];932 if (oElement.getId().endsWith(sSearch)) {933 var $check = jQuery(oElement.getDomRef());934 if ($check.is(":visible")) {935 return n;936 } else {937 i++;938 sSearch = aIdEndsWith[i];939 }940 }941 n--;942 }943 return 0;944 }945 function _createRow(oCondition, oGrid, iIndex, oBindingContext, iRow) {946 var sIdPrefix = this.getId() + "--" + iRow;947 if (!this._oOperatorFieldType) {948 this._oOperatorFieldType = new StringType({}, {minLength: 1});949 }950 var oOperatorField = new Field(sIdPrefix + "-operator", {951 value: {path: "$this>operator", type: this._oOperatorFieldType},952 width: "100%",953 display: "Description",954 fieldHelp: this.getId() + "--rowSelect-help",955 change: this.onSelectChange.bind(this),956 ariaLabelledBy: this.getId() + "--ivtOperator"957 })958 .setLayoutData(new GridData({span: {path: "$this>/conditions", formatter: _getSpanForOperator.bind(this)}, linebreak: true}))959 .setBindingContext(oBindingContext, "$this");960 if (oBindingContext) {961 // validate only complete condition962 oOperatorField.setFieldGroupIds([oBindingContext.getPath()]); // use path to have a ID for every condition963 }964 // as selected key can be changed by reopening dialog listen on property change not on change event965 this._oObserver.observe(oOperatorField, {966 properties: ["value"]967 });968 oGrid.insertContent(oOperatorField, iIndex); // insert as add-Button is already at the end969 iIndex++;970 var oRemoveButton = new Button(sIdPrefix + "--removeBtnSmall", {971 press: this.removeCondition.bind(this),972 type: ButtonType.Transparent,973 icon: "sap-icon://decline",974 tooltip: "{$i18n>valuehelp.DEFINECONDITIONS_REMOVECONDITION}"975 })976 .setLayoutData(new GridData({span: "XL1 L1 M1 S2",977 indent: {path: "$this>operator", formatter: _getIndentForOperator},978 visibleS: {path: "$this>/conditions", formatter: _getRemoveButtonVisible.bind(this)},979 visibleM: false,980 visibleL: false,981 visibleXL: false982 }))983 .setBindingContext(oBindingContext, "$this"); // to find condition on remove984 if (oBindingContext) {985 // as Button is between Operatot and Value don't trigger validation on tabbing between986 oRemoveButton.setFieldGroupIds([oBindingContext.getPath()]); // use path to have a ID for every condition987 }988 oGrid.insertContent(oRemoveButton, iIndex);989 iIndex++;990 if (oCondition) { // for initial dummy row don't create value fields (as we don't know the operator or type)991 for (var i = 0; i < oCondition.values.length; i++) {992 var oControl = _createControl.call(this, oCondition, i, sIdPrefix + "-values" + i, oBindingContext);993 if (oControl) {994 oGrid.insertContent(oControl, iIndex);995 iIndex++;996 }997 }998 }999 var oRemoveButton2 = new Button(sIdPrefix + "--removeBtnLarge", {1000 press: this.removeCondition.bind(this),1001 type: ButtonType.Transparent,1002 icon: "sap-icon://decline",1003 tooltip: "{$i18n>valuehelp.DEFINECONDITIONS_REMOVECONDITION}"1004 })1005 .setLayoutData(new GridData({span: "XL1 L1 M1 S1",1006 indent: {path: "$this>operator", formatter: _getIndentForOperator},1007 visibleS: false,1008 visibleM: {path: "$this>/conditions", formatter: _getRemoveButtonVisible.bind(this)},1009 visibleL: {path: "$this>/conditions", formatter: _getRemoveButtonVisible.bind(this)},1010 visibleXL: {path: "$this>/conditions", formatter: _getRemoveButtonVisible.bind(this)}1011 }))1012 .setBindingContext(oBindingContext, "$this"); // to find condition on remove1013 oGrid.insertContent(oRemoveButton2, iIndex);1014 iIndex++;1015 return iIndex;1016 }1017 function _getEditModeFromOperator(sOperator) {1018 if (!sOperator) {1019 return EditMode.Display;1020 }1021 var oOperator = FilterOperatorUtil.getOperator(sOperator);1022 var bStaticText = false;1023 if (oOperator && oOperator.valueTypes[0] === Operator.ValueType.Static) {1024 bStaticText = true;1025 }1026 return bStaticText ? EditMode.Display : EditMode.Editable;1027 }1028 function _getIndentForOperator(sOperator) {1029 var oOperator = sOperator && FilterOperatorUtil.getOperator(sOperator);1030 if (!oOperator || !oOperator.valueTypes[0]) {1031 return "XL8 L8 M8 S0";1032 } else {1033 return "";1034 }1035 }1036 function _getSpanForOperator(aConditions) {1037 var oFormatOptions = this.getFormatOptions();1038 var iMaxConditions = oFormatOptions.hasOwnProperty("maxConditions") ? oFormatOptions.maxConditions : -1;1039 var sSpan = "XL3 L3 M3 ";1040 if (iMaxConditions === 1) {1041 sSpan += "S12";1042 } else {1043 sSpan += "S10";1044 }1045 return sSpan;1046 }1047 function _getSpanForValue(oCondition) {1048 var oFormatOptions = this.getFormatOptions();1049 var iMaxConditions = oFormatOptions.hasOwnProperty("maxConditions") ? oFormatOptions.maxConditions : -1;1050 var oOperator = oCondition && FilterOperatorUtil.getOperator(oCondition.operator);1051 var sSpan = "";1052 if (oOperator && oOperator.valueTypes[1]) {1053 sSpan = "XL4 L4 M4 ";1054 } else {1055 sSpan = "XL8 L8 M8 ";1056 }1057 if (iMaxConditions === 1) {1058 sSpan += "S12";1059 } else {1060 sSpan += "S10";1061 }1062 return sSpan;1063 }1064 function _getPlaceholder1ForOperator(sOperator) {1065 var oOperator = sOperator && FilterOperatorUtil.getOperator(sOperator);1066 if (oOperator && oOperator.aLabels) {1067 return oOperator.aLabels[0];1068 } else if (oOperator && oOperator.valueTypes[1]) {1069 return oMessageBundle.getText("valuehelp.DEFINECONDITIONS_FROM");1070 } else {1071 return oMessageBundle.getText("valuehelp.DEFINECONDITIONS_VALUE");1072 }1073 }1074 function _getPlaceholder2ForOperator(sOperator) {1075 var oOperator = sOperator && FilterOperatorUtil.getOperator(sOperator);1076 if (oOperator && oOperator.aLabels) {1077 return oOperator.aLabels[1];1078 } else if (oOperator && oOperator.valueTypes[1]) {1079 return oMessageBundle.getText("valuehelp.DEFINECONDITIONS_TO");1080 }1081 }1082 function _updateRow(oCondition, oGrid, iIndex, oBindingContext, iRow) {1083 var sIdPrefix = this.getId() + "--" + iRow;1084 var aGridContent = oGrid.getContent();1085 var oNullableType;1086 var oOperatorField = aGridContent[iIndex];1087 oOperatorField.setBindingContext(oBindingContext, "$this");1088 if (oBindingContext) {1089 oOperatorField.setFieldGroupIds([oBindingContext.getPath()]); // use path to have a ID for every condition1090 }1091 iIndex++;1092 var oRemoveButton = aGridContent[iIndex];1093 oRemoveButton.setBindingContext(oBindingContext, "$this");1094 if (oBindingContext) {1095 // as Button is between Operatot and Value don't trigger validation on tabbing between1096 oRemoveButton.setFieldGroupIds([oBindingContext.getPath()]); // use path to have a ID for every condition1097 }1098 iIndex++;1099 var oValueBindingContext;1100 var oValue0Field = aGridContent[iIndex];1101 var oValue1Field;1102 if (oValue0Field.hasOwnProperty("_iValueIndex") && oValue0Field._iValueIndex === 0) {1103 var sEditMode = _getEditModeFromOperator(oCondition.operator);1104 if (oCondition.values.length > 0 || sEditMode === EditMode.Display) { // as static text for display controls is created after update1105 oValueBindingContext = this._oManagedObjectModel.getContext(oBindingContext.getPath() + "values/0/");1106 oValue0Field.setBindingContext(oValueBindingContext, "$this");1107 oValue0Field.setBindingContext(oBindingContext, "$condition");1108 if (oValue0Field.getMetadata().hasProperty("value") && (this._bUpdateType || !oValue0Field.getBindingInfo("value"))) {1109 oNullableType = _getFieldType.call(this, oCondition.operator, 0);1110 // change type for binding1111 oValue0Field.bindProperty("value", {path: "$this>", type: oNullableType});1112 }1113 iIndex++;1114 // value[1] only possible if value[0] exist1115 oValue1Field = aGridContent[iIndex];1116 if (oValue1Field.hasOwnProperty("_iValueIndex") && oValue1Field._iValueIndex === 1) {1117 if (oCondition.values.length > 1) {1118 oValueBindingContext = this._oManagedObjectModel.getContext(oBindingContext.getPath() + "values/1/");1119 oValue1Field.setBindingContext(oValueBindingContext, "$this");1120 if (oValue1Field.getMetadata().hasProperty("value") && (this._bUpdateType || !oValue1Field.getBindingInfo("value"))) {1121 oNullableType = _getFieldType.call(this, oCondition.operator, 1);1122 // change type for binding1123 oValue1Field.bindProperty("value", {path: "$this>", type: oNullableType});1124 }1125 iIndex++;1126 } else {1127 oValue1Field.destroy();1128 }1129 } else if (oCondition.values.length > 1) {1130 // insert new field1131 oValue1Field = _createControl.call(this, oCondition, 1, sIdPrefix + "-values1", oBindingContext);1132 if (oValue1Field) {1133 oGrid.insertContent(oValue1Field, iIndex);1134 iIndex++;1135 }1136 }1137 } else {1138 oValue0Field.destroy();1139 oValue0Field = undefined;1140 oValue1Field = aGridContent[iIndex + 1];1141 if (oValue1Field && oValue1Field.hasOwnProperty("_iValueIndex") && oValue1Field._iValueIndex === 1) {1142 oValue1Field.destroy();1143 }1144 }1145 } else if (oCondition.values.length > 0) {1146 for (var i = 0; i < oCondition.values.length; i++) {1147 var oControl = _createControl.call(this, oCondition, i, sIdPrefix + "-values" + i, oBindingContext);1148 if (oControl) {1149 oGrid.insertContent(oControl, iIndex);1150 iIndex++;1151 }1152 }1153 }1154 aGridContent = oGrid.getContent(); // as field might be added or removed1155 var oRemoveButton2 = aGridContent[iIndex];1156 oRemoveButton2.setBindingContext(oBindingContext, "$this");1157 iIndex++;1158 return iIndex;1159 }1160 function _validateFieldGroup(oEvent) {1161 // TODO: can there be FieldGroups set from outside?1162 var oField = oEvent.getSource();1163 while (!(oField.getParent() instanceof Grid)) {1164 // event might be fired on inner control -> find Field1165 oField = oField.getParent();1166 }1167 _validateCondition.call(this, oField);1168 }1169 function _validateCondition(oField) {1170 var oGrid = oField.getParent();1171 var iIndex = oGrid.indexOfContent(oField);1172 var oBindingContext;1173 if (oField.getId().endsWith("-operator")) {1174 // operator field - use first value field fo validate1175 oBindingContext = oField.getBindingContext("$this");1176 iIndex = iIndex + 2; // as remove button is between operator an value field1177 oField = oGrid.getContent()[iIndex];1178 } else if (oField.getId().endsWith("-removeBtnSmall")) {1179 // operator field - use first value field fo validate1180 oBindingContext = oField.getBindingContext("$this");1181 iIndex = iIndex + 1; // as remove button is between operator an value field1182 oField = oGrid.getContent()[iIndex];1183 } else {1184 oBindingContext = oField.getBindingContext("$condition");1185 }1186 var oField2; // also update second Field if exist1187 var oCondition = oBindingContext.getObject();1188 var oOperator = FilterOperatorUtil.getOperator(oCondition.operator);1189 var bInvalid = false;1190 if (oOperator.valueTypes.length > 0 && oOperator.valueTypes[0] !== Operator.ValueType.Static) {1191 // check only not static operators1192 if (oOperator.valueTypes.length > 1 && oOperator.valueTypes[1]) {1193 // two fields exist1194 if (oField.hasOwnProperty("_iValueIndex") && oField._iValueIndex === 0) {1195 oField2 = oGrid.getContent()[iIndex + 1];1196 } else if (oField.hasOwnProperty("_iValueIndex") && oField._iValueIndex === 1) {1197 oField2 = oGrid.getContent()[iIndex - 1];1198 }1199 }1200 if (oField.getMetadata().getAllProperties().valueState && !oField._bParseError && (!oField2 || !oField2._bParseError)) { // TODO: better was to find out parsing error1201 // if Field is in parsing error state, user entry is not transfered to condition, so validating makes no sense.1202 var oType = oField.getBinding("value").getType(); // use nullable data type from Field - don't create new type for each check1203 try {1204 oOperator.validate(oCondition.values, oType);1205 oField.setValueState(ValueState.None);1206 oField.setValueStateText();1207 if (oField2 && oField2.getMetadata().getAllProperties().valueState) {1208 oField2.setValueState(ValueState.None);1209 oField2.setValueStateText();1210 }1211 } catch (oException) {1212 bInvalid = true;1213 oField.setValueState(ValueState.Error);1214 oField.setValueStateText(oException.message);1215 if (oField2 && oField2.getMetadata().getAllProperties().valueState) {1216 oField2.setValueState(ValueState.Error);1217 oField2.setValueStateText(oException.message);1218 }1219 }1220 }1221 }1222 // check if at least one condition has an error1223 _checkInvalidInput.call(this, bInvalid);1224 this.fireConditionProcessed();1225 }1226 function _checkInvalidInput(bInvalid) {1227 if (bInvalid !== true) {1228 // if already known that invalid input exist -> no additional check needed1229 var oGrid = this.byId("conditions");1230 var aContent = oGrid.getContent();1231 bInvalid = false;1232 for (var i = 0; i < aContent.length; i++) {1233 var oControl = aContent[i];1234 if (oControl instanceof Field && oControl.hasOwnProperty("_iValueIndex") && oControl.getValueState() === ValueState.Error) {1235 bInvalid = true;1236 break;1237 }1238 }1239 }1240 this.setProperty("inputOK", !bInvalid, true); // do not invalidate whole DefineConditionPanel1241 }1242 return DefineConditionPanel;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var util = require('util');2var getOperator = util.getOperator;3var operator = getOperator('operator1');4var util = require('util');5var getOperator = util.getOperator;6var operator = getOperator('operator1');7var util = require('util');8var getOperator = util.getOperator;9var operator = getOperator('operator1');10var util = require('util');11var getOperator = util.getOperator;12var operator = getOperator('operator1');13var util = require('util');14var getOperator = util.getOperator;15var operator = getOperator('operator1');16var util = require('util');17var getOperator = util.getOperator;18var operator = getOperator('operator1');19var util = require('util');20var getOperator = util.getOperator;21var operator = getOperator('operator1');22var util = require('util');23var getOperator = util.getOperator;24var operator = getOperator('operator1');25var util = require('util');26var getOperator = util.getOperator;27var operator = getOperator('operator1');28var util = require('util');29var getOperator = util.getOperator;30var operator = getOperator('operator1');31var util = require('util');32var getOperator = util.getOperator;33var operator = getOperator('operator1');34var util = require('util');35var getOperator = util.getOperator;36var operator = getOperator('operator1');37var util = require('util');38var getOperator = util.getOperator;39var operator = getOperator('operator1');40var util = require('util');41var getOperator = util.getOperator;42var operator = getOperator('operator1');

Full Screen

Using AI Code Generation

copy

Full Screen

1var util = require('util');2var operator = util.getOperator('operator1');3console.log(operator);4var getOperator = function(operatorId) {5 return getAsset(operatorId);6};7exports.getOperator = getOperator;8var getAsset = function(assetId) {9 var assetAsBytes = stub.getState(assetId);10 if (!assetAsBytes || assetAsBytes.toString().length <= 0) {11 throw new Error(assetId + ' does not exist: ');12 }13 return JSON.parse(assetAsBytes.toString());14};15exports.getAsset = getAsset;

Full Screen

Using AI Code Generation

copy

Full Screen

1var util = require('./util.js');2var operator = util.getOperator();3console.log(operator);4var operator = 'operator1';5exports.getOperator = function() {6 return operator;7}8var util = require('./util.js');9var operator = util.getOperator();10console.log(operator);11var operator = 'operator1';12exports.getOperator = function() {13 return operator;14}

Full Screen

Using AI Code Generation

copy

Full Screen

1var util = require('util');2var getOperator = util.getOperator;3var operator = getOperator();4var operatorId = operator.operatorId;5var operatorName = operator.operatorName;6var operatorRole = operator.operatorRole;7var util = require('util');8var getOperator = util.getOperator;9var operator = getOperator();10var operatorId = operator.operatorId;11var operatorName = operator.operatorName;12var operatorRole = operator.operatorRole;13var util = require('util');14var getOperator = util.getOperator;15var operator = getOperator();16var operatorId = operator.operatorId;17var operatorName = operator.operatorName;18var operatorRole = operator.operatorRole;19var util = require('util');20var getOperator = util.getOperator;21var operator = getOperator();22var operatorId = operator.operatorId;23var operatorName = operator.operatorName;24var operatorRole = operator.operatorRole;25var util = require('util');26var getOperator = util.getOperator;27var operator = getOperator();28var operatorId = operator.operatorId;29var operatorName = operator.operatorName;30var operatorRole = operator.operatorRole;31var util = require('util');32var getOperator = util.getOperator;33var operator = getOperator();34var operatorId = operator.operatorId;35var operatorName = operator.operatorName;36var operatorRole = operator.operatorRole;37var util = require('util');38var getOperator = util.getOperator;39var operator = getOperator();40var operatorId = operator.operatorId;41var operatorName = operator.operatorName;42var operatorRole = operator.operatorRole;43var util = require('util');44var getOperator = util.getOperator;45var operator = getOperator();46var operatorId = operator.operatorId;47var operatorName = operator.operatorName;48var operatorRole = operator.operatorRole;49var util = require('util');50var getOperator = util.getOperator;51var operator = getOperator();52var operatorId = operator.operatorId;53var operatorName = operator.operatorName;

Full Screen

Using AI Code Generation

copy

Full Screen

1var util = require('util');2var operator = util.getOperator('operator', 'password');3console.log(operator);4var getOperator = function (username, password) {5 var operator = {6 };7 return operator;8};9exports.getOperator = getOperator;

Full Screen

Using AI Code Generation

copy

Full Screen

1var util = require('./util.js');2var operator = util.getOperator();3operator.invoke("invoke", ["a", "b", "100"]);4var hfc = require('hfc');5var util = require('util');6var fs = require('fs');7var chain;8var operator;9var setupChain = function() {10 chain = hfc.newChain("myChain");11 chain.setKeyValStore(hfc.newFileKeyValStore('/tmp/keyValStore'));12 chain.enroll("WebAppAdmin", "DJY27pEnl16d", function(err, webAppAdmin) {13 if (err) throw Error(" Failed to register and enroll webAppAdmin");14 operator = webAppAdmin;15 chain.setRegistrar(webAppAdmin);16 });17};18setupChain();19exports.getOperator = function() {20 return operator;21};22var util = require('./util.js');23var operator = util.getOperator();24var chaincodeID = "mycc";25operator.queryChaincode(chaincodeID, ["query", "a"], function(err, resp) {26 if (err) throw Error("Failed to query chaincode. Error: " + err.stack ? err.stack : err);27 else console.log("Response is ", resp);28});29var util = require('./util.js');30var operator = util.getOperator();31var chaincodeID = "mycc";32operator.invokeChaincode(chaincodeID, ["invoke", "a", "b", "100"], function(err, resp) {33 if (err) throw Error("Failed to invoke chaincode. Error: " + err.stack ? err.stack : err);34 else console.log("Response

Full Screen

Using AI Code Generation

copy

Full Screen

1var util = require('util');2var getOperator = util.getOperator;3var operator = getOperator();4console.log(operator);5module.exports = {6 getOperator: function() {7 return 'Operator: ' + process.env.OPERATOR;8 }9};

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run chai automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful