@sapui5/sap.rules.ui 1.106.0 → 1.108.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/package.json +1 -1
  2. package/src/sap/rules/ui/.library +1 -1
  3. package/src/sap/rules/ui/AstExpressionBasic.js +27 -6
  4. package/src/sap/rules/ui/AstExpressionBasicRenderer.js +71 -55
  5. package/src/sap/rules/ui/AutoCompleteSuggestionContent.js +5 -3
  6. package/src/sap/rules/ui/AutoCompleteSuggestionContentRenderer.js +39 -40
  7. package/src/sap/rules/ui/BindingSpy.js +1 -1
  8. package/src/sap/rules/ui/DecisionTable.js +2157 -2154
  9. package/src/sap/rules/ui/DecisionTableCell.js +7 -4
  10. package/src/sap/rules/ui/DecisionTableCellAstExpressionBasic.js +7 -4
  11. package/src/sap/rules/ui/DecisionTableCellAstExpressionBasicRenderer.js +5 -3
  12. package/src/sap/rules/ui/DecisionTableCellExpressionAdvanced.js +238 -236
  13. package/src/sap/rules/ui/DecisionTableCellExpressionAdvancedRenderer.js +6 -4
  14. package/src/sap/rules/ui/DecisionTableCellExpressionBasic.js +7 -4
  15. package/src/sap/rules/ui/DecisionTableCellExpressionBasicRenderer.js +6 -4
  16. package/src/sap/rules/ui/DecisionTableCellRenderer.js +10 -10
  17. package/src/sap/rules/ui/DecisionTableConfiguration.js +1 -1
  18. package/src/sap/rules/ui/DecisionTableRenderer.js +163 -161
  19. package/src/sap/rules/ui/DecisionTableSettings.js +6 -4
  20. package/src/sap/rules/ui/DecisionTableSettingsOld.js +963 -961
  21. package/src/sap/rules/ui/DecisionTableSettingsOldRenderer.js +9 -10
  22. package/src/sap/rules/ui/DecisionTableSettingsRenderer.js +9 -10
  23. package/src/sap/rules/ui/ExpressionAdvanced.js +1726 -1724
  24. package/src/sap/rules/ui/ExpressionAdvancedRenderer.js +8 -8
  25. package/src/sap/rules/ui/ExpressionBase.js +1 -1
  26. package/src/sap/rules/ui/ExpressionBasic.js +7 -4
  27. package/src/sap/rules/ui/ExpressionBasicRenderer.js +8 -7
  28. package/src/sap/rules/ui/InstructionRenderer.js +73 -33
  29. package/src/sap/rules/ui/RuleBase.js +1 -1
  30. package/src/sap/rules/ui/RuleBuilder.js +433 -430
  31. package/src/sap/rules/ui/RuleBuilderRenderer.js +8 -9
  32. package/src/sap/rules/ui/TextRule.js +7 -4
  33. package/src/sap/rules/ui/TextRuleConfiguration.js +1 -1
  34. package/src/sap/rules/ui/TextRuleRenderer.js +45 -44
  35. package/src/sap/rules/ui/TextRuleSettings.js +6 -4
  36. package/src/sap/rules/ui/TextRuleSettingsRenderer.js +9 -9
  37. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionAdvancedFunctionPanel.js +4 -3
  38. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionAdvancedFunctionPanelRenderer.js +10 -11
  39. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionAggregateFunctionPanel.js +100 -98
  40. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionAggregateFunctionPanelRenderer.js +9 -10
  41. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionArrayOperatorPanel.js +4 -3
  42. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionArrayOperatorPanelRenderer.js +10 -10
  43. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionComparisionOperatorPanel.js +109 -107
  44. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionComparisionOperatorPanelRenderer.js +39 -40
  45. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionDateAndTimePanel.js +5 -3
  46. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionDateAndTimePanelRenderer.js +10 -10
  47. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionFixedValuePanel.js +840 -838
  48. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionFixedValuePanelRenderer.js +40 -40
  49. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionFunctionalOperatorPanel.js +4 -3
  50. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionFunctionalOperatorPanelRenderer.js +10 -11
  51. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionLogicalOperatorPanel.js +112 -110
  52. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionLogicalOperatorPanelRenderer.js +39 -40
  53. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionLoopFunctionPanel.js +100 -98
  54. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionLoopFunctionPanelRenderer.js +9 -10
  55. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionMathematicalOperatorPanel.js +122 -119
  56. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionMathematicalOperatorPanelRenderer.js +39 -40
  57. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionMiscellaneousOperatorPanel.js +5 -2
  58. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionMiscellaneousOperatorPanelRenderer.js +10 -11
  59. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionOperationsPanel.js +4 -3
  60. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionOperationsPanelRenderer.js +10 -11
  61. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionRangeOperatorPanel.js +4 -3
  62. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionRangeOperatorPanelRenderer.js +10 -11
  63. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionSelectFunctionPanel.js +108 -106
  64. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionSelectFunctionPanelRenderer.js +40 -40
  65. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionTimeAndDurationFunctionPanel.js +254 -252
  66. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionTimeAndDurationFunctionPanelRenderer.js +40 -40
  67. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionVocabularyPanel.js +631 -629
  68. package/src/sap/rules/ui/ast/autoCompleteContent/AutoSuggestionVocabularyPanelRenderer.js +40 -40
  69. package/src/sap/rules/ui/library.js +31 -10
  70. package/src/sap/rules/ui/type/ExpressionAbs.js +1 -1
@@ -1,1727 +1,1729 @@
1
- /*!
1
+ /*!
2
2
  * SAP UI development toolkit for HTML5 (SAPUI5)
3
3
 
4
4
  (c) Copyright 2009-2016 SAP SE. All rights reserved
5
-
6
- */
7
-
8
- // Provides the sap.rules.ui.ExpressionAdvanced control
9
- sap.ui.define([
10
- "sap/base/Log",
11
- "sap/m/Dialog",
12
- "sap/ui/core/Control",
13
- "sap/m/Button",
14
- "sap/m/TextArea",
15
- "sap/m/Text",
16
- "sap/m/MessageBox",
17
- "sap/ui/layout/HorizontalLayout",
18
- "sap/rules/ui/Utils",
19
- "sap/ui/core/Popup",
20
- "jquery.sap.global",
21
- "sap/rules/ui/ExpressionBase",
22
- "sap/ui/comp/odata/MetadataAnalyser",
23
- "sap/rules/ui/providers/ValueHelpProvider",
24
- "sap/ui/core/LocaleData",
25
- "sap/rules/ui/Constants",
26
- "sap/rules/ui/codemirror/lib/codemirror",
27
- "sap/rules/ui/codemirror/addon/hint/show-hint",
28
- "sap/rules/ui/codemirror/mode/hdf/hdf",
29
- "sap/rules/ui/codemirror/addon/display/placeholder",
30
- "sap/rules/ui/codemirror/addon/mh/mark-selection",
31
- "sap/rules/ui/codemirror/addon/hint/hdf-hint",
32
- "sap/rules/ui/codemirror/addon/closeBrackets/closebrackets",
33
- "sap/rules/ui/codemirror/addon/search/search"
34
-
35
- ], function(Log, Dialog, Control, Button, TextArea, Text, MessageBox, HorizontalLayout, Utils, Popup, jQ, ExpressionBase, MetadataAnalyser,
36
- ValueHelpProvider, LocaleData, Constants) {
37
- "use strict";
38
- /**
39
- * Constructor for a new ExpressionAdvanced.
40
- *
41
- * @param {string} [sId] ID for the new control, generated automatically if no ID is given
42
- * @param {object} [mSettings] Initial settings for the new control
43
- *
44
- * @class
45
- * The <code>sap.rules.ui.ExpressionAdvanced</code> control provides the ability to define expressions for complex rules in a decision table.
46
- * @extends sap.ui.core.Control
47
- *
48
- * @author SAP SE
49
- * @version 1.58.1
50
- *
51
- * @constructor
52
- * @private
53
- * @experimental Only for internal use.
54
- *
55
- * @alias sap.rules.ui.ExpressionAdvanced
56
- * @ui5-metamodel This control also will be described in the UI5 (legacy) designtime metamodel
57
- */
58
-
59
- var ExpressionAdvanced = ExpressionBase.extend("sap.rules.ui.ExpressionAdvanced", {
60
-
61
- metadata: {
62
- properties: {
63
-
64
- /**
65
- * The business data type of the expression (e.g. String, Number, Boolean).
66
- * The default value <code>sap.rules.ui.ExpressionType.All</code> means that all valid business data types are permitted.
67
- */
68
- type: {
69
- type: "sap.rules.ui.ExpressionType",
70
- defaultValue: sap.rules.ui.ExpressionType.All,
71
- bindable: "bindable"
72
- },
73
-
74
- /**
75
- * Defines weather the expression evaluates to a collection of values or to a single value.
76
- */
77
- collection: {
78
- type: "boolean",
79
- defaultValue: false
80
- },
81
-
82
- /**
83
- * Defines a short hint intended to aid the user with data entry when the control has no value.
84
- */
85
- placeholder: {
86
- type: "string",
87
- defaultValue: null
88
- },
89
-
90
- /**
91
- * Defines whether the focus is set to the control upon loading.
92
- */
93
- focusOnLoad: {
94
- type: "boolean",
95
- defaultValue: false
96
- },
97
-
98
- attributeInfo: {
99
- type: "string",
100
- defaultValue: "",
101
- bindable: "bindable"
102
- }
103
- },
104
- aggregations: {
105
-
106
- // A hidden text area is provided for the codemirror rendering.
107
- _expressionArea: {
108
- type: "sap.m.TextArea",
109
- multiple: false,
110
- visibility: "hidden"
111
- }
112
- },
113
- events: {
114
-
115
- /**
116
- * This event is fired when the text in the input field has changed and the focus leaves the input field or the enter key is pressed.
117
- */
118
- "change": {},
119
-
120
- /**
121
- * This event is fired when the value of the input is changed - e.g. at each keypress
122
- */
123
- "liveChange": {},
124
- "valueHelpRequest": {
125
- parameters: {
126
-
127
- /**
128
- * The event parameter is set to true, when the button at the end of the suggestion table is clicked, otherwise false. It can be used to determine whether the "value help" trigger or the "show all items" trigger has been pressed.
129
- */
130
- fromSuggestions: {
131
- type: "boolean"
132
- }
133
- }
134
- }
135
- },
136
- publicMethosds: ["validate"]
137
- }
138
- });
139
-
140
- ExpressionAdvanced.prototype.init = function() {
141
- ExpressionBase.prototype.init.apply(this, arguments);
142
- var codeMirrorCSS = jQuery.sap.getModulePath("sap.rules.ui.codemirror.lib") + "/codemirror.css";
143
- var showHintCSS = jQuery.sap.getModulePath("sap.rules.ui.codemirror.addon.hint") + "/show-hint.css";
144
- jQuery.sap.includeStyleSheet(codeMirrorCSS);
145
- jQuery.sap.includeStyleSheet(showHintCSS);
146
-
147
- this.pop = new Popup(jQ('<span></span>')[0], false, false, false);
148
- this.errorWidgets = [];
149
- this.expressionTokens = [];
150
- this._liveValue = "";
151
- this.oBundle = sap.ui.getCore().getLibraryResourceBundle("sap.rules.ui.i18n");
152
- this.dataModel = this.initControlDataModel();
153
-
154
- // Expression area
155
- this.oTextArea = new TextArea({
156
- width: "100%"
157
- });
158
- this.validationCompleteEvent = document.createEvent("Event");
159
- this.validationCompleteEvent.initEvent("validationCompleteEvent", true, false);
160
- //this.validationCompleteEvent = document.createEvent("validationCompleteEvent");
161
- this.setAggregation("_expressionArea", this.oTextArea, true);
162
- this.bFlagForEventListener = true;
163
-
164
- // Date instance which is used to convert the selected date from calendar control to short format
165
- var oLocale = sap.ui.getCore().getConfiguration().getFormatSettings().getFormatLocale();
166
- var oLocaleData = LocaleData.getInstance(oLocale);
167
-
168
- this.oFormatDate = sap.ui.core.format.DateFormat.getInstance({
169
- pattern: oLocaleData.getDatePattern('short'),
170
- calendarType: sap.ui.core.CalendarType.Gregorian
171
- },
172
- oLocale
173
- );
174
- this._dateBusinessDataType = "Date";
175
- this._valueHelpSelectionText = "Select from value help...";
176
- this._hasValueSource = "HasValueSource";
177
- this._propertyValue = "Value";
178
- this._propertyDescription = "Description";
179
- };
180
-
181
- ExpressionAdvanced.prototype._processValidationResult = function(result) {
182
- if (result.status === sap.rules.ui.ValidationStatus.Error) {
183
- var msg = Utils.parseUTFToString(result.errorDetails /* || "unknown message" */ );
184
- msg = msg.replace(/\r\n/g, " ").replace(/\r/g, " ").replace(/\n/g, " ");
185
- this.errorCursorPosition = result.cursorPosition;
186
- this.setValueStateText(msg);
187
- //this._showPopUp();
188
- } else {
189
- this.oTextArea.setValueState("None");
190
- this.oTextArea.setValueStateText("");
191
- this.setValueStateText("");
192
- jQuery(this.codeMirror.getWrapperElement()).removeClass('sapMInputBaseStateInner sapMInputBaseErrorInner sapMInputBaseContentWrapper sapMInputBaseContentWrapperState sapMInputBaseContentWrapperError');
193
- }
194
-
195
- };
196
-
197
- ExpressionAdvanced.prototype.validateExpression = function(sInput) {
198
- for (var i = 0; i < this.errorWidgets.length; i++) {
199
- this.codeMirror.removeLineWidget(this.errorWidgets[i]);
200
- }
201
- this.errorWidgets = [];
202
- var expressionValue = this.codeMirror ? this.codeMirror.getValue() : this.getValue();
203
- var result = {};
204
- var incomingdata = {};
205
- var oEL = sap.ui.getCore().byId(this.getExpressionLanguage());
206
- if (oEL) {
207
- incomingdata = oEL.validateExpression(
208
- sInput || expressionValue,
209
- this.getProperty("type"),
210
- this.getCollection(),
211
- false
212
- );
213
- if (incomingdata && this.isActive()) {
214
- result = incomingdata;
215
- this._processValidationResult(result);
216
- if (result.deferredResult) {
217
- result.deferredResult.done(function(result) {
218
- this._processValidationResult(result);
219
- document.dispatchEvent(this.validationCompleteEvent);
220
- }.bind(this));
221
- }
222
- }
223
- }
224
- return incomingdata;
225
- };
226
-
227
- ExpressionAdvanced.prototype._showPopUp = function() {
228
- var errorState = "Error";
229
- var errorMessage = this.getProperty("valueStateText");
230
- var thisId = this.getId() + '-message';
231
- var pop = this.pop; //new Popup(jQ('<span></span>')[0], false, false, false);
232
- if (!this.pop) { //bug 4813
233
- return;
234
- }
235
- pop.attachClosed(function() {
236
- jQ.sap.byId(thisId).remove();
237
- });
238
- var dock = Popup.Dock;
239
- var cssClass = 'sapMInputBaseMessage' + errorState + ' sapMFocus';
240
- var T = 'sapMValueStateMessageError sapMText';
241
- var r = sap.ui.getCore().getLibraryResourceBundle('sap.m');
242
-
243
- if (errorState === sap.ui.core.ValueState.Success) {
244
- cssClass = 'sapUiInvisibleText';
245
- errorMessage = '';
246
- }
247
- var oContent = jQ('<div>', {
248
- 'id': thisId,
249
- 'class': cssClass,
250
- 'role': 'tooltip',
251
- 'aria-live': 'assertive'
252
- }).append(jQ('<span>', {
253
- 'aria-hidden': true,
254
- 'class': 'sapUiHidden',
255
- 'text': r.getText('INPUTBASE_VALUE_STATE_' + errorState.toUpperCase())
256
- })).append(jQ('<span>', {
257
- 'id': thisId + '-text',
258
- 'class': T,
259
- 'text': errorMessage
260
- }));
261
- pop.setContent(oContent[0]);
262
- pop.close(0);
263
- pop.open(0, dock.BeginTop, dock.BeginBottom, jQuery(this.codeMirror.getWrapperElement()), null, "none flip", true);
264
- var sPopUpWidth = this.pop.oContent.clientWidth;
265
- var oTextAreaHTMLElement = document.getElementById(this.getAggregation("_expressionArea"));
266
- if (!oTextAreaHTMLElement) {
267
- return;
268
- }
269
- var sExpressionAdvancedWidth = oTextAreaHTMLElement.sId.clientWidth;
270
- if (sPopUpWidth > sExpressionAdvancedWidth) {
271
- jQuery(".sapMText").css('width', sExpressionAdvancedWidth);
272
- jQuery(".sapMText").css('padding-left', '12px');
273
- jQuery(".sapMText").css('padding-right', '12px');
274
- jQuery(".sapMText").css('padding-top', '8px');
275
- jQuery(".sapMText").css('padding-bottom', '8px');
276
- }
277
- };
278
-
279
- ExpressionAdvanced.prototype._closePopUp = function() {
280
- if (this.pop) {
281
- this.pop.close(0);
282
- }
283
- };
284
-
285
- ExpressionAdvanced.prototype._showErrorMessage = function() {
286
- var errorMessage = this.getValueStateText();
287
- if (errorMessage && errorMessage !== "") {
288
- this._setExpressionErrorStyle();
289
- }
290
- };
291
-
292
- ExpressionAdvanced.prototype.initControlDataModel = function() {
293
- var oDataModel = new sap.ui.model.json.JSONModel();
294
- var data = {};
295
- oDataModel.setData(data);
296
- return oDataModel;
297
- };
298
-
299
- ExpressionAdvanced.prototype.setExpressionTokens = function(tokens) {
300
- var maxLineEnd = 0,
301
- newLineExist = false;
302
- this.expressionTokens = [];
303
- if (tokens instanceof Array) {
304
- for (var i = 0; i < tokens.length; i++) {
305
- var tokenMetaData = tokens[i];
306
- //minimize the number of cached tokens
307
- var newLineReg = /\n/;
308
- if (newLineReg.test(tokenMetaData.token)) {
309
- maxLineEnd = tokenMetaData.start + tokenMetaData.token.lastIndexOf('\n') + 1;
310
- newLineExist = true;
311
- continue;
312
- }
313
- if (newLineExist) {
314
- tokenMetaData.start = tokenMetaData.start - maxLineEnd;
315
- tokenMetaData.end = tokenMetaData.end - maxLineEnd + 1;
316
- } else {
317
- tokenMetaData.end = tokenMetaData.end + 1;
318
- }
319
- this.expressionTokens.push(tokenMetaData);
320
- }
321
- }
322
- };
323
-
324
- ExpressionAdvanced.prototype.getExpressionTokens = function() {
325
- return this.expressionTokens;
326
- };
327
-
328
- /** INTERFACE */
329
-
330
- ExpressionAdvanced.prototype.getValue = function() {
331
- if (this.codeMirror !== undefined) {
332
- return this.codeMirror.getValue();
333
- }
334
- return this.getProperty("value");
335
- };
336
- ExpressionAdvanced.prototype.setValue = function(value) {
337
- if (value === undefined || value === null) {
338
- value = "";
339
- }
340
- this._liveValue = value;
341
- this.oTextArea.setValue(value);
342
- if (this.getProperty("value") === value) {
343
- return;
344
- }
345
- this.setProperty("value", value, true);
346
- if (this.codeMirror !== undefined) {
347
- this.codeMirror.setValue(value);
348
- }
349
- };
350
-
351
- ExpressionAdvanced.prototype.setPlaceholder = function(value) {
352
- this.setProperty("placeholder", value);
353
- var modelValue = (this.getEditable()) ? value : "";
354
- this.dataModel.setProperty("/placeholder", modelValue);
355
- };
356
-
357
- ExpressionAdvanced.prototype.getPlaceholder = function() {
358
- return this.dataModel.getProperty("/placeholder");
359
- };
360
-
361
- ExpressionAdvanced.prototype.setValueStateText = function(message) {
362
- this.setProperty("valueStateText", message, true);
363
- if (message){
364
- this._showErrorMessage(message);
365
- } else {
366
- jQuery(this.codeMirror.getWrapperElement()).removeClass('CodeMirror-error');
367
- jQuery(this.codeMirror.getWrapperElement()).removeClass('sapMInputBaseStateInner sapMInputBaseErrorInner sapMInputBaseContentWrapper sapMInputBaseContentWrapperState sapMInputBaseContentWrapperError');
368
- }
369
- };
370
-
371
- ExpressionAdvanced.prototype.setEditable = function(value) {
372
- this.setProperty("editable", value);
373
- this.getAggregation("_expressionArea").setProperty("editable", value);
374
- if (this.codeMirror) {
375
- jQuery(this.codeMirror.getWrapperElement()).addClass('CodeMirror-rules-Not-Editable');
376
- }
377
- // placeholder is relevant only for editable field
378
- var _placeholder = (value) ? this.getProperty("placeholder") : "";
379
- this.dataModel.setProperty("/placeholder", _placeholder);
380
- this.invalidate();
381
- };
382
-
383
- ExpressionAdvanced.prototype.setType = function(type) {
384
- if (type === Constants.DATE_BUSINESS_TYPE || type === Constants.TIMESTAMP_BUSINESS_TYPE || type === Constants.NUMBER || type ===
385
- Constants.STRING || type === Constants.BOOLEAN_BUSINESS_TYPE || type === Constants.BOOLEAN_ENHANCED_BUSINESS_TYPE) {
386
- this.setProperty("type", type);
387
- }
388
-
389
- if (this.codeMirror) {
390
- this.codeMirror.options.returnType = type;
391
- }
392
- };
393
-
394
- ExpressionAdvanced.prototype.setCollection = function(isCollection) {
395
- this.setProperty("collection", isCollection, true);
396
- if (this.codeMirror) {
397
- this.codeMirror.options.collection = isCollection;
398
- }
399
- };
400
-
401
- /* end INTERFACE section */
402
-
403
- /* Public methods section */
404
-
405
- /**
406
- * validates the current value of the control.
407
- * @internal
408
- * @return {object} [oResult] validation object.
409
- */
410
- ExpressionAdvanced.prototype.validate = function() {
411
- return this.validateExpression();
412
- };
413
-
414
- ExpressionAdvanced.prototype.setFocusOnLoad = function(value) {
415
- this.dataModel.setProperty("/focus", value);
416
- this.setProperty("focusOnLoad", value, true);
417
- };
418
-
419
- ExpressionAdvanced.prototype.focus = function() {
420
- if (this.codeMirror) {
421
- var lastLine = this.codeMirror.getLine(this.codeMirror.lastLine());
422
- var cursorPos = lastLine.length;
423
- this.codeMirror.setCursor({
424
- line: this.codeMirror.lastLine(),
425
- ch: cursorPos
426
- });
427
- this.codeMirror.focus();
428
- }
429
- };
430
-
431
- ExpressionAdvanced.prototype.onAliasLinkPress = function(aliasName) {
432
- var expressionLanguage = sap.ui.getCore().byId(this.getExpressionLanguage());
433
- if (expressionLanguage) {
434
- expressionLanguage.onAliasLinkPress(aliasName);
435
- expressionLanguage.attachEvent("aliasDialogClosed", this.aliasClickCancel, this);
436
- }
437
- };
438
-
439
- ExpressionAdvanced.prototype.onCreateAliasLinkForText = function(text) {
440
- var expressionLanguage = sap.ui.getCore().byId(this.getExpressionLanguage());
441
- if (expressionLanguage) {
442
- expressionLanguage.attachEvent("aliasDialogClosed", this.replaceTextWithAlias, this);
443
- expressionLanguage.onCreateAliasLinkForText(text);
444
- }
445
- };
446
-
447
- ExpressionAdvanced.prototype.replaceTextWithAlias = function(oEvent) {
448
- if (oEvent.getParameter("isSave")) {
449
- this.codeMirror.replaceSelection(oEvent.getParameter("savedAliasName"));
450
- }
451
- };
452
-
453
- ExpressionAdvanced.prototype.aliasClickCancel = function(oEvent) {
454
- this.codeMirror.focus();
455
- this.codeMirror.execCommand("goLineEnd");
456
- this.fireDialog({
457
- dialogStatus: sap.rules.ui.ValueListDialogMode.Close
458
- });
459
- };
460
-
461
- ExpressionAdvanced.prototype.onAfterRendering = function() {
462
-
463
- this.timer = null;
464
- // needAutoComplete tells us whether an auto complete action is required.
465
- // we need it since we execute the popup opening in a delayed manner. sometimes it should not open (case 2):
466
- // case 1. press key -> ... -> delayed open of popup (need to open)
467
- // case 2. press key -> ... -> press Enter (to select form list) -> ... -> delayed open of popup (need not open)
468
- this.needAutoComplete = false;
469
- this.endCompletion = false;
470
- this._setCodeMirror();
471
- this._setEditorStyle();
472
- this._handleMousedown();
473
- this._handleChange();
474
- this._handleFocusLeave(); //blur
475
- this._handleEndCodeCompletion();
476
- this._handleKeyPress();
477
- this._handleEditableProperty();
478
- this._handleOnLoadValidation();
479
- this._refreshOnNavigationEnd();
480
- this._handleFocus();
481
- this._handleValueListSelect();
482
- this._handleCalendarChange();
483
-
484
- //bug RULES-4848\5031\5030 after choose value from auto complete - popover will not closed
485
- if (this.bFlagForEventListener) {
486
- this.bFlagForEventListener = false;
487
- this.fnMouseDownListsner = function(oEvent) {
488
- this.bFlagForChangeBeforeBlur = oEvent.target.className.indexOf("CodeMirror-hint") > -1;
489
- }.bind(this);
490
-
491
- this.fnBlurListsner = function(oEvent) {
492
- if (this.bFlagForChangeBeforeBlur) {
493
- this.bFlagForChangeBeforeBlur = false;
494
- oEvent.stopPropagation();
495
- this.codeMirror.focus();
496
- }
497
- }.bind(this);
498
-
499
- document.addEventListener("mousedown", this.fnMouseDownListsner, true);
500
- document.getElementById(this.getId()).addEventListener("blur", this.fnBlurListsner, true);
501
- }
502
-
503
- };
504
-
505
- // Event listerner for change date click event
506
- ExpressionAdvanced.prototype._handleCalendarChange = function() {
507
- var that = this;
508
- this.codeMirror.on('onChangeDate', function() {
509
- that._createCalendarDialog(that.codeMirror.getCursor());
510
- }.bind(this));
511
- };
512
-
513
- // Utility function to oprn calendate dialog
514
- ExpressionAdvanced.prototype._createCalendarDialog = function(curPos) {
515
- var bAddSpace = false;
516
- var that = this;
517
-
518
- var oCalendar = new sap.ui.unified.Calendar({
519
- width: "100%",
520
- select: this.handleCalendarSelect.bind(this)
521
- });
522
-
523
- this._oSelectNewDateDialog = new Dialog({
524
- title: this.oBundle.getText("calendarTitle"),
525
- content: [
526
- oCalendar
527
- ],
528
- beginButton: new Button({
529
- text: this.oBundle.getText("okBtn"),
530
- enabled: false,
531
- press: function() {
532
- var date = this.updateText(oCalendar);
533
- that._updateModal(false);
534
- that.setTextOnCursor(date, curPos, false, this._dateBusinessDataType, bAddSpace, false);
535
- that._oSelectNewDateDialog.close();
536
- that.focus(that.codeMirror);
537
- }.bind(this)
538
- }),
539
- endButton: new Button({
540
- text: this.oBundle.getText("clsBtn"),
541
- press: function() {
542
- that._updateModal(false);
543
- that._oSelectNewDateDialog.close();
544
- that.focus(that.codeMirror);
545
- }.bind(this)
546
- })
547
- });
548
-
549
- this._oSelectNewDateDialog.open();
550
-
551
- };
552
-
553
- // Utility function to update Modal Property of modal
554
- ExpressionAdvanced.prototype._updateModal = function(modalValue) {
555
- var pop = sap.ui.getCore().byId("popover");
556
- if (pop) {
557
- pop.setModal(modalValue);
558
- }
559
- };
560
-
561
- // Utility function to set calendar enabled property
562
- ExpressionAdvanced.prototype.handleCalendarSelect = function(oEvent) {
563
- var oCalendar = oEvent.getSource(),
564
- oSelectedDate = oCalendar.getSelectedDates()[0].getStartDate();
565
-
566
- if (oSelectedDate) {
567
- this._oSelectNewDateDialog.getBeginButton().setEnabled(true);
568
- }
569
- };
570
-
571
- // Utility function to format date
572
- ExpressionAdvanced.prototype.updateText = function(oCalendar) {
573
- var aSelectedDates = oCalendar.getSelectedDates();
574
- var oDate;
575
- if (aSelectedDates.length > 0) {
576
- oDate = aSelectedDates[0].getStartDate();
577
- return this.oFormatDate.format(oDate);
578
- }
579
- };
580
-
581
- ExpressionAdvanced.prototype._raiseError = function(sError) {
582
- //handling a scenario when the callback or the model are invalid
583
- Log.error(sError);
584
- var oBundle = sap.ui.getCore().getLibraryResourceBundle("sap.rules.ui.i18n");
585
- this.setValueStateText(oBundle.getText("valueHelpTechnicalError"));
586
- this._showPopUp();
587
- };
588
-
589
- /*
590
- * Invoke this function once user select on 'Select value from list' suggestion
591
- * This is listener to 'onValueListSelect' code mirror event/signal.
592
- */
593
- ExpressionAdvanced.prototype._handleValueListSelect = function() {
594
-
595
- this.codeMirror.on('onValueListSelect', function() {
596
- var suggestions = this.codeMirror.currentHintData.data.listCompletion;
597
- var valueHelpInfo = [];
598
- for (var sugg = 0; sugg < suggestions.length; sugg++) {
599
- if (suggestions[sugg].text === this._valueHelpSelectionText) {
600
- valueHelpInfo = suggestions[sugg].info;
601
- }
602
- }
603
- var expressionLanguage = sap.ui.getCore().byId(this.getExpressionLanguage());
604
- valueHelpInfo.expressionLanguage = expressionLanguage;
605
- var callback = expressionLanguage.getValueHelpCallback();
606
- this.oTextArea.setValueState("None");
607
- this.oTextArea.setValueStateText("");
608
- this.setValueStateText("");
609
- jQuery(this.codeMirror.getWrapperElement()).removeClass('sapMInputBaseStateInner sapMInputBaseErrorInner sapMInputBaseContentWrapper sapMInputBaseContentWrapperState sapMInputBaseContentWrapperError');
610
- if ((typeof callback) !== "function" && valueHelpInfo.metadata.hasOwnProperty(this._hasValueSource) && valueHelpInfo.metadata.HasValueSource ===
611
- true) {
612
- this._createCpValueHelp(valueHelpInfo, this.codeMirror.getCursor(), false);
613
- } else {
614
- if ((typeof callback) !== "function") {
615
- this._raiseError("value help callback is not set or is not a function");
616
- } else {
617
- // enrich the valueHelpInfo with the valueHelp model
618
- callback.call(this, valueHelpInfo);
619
- // create provider
620
- var oModel = valueHelpInfo[0].model;
621
- if (!(oModel instanceof sap.ui.model.odata.v2.ODataModel)) {
622
- this._raiseError("value help model is not an oData V2 model");
623
- } else if (oModel.isMetadataLoadingFailed()) {
624
- this._raiseError("model metadata loading has failed in the past");
625
- } else if (!(oModel.getMetaModel().oModel)) {
626
- oModel.attachMetadataLoaded(function() {
627
- this._createValueHelpProvider(valueHelpInfo[0]);
628
- }.bind(this));
629
- oModel.attachMetadataFailed(function() {
630
- this._raiseError("attached model metadata failed");
631
- }.bind(this));
632
- } else {
633
- this._createValueHelpProvider(valueHelpInfo[0]);
634
- }
635
- }
636
- }
637
- }.bind(this));
638
- };
639
-
640
- ExpressionAdvanced.prototype._createValueHelpProvider = function(valueHelpInfo, bReplaceWord) {
641
-
642
- var oModel = valueHelpInfo.model;
643
- this.oMetadataAnalyzer = new sap.ui.comp.odata.MetadataAnalyser(oModel);
644
- var sAnnotationPath = valueHelpInfo.metadata.propertyPath;
645
- var oValueListAnnotation = this.oMetadataAnalyzer.getValueListAnnotation(sAnnotationPath);
646
- if (!oValueListAnnotation.primaryValueListAnnotation) {
647
- this._raiseError("proprety path is wrong");
648
- return;
649
- }
650
- var tokens = this.getExpressionTokens();
651
- var bAddSpace = false;
652
- if (tokens.length > 0) {
653
- bAddSpace = (tokens[tokens.length - 1].tokenType !== "whitespace");
654
- }
655
-
656
- if (this.oValueHelpDialogProvider) {
657
- this.oValueHelpDialogProvider.destroy();
658
- }
659
-
660
- this.oValueHelpDialogProvider = new ValueHelpProvider({
661
- annotation: oValueListAnnotation.primaryValueListAnnotation,
662
- additionalAnnotations: oValueListAnnotation.additionalAnnotations,
663
- control: this,
664
- model: oModel,
665
- preventInitialDataFetchInValueHelpDialog: false,
666
- supportMultiSelect: false,
667
- supportRanges: false,
668
- takeOverInputValue: false,
669
- fieldName: oValueListAnnotation.primaryValueListAnnotation.valueListTitle,
670
- title: oValueListAnnotation.primaryValueListAnnotation.valueListTitle,
671
- cursorPosition: this.codeMirror.getCursor(),
672
- bReplaceWord: bReplaceWord,
673
- businessDataType: valueHelpInfo.metadata.businessDataType,
674
- bAddSpace: bAddSpace
675
-
676
- });
677
-
678
- // open dialog
679
- this.fireValueHelpRequest({
680
- fromSuggestions: false
681
- });
682
-
683
- };
684
-
685
- ExpressionAdvanced.prototype._createCpValueHelp = function(valueHelpInfo, curPos, bReplaceWord, bValuehelpLinkPress) {
686
- var businessDataType = valueHelpInfo.metadata.businessDataType;
687
- var tokens = this.getExpressionTokens();
688
- var bAddSpace = false;
689
- var pop = sap.ui.getCore().byId("popover");
690
- if (pop) {
691
- pop.setModal(true);
692
- }
693
- if (tokens.length > 0) {
694
- bAddSpace = (tokens[tokens.length - 1].tokenType !== "whitespace");
695
- }
696
-
697
- if (this.oDialog) {
698
- this.oDialog.destroy();
699
- }
700
- var basePath = sap.ui.getCore().byId(this.getExpressionLanguage()).getModel().sServiceUrl;
701
- this._createDialog(basePath, valueHelpInfo, curPos, businessDataType, bAddSpace, bReplaceWord, bValuehelpLinkPress);
702
- };
703
-
704
- /*
705
- * Creates the necessary control for the value Help Dialog.
706
- *
707
- */
708
- ExpressionAdvanced.prototype._createDialog = function(basePath, valueHelpInfo, curPos, businessDataType, bAddSpace, bReplaceWord,
709
- bValuehelpLinkPress) {
710
- this._createValueHelpDialog(basePath, valueHelpInfo, curPos, businessDataType, bAddSpace, bReplaceWord, bValuehelpLinkPress);
711
- this._createSmartFilterBar(basePath, valueHelpInfo);
712
- this.oValueHelpDialog.setFilterBar(this.oFilterBar);
713
- this.oValueHelpDialog.open();
714
- this.oValueHelpDialog.getTable().setBusy(true);
715
- };
716
-
717
- /*
718
- * Creates the Value Help Dialog.
719
- */
720
-
721
- ExpressionAdvanced.prototype._createValueHelpDialog = function(basePath, valueHelpInfo, curPos, businessDataType, bAddSpace,
722
- bReplaceWord, bValuehelpLinkPress) {
723
- var that = this;
724
- var expressionData = valueHelpInfo.expressionLanguage.getModel();
725
- var attributePath = "Attributes(Id='"+ valueHelpInfo.metadata.attributeId + "',VocabularyId='" + valueHelpInfo.metadata.vocabularyId + "',DataObjectId='" + valueHelpInfo.metadata.dataObjectId + "')";
726
- if(attributePath.includes(":")) {
727
- attributePath = attributePath = attributePath.replace(":","%3A");
728
- }
729
- this.attributeName = expressionData.oData[attributePath].Name;
730
- sap.ui.core.BusyIndicator.show(0);
731
- this.oValueHelpDialog = new sap.ui.comp.valuehelpdialog.ValueHelpDialog({
732
- supportMultiselect : false,
733
- supportRanges : false,
734
- horizontalScrolling : false,
735
- title : that.attributeName,
736
- resizable : false,
737
- beforeOpen : function() {
738
- that._bindTable(basePath, valueHelpInfo);
739
- },
740
- ok : function(oEvt) {
741
- var oSelRow = oEvt.getParameter("tokens")[0].data("row");
742
- var value = oSelRow.Value;
743
- if (businessDataType === that._dateBusinessDataType) {
744
- value = that._formatDate(value);
745
- }
746
- that.setTextOnCursor(value, curPos, bReplaceWord, businessDataType, bAddSpace, bValuehelpLinkPress);
747
- that._updateModal(false);
748
- that.oValueHelpDialog.close();
749
- that.focus(that.codeMirror);
750
-
751
- },
752
- cancel : function() {
753
- that._updateModal(false);
754
- that.oValueHelpDialog.close();
755
- that.focus(that.codeMirror);
756
-
757
- },
758
- afterClose : function() {
759
- that._updateModal(false);
760
- that.oValueHelpDialog.destroy();
761
- that.focus(that.codeMirror);
762
- that.oFilterBar.destroy();
763
- sap.ui.core.BusyIndicator.hide();
764
- }
765
- });
766
- };
767
-
768
- /*
769
- * Utility function to format Date.
770
- */
771
- ExpressionAdvanced.prototype._formatDate = function(value) {
772
- return this.oFormatDate.format(this.oFormatDate.parse(value));
773
- };
774
-
775
- /*
776
- * Creates the necessary control os SmartFilterBar for the ValueHelp Dialog.
777
- */
778
- ExpressionAdvanced.prototype._createSmartFilterBar = function(basePath, valueHelpInfo) {
779
- var that = this;
780
- this.oFilterBar = new sap.ui.comp.smartfilterbar.SmartFilterBar({
781
- entitySet : valueHelpInfo.metadata.entitySet,
782
- enableBasicSearch : true,
783
- advancedMode : true,
784
- filterBarExpanded: true,
785
- search : function() {
786
- that.onSearch(basePath, valueHelpInfo);
787
-
788
- },
789
- filterChange: function(oEvent) {
790
- that.setValueStateFilter(oEvent);
791
- },
792
- controlConfiguration : [ that._createControlConfiguration() ]
793
- });
794
- var oModel = new sap.ui.model.odata.v2.ODataModel(basePath);
795
- this.oFilterBar.setModel(oModel);
796
- };
797
-
798
- /*
799
- * Creating the Control Configuration for the smartFilter of the valueHelp Dialog.
800
- */
801
- ExpressionAdvanced.prototype._createControlConfiguration = function() {
802
- var aControlConfiguration = [ new sap.ui.comp.smartfilterbar.ControlConfiguration({
803
- hasValueHelpDialog : true,
804
- key : "Value",
805
- label : "Value",
806
- visibleInAdvancedArea : true,
807
- width : "100px",
808
- index : 1
809
-
810
- }), new sap.ui.comp.smartfilterbar.ControlConfiguration({
811
- hasValueHelpDialog : true,
812
- key : "Description",
813
- label : "Description",
814
- visibleInAdvancedArea : true,
815
- width : "100px",
816
- index : 2
817
-
818
- }), new sap.ui.comp.smartfilterbar.ControlConfiguration({
819
- hasValueHelpDialog : true,
820
- key : "VocabularyId",
821
- label : "VocabularyId",
822
- width : "100px",
823
- visible : false,
824
- index : 3
825
-
826
- }), new sap.ui.comp.smartfilterbar.ControlConfiguration({
827
- hasValueHelpDialog : true,
828
- key : "DataObjectId",
829
- label : "DataObjectId",
830
- visible : false,
831
- width : "100px",
832
- groupId : "abc",
833
- index : 4
834
-
835
- }), new sap.ui.comp.smartfilterbar.ControlConfiguration({
836
- hasValueHelpDialog : true,
837
- key : "AttributeId",
838
- label : "AttributeId",
839
- visible : false,
840
- width : "100px",
841
- index : 5
842
-
843
- }),
844
- new sap.ui.comp.smartfilterbar.ControlConfiguration({
845
- hasValueHelpDialog : true,
846
- key : "Version",
847
- label : "Version",
848
- visible : false,
849
- width : "100px",
850
- index : 6
851
-
852
- })];
853
- return aControlConfiguration;
854
- };
855
-
856
- /*
857
- * Called when the search is triggered in SmartFilter.
858
- */
859
- ExpressionAdvanced.prototype.onSearch = function(basePath, valueHelpInfo) {
860
- this.oValueHelpDialog.getTable().setBusy(true);
861
- this._unBindTable();
862
- this._bindTable(basePath, valueHelpInfo);
863
- };
864
-
865
- /*
866
- * Binds the table taking current filters parameters into account.
867
- */
868
- ExpressionAdvanced.prototype._bindTable = function(basePath, valueHelpInfo) {
869
- var serviceUrl = valueHelpInfo.metadata.serviceURL;
870
- var aFilterParams = this._fetchFilterParams(valueHelpInfo);
871
- var mEntities = {
872
- valueHelp : {
873
- collection : serviceUrl,
874
- properties : [ this._propertyValue, this._propertyDescription ]
875
- }
876
- };
877
-
878
- var oTable = this.oValueHelpDialog.getTable();
879
- oTable.setThreshold(10);
880
-
881
- for (var i = 0; i < mEntities.valueHelp.properties.length; i++) {
882
- this._addValueHelpColumn(mEntities.valueHelp.properties[i], oTable);
883
- }
884
-
885
- var oModel = new sap.ui.model.odata.v2.ODataModel(basePath);
886
- oTable.setModel(oModel);
887
- oTable.bindRows(mEntities.valueHelp.collection, null, aFilterParams);
888
- oTable.getBinding("rows").attachDataReceived(this._handleRowsDataReceived, this);
889
- };
890
-
891
- //handles the Busy State of the busy state for the data recieved.
892
- ExpressionAdvanced.prototype._handleRowsDataReceived = function(oEvent) {
893
- var that = this;
894
- var data = oEvent.getParameter("data");
895
- if (jQuery.isEmptyObject(data) || (data && data.results && data.results.length === 0)) {
896
- this.oValueHelpDialog.getTable().setNoData(that.oBundle.getText("no_data"));
897
- } else {
898
- this.oValueHelpDialog.getTable().setNoData(that.oBundle.getText("searching"));
899
- }
900
- this.oValueHelpDialog.getTable().setBusy(false);
901
- };
902
-
903
- // Utility function to create columns for the table.
904
- ExpressionAdvanced.prototype._addValueHelpColumn = function(oColumName, oTable) {
905
- var oColumn = new sap.ui.table.Column().setLabel(new sap.m.Label({
906
- text : oColumName
907
- }));
908
- if (oColumName === this._propertyValue) {
909
- oColumn.setSortProperty(oColumName);
910
- }
911
- oTable.addColumn(oColumn.setTemplate(new sap.m.Text().bindProperty("text", oColumName)));
912
- };
913
-
914
- /*
915
- * unBind the table Rows.
916
- */
917
- ExpressionAdvanced.prototype._unBindTable = function() {
918
- var oTable = this.oValueHelpDialog.getTable();
919
- oTable.destroyColumns();
920
- oTable.unbindRows();
921
-
922
- };
923
-
924
-
925
- /*
926
- * fetch the latest filter parmas depending on the filter or the search param set.
927
- */
928
- ExpressionAdvanced.prototype._fetchFilterParams = function(valueHelpInfo) {
929
- var that = this;
930
- var aSearchParams = [];
931
- var aFilterParams = [ new sap.ui.model.Filter("AttributeId", sap.ui.model.FilterOperator.EQ, valueHelpInfo.metadata.attributeId),
932
- new sap.ui.model.Filter("DataObjectId", sap.ui.model.FilterOperator.EQ, valueHelpInfo.metadata.dataObjectId),
933
- new sap.ui.model.Filter("VocabularyId", sap.ui.model.FilterOperator.EQ, valueHelpInfo.metadata.vocabularyId) ];
934
-
935
- var aFilters = this.oFilterBar.getFilters();
936
- var searchParam = this.oFilterBar.getParameters();
937
- //When both search and filter is selected
938
- if (!jQuery.isEmptyObject(searchParam) && aFilters && aFilters.length > 0) {
939
- searchParam = this.oFilterBar.getParameters().custom.search;
940
- aSearchParams = this._getSearchFilters(searchParam);
941
- aFilters = that._formatFilterParams(aFilters);
942
- aFilterParams.push(new sap.ui.model.Filter({
943
- filters : [ new sap.ui.model.Filter(aFilters), new sap.ui.model.Filter(aSearchParams) ],
944
- and : true
945
- }));
946
- } else if (!jQuery.isEmptyObject(searchParam)) {
947
- //when only Search is selected.
948
- searchParam = this.oFilterBar.getParameters().custom.search;
949
- aSearchParams = this._getSearchFilters(searchParam);
950
- aFilterParams.push(aSearchParams);
951
- } else if (aFilters && aFilters.length > 0) {
952
- //When only filters is selected.
953
- aFilters = that._formatFilterParams(aFilters);
954
- aFilterParams.push(aFilters[0]);
955
- }
956
- return aFilterParams;
957
- };
958
-
959
- /*
960
- * format the filterParams to support Contains and Between.
961
- */
962
- ExpressionAdvanced.prototype._formatFilterParams = function(aFilters) {
963
- var that = this;
964
- if (aFilters[0] && aFilters.length === 1 && aFilters[0].aFilters[0] && aFilters[0].aFilters[0].sOperator) {
965
- aFilters = that._formatSingleFilter(aFilters);
966
- } else if (aFilters[0] && aFilters[0].aFilters[0] && aFilters[0].aFilters[0].aFilters[0] && aFilters[0].aFilters[0].aFilters[0].aFilters && aFilters[0].aFilters[1].aFilters[0].aFilters) {
967
- aFilters = that._formatMultiFilter(aFilters, 0, true);
968
- aFilters = that._formatMultiFilter(aFilters, 1, true);
969
-
970
- } else if (aFilters[0] && aFilters[0].aFilters[0] && aFilters[0].aFilters[1] && aFilters[0].aFilters[0].aFilters[0] && aFilters[0].aFilters[0].aFilters[0].aFilters && aFilters[0].aFilters[1].aFilters) {
971
- aFilters = that._formatMultiFilter(aFilters, 0, true);
972
- aFilters = that._formatMultiFilter(aFilters, 1, false);
973
-
974
- } else if (aFilters[0] && aFilters[0].aFilters[0] && aFilters[0].aFilters[1] && aFilters[0].aFilters[1].aFilters[0] && aFilters[0].aFilters[0].aFilters && aFilters[0].aFilters[1].aFilters[0].aFilters) {
975
- aFilters = that._formatMultiFilter(aFilters, 0, false);
976
- aFilters = that._formatMultiFilter(aFilters, 1, true);
977
-
978
- } else if (aFilters[0] && aFilters[0].aFilters[0] && aFilters[0].aFilters[1] && aFilters[0].aFilters[0].aFilters && aFilters[0].aFilters[1].aFilters) {
979
- aFilters = that._formatMultiFilter(aFilters, 0, false);
980
- aFilters = that._formatMultiFilter(aFilters, 1, false);
981
-
982
- }
983
-
984
- return aFilters;
985
- };
986
-
987
- ExpressionAdvanced.prototype._formatSingleFilter = function(aFilters) {
988
- var that = this;
989
- var _valueField = null;
990
-
991
- for (var iterator = 0; iterator < aFilters[0].aFilters.length; iterator++) {
992
- if (aFilters[0].aFilters[iterator].sOperator === "Contains") {
993
- aFilters[0].aFilters[iterator].sOperator = "EQ";
994
- } else if (aFilters[0].aFilters[iterator].sOperator === "BT") {
995
-
996
- var convertedFilterParam = that._manageParam(aFilters[0].aFilters[iterator].sPath,aFilters[0].aFilters[iterator].sOperator,
997
- aFilters[0].aFilters[iterator].oValue1, aFilters[0].aFilters[iterator].oValue2);
998
- delete aFilters[0].aFilters[iterator];
999
- aFilters[0].aFilters[iterator] = convertedFilterParam;
1000
- } else if (aFilters[0].aFilters[iterator].sOperator === "StartsWith") {
1001
- _valueField = (aFilters[0].aFilters[iterator].sPath === this._propertyValue) ? this._valueFieldValue : this._valueFieldDescription;
1002
- _valueField.setValueState("Error");
1003
- _valueField.setValueStateText(aFilters[0].aFilters[iterator].sOperator + " operator not supported");
1004
- } else if (aFilters[0].aFilters[iterator].sOperator === "EndsWith") {
1005
- _valueField = (aFilters[0].aFilters[iterator].sPath === this._propertyValue) ? this._valueFieldValue : this._valueFieldDescription;
1006
- _valueField.setValueState("Error");
1007
- _valueField.setValueStateText(aFilters[0].aFilters[iterator].sOperator + " operator not supported");
1008
- }
1009
-
1010
- }
1011
- return aFilters;
1012
-
1013
- };
1014
- ExpressionAdvanced.prototype._formatMultiFilter = function(aFilters, index, bMultifilter) {
1015
- var that = this;
1016
- var _valueField = null;
1017
- var aComputeFilterParma = [];
1018
- if (bMultifilter) {
1019
- aComputeFilterParma = aFilters[0].aFilters[index].aFilters[0].aFilters;
1020
- } else {
1021
- aComputeFilterParma = aFilters[0].aFilters[index].aFilters;
1022
- }
1023
- for (var iterator = 0; iterator < aComputeFilterParma.length; iterator++) {
1024
- if (aComputeFilterParma[iterator].sOperator === "Contains") {
1025
- aComputeFilterParma[iterator].sOperator = "EQ";
1026
- } else if (aComputeFilterParma[iterator].sOperator === "BT") {
1027
-
1028
- var convertedFilterParam = that._manageParam(aComputeFilterParma[iterator].sPath,aComputeFilterParma[iterator].sOperator,
1029
- aComputeFilterParma[iterator].oValue1, aComputeFilterParma[iterator].oValue2);
1030
- delete aComputeFilterParma[iterator];
1031
- aComputeFilterParma[iterator] = convertedFilterParam;
1032
-
1033
- } else if (aComputeFilterParma[iterator].sOperator === "StartsWith") {
1034
- _valueField = (aComputeFilterParma[iterator].sPath === this._propertyValue) ? this._valueFieldValue : this._valueFieldDescription;
1035
- _valueField.setValueState("Error");
1036
- _valueField.setValueStateText(aComputeFilterParma[iterator].sOperator + " operator not supported");
1037
- } else if (aComputeFilterParma[iterator].sOperator === "EndsWith") {
1038
- _valueField = (aComputeFilterParma[iterator].sPath === this._propertyValue) ? this._valueFieldValue : this._valueFieldDescription;
1039
- _valueField.setValueState("Error");
1040
- _valueField.setValueStateText(aComputeFilterParma[iterator].sOperator + " operator not supported");
1041
- }
1042
- }
1043
- return aFilters;
1044
- };
1045
-
1046
- /*
1047
- * Converts the Between Operator to Less than and Equal to Operator.
1048
- */
1049
- ExpressionAdvanced.prototype._manageParam = function(sPath, operator, value1, value2) {
1050
- var filterParam = [];
1051
- if (value1 && value2) {
1052
- filterParam = new sap.ui.model.Filter({
1053
- filters : [ new sap.ui.model.Filter(sPath, sap.ui.model.FilterOperator.GT, value1),
1054
- new sap.ui.model.Filter(sPath, sap.ui.model.FilterOperator.LT, value2) ],
1055
- and : true
1056
- });
1057
- }
1058
- return filterParam;
1059
- };
1060
-
1061
- // Utility function to form the search filter params.
1062
- ExpressionAdvanced.prototype._getSearchFilters = function(searchParam) {
1063
- return new sap.ui.model.Filter({
1064
- filters : [ new sap.ui.model.Filter(this._propertyValue, sap.ui.model.FilterOperator.EQ, searchParam),
1065
- new sap.ui.model.Filter(this._propertyDescription, sap.ui.model.FilterOperator.EQ, searchParam) ],
1066
- and : false
1067
- });
1068
- };
1069
-
1070
- ExpressionAdvanced.prototype.setValueStateFilter = function(oEvent) {
1071
- var sId = oEvent.getSource().sId;
1072
- this._valueFieldValue = sap.ui.getCore().byId(sId + "-filterItemControlA_-Value");
1073
- if (this._valueFieldValue) {
1074
- this._valueFieldValue.setValueState("None");
1075
- this._valueFieldValue.setValueStateText("");
1076
- }
1077
- this._valueFieldDescription = sap.ui.getCore().byId(sId + "-filterItemControlA_-Description");
1078
- if (this._valueFieldDescription) {
1079
- this._valueFieldDescription.setValueState("None");
1080
- this._valueFieldDescription.setValueStateText("");
1081
- }
1082
- };
1083
-
1084
- /*
1085
- * Callback fucntion event which is fired once the user clicked on 'ValueHelp' token link. onValueHelpLinkPress : create code mirror
1086
- * search cursor based on the 'ValueList' token which has been clicked. Create Select Dialog display all 'ValueList' suggestions. @param
1087
- * valueHelpText : 'ValueHelp' token text value. @param valueHelpId : ValueHelp Id of the token.
1088
- */
1089
- ExpressionAdvanced.prototype.onValueHelpLinkPress = function(valueHelpText, valueHelpId) {
1090
- if (!this.getEditable()) {
1091
- return;
1092
- }
1093
- var expressionLanguage = sap.ui.getCore().byId(this.getExpressionLanguage());
1094
- var callback = expressionLanguage.getValueHelpCallback();
1095
-
1096
- //build valueHelpInfo
1097
- var tokens = this.getExpressionTokens();
1098
- var i;
1099
- var valueHelpInfo;
1100
- var line = this.codeMirror.getCursor().line;
1101
- var valueListPosition;
1102
- for (i = 0; i < tokens.length; i++) {
1103
- if (tokens[i].tokenType === 'valueList' && tokens[i].info && tokens[i].info.id === valueHelpId &&
1104
- tokens[i].token === valueHelpText) {
1105
- valueHelpInfo = [tokens[i].info];
1106
- valueListPosition = tokens[i].end;
1107
- break;
1108
- }
1109
- }
1110
- var curPostion = {};
1111
- curPostion.ch = valueListPosition;
1112
- curPostion.line = line;
1113
-
1114
- if ((typeof callback) === "function") {
1115
-
1116
- callback.call(this, valueHelpInfo);
1117
- var oModel = valueHelpInfo[0].model;
1118
- if (!oModel.getMetaModel().oModel) {
1119
- oModel.attachMetadataLoaded(function() {
1120
- this._createValueHelpProvider(valueHelpInfo[0], true);
1121
- }.bind(this));
1122
- } else {
1123
- this._createValueHelpProvider(valueHelpInfo[0], true);
1124
- }
1125
- } else if (valueHelpInfo && valueHelpInfo[0].metadata.hasOwnProperty(this._hasValueSource) && valueHelpInfo[0].metadata.HasValueSource ===
1126
- true) {
1127
- valueHelpInfo[0].expressionLanguage = expressionLanguage;
1128
- this._createCpValueHelp(valueHelpInfo[0], curPostion, true, true);
1129
- }
1130
- };
1131
-
1132
- ExpressionAdvanced.prototype._createSearchCursor = function(valueHelpText) {
1133
- var cm = this.codeMirror;
1134
- cm.getCursor().ch = cm.getCursor().ch + valueHelpText.length;
1135
- var cursor = cm.getSearchCursor(valueHelpText, cm.getCursor(), typeof valueHelpText == "string" && valueHelpText == valueHelpText.toLowerCase());
1136
- return cursor;
1137
- };
1138
-
1139
- ExpressionAdvanced.prototype.setTextOnCursor = function(sValue, cursorPosition, bReplaceWord, businessDataType, bAddSpace,
1140
- bValuehelpLinkPress) {
1141
-
1142
- function getNextLine(currentLine, arrLines) {
1143
- // this function skips empty lines
1144
- var nextLine = currentLine + 1;
1145
- for (var j = nextLine; j < arrLines.length; j++) {
1146
- if (arrLines[j].length === 0) {
1147
- nextLine++;
1148
- } else {
1149
- break;
1150
- }
1151
- }
1152
- return nextLine;
1153
- }
1154
-
1155
- var TYPE_STRING = "String",
1156
- TYPE_DATE = "Date",
1157
- TYPE_TIMESTAMP = "Timestamp",
1158
- TYPE_TIME = "Time";
1159
-
1160
- // inserting a new selection
1161
- var cursorPos;
1162
- var sFormatedValue = ((businessDataType === TYPE_STRING) ||
1163
- (businessDataType === TYPE_DATE) ||
1164
- (businessDataType === TYPE_TIMESTAMP) ||
1165
- (businessDataType === TYPE_TIME)) ? "'" + sValue + "'" : sValue;
1166
-
1167
- var tokens = this.getExpressionTokens();
1168
- var lines = this.getValue().split("\n");
1169
- var line = -1;
1170
- var oToken = {
1171
- start: {
1172
- line: cursorPosition.line,
1173
- ch: cursorPosition.ch
1174
- },
1175
- end: {
1176
- line: cursorPosition.line,
1177
- ch: cursorPosition.ch
1178
- }
1179
- };
1180
- for (var i = 0; i < tokens.length; i++) {
1181
- line = (tokens[i].start === 0) ? getNextLine(line, lines) : line;
1182
- if (line === cursorPosition.line && (tokens[i].end > cursorPosition.ch) || (tokens[i].end >= cursorPosition.ch && bValuehelpLinkPress)) {
1183
- oToken.start.ch = tokens[i].start;
1184
- oToken.end.ch = tokens[i].end;
1185
- bReplaceWord = true;
1186
- break;
1187
- }
1188
- }
1189
- if (bReplaceWord) {
1190
- this.codeMirror.replaceRange(sFormatedValue, oToken.start, oToken.end); // replace the selection
1191
- cursorPos = this.codeMirror.findPosH(oToken.start, sFormatedValue.length, "char", true);
1192
- this.codeMirror.setCursor(cursorPos); // set the cursor at the end of the word
1193
- } else {
1194
- sFormatedValue = bAddSpace ? " " + sFormatedValue : sFormatedValue;
1195
- this.codeMirror.replaceRange(sFormatedValue, cursorPosition); // insert the selection
1196
- cursorPos = this.codeMirror.findPosH(cursorPosition, sFormatedValue.length, "char", true);
1197
- this.codeMirror.setCursor(cursorPos); // set the cursor past the new selection
1198
- }
1199
- var oExpressionLanguage = sap.ui.getCore().byId(this.getExpressionLanguage());
1200
- this.getFormattingTokens(oExpressionLanguage);
1201
- this.ValueHelpRequested = false;
1202
- };
1203
-
1204
- ExpressionAdvanced.prototype._setCodeMirror = function() {
1205
- var editable = this.getEditable();
1206
- var attributeInfo;
1207
- if ("getAttributeInfo" in this && this.getAttributeInfo()) {
1208
- attributeInfo = this.getAttributeInfo();
1209
- }
1210
- var expressionLanguage = sap.ui.getCore().byId(this.getExpressionLanguage());
1211
- var valueListAttribute;
1212
- if (attributeInfo) {
1213
- valueListAttribute = expressionLanguage.getValueListAttribute(attributeInfo);
1214
- }
1215
-
1216
- function autoComplete(cm, commandName, timeout) {
1217
- var oAdvancedExpressionEditor = cm.options.expressionEditor;
1218
- if ((oAdvancedExpressionEditor.getEditable() !== false) && sap.ui.getCore().byId(oAdvancedExpressionEditor.getExpressionLanguage())) {
1219
- window.clearTimeout(oAdvancedExpressionEditor.timer);
1220
- oAdvancedExpressionEditor.timer = window.setTimeout(function() {
1221
- cm.execCommand(commandName);
1222
- }, timeout);
1223
- return window.CodeMirror.Pass; // tell CodeMirror we didn't handle the key
1224
- }
1225
- return null;
1226
- }
1227
-
1228
- function ordinaryKeyCallback(cm) {
1229
- var oAdvancedExpressionEditor = cm.options.expressionEditor;
1230
- if (oAdvancedExpressionEditor.getEditable() !== false) {
1231
- window.clearTimeout(oAdvancedExpressionEditor.timer);
1232
- oAdvancedExpressionEditor.needAutoComplete = true;
1233
- oAdvancedExpressionEditor.timer = window.setTimeout(function() {
1234
- if (oAdvancedExpressionEditor.needAutoComplete && sap.ui.getCore().byId(oAdvancedExpressionEditor.getExpressionLanguage())) {
1235
- cm.execCommand("autocomplete");
1236
- }
1237
- }, 500);
1238
- return window.CodeMirror.Pass; // tell CodeMirror we didn't handle the key
1239
- }
1240
- return null;
1241
- }
1242
-
1243
- function enterKeyCallback(cm) {
1244
- return autoComplete(cm, "enterAutocomplete", 500);
1245
- }
1246
-
1247
- function colonKeyCallback(cm) {
1248
- return autoComplete(cm, "colonAutocomplete", 500);
1249
- }
1250
-
1251
- function ctrlSpaceKeysCallback(cm) {
1252
- autoComplete(cm, "autocomplete", 0);
1253
- }
1254
-
1255
- /*
1256
- * SPACE is use for both opening the hints, and closing them if writing a non-existent expression.
1257
- * As such, it is separated from the common ordinaryKeyCallback() key handling.
1258
- * If not so, it alternately opens the hints every 2nd press. Example flow:
1259
- * press SPACE:
1260
- * 1. ordinaryKeyCallback() sets the timeout
1261
- * 2. ordinaryKeyCallback() delayed opening of hints
1262
- * press SPACE (not in one of the hints):
1263
- * 1. ordinaryKeyCallback() sets the timeout
1264
- * 2. _handleEndCodeCompletion sets needAutoComplete as false (event coming from CodeMirror hints)
1265
- * 3. ordinaryKeyCallback() delayed opening of hints - not opening the hints as needAutoComplete is false
1266
- * **/
1267
- function spaceKeyCallback(cm) {
1268
- return autoComplete(cm, "autocomplete", 500);
1269
- }
1270
-
1271
- function valueHelpCallback(cm) {
1272
- var oAdvancedExpressionEditor = cm.options.expressionEditor;
1273
- var input = cm.getRange({
1274
- line: 0,
1275
- ch: 0
1276
- }, cm.getCursor());
1277
- if (cm.options.headerValue) {
1278
- var prefix = cm.options.headerValue + " ";
1279
- if (cm.options.fixedOperator) {
1280
- prefix = prefix + cm.options.fixedOperator + " ";
1281
- }
1282
- input = prefix + input;
1283
- }
1284
- var autoSuggestions = cm.options.relDelegate.getSuggestions(
1285
- input,
1286
- cm.options.returnType,
1287
- cm.options.collection);
1288
- var suggestions;
1289
- if (autoSuggestions && autoSuggestions.hasOwnProperty("suggs") && autoSuggestions.suggs.length > 0) {
1290
- suggestions = autoSuggestions.suggs;
1291
- for (var i = 0; i < suggestions.length; i++) {
1292
- if (suggestions[i].tokenType === 'valueList' && suggestions[i].info.metadata.hasOwnProperty(oAdvancedExpressionEditor._hasValueSource)) {
1293
- oAdvancedExpressionEditor._createCpValueHelp(suggestions[i].info, cm.getCursor(), false);
1294
- }
1295
- }
1296
- }
1297
- }
1298
-
1299
- this.keyMap = {
1300
- "Tab": false,
1301
- "Shift-Tab": false,
1302
- "Ctrl-Space": ctrlSpaceKeysCallback,
1303
- "Backspace": ordinaryKeyCallback,
1304
- "Enter": enterKeyCallback,
1305
- "':'": colonKeyCallback,
1306
- "'+'": ordinaryKeyCallback,
1307
- "'-'": ordinaryKeyCallback,
1308
- "'*'": ordinaryKeyCallback,
1309
- "'/'": ordinaryKeyCallback,
1310
- "'_'": ordinaryKeyCallback,
1311
- "'o'": ordinaryKeyCallback,
1312
- "'q'": ordinaryKeyCallback,
1313
- "'w'": ordinaryKeyCallback,
1314
- "'e'": ordinaryKeyCallback,
1315
- "'r'": ordinaryKeyCallback,
1316
- "'t'": ordinaryKeyCallback,
1317
- "'y'": ordinaryKeyCallback,
1318
- "'u'": ordinaryKeyCallback,
1319
- "'i'": ordinaryKeyCallback,
1320
- "'p'": ordinaryKeyCallback,
1321
- "'.'": ordinaryKeyCallback,
1322
- "'a'": ordinaryKeyCallback,
1323
- "'s'": ordinaryKeyCallback,
1324
- "'d'": ordinaryKeyCallback,
1325
- "'f'": ordinaryKeyCallback,
1326
- "'g'": ordinaryKeyCallback,
1327
- "'h'": ordinaryKeyCallback,
1328
- "'j'": ordinaryKeyCallback,
1329
- "'k'": ordinaryKeyCallback,
1330
- "'l'": ordinaryKeyCallback,
1331
- "'z'": ordinaryKeyCallback,
1332
- "'x'": ordinaryKeyCallback,
1333
- "'c'": ordinaryKeyCallback,
1334
- "'v'": ordinaryKeyCallback,
1335
- "'b'": ordinaryKeyCallback,
1336
- "'n'": ordinaryKeyCallback,
1337
- "'m'": ordinaryKeyCallback,
1338
- "'O'": ordinaryKeyCallback,
1339
- "'Q'": ordinaryKeyCallback,
1340
- "'W'": ordinaryKeyCallback,
1341
- "'E'": ordinaryKeyCallback,
1342
- "'R'": ordinaryKeyCallback,
1343
- "'T'": ordinaryKeyCallback,
1344
- "'Y'": ordinaryKeyCallback,
1345
- "'U'": ordinaryKeyCallback,
1346
- "'I'": ordinaryKeyCallback,
1347
- "'P'": ordinaryKeyCallback,
1348
- "'A'": ordinaryKeyCallback,
1349
- "'S'": ordinaryKeyCallback,
1350
- "'D'": ordinaryKeyCallback,
1351
- "'F'": ordinaryKeyCallback,
1352
- "'G'": ordinaryKeyCallback,
1353
- "'H'": ordinaryKeyCallback,
1354
- "'J'": ordinaryKeyCallback,
1355
- "'K'": ordinaryKeyCallback,
1356
- "'L'": ordinaryKeyCallback,
1357
- "'Z'": ordinaryKeyCallback,
1358
- "'X'": ordinaryKeyCallback,
1359
- "'C'": ordinaryKeyCallback,
1360
- "'V'": ordinaryKeyCallback,
1361
- "'B'": ordinaryKeyCallback,
1362
- "'N'": ordinaryKeyCallback,
1363
- "'M'": ordinaryKeyCallback,
1364
- "'0'": false,
1365
- "'1'": false,
1366
- "'2'": false,
1367
- "'3'": false,
1368
- "'4'": false,
1369
- "'5'": false,
1370
- "'6'": false,
1371
- "'7'": false,
1372
- "'8'": false,
1373
- "'9'": false,
1374
- "' '": spaceKeyCallback,
1375
- "F4": valueHelpCallback
1376
- };
1377
-
1378
- function keyMapping(oAdvancedExpressionEditor) {
1379
- return oAdvancedExpressionEditor.keyMap;
1380
- }
1381
-
1382
- if (this.expressionTokens.length === 0) {
1383
- var oEL = sap.ui.getCore().byId(this.getExpressionLanguage());
1384
- if (oEL) {
1385
- this.getFormattingTokens(oEL);
1386
- }
1387
- }
1388
- var keyMap = keyMapping(this);
1389
- var textAreaId = this.oTextArea.getId() + '-inner';
1390
- var isMSIE = (Utils.msieversion() >= 0);
1391
- if (isMSIE) {
1392
- jQuery('#' + textAreaId).attr('placeholder', this.getProperty('placeholder'));
1393
- }
1394
- this.codeMirror = window.CodeMirror.fromTextArea(document.getElementById(textAreaId), {
1395
- mode: "text/hdf",
1396
- lineNumbers: false,
1397
- lineWrapping: true,
1398
- matchBrackets: editable === true ? true : false,
1399
- highlightSelectionMatches: editable === true ? {
1400
- showToken: /\w/
1401
- } : {},
1402
- relDelegate: expressionLanguage,
1403
- returnType: this.getProperty("type"),
1404
- collection: this.getProperty("collection"),
1405
- valueListAttribute: valueListAttribute,
1406
- expressionEditor: this,
1407
- stillNeedShowHint: true,
1408
- shouldValidate: true,
1409
- styleSelectedText: true,
1410
- smartIndent: true,
1411
- autoCloseBrackets: true,
1412
- indentUnit: 6
1413
- });
1414
- this.codeMirror.addKeyMap(keyMap, true);
1415
-
1416
- // //In order to support aliases - we must reset the aliases after initialization of codeMirror object
1417
- // if (window.CodeMirror.mimeModes.hasOwnProperty('text/hdf'))
1418
- // window.CodeMirror.mimeModes['text/hdf'].aliases = me.getRelDelegate().vocabualryAliasesNames;
1419
- };
1420
-
1421
- ExpressionAdvanced.prototype.getFormattingTokens = function(oExpressionLanguage) {
1422
- this.tokens = [];
1423
- this.valueListAttrInfo = oExpressionLanguage.getValueListAttribute(this.mProperties.attributeInfo);
1424
- var exprssionMetadata = oExpressionLanguage.getExpressionMetadata(this._liveValue);
1425
- if (exprssionMetadata) {
1426
- this.tokens = exprssionMetadata.tokens;
1427
- }
1428
- if (oExpressionLanguage._hasValueSource && this.valueListAttrInfo) {
1429
- this.newExpression = this.valueListAttrInfo.navPath + " " + Constants.IS_EQUAL_TO + " " + this._liveValue;
1430
- exprssionMetadata = oExpressionLanguage.getExpressionMetadata(this.newExpression);
1431
- if (exprssionMetadata) {
1432
- var tokensWithPath = exprssionMetadata.tokens;
1433
- for (var tokenPos = 0; tokenPos < tokensWithPath.length; tokenPos++) {
1434
- for (var pos = 0; pos < this.tokens.length; pos++) {
1435
- if (tokensWithPath[tokenPos].tokenType === "valueList" && tokensWithPath[tokenPos].token === this.tokens[pos].token) {
1436
- this.tokens[pos].info = tokensWithPath[tokenPos].info;
1437
- this.tokens[pos].tokenType = tokensWithPath[tokenPos].tokenType;
1438
- }
1439
- }
1440
-
1441
- }
1442
- }
1443
- }
1444
- this.setExpressionTokens(this.tokens);
1445
- };
1446
-
1447
- ExpressionAdvanced.prototype._setEditorStyle = function() {
1448
- //We added to the codeMirror code (see codeMirror.js) styles class derived from SAPUI5
1449
- //Set CSS style to the new added codemirror control - according to SAPUI5 textField CSS
1450
- //sapUiTf sapUiTfBack sapUiTfBrd sapUiTfStd sapUiTxtA
1451
-
1452
- //We need to mimic the way input control is being used in sapui5 which means:
1453
- //level 1: sapMInput sapMInputBase
1454
- //level 2: sapMInputBaseInner
1455
- if (this.getValueStateText() && this.getValueStateText() !== "") {
1456
- jQuery(this.codeMirror.getWrapperElement()).addClass('CodeMirror-error');
1457
- jQuery(this.codeMirror.getWrapperElement()).addClass('sapMInputBaseStateInner sapMInputBaseErrorInner sapMInputBaseContentWrapper sapMInputBaseContentWrapperState sapMInputBaseContentWrapperError');
1458
- jQuery('#' + this.oTextArea.getId()).addClass('sapMInputBaseError');
1459
- }
1460
- jQuery('#' + this.oTextArea.getId()).removeClass().addClass('sapMInput'); //sapMInputBase
1461
- jQuery(this.codeMirror.getWrapperElement()).addClass('sapMInputBaseInner CodeMirror-rules');
1462
- if (!this.getEditable()) {
1463
- jQuery(this.codeMirror.getWrapperElement()).addClass('CodeMirror-rules-Not-Editable');
1464
- } else {
1465
- jQuery(this.codeMirror.getWrapperElement()).removeClass('CodeMirror-rules-Not-Editable');
1466
- }
1467
-
1468
- // bug fix - without it the height of codeMirror to big --> cause to wrong cursor positioning
1469
- if (this.codeMirror) {
1470
- this.codeMirror.refresh();
1471
- }
1472
- };
1473
-
1474
- ExpressionAdvanced.prototype._handleOnLoadValidation = function() {
1475
- if (this.getValidateOnLoad()) {
1476
- this.validateExpression();
1477
- this.setValidateOnLoad(false);
1478
- }
1479
- };
1480
-
1481
- ExpressionAdvanced.prototype._handleEditableProperty = function() {
1482
- if (this.getEditable() === false) {
1483
- this.codeMirror.setOption("readOnly", "true");
1484
- this.codeMirror.setOption("theme", "read-only");
1485
- }
1486
- };
1487
-
1488
- ExpressionAdvanced.prototype._handleFocus = function() {
1489
- var oCodeMirror = this.codeMirror;
1490
- if (this.getFocusOnLoad()) {
1491
- this.focus();
1492
- }
1493
- this.codeMirror.on("focus", function(cm, change) {
1494
- var errorMessage = cm.options.expressionEditor.getProperty("valueStateText");
1495
- if (errorMessage && errorMessage !== "") {
1496
- cm.options.expressionEditor._showPopUp();
1497
- }
1498
- cm.options.stillNeedShowHint = true;
1499
- jQuery('#' + cm.options.expressionEditor.oTextArea.getId()).addClass('sapMInputFocused');
1500
- jQuery(cm.getWrapperElement()).removeClass('CodeMirror-errorBackground');
1501
- });
1502
-
1503
- if (this.dataModel.getProperty("/focus") === true) {
1504
- window.setTimeout(function() {
1505
- var lastLine = oCodeMirror.getLine(oCodeMirror.lastLine());
1506
- var cursorPos = lastLine.length;
1507
- oCodeMirror.setCursor({
1508
- line: oCodeMirror.lastLine(),
1509
- ch: cursorPos
1510
- });
1511
- //oCodeMirror.focus();
1512
- }, 10);
1513
- }
1514
- };
1515
-
1516
- ExpressionAdvanced.prototype._refreshOnNavigationEnd = function() {
1517
- jQuery(".sapMNav").on('webkitTransitionEnd oTransitionEnd transitionend msTransitionEnd', jQuery.proxy(_refreshCodemirror, this));
1518
-
1519
- function _refreshCodemirror() {
1520
- if (this.codeMirror) {
1521
- this.codeMirror.refresh();
1522
- }
1523
- }
1524
-
1525
- };
1526
-
1527
- ExpressionAdvanced.prototype._handleKeyPress = function() {
1528
- this.codeMirror.on("keyHandled", function(cm, key, event) {
1529
- if (event.keyCode === 27 && this && this.endCompletion === true) {
1530
- event.stopPropagation();
1531
- this.endCompletion = false;
1532
- }
1533
- if (event.ctrlKey === true && key === "Ctrl-A") {
1534
- event.stopPropagation();
1535
- }
1536
- });
1537
- };
1538
-
1539
- ExpressionAdvanced.prototype._handleEndCodeCompletion = function() {
1540
- this.codeMirror.on("endCompletion", function(cm) {
1541
- cm.options.expressionEditor.needAutoComplete = false;
1542
- cm.options.expressionEditor.endCompletion = !cm.options.expressionEditor.endCompletion;
1543
- });
1544
- };
1545
-
1546
- ExpressionAdvanced.prototype._handleMousedown = function() {
1547
- this.codeMirror.on("mousedown", function(cm, event) {
1548
-
1549
- //Once user click on 'ValueList' token
1550
- event.stopPropagation();
1551
-
1552
- var target = event.target || event.srcElement;
1553
-
1554
- if (target && event.button === 0) {
1555
- var classList = target.className.split(/\s+/);
1556
-
1557
- for (var i = 0; i < classList.length; i++) {
1558
- if (classList[i] === 'cm-valuehelp') {
1559
- var valueHelpId = classList[++i].split('-valuehelpid-')[1];
1560
- //vlaueHelpPopUp
1561
- cm.options.expressionEditor.onValueHelpLinkPress(target.textContent, valueHelpId);
1562
- }
1563
- }
1564
- }
1565
- });
1566
- };
1567
-
1568
- /*
1569
- /!*
1570
- * Get complete token string from tokens cached array
1571
- * @param selectedValueList - selected html element outerHTML, contain only partaily token value
1572
- * @param oControll expression editor instance
1573
- * @returns complete token string
1574
- *!/
1575
- ExpressionAdvanced.prototype._getValueListToken = function (selectedValueList, oControll){
1576
- var tokens = oControll.getExpressionTokens();
1577
- var tokensLength = tokens.length;
1578
- for (var index = 0; index < tokensLength; index++){
1579
- if (tokens[index].token.indexOf(selectedValueList) > -1){
1580
- return tokens[index].token;
1581
- }
1582
- }
1583
- return null;
1584
- };*/
1585
-
1586
- ExpressionAdvanced.prototype._handleChange = function() {
1587
- this.codeMirror.on("change", function(cm, change) {
1588
- var oAdvancedExpressionEditor = cm.options.expressionEditor;
1589
- if (oAdvancedExpressionEditor.codeMirror.state.completionActive && oAdvancedExpressionEditor.keyMap["'" + change.text[0] + "'"] ===
1590
- false) {
1591
- oAdvancedExpressionEditor.codeMirror.state.completionActive.close();
1592
- }
1593
-
1594
- jQuery(oAdvancedExpressionEditor.codeMirror.getWrapperElement()).removeClass('CodeMirror-error');
1595
- jQuery(oAdvancedExpressionEditor.codeMirror.getWrapperElement()).removeClass('sapMInputBaseStateInner sapMInputBaseErrorInner sapMInputBaseContentWrapper sapMInputBaseContentWrapperState sapMInputBaseContentWrapperError');
1596
- oAdvancedExpressionEditor._liveValue = cm.getValue();
1597
-
1598
- var oEL = sap.ui.getCore().byId(oAdvancedExpressionEditor.getExpressionLanguage());
1599
- if (oEL) {
1600
- oAdvancedExpressionEditor.getFormattingTokens(oEL);
1601
- }
1602
-
1603
- oAdvancedExpressionEditor.codeMirror.options.shouldValidate = true;
1604
- oAdvancedExpressionEditor.fireLiveChange({
1605
- newValue: cm.getValue()
1606
- });
1607
- // we dont indent on delete
1608
- if (change.origin !== "+delete") {
1609
- cm.operation(function() {
1610
- for (var line = 0, end = cm.lineCount(); line < end; ++line) {
1611
- cm.indentLine(line, "smart");
1612
- }
1613
- });
1614
- }
1615
- });
1616
- };
1617
-
1618
- ExpressionAdvanced.prototype._handleFocusLeave = function() {
1619
- this.codeMirror.on("blur", function(cm) {
1620
- var oAdvancedExpressionEditor = cm.options.expressionEditor;
1621
- oAdvancedExpressionEditor._closePopUp();
1622
- oAdvancedExpressionEditor.codeMirror.options.stillNeedShowHint = false;
1623
-
1624
- // shouldValidate flag indicates:
1625
- // - this is real focus leave, not because of click on Hint
1626
- // - value was changed while the control was in focus
1627
- // - oAdvancedExpressionEditor.bFlagForPreventBlurWhenPopOverOpen see bug 4810
1628
- if (oAdvancedExpressionEditor.codeMirror.options.shouldValidate && !oAdvancedExpressionEditor.bFlagForPreventBlurWhenPopOverOpen) {
1629
- oAdvancedExpressionEditor.setValue(oAdvancedExpressionEditor.codeMirror.getValue());
1630
- //if (oAdvancedExpressionEditor.getProperty("automaticValidation")){
1631
- if (!(oAdvancedExpressionEditor instanceof sap.rules.ui.DecisionTableCellExpressionAdvanced)) {
1632
- oAdvancedExpressionEditor.validate();
1633
- }
1634
- oAdvancedExpressionEditor._closePopUp();
1635
- //}
1636
- oAdvancedExpressionEditor.fireChange({
1637
- newValue: cm.getValue()
1638
- });
1639
- oAdvancedExpressionEditor.codeMirror.options.shouldValidate = false;
1640
- }
1641
- jQuery('#' + oAdvancedExpressionEditor.oTextArea.getId()).removeClass('sapMInputFocused');
1642
- oAdvancedExpressionEditor.dataModel.setProperty("/focus", false);
1643
- });
1644
- };
1645
-
1646
- ExpressionAdvanced.prototype._setExpressionErrorStyle = function() {
1647
- var errorMsg = this.getProperty("valueStateText");
1648
- if (errorMsg !== "" && errorMsg !== undefined && this.codeMirror) {
1649
- jQuery(this.codeMirror.getWrapperElement()).addClass('CodeMirror-error');
1650
- jQuery(this.codeMirror.getWrapperElement()).addClass('sapMInputBaseStateInner sapMInputBaseErrorInner sapMInputBaseContentWrapper sapMInputBaseContentWrapperState sapMInputBaseContentWrapperError');
1651
- jQuery('#' + this.oTextArea.getId()).addClass('sapMInputBaseError');
1652
-
1653
- // Position the cursor within the control
1654
- var cursorPos;
1655
- if (this.errorCursorPosition < 0) {
1656
- var lastLine = this.codeMirror.getLine(this.codeMirror.lastLine());
1657
- cursorPos = lastLine.length;
1658
- //this.codeMirror.setCursor({line: lastLine, ch: cursorPos});
1659
- jQuery(this.codeMirror.getWrapperElement()).addClass('CodeMirror-errorBackground');
1660
- } else {
1661
- var idx = errorMsg.lastIndexOf("'");
1662
- if (idx > 0) {
1663
- var offendingText = errorMsg.substring(0, idx);
1664
- idx = offendingText.lastIndexOf("'");
1665
- if (idx > 0) {
1666
- offendingText = offendingText.substring(idx + 1);
1667
- }
1668
- var found = false;
1669
- for (var lineNum = this.codeMirror.lastLine(); !found && lineNum >= 0; lineNum--) {
1670
- var exp = this.codeMirror.getLine(lineNum);
1671
- cursorPos = exp.lastIndexOf(offendingText);
1672
- if (cursorPos >= 0) {
1673
- found = true;
1674
- this.codeMirror.setSelection({
1675
- line: lineNum,
1676
- ch: cursorPos
1677
- }, {
1678
- line: lineNum,
1679
- ch: cursorPos + offendingText.length
1680
- });
1681
- }
1682
- }
1683
- }
1684
- }
1685
- }
1686
- };
1687
-
1688
- /* ExpressionAdvanced.prototype.createAliasFromTextMenu = function (e){
1689
-
1690
- // build context menu
1691
- this.oContextMenu = new sap.m.ActionSheet();
1692
-
1693
- //Create the items and add them to the menu
1694
- var oMenuItemSaveAsAlias = new Button({
1695
- text: this.oBundle.getText("SAVE_AS_ALIAS")
1696
- });
1697
- oMenuItemSaveAsAlias.attachPress(function (){
1698
- // concat text of all elements
1699
- var text = this.getSelectedText();
1700
- this.onCreateAliasLinkForText(text);
1701
- });
1702
- this.oContextMenu.addButton(oMenuItemSaveAsAlias);
1703
- };*/
1704
-
1705
- ExpressionAdvanced.prototype.getSelectedText = function() {
1706
- return this.codeMirror.getSelection();
1707
- };
1708
-
1709
- /* ExpressionAdvanced.prototype.openAliasFromTextMenu = function (e){
1710
- window.setTimeout(function (){
1711
- if (this.codeMirror.getSelection() !== ""){
1712
- if (!this.oContextMenu){
1713
- this.createAliasFromTextMenu(e);
1714
- }
1715
- this.oContextMenu.openBy(jQuery('#' + this.getId() + " .CodeMirror .CodeMirror-selectedtext")[0]);
1716
- } else if (this.oContextMenu && this.oContextMenu.isOpen()){
1717
- this.oContextMenu.close();
1718
- }
1719
-
1720
- }, 300);
1721
- };*/
1722
- ExpressionAdvanced.prototype.exit = function() {
1723
- document.removeEventListener("mousedown", this.fnMouseDownListsner, true);
1724
- };
1725
- return ExpressionAdvanced;
1726
-
1727
- }, /* bExport= */ true);
5
+
6
+ */
7
+
8
+ // Provides the sap.rules.ui.ExpressionAdvanced control
9
+ sap.ui.define([
10
+ "./ExpressionAdvancedRenderer",
11
+ "sap/base/Log",
12
+ "sap/m/Dialog",
13
+ "sap/ui/core/Control",
14
+ "sap/m/Button",
15
+ "sap/m/TextArea",
16
+ "sap/m/Text",
17
+ "sap/m/MessageBox",
18
+ "sap/ui/layout/HorizontalLayout",
19
+ "sap/rules/ui/Utils",
20
+ "sap/ui/core/Popup",
21
+ "jquery.sap.global",
22
+ "sap/rules/ui/ExpressionBase",
23
+ "sap/ui/comp/odata/MetadataAnalyser",
24
+ "sap/rules/ui/providers/ValueHelpProvider",
25
+ "sap/ui/core/LocaleData",
26
+ "sap/rules/ui/Constants",
27
+ "sap/rules/ui/codemirror/lib/codemirror",
28
+ "sap/rules/ui/codemirror/addon/hint/show-hint",
29
+ "sap/rules/ui/codemirror/mode/hdf/hdf",
30
+ "sap/rules/ui/codemirror/addon/display/placeholder",
31
+ "sap/rules/ui/codemirror/addon/mh/mark-selection",
32
+ "sap/rules/ui/codemirror/addon/hint/hdf-hint",
33
+ "sap/rules/ui/codemirror/addon/closeBrackets/closebrackets",
34
+ "sap/rules/ui/codemirror/addon/search/search"
35
+
36
+ ], function(ExpressionAdvancedRenderer, Log, Dialog, Control, Button, TextArea, Text, MessageBox, HorizontalLayout, Utils, Popup, jQ, ExpressionBase, MetadataAnalyser,
37
+ ValueHelpProvider, LocaleData, Constants) {
38
+ "use strict";
39
+ /**
40
+ * Constructor for a new ExpressionAdvanced.
41
+ *
42
+ * @param {string} [sId] ID for the new control, generated automatically if no ID is given
43
+ * @param {object} [mSettings] Initial settings for the new control
44
+ *
45
+ * @class
46
+ * The <code>sap.rules.ui.ExpressionAdvanced</code> control provides the ability to define expressions for complex rules in a decision table.
47
+ * @extends sap.ui.core.Control
48
+ *
49
+ * @author SAP SE
50
+ * @version 1.58.1
51
+ *
52
+ * @constructor
53
+ * @private
54
+ * @experimental Only for internal use.
55
+ *
56
+ * @alias sap.rules.ui.ExpressionAdvanced
57
+ * @ui5-metamodel This control also will be described in the UI5 (legacy) designtime metamodel
58
+ */
59
+
60
+ var ExpressionAdvanced = ExpressionBase.extend("sap.rules.ui.ExpressionAdvanced", {
61
+
62
+ metadata: {
63
+ properties: {
64
+
65
+ /**
66
+ * The business data type of the expression (e.g. String, Number, Boolean).
67
+ * The default value <code>sap.rules.ui.ExpressionType.All</code> means that all valid business data types are permitted.
68
+ */
69
+ type: {
70
+ type: "sap.rules.ui.ExpressionType",
71
+ defaultValue: sap.rules.ui.ExpressionType.All,
72
+ bindable: "bindable"
73
+ },
74
+
75
+ /**
76
+ * Defines weather the expression evaluates to a collection of values or to a single value.
77
+ */
78
+ collection: {
79
+ type: "boolean",
80
+ defaultValue: false
81
+ },
82
+
83
+ /**
84
+ * Defines a short hint intended to aid the user with data entry when the control has no value.
85
+ */
86
+ placeholder: {
87
+ type: "string",
88
+ defaultValue: null
89
+ },
90
+
91
+ /**
92
+ * Defines whether the focus is set to the control upon loading.
93
+ */
94
+ focusOnLoad: {
95
+ type: "boolean",
96
+ defaultValue: false
97
+ },
98
+
99
+ attributeInfo: {
100
+ type: "string",
101
+ defaultValue: "",
102
+ bindable: "bindable"
103
+ }
104
+ },
105
+ aggregations: {
106
+
107
+ // A hidden text area is provided for the codemirror rendering.
108
+ _expressionArea: {
109
+ type: "sap.m.TextArea",
110
+ multiple: false,
111
+ visibility: "hidden"
112
+ }
113
+ },
114
+ events: {
115
+
116
+ /**
117
+ * This event is fired when the text in the input field has changed and the focus leaves the input field or the enter key is pressed.
118
+ */
119
+ "change": {},
120
+
121
+ /**
122
+ * This event is fired when the value of the input is changed - e.g. at each keypress
123
+ */
124
+ "liveChange": {},
125
+ "valueHelpRequest": {
126
+ parameters: {
127
+
128
+ /**
129
+ * The event parameter is set to true, when the button at the end of the suggestion table is clicked, otherwise false. It can be used to determine whether the "value help" trigger or the "show all items" trigger has been pressed.
130
+ */
131
+ fromSuggestions: {
132
+ type: "boolean"
133
+ }
134
+ }
135
+ }
136
+ },
137
+ publicMethosds: ["validate"]
138
+ },
139
+ renderer: ExpressionAdvancedRenderer
140
+ });
141
+
142
+ ExpressionAdvanced.prototype.init = function() {
143
+ ExpressionBase.prototype.init.apply(this, arguments);
144
+ var codeMirrorCSS = jQuery.sap.getModulePath("sap.rules.ui.codemirror.lib") + "/codemirror.css";
145
+ var showHintCSS = jQuery.sap.getModulePath("sap.rules.ui.codemirror.addon.hint") + "/show-hint.css";
146
+ jQuery.sap.includeStyleSheet(codeMirrorCSS);
147
+ jQuery.sap.includeStyleSheet(showHintCSS);
148
+
149
+ this.pop = new Popup(jQ('<span></span>')[0], false, false, false);
150
+ this.errorWidgets = [];
151
+ this.expressionTokens = [];
152
+ this._liveValue = "";
153
+ this.oBundle = sap.ui.getCore().getLibraryResourceBundle("sap.rules.ui.i18n");
154
+ this.dataModel = this.initControlDataModel();
155
+
156
+ // Expression area
157
+ this.oTextArea = new TextArea({
158
+ width: "100%"
159
+ });
160
+ this.validationCompleteEvent = document.createEvent("Event");
161
+ this.validationCompleteEvent.initEvent("validationCompleteEvent", true, false);
162
+ //this.validationCompleteEvent = document.createEvent("validationCompleteEvent");
163
+ this.setAggregation("_expressionArea", this.oTextArea, true);
164
+ this.bFlagForEventListener = true;
165
+
166
+ // Date instance which is used to convert the selected date from calendar control to short format
167
+ var oLocale = sap.ui.getCore().getConfiguration().getFormatSettings().getFormatLocale();
168
+ var oLocaleData = LocaleData.getInstance(oLocale);
169
+
170
+ this.oFormatDate = sap.ui.core.format.DateFormat.getInstance({
171
+ pattern: oLocaleData.getDatePattern('short'),
172
+ calendarType: sap.ui.core.CalendarType.Gregorian
173
+ },
174
+ oLocale
175
+ );
176
+ this._dateBusinessDataType = "Date";
177
+ this._valueHelpSelectionText = "Select from value help...";
178
+ this._hasValueSource = "HasValueSource";
179
+ this._propertyValue = "Value";
180
+ this._propertyDescription = "Description";
181
+ };
182
+
183
+ ExpressionAdvanced.prototype._processValidationResult = function(result) {
184
+ if (result.status === sap.rules.ui.ValidationStatus.Error) {
185
+ var msg = Utils.parseUTFToString(result.errorDetails /* || "unknown message" */ );
186
+ msg = msg.replace(/\r\n/g, " ").replace(/\r/g, " ").replace(/\n/g, " ");
187
+ this.errorCursorPosition = result.cursorPosition;
188
+ this.setValueStateText(msg);
189
+ //this._showPopUp();
190
+ } else {
191
+ this.oTextArea.setValueState("None");
192
+ this.oTextArea.setValueStateText("");
193
+ this.setValueStateText("");
194
+ jQuery(this.codeMirror.getWrapperElement()).removeClass('sapMInputBaseStateInner sapMInputBaseErrorInner sapMInputBaseContentWrapper sapMInputBaseContentWrapperState sapMInputBaseContentWrapperError');
195
+ }
196
+
197
+ };
198
+
199
+ ExpressionAdvanced.prototype.validateExpression = function(sInput) {
200
+ for (var i = 0; i < this.errorWidgets.length; i++) {
201
+ this.codeMirror.removeLineWidget(this.errorWidgets[i]);
202
+ }
203
+ this.errorWidgets = [];
204
+ var expressionValue = this.codeMirror ? this.codeMirror.getValue() : this.getValue();
205
+ var result = {};
206
+ var incomingdata = {};
207
+ var oEL = sap.ui.getCore().byId(this.getExpressionLanguage());
208
+ if (oEL) {
209
+ incomingdata = oEL.validateExpression(
210
+ sInput || expressionValue,
211
+ this.getProperty("type"),
212
+ this.getCollection(),
213
+ false
214
+ );
215
+ if (incomingdata && this.isActive()) {
216
+ result = incomingdata;
217
+ this._processValidationResult(result);
218
+ if (result.deferredResult) {
219
+ result.deferredResult.done(function(result) {
220
+ this._processValidationResult(result);
221
+ document.dispatchEvent(this.validationCompleteEvent);
222
+ }.bind(this));
223
+ }
224
+ }
225
+ }
226
+ return incomingdata;
227
+ };
228
+
229
+ ExpressionAdvanced.prototype._showPopUp = function() {
230
+ var errorState = "Error";
231
+ var errorMessage = this.getProperty("valueStateText");
232
+ var thisId = this.getId() + '-message';
233
+ var pop = this.pop; //new Popup(jQ('<span></span>')[0], false, false, false);
234
+ if (!this.pop) { //bug 4813
235
+ return;
236
+ }
237
+ pop.attachClosed(function() {
238
+ jQ.sap.byId(thisId).remove();
239
+ });
240
+ var dock = Popup.Dock;
241
+ var cssClass = 'sapMInputBaseMessage' + errorState + ' sapMFocus';
242
+ var T = 'sapMValueStateMessageError sapMText';
243
+ var r = sap.ui.getCore().getLibraryResourceBundle('sap.m');
244
+
245
+ if (errorState === sap.ui.core.ValueState.Success) {
246
+ cssClass = 'sapUiInvisibleText';
247
+ errorMessage = '';
248
+ }
249
+ var oContent = jQ('<div>', {
250
+ 'id': thisId,
251
+ 'class': cssClass,
252
+ 'role': 'tooltip',
253
+ 'aria-live': 'assertive'
254
+ }).append(jQ('<span>', {
255
+ 'aria-hidden': true,
256
+ 'class': 'sapUiHidden',
257
+ 'text': r.getText('INPUTBASE_VALUE_STATE_' + errorState.toUpperCase())
258
+ })).append(jQ('<span>', {
259
+ 'id': thisId + '-text',
260
+ 'class': T,
261
+ 'text': errorMessage
262
+ }));
263
+ pop.setContent(oContent[0]);
264
+ pop.close(0);
265
+ pop.open(0, dock.BeginTop, dock.BeginBottom, jQuery(this.codeMirror.getWrapperElement()), null, "none flip", true);
266
+ var sPopUpWidth = this.pop.oContent.clientWidth;
267
+ var oTextAreaHTMLElement = document.getElementById(this.getAggregation("_expressionArea"));
268
+ if (!oTextAreaHTMLElement) {
269
+ return;
270
+ }
271
+ var sExpressionAdvancedWidth = oTextAreaHTMLElement.sId.clientWidth;
272
+ if (sPopUpWidth > sExpressionAdvancedWidth) {
273
+ jQuery(".sapMText").css('width', sExpressionAdvancedWidth);
274
+ jQuery(".sapMText").css('padding-left', '12px');
275
+ jQuery(".sapMText").css('padding-right', '12px');
276
+ jQuery(".sapMText").css('padding-top', '8px');
277
+ jQuery(".sapMText").css('padding-bottom', '8px');
278
+ }
279
+ };
280
+
281
+ ExpressionAdvanced.prototype._closePopUp = function() {
282
+ if (this.pop) {
283
+ this.pop.close(0);
284
+ }
285
+ };
286
+
287
+ ExpressionAdvanced.prototype._showErrorMessage = function() {
288
+ var errorMessage = this.getValueStateText();
289
+ if (errorMessage && errorMessage !== "") {
290
+ this._setExpressionErrorStyle();
291
+ }
292
+ };
293
+
294
+ ExpressionAdvanced.prototype.initControlDataModel = function() {
295
+ var oDataModel = new sap.ui.model.json.JSONModel();
296
+ var data = {};
297
+ oDataModel.setData(data);
298
+ return oDataModel;
299
+ };
300
+
301
+ ExpressionAdvanced.prototype.setExpressionTokens = function(tokens) {
302
+ var maxLineEnd = 0,
303
+ newLineExist = false;
304
+ this.expressionTokens = [];
305
+ if (tokens instanceof Array) {
306
+ for (var i = 0; i < tokens.length; i++) {
307
+ var tokenMetaData = tokens[i];
308
+ //minimize the number of cached tokens
309
+ var newLineReg = /\n/;
310
+ if (newLineReg.test(tokenMetaData.token)) {
311
+ maxLineEnd = tokenMetaData.start + tokenMetaData.token.lastIndexOf('\n') + 1;
312
+ newLineExist = true;
313
+ continue;
314
+ }
315
+ if (newLineExist) {
316
+ tokenMetaData.start = tokenMetaData.start - maxLineEnd;
317
+ tokenMetaData.end = tokenMetaData.end - maxLineEnd + 1;
318
+ } else {
319
+ tokenMetaData.end = tokenMetaData.end + 1;
320
+ }
321
+ this.expressionTokens.push(tokenMetaData);
322
+ }
323
+ }
324
+ };
325
+
326
+ ExpressionAdvanced.prototype.getExpressionTokens = function() {
327
+ return this.expressionTokens;
328
+ };
329
+
330
+ /** INTERFACE */
331
+
332
+ ExpressionAdvanced.prototype.getValue = function() {
333
+ if (this.codeMirror !== undefined) {
334
+ return this.codeMirror.getValue();
335
+ }
336
+ return this.getProperty("value");
337
+ };
338
+ ExpressionAdvanced.prototype.setValue = function(value) {
339
+ if (value === undefined || value === null) {
340
+ value = "";
341
+ }
342
+ this._liveValue = value;
343
+ this.oTextArea.setValue(value);
344
+ if (this.getProperty("value") === value) {
345
+ return;
346
+ }
347
+ this.setProperty("value", value, true);
348
+ if (this.codeMirror !== undefined) {
349
+ this.codeMirror.setValue(value);
350
+ }
351
+ };
352
+
353
+ ExpressionAdvanced.prototype.setPlaceholder = function(value) {
354
+ this.setProperty("placeholder", value);
355
+ var modelValue = (this.getEditable()) ? value : "";
356
+ this.dataModel.setProperty("/placeholder", modelValue);
357
+ };
358
+
359
+ ExpressionAdvanced.prototype.getPlaceholder = function() {
360
+ return this.dataModel.getProperty("/placeholder");
361
+ };
362
+
363
+ ExpressionAdvanced.prototype.setValueStateText = function(message) {
364
+ this.setProperty("valueStateText", message, true);
365
+ if (message){
366
+ this._showErrorMessage(message);
367
+ } else {
368
+ jQuery(this.codeMirror.getWrapperElement()).removeClass('CodeMirror-error');
369
+ jQuery(this.codeMirror.getWrapperElement()).removeClass('sapMInputBaseStateInner sapMInputBaseErrorInner sapMInputBaseContentWrapper sapMInputBaseContentWrapperState sapMInputBaseContentWrapperError');
370
+ }
371
+ };
372
+
373
+ ExpressionAdvanced.prototype.setEditable = function(value) {
374
+ this.setProperty("editable", value);
375
+ this.getAggregation("_expressionArea").setProperty("editable", value);
376
+ if (this.codeMirror) {
377
+ jQuery(this.codeMirror.getWrapperElement()).addClass('CodeMirror-rules-Not-Editable');
378
+ }
379
+ // placeholder is relevant only for editable field
380
+ var _placeholder = (value) ? this.getProperty("placeholder") : "";
381
+ this.dataModel.setProperty("/placeholder", _placeholder);
382
+ this.invalidate();
383
+ };
384
+
385
+ ExpressionAdvanced.prototype.setType = function(type) {
386
+ if (type === Constants.DATE_BUSINESS_TYPE || type === Constants.TIMESTAMP_BUSINESS_TYPE || type === Constants.NUMBER || type ===
387
+ Constants.STRING || type === Constants.BOOLEAN_BUSINESS_TYPE || type === Constants.BOOLEAN_ENHANCED_BUSINESS_TYPE) {
388
+ this.setProperty("type", type);
389
+ }
390
+
391
+ if (this.codeMirror) {
392
+ this.codeMirror.options.returnType = type;
393
+ }
394
+ };
395
+
396
+ ExpressionAdvanced.prototype.setCollection = function(isCollection) {
397
+ this.setProperty("collection", isCollection, true);
398
+ if (this.codeMirror) {
399
+ this.codeMirror.options.collection = isCollection;
400
+ }
401
+ };
402
+
403
+ /* end INTERFACE section */
404
+
405
+ /* Public methods section */
406
+
407
+ /**
408
+ * validates the current value of the control.
409
+ * @internal
410
+ * @return {object} [oResult] validation object.
411
+ */
412
+ ExpressionAdvanced.prototype.validate = function() {
413
+ return this.validateExpression();
414
+ };
415
+
416
+ ExpressionAdvanced.prototype.setFocusOnLoad = function(value) {
417
+ this.dataModel.setProperty("/focus", value);
418
+ this.setProperty("focusOnLoad", value, true);
419
+ };
420
+
421
+ ExpressionAdvanced.prototype.focus = function() {
422
+ if (this.codeMirror) {
423
+ var lastLine = this.codeMirror.getLine(this.codeMirror.lastLine());
424
+ var cursorPos = lastLine.length;
425
+ this.codeMirror.setCursor({
426
+ line: this.codeMirror.lastLine(),
427
+ ch: cursorPos
428
+ });
429
+ this.codeMirror.focus();
430
+ }
431
+ };
432
+
433
+ ExpressionAdvanced.prototype.onAliasLinkPress = function(aliasName) {
434
+ var expressionLanguage = sap.ui.getCore().byId(this.getExpressionLanguage());
435
+ if (expressionLanguage) {
436
+ expressionLanguage.onAliasLinkPress(aliasName);
437
+ expressionLanguage.attachEvent("aliasDialogClosed", this.aliasClickCancel, this);
438
+ }
439
+ };
440
+
441
+ ExpressionAdvanced.prototype.onCreateAliasLinkForText = function(text) {
442
+ var expressionLanguage = sap.ui.getCore().byId(this.getExpressionLanguage());
443
+ if (expressionLanguage) {
444
+ expressionLanguage.attachEvent("aliasDialogClosed", this.replaceTextWithAlias, this);
445
+ expressionLanguage.onCreateAliasLinkForText(text);
446
+ }
447
+ };
448
+
449
+ ExpressionAdvanced.prototype.replaceTextWithAlias = function(oEvent) {
450
+ if (oEvent.getParameter("isSave")) {
451
+ this.codeMirror.replaceSelection(oEvent.getParameter("savedAliasName"));
452
+ }
453
+ };
454
+
455
+ ExpressionAdvanced.prototype.aliasClickCancel = function(oEvent) {
456
+ this.codeMirror.focus();
457
+ this.codeMirror.execCommand("goLineEnd");
458
+ this.fireDialog({
459
+ dialogStatus: sap.rules.ui.ValueListDialogMode.Close
460
+ });
461
+ };
462
+
463
+ ExpressionAdvanced.prototype.onAfterRendering = function() {
464
+
465
+ this.timer = null;
466
+ // needAutoComplete tells us whether an auto complete action is required.
467
+ // we need it since we execute the popup opening in a delayed manner. sometimes it should not open (case 2):
468
+ // case 1. press key -> ... -> delayed open of popup (need to open)
469
+ // case 2. press key -> ... -> press Enter (to select form list) -> ... -> delayed open of popup (need not open)
470
+ this.needAutoComplete = false;
471
+ this.endCompletion = false;
472
+ this._setCodeMirror();
473
+ this._setEditorStyle();
474
+ this._handleMousedown();
475
+ this._handleChange();
476
+ this._handleFocusLeave(); //blur
477
+ this._handleEndCodeCompletion();
478
+ this._handleKeyPress();
479
+ this._handleEditableProperty();
480
+ this._handleOnLoadValidation();
481
+ this._refreshOnNavigationEnd();
482
+ this._handleFocus();
483
+ this._handleValueListSelect();
484
+ this._handleCalendarChange();
485
+
486
+ //bug RULES-4848\5031\5030 after choose value from auto complete - popover will not closed
487
+ if (this.bFlagForEventListener) {
488
+ this.bFlagForEventListener = false;
489
+ this.fnMouseDownListsner = function(oEvent) {
490
+ this.bFlagForChangeBeforeBlur = oEvent.target.className.indexOf("CodeMirror-hint") > -1;
491
+ }.bind(this);
492
+
493
+ this.fnBlurListsner = function(oEvent) {
494
+ if (this.bFlagForChangeBeforeBlur) {
495
+ this.bFlagForChangeBeforeBlur = false;
496
+ oEvent.stopPropagation();
497
+ this.codeMirror.focus();
498
+ }
499
+ }.bind(this);
500
+
501
+ document.addEventListener("mousedown", this.fnMouseDownListsner, true);
502
+ document.getElementById(this.getId()).addEventListener("blur", this.fnBlurListsner, true);
503
+ }
504
+
505
+ };
506
+
507
+ // Event listerner for change date click event
508
+ ExpressionAdvanced.prototype._handleCalendarChange = function() {
509
+ var that = this;
510
+ this.codeMirror.on('onChangeDate', function() {
511
+ that._createCalendarDialog(that.codeMirror.getCursor());
512
+ }.bind(this));
513
+ };
514
+
515
+ // Utility function to oprn calendate dialog
516
+ ExpressionAdvanced.prototype._createCalendarDialog = function(curPos) {
517
+ var bAddSpace = false;
518
+ var that = this;
519
+
520
+ var oCalendar = new sap.ui.unified.Calendar({
521
+ width: "100%",
522
+ select: this.handleCalendarSelect.bind(this)
523
+ });
524
+
525
+ this._oSelectNewDateDialog = new Dialog({
526
+ title: this.oBundle.getText("calendarTitle"),
527
+ content: [
528
+ oCalendar
529
+ ],
530
+ beginButton: new Button({
531
+ text: this.oBundle.getText("okBtn"),
532
+ enabled: false,
533
+ press: function() {
534
+ var date = this.updateText(oCalendar);
535
+ that._updateModal(false);
536
+ that.setTextOnCursor(date, curPos, false, this._dateBusinessDataType, bAddSpace, false);
537
+ that._oSelectNewDateDialog.close();
538
+ that.focus(that.codeMirror);
539
+ }.bind(this)
540
+ }),
541
+ endButton: new Button({
542
+ text: this.oBundle.getText("clsBtn"),
543
+ press: function() {
544
+ that._updateModal(false);
545
+ that._oSelectNewDateDialog.close();
546
+ that.focus(that.codeMirror);
547
+ }.bind(this)
548
+ })
549
+ });
550
+
551
+ this._oSelectNewDateDialog.open();
552
+
553
+ };
554
+
555
+ // Utility function to update Modal Property of modal
556
+ ExpressionAdvanced.prototype._updateModal = function(modalValue) {
557
+ var pop = sap.ui.getCore().byId("popover");
558
+ if (pop) {
559
+ pop.setModal(modalValue);
560
+ }
561
+ };
562
+
563
+ // Utility function to set calendar enabled property
564
+ ExpressionAdvanced.prototype.handleCalendarSelect = function(oEvent) {
565
+ var oCalendar = oEvent.getSource(),
566
+ oSelectedDate = oCalendar.getSelectedDates()[0].getStartDate();
567
+
568
+ if (oSelectedDate) {
569
+ this._oSelectNewDateDialog.getBeginButton().setEnabled(true);
570
+ }
571
+ };
572
+
573
+ // Utility function to format date
574
+ ExpressionAdvanced.prototype.updateText = function(oCalendar) {
575
+ var aSelectedDates = oCalendar.getSelectedDates();
576
+ var oDate;
577
+ if (aSelectedDates.length > 0) {
578
+ oDate = aSelectedDates[0].getStartDate();
579
+ return this.oFormatDate.format(oDate);
580
+ }
581
+ };
582
+
583
+ ExpressionAdvanced.prototype._raiseError = function(sError) {
584
+ //handling a scenario when the callback or the model are invalid
585
+ Log.error(sError);
586
+ var oBundle = sap.ui.getCore().getLibraryResourceBundle("sap.rules.ui.i18n");
587
+ this.setValueStateText(oBundle.getText("valueHelpTechnicalError"));
588
+ this._showPopUp();
589
+ };
590
+
591
+ /*
592
+ * Invoke this function once user select on 'Select value from list' suggestion
593
+ * This is listener to 'onValueListSelect' code mirror event/signal.
594
+ */
595
+ ExpressionAdvanced.prototype._handleValueListSelect = function() {
596
+
597
+ this.codeMirror.on('onValueListSelect', function() {
598
+ var suggestions = this.codeMirror.currentHintData.data.listCompletion;
599
+ var valueHelpInfo = [];
600
+ for (var sugg = 0; sugg < suggestions.length; sugg++) {
601
+ if (suggestions[sugg].text === this._valueHelpSelectionText) {
602
+ valueHelpInfo = suggestions[sugg].info;
603
+ }
604
+ }
605
+ var expressionLanguage = sap.ui.getCore().byId(this.getExpressionLanguage());
606
+ valueHelpInfo.expressionLanguage = expressionLanguage;
607
+ var callback = expressionLanguage.getValueHelpCallback();
608
+ this.oTextArea.setValueState("None");
609
+ this.oTextArea.setValueStateText("");
610
+ this.setValueStateText("");
611
+ jQuery(this.codeMirror.getWrapperElement()).removeClass('sapMInputBaseStateInner sapMInputBaseErrorInner sapMInputBaseContentWrapper sapMInputBaseContentWrapperState sapMInputBaseContentWrapperError');
612
+ if ((typeof callback) !== "function" && valueHelpInfo.metadata.hasOwnProperty(this._hasValueSource) && valueHelpInfo.metadata.HasValueSource ===
613
+ true) {
614
+ this._createCpValueHelp(valueHelpInfo, this.codeMirror.getCursor(), false);
615
+ } else {
616
+ if ((typeof callback) !== "function") {
617
+ this._raiseError("value help callback is not set or is not a function");
618
+ } else {
619
+ // enrich the valueHelpInfo with the valueHelp model
620
+ callback.call(this, valueHelpInfo);
621
+ // create provider
622
+ var oModel = valueHelpInfo[0].model;
623
+ if (!(oModel instanceof sap.ui.model.odata.v2.ODataModel)) {
624
+ this._raiseError("value help model is not an oData V2 model");
625
+ } else if (oModel.isMetadataLoadingFailed()) {
626
+ this._raiseError("model metadata loading has failed in the past");
627
+ } else if (!(oModel.getMetaModel().oModel)) {
628
+ oModel.attachMetadataLoaded(function() {
629
+ this._createValueHelpProvider(valueHelpInfo[0]);
630
+ }.bind(this));
631
+ oModel.attachMetadataFailed(function() {
632
+ this._raiseError("attached model metadata failed");
633
+ }.bind(this));
634
+ } else {
635
+ this._createValueHelpProvider(valueHelpInfo[0]);
636
+ }
637
+ }
638
+ }
639
+ }.bind(this));
640
+ };
641
+
642
+ ExpressionAdvanced.prototype._createValueHelpProvider = function(valueHelpInfo, bReplaceWord) {
643
+
644
+ var oModel = valueHelpInfo.model;
645
+ this.oMetadataAnalyzer = new sap.ui.comp.odata.MetadataAnalyser(oModel);
646
+ var sAnnotationPath = valueHelpInfo.metadata.propertyPath;
647
+ var oValueListAnnotation = this.oMetadataAnalyzer.getValueListAnnotation(sAnnotationPath);
648
+ if (!oValueListAnnotation.primaryValueListAnnotation) {
649
+ this._raiseError("proprety path is wrong");
650
+ return;
651
+ }
652
+ var tokens = this.getExpressionTokens();
653
+ var bAddSpace = false;
654
+ if (tokens.length > 0) {
655
+ bAddSpace = (tokens[tokens.length - 1].tokenType !== "whitespace");
656
+ }
657
+
658
+ if (this.oValueHelpDialogProvider) {
659
+ this.oValueHelpDialogProvider.destroy();
660
+ }
661
+
662
+ this.oValueHelpDialogProvider = new ValueHelpProvider({
663
+ annotation: oValueListAnnotation.primaryValueListAnnotation,
664
+ additionalAnnotations: oValueListAnnotation.additionalAnnotations,
665
+ control: this,
666
+ model: oModel,
667
+ preventInitialDataFetchInValueHelpDialog: false,
668
+ supportMultiSelect: false,
669
+ supportRanges: false,
670
+ takeOverInputValue: false,
671
+ fieldName: oValueListAnnotation.primaryValueListAnnotation.valueListTitle,
672
+ title: oValueListAnnotation.primaryValueListAnnotation.valueListTitle,
673
+ cursorPosition: this.codeMirror.getCursor(),
674
+ bReplaceWord: bReplaceWord,
675
+ businessDataType: valueHelpInfo.metadata.businessDataType,
676
+ bAddSpace: bAddSpace
677
+
678
+ });
679
+
680
+ // open dialog
681
+ this.fireValueHelpRequest({
682
+ fromSuggestions: false
683
+ });
684
+
685
+ };
686
+
687
+ ExpressionAdvanced.prototype._createCpValueHelp = function(valueHelpInfo, curPos, bReplaceWord, bValuehelpLinkPress) {
688
+ var businessDataType = valueHelpInfo.metadata.businessDataType;
689
+ var tokens = this.getExpressionTokens();
690
+ var bAddSpace = false;
691
+ var pop = sap.ui.getCore().byId("popover");
692
+ if (pop) {
693
+ pop.setModal(true);
694
+ }
695
+ if (tokens.length > 0) {
696
+ bAddSpace = (tokens[tokens.length - 1].tokenType !== "whitespace");
697
+ }
698
+
699
+ if (this.oDialog) {
700
+ this.oDialog.destroy();
701
+ }
702
+ var basePath = sap.ui.getCore().byId(this.getExpressionLanguage()).getModel().sServiceUrl;
703
+ this._createDialog(basePath, valueHelpInfo, curPos, businessDataType, bAddSpace, bReplaceWord, bValuehelpLinkPress);
704
+ };
705
+
706
+ /*
707
+ * Creates the necessary control for the value Help Dialog.
708
+ *
709
+ */
710
+ ExpressionAdvanced.prototype._createDialog = function(basePath, valueHelpInfo, curPos, businessDataType, bAddSpace, bReplaceWord,
711
+ bValuehelpLinkPress) {
712
+ this._createValueHelpDialog(basePath, valueHelpInfo, curPos, businessDataType, bAddSpace, bReplaceWord, bValuehelpLinkPress);
713
+ this._createSmartFilterBar(basePath, valueHelpInfo);
714
+ this.oValueHelpDialog.setFilterBar(this.oFilterBar);
715
+ this.oValueHelpDialog.open();
716
+ this.oValueHelpDialog.getTable().setBusy(true);
717
+ };
718
+
719
+ /*
720
+ * Creates the Value Help Dialog.
721
+ */
722
+
723
+ ExpressionAdvanced.prototype._createValueHelpDialog = function(basePath, valueHelpInfo, curPos, businessDataType, bAddSpace,
724
+ bReplaceWord, bValuehelpLinkPress) {
725
+ var that = this;
726
+ var expressionData = valueHelpInfo.expressionLanguage.getModel();
727
+ var attributePath = "Attributes(Id='"+ valueHelpInfo.metadata.attributeId + "',VocabularyId='" + valueHelpInfo.metadata.vocabularyId + "',DataObjectId='" + valueHelpInfo.metadata.dataObjectId + "')";
728
+ if(attributePath.includes(":")) {
729
+ attributePath = attributePath = attributePath.replace(":","%3A");
730
+ }
731
+ this.attributeName = expressionData.oData[attributePath].Name;
732
+ sap.ui.core.BusyIndicator.show(0);
733
+ this.oValueHelpDialog = new sap.ui.comp.valuehelpdialog.ValueHelpDialog({
734
+ supportMultiselect : false,
735
+ supportRanges : false,
736
+ horizontalScrolling : false,
737
+ title : that.attributeName,
738
+ resizable : false,
739
+ beforeOpen : function() {
740
+ that._bindTable(basePath, valueHelpInfo);
741
+ },
742
+ ok : function(oEvt) {
743
+ var oSelRow = oEvt.getParameter("tokens")[0].data("row");
744
+ var value = oSelRow.Value;
745
+ if (businessDataType === that._dateBusinessDataType) {
746
+ value = that._formatDate(value);
747
+ }
748
+ that.setTextOnCursor(value, curPos, bReplaceWord, businessDataType, bAddSpace, bValuehelpLinkPress);
749
+ that._updateModal(false);
750
+ that.oValueHelpDialog.close();
751
+ that.focus(that.codeMirror);
752
+
753
+ },
754
+ cancel : function() {
755
+ that._updateModal(false);
756
+ that.oValueHelpDialog.close();
757
+ that.focus(that.codeMirror);
758
+
759
+ },
760
+ afterClose : function() {
761
+ that._updateModal(false);
762
+ that.oValueHelpDialog.destroy();
763
+ that.focus(that.codeMirror);
764
+ that.oFilterBar.destroy();
765
+ sap.ui.core.BusyIndicator.hide();
766
+ }
767
+ });
768
+ };
769
+
770
+ /*
771
+ * Utility function to format Date.
772
+ */
773
+ ExpressionAdvanced.prototype._formatDate = function(value) {
774
+ return this.oFormatDate.format(this.oFormatDate.parse(value));
775
+ };
776
+
777
+ /*
778
+ * Creates the necessary control os SmartFilterBar for the ValueHelp Dialog.
779
+ */
780
+ ExpressionAdvanced.prototype._createSmartFilterBar = function(basePath, valueHelpInfo) {
781
+ var that = this;
782
+ this.oFilterBar = new sap.ui.comp.smartfilterbar.SmartFilterBar({
783
+ entitySet : valueHelpInfo.metadata.entitySet,
784
+ enableBasicSearch : true,
785
+ advancedMode : true,
786
+ filterBarExpanded: true,
787
+ search : function() {
788
+ that.onSearch(basePath, valueHelpInfo);
789
+
790
+ },
791
+ filterChange: function(oEvent) {
792
+ that.setValueStateFilter(oEvent);
793
+ },
794
+ controlConfiguration : [ that._createControlConfiguration() ]
795
+ });
796
+ var oModel = new sap.ui.model.odata.v2.ODataModel(basePath);
797
+ this.oFilterBar.setModel(oModel);
798
+ };
799
+
800
+ /*
801
+ * Creating the Control Configuration for the smartFilter of the valueHelp Dialog.
802
+ */
803
+ ExpressionAdvanced.prototype._createControlConfiguration = function() {
804
+ var aControlConfiguration = [ new sap.ui.comp.smartfilterbar.ControlConfiguration({
805
+ hasValueHelpDialog : true,
806
+ key : "Value",
807
+ label : "Value",
808
+ visibleInAdvancedArea : true,
809
+ width : "100px",
810
+ index : 1
811
+
812
+ }), new sap.ui.comp.smartfilterbar.ControlConfiguration({
813
+ hasValueHelpDialog : true,
814
+ key : "Description",
815
+ label : "Description",
816
+ visibleInAdvancedArea : true,
817
+ width : "100px",
818
+ index : 2
819
+
820
+ }), new sap.ui.comp.smartfilterbar.ControlConfiguration({
821
+ hasValueHelpDialog : true,
822
+ key : "VocabularyId",
823
+ label : "VocabularyId",
824
+ width : "100px",
825
+ visible : false,
826
+ index : 3
827
+
828
+ }), new sap.ui.comp.smartfilterbar.ControlConfiguration({
829
+ hasValueHelpDialog : true,
830
+ key : "DataObjectId",
831
+ label : "DataObjectId",
832
+ visible : false,
833
+ width : "100px",
834
+ groupId : "abc",
835
+ index : 4
836
+
837
+ }), new sap.ui.comp.smartfilterbar.ControlConfiguration({
838
+ hasValueHelpDialog : true,
839
+ key : "AttributeId",
840
+ label : "AttributeId",
841
+ visible : false,
842
+ width : "100px",
843
+ index : 5
844
+
845
+ }),
846
+ new sap.ui.comp.smartfilterbar.ControlConfiguration({
847
+ hasValueHelpDialog : true,
848
+ key : "Version",
849
+ label : "Version",
850
+ visible : false,
851
+ width : "100px",
852
+ index : 6
853
+
854
+ })];
855
+ return aControlConfiguration;
856
+ };
857
+
858
+ /*
859
+ * Called when the search is triggered in SmartFilter.
860
+ */
861
+ ExpressionAdvanced.prototype.onSearch = function(basePath, valueHelpInfo) {
862
+ this.oValueHelpDialog.getTable().setBusy(true);
863
+ this._unBindTable();
864
+ this._bindTable(basePath, valueHelpInfo);
865
+ };
866
+
867
+ /*
868
+ * Binds the table taking current filters parameters into account.
869
+ */
870
+ ExpressionAdvanced.prototype._bindTable = function(basePath, valueHelpInfo) {
871
+ var serviceUrl = valueHelpInfo.metadata.serviceURL;
872
+ var aFilterParams = this._fetchFilterParams(valueHelpInfo);
873
+ var mEntities = {
874
+ valueHelp : {
875
+ collection : serviceUrl,
876
+ properties : [ this._propertyValue, this._propertyDescription ]
877
+ }
878
+ };
879
+
880
+ var oTable = this.oValueHelpDialog.getTable();
881
+ oTable.setThreshold(10);
882
+
883
+ for (var i = 0; i < mEntities.valueHelp.properties.length; i++) {
884
+ this._addValueHelpColumn(mEntities.valueHelp.properties[i], oTable);
885
+ }
886
+
887
+ var oModel = new sap.ui.model.odata.v2.ODataModel(basePath);
888
+ oTable.setModel(oModel);
889
+ oTable.bindRows(mEntities.valueHelp.collection, null, aFilterParams);
890
+ oTable.getBinding("rows").attachDataReceived(this._handleRowsDataReceived, this);
891
+ };
892
+
893
+ //handles the Busy State of the busy state for the data recieved.
894
+ ExpressionAdvanced.prototype._handleRowsDataReceived = function(oEvent) {
895
+ var that = this;
896
+ var data = oEvent.getParameter("data");
897
+ if (jQuery.isEmptyObject(data) || (data && data.results && data.results.length === 0)) {
898
+ this.oValueHelpDialog.getTable().setNoData(that.oBundle.getText("no_data"));
899
+ } else {
900
+ this.oValueHelpDialog.getTable().setNoData(that.oBundle.getText("searching"));
901
+ }
902
+ this.oValueHelpDialog.getTable().setBusy(false);
903
+ };
904
+
905
+ // Utility function to create columns for the table.
906
+ ExpressionAdvanced.prototype._addValueHelpColumn = function(oColumName, oTable) {
907
+ var oColumn = new sap.ui.table.Column().setLabel(new sap.m.Label({
908
+ text : oColumName
909
+ }));
910
+ if (oColumName === this._propertyValue) {
911
+ oColumn.setSortProperty(oColumName);
912
+ }
913
+ oTable.addColumn(oColumn.setTemplate(new sap.m.Text().bindProperty("text", oColumName)));
914
+ };
915
+
916
+ /*
917
+ * unBind the table Rows.
918
+ */
919
+ ExpressionAdvanced.prototype._unBindTable = function() {
920
+ var oTable = this.oValueHelpDialog.getTable();
921
+ oTable.destroyColumns();
922
+ oTable.unbindRows();
923
+
924
+ };
925
+
926
+
927
+ /*
928
+ * fetch the latest filter parmas depending on the filter or the search param set.
929
+ */
930
+ ExpressionAdvanced.prototype._fetchFilterParams = function(valueHelpInfo) {
931
+ var that = this;
932
+ var aSearchParams = [];
933
+ var aFilterParams = [ new sap.ui.model.Filter("AttributeId", sap.ui.model.FilterOperator.EQ, valueHelpInfo.metadata.attributeId),
934
+ new sap.ui.model.Filter("DataObjectId", sap.ui.model.FilterOperator.EQ, valueHelpInfo.metadata.dataObjectId),
935
+ new sap.ui.model.Filter("VocabularyId", sap.ui.model.FilterOperator.EQ, valueHelpInfo.metadata.vocabularyId) ];
936
+
937
+ var aFilters = this.oFilterBar.getFilters();
938
+ var searchParam = this.oFilterBar.getParameters();
939
+ //When both search and filter is selected
940
+ if (!jQuery.isEmptyObject(searchParam) && aFilters && aFilters.length > 0) {
941
+ searchParam = this.oFilterBar.getParameters().custom.search;
942
+ aSearchParams = this._getSearchFilters(searchParam);
943
+ aFilters = that._formatFilterParams(aFilters);
944
+ aFilterParams.push(new sap.ui.model.Filter({
945
+ filters : [ new sap.ui.model.Filter(aFilters), new sap.ui.model.Filter(aSearchParams) ],
946
+ and : true
947
+ }));
948
+ } else if (!jQuery.isEmptyObject(searchParam)) {
949
+ //when only Search is selected.
950
+ searchParam = this.oFilterBar.getParameters().custom.search;
951
+ aSearchParams = this._getSearchFilters(searchParam);
952
+ aFilterParams.push(aSearchParams);
953
+ } else if (aFilters && aFilters.length > 0) {
954
+ //When only filters is selected.
955
+ aFilters = that._formatFilterParams(aFilters);
956
+ aFilterParams.push(aFilters[0]);
957
+ }
958
+ return aFilterParams;
959
+ };
960
+
961
+ /*
962
+ * format the filterParams to support Contains and Between.
963
+ */
964
+ ExpressionAdvanced.prototype._formatFilterParams = function(aFilters) {
965
+ var that = this;
966
+ if (aFilters[0] && aFilters.length === 1 && aFilters[0].aFilters[0] && aFilters[0].aFilters[0].sOperator) {
967
+ aFilters = that._formatSingleFilter(aFilters);
968
+ } else if (aFilters[0] && aFilters[0].aFilters[0] && aFilters[0].aFilters[0].aFilters[0] && aFilters[0].aFilters[0].aFilters[0].aFilters && aFilters[0].aFilters[1].aFilters[0].aFilters) {
969
+ aFilters = that._formatMultiFilter(aFilters, 0, true);
970
+ aFilters = that._formatMultiFilter(aFilters, 1, true);
971
+
972
+ } else if (aFilters[0] && aFilters[0].aFilters[0] && aFilters[0].aFilters[1] && aFilters[0].aFilters[0].aFilters[0] && aFilters[0].aFilters[0].aFilters[0].aFilters && aFilters[0].aFilters[1].aFilters) {
973
+ aFilters = that._formatMultiFilter(aFilters, 0, true);
974
+ aFilters = that._formatMultiFilter(aFilters, 1, false);
975
+
976
+ } else if (aFilters[0] && aFilters[0].aFilters[0] && aFilters[0].aFilters[1] && aFilters[0].aFilters[1].aFilters[0] && aFilters[0].aFilters[0].aFilters && aFilters[0].aFilters[1].aFilters[0].aFilters) {
977
+ aFilters = that._formatMultiFilter(aFilters, 0, false);
978
+ aFilters = that._formatMultiFilter(aFilters, 1, true);
979
+
980
+ } else if (aFilters[0] && aFilters[0].aFilters[0] && aFilters[0].aFilters[1] && aFilters[0].aFilters[0].aFilters && aFilters[0].aFilters[1].aFilters) {
981
+ aFilters = that._formatMultiFilter(aFilters, 0, false);
982
+ aFilters = that._formatMultiFilter(aFilters, 1, false);
983
+
984
+ }
985
+
986
+ return aFilters;
987
+ };
988
+
989
+ ExpressionAdvanced.prototype._formatSingleFilter = function(aFilters) {
990
+ var that = this;
991
+ var _valueField = null;
992
+
993
+ for (var iterator = 0; iterator < aFilters[0].aFilters.length; iterator++) {
994
+ if (aFilters[0].aFilters[iterator].sOperator === "Contains") {
995
+ aFilters[0].aFilters[iterator].sOperator = "EQ";
996
+ } else if (aFilters[0].aFilters[iterator].sOperator === "BT") {
997
+
998
+ var convertedFilterParam = that._manageParam(aFilters[0].aFilters[iterator].sPath,aFilters[0].aFilters[iterator].sOperator,
999
+ aFilters[0].aFilters[iterator].oValue1, aFilters[0].aFilters[iterator].oValue2);
1000
+ delete aFilters[0].aFilters[iterator];
1001
+ aFilters[0].aFilters[iterator] = convertedFilterParam;
1002
+ } else if (aFilters[0].aFilters[iterator].sOperator === "StartsWith") {
1003
+ _valueField = (aFilters[0].aFilters[iterator].sPath === this._propertyValue) ? this._valueFieldValue : this._valueFieldDescription;
1004
+ _valueField.setValueState("Error");
1005
+ _valueField.setValueStateText(aFilters[0].aFilters[iterator].sOperator + " operator not supported");
1006
+ } else if (aFilters[0].aFilters[iterator].sOperator === "EndsWith") {
1007
+ _valueField = (aFilters[0].aFilters[iterator].sPath === this._propertyValue) ? this._valueFieldValue : this._valueFieldDescription;
1008
+ _valueField.setValueState("Error");
1009
+ _valueField.setValueStateText(aFilters[0].aFilters[iterator].sOperator + " operator not supported");
1010
+ }
1011
+
1012
+ }
1013
+ return aFilters;
1014
+
1015
+ };
1016
+ ExpressionAdvanced.prototype._formatMultiFilter = function(aFilters, index, bMultifilter) {
1017
+ var that = this;
1018
+ var _valueField = null;
1019
+ var aComputeFilterParma = [];
1020
+ if (bMultifilter) {
1021
+ aComputeFilterParma = aFilters[0].aFilters[index].aFilters[0].aFilters;
1022
+ } else {
1023
+ aComputeFilterParma = aFilters[0].aFilters[index].aFilters;
1024
+ }
1025
+ for (var iterator = 0; iterator < aComputeFilterParma.length; iterator++) {
1026
+ if (aComputeFilterParma[iterator].sOperator === "Contains") {
1027
+ aComputeFilterParma[iterator].sOperator = "EQ";
1028
+ } else if (aComputeFilterParma[iterator].sOperator === "BT") {
1029
+
1030
+ var convertedFilterParam = that._manageParam(aComputeFilterParma[iterator].sPath,aComputeFilterParma[iterator].sOperator,
1031
+ aComputeFilterParma[iterator].oValue1, aComputeFilterParma[iterator].oValue2);
1032
+ delete aComputeFilterParma[iterator];
1033
+ aComputeFilterParma[iterator] = convertedFilterParam;
1034
+
1035
+ } else if (aComputeFilterParma[iterator].sOperator === "StartsWith") {
1036
+ _valueField = (aComputeFilterParma[iterator].sPath === this._propertyValue) ? this._valueFieldValue : this._valueFieldDescription;
1037
+ _valueField.setValueState("Error");
1038
+ _valueField.setValueStateText(aComputeFilterParma[iterator].sOperator + " operator not supported");
1039
+ } else if (aComputeFilterParma[iterator].sOperator === "EndsWith") {
1040
+ _valueField = (aComputeFilterParma[iterator].sPath === this._propertyValue) ? this._valueFieldValue : this._valueFieldDescription;
1041
+ _valueField.setValueState("Error");
1042
+ _valueField.setValueStateText(aComputeFilterParma[iterator].sOperator + " operator not supported");
1043
+ }
1044
+ }
1045
+ return aFilters;
1046
+ };
1047
+
1048
+ /*
1049
+ * Converts the Between Operator to Less than and Equal to Operator.
1050
+ */
1051
+ ExpressionAdvanced.prototype._manageParam = function(sPath, operator, value1, value2) {
1052
+ var filterParam = [];
1053
+ if (value1 && value2) {
1054
+ filterParam = new sap.ui.model.Filter({
1055
+ filters : [ new sap.ui.model.Filter(sPath, sap.ui.model.FilterOperator.GT, value1),
1056
+ new sap.ui.model.Filter(sPath, sap.ui.model.FilterOperator.LT, value2) ],
1057
+ and : true
1058
+ });
1059
+ }
1060
+ return filterParam;
1061
+ };
1062
+
1063
+ // Utility function to form the search filter params.
1064
+ ExpressionAdvanced.prototype._getSearchFilters = function(searchParam) {
1065
+ return new sap.ui.model.Filter({
1066
+ filters : [ new sap.ui.model.Filter(this._propertyValue, sap.ui.model.FilterOperator.EQ, searchParam),
1067
+ new sap.ui.model.Filter(this._propertyDescription, sap.ui.model.FilterOperator.EQ, searchParam) ],
1068
+ and : false
1069
+ });
1070
+ };
1071
+
1072
+ ExpressionAdvanced.prototype.setValueStateFilter = function(oEvent) {
1073
+ var sId = oEvent.getSource().sId;
1074
+ this._valueFieldValue = sap.ui.getCore().byId(sId + "-filterItemControlA_-Value");
1075
+ if (this._valueFieldValue) {
1076
+ this._valueFieldValue.setValueState("None");
1077
+ this._valueFieldValue.setValueStateText("");
1078
+ }
1079
+ this._valueFieldDescription = sap.ui.getCore().byId(sId + "-filterItemControlA_-Description");
1080
+ if (this._valueFieldDescription) {
1081
+ this._valueFieldDescription.setValueState("None");
1082
+ this._valueFieldDescription.setValueStateText("");
1083
+ }
1084
+ };
1085
+
1086
+ /*
1087
+ * Callback fucntion event which is fired once the user clicked on 'ValueHelp' token link. onValueHelpLinkPress : create code mirror
1088
+ * search cursor based on the 'ValueList' token which has been clicked. Create Select Dialog display all 'ValueList' suggestions. @param
1089
+ * valueHelpText : 'ValueHelp' token text value. @param valueHelpId : ValueHelp Id of the token.
1090
+ */
1091
+ ExpressionAdvanced.prototype.onValueHelpLinkPress = function(valueHelpText, valueHelpId) {
1092
+ if (!this.getEditable()) {
1093
+ return;
1094
+ }
1095
+ var expressionLanguage = sap.ui.getCore().byId(this.getExpressionLanguage());
1096
+ var callback = expressionLanguage.getValueHelpCallback();
1097
+
1098
+ //build valueHelpInfo
1099
+ var tokens = this.getExpressionTokens();
1100
+ var i;
1101
+ var valueHelpInfo;
1102
+ var line = this.codeMirror.getCursor().line;
1103
+ var valueListPosition;
1104
+ for (i = 0; i < tokens.length; i++) {
1105
+ if (tokens[i].tokenType === 'valueList' && tokens[i].info && tokens[i].info.id === valueHelpId &&
1106
+ tokens[i].token === valueHelpText) {
1107
+ valueHelpInfo = [tokens[i].info];
1108
+ valueListPosition = tokens[i].end;
1109
+ break;
1110
+ }
1111
+ }
1112
+ var curPostion = {};
1113
+ curPostion.ch = valueListPosition;
1114
+ curPostion.line = line;
1115
+
1116
+ if ((typeof callback) === "function") {
1117
+
1118
+ callback.call(this, valueHelpInfo);
1119
+ var oModel = valueHelpInfo[0].model;
1120
+ if (!oModel.getMetaModel().oModel) {
1121
+ oModel.attachMetadataLoaded(function() {
1122
+ this._createValueHelpProvider(valueHelpInfo[0], true);
1123
+ }.bind(this));
1124
+ } else {
1125
+ this._createValueHelpProvider(valueHelpInfo[0], true);
1126
+ }
1127
+ } else if (valueHelpInfo && valueHelpInfo[0].metadata.hasOwnProperty(this._hasValueSource) && valueHelpInfo[0].metadata.HasValueSource ===
1128
+ true) {
1129
+ valueHelpInfo[0].expressionLanguage = expressionLanguage;
1130
+ this._createCpValueHelp(valueHelpInfo[0], curPostion, true, true);
1131
+ }
1132
+ };
1133
+
1134
+ ExpressionAdvanced.prototype._createSearchCursor = function(valueHelpText) {
1135
+ var cm = this.codeMirror;
1136
+ cm.getCursor().ch = cm.getCursor().ch + valueHelpText.length;
1137
+ var cursor = cm.getSearchCursor(valueHelpText, cm.getCursor(), typeof valueHelpText == "string" && valueHelpText == valueHelpText.toLowerCase());
1138
+ return cursor;
1139
+ };
1140
+
1141
+ ExpressionAdvanced.prototype.setTextOnCursor = function(sValue, cursorPosition, bReplaceWord, businessDataType, bAddSpace,
1142
+ bValuehelpLinkPress) {
1143
+
1144
+ function getNextLine(currentLine, arrLines) {
1145
+ // this function skips empty lines
1146
+ var nextLine = currentLine + 1;
1147
+ for (var j = nextLine; j < arrLines.length; j++) {
1148
+ if (arrLines[j].length === 0) {
1149
+ nextLine++;
1150
+ } else {
1151
+ break;
1152
+ }
1153
+ }
1154
+ return nextLine;
1155
+ }
1156
+
1157
+ var TYPE_STRING = "String",
1158
+ TYPE_DATE = "Date",
1159
+ TYPE_TIMESTAMP = "Timestamp",
1160
+ TYPE_TIME = "Time";
1161
+
1162
+ // inserting a new selection
1163
+ var cursorPos;
1164
+ var sFormatedValue = ((businessDataType === TYPE_STRING) ||
1165
+ (businessDataType === TYPE_DATE) ||
1166
+ (businessDataType === TYPE_TIMESTAMP) ||
1167
+ (businessDataType === TYPE_TIME)) ? "'" + sValue + "'" : sValue;
1168
+
1169
+ var tokens = this.getExpressionTokens();
1170
+ var lines = this.getValue().split("\n");
1171
+ var line = -1;
1172
+ var oToken = {
1173
+ start: {
1174
+ line: cursorPosition.line,
1175
+ ch: cursorPosition.ch
1176
+ },
1177
+ end: {
1178
+ line: cursorPosition.line,
1179
+ ch: cursorPosition.ch
1180
+ }
1181
+ };
1182
+ for (var i = 0; i < tokens.length; i++) {
1183
+ line = (tokens[i].start === 0) ? getNextLine(line, lines) : line;
1184
+ if (line === cursorPosition.line && (tokens[i].end > cursorPosition.ch) || (tokens[i].end >= cursorPosition.ch && bValuehelpLinkPress)) {
1185
+ oToken.start.ch = tokens[i].start;
1186
+ oToken.end.ch = tokens[i].end;
1187
+ bReplaceWord = true;
1188
+ break;
1189
+ }
1190
+ }
1191
+ if (bReplaceWord) {
1192
+ this.codeMirror.replaceRange(sFormatedValue, oToken.start, oToken.end); // replace the selection
1193
+ cursorPos = this.codeMirror.findPosH(oToken.start, sFormatedValue.length, "char", true);
1194
+ this.codeMirror.setCursor(cursorPos); // set the cursor at the end of the word
1195
+ } else {
1196
+ sFormatedValue = bAddSpace ? " " + sFormatedValue : sFormatedValue;
1197
+ this.codeMirror.replaceRange(sFormatedValue, cursorPosition); // insert the selection
1198
+ cursorPos = this.codeMirror.findPosH(cursorPosition, sFormatedValue.length, "char", true);
1199
+ this.codeMirror.setCursor(cursorPos); // set the cursor past the new selection
1200
+ }
1201
+ var oExpressionLanguage = sap.ui.getCore().byId(this.getExpressionLanguage());
1202
+ this.getFormattingTokens(oExpressionLanguage);
1203
+ this.ValueHelpRequested = false;
1204
+ };
1205
+
1206
+ ExpressionAdvanced.prototype._setCodeMirror = function() {
1207
+ var editable = this.getEditable();
1208
+ var attributeInfo;
1209
+ if ("getAttributeInfo" in this && this.getAttributeInfo()) {
1210
+ attributeInfo = this.getAttributeInfo();
1211
+ }
1212
+ var expressionLanguage = sap.ui.getCore().byId(this.getExpressionLanguage());
1213
+ var valueListAttribute;
1214
+ if (attributeInfo) {
1215
+ valueListAttribute = expressionLanguage.getValueListAttribute(attributeInfo);
1216
+ }
1217
+
1218
+ function autoComplete(cm, commandName, timeout) {
1219
+ var oAdvancedExpressionEditor = cm.options.expressionEditor;
1220
+ if ((oAdvancedExpressionEditor.getEditable() !== false) && sap.ui.getCore().byId(oAdvancedExpressionEditor.getExpressionLanguage())) {
1221
+ window.clearTimeout(oAdvancedExpressionEditor.timer);
1222
+ oAdvancedExpressionEditor.timer = window.setTimeout(function() {
1223
+ cm.execCommand(commandName);
1224
+ }, timeout);
1225
+ return window.CodeMirror.Pass; // tell CodeMirror we didn't handle the key
1226
+ }
1227
+ return null;
1228
+ }
1229
+
1230
+ function ordinaryKeyCallback(cm) {
1231
+ var oAdvancedExpressionEditor = cm.options.expressionEditor;
1232
+ if (oAdvancedExpressionEditor.getEditable() !== false) {
1233
+ window.clearTimeout(oAdvancedExpressionEditor.timer);
1234
+ oAdvancedExpressionEditor.needAutoComplete = true;
1235
+ oAdvancedExpressionEditor.timer = window.setTimeout(function() {
1236
+ if (oAdvancedExpressionEditor.needAutoComplete && sap.ui.getCore().byId(oAdvancedExpressionEditor.getExpressionLanguage())) {
1237
+ cm.execCommand("autocomplete");
1238
+ }
1239
+ }, 500);
1240
+ return window.CodeMirror.Pass; // tell CodeMirror we didn't handle the key
1241
+ }
1242
+ return null;
1243
+ }
1244
+
1245
+ function enterKeyCallback(cm) {
1246
+ return autoComplete(cm, "enterAutocomplete", 500);
1247
+ }
1248
+
1249
+ function colonKeyCallback(cm) {
1250
+ return autoComplete(cm, "colonAutocomplete", 500);
1251
+ }
1252
+
1253
+ function ctrlSpaceKeysCallback(cm) {
1254
+ autoComplete(cm, "autocomplete", 0);
1255
+ }
1256
+
1257
+ /*
1258
+ * SPACE is use for both opening the hints, and closing them if writing a non-existent expression.
1259
+ * As such, it is separated from the common ordinaryKeyCallback() key handling.
1260
+ * If not so, it alternately opens the hints every 2nd press. Example flow:
1261
+ * press SPACE:
1262
+ * 1. ordinaryKeyCallback() sets the timeout
1263
+ * 2. ordinaryKeyCallback() delayed opening of hints
1264
+ * press SPACE (not in one of the hints):
1265
+ * 1. ordinaryKeyCallback() sets the timeout
1266
+ * 2. _handleEndCodeCompletion sets needAutoComplete as false (event coming from CodeMirror hints)
1267
+ * 3. ordinaryKeyCallback() delayed opening of hints - not opening the hints as needAutoComplete is false
1268
+ * **/
1269
+ function spaceKeyCallback(cm) {
1270
+ return autoComplete(cm, "autocomplete", 500);
1271
+ }
1272
+
1273
+ function valueHelpCallback(cm) {
1274
+ var oAdvancedExpressionEditor = cm.options.expressionEditor;
1275
+ var input = cm.getRange({
1276
+ line: 0,
1277
+ ch: 0
1278
+ }, cm.getCursor());
1279
+ if (cm.options.headerValue) {
1280
+ var prefix = cm.options.headerValue + " ";
1281
+ if (cm.options.fixedOperator) {
1282
+ prefix = prefix + cm.options.fixedOperator + " ";
1283
+ }
1284
+ input = prefix + input;
1285
+ }
1286
+ var autoSuggestions = cm.options.relDelegate.getSuggestions(
1287
+ input,
1288
+ cm.options.returnType,
1289
+ cm.options.collection);
1290
+ var suggestions;
1291
+ if (autoSuggestions && autoSuggestions.hasOwnProperty("suggs") && autoSuggestions.suggs.length > 0) {
1292
+ suggestions = autoSuggestions.suggs;
1293
+ for (var i = 0; i < suggestions.length; i++) {
1294
+ if (suggestions[i].tokenType === 'valueList' && suggestions[i].info.metadata.hasOwnProperty(oAdvancedExpressionEditor._hasValueSource)) {
1295
+ oAdvancedExpressionEditor._createCpValueHelp(suggestions[i].info, cm.getCursor(), false);
1296
+ }
1297
+ }
1298
+ }
1299
+ }
1300
+
1301
+ this.keyMap = {
1302
+ "Tab": false,
1303
+ "Shift-Tab": false,
1304
+ "Ctrl-Space": ctrlSpaceKeysCallback,
1305
+ "Backspace": ordinaryKeyCallback,
1306
+ "Enter": enterKeyCallback,
1307
+ "':'": colonKeyCallback,
1308
+ "'+'": ordinaryKeyCallback,
1309
+ "'-'": ordinaryKeyCallback,
1310
+ "'*'": ordinaryKeyCallback,
1311
+ "'/'": ordinaryKeyCallback,
1312
+ "'_'": ordinaryKeyCallback,
1313
+ "'o'": ordinaryKeyCallback,
1314
+ "'q'": ordinaryKeyCallback,
1315
+ "'w'": ordinaryKeyCallback,
1316
+ "'e'": ordinaryKeyCallback,
1317
+ "'r'": ordinaryKeyCallback,
1318
+ "'t'": ordinaryKeyCallback,
1319
+ "'y'": ordinaryKeyCallback,
1320
+ "'u'": ordinaryKeyCallback,
1321
+ "'i'": ordinaryKeyCallback,
1322
+ "'p'": ordinaryKeyCallback,
1323
+ "'.'": ordinaryKeyCallback,
1324
+ "'a'": ordinaryKeyCallback,
1325
+ "'s'": ordinaryKeyCallback,
1326
+ "'d'": ordinaryKeyCallback,
1327
+ "'f'": ordinaryKeyCallback,
1328
+ "'g'": ordinaryKeyCallback,
1329
+ "'h'": ordinaryKeyCallback,
1330
+ "'j'": ordinaryKeyCallback,
1331
+ "'k'": ordinaryKeyCallback,
1332
+ "'l'": ordinaryKeyCallback,
1333
+ "'z'": ordinaryKeyCallback,
1334
+ "'x'": ordinaryKeyCallback,
1335
+ "'c'": ordinaryKeyCallback,
1336
+ "'v'": ordinaryKeyCallback,
1337
+ "'b'": ordinaryKeyCallback,
1338
+ "'n'": ordinaryKeyCallback,
1339
+ "'m'": ordinaryKeyCallback,
1340
+ "'O'": ordinaryKeyCallback,
1341
+ "'Q'": ordinaryKeyCallback,
1342
+ "'W'": ordinaryKeyCallback,
1343
+ "'E'": ordinaryKeyCallback,
1344
+ "'R'": ordinaryKeyCallback,
1345
+ "'T'": ordinaryKeyCallback,
1346
+ "'Y'": ordinaryKeyCallback,
1347
+ "'U'": ordinaryKeyCallback,
1348
+ "'I'": ordinaryKeyCallback,
1349
+ "'P'": ordinaryKeyCallback,
1350
+ "'A'": ordinaryKeyCallback,
1351
+ "'S'": ordinaryKeyCallback,
1352
+ "'D'": ordinaryKeyCallback,
1353
+ "'F'": ordinaryKeyCallback,
1354
+ "'G'": ordinaryKeyCallback,
1355
+ "'H'": ordinaryKeyCallback,
1356
+ "'J'": ordinaryKeyCallback,
1357
+ "'K'": ordinaryKeyCallback,
1358
+ "'L'": ordinaryKeyCallback,
1359
+ "'Z'": ordinaryKeyCallback,
1360
+ "'X'": ordinaryKeyCallback,
1361
+ "'C'": ordinaryKeyCallback,
1362
+ "'V'": ordinaryKeyCallback,
1363
+ "'B'": ordinaryKeyCallback,
1364
+ "'N'": ordinaryKeyCallback,
1365
+ "'M'": ordinaryKeyCallback,
1366
+ "'0'": false,
1367
+ "'1'": false,
1368
+ "'2'": false,
1369
+ "'3'": false,
1370
+ "'4'": false,
1371
+ "'5'": false,
1372
+ "'6'": false,
1373
+ "'7'": false,
1374
+ "'8'": false,
1375
+ "'9'": false,
1376
+ "' '": spaceKeyCallback,
1377
+ "F4": valueHelpCallback
1378
+ };
1379
+
1380
+ function keyMapping(oAdvancedExpressionEditor) {
1381
+ return oAdvancedExpressionEditor.keyMap;
1382
+ }
1383
+
1384
+ if (this.expressionTokens.length === 0) {
1385
+ var oEL = sap.ui.getCore().byId(this.getExpressionLanguage());
1386
+ if (oEL) {
1387
+ this.getFormattingTokens(oEL);
1388
+ }
1389
+ }
1390
+ var keyMap = keyMapping(this);
1391
+ var textAreaId = this.oTextArea.getId() + '-inner';
1392
+ var isMSIE = (Utils.msieversion() >= 0);
1393
+ if (isMSIE) {
1394
+ jQuery('#' + textAreaId).attr('placeholder', this.getProperty('placeholder'));
1395
+ }
1396
+ this.codeMirror = window.CodeMirror.fromTextArea(document.getElementById(textAreaId), {
1397
+ mode: "text/hdf",
1398
+ lineNumbers: false,
1399
+ lineWrapping: true,
1400
+ matchBrackets: editable === true ? true : false,
1401
+ highlightSelectionMatches: editable === true ? {
1402
+ showToken: /\w/
1403
+ } : {},
1404
+ relDelegate: expressionLanguage,
1405
+ returnType: this.getProperty("type"),
1406
+ collection: this.getProperty("collection"),
1407
+ valueListAttribute: valueListAttribute,
1408
+ expressionEditor: this,
1409
+ stillNeedShowHint: true,
1410
+ shouldValidate: true,
1411
+ styleSelectedText: true,
1412
+ smartIndent: true,
1413
+ autoCloseBrackets: true,
1414
+ indentUnit: 6
1415
+ });
1416
+ this.codeMirror.addKeyMap(keyMap, true);
1417
+
1418
+ // //In order to support aliases - we must reset the aliases after initialization of codeMirror object
1419
+ // if (window.CodeMirror.mimeModes.hasOwnProperty('text/hdf'))
1420
+ // window.CodeMirror.mimeModes['text/hdf'].aliases = me.getRelDelegate().vocabualryAliasesNames;
1421
+ };
1422
+
1423
+ ExpressionAdvanced.prototype.getFormattingTokens = function(oExpressionLanguage) {
1424
+ this.tokens = [];
1425
+ this.valueListAttrInfo = oExpressionLanguage.getValueListAttribute(this.mProperties.attributeInfo);
1426
+ var exprssionMetadata = oExpressionLanguage.getExpressionMetadata(this._liveValue);
1427
+ if (exprssionMetadata) {
1428
+ this.tokens = exprssionMetadata.tokens;
1429
+ }
1430
+ if (oExpressionLanguage._hasValueSource && this.valueListAttrInfo) {
1431
+ this.newExpression = this.valueListAttrInfo.navPath + " " + Constants.IS_EQUAL_TO + " " + this._liveValue;
1432
+ exprssionMetadata = oExpressionLanguage.getExpressionMetadata(this.newExpression);
1433
+ if (exprssionMetadata) {
1434
+ var tokensWithPath = exprssionMetadata.tokens;
1435
+ for (var tokenPos = 0; tokenPos < tokensWithPath.length; tokenPos++) {
1436
+ for (var pos = 0; pos < this.tokens.length; pos++) {
1437
+ if (tokensWithPath[tokenPos].tokenType === "valueList" && tokensWithPath[tokenPos].token === this.tokens[pos].token) {
1438
+ this.tokens[pos].info = tokensWithPath[tokenPos].info;
1439
+ this.tokens[pos].tokenType = tokensWithPath[tokenPos].tokenType;
1440
+ }
1441
+ }
1442
+
1443
+ }
1444
+ }
1445
+ }
1446
+ this.setExpressionTokens(this.tokens);
1447
+ };
1448
+
1449
+ ExpressionAdvanced.prototype._setEditorStyle = function() {
1450
+ //We added to the codeMirror code (see codeMirror.js) styles class derived from SAPUI5
1451
+ //Set CSS style to the new added codemirror control - according to SAPUI5 textField CSS
1452
+ //sapUiTf sapUiTfBack sapUiTfBrd sapUiTfStd sapUiTxtA
1453
+
1454
+ //We need to mimic the way input control is being used in sapui5 which means:
1455
+ //level 1: sapMInput sapMInputBase
1456
+ //level 2: sapMInputBaseInner
1457
+ if (this.getValueStateText() && this.getValueStateText() !== "") {
1458
+ jQuery(this.codeMirror.getWrapperElement()).addClass('CodeMirror-error');
1459
+ jQuery(this.codeMirror.getWrapperElement()).addClass('sapMInputBaseStateInner sapMInputBaseErrorInner sapMInputBaseContentWrapper sapMInputBaseContentWrapperState sapMInputBaseContentWrapperError');
1460
+ jQuery('#' + this.oTextArea.getId()).addClass('sapMInputBaseError');
1461
+ }
1462
+ jQuery('#' + this.oTextArea.getId()).removeClass().addClass('sapMInput'); //sapMInputBase
1463
+ jQuery(this.codeMirror.getWrapperElement()).addClass('sapMInputBaseInner CodeMirror-rules');
1464
+ if (!this.getEditable()) {
1465
+ jQuery(this.codeMirror.getWrapperElement()).addClass('CodeMirror-rules-Not-Editable');
1466
+ } else {
1467
+ jQuery(this.codeMirror.getWrapperElement()).removeClass('CodeMirror-rules-Not-Editable');
1468
+ }
1469
+
1470
+ // bug fix - without it the height of codeMirror to big --> cause to wrong cursor positioning
1471
+ if (this.codeMirror) {
1472
+ this.codeMirror.refresh();
1473
+ }
1474
+ };
1475
+
1476
+ ExpressionAdvanced.prototype._handleOnLoadValidation = function() {
1477
+ if (this.getValidateOnLoad()) {
1478
+ this.validateExpression();
1479
+ this.setValidateOnLoad(false);
1480
+ }
1481
+ };
1482
+
1483
+ ExpressionAdvanced.prototype._handleEditableProperty = function() {
1484
+ if (this.getEditable() === false) {
1485
+ this.codeMirror.setOption("readOnly", "true");
1486
+ this.codeMirror.setOption("theme", "read-only");
1487
+ }
1488
+ };
1489
+
1490
+ ExpressionAdvanced.prototype._handleFocus = function() {
1491
+ var oCodeMirror = this.codeMirror;
1492
+ if (this.getFocusOnLoad()) {
1493
+ this.focus();
1494
+ }
1495
+ this.codeMirror.on("focus", function(cm, change) {
1496
+ var errorMessage = cm.options.expressionEditor.getProperty("valueStateText");
1497
+ if (errorMessage && errorMessage !== "") {
1498
+ cm.options.expressionEditor._showPopUp();
1499
+ }
1500
+ cm.options.stillNeedShowHint = true;
1501
+ jQuery('#' + cm.options.expressionEditor.oTextArea.getId()).addClass('sapMInputFocused');
1502
+ jQuery(cm.getWrapperElement()).removeClass('CodeMirror-errorBackground');
1503
+ });
1504
+
1505
+ if (this.dataModel.getProperty("/focus") === true) {
1506
+ window.setTimeout(function() {
1507
+ var lastLine = oCodeMirror.getLine(oCodeMirror.lastLine());
1508
+ var cursorPos = lastLine.length;
1509
+ oCodeMirror.setCursor({
1510
+ line: oCodeMirror.lastLine(),
1511
+ ch: cursorPos
1512
+ });
1513
+ //oCodeMirror.focus();
1514
+ }, 10);
1515
+ }
1516
+ };
1517
+
1518
+ ExpressionAdvanced.prototype._refreshOnNavigationEnd = function() {
1519
+ jQuery(".sapMNav").on('webkitTransitionEnd oTransitionEnd transitionend msTransitionEnd', jQuery.proxy(_refreshCodemirror, this));
1520
+
1521
+ function _refreshCodemirror() {
1522
+ if (this.codeMirror) {
1523
+ this.codeMirror.refresh();
1524
+ }
1525
+ }
1526
+
1527
+ };
1528
+
1529
+ ExpressionAdvanced.prototype._handleKeyPress = function() {
1530
+ this.codeMirror.on("keyHandled", function(cm, key, event) {
1531
+ if (event.keyCode === 27 && this && this.endCompletion === true) {
1532
+ event.stopPropagation();
1533
+ this.endCompletion = false;
1534
+ }
1535
+ if (event.ctrlKey === true && key === "Ctrl-A") {
1536
+ event.stopPropagation();
1537
+ }
1538
+ });
1539
+ };
1540
+
1541
+ ExpressionAdvanced.prototype._handleEndCodeCompletion = function() {
1542
+ this.codeMirror.on("endCompletion", function(cm) {
1543
+ cm.options.expressionEditor.needAutoComplete = false;
1544
+ cm.options.expressionEditor.endCompletion = !cm.options.expressionEditor.endCompletion;
1545
+ });
1546
+ };
1547
+
1548
+ ExpressionAdvanced.prototype._handleMousedown = function() {
1549
+ this.codeMirror.on("mousedown", function(cm, event) {
1550
+
1551
+ //Once user click on 'ValueList' token
1552
+ event.stopPropagation();
1553
+
1554
+ var target = event.target || event.srcElement;
1555
+
1556
+ if (target && event.button === 0) {
1557
+ var classList = target.className.split(/\s+/);
1558
+
1559
+ for (var i = 0; i < classList.length; i++) {
1560
+ if (classList[i] === 'cm-valuehelp') {
1561
+ var valueHelpId = classList[++i].split('-valuehelpid-')[1];
1562
+ //vlaueHelpPopUp
1563
+ cm.options.expressionEditor.onValueHelpLinkPress(target.textContent, valueHelpId);
1564
+ }
1565
+ }
1566
+ }
1567
+ });
1568
+ };
1569
+
1570
+ /*
1571
+ /!*
1572
+ * Get complete token string from tokens cached array
1573
+ * @param selectedValueList - selected html element outerHTML, contain only partaily token value
1574
+ * @param oControll expression editor instance
1575
+ * @returns complete token string
1576
+ *!/
1577
+ ExpressionAdvanced.prototype._getValueListToken = function (selectedValueList, oControll){
1578
+ var tokens = oControll.getExpressionTokens();
1579
+ var tokensLength = tokens.length;
1580
+ for (var index = 0; index < tokensLength; index++){
1581
+ if (tokens[index].token.indexOf(selectedValueList) > -1){
1582
+ return tokens[index].token;
1583
+ }
1584
+ }
1585
+ return null;
1586
+ };*/
1587
+
1588
+ ExpressionAdvanced.prototype._handleChange = function() {
1589
+ this.codeMirror.on("change", function(cm, change) {
1590
+ var oAdvancedExpressionEditor = cm.options.expressionEditor;
1591
+ if (oAdvancedExpressionEditor.codeMirror.state.completionActive && oAdvancedExpressionEditor.keyMap["'" + change.text[0] + "'"] ===
1592
+ false) {
1593
+ oAdvancedExpressionEditor.codeMirror.state.completionActive.close();
1594
+ }
1595
+
1596
+ jQuery(oAdvancedExpressionEditor.codeMirror.getWrapperElement()).removeClass('CodeMirror-error');
1597
+ jQuery(oAdvancedExpressionEditor.codeMirror.getWrapperElement()).removeClass('sapMInputBaseStateInner sapMInputBaseErrorInner sapMInputBaseContentWrapper sapMInputBaseContentWrapperState sapMInputBaseContentWrapperError');
1598
+ oAdvancedExpressionEditor._liveValue = cm.getValue();
1599
+
1600
+ var oEL = sap.ui.getCore().byId(oAdvancedExpressionEditor.getExpressionLanguage());
1601
+ if (oEL) {
1602
+ oAdvancedExpressionEditor.getFormattingTokens(oEL);
1603
+ }
1604
+
1605
+ oAdvancedExpressionEditor.codeMirror.options.shouldValidate = true;
1606
+ oAdvancedExpressionEditor.fireLiveChange({
1607
+ newValue: cm.getValue()
1608
+ });
1609
+ // we dont indent on delete
1610
+ if (change.origin !== "+delete") {
1611
+ cm.operation(function() {
1612
+ for (var line = 0, end = cm.lineCount(); line < end; ++line) {
1613
+ cm.indentLine(line, "smart");
1614
+ }
1615
+ });
1616
+ }
1617
+ });
1618
+ };
1619
+
1620
+ ExpressionAdvanced.prototype._handleFocusLeave = function() {
1621
+ this.codeMirror.on("blur", function(cm) {
1622
+ var oAdvancedExpressionEditor = cm.options.expressionEditor;
1623
+ oAdvancedExpressionEditor._closePopUp();
1624
+ oAdvancedExpressionEditor.codeMirror.options.stillNeedShowHint = false;
1625
+
1626
+ // shouldValidate flag indicates:
1627
+ // - this is real focus leave, not because of click on Hint
1628
+ // - value was changed while the control was in focus
1629
+ // - oAdvancedExpressionEditor.bFlagForPreventBlurWhenPopOverOpen see bug 4810
1630
+ if (oAdvancedExpressionEditor.codeMirror.options.shouldValidate && !oAdvancedExpressionEditor.bFlagForPreventBlurWhenPopOverOpen) {
1631
+ oAdvancedExpressionEditor.setValue(oAdvancedExpressionEditor.codeMirror.getValue());
1632
+ //if (oAdvancedExpressionEditor.getProperty("automaticValidation")){
1633
+ if (!(oAdvancedExpressionEditor instanceof sap.rules.ui.DecisionTableCellExpressionAdvanced)) {
1634
+ oAdvancedExpressionEditor.validate();
1635
+ }
1636
+ oAdvancedExpressionEditor._closePopUp();
1637
+ //}
1638
+ oAdvancedExpressionEditor.fireChange({
1639
+ newValue: cm.getValue()
1640
+ });
1641
+ oAdvancedExpressionEditor.codeMirror.options.shouldValidate = false;
1642
+ }
1643
+ jQuery('#' + oAdvancedExpressionEditor.oTextArea.getId()).removeClass('sapMInputFocused');
1644
+ oAdvancedExpressionEditor.dataModel.setProperty("/focus", false);
1645
+ });
1646
+ };
1647
+
1648
+ ExpressionAdvanced.prototype._setExpressionErrorStyle = function() {
1649
+ var errorMsg = this.getProperty("valueStateText");
1650
+ if (errorMsg !== "" && errorMsg !== undefined && this.codeMirror) {
1651
+ jQuery(this.codeMirror.getWrapperElement()).addClass('CodeMirror-error');
1652
+ jQuery(this.codeMirror.getWrapperElement()).addClass('sapMInputBaseStateInner sapMInputBaseErrorInner sapMInputBaseContentWrapper sapMInputBaseContentWrapperState sapMInputBaseContentWrapperError');
1653
+ jQuery('#' + this.oTextArea.getId()).addClass('sapMInputBaseError');
1654
+
1655
+ // Position the cursor within the control
1656
+ var cursorPos;
1657
+ if (this.errorCursorPosition < 0) {
1658
+ var lastLine = this.codeMirror.getLine(this.codeMirror.lastLine());
1659
+ cursorPos = lastLine.length;
1660
+ //this.codeMirror.setCursor({line: lastLine, ch: cursorPos});
1661
+ jQuery(this.codeMirror.getWrapperElement()).addClass('CodeMirror-errorBackground');
1662
+ } else {
1663
+ var idx = errorMsg.lastIndexOf("'");
1664
+ if (idx > 0) {
1665
+ var offendingText = errorMsg.substring(0, idx);
1666
+ idx = offendingText.lastIndexOf("'");
1667
+ if (idx > 0) {
1668
+ offendingText = offendingText.substring(idx + 1);
1669
+ }
1670
+ var found = false;
1671
+ for (var lineNum = this.codeMirror.lastLine(); !found && lineNum >= 0; lineNum--) {
1672
+ var exp = this.codeMirror.getLine(lineNum);
1673
+ cursorPos = exp.lastIndexOf(offendingText);
1674
+ if (cursorPos >= 0) {
1675
+ found = true;
1676
+ this.codeMirror.setSelection({
1677
+ line: lineNum,
1678
+ ch: cursorPos
1679
+ }, {
1680
+ line: lineNum,
1681
+ ch: cursorPos + offendingText.length
1682
+ });
1683
+ }
1684
+ }
1685
+ }
1686
+ }
1687
+ }
1688
+ };
1689
+
1690
+ /* ExpressionAdvanced.prototype.createAliasFromTextMenu = function (e){
1691
+
1692
+ // build context menu
1693
+ this.oContextMenu = new sap.m.ActionSheet();
1694
+
1695
+ //Create the items and add them to the menu
1696
+ var oMenuItemSaveAsAlias = new Button({
1697
+ text: this.oBundle.getText("SAVE_AS_ALIAS")
1698
+ });
1699
+ oMenuItemSaveAsAlias.attachPress(function (){
1700
+ // concat text of all elements
1701
+ var text = this.getSelectedText();
1702
+ this.onCreateAliasLinkForText(text);
1703
+ });
1704
+ this.oContextMenu.addButton(oMenuItemSaveAsAlias);
1705
+ };*/
1706
+
1707
+ ExpressionAdvanced.prototype.getSelectedText = function() {
1708
+ return this.codeMirror.getSelection();
1709
+ };
1710
+
1711
+ /* ExpressionAdvanced.prototype.openAliasFromTextMenu = function (e){
1712
+ window.setTimeout(function (){
1713
+ if (this.codeMirror.getSelection() !== ""){
1714
+ if (!this.oContextMenu){
1715
+ this.createAliasFromTextMenu(e);
1716
+ }
1717
+ this.oContextMenu.openBy(jQuery('#' + this.getId() + " .CodeMirror .CodeMirror-selectedtext")[0]);
1718
+ } else if (this.oContextMenu && this.oContextMenu.isOpen()){
1719
+ this.oContextMenu.close();
1720
+ }
1721
+
1722
+ }, 300);
1723
+ };*/
1724
+ ExpressionAdvanced.prototype.exit = function() {
1725
+ document.removeEventListener("mousedown", this.fnMouseDownListsner, true);
1726
+ };
1727
+ return ExpressionAdvanced;
1728
+
1729
+ }, /* bExport= */ true);