@sapui5/sap.rules.ui 1.107.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,2157 +1,2160 @@
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 this._validatecontrol sap.rules.ui.
9
- sap.ui.define([
10
- "sap/base/Log",
11
- "jquery.sap.global",
12
- "./library",
13
- "sap/rules/ui/DecisionTableCell",
14
- "sap/rules/ui/RuleBase",
15
- "sap/rules/ui/Utils",
16
- "sap/ui/table/Table",
17
- "sap/ui/table/Column",
18
- "sap/m/OverflowToolbar",
19
- "sap/m/Popover",
20
- "sap/m/Menu",
21
- "sap/m/Dialog",
22
- "sap/m/MenuButton",
23
- "sap/m/Button",
24
- "sap/m/ToolbarSpacer",
25
- "sap/m/Text",
26
- "sap/m/Input",
27
- "sap/m/ObjectIdentifier",
28
- "sap/m/Link",
29
- "sap/m/Label",
30
- "sap/m/BusyIndicator",
31
- "sap/m/DisplayListItem",
32
- "sap/m/MenuItem",
33
- "sap/m/FlexBox",
34
- "sap/m/MessageStrip",
35
- "sap/rules/ui/DecisionTableSettingsOld",
36
- "sap/rules/ui/type/DecisionTableCell",
37
- "sap/rules/ui/ast/constants/Constants",
38
- "sap/rules/ui/services/AstExpressionLanguage",
39
- "sap/rules/ui/ast/util/AstUtil",
40
- "sap/rules/ui/Constants",
41
- "sap/ui/core/LocaleData"
42
-
43
- ], function (Log, jQuery, library, DecisionTableCell, RuleBase, Utils, Table, Column, OverflowToolbar, Popover, Menu, Dialog, MenuButton, Button,
44
- ToolbarSpacer, Text, Input, ObjectIdentifier, Link, Label, BusyIndicator, DisplayListItem, MenuItem, FlexBox, MessageStrip,
45
- DecisionTableSettingsOld, DecisionTableCellFormatter, ConstantUtils, AstExpressionLanguage, AstUtil, Constants, LocaleData) {
46
-
47
- "use strict";
48
-
49
- /**
50
- * Constructor for a new DecisionTable Control.
51
- *
52
- * @param {string} [sId] id for the new control, generated automatically if no id is given
53
- * @param {object} [mSettings] initial settings for the new control
54
- *
55
- * @class
56
- * Some class description goes here.
57
- * @extends Control
58
- *
59
- * @author SAP SE
60
- * @version 1.107.0
61
- *
62
- * @constructor
63
- * @private
64
- * @alias sap.rules.ui.DecisionTable
65
- * @ui5-metamodel This control/element also will be described in the UI5 (legacy) design time meta model
66
- */
67
-
68
- var dataPartName = {
69
- vocabulary: "vocabulary",
70
- rule: "rule",
71
- columns: "columns",
72
- rows: "rows"
73
- };
74
-
75
- var emptyTable = 3;
76
-
77
- var oDecisionTable = RuleBase.extend("sap.rules.ui.DecisionTable", {
78
- metadata: {
79
- properties: {
80
- enableSettings: {
81
- type: "boolean",
82
- group: "Misc",
83
- defaultValue: false
84
- },
85
- enableSettingResult: {
86
- type: "boolean",
87
- defaultValue: true
88
- },
89
- cellFormat: {
90
- type: "sap.rules.ui.DecisionTableCellFormat",
91
- defaultValue: sap.rules.ui.DecisionTableCellFormat.Both
92
- },
93
- hitPolicies: {
94
- type: "sap.rules.ui.RuleHitPolicy[]",
95
- defaultValue: [sap.rules.ui.RuleHitPolicy.FirstMatch, sap.rules.ui.RuleHitPolicy.AllMatch]
96
- },
97
- lineActionBuffer: {
98
- type: "any",
99
- defaultValue: {
100
- rowPath: null,
101
- operation: null
102
- }
103
- },
104
- decisionTableFormat: {
105
- type: "sap.rules.ui.DecisionTableFormat",
106
- defaultValue: sap.rules.ui.DecisionTableFormat.CellFormat
107
- },
108
- threshold: {
109
- type: "int",
110
- defaultValue: 999
111
- },
112
- visibleRowCount: {
113
- type: "int",
114
- defaultValue: 999
115
- }
116
- },
117
- aggregations: {
118
- "_toolbar": {
119
- type: "sap.m.OverflowToolbar",
120
- multiple: false,
121
- singularName: "_toolbar"
122
- },
123
- "_table": {
124
- type: "sap.ui.core.Control",
125
- multiple: false,
126
- singularName: "_table"
127
- },
128
- "_errorsText": {
129
- type: "sap.m.MessageStrip", //"sap.m.Text",
130
- multiple: false,
131
- singularName: "_errorsText"
132
- }
133
- },
134
- associations: {
135
- /**
136
- * Association to controls / IDs which label this control (see WAI-ARIA attribute <code>aria-labelledby</code>).
137
- */
138
- ariaLabelledBy: {
139
- type: "sap.ui.core.Control",
140
- multiple: true,
141
- singularName: "ariaLabelledBy"
142
- },
143
- ariaRoleDescription: {
144
- type: "sap.ui.core.Control",
145
- multiple: true,
146
- singularName: "ariaRoleDescription"
147
- }
148
- }
149
- },
150
-
151
- _addErrorLabel: function () {
152
- //var oErrorLabel = new sap.m.Text().addStyleClass("sapThemeCriticalText").addStyleClass("sapUiSmallMargin");
153
- var oErrorLabel = new MessageStrip({
154
- showCloseButton: true,
155
- showIcon: true,
156
- type: sap.ui.core.MessageType.Error,
157
- visible: false
158
- }).addStyleClass("sapUiTinyMargin");
159
- this.setAggregation("_errorsText", oErrorLabel, true);
160
- },
161
-
162
- _addNewRow: function (selectedRow, bFirst) {
163
- var oMenu = this.oMenu;
164
- if (oMenu) {
165
- oMenu.close();
166
- }
167
- var oModel = this._getModel();
168
- var columns = this.dataBucket.columns && this.dataBucket.columns.results;
169
- if (!oModel || !columns) {
170
- return;
171
- }
172
- var oTable = this.getAggregation("_table"),
173
- oContext = this.getBindingContext(),
174
- sRuleId = oContext.getProperty("Id"),
175
- sVersion = oContext.getProperty("Version");
176
- var oRowData = {
177
- RuleId: sRuleId,
178
- Version: sVersion
179
- };
180
- selectedRow = selectedRow || 0;
181
- var rowPath;
182
- if (bFirst) {
183
- oRowData.Sequence = 1;
184
- } else {
185
- rowPath = oTable.getContextByIndex(selectedRow).getPath();
186
- oRowData.Sequence = oModel.getProperty(rowPath).Sequence;
187
- oRowData.Sequence++;
188
- }
189
- oRowData.Id = this._calNextRowId();
190
- // create row
191
- oModel.createEntry("/DecisionTableRows", {
192
- properties: oRowData
193
- });
194
- oTable.setSelectedIndex(oRowData.Sequence -1);
195
- this._clearErrorMessages();
196
- this._saveWorkAround([],this.oBundle.getText("addRowSuccess"));
197
- },
198
-
199
- _addNewRowWorkaround: function (bFirst) {
200
- var selectedRow = this._internalModel.getProperty("/selectedRow");
201
- this._addNewRow(selectedRow, bFirst);
202
- },
203
-
204
- _addNodeObject: function (astNode) {
205
- var oNodeArray = [];
206
- var oAstExpressionLanguage = sap.ui.getCore().byId(this.getAstExpressionLanguage());
207
- var oAstUtil = oAstExpressionLanguage._astBunldeInstance.ASTUtil;
208
-
209
- var updatedAstNode = [];
210
- updatedAstNode.Root = astNode.Root;
211
- updatedAstNode.SequenceNumber = astNode.Sequence;
212
- updatedAstNode.ParentId = astNode.ParentId;
213
- updatedAstNode.Reference = astNode.Reference;
214
- updatedAstNode.Id = astNode.NodeId;
215
- updatedAstNode.Type = astNode.Type;
216
- updatedAstNode.Value = astNode.Value ? astNode.Value : "";
217
- if (astNode.Type === "I") {
218
- updatedAstNode.Value = astNode.IncompleteExpression;
219
- }
220
- if (astNode.Function) {
221
- updatedAstNode.Function = astNode.Function;
222
- }
223
- if (astNode.Type !== "P" && astNode.Type !== "O" && !astNode.Function) {
224
- var Output = [];
225
- Output.BusinessDataType = astNode.Output ? astNode.Output.BusinessDataType : astNode.BusinessDataType;
226
- Output.DataObjectType = astNode.Output ? astNode.Output.DataObjectType : astNode.DataObjectType;
227
- updatedAstNode.Output = Output;
228
- }
229
- oAstUtil.createNode(updatedAstNode);
230
- },
231
-
232
- _addTable: function () {
233
- var oTable = new Table({
234
- visibleRowCount: this.VISIBLEROWCOUNT,
235
- threshold: this.THRESHOLD,
236
- visibleRowCountMode: sap.ui.table.VisibleRowCountMode.Fixed,
237
- selectionMode: {
238
- parts: [{
239
- path: "dtModel>/editable"
240
- }],
241
- formatter: this._decideSelectionMode
242
- },
243
- rowSelectionChange: function () {
244
- this.oParent._rowSelectionChange();
245
- },
246
- enableColumnReordering: false,
247
- busy: "{dtModel>/busyTableState}"
248
- });
249
- oTable._updateTableCell = this._updateTableCell;
250
- oTable.setBusyIndicatorDelay(0);
251
- this.setAggregation("_table", oTable, true);
252
- },
253
-
254
- /*
255
- * @private
256
- */
257
- _addToolBar: function () {
258
- var oToolbar = new OverflowToolbar({
259
- design: "Transparent",
260
- enabled: "{dtModel>/editable}"
261
- });
262
- var oTitle = new sap.m.Title({
263
- text: this.oBundle.getText("decisionTable"),
264
- tooltip:this.oBundle.getText("decisionTable")
265
- });
266
- var oAddLink = new MenuButton({
267
- text: this.oBundle.getText("addRow"),
268
- visible: "{dtModel>/editable}",
269
- enabled: {
270
- parts: [{
271
- path: "dtModel>/newTable"
272
- }],
273
- formatter: this._decideAddRowEnablement
274
- },
275
- menu: new Menu({
276
- items: this._getMenuItems()
277
- })
278
- }).setTooltip(this.oBundle.getText("addRow"));
279
-
280
- var oDeleteLink = new Button({
281
- text: this.oBundle.getText("deleteRow"),
282
- press: [this._deleteRowWorkaround, this],
283
- visible: "{dtModel>/editable}",
284
- type: sap.m.ButtonType.Transparent,
285
- enabled: {
286
- parts: [{
287
- path: "dtModel>/newTable"
288
- }, {
289
- path: "dtModel>/isAtLeastOneRowSelected"
290
- }],
291
- formatter: this._decideDeleteRowEnablement
292
- }
293
- }).setTooltip(this.oBundle.getText("deleteRow"));
294
-
295
- var oCopyLink = new Button({
296
- text: this.oBundle.getText("copyRow"),
297
- press: [this._copyRow, this],
298
- type: sap.m.ButtonType.Transparent,
299
- visible: {
300
- parts: [{
301
- path: "dtModel>/editable"
302
- }, {
303
- path: "dtModel>/sequenceExist"
304
- }],
305
- formatter: this._decideLineActionVisibility
306
- },
307
- enabled: {
308
- parts: [{
309
- path: "dtModel>/newTable"
310
- }, {
311
- path: "dtModel>/isExactlyOneRowSelected"
312
- }],
313
- formatter: this._decideCopyRowEnablement
314
- }
315
- }).setTooltip(this.oBundle.getText("copyRow"));
316
-
317
- var oCutLink = new Button({
318
- text: this.oBundle.getText("cutRow"),
319
- type: sap.m.ButtonType.Transparent,
320
- press: [this._cutRow, this],
321
- visible: {
322
- parts: [{
323
- path: "dtModel>/editable"
324
- }, {
325
- path: "dtModel>/sequenceExist"
326
- }],
327
- formatter: this._decideLineActionVisibility
328
- },
329
- enabled: {
330
- parts: [{
331
- path: "dtModel>/newTable"
332
- }, {
333
- path: "dtModel>/isExactlyOneRowSelected"
334
- }],
335
- formatter: this._decideCopyRowEnablement
336
- }
337
- }).setTooltip(this.oBundle.getText("cutRow"));
338
-
339
- var oPasteLink = new MenuButton({
340
- text: this.oBundle.getText("pasteRow"),
341
- type: sap.m.ButtonType.Transparent,
342
- visible: {
343
- parts: [{
344
- path: "dtModel>/editable"
345
- }, {
346
- path: "dtModel>/sequenceExist"
347
- }],
348
- formatter: this._decideLineActionVisibility
349
- },
350
- enabled: {
351
- parts: [{
352
- path: "dtModel>/newTable"
353
- }, {
354
- path: "dtModel>/isExactlyOneRowSelected"
355
- }, {
356
- path: "dtModel>/isSelection"
357
- }],
358
- formatter: this._decidePasteRowEnablement
359
- },
360
- menu: new Menu({
361
- items: this._getPasteMenuItems()
362
- })
363
- }).setTooltip(this.oBundle.getText("pasteRow"));
364
-
365
- var oSettingsButton = new Button({
366
- text: "",
367
- press: this._openTableSettings.bind(this),
368
- visible: {
369
- parts: [{
370
- path: "dtModel>/enableSettings"
371
- }, {
372
- path: "dtModel>/editable"
373
- }],
374
- formatter: this._decideSettingsEnablement
375
- },
376
- enabled: {
377
- parts: [{
378
- path: "dtModel>/enableSettings"
379
- }, {
380
- path: "dtModel>/editable"
381
- }],
382
- formatter: this._decideSettingsEnablement
383
- }
384
- }).setTooltip(this.oBundle.getText("tableSettings"));
385
- oSettingsButton.setIcon("sap-icon://action-settings");
386
-
387
- // Remove space in order to align DT title to left
388
- // oToolbar.addContent(new ToolbarSpacer({
389
- // width: "1em"
390
- // }));
391
-
392
- oToolbar.addContent(oTitle);
393
- oToolbar.addContent(new ToolbarSpacer({}));
394
- oToolbar.addContent(oAddLink);
395
- oToolbar.addContent(new ToolbarSpacer({
396
- width: "1em"
397
- }));
398
- oToolbar.addContent(oDeleteLink);
399
- oToolbar._delete = oDeleteLink;
400
-
401
- oToolbar.addContent(new ToolbarSpacer({
402
- width: "1em"
403
- }));
404
- oToolbar.addContent(oCopyLink);
405
- oToolbar.addContent(new ToolbarSpacer({
406
- width: "1em"
407
- }));
408
- oToolbar.addContent(oCutLink);
409
- oToolbar.addContent(new ToolbarSpacer({
410
- width: "1em"
411
- }));
412
- oToolbar.addContent(oPasteLink);
413
- oToolbar.addContent(new ToolbarSpacer({
414
- width: "1em"
415
- }));
416
-
417
- oToolbar.addContent(oSettingsButton);
418
- oToolbar.addContent(new ToolbarSpacer({
419
- width: "1em"
420
- }));
421
-
422
- this.setAggregation("_toolbar", oToolbar, true);
423
- },
424
-
425
- _bindColumns: function () {
426
- var oTable = this.getAggregation("_table");
427
- var bindingPath = [this._getBindModelName(), this.getBindingContextPath(), "/DecisionTable/DecisionTableColumns"].join("");
428
- var expandPath = "Condition,Result";
429
- if(this.getAstExpressionLanguage()){
430
- expandPath = "Condition/DecisionTableColumnConditionASTs,Result/DecisionTableColumnResultASTs";
431
- }
432
-
433
- oTable.bindColumns({
434
- path: bindingPath,
435
- parameters: {
436
- expand: expandPath
437
- },
438
- factory: this._columnFactory.bind(this)
439
- });
440
-
441
- oTable.getBinding("columns").attachDataRequested(this._handleColumnsDataRequested, this);
442
- oTable.getBinding("columns").attachDataReceived(this._handleColumnsDataReceived, this);
443
- oTable.attachColumnResize(oTable, this._onColumnResize, this);
444
- },
445
-
446
- _onColumnResize: function () {
447
- this.columnResized = true;
448
- var obj = { "colResize" : true };
449
- var oEventBus = sap.ui.getCore().getEventBus();
450
- oEventBus.publish("sap.ui.rules","_onColumnResized", obj);
451
- },
452
-
453
- _bindRows: function () {
454
- var oTable = this.getAggregation("_table");
455
- var bindingPath = [this._getBindModelName(), this.getBindingContextPath(), "/DecisionTable/DecisionTableRows"].join("");
456
- var expandPath = "Cells";
457
- if(this.getAstExpressionLanguage()){
458
- expandPath = "Cells/DecisionTableRowCellASTs";
459
- }
460
- var oSorter = new sap.ui.model.Sorter("Sequence");
461
-
462
- oTable.bindRows({
463
- path: bindingPath,
464
- parameters: {
465
- expand: expandPath
466
- },
467
- sorter: oSorter
468
- });
469
-
470
- oTable.getBinding("rows").attachDataRequested(this._handleRowsDataRequested, this);
471
- oTable.getBinding("rows").attachDataReceived(this._handleRowsDataReceived, this);
472
- },
473
-
474
- _bindRule: function () {
475
- var bindingPath = [this._getBindModelName(), this.getBindingContextPath()].join("");
476
- this.bindElement({
477
- path: bindingPath,
478
- parameters: {
479
- expand: "DecisionTable"
480
- }
481
- });
482
-
483
- this.getElementBinding().attachDataRequested(this._handleRuleDataRequested, this);
484
- this.getElementBinding().attachDataReceived(this._handleRuleDataReceived, this);
485
-
486
- // force data load (otherwise if data exists there is no data fetch)
487
- this.getElementBinding().refresh();
488
- },
489
-
490
- _buildMessagesStructure: function (validateResults, columnErrorsMap, headerErrorArray) {
491
- var detail;
492
- var additionalInfo;
493
- var description;
494
- var errorKey;
495
- if (!validateResults.details) {
496
- return columnErrorsMap;
497
- }
498
-
499
- for (var w = 0; w < validateResults.details.length; w++) {
500
- detail = validateResults.details[w];
501
- if (!detail.messages) {
502
- continue;
503
- }
504
- for (var i = 0; i < detail.messages.length; i++) {
505
- description = detail.messages[i].description;
506
- additionalInfo = detail.messages[i].additionalInfo;
507
- if (additionalInfo.type === "ruleResult") {
508
- headerErrorArray.push(description);
509
- errorKey = "genericError";
510
- columnErrorsMap[errorKey] = headerErrorArray;
511
- } else if (additionalInfo.type === "column") {
512
- errorKey = "errorInColumnHeader";
513
- columnErrorsMap[errorKey] = true;
514
- } else if (additionalInfo.type === "cell") {
515
- errorKey = "RowId=" + additionalInfo.rowId + ",ColId=" + additionalInfo.colId;
516
- columnErrorsMap[errorKey] = description;
517
- }
518
- }
519
- }
520
- return columnErrorsMap;
521
- },
522
-
523
- /**
524
- * Copy a row from the buffer after a copy/cut line action using a function import
525
- * /sap/opu/odata/SAP/RULE_SRV/CopyRuleRow?RuleId='xxx'&SourceRowId='yyy'&TargetRowSeq='zzz'
526
- * @param {string} [sRuleId] The current rule ID
527
- * @param {string} [sVersion] The current rule version
528
- * @param {string} [sSourceRowId] The copied row stable ID
529
- * @param {string} [sTargetRowSeq] A sequence for paste/insert the row
530
- * @param {boolean} [shouldCut] A flag indicating if we cut or copy
531
- * @param {boolean} [sOverrideInd] A flag indicating if we paste
532
- * @private
533
- **/
534
- _callCopyRuleRow: function (sRuleId, sVersion, sSourceRowId, sTargetRowSeq, shouldCut, sOverrideInd) {
535
- var changesGroupID = {
536
- groupId: "changes"
537
- };
538
- this._getModel().setDeferredGroups([changesGroupID.groupId]);
539
- var submitSuccess = function (response) {
540
- this.resetControl();
541
- this._internalModel.setProperty("/busyState", false);
542
- }.bind(this);
543
-
544
- var submitError = function (e) {
545
- sap.m.MessageToast.show(e);
546
- }.bind(this);
547
-
548
- var callFunctionSuccess = function (response) {
549
- this._getModel().callFunction("/CopyRuleRow", {
550
- method: "POST",
551
- groupId: changesGroupID.groupId,
552
- urlParameters: {
553
- RuleId: sRuleId,
554
- SourceRowId: sSourceRowId,
555
- TargetRowSeq: sTargetRowSeq,
556
- DeleteSourceRow: shouldCut,
557
- OverrideTargetRow: sOverrideInd
558
- }
559
- });
560
- this._getModel().submitChanges({
561
- groupId: changesGroupID.groupId,
562
- success: submitSuccess,
563
- error: submitError
564
- });
565
- }.bind(this);
566
-
567
- if (this._getModel().hasPendingChanges()) {
568
- this._getModel().submitChanges({
569
- groupId: changesGroupID.groupId,
570
- success: callFunctionSuccess,
571
- error: submitError
572
- });
573
- } else {
574
- callFunctionSuccess();
575
- }
576
- },
577
-
578
- _calNextRowId: function () {
579
- var rows = this.dataBucket.rows.results;
580
- var maxRowId = 0;
581
- //Calc max "Id"
582
- for (var i = 0; i < rows.length; i++) {
583
- if (rows[i].Id > maxRowId) {
584
- maxRowId = rows[i].Id;
585
- }
586
- }
587
- var nextId = maxRowId + 1;
588
- return nextId;
589
- },
590
-
591
- _clearErrorMessages: function () {
592
- //Clear header message
593
- var oText = this.getAggregation("_errorsText");
594
- oText.setText("");
595
- oText.setVisible(false);
596
- this._internalModel.setProperty("/validationStatus", {}, null, true);
597
- this._internalModel.setProperty("/valueState", {}, null, true);
598
- },
599
-
600
- //Closes cell popover
601
- _closePopover: function () {
602
- var pop = sap.ui.getCore().byId("popover");
603
- if (pop) {
604
- pop.close();
605
- }
606
- },
607
-
608
- _collectColIdAndExpressionDetails: function (columns) {
609
- var columnCount = columns.length;
610
- var resultExpressionArray = [];
611
- for (var columnIndex = 0; columnIndex < columnCount; columnIndex++) {
612
- if (columns[columnIndex].Result && columns[columnIndex].Result.Expression) {
613
- var oResult = {
614
- 'columnID': columns[columnIndex].Result.Id,
615
- 'expressionContent': columns[columnIndex].Result.Expression
616
- };
617
- resultExpressionArray.push(oResult);
618
- }
619
- }
620
- return resultExpressionArray;
621
- },
622
-
623
- _columnFactory: function (sId, oContext) {
624
- var that = this;
625
- if (this.multiHeaderFlag) {
626
- this.multiHeaderFlag = false;
627
- }
628
- var relativePath = this._getBindModelName();
629
- var columnType = oContext.getProperty("Type"),
630
- coId = oContext.getProperty("Id"),
631
- ruleId = oContext.getProperty("RuleId"),
632
- version = oContext.getProperty("Version");
633
- var oHeaderKey = {
634
- RuleId: ruleId,
635
- Id: coId,
636
- Version: version
637
- };
638
- var headPath = relativePath + oContext.getModel().createKey("/DecisionTableColumnResults", oHeaderKey);
639
- var contextModel = oContext.getModel();
640
- var bindingInfo = contextModel.aBindings;
641
- this.columnWidth = "auto";
642
-
643
- var column = new Column(sId, {
644
- width: this.columnWidth,
645
- minWidth : 128,
646
- multiLabels: [
647
- this._createColIfThenHeader(oContext), // The order of the labels is important!
648
- this._createColDescriptionHeader(oContext, this)
649
- ],
650
- template: this._createCell(oContext) //, headerSpan: columnType === sap.rules.ui.DecisionTableColumn.Condition ? [this.iNumOfCondition, 1] : [this.iNumOfResults, 1]
651
- });
652
-
653
- relativePath = this._getBindModelName();
654
- this.firstResultColumnBound = oContext.getProperty(relativePath + "Type") === sap.rules.ui.DecisionTableColumn.Result;
655
- if (columnType === sap.rules.ui.DecisionTableColumn.Result) {
656
-
657
- if (this.getAstExpressionLanguage()) {
658
- column.bindProperty("visible", {
659
- parts: [{
660
- path: headPath + "/AccessMode"
661
- }],
662
- formatter: this._columnVisibility
663
- });
664
- }
665
- if (this.getExpressionLanguage()) {
666
-
667
- column.bindProperty("visible", {
668
- parts: [{
669
- path: headPath + "/AccessMode"
670
- }],
671
- formatter: function() {
672
- var type = that.getModel() && headPath!== "" ? that.getModel().getObject(headPath).BusinessDataType : "";
673
- if (type === Constants.DATE_BUSINESS_TYPE || type === Constants.TIMESTAMP_BUSINESS_TYPE || type === Constants.NUMBER || type ===
674
- Constants.STRING || type === Constants.BOOLEAN_BUSINESS_TYPE || type === Constants.BOOLEAN_ENHANCED_BUSINESS_TYPE) {
675
- var accessMode = that.getModel().getObject(headPath).AccessMode;
676
- return that._columnVisibility(accessMode);
677
- } else {
678
- return false;
679
- }
680
- }
681
- });
682
- }
683
- }
684
-
685
- return column;
686
- },
687
-
688
- _columnVisibility: function (accessMode) {
689
- if (accessMode === "Hidden" || accessMode === "HIDDEN") {
690
- return false;
691
- } else {
692
- return true;
693
- }
694
- },
695
-
696
- _concatinateColumnsHeaderErrors: function (columnErrorsMap) {
697
- var errorMessage = "";
698
- for (var column in columnErrorsMap) {
699
- if (columnErrorsMap.hasOwnProperty(column)) {
700
- if (columnErrorsMap[column].header) {
701
- errorMessage += "In Col: " + column + " - " + columnErrorsMap[column].header + "\n";
702
- }
703
- }
704
- }
705
- return errorMessage;
706
- },
707
-
708
- _concatinateHeaderErrors: function (headerErrorsArray) {
709
- var errorMessage = "";
710
- for (var i = 0; i < headerErrorsArray.length; i++) {
711
- errorMessage += "\n" + headerErrorsArray[i];
712
- }
713
- return errorMessage;
714
- },
715
-
716
- _convertAndValidate: function () {
717
- var ruleData = this._getRuleData();
718
- var oExpressionLanguage = sap.ui.getCore().byId(this.getExpressionLanguage());
719
- if (oExpressionLanguage) {
720
- var validateResults = {};
721
- if (oExpressionLanguage && ruleData) {
722
- validateResults = oExpressionLanguage.convertRuleToDisplayValues(ruleData);
723
- if (validateResults.deferredResult) {
724
- validateResults.deferredResult.done(this._processValidationResults.bind(this));
725
- } else {
726
- this._processValidationResults(validateResults, ruleData);
727
- }
728
- }
729
- } else {
730
- this._displayModel.setData(ruleData);
731
- this._settingsModel.setData(ruleData);
732
- }
733
-
734
- },
735
-
736
- _copyRow: function () {
737
- this._cutCopyRow("copy");
738
- },
739
-
740
- _createCell: function (oContext) {
741
- var colID = oContext.getProperty("Id");
742
- var colType = oContext.getProperty("Type");
743
-
744
- var oCell = new DecisionTableCell({
745
- editable: "{dtModel>/editable}",
746
- displayModelName: "displayModel",
747
- decisionTableCellType: this._decisionTableCellFormatter
748
- // type: sap.rules.ui.ExpressionType.BooleanEnhanced
749
- }).data({
750
- colId: colID,
751
- colType: colType,
752
- table: this.getAggregation("_table")
753
- });
754
-
755
- if (this.getAstExpressionLanguage()) {
756
- oCell.setAstExpressionLanguage(this.getAstExpressionLanguage());
757
- } else {
758
- oCell.setExpressionLanguage(this.getExpressionLanguage());
759
- }
760
- return oCell;
761
- },
762
-
763
- _createColDescriptionHeader: function (oContext, oDtControl) {
764
- var that = this;
765
- var columnType = oContext.getProperty("Type"),
766
- coId = oContext.getProperty("Id"),
767
- ruleId = oContext.getProperty("RuleId"),
768
- version = oContext.getProperty("Version");
769
- var relativePath = "";
770
- var headerPath;
771
- var sPath;
772
- var oAstContext;
773
- var displayExpression;
774
- var oHeaderKey = {
775
- RuleId: ruleId,
776
- Id: coId,
777
- Version: version
778
- };
779
- var sDTColPath;
780
-
781
- //For rel
782
- if (this.getExpressionLanguage()) {
783
- relativePath = "displayModel>";
784
- }
785
- var numOfLines = document.getElementsByClassName("sapUiSizeCozy").length > 0 ? 3 : 1;
786
-
787
- var oText = new Text({
788
- maxLines: numOfLines
789
- }).addStyleClass("sapRULDecisionTableColumnHeaderLabel");
790
-
791
- //Condition header text
792
- if (columnType === sap.rules.ui.DecisionTableColumn.Condition) {
793
- sPath = oContext.getModel().createKey("/DecisionTableColumnConditions", oHeaderKey);
794
- sDTColPath = oContext.getModel().createKey("/DecisionTableColumns", oHeaderKey);
795
- oAstContext = new sap.ui.model.Context(oContext.getModel(), sPath);
796
- if (this.getAstExpressionLanguage()) {
797
- displayExpression = oDtControl._getExpressionFromAstNodes(oAstContext);
798
- }
799
- headerPath = relativePath + sPath;
800
- oText.bindText({
801
- parts: [{
802
- path: headerPath + "/Expression"
803
- }, {
804
- path: sDTColPath + "/Label"
805
- }, {
806
- path: headerPath + "/FixedOperator"
807
- }],
808
- formatter: function (sExpression, sLabel, sFixedOperator) {
809
- //bug RULES-5278
810
- var titleText = "";
811
- if(that.getAstExpressionLanguage()){
812
- titleText = !sLabel ? displayExpression : sLabel;
813
- } else {
814
- titleText = !sLabel ? sExpression : sLabel;
815
- }
816
- if (sFixedOperator) {
817
- var sOperator = that.getAstExpressionLanguage() ? that.astUtil._getCapitalOperatorName(sFixedOperator) : sFixedOperator;
818
- titleText += " " + sOperator;
819
- }
820
- return titleText;
821
- }
822
- });
823
-
824
- oText.bindProperty("tooltip", {
825
- parts: [{
826
- path: headerPath + "/Expression"
827
- }, {
828
- path: headerPath + "/FixedOperator"
829
- }],
830
- formatter: function (sExpression, sFixedOperator) {
831
- var titleText = "";
832
- if(that.getAstExpressionLanguage()){
833
- titleText = displayExpression ? displayExpression : "";
834
- } else {
835
- titleText = sExpression;
836
- }
837
- if (sFixedOperator) {
838
- var sOperator = that.getAstExpressionLanguage() ? that.astUtil._getCapitalOperatorName(sFixedOperator) : sFixedOperator;
839
- titleText += " " + sOperator;
840
- }
841
- return titleText;
842
- }
843
- });
844
-
845
- //Result header text
846
- } else if (columnType === sap.rules.ui.DecisionTableColumn.Result) {
847
- var sResultPath = oContext.getModel().createKey("/DecisionTableColumnResults", oHeaderKey);
848
- headerPath = relativePath + sResultPath;
849
- oText.bindText({
850
- parts: [{
851
- path: headerPath + "/DataObjectAttributeName"
852
- }, {
853
- path: headerPath + "/DataObjectAttributeLabel"
854
- }, {
855
- path: "dtModel>/busyState"
856
- }],
857
- formatter: this._getOutputColumnDescription.bind(this)
858
- });
859
-
860
- oText.bindProperty("tooltip", {
861
- parts: [{
862
- path: headerPath + "/DataObjectAttributeName"
863
- }, {
864
- path: headerPath + "/DataObjectAttributeLabel"
865
- }, {
866
- path: "dtModel>/busyState"
867
- }],
868
- formatter: this._getOutputColumnDescription.bind(this)
869
- });
870
- }
871
- return oText;
872
- },
873
-
874
- _createColIfThenHeader: function (oContext) {
875
- //var model = oContext.getModel();
876
- var relativePath = this._getBindModelName();
877
- var oBundle = this.oBundle;
878
-
879
- return new Label({
880
- text: {
881
- parts: [{
882
- path: relativePath + "Type"
883
- }, {
884
- path: relativePath + "Sequence"
885
- }],
886
- formatter: function (sType, iSequence) {
887
- if (iSequence === 1) {
888
- return oBundle.getText("conditionIfColumn");
889
- } else if (sType === sap.rules.ui.DecisionTableColumn.Result) {
890
- return oBundle.getText("resultThenColumn");
891
- } else {
892
- return "";
893
- }
894
- }
895
- },
896
- design: "Bold"
897
- });
898
- },
899
-
900
- _createDecisionTableSettings: function () {
901
- var oDecisionTableSettings;
902
- if (this.isSequenceExistsInOdataMetadata()) {
903
- oDecisionTableSettings = this._createNewDecisionTableSettings();
904
- } else {
905
- oDecisionTableSettings = this._createOldDecisionTableSettings();
906
- }
907
- return oDecisionTableSettings;
908
- },
909
-
910
- _createNewDecisionTableSettings: function () {
911
- var oModel = this._getModel();
912
- var oContext = this.getBindingContext();
913
- var oDecisionTableSettings = new sap.rules.ui.DecisionTableSettings({
914
- hitPolicies: "{dtModel>/hitPolicies}",
915
- newDecisionTable: this._internalModel.getProperty("/newTable"),
916
- cellFormat: "{dtModel>/cellFormat}",
917
- decisionTableFormat: this.getDecisionTableFormat(),
918
- enableSettingResult: this.getEnableSettingResult()
919
- });
920
- if (this.getAstExpressionLanguage()) {
921
- oDecisionTableSettings.setAstExpressionLanguage(this.getAstExpressionLanguage());
922
- } else {
923
- oDecisionTableSettings.setExpressionLanguage(this.getExpressionLanguage());
924
- }
925
- //Create a copy of the setting model.
926
- var settingModelDataStr = JSON.stringify(this._settingsModel.getData());
927
- var settingModelData = JSON.parse(settingModelDataStr);
928
-
929
- var settingModel = new sap.ui.model.json.JSONModel(settingModelData);
930
-
931
- oDecisionTableSettings.setModel(settingModel);
932
-
933
- //Set configuration model
934
- oDecisionTableSettings.setModel(this._internalModel, "dtModel");
935
-
936
- //Set OdataModel + context (needed for apply button)
937
- oDecisionTableSettings.setModel(oModel, "oDataModel");
938
-
939
- oDecisionTableSettings.setBindingContext(oContext, "dummy");
940
-
941
- return oDecisionTableSettings;
942
- },
943
-
944
- _createOldDecisionTableSettings: function () {
945
- var oModel = this._getModel();
946
- var oContext = this.getBindingContext();
947
- var oDecisionTableSettings = new DecisionTableSettingsOld({
948
- expressionLanguage: this.getExpressionLanguage(),
949
- hitPolicies: "{dtModel>/hitPolicies}",
950
- newDecisionTable: this._internalModel.getProperty("/newTable")
951
- });
952
- oDecisionTableSettings.setModel(oModel);
953
- oDecisionTableSettings.setModel(this._internalModel, "dtModel");
954
- oDecisionTableSettings.setBindingContext(oContext);
955
- return oDecisionTableSettings;
956
- },
957
-
958
- _cutCopyRow: function (operation) {
959
- var oModel = this._getModel();
960
- if (!oModel) {
961
- return;
962
- }
963
- var oTable = this.getAggregation("_table");
964
- var oSelectedRows = [];
965
- if (oTable) {
966
- oSelectedRows = oTable.getSelectedIndices();
967
- }
968
- if (oSelectedRows.length !== 1) {
969
- return;
970
- }
971
- var rowPath = oTable.getContextByIndex(oSelectedRows[0]).getPath();
972
- this._markSelection(false);
973
- this.setLineActionBuffer({
974
- rowPath: rowPath,
975
- operation: operation
976
- });
977
- this._markSelection(true);
978
- oTable.setSelectedIndex(-1);
979
- sap.m.MessageToast.show(this.oBundle.getText(operation + "RowSuccess"));
980
- },
981
-
982
- _cutRow: function () {
983
- this._cutCopyRow("cut");
984
- },
985
-
986
- // dataBucket
987
- _dataPartRequested: function (partName) {
988
- this.dataBucket.dataReceived[partName] = false;
989
- this._setDataLoadedPromise();
990
- this._updateBusyState();
991
- },
992
-
993
- _dataPartReceived: function (partName) {
994
- this.dataBucket.dataReceived[partName] = true;
995
- if (!this._isAllDataReceived()) {
996
- return;
997
- }
998
- try {
999
- this._convertAndValidate();
1000
- this.dataBucket.collectRowsMode = "replace";
1001
- } catch (sError) {
1002
- // show message Toast
1003
- window.console.log(sError);
1004
- }
1005
- this._updateBusyState();
1006
- this._dataLoaded.resolve();
1007
- },
1008
-
1009
- _decideAddRowEnablement: function (newTable) {
1010
- return !newTable;
1011
- },
1012
-
1013
- _decideCopyRowEnablement: function (newTable, isExactlyOneRowSelected) {
1014
- return newTable === false && isExactlyOneRowSelected;
1015
- },
1016
-
1017
- _decideDeleteRowEnablement: function (newTable, isAtLeastOneRowSelected) {
1018
- return newTable === false && isAtLeastOneRowSelected;
1019
- },
1020
-
1021
- _decideLineActionVisibility: function (isEditable, isSequenceExist) {
1022
- return isEditable === true && isSequenceExist;
1023
- },
1024
-
1025
- _decidePasteRowEnablement: function (newTable, isExactlyOneRowSelected, isSelection) {
1026
- return newTable === false && isExactlyOneRowSelected && isSelection;
1027
- },
1028
-
1029
- _decideSelectionMode: function (editable) {
1030
- return editable ? sap.ui.table.SelectionMode.MultiToggle : sap.ui.table.SelectionMode.None;
1031
- },
1032
-
1033
- _decideSettingsEnablement: function (enableSettings, editable) {
1034
- return enableSettings && editable;
1035
- },
1036
-
1037
- _deleteRow: function () {
1038
- var oModel = this._getModel();
1039
- if (!oModel) {
1040
- return;
1041
- }
1042
- var oTable = this.getAggregation("_table");
1043
- var oSelectedRows = [];
1044
- if (oTable) {
1045
- oSelectedRows = oTable.getSelectedIndices();
1046
- }
1047
- if (oSelectedRows.length === 0) {
1048
- return;
1049
- }
1050
- var rowsLength = oSelectedRows.length;
1051
- for (var i = 0; i < rowsLength; i++) {
1052
- var rowPath = oTable.getContextByIndex(oSelectedRows[i]).getPath();
1053
- // remove row
1054
- oModel.remove(rowPath);
1055
- }
1056
- oTable.setSelectedIndex(-1);
1057
- this._clearErrorMessages();
1058
- this.setLineActionBuffer({
1059
- rowPath: null,
1060
- operation: null
1061
- });
1062
- sap.m.MessageToast.show(this.oBundle.getText("deleteRowSuccess"));
1063
- },
1064
-
1065
- _deleteRowWorkaround: function () {
1066
- var oModel = this._getModel();
1067
- if (oModel.hasPendingChanges()) {
1068
- // save all model's changes before row removal
1069
- this._saveWorkAround({
1070
- success: function () {
1071
- this._deleteRow();
1072
- }.bind(this)
1073
- });
1074
- } else {
1075
- this._deleteRow();
1076
- }
1077
- },
1078
-
1079
- _displayErrorMessages: function (headerErrorsArray, columnErrorsMap) {
1080
- // I commnted this call in order to remove the header error message, next we'll add here a different errors control
1081
- //this._displayHeaderErrorMessages(headerErrorsArray, columnErrorsMap);
1082
- },
1083
-
1084
- _displayHeaderErrorMessages: function (headerErrorsArray, columnErrorsMap) {
1085
- var oText = this.getAggregation("_errorsText");
1086
- this.oBundle = sap.ui.getCore().getLibraryResourceBundle("sap.rules.ui.i18n");
1087
- var errorHeaderMessage = this._concatinateHeaderErrors(headerErrorsArray);
1088
- oText.setText(this.oBundle.getText("errorInTableHeader") + errorHeaderMessage); // + "\n" + errorColumnsHeaderMessage);
1089
- oText.setVisible(true);
1090
- },
1091
-
1092
- /**
1093
- * @private
1094
- * Gets a rule in deep format (as returned from the parser), and flats the rule to the format of the oDataModel.
1095
- * e.g. DecisionTableRowCell(RuleId='0050569181751ED683EFEEC6AA2B73C5', Version='000001', RowId='1', ColId='1')
1096
- * @param {oRule} oRule in deep format
1097
- * @returns {object} rule in oDataModel flatted format
1098
- */
1099
- _flatRule: function (oRule) {
1100
- var oModel = this._getModel();
1101
- var oRuleFlat = {};
1102
- var createEntry = function (oData, entryName, properties) {
1103
- var key = oModel.createKey(entryName, properties);
1104
- oData[key] = properties;
1105
- };
1106
-
1107
- // Flat columns
1108
- oRule.DecisionTable.DecisionTableColumns.results.forEach(function (col, index) {
1109
- if (col.Type === "CONDITION") {
1110
- var condition = col.Condition;
1111
- if (condition.parserResults && condition.parserResults.status === "Success") {
1112
- condition.Expression = condition.parserResults.converted.Expression;
1113
- if (condition.parserResults.converted.FixedOperator || condition.parserResults.converted.FixedOperator === "") {
1114
- condition.FixedOperator = condition.parserResults.converted.FixedOperator;
1115
- } else {
1116
- condition.FixedOperator = condition.FixedOperator;
1117
- }
1118
- } else {
1119
- try {
1120
- condition.Expression = JSON.parse(condition.Expression).text;
1121
- } catch (err) {
1122
- condition.Expression = condition.Expression;
1123
- }
1124
- try {
1125
- condition.FixedOperator = JSON.parse(condition.FixedOperator).text;
1126
- } catch (err) {
1127
- condition.Expression = condition.Expression;
1128
- }
1129
- }
1130
- delete condition.parserResults;
1131
- createEntry(oRuleFlat, "DecisionTableColumnConditions", condition);
1132
- } else if (col.Type === "RESULT") {
1133
- var result = col.Result;
1134
- createEntry(oRuleFlat, "DecisionTableColumnResults", result);
1135
- }
1136
- });
1137
-
1138
- // Flat cells
1139
- oRule.DecisionTable.DecisionTableRows.results.forEach(function (row) {
1140
- var cellArr = row.Cells;
1141
- cellArr.results.forEach(function (cell) {
1142
- if (cell.parserResults && cell.parserResults.status === "Success") {
1143
- if(cell.parserResults.converted.Content){
1144
- cell.Content = cell.parserResults.converted.Content;
1145
- }else{
1146
- cell.Content = cell.Content;
1147
- }
1148
- } else if (cell.parserResults && cell.parserResults.status === "Error") {
1149
- try {
1150
- if (cell.Content === Object) {
1151
- cell.Content = JSON.parse(cell.Content).text;
1152
- } else {
1153
- cell.Content = cell.Content;
1154
- }
1155
-
1156
- } catch (err) {
1157
- cell.Content = "";
1158
- Log.error("failed to pars AST cell in ColId " + cell.ColId + " RowId " + cell.RowId +
1159
- " set cell content to empty");
1160
- }
1161
- }
1162
- delete cell.parserResults;
1163
- createEntry(oRuleFlat, "DecisionTableRowCells", cell);
1164
- });
1165
- });
1166
-
1167
- return oRuleFlat;
1168
- },
1169
-
1170
- _getBindModelName: function () {
1171
- var path = "";
1172
- var modelName = this.getModelName();
1173
- if (modelName) {
1174
- path = modelName + ">";
1175
- }
1176
- return path;
1177
- },
1178
-
1179
- _getBlankContent: function () {
1180
- var oLabelContent = new Label({
1181
- text: this.oBundle.getText("start")
1182
- });
1183
- var oSpaceTextContent = new Text();
1184
- oSpaceTextContent.setText("\u00a0");
1185
- var oLinkToSettingsFromBlank = new Link({
1186
- enabled: {
1187
- parts: [{
1188
- path: "dtModel>/enableSettings"
1189
- }, {
1190
- path: "dtModel>/editable"
1191
- }],
1192
- formatter: this._decideSettingsEnablement
1193
- },
1194
- text: " " + this.oBundle.getText("settings"),
1195
- press: [this._openTableSettings, this]
1196
- }).addStyleClass("sapRULDecisionTableLink");
1197
-
1198
- var oFlexBox = new FlexBox({
1199
- justifyContent: "Center",
1200
- items: [oLabelContent, oSpaceTextContent, oLinkToSettingsFromBlank],
1201
- visible: {
1202
- parts: [{
1203
- path: "dtModel>/enableSettings"
1204
- }, {
1205
- path: "dtModel>/editable"
1206
- }],
1207
- formatter: this._decideSettingsEnablement
1208
- }
1209
- }).addStyleClass("sapUiMediumMargin");
1210
-
1211
- return oFlexBox;
1212
- },
1213
-
1214
- _getDataLoadedPromise: function () {
1215
- if (!this._dataLoaded) {
1216
- this._setDataLoadedPromise();
1217
- }
1218
- return this._dataLoaded.promise();
1219
- },
1220
-
1221
- _getExpressionFromAstNodes: function (oContext) {
1222
- var that = this;
1223
- var oAstExpressionLanguage = sap.ui.getCore().byId(this.getAstExpressionLanguage());
1224
- var termsProvider = oAstExpressionLanguage._astBunldeInstance.TermsProvider.TermsProvider;
1225
- var displayExpression = "";
1226
- var displayTermExpression = "";
1227
- var sPath = oContext.getPath();
1228
- var oData = oContext.getObject(sPath);
1229
- var astList = oData.DecisionTableColumnConditionASTs;
1230
- var oAstUtil = oAstExpressionLanguage._astBunldeInstance.ASTUtil;
1231
- var columnArray = this._internalModel.getProperty("/conditionCellAstValues");
1232
- var len = 0;
1233
- var jsonLength = 0;
1234
- var aFunction = [ConstantUtils.AVG, ConstantUtils.SUM, ConstantUtils.COUNT, ConstantUtils.COUNTDISTINCT, ConstantUtils.DISTINCT,
1235
- ConstantUtils.MIN, ConstantUtils.MAX, ConstantUtils.FILTER, ConstantUtils.TOP, ConstantUtils.BOTTOM, ConstantUtils.FIRST, ConstantUtils.SELECT, ConstantUtils.SORTASC, ConstantUtils.SORTDESC];
1236
- oAstUtil.clearNodes();
1237
- astList = astList.__list;
1238
- if (astList && astList.length > 0) {
1239
- for (var entry in astList) {
1240
- var path = astList[entry];
1241
- that._addNodeObject(oContext.getObject("/" + path));
1242
- }
1243
- var astNodes = oAstUtil.getNodes();
1244
- //displayExpression = oAstUtil.toAstExpressionString(astNodes);
1245
- var dateFormat = that._getDateFormatter();
1246
- var timeFormat = that._getDateTimeFormatter();
1247
- displayExpression = oAstUtil.toAstExpressionStringForDt(astNodes, dateFormat, timeFormat);
1248
- jsonLength = displayExpression.JSON.length;
1249
- var fixedOperator = oContext.getObject(oContext.getPath()).FixedOperator;
1250
- var sOperator = that.astUtil._getCapitalOperatorName(fixedOperator);
1251
- if(displayExpression && displayExpression.relString) {
1252
- displayExpression.relString = displayExpression.relString.replace(/\\/g,"\\\\").replace(/{/g, "\\{").replace(/}/g, "\\}");
1253
- }
1254
- columnArray[oContext.getPath()] = {
1255
- "headerValue": displayExpression.relString + " " + sOperator
1256
- };
1257
- var termsArray = displayExpression.shortRELString ? displayExpression.shortRELString.split(" ") : [];
1258
- termsArray = displayExpression.displayString ? displayExpression.displayString.split(" ") : [];
1259
- for (var term in termsArray) {
1260
- var referenceExpression = "";
1261
- if (termsArray[term].startsWith("./") || termsArray[term].startsWith("/")) {
1262
- referenceExpression = termsProvider.getTermNameFromASTNodeReference(termsArray[term]);
1263
- }
1264
- if (referenceExpression !== "") {
1265
- displayTermExpression = displayTermExpression + " " + referenceExpression;
1266
- } else {
1267
- var splitArray = termsArray[term].split("(");
1268
- if(that.includes(aFunction,splitArray[0]) && len < jsonLength){
1269
- termsArray[term] = termsArray[term].replace(displayExpression.JSON[len].dataObject,
1270
- termsProvider.getTermNameFromASTNodeReference(displayExpression.JSON[len].dataObject));
1271
- len++;
1272
- }
1273
- displayTermExpression = displayTermExpression + " " + termsArray[term];
1274
- }
1275
- }
1276
- if (displayTermExpression != "") {
1277
- displayExpression = displayTermExpression;
1278
- }
1279
- }
1280
- if (!columnArray[oContext.getPath()]) {
1281
- columnArray[oContext.getPath()] = {
1282
- "headerValue": ""
1283
- };
1284
- }
1285
- this._internalModel.setProperty("/conditionCellAstValues", columnArray);
1286
- return (displayExpression instanceof Object ? displayExpression.shortRELString : displayExpression.trim());
1287
- },
1288
-
1289
- _getMenuItems: function () {
1290
- var oMenuItems = [
1291
- new MenuItem({
1292
- text: this.oBundle.getText("insertFirst"),
1293
- enabled: true,
1294
- press: this._addNewRowWorkaround.bind(this, true)
1295
- }),
1296
- new MenuItem({
1297
- text: this.oBundle.getText("insertAfter"),
1298
- enabled: {
1299
- parts: [{
1300
- path: "dtModel>/newTable"
1301
- }, {
1302
- path: "dtModel>/isExactlyOneRowSelected"
1303
- }],
1304
- formatter: this._decideCopyRowEnablement
1305
- },
1306
- // select: this._addNewRow.bind(this, oSelectedRows[0], false)
1307
- press: this._addNewRowWorkaround.bind(this, false)
1308
- })
1309
- ];
1310
- return oMenuItems;
1311
- },
1312
-
1313
- _getModel: function () {
1314
- var modelName = this.getModelName();
1315
- if (modelName) {
1316
- return this.getModel(modelName);
1317
- }
1318
- return this.getModel();
1319
- },
1320
-
1321
- _getOutputColumnDescription: function (oName, oLabel) {
1322
- var expLanguage;
1323
- if (this.getExpressionLanguage()) {
1324
- expLanguage = sap.ui.getCore().byId(this.getExpressionLanguage());
1325
- if (expLanguage && expLanguage._isDataExist()) {
1326
- var ResultID = this.getBindingContext().getProperty("ResultDataObjectId");
1327
- var desc = expLanguage.getResultColumnDescription(oName, ResultID, oLabel);
1328
- return desc;
1329
- }
1330
- }
1331
- return (oLabel ? oLabel : oName);
1332
- },
1333
-
1334
- _getPasteMenuItems: function () {
1335
- var oMenuItems = [
1336
- new MenuItem({
1337
- text: this.oBundle.getText("pasteRowAction"),
1338
- enabled: {
1339
- parts: [{
1340
- path: "dtModel>/newTable"
1341
- }, {
1342
- path: "dtModel>/isExactlyOneRowSelected"
1343
- }],
1344
- formatter: this._decideCopyRowEnablement
1345
- },
1346
- // select: this._addNewRow.bind(this, oSelectedRows[0], true)
1347
- press: this._rowAction.bind(this, "paste")
1348
- }),
1349
- new MenuItem({
1350
- text: this.oBundle.getText("insertBeforeRowAction"),
1351
- enabled: {
1352
- parts: [{
1353
- path: "dtModel>/newTable"
1354
- }, {
1355
- path: "dtModel>/isExactlyOneRowSelected"
1356
- }],
1357
- formatter: this._decideCopyRowEnablement
1358
- },
1359
- // select: this._addNewRow.bind(this, oSelectedRows[0], false)
1360
- press: this._rowAction.bind(this, "insertBefore")
1361
- }),
1362
- new MenuItem({
1363
- text: this.oBundle.getText("insertAfterRowAction"),
1364
- enabled: {
1365
- parts: [{
1366
- path: "dtModel>/newTable"
1367
- }, {
1368
- path: "dtModel>/isExactlyOneRowSelected"
1369
- }],
1370
- formatter: this._decideCopyRowEnablement
1371
- },
1372
- // select: this._addNewRow.bind(this, oSelectedRows[0], false)
1373
- press: this._rowAction.bind(this, "insertAfter")
1374
- })
1375
- ];
1376
- return oMenuItems;
1377
- },
1378
-
1379
- _getRuleData: function () {
1380
- var contextPath = this.getBindingContextPath();
1381
- var oModel = this._getModel();
1382
- var ruleData = jQuery.extend({}, true, oModel.getProperty(contextPath, null, true));
1383
- var dtData = ruleData.DecisionTable;
1384
- dtData.DecisionTableColumns = this.dataBucket.columns;
1385
- dtData.DecisionTableRows = this.dataBucket.rows;
1386
- return ruleData;
1387
- },
1388
-
1389
- // cols
1390
- _handleColumnsDataReceived: function (oEvent) {
1391
- var data = oEvent.getParameter("data");
1392
- if (!data) {
1393
- return;
1394
- }
1395
- // change newTable flag
1396
- // set table.noData according to newTable flag
1397
- var oTable = this.getAggregation("_table");
1398
- if (data.results && data.results.length > 0) {
1399
- this._internalModel.setProperty("/newTable", false);
1400
- oTable.setNoData(null);
1401
- this._setExpressionLanguageVersionOnoData(false);
1402
- } else {
1403
- this._internalModel.setProperty("/newTable", true);
1404
- var blankContent = this._getBlankContent();
1405
- oTable.setNoData(blankContent);
1406
- this._setExpressionLanguageVersionOnoData(true);
1407
- }
1408
- this.dataBucket[dataPartName.columns] = data;
1409
- this._dataPartReceived(dataPartName.columns);
1410
- this._handleHeaderSpan();
1411
- },
1412
-
1413
- _handleColumnsDataRequested: function (oEvent) {
1414
- this._dataPartRequested(dataPartName.columns);
1415
- },
1416
-
1417
- // rows
1418
- _handleRowsDataReceived: function (oEvent) {
1419
- var data = oEvent.getParameter("data");
1420
- if (data) {
1421
- if (this.dataBucket.collectRowsMode === "replace") {
1422
- this.dataBucket[dataPartName.rows] = data;
1423
- this.dataBucket.collectRowsMode = "append";
1424
- } else {
1425
- // "append"
1426
- var previousData = this.dataBucket[dataPartName.rows];
1427
- var newData = {
1428
- results: (previousData.results) ? previousData.results.concat(data.results) : data.results
1429
- };
1430
- this.dataBucket[dataPartName.rows] = newData;
1431
- }
1432
- this._dataPartReceived(dataPartName.rows);
1433
- }
1434
- this._setTableRows();
1435
- },
1436
-
1437
- _handleRowsDataRequested: function (oEvent) {
1438
- this._dataPartRequested(dataPartName.rows);
1439
- },
1440
-
1441
- // rule
1442
- _handleRuleDataReceived: function (data) {
1443
- if (data) {
1444
- this._dataPartReceived(dataPartName.rule);
1445
- }
1446
- },
1447
-
1448
- _handleRuleDataRequested: function () {
1449
- this._dataPartRequested(dataPartName.rule);
1450
- },
1451
-
1452
- // vocabulary
1453
- _handleVocabularyDataChanged: function (oEvent) {
1454
- var data = oEvent.getParameter("data");
1455
- if (data) {
1456
- this._handleVocabularyDataReceived(data);
1457
- } else {
1458
- this._handleVocabularyDataRequested();
1459
- }
1460
- },
1461
-
1462
- _handleVocabularyDataReceived: function (data) {
1463
- if (data) {
1464
- this._dataPartReceived(dataPartName.vocabulary);
1465
- }
1466
- },
1467
-
1468
- _handleVocabularyDataRequested: function () {
1469
- this._dataPartRequested(dataPartName.vocabulary);
1470
- },
1471
-
1472
- _handleHeaderSpan: function () {
1473
- if (!this.multiHeaderFlag) {
1474
- var i;
1475
- this.multiHeaderFlag = true;
1476
- var aColumns = this.dataBucket.columns.results;
1477
- this.iNumOfCondition = 0;
1478
- this.iNumOfResults = 0;
1479
- for (i = 0; i < aColumns.length; i++) {
1480
- if (aColumns[i].Type === sap.rules.ui.DecisionTableColumn.Condition) {
1481
- this.iNumOfCondition++;
1482
- } else if (aColumns[i].Type === sap.rules.ui.DecisionTableColumn.Result) {
1483
- this.iNumOfResults++;
1484
- }
1485
- }
1486
- var oTable = this.getAggregation('_table');
1487
- aColumns = oTable.getAggregation('columns');
1488
- for (i = 0; i < this.iNumOfCondition; i++) {
1489
- aColumns[i].setHeaderSpan([this.iNumOfCondition, 1]);
1490
- }
1491
- for (; i < aColumns.length; i++) {
1492
- aColumns[i].setHeaderSpan([this.iNumOfResults, 1]);
1493
- }
1494
- }
1495
- },
1496
-
1497
- _initDataBucket: function () {
1498
- var vocaDataReceived = false;
1499
- var oEL;
1500
- if (this.getAstExpressionLanguage()) {
1501
- oEL = sap.ui.getCore().byId(this.getAstExpressionLanguage());
1502
- } else {
1503
- oEL = sap.ui.getCore().byId(this.getExpressionLanguage());
1504
- }
1505
- if (oEL && oEL._isDataExist()) {
1506
- vocaDataReceived = true;
1507
- }
1508
- this.dataBucket = {
1509
- dataReceived: {
1510
- vocabulary: vocaDataReceived,
1511
- rule: false,
1512
- rows: false,
1513
- columns: false
1514
- },
1515
- rows: {},
1516
- columns: {},
1517
- collectRowsMode: "replace" // "append"
1518
- };
1519
- },
1520
-
1521
- _initDisplayModel: function () {
1522
- this._displayModel = new sap.ui.model.json.JSONModel();
1523
- this.setModel(this._displayModel, "displayModel");
1524
- this._settingsModel = new sap.ui.model.json.JSONModel();
1525
- this.setModel(this._settingsModel, "settingModel");
1526
- },
1527
-
1528
- _initInternalModel: function () {
1529
- var data = {};
1530
- data.editable = this.getEditable();
1531
- data.newTable = true;
1532
- data.sequenceExist = true;
1533
- data.busyState = true;
1534
- data.busyTableState = true;
1535
- data.cellFormat = this.getCellFormat();
1536
- data.hitPolicies = this.getHitPolicies();
1537
- data.enableSettings = this.getEnableSettings();
1538
- data.isAtLeastOneRowSelected = false;
1539
- data.isExactlyOneRowSelected = false;
1540
- data.isSelection = false;
1541
- data.validationStatus = {};
1542
- data.valueState = {};
1543
- data.selectedRow = null;
1544
- data.conditionCellAstValues = [];
1545
- data.ruleBindingPath = "";
1546
- this._internalModel = new sap.ui.model.json.JSONModel(data);
1547
- this.setModel(this._internalModel, "dtModel");
1548
- },
1549
-
1550
- _isAllDataReceived: function () {
1551
- var dataParts = this.dataBucket.dataReceived;
1552
- return dataParts.rule && dataParts.rows && dataParts.columns && dataParts.vocabulary;
1553
- },
1554
-
1555
- _markSelection: function (bMarkSelection) {
1556
- var rowPath = this.getLineActionBuffer().rowPath;
1557
- var oTable = this.getAggregation("_table");
1558
- var oModel = this._getModel();
1559
- if (rowPath) {
1560
- var firstVisibleRow = oTable.getFirstVisibleRow();
1561
- var rowIndex = oModel.getProperty(rowPath).Sequence - 1;
1562
- if ((rowIndex - firstVisibleRow > -1) && (rowIndex - firstVisibleRow < oTable.getVisibleRowCount())) {
1563
- var oRow = oTable.getRows()[rowIndex - firstVisibleRow];
1564
- var oCells = oRow.getCells();
1565
- if (oCells) {
1566
- for (var i = 0; i < oCells.length; i++) {
1567
- if (bMarkSelection) {
1568
- //jQuery(oCells[i].getDomRef()).parent().parent().parent().addClass("sapRULDecisionTableSCellMarked");
1569
- oCells[i].addStyleClass("sapRULDecisionTableSCellMarked");
1570
- } else {
1571
- //jQuery(oCells[i].getDomRef()).parent().parent().parent().removeClass("sapRULDecisionTableSCellMarked");
1572
- oCells[i].removeStyleClass("sapRULDecisionTableSCellMarked");
1573
- }
1574
- }
1575
- }
1576
- }
1577
- }
1578
- },
1579
-
1580
- _openTableSettings: function () {
1581
- //bug 5230 - after apply we call twice to validateRule - need to clear dataBucket.rows
1582
- this.dataBucket.dataReceived.rows = false;
1583
- var decisionTableSettings = this._createDecisionTableSettings();
1584
- var oDialog = new Dialog({
1585
- contentWidth: "70%",
1586
- contentHeight: "490px",
1587
- title: this.oBundle.getText("tableSettings")
1588
- });
1589
- oDialog.addContent(decisionTableSettings);
1590
- var aButtons = decisionTableSettings.getButtons(oDialog);
1591
- for (var i = 0; i < aButtons.length; i++) {
1592
- oDialog.addButton(aButtons[i]);
1593
- }
1594
- oDialog.attachBeforeClose(function (oData) {
1595
- var dialogState = oDialog.getState();
1596
- oDialog.destroy();
1597
- //User press on "Apply" (and not on "Cancel")
1598
- if (dialogState === sap.ui.core.ValueState.Success) {
1599
- this._initDisplayModel();
1600
- this._refreshBinding();
1601
- }
1602
- }, this);
1603
- this._closePopover();
1604
- oDialog.open();
1605
- },
1606
-
1607
- /**
1608
- * @private
1609
- * @param {validateResults} validateResults -
1610
- * @param {ruleData} ruleData -
1611
- */
1612
- _processValidationResults: function (validateResults, ruleData) {
1613
- if (validateResults && validateResults.output) {
1614
- if (validateResults.output.status === "Error") {
1615
- var headerErrorsArray = [];
1616
- var columnErrorsMap = this._internalModel.getProperty("/validationStatus");
1617
- var cellValueStateMap = {};
1618
- columnErrorsMap = this._buildMessagesStructure(validateResults, columnErrorsMap, headerErrorsArray);
1619
- for (var cell in columnErrorsMap) {
1620
- if (columnErrorsMap.hasOwnProperty(cell) && (typeof columnErrorsMap[cell] === "string") && columnErrorsMap[cell] !== "null") {
1621
- cellValueStateMap[cell] = sap.ui.core.ValueState.Error;
1622
- }
1623
- }
1624
- this._displayErrorMessages(headerErrorsArray, columnErrorsMap);
1625
-
1626
- this._internalModel.setProperty("/validationStatus", columnErrorsMap, null, true);
1627
- this._internalModel.setProperty("/valueState", cellValueStateMap, null, true);
1628
- }
1629
-
1630
- var flatData = this._flatRule(validateResults.output.decisionTableData);
1631
- //validateResults.output.decisionTableData.DecisionTable.DecisionTableRows = null;
1632
- this._settingsModel.setData(validateResults.output.decisionTableData);
1633
- if (this.dataBucket.rows.results) {
1634
- this._settingsModel.rowLength = this.dataBucket.rows.results.length;
1635
- }
1636
- this._displayModel.setData(flatData, true);
1637
- }
1638
- },
1639
-
1640
- _rowAction: function (operation) {
1641
- this._rowActionWorkAround(operation);
1642
- },
1643
-
1644
- _rowActionWorkAround: function (operation) {
1645
- var selectedRow = this._internalModel.getProperty("/selectedRow");
1646
- this._markSelection(false);
1647
- var buffer = this.getLineActionBuffer();
1648
- this.setLineActionBuffer({
1649
- rowPath: null,
1650
- operation: null
1651
- });
1652
- var oTable = this.getAggregation("_table");
1653
-
1654
- var sTargetRowSeq = selectedRow + 1;
1655
- if (operation === "insertAfter") {
1656
- sTargetRowSeq++;
1657
- }
1658
- var oModel = this._getModel();
1659
- var sSourceRowId = oModel.getProperty(buffer.rowPath).Id;
1660
- var sRuleId = oModel.getProperty(buffer.rowPath).RuleId;
1661
- var sVersion = oModel.getProperty(buffer.rowPath).Version;
1662
- this._internalModel.setProperty("/busyState", true);
1663
- var isCut = (buffer.operation === "cut");
1664
- if (operation === "paste") {
1665
- this._callCopyRuleRow(sRuleId, sVersion, sSourceRowId, sTargetRowSeq, isCut, true);
1666
- } else {
1667
- this._callCopyRuleRow(sRuleId, sVersion, sSourceRowId, sTargetRowSeq, isCut, false);
1668
- }
1669
- oTable.setSelectedIndex(-1);
1670
- if (operation === "insertBefore" || operation === "insertAfter") {
1671
- sap.m.MessageToast.show(this.oBundle.getText("addRowSuccess"));
1672
- }
1673
- if (operation === "paste") {
1674
- sap.m.MessageToast.show(this.oBundle.getText("pasteSuccess"));
1675
- }
1676
- },
1677
-
1678
- _refreshBinding: function () {
1679
- var oTable = this.getAggregation("_table");
1680
- var ruleBinding = this.getElementBinding();
1681
- if (ruleBinding) {
1682
- ruleBinding.refresh();
1683
- }
1684
- var columnBinding = oTable.getBinding("columns");
1685
- if (columnBinding) {
1686
- columnBinding.refresh();
1687
- }
1688
- var rowBinding = oTable.getBinding("rows");
1689
- if (rowBinding) {
1690
- rowBinding.refresh();
1691
- }
1692
- var oEventBus = sap.ui.getCore().getEventBus();
1693
- oEventBus.publish("sap.ui.rules", "refreshDTRuleModel");
1694
- },
1695
-
1696
- _rowSelectionChange: function () {
1697
- var oTable = this.getAggregation("_table");
1698
- var oSelectedRows = [];
1699
- if (oTable) {
1700
- oSelectedRows = oTable.getSelectedIndices();
1701
- }
1702
- if (oSelectedRows.length > 0) {
1703
- this._internalModel.setProperty("/isAtLeastOneRowSelected", true);
1704
- this._internalModel.setProperty("/selectedRow", oSelectedRows[0]);
1705
- } else {
1706
- this._internalModel.setProperty("/isAtLeastOneRowSelected", false);
1707
- }
1708
- if (oSelectedRows.length == 1) {
1709
- this._internalModel.setProperty("/isExactlyOneRowSelected", true);
1710
- } else {
1711
- this._internalModel.setProperty("/isExactlyOneRowSelected", false);
1712
- }
1713
- if (this.getLineActionBuffer().rowPath) {
1714
- this._internalModel.setProperty("/isSelection", true);
1715
- } else {
1716
- this._internalModel.setProperty("/isSelection", false);
1717
- }
1718
- },
1719
-
1720
- _setDataLoadedPromise: function () {
1721
- if (!this._dataLoaded || this._dataLoaded.state() !== "pending") {
1722
- this._dataLoaded = new jQuery.Deferred();
1723
- }
1724
- },
1725
-
1726
- // set the ExpressionLanguageVersion for new rule on oData model according to the parser version, for old rule without ExpressionLanguageVersion we set old parser version on type and not on the model.
1727
- _setExpressionLanguageVersionOnoData: function (bNewRule) {
1728
- var oModel = this._getModel();
1729
- var oContext = this.getBindingContext();
1730
- var sVersion = "1.0.0";
1731
- if (bNewRule) {
1732
- var oEL;
1733
- if (this.getAstExpressionLanguage()) {
1734
- oEL = sap.ui.getCore().byId(this.getAstExpressionLanguage());
1735
- sVersion = "2.0.0";
1736
- } else {
1737
- oEL = sap.ui.getCore().byId(this.getExpressionLanguage());
1738
- sVersion = oEL.getExpressionLanguageVersion();
1739
- }
1740
- oModel.setProperty("ExpressionLanguageVersion", sVersion, oContext, true);
1741
- } else {
1742
- sVersion = oModel.getProperty(this.getBindingContextPath() + '/ExpressionLanguageVersion');
1743
- if (!sVersion) {
1744
- sVersion = "1.0.0";
1745
- }
1746
- }
1747
- this._decisionTableCellFormatter.setExpressionLanguageVersion(sVersion);
1748
- },
1749
-
1750
- _setTableRows: function () {
1751
- var oTable = this.getAggregation("_table");
1752
- var oRowBinding = oTable.getBinding("rows");
1753
- var iVisibleRowCount = emptyTable;
1754
- if (oRowBinding && oRowBinding.getLength()) {
1755
- iVisibleRowCount = Math.min(oRowBinding.getLength(), this.VISIBLEROWCOUNT);
1756
- }
1757
-
1758
- var currVisibleRowCount = oTable.getVisibleRowCount();
1759
- if (currVisibleRowCount !== iVisibleRowCount) {
1760
- oTable.setVisibleRowCount(iVisibleRowCount);
1761
- }
1762
- if ((this.dataBucket && this.dataBucket.rows && this.dataBucket.rows.results.length === 0) || !this.getEditable()) {
1763
- oTable.setSelectionMode(sap.ui.table.SelectionMode.None);
1764
- } else {
1765
- oTable.setSelectionMode(sap.ui.table.SelectionMode.MultiToggle);
1766
- }
1767
- },
1768
-
1769
- _unbindColumns: function () {
1770
- var oTable = this.getAggregation("_table");
1771
- oTable.unbindColumns();
1772
- },
1773
-
1774
- _unbindRows: function () {
1775
- var oTable = this.getAggregation("_table");
1776
- oTable.unbindRows();
1777
- },
1778
-
1779
- _unbindRule: function () {
1780
- this.unbindElement();
1781
- },
1782
-
1783
- _updateBusyState: function () {
1784
- var dataParts = this.dataBucket.dataReceived;
1785
- var dataReceived = dataParts.rule && dataParts.columns && dataParts.vocabulary;
1786
- var isBusy = !dataReceived;
1787
- this._internalModel.setProperty("/busyState", isBusy);
1788
- var tableIsBusy = !dataParts.rows;
1789
- this._internalModel.setProperty("/busyTableState", tableIsBusy);
1790
- },
1791
-
1792
- _updateTableCell: function (oCell, oRowContext, dtDomElement, rowIndex) {
1793
- //jQuery(oCell.getDomRef()).parent().parent().parent().removeClass("sapRULDecisionTableSCellMarked");
1794
- oCell.removeStyleClass("sapRULDecisionTableSCellMarked");
1795
- var path = "null";
1796
- var that = this;
1797
- var oParent = this.getParent();
1798
-
1799
- if (oRowContext) {
1800
- var colId = oCell.data("colId");
1801
- var rowId = oRowContext.getProperty("Id");
1802
- var ruleId = oRowContext.getProperty("RuleId");
1803
- var version = oRowContext.getProperty("Version");
1804
- var oModel = oRowContext.getModel();
1805
-
1806
- var headerPath = '';
1807
- var rulePath = '';
1808
- // NOTE: we assume that colId represents also the order of Columns and starts from 1
1809
- var oCellProperties = {
1810
- RuleId :ruleId,
1811
- ColId: colId,
1812
- RowId: rowId,
1813
- Version: version
1814
- };
1815
- var cellBindingPath = oModel.createKey("/DecisionTableRowCells", oCellProperties);
1816
- var oCellContext = new sap.ui.model.Context(oModel, cellBindingPath);
1817
-
1818
- //Condition path from model
1819
- var oProperties = {
1820
- RuleId: ruleId,
1821
- Id: colId,
1822
- Version: version
1823
- };
1824
- var sConditionPath = oModel.createKey("/DecisionTableColumnConditions", oProperties);
1825
- var columnArray = oParent.getModel("dtModel").getData().conditionCellAstValues;
1826
-
1827
- //var bindModelName = oCell.data("bindModelName");
1828
-
1829
- var cellKeyProperties = {
1830
- RuleId: ruleId,
1831
- Id: colId,
1832
- Version: version
1833
- };
1834
-
1835
- var ruleKeyProperties = {
1836
- Id: ruleId,
1837
- Version: version
1838
- };
1839
-
1840
- path = cellBindingPath + "/Content";
1841
-
1842
- switch (oCell.data("colType")) {
1843
- case "CONDITION":
1844
- headerPath = "/" + oModel.createKey("DecisionTableColumnConditions", cellKeyProperties);
1845
- rulePath = "/" + oModel.createKey("Rules", ruleKeyProperties);
1846
- oCell.setHeaderValuePath(headerPath + '/Expression');
1847
- oCell.setFixedOperatorPath(headerPath + '/FixedOperator');
1848
- oCell.setRuleFormatPath(rulePath + '/RuleFormat');
1849
- oCell.setDecisionTableFormat(that.getParent().getDecisionTableFormat());
1850
- oCell.setValueOnlyPath(headerPath + '/ValueOnly');
1851
- if (columnArray[sConditionPath]) {
1852
- oCell.setHeaderInfo(columnArray[sConditionPath]);
1853
- }
1854
- break;
1855
- case "RESULT":
1856
- headerPath = "/" + oModel.createKey("DecisionTableColumnResults", cellKeyProperties);
1857
- rulePath = "/" + oModel.createKey("Rules", ruleKeyProperties);
1858
- oCell.setTypePath(headerPath + '/BusinessDataType');
1859
- if (sap.ui.getCore().byId(oParent.getAstExpressionLanguage())) {
1860
- var sResultDataObjectId = oParent.getModel("settingModel").getData().ResultDataObjectId;
1861
- var sAttributeId = oModel.getProperty(headerPath + '/DataObjectAttributeId');
1862
- oCell.setAttributeInfoPath("/" + sResultDataObjectId + "/" + that.getParent()._formatAttributeId(sAttributeId));
1863
- } else {
1864
- oCell.setAttributeInfoPath(headerPath + '/DataObjectAttributeId');
1865
- }
1866
- oCell.setAttributeNamePath(headerPath + '/DataObjectAttributeName');
1867
- oCell.setRuleFormatPath(rulePath + '/RuleFormat');
1868
- oCell.setDecisionTableFormat(that.getParent().getDecisionTableFormat());
1869
- break;
1870
-
1871
- default:
1872
- break;
1873
- }
1874
-
1875
- oCell.setKeyProperties(oCellProperties);
1876
- oCell.setValueStateTextPath("dtModel>/validationStatus/" + "RowId=" + rowId + ",ColId=" + colId);
1877
- oCell.setValueStatePath("dtModel>/valueState/" + "RowId=" + rowId + ",ColId=" + colId);
1878
- }
1879
-
1880
- oCell.setValuePath(path);
1881
- },
1882
-
1883
- //In case of reference object we will have attribues with ":" which should be replace by /
1884
- _formatAttributeId: function (attributeId) {
1885
- var formattedAttributeId = attributeId;
1886
- if(formattedAttributeId && formattedAttributeId.indexOf(":") > -1) {
1887
- formattedAttributeId = formattedAttributeId.replace(/:/g, "/");
1888
- }
1889
- return formattedAttributeId
1890
- },
1891
-
1892
- exit: function () {
1893
- var oMenu = this.oMenu;
1894
- if (oMenu) {
1895
- oMenu.destroy();
1896
- }
1897
- },
1898
-
1899
- init: function () {
1900
- this.multiHeaderFlag = false; //flag for calculate only once header span for multi header in columnFactory function
1901
- this.resetContent = true;
1902
- this.astUtil = new AstUtil();
1903
- this._initInternalModel();
1904
- this._initDisplayModel();
1905
- this._initDataBucket();
1906
- this.bindProperty("busy", "dtModel>/busyState");
1907
- this.oBundle = sap.ui.getCore().getLibraryResourceBundle("sap.rules.ui.i18n");
1908
- this._addToolBar();
1909
- this._addTable();
1910
- this._addErrorLabel();
1911
- this._decisionTableCellFormatter = new DecisionTableCellFormatter();
1912
- this.setBusyIndicatorDelay(0);
1913
- },
1914
-
1915
- isSequenceExistsInOdataMetadata: function () {
1916
- var model = this.getModel();
1917
- if (model) {
1918
- var serviceMetadata = model.getServiceMetadata();
1919
- if (serviceMetadata) {
1920
- var aEntities = serviceMetadata.dataServices.schema[0].entityType;
1921
- var entity;
1922
- var aProperties;
1923
- var property;
1924
-
1925
- for (var i = 0; i < aEntities.length; i++) {
1926
- entity = aEntities[i];
1927
-
1928
- if (entity.name !== "DecisionTableColumn") {
1929
- continue;
1930
- }
1931
-
1932
- aProperties = entity.property;
1933
-
1934
- for (var j = 0; j < aProperties.length; j++) {
1935
- property = aProperties[j];
1936
-
1937
- if (property.name === "Sequence") {
1938
- return true;
1939
- }
1940
- }
1941
- }
1942
- }
1943
- }
1944
- return false;
1945
- },
1946
-
1947
- onBeforeRendering: function () {
1948
- if (this.resetContent) {
1949
- this.resetControl();
1950
- this.resetContent = false;
1951
- }
1952
- },
1953
-
1954
- resetControl: function () {
1955
- this._unbindRule();
1956
- this._unbindRows();
1957
- this._unbindColumns();
1958
- this._clearErrorMessages();
1959
- this._initDataBucket();
1960
- this._initDisplayModel();
1961
- this._updateBusyState();
1962
- var oModel = this._getModel();
1963
- var bindingContextPath = this.getBindingContextPath();
1964
- if (!bindingContextPath || !oModel) {
1965
- return;
1966
- }
1967
- var oContext = new sap.ui.model.Context(oModel, bindingContextPath);
1968
- this._internalModel.setProperty("/ruleBindingPath", bindingContextPath);
1969
- this.setBindingContext(oContext);
1970
- this._bindRule();
1971
- this._bindRows();
1972
- this._bindColumns();
1973
- },
1974
-
1975
- /** Control's properties getters/setters */
1976
- setAstExpressionLanguage: function (value) {
1977
- this.setAssociation("astExpressionLanguage", value, true);
1978
- var astExpressionLanguage = (value instanceof Object) ? value : sap.ui.getCore().byId(value);
1979
- if (!astExpressionLanguage) {
1980
- return this;
1981
- }
1982
-
1983
- // if table has been built already - refresh it
1984
- var oTable = this.getAggregation("_table");
1985
- if (oTable) {
1986
- var columnBinding = oTable.getBinding("columns");
1987
- if (columnBinding) {
1988
- columnBinding.refresh();
1989
- }
1990
- }
1991
-
1992
- if (astExpressionLanguage._isDataExist()) {
1993
- var oEvent = new sap.ui.base.Event("", "", {
1994
- data: true
1995
- });
1996
- this._handleVocabularyDataChanged(oEvent);
1997
- }
1998
- astExpressionLanguage.attachDataChange(this._handleVocabularyDataChanged.bind(this));
1999
-
2000
- return this;
2001
- },
2002
-
2003
- setBindingContextPath: function (value) {
2004
- var oldValue = this.getBindingContextPath();
2005
- if (value && (oldValue !== value)) {
2006
- this._unbindRule();
2007
- this._unbindRows();
2008
- this._unbindColumns();
2009
- this.setProperty("bindingContextPath", value);
2010
- this.resetContent = true;
2011
-
2012
- // reset dataBucket now (don't wait for onBeforeRendering),
2013
- // attemption for preventing possible convertAndFormat with wrong data
2014
- this._initDataBucket();
2015
- var oModel = this.getModel()
2016
- if (!oModel.isMetadataLoadingFailed()) {
2017
- if (oModel.getServiceMetadata()) {
2018
- this._internalModel.setProperty("/sequenceExist", this.isSequenceExistsInOdataMetadata());
2019
- } else {
2020
- oModel.attachMetadataLoaded(function () {
2021
- this._internalModel.setProperty("/sequenceExist", this.isSequenceExistsInOdataMetadata());
2022
- }.bind(this));
2023
- }
2024
- }
2025
- }
2026
- return this;
2027
- },
2028
-
2029
- setCellFormat: function (value) {
2030
- this.setProperty("cellFormat", value, true);
2031
- this._internalModel.setProperty("/cellFormat", value);
2032
- return this;
2033
- },
2034
-
2035
- setEditable: function (value) {
2036
- this.setProperty("editable", value, true);
2037
- this._internalModel.setProperty("/editable", value);
2038
- this._internalModel.setProperty("/sequenceExist", this.isSequenceExistsInOdataMetadata());
2039
- var oTable = this.getAggregation("_table");
2040
- var oToolbar = this.getAggregation("_toolbar");
2041
- if (value === false) {
2042
- oTable.addStyleClass("sapRULDecisionTableEdit");
2043
- oToolbar.removeStyleClass("sapRULDecisionTableToolBar");
2044
- } else {
2045
- oTable.removeStyleClass("sapRULDecisionTableEdit");
2046
- oToolbar.addStyleClass("sapRULDecisionTableToolBar");
2047
- }
2048
- if (value === false) {
2049
- this._clearErrorMessages();
2050
- }
2051
- return this;
2052
- },
2053
-
2054
- setEnableSettings: function (value) {
2055
- this.setProperty("enableSettings", value, true);
2056
- this._internalModel.setProperty("/enableSettings", value);
2057
- return this;
2058
- },
2059
-
2060
- setEnableSettingResult: function (value) {
2061
- this.setProperty("enableSettingResult", value, true);
2062
- return this;
2063
- },
2064
-
2065
- setExpressionLanguage: function (value) {
2066
- this.setAssociation("expressionLanguage", value, true);
2067
- this._decisionTableCellFormatter.setExpressionLanguage(this.getExpressionLanguage());
2068
- var expressionLanguage = (value instanceof Object) ? value : sap.ui.getCore().byId(value);
2069
- if (!expressionLanguage) {
2070
- return this;
2071
- }
2072
-
2073
- // if table has been built already - refresh it
2074
- var oTable = this.getAggregation("_table");
2075
- if (oTable) {
2076
- var columnBinding = oTable.getBinding("columns");
2077
- if (columnBinding) {
2078
- columnBinding.refresh();
2079
- }
2080
- }
2081
-
2082
- if (expressionLanguage._isDataExist()) {
2083
- var oEvent = new sap.ui.base.Event("", "", {
2084
- data: true
2085
- });
2086
- this._handleVocabularyDataChanged(oEvent);
2087
- }
2088
- expressionLanguage.attachDataChange(this._handleVocabularyDataChanged.bind(this));
2089
-
2090
- return this;
2091
- },
2092
-
2093
- setHitPolicies: function (value) {
2094
- this.setProperty("hitPolicies", value, true);
2095
- this._internalModel.setProperty("/hitPolicies", value);
2096
- return this;
2097
- },
2098
-
2099
- setModelName: function (value) {
2100
- this.setProperty("modelName", value);
2101
- this.resetContent = true;
2102
- return this;
2103
- }
2104
-
2105
- });
2106
-
2107
- /**
2108
- * @private
2109
- * @param {map} mParameters? -
2110
- */
2111
- sap.rules.ui.DecisionTable.prototype._saveWorkAround = function (mParameters, toastMessage) {
2112
- var oModel = this._getModel();
2113
- oModel.submitChanges(mParameters);
2114
- sap.m.MessageToast.show(toastMessage);
2115
- };
2116
-
2117
- sap.rules.ui.DecisionTable.prototype.includes = function (parent, str) {
2118
- var returnValue = false;
2119
-
2120
- if (parent.indexOf(str) !== -1) {
2121
- returnValue = true;
2122
- }
2123
-
2124
- return returnValue;
2125
- };
2126
-
2127
- sap.rules.ui.DecisionTable.prototype._getLocaleData = function () {
2128
- var oLocale = sap.ui.getCore().getConfiguration().getFormatSettings().getFormatLocale();
2129
- return LocaleData.getInstance(oLocale);
2130
- };
2131
-
2132
- sap.rules.ui.DecisionTable.prototype._getDateFormatter = function () {
2133
- var oLocaleData = this._getLocaleData();
2134
- var datePattern = oLocaleData.getDatePattern('medium');
2135
- var dateFormatter = sap.ui.core.format.DateFormat.getDateInstance({
2136
- pattern: datePattern
2137
- });
2138
- return dateFormatter;
2139
- };
2140
-
2141
- sap.rules.ui.DecisionTable.prototype._getDateTimeFormatter = function () {
2142
- var oLocaleData = this._getLocaleData();
2143
- var datePattern = oLocaleData.getDatePattern('medium');
2144
- var timePattern = oLocaleData.getTimePattern('medium');
2145
- var dateTimeFormatter = sap.ui.core.format.DateFormat.getDateTimeInstance({
2146
- pattern: datePattern + " " + timePattern
2147
- });
2148
- return dateTimeFormatter;
2149
- };
2150
-
2151
- sap.rules.ui.DecisionTable.prototype.VISIBLEROWCOUNT = 30;
2152
-
2153
- sap.rules.ui.DecisionTable.prototype.THRESHOLD = 30;
2154
-
2155
- return oDecisionTable;
2156
-
2157
- }, /* bExport= */ true);
5
+
6
+ */
7
+
8
+ // Provides this._validatecontrol sap.rules.ui.
9
+ sap.ui.define([
10
+ "sap/base/Log",
11
+ "jquery.sap.global",
12
+ "./library",
13
+ "sap/rules/ui/DecisionTableCell",
14
+ "sap/rules/ui/RuleBase",
15
+ "sap/rules/ui/Utils",
16
+ "sap/ui/table/Table",
17
+ "sap/ui/table/Column",
18
+ "sap/m/OverflowToolbar",
19
+ "sap/m/Popover",
20
+ "sap/m/Menu",
21
+ "sap/m/Dialog",
22
+ "sap/m/MenuButton",
23
+ "sap/m/Button",
24
+ "sap/m/ToolbarSpacer",
25
+ "sap/m/Text",
26
+ "sap/m/Input",
27
+ "sap/m/ObjectIdentifier",
28
+ "sap/m/Link",
29
+ "sap/m/Label",
30
+ "sap/m/BusyIndicator",
31
+ "sap/m/DisplayListItem",
32
+ "sap/m/MenuItem",
33
+ "sap/m/FlexBox",
34
+ "sap/m/MessageStrip",
35
+ "sap/rules/ui/DecisionTableSettingsOld",
36
+ "sap/rules/ui/type/DecisionTableCell",
37
+ "sap/rules/ui/ast/constants/Constants",
38
+ "sap/rules/ui/services/AstExpressionLanguage",
39
+ "sap/rules/ui/ast/util/AstUtil",
40
+ "sap/rules/ui/Constants",
41
+ "sap/ui/core/LocaleData",
42
+ "./DecisionTableRenderer"
43
+
44
+ ], function (Log, jQuery, library, DecisionTableCell, RuleBase, Utils, Table, Column, OverflowToolbar, Popover, Menu, Dialog, MenuButton, Button,
45
+ ToolbarSpacer, Text, Input, ObjectIdentifier, Link, Label, BusyIndicator, DisplayListItem, MenuItem, FlexBox, MessageStrip,
46
+ DecisionTableSettingsOld, DecisionTableCellFormatter, ConstantUtils, AstExpressionLanguage, AstUtil, Constants, LocaleData, DecisionTableRenderer) {
47
+
48
+ "use strict";
49
+
50
+ /**
51
+ * Constructor for a new DecisionTable Control.
52
+ *
53
+ * @param {string} [sId] id for the new control, generated automatically if no id is given
54
+ * @param {object} [mSettings] initial settings for the new control
55
+ *
56
+ * @class
57
+ * Some class description goes here.
58
+ * @extends Control
59
+ *
60
+ * @author SAP SE
61
+ * @version 1.108.0
62
+ *
63
+ * @constructor
64
+ * @private
65
+ * @alias sap.rules.ui.DecisionTable
66
+ * @ui5-metamodel This control/element also will be described in the UI5 (legacy) design time meta model
67
+ */
68
+
69
+ var dataPartName = {
70
+ vocabulary: "vocabulary",
71
+ rule: "rule",
72
+ columns: "columns",
73
+ rows: "rows"
74
+ };
75
+
76
+ var emptyTable = 3;
77
+
78
+ var oDecisionTable = RuleBase.extend("sap.rules.ui.DecisionTable", {
79
+ metadata: {
80
+ properties: {
81
+ enableSettings: {
82
+ type: "boolean",
83
+ group: "Misc",
84
+ defaultValue: false
85
+ },
86
+ enableSettingResult: {
87
+ type: "boolean",
88
+ defaultValue: true
89
+ },
90
+ cellFormat: {
91
+ type: "sap.rules.ui.DecisionTableCellFormat",
92
+ defaultValue: sap.rules.ui.DecisionTableCellFormat.Both
93
+ },
94
+ hitPolicies: {
95
+ type: "sap.rules.ui.RuleHitPolicy[]",
96
+ defaultValue: [sap.rules.ui.RuleHitPolicy.FirstMatch, sap.rules.ui.RuleHitPolicy.AllMatch]
97
+ },
98
+ lineActionBuffer: {
99
+ type: "any",
100
+ defaultValue: {
101
+ rowPath: null,
102
+ operation: null
103
+ }
104
+ },
105
+ decisionTableFormat: {
106
+ type: "sap.rules.ui.DecisionTableFormat",
107
+ defaultValue: sap.rules.ui.DecisionTableFormat.CellFormat
108
+ },
109
+ threshold: {
110
+ type: "int",
111
+ defaultValue: 999
112
+ },
113
+ visibleRowCount: {
114
+ type: "int",
115
+ defaultValue: 999
116
+ }
117
+ },
118
+ aggregations: {
119
+ "_toolbar": {
120
+ type: "sap.m.OverflowToolbar",
121
+ multiple: false,
122
+ singularName: "_toolbar"
123
+ },
124
+ "_table": {
125
+ type: "sap.ui.core.Control",
126
+ multiple: false,
127
+ singularName: "_table"
128
+ },
129
+ "_errorsText": {
130
+ type: "sap.m.MessageStrip", //"sap.m.Text",
131
+ multiple: false,
132
+ singularName: "_errorsText"
133
+ }
134
+ },
135
+ associations: {
136
+ /**
137
+ * Association to controls / IDs which label this control (see WAI-ARIA attribute <code>aria-labelledby</code>).
138
+ */
139
+ ariaLabelledBy: {
140
+ type: "sap.ui.core.Control",
141
+ multiple: true,
142
+ singularName: "ariaLabelledBy"
143
+ },
144
+ ariaRoleDescription: {
145
+ type: "sap.ui.core.Control",
146
+ multiple: true,
147
+ singularName: "ariaRoleDescription"
148
+ }
149
+ }
150
+ },
151
+
152
+ _addErrorLabel: function () {
153
+ //var oErrorLabel = new sap.m.Text().addStyleClass("sapThemeCriticalText").addStyleClass("sapUiSmallMargin");
154
+ var oErrorLabel = new MessageStrip({
155
+ showCloseButton: true,
156
+ showIcon: true,
157
+ type: sap.ui.core.MessageType.Error,
158
+ visible: false
159
+ }).addStyleClass("sapUiTinyMargin");
160
+ this.setAggregation("_errorsText", oErrorLabel, true);
161
+ },
162
+
163
+ _addNewRow: function (selectedRow, bFirst) {
164
+ var oMenu = this.oMenu;
165
+ if (oMenu) {
166
+ oMenu.close();
167
+ }
168
+ var oModel = this._getModel();
169
+ var columns = this.dataBucket.columns && this.dataBucket.columns.results;
170
+ if (!oModel || !columns) {
171
+ return;
172
+ }
173
+ var oTable = this.getAggregation("_table"),
174
+ oContext = this.getBindingContext(),
175
+ sRuleId = oContext.getProperty("Id"),
176
+ sVersion = oContext.getProperty("Version");
177
+ var oRowData = {
178
+ RuleId: sRuleId,
179
+ Version: sVersion
180
+ };
181
+ selectedRow = selectedRow || 0;
182
+ var rowPath;
183
+ if (bFirst) {
184
+ oRowData.Sequence = 1;
185
+ } else {
186
+ rowPath = oTable.getContextByIndex(selectedRow).getPath();
187
+ oRowData.Sequence = oModel.getProperty(rowPath).Sequence;
188
+ oRowData.Sequence++;
189
+ }
190
+ oRowData.Id = this._calNextRowId();
191
+ // create row
192
+ oModel.createEntry("/DecisionTableRows", {
193
+ properties: oRowData
194
+ });
195
+ oTable.setSelectedIndex(oRowData.Sequence -1);
196
+ this._clearErrorMessages();
197
+ this._saveWorkAround([],this.oBundle.getText("addRowSuccess"));
198
+ },
199
+
200
+ _addNewRowWorkaround: function (bFirst) {
201
+ var selectedRow = this._internalModel.getProperty("/selectedRow");
202
+ this._addNewRow(selectedRow, bFirst);
203
+ },
204
+
205
+ _addNodeObject: function (astNode) {
206
+ var oNodeArray = [];
207
+ var oAstExpressionLanguage = sap.ui.getCore().byId(this.getAstExpressionLanguage());
208
+ var oAstUtil = oAstExpressionLanguage._astBunldeInstance.ASTUtil;
209
+
210
+ var updatedAstNode = [];
211
+ updatedAstNode.Root = astNode.Root;
212
+ updatedAstNode.SequenceNumber = astNode.Sequence;
213
+ updatedAstNode.ParentId = astNode.ParentId;
214
+ updatedAstNode.Reference = astNode.Reference;
215
+ updatedAstNode.Id = astNode.NodeId;
216
+ updatedAstNode.Type = astNode.Type;
217
+ updatedAstNode.Value = astNode.Value ? astNode.Value : "";
218
+ if (astNode.Type === "I") {
219
+ updatedAstNode.Value = astNode.IncompleteExpression;
220
+ }
221
+ if (astNode.Function) {
222
+ updatedAstNode.Function = astNode.Function;
223
+ }
224
+ if (astNode.Type !== "P" && astNode.Type !== "O" && !astNode.Function) {
225
+ var Output = [];
226
+ Output.BusinessDataType = astNode.Output ? astNode.Output.BusinessDataType : astNode.BusinessDataType;
227
+ Output.DataObjectType = astNode.Output ? astNode.Output.DataObjectType : astNode.DataObjectType;
228
+ updatedAstNode.Output = Output;
229
+ }
230
+ oAstUtil.createNode(updatedAstNode);
231
+ },
232
+
233
+ _addTable: function () {
234
+ var oTable = new Table({
235
+ visibleRowCount: this.VISIBLEROWCOUNT,
236
+ threshold: this.THRESHOLD,
237
+ visibleRowCountMode: sap.ui.table.VisibleRowCountMode.Fixed,
238
+ selectionMode: {
239
+ parts: [{
240
+ path: "dtModel>/editable"
241
+ }],
242
+ formatter: this._decideSelectionMode
243
+ },
244
+ rowSelectionChange: function () {
245
+ this.oParent._rowSelectionChange();
246
+ },
247
+ enableColumnReordering: false,
248
+ busy: "{dtModel>/busyTableState}"
249
+ });
250
+ oTable._updateTableCell = this._updateTableCell;
251
+ oTable.setBusyIndicatorDelay(0);
252
+ this.setAggregation("_table", oTable, true);
253
+ },
254
+
255
+ /*
256
+ * @private
257
+ */
258
+ _addToolBar: function () {
259
+ var oToolbar = new OverflowToolbar({
260
+ design: "Transparent",
261
+ enabled: "{dtModel>/editable}"
262
+ });
263
+ var oTitle = new sap.m.Title({
264
+ text: this.oBundle.getText("decisionTable"),
265
+ tooltip:this.oBundle.getText("decisionTable")
266
+ });
267
+ var oAddLink = new MenuButton({
268
+ text: this.oBundle.getText("addRow"),
269
+ visible: "{dtModel>/editable}",
270
+ enabled: {
271
+ parts: [{
272
+ path: "dtModel>/newTable"
273
+ }],
274
+ formatter: this._decideAddRowEnablement
275
+ },
276
+ menu: new Menu({
277
+ items: this._getMenuItems()
278
+ })
279
+ }).setTooltip(this.oBundle.getText("addRow"));
280
+
281
+ var oDeleteLink = new Button({
282
+ text: this.oBundle.getText("deleteRow"),
283
+ press: [this._deleteRowWorkaround, this],
284
+ visible: "{dtModel>/editable}",
285
+ type: sap.m.ButtonType.Transparent,
286
+ enabled: {
287
+ parts: [{
288
+ path: "dtModel>/newTable"
289
+ }, {
290
+ path: "dtModel>/isAtLeastOneRowSelected"
291
+ }],
292
+ formatter: this._decideDeleteRowEnablement
293
+ }
294
+ }).setTooltip(this.oBundle.getText("deleteRow"));
295
+
296
+ var oCopyLink = new Button({
297
+ text: this.oBundle.getText("copyRow"),
298
+ press: [this._copyRow, this],
299
+ type: sap.m.ButtonType.Transparent,
300
+ visible: {
301
+ parts: [{
302
+ path: "dtModel>/editable"
303
+ }, {
304
+ path: "dtModel>/sequenceExist"
305
+ }],
306
+ formatter: this._decideLineActionVisibility
307
+ },
308
+ enabled: {
309
+ parts: [{
310
+ path: "dtModel>/newTable"
311
+ }, {
312
+ path: "dtModel>/isExactlyOneRowSelected"
313
+ }],
314
+ formatter: this._decideCopyRowEnablement
315
+ }
316
+ }).setTooltip(this.oBundle.getText("copyRow"));
317
+
318
+ var oCutLink = new Button({
319
+ text: this.oBundle.getText("cutRow"),
320
+ type: sap.m.ButtonType.Transparent,
321
+ press: [this._cutRow, this],
322
+ visible: {
323
+ parts: [{
324
+ path: "dtModel>/editable"
325
+ }, {
326
+ path: "dtModel>/sequenceExist"
327
+ }],
328
+ formatter: this._decideLineActionVisibility
329
+ },
330
+ enabled: {
331
+ parts: [{
332
+ path: "dtModel>/newTable"
333
+ }, {
334
+ path: "dtModel>/isExactlyOneRowSelected"
335
+ }],
336
+ formatter: this._decideCopyRowEnablement
337
+ }
338
+ }).setTooltip(this.oBundle.getText("cutRow"));
339
+
340
+ var oPasteLink = new MenuButton({
341
+ text: this.oBundle.getText("pasteRow"),
342
+ type: sap.m.ButtonType.Transparent,
343
+ visible: {
344
+ parts: [{
345
+ path: "dtModel>/editable"
346
+ }, {
347
+ path: "dtModel>/sequenceExist"
348
+ }],
349
+ formatter: this._decideLineActionVisibility
350
+ },
351
+ enabled: {
352
+ parts: [{
353
+ path: "dtModel>/newTable"
354
+ }, {
355
+ path: "dtModel>/isExactlyOneRowSelected"
356
+ }, {
357
+ path: "dtModel>/isSelection"
358
+ }],
359
+ formatter: this._decidePasteRowEnablement
360
+ },
361
+ menu: new Menu({
362
+ items: this._getPasteMenuItems()
363
+ })
364
+ }).setTooltip(this.oBundle.getText("pasteRow"));
365
+
366
+ var oSettingsButton = new Button({
367
+ text: "",
368
+ press: this._openTableSettings.bind(this),
369
+ visible: {
370
+ parts: [{
371
+ path: "dtModel>/enableSettings"
372
+ }, {
373
+ path: "dtModel>/editable"
374
+ }],
375
+ formatter: this._decideSettingsEnablement
376
+ },
377
+ enabled: {
378
+ parts: [{
379
+ path: "dtModel>/enableSettings"
380
+ }, {
381
+ path: "dtModel>/editable"
382
+ }],
383
+ formatter: this._decideSettingsEnablement
384
+ }
385
+ }).setTooltip(this.oBundle.getText("tableSettings"));
386
+ oSettingsButton.setIcon("sap-icon://action-settings");
387
+
388
+ // Remove space in order to align DT title to left
389
+ // oToolbar.addContent(new ToolbarSpacer({
390
+ // width: "1em"
391
+ // }));
392
+
393
+ oToolbar.addContent(oTitle);
394
+ oToolbar.addContent(new ToolbarSpacer({}));
395
+ oToolbar.addContent(oAddLink);
396
+ oToolbar.addContent(new ToolbarSpacer({
397
+ width: "1em"
398
+ }));
399
+ oToolbar.addContent(oDeleteLink);
400
+ oToolbar._delete = oDeleteLink;
401
+
402
+ oToolbar.addContent(new ToolbarSpacer({
403
+ width: "1em"
404
+ }));
405
+ oToolbar.addContent(oCopyLink);
406
+ oToolbar.addContent(new ToolbarSpacer({
407
+ width: "1em"
408
+ }));
409
+ oToolbar.addContent(oCutLink);
410
+ oToolbar.addContent(new ToolbarSpacer({
411
+ width: "1em"
412
+ }));
413
+ oToolbar.addContent(oPasteLink);
414
+ oToolbar.addContent(new ToolbarSpacer({
415
+ width: "1em"
416
+ }));
417
+
418
+ oToolbar.addContent(oSettingsButton);
419
+ oToolbar.addContent(new ToolbarSpacer({
420
+ width: "1em"
421
+ }));
422
+
423
+ this.setAggregation("_toolbar", oToolbar, true);
424
+ },
425
+
426
+ _bindColumns: function () {
427
+ var oTable = this.getAggregation("_table");
428
+ var bindingPath = [this._getBindModelName(), this.getBindingContextPath(), "/DecisionTable/DecisionTableColumns"].join("");
429
+ var expandPath = "Condition,Result";
430
+ if(this.getAstExpressionLanguage()){
431
+ expandPath = "Condition/DecisionTableColumnConditionASTs,Result/DecisionTableColumnResultASTs";
432
+ }
433
+
434
+ oTable.bindColumns({
435
+ path: bindingPath,
436
+ parameters: {
437
+ expand: expandPath
438
+ },
439
+ factory: this._columnFactory.bind(this)
440
+ });
441
+
442
+ oTable.getBinding("columns").attachDataRequested(this._handleColumnsDataRequested, this);
443
+ oTable.getBinding("columns").attachDataReceived(this._handleColumnsDataReceived, this);
444
+ oTable.attachColumnResize(oTable, this._onColumnResize, this);
445
+ },
446
+
447
+ _onColumnResize: function () {
448
+ this.columnResized = true;
449
+ var obj = { "colResize" : true };
450
+ var oEventBus = sap.ui.getCore().getEventBus();
451
+ oEventBus.publish("sap.ui.rules","_onColumnResized", obj);
452
+ },
453
+
454
+ _bindRows: function () {
455
+ var oTable = this.getAggregation("_table");
456
+ var bindingPath = [this._getBindModelName(), this.getBindingContextPath(), "/DecisionTable/DecisionTableRows"].join("");
457
+ var expandPath = "Cells";
458
+ if(this.getAstExpressionLanguage()){
459
+ expandPath = "Cells/DecisionTableRowCellASTs";
460
+ }
461
+ var oSorter = new sap.ui.model.Sorter("Sequence");
462
+
463
+ oTable.bindRows({
464
+ path: bindingPath,
465
+ parameters: {
466
+ expand: expandPath
467
+ },
468
+ sorter: oSorter
469
+ });
470
+
471
+ oTable.getBinding("rows").attachDataRequested(this._handleRowsDataRequested, this);
472
+ oTable.getBinding("rows").attachDataReceived(this._handleRowsDataReceived, this);
473
+ },
474
+
475
+ _bindRule: function () {
476
+ var bindingPath = [this._getBindModelName(), this.getBindingContextPath()].join("");
477
+ this.bindElement({
478
+ path: bindingPath,
479
+ parameters: {
480
+ expand: "DecisionTable"
481
+ }
482
+ });
483
+
484
+ this.getElementBinding().attachDataRequested(this._handleRuleDataRequested, this);
485
+ this.getElementBinding().attachDataReceived(this._handleRuleDataReceived, this);
486
+
487
+ // force data load (otherwise if data exists there is no data fetch)
488
+ this.getElementBinding().refresh();
489
+ },
490
+
491
+ _buildMessagesStructure: function (validateResults, columnErrorsMap, headerErrorArray) {
492
+ var detail;
493
+ var additionalInfo;
494
+ var description;
495
+ var errorKey;
496
+ if (!validateResults.details) {
497
+ return columnErrorsMap;
498
+ }
499
+
500
+ for (var w = 0; w < validateResults.details.length; w++) {
501
+ detail = validateResults.details[w];
502
+ if (!detail.messages) {
503
+ continue;
504
+ }
505
+ for (var i = 0; i < detail.messages.length; i++) {
506
+ description = detail.messages[i].description;
507
+ additionalInfo = detail.messages[i].additionalInfo;
508
+ if (additionalInfo.type === "ruleResult") {
509
+ headerErrorArray.push(description);
510
+ errorKey = "genericError";
511
+ columnErrorsMap[errorKey] = headerErrorArray;
512
+ } else if (additionalInfo.type === "column") {
513
+ errorKey = "errorInColumnHeader";
514
+ columnErrorsMap[errorKey] = true;
515
+ } else if (additionalInfo.type === "cell") {
516
+ errorKey = "RowId=" + additionalInfo.rowId + ",ColId=" + additionalInfo.colId;
517
+ columnErrorsMap[errorKey] = description;
518
+ }
519
+ }
520
+ }
521
+ return columnErrorsMap;
522
+ },
523
+
524
+ /**
525
+ * Copy a row from the buffer after a copy/cut line action using a function import
526
+ * /sap/opu/odata/SAP/RULE_SRV/CopyRuleRow?RuleId='xxx'&SourceRowId='yyy'&TargetRowSeq='zzz'
527
+ * @param {string} [sRuleId] The current rule ID
528
+ * @param {string} [sVersion] The current rule version
529
+ * @param {string} [sSourceRowId] The copied row stable ID
530
+ * @param {string} [sTargetRowSeq] A sequence for paste/insert the row
531
+ * @param {boolean} [shouldCut] A flag indicating if we cut or copy
532
+ * @param {boolean} [sOverrideInd] A flag indicating if we paste
533
+ * @private
534
+ **/
535
+ _callCopyRuleRow: function (sRuleId, sVersion, sSourceRowId, sTargetRowSeq, shouldCut, sOverrideInd) {
536
+ var changesGroupID = {
537
+ groupId: "changes"
538
+ };
539
+ this._getModel().setDeferredGroups([changesGroupID.groupId]);
540
+ var submitSuccess = function (response) {
541
+ this.resetControl();
542
+ this._internalModel.setProperty("/busyState", false);
543
+ }.bind(this);
544
+
545
+ var submitError = function (e) {
546
+ sap.m.MessageToast.show(e);
547
+ }.bind(this);
548
+
549
+ var callFunctionSuccess = function (response) {
550
+ this._getModel().callFunction("/CopyRuleRow", {
551
+ method: "POST",
552
+ groupId: changesGroupID.groupId,
553
+ urlParameters: {
554
+ RuleId: sRuleId,
555
+ SourceRowId: sSourceRowId,
556
+ TargetRowSeq: sTargetRowSeq,
557
+ DeleteSourceRow: shouldCut,
558
+ OverrideTargetRow: sOverrideInd
559
+ }
560
+ });
561
+ this._getModel().submitChanges({
562
+ groupId: changesGroupID.groupId,
563
+ success: submitSuccess,
564
+ error: submitError
565
+ });
566
+ }.bind(this);
567
+
568
+ if (this._getModel().hasPendingChanges()) {
569
+ this._getModel().submitChanges({
570
+ groupId: changesGroupID.groupId,
571
+ success: callFunctionSuccess,
572
+ error: submitError
573
+ });
574
+ } else {
575
+ callFunctionSuccess();
576
+ }
577
+ },
578
+
579
+ _calNextRowId: function () {
580
+ var rows = this.dataBucket.rows.results;
581
+ var maxRowId = 0;
582
+ //Calc max "Id"
583
+ for (var i = 0; i < rows.length; i++) {
584
+ if (rows[i].Id > maxRowId) {
585
+ maxRowId = rows[i].Id;
586
+ }
587
+ }
588
+ var nextId = maxRowId + 1;
589
+ return nextId;
590
+ },
591
+
592
+ _clearErrorMessages: function () {
593
+ //Clear header message
594
+ var oText = this.getAggregation("_errorsText");
595
+ oText.setText("");
596
+ oText.setVisible(false);
597
+ this._internalModel.setProperty("/validationStatus", {}, null, true);
598
+ this._internalModel.setProperty("/valueState", {}, null, true);
599
+ },
600
+
601
+ //Closes cell popover
602
+ _closePopover: function () {
603
+ var pop = sap.ui.getCore().byId("popover");
604
+ if (pop) {
605
+ pop.close();
606
+ }
607
+ },
608
+
609
+ _collectColIdAndExpressionDetails: function (columns) {
610
+ var columnCount = columns.length;
611
+ var resultExpressionArray = [];
612
+ for (var columnIndex = 0; columnIndex < columnCount; columnIndex++) {
613
+ if (columns[columnIndex].Result && columns[columnIndex].Result.Expression) {
614
+ var oResult = {
615
+ 'columnID': columns[columnIndex].Result.Id,
616
+ 'expressionContent': columns[columnIndex].Result.Expression
617
+ };
618
+ resultExpressionArray.push(oResult);
619
+ }
620
+ }
621
+ return resultExpressionArray;
622
+ },
623
+
624
+ _columnFactory: function (sId, oContext) {
625
+ var that = this;
626
+ if (this.multiHeaderFlag) {
627
+ this.multiHeaderFlag = false;
628
+ }
629
+ var relativePath = this._getBindModelName();
630
+ var columnType = oContext.getProperty("Type"),
631
+ coId = oContext.getProperty("Id"),
632
+ ruleId = oContext.getProperty("RuleId"),
633
+ version = oContext.getProperty("Version");
634
+ var oHeaderKey = {
635
+ RuleId: ruleId,
636
+ Id: coId,
637
+ Version: version
638
+ };
639
+ var headPath = relativePath + oContext.getModel().createKey("/DecisionTableColumnResults", oHeaderKey);
640
+ var contextModel = oContext.getModel();
641
+ var bindingInfo = contextModel.aBindings;
642
+ this.columnWidth = "auto";
643
+
644
+ var column = new Column(sId, {
645
+ width: this.columnWidth,
646
+ minWidth : 128,
647
+ multiLabels: [
648
+ this._createColIfThenHeader(oContext), // The order of the labels is important!
649
+ this._createColDescriptionHeader(oContext, this)
650
+ ],
651
+ template: this._createCell(oContext) //, headerSpan: columnType === sap.rules.ui.DecisionTableColumn.Condition ? [this.iNumOfCondition, 1] : [this.iNumOfResults, 1]
652
+ });
653
+
654
+ relativePath = this._getBindModelName();
655
+ this.firstResultColumnBound = oContext.getProperty(relativePath + "Type") === sap.rules.ui.DecisionTableColumn.Result;
656
+ if (columnType === sap.rules.ui.DecisionTableColumn.Result) {
657
+
658
+ if (this.getAstExpressionLanguage()) {
659
+ column.bindProperty("visible", {
660
+ parts: [{
661
+ path: headPath + "/AccessMode"
662
+ }],
663
+ formatter: this._columnVisibility
664
+ });
665
+ }
666
+ if (this.getExpressionLanguage()) {
667
+
668
+ column.bindProperty("visible", {
669
+ parts: [{
670
+ path: headPath + "/AccessMode"
671
+ }],
672
+ formatter: function() {
673
+ var type = that.getModel() && headPath!== "" ? that.getModel().getObject(headPath).BusinessDataType : "";
674
+ if (type === Constants.DATE_BUSINESS_TYPE || type === Constants.TIMESTAMP_BUSINESS_TYPE || type === Constants.NUMBER || type ===
675
+ Constants.STRING || type === Constants.BOOLEAN_BUSINESS_TYPE || type === Constants.BOOLEAN_ENHANCED_BUSINESS_TYPE) {
676
+ var accessMode = that.getModel().getObject(headPath).AccessMode;
677
+ return that._columnVisibility(accessMode);
678
+ } else {
679
+ return false;
680
+ }
681
+ }
682
+ });
683
+ }
684
+ }
685
+
686
+ return column;
687
+ },
688
+
689
+ _columnVisibility: function (accessMode) {
690
+ if (accessMode === "Hidden" || accessMode === "HIDDEN") {
691
+ return false;
692
+ } else {
693
+ return true;
694
+ }
695
+ },
696
+
697
+ _concatinateColumnsHeaderErrors: function (columnErrorsMap) {
698
+ var errorMessage = "";
699
+ for (var column in columnErrorsMap) {
700
+ if (columnErrorsMap.hasOwnProperty(column)) {
701
+ if (columnErrorsMap[column].header) {
702
+ errorMessage += "In Col: " + column + " - " + columnErrorsMap[column].header + "\n";
703
+ }
704
+ }
705
+ }
706
+ return errorMessage;
707
+ },
708
+
709
+ _concatinateHeaderErrors: function (headerErrorsArray) {
710
+ var errorMessage = "";
711
+ for (var i = 0; i < headerErrorsArray.length; i++) {
712
+ errorMessage += "\n" + headerErrorsArray[i];
713
+ }
714
+ return errorMessage;
715
+ },
716
+
717
+ _convertAndValidate: function () {
718
+ var ruleData = this._getRuleData();
719
+ var oExpressionLanguage = sap.ui.getCore().byId(this.getExpressionLanguage());
720
+ if (oExpressionLanguage) {
721
+ var validateResults = {};
722
+ if (oExpressionLanguage && ruleData) {
723
+ validateResults = oExpressionLanguage.convertRuleToDisplayValues(ruleData);
724
+ if (validateResults.deferredResult) {
725
+ validateResults.deferredResult.done(this._processValidationResults.bind(this));
726
+ } else {
727
+ this._processValidationResults(validateResults, ruleData);
728
+ }
729
+ }
730
+ } else {
731
+ this._displayModel.setData(ruleData);
732
+ this._settingsModel.setData(ruleData);
733
+ }
734
+
735
+ },
736
+
737
+ _copyRow: function () {
738
+ this._cutCopyRow("copy");
739
+ },
740
+
741
+ _createCell: function (oContext) {
742
+ var colID = oContext.getProperty("Id");
743
+ var colType = oContext.getProperty("Type");
744
+
745
+ var oCell = new DecisionTableCell({
746
+ editable: "{dtModel>/editable}",
747
+ displayModelName: "displayModel",
748
+ decisionTableCellType: this._decisionTableCellFormatter
749
+ // type: sap.rules.ui.ExpressionType.BooleanEnhanced
750
+ }).data({
751
+ colId: colID,
752
+ colType: colType,
753
+ table: this.getAggregation("_table")
754
+ });
755
+
756
+ if (this.getAstExpressionLanguage()) {
757
+ oCell.setAstExpressionLanguage(this.getAstExpressionLanguage());
758
+ } else {
759
+ oCell.setExpressionLanguage(this.getExpressionLanguage());
760
+ }
761
+ return oCell;
762
+ },
763
+
764
+ _createColDescriptionHeader: function (oContext, oDtControl) {
765
+ var that = this;
766
+ var columnType = oContext.getProperty("Type"),
767
+ coId = oContext.getProperty("Id"),
768
+ ruleId = oContext.getProperty("RuleId"),
769
+ version = oContext.getProperty("Version");
770
+ var relativePath = "";
771
+ var headerPath;
772
+ var sPath;
773
+ var oAstContext;
774
+ var displayExpression;
775
+ var oHeaderKey = {
776
+ RuleId: ruleId,
777
+ Id: coId,
778
+ Version: version
779
+ };
780
+ var sDTColPath;
781
+
782
+ //For rel
783
+ if (this.getExpressionLanguage()) {
784
+ relativePath = "displayModel>";
785
+ }
786
+ var numOfLines = document.getElementsByClassName("sapUiSizeCozy").length > 0 ? 3 : 1;
787
+
788
+ var oText = new Text({
789
+ maxLines: numOfLines
790
+ }).addStyleClass("sapRULDecisionTableColumnHeaderLabel");
791
+
792
+ //Condition header text
793
+ if (columnType === sap.rules.ui.DecisionTableColumn.Condition) {
794
+ sPath = oContext.getModel().createKey("/DecisionTableColumnConditions", oHeaderKey);
795
+ sDTColPath = oContext.getModel().createKey("/DecisionTableColumns", oHeaderKey);
796
+ oAstContext = new sap.ui.model.Context(oContext.getModel(), sPath);
797
+ if (this.getAstExpressionLanguage()) {
798
+ displayExpression = oDtControl._getExpressionFromAstNodes(oAstContext);
799
+ }
800
+ headerPath = relativePath + sPath;
801
+ oText.bindText({
802
+ parts: [{
803
+ path: headerPath + "/Expression"
804
+ }, {
805
+ path: sDTColPath + "/Label"
806
+ }, {
807
+ path: headerPath + "/FixedOperator"
808
+ }],
809
+ formatter: function (sExpression, sLabel, sFixedOperator) {
810
+ //bug RULES-5278
811
+ var titleText = "";
812
+ if(that.getAstExpressionLanguage()){
813
+ titleText = !sLabel ? displayExpression : sLabel;
814
+ } else {
815
+ titleText = !sLabel ? sExpression : sLabel;
816
+ }
817
+ if (sFixedOperator) {
818
+ var sOperator = that.getAstExpressionLanguage() ? that.astUtil._getCapitalOperatorName(sFixedOperator) : sFixedOperator;
819
+ titleText += " " + sOperator;
820
+ }
821
+ return titleText;
822
+ }
823
+ });
824
+
825
+ oText.bindProperty("tooltip", {
826
+ parts: [{
827
+ path: headerPath + "/Expression"
828
+ }, {
829
+ path: headerPath + "/FixedOperator"
830
+ }],
831
+ formatter: function (sExpression, sFixedOperator) {
832
+ var titleText = "";
833
+ if(that.getAstExpressionLanguage()){
834
+ titleText = displayExpression ? displayExpression : "";
835
+ } else {
836
+ titleText = sExpression;
837
+ }
838
+ if (sFixedOperator) {
839
+ var sOperator = that.getAstExpressionLanguage() ? that.astUtil._getCapitalOperatorName(sFixedOperator) : sFixedOperator;
840
+ titleText += " " + sOperator;
841
+ }
842
+ return titleText;
843
+ }
844
+ });
845
+
846
+ //Result header text
847
+ } else if (columnType === sap.rules.ui.DecisionTableColumn.Result) {
848
+ var sResultPath = oContext.getModel().createKey("/DecisionTableColumnResults", oHeaderKey);
849
+ headerPath = relativePath + sResultPath;
850
+ oText.bindText({
851
+ parts: [{
852
+ path: headerPath + "/DataObjectAttributeName"
853
+ }, {
854
+ path: headerPath + "/DataObjectAttributeLabel"
855
+ }, {
856
+ path: "dtModel>/busyState"
857
+ }],
858
+ formatter: this._getOutputColumnDescription.bind(this)
859
+ });
860
+
861
+ oText.bindProperty("tooltip", {
862
+ parts: [{
863
+ path: headerPath + "/DataObjectAttributeName"
864
+ }, {
865
+ path: headerPath + "/DataObjectAttributeLabel"
866
+ }, {
867
+ path: "dtModel>/busyState"
868
+ }],
869
+ formatter: this._getOutputColumnDescription.bind(this)
870
+ });
871
+ }
872
+ return oText;
873
+ },
874
+
875
+ _createColIfThenHeader: function (oContext) {
876
+ //var model = oContext.getModel();
877
+ var relativePath = this._getBindModelName();
878
+ var oBundle = this.oBundle;
879
+
880
+ return new Label({
881
+ text: {
882
+ parts: [{
883
+ path: relativePath + "Type"
884
+ }, {
885
+ path: relativePath + "Sequence"
886
+ }],
887
+ formatter: function (sType, iSequence) {
888
+ if (iSequence === 1) {
889
+ return oBundle.getText("conditionIfColumn");
890
+ } else if (sType === sap.rules.ui.DecisionTableColumn.Result) {
891
+ return oBundle.getText("resultThenColumn");
892
+ } else {
893
+ return "";
894
+ }
895
+ }
896
+ },
897
+ design: "Bold"
898
+ });
899
+ },
900
+
901
+ _createDecisionTableSettings: function () {
902
+ var oDecisionTableSettings;
903
+ if (this.isSequenceExistsInOdataMetadata()) {
904
+ oDecisionTableSettings = this._createNewDecisionTableSettings();
905
+ } else {
906
+ oDecisionTableSettings = this._createOldDecisionTableSettings();
907
+ }
908
+ return oDecisionTableSettings;
909
+ },
910
+
911
+ _createNewDecisionTableSettings: function () {
912
+ var oModel = this._getModel();
913
+ var oContext = this.getBindingContext();
914
+ var oDecisionTableSettings = new sap.rules.ui.DecisionTableSettings({
915
+ hitPolicies: "{dtModel>/hitPolicies}",
916
+ newDecisionTable: this._internalModel.getProperty("/newTable"),
917
+ cellFormat: "{dtModel>/cellFormat}",
918
+ decisionTableFormat: this.getDecisionTableFormat(),
919
+ enableSettingResult: this.getEnableSettingResult()
920
+ });
921
+ if (this.getAstExpressionLanguage()) {
922
+ oDecisionTableSettings.setAstExpressionLanguage(this.getAstExpressionLanguage());
923
+ } else {
924
+ oDecisionTableSettings.setExpressionLanguage(this.getExpressionLanguage());
925
+ }
926
+ //Create a copy of the setting model.
927
+ var settingModelDataStr = JSON.stringify(this._settingsModel.getData());
928
+ var settingModelData = JSON.parse(settingModelDataStr);
929
+
930
+ var settingModel = new sap.ui.model.json.JSONModel(settingModelData);
931
+
932
+ oDecisionTableSettings.setModel(settingModel);
933
+
934
+ //Set configuration model
935
+ oDecisionTableSettings.setModel(this._internalModel, "dtModel");
936
+
937
+ //Set OdataModel + context (needed for apply button)
938
+ oDecisionTableSettings.setModel(oModel, "oDataModel");
939
+
940
+ oDecisionTableSettings.setBindingContext(oContext, "dummy");
941
+
942
+ return oDecisionTableSettings;
943
+ },
944
+
945
+ _createOldDecisionTableSettings: function () {
946
+ var oModel = this._getModel();
947
+ var oContext = this.getBindingContext();
948
+ var oDecisionTableSettings = new DecisionTableSettingsOld({
949
+ expressionLanguage: this.getExpressionLanguage(),
950
+ hitPolicies: "{dtModel>/hitPolicies}",
951
+ newDecisionTable: this._internalModel.getProperty("/newTable")
952
+ });
953
+ oDecisionTableSettings.setModel(oModel);
954
+ oDecisionTableSettings.setModel(this._internalModel, "dtModel");
955
+ oDecisionTableSettings.setBindingContext(oContext);
956
+ return oDecisionTableSettings;
957
+ },
958
+
959
+ _cutCopyRow: function (operation) {
960
+ var oModel = this._getModel();
961
+ if (!oModel) {
962
+ return;
963
+ }
964
+ var oTable = this.getAggregation("_table");
965
+ var oSelectedRows = [];
966
+ if (oTable) {
967
+ oSelectedRows = oTable.getSelectedIndices();
968
+ }
969
+ if (oSelectedRows.length !== 1) {
970
+ return;
971
+ }
972
+ var rowPath = oTable.getContextByIndex(oSelectedRows[0]).getPath();
973
+ this._markSelection(false);
974
+ this.setLineActionBuffer({
975
+ rowPath: rowPath,
976
+ operation: operation
977
+ });
978
+ this._markSelection(true);
979
+ oTable.setSelectedIndex(-1);
980
+ sap.m.MessageToast.show(this.oBundle.getText(operation + "RowSuccess"));
981
+ },
982
+
983
+ _cutRow: function () {
984
+ this._cutCopyRow("cut");
985
+ },
986
+
987
+ // dataBucket
988
+ _dataPartRequested: function (partName) {
989
+ this.dataBucket.dataReceived[partName] = false;
990
+ this._setDataLoadedPromise();
991
+ this._updateBusyState();
992
+ },
993
+
994
+ _dataPartReceived: function (partName) {
995
+ this.dataBucket.dataReceived[partName] = true;
996
+ if (!this._isAllDataReceived()) {
997
+ return;
998
+ }
999
+ try {
1000
+ this._convertAndValidate();
1001
+ this.dataBucket.collectRowsMode = "replace";
1002
+ } catch (sError) {
1003
+ // show message Toast
1004
+ window.console.log(sError);
1005
+ }
1006
+ this._updateBusyState();
1007
+ this._dataLoaded.resolve();
1008
+ },
1009
+
1010
+ _decideAddRowEnablement: function (newTable) {
1011
+ return !newTable;
1012
+ },
1013
+
1014
+ _decideCopyRowEnablement: function (newTable, isExactlyOneRowSelected) {
1015
+ return newTable === false && isExactlyOneRowSelected;
1016
+ },
1017
+
1018
+ _decideDeleteRowEnablement: function (newTable, isAtLeastOneRowSelected) {
1019
+ return newTable === false && isAtLeastOneRowSelected;
1020
+ },
1021
+
1022
+ _decideLineActionVisibility: function (isEditable, isSequenceExist) {
1023
+ return isEditable === true && isSequenceExist;
1024
+ },
1025
+
1026
+ _decidePasteRowEnablement: function (newTable, isExactlyOneRowSelected, isSelection) {
1027
+ return newTable === false && isExactlyOneRowSelected && isSelection;
1028
+ },
1029
+
1030
+ _decideSelectionMode: function (editable) {
1031
+ return editable ? sap.ui.table.SelectionMode.MultiToggle : sap.ui.table.SelectionMode.None;
1032
+ },
1033
+
1034
+ _decideSettingsEnablement: function (enableSettings, editable) {
1035
+ return enableSettings && editable;
1036
+ },
1037
+
1038
+ _deleteRow: function () {
1039
+ var oModel = this._getModel();
1040
+ if (!oModel) {
1041
+ return;
1042
+ }
1043
+ var oTable = this.getAggregation("_table");
1044
+ var oSelectedRows = [];
1045
+ if (oTable) {
1046
+ oSelectedRows = oTable.getSelectedIndices();
1047
+ }
1048
+ if (oSelectedRows.length === 0) {
1049
+ return;
1050
+ }
1051
+ var rowsLength = oSelectedRows.length;
1052
+ for (var i = 0; i < rowsLength; i++) {
1053
+ var rowPath = oTable.getContextByIndex(oSelectedRows[i]).getPath();
1054
+ // remove row
1055
+ oModel.remove(rowPath);
1056
+ }
1057
+ oTable.setSelectedIndex(-1);
1058
+ this._clearErrorMessages();
1059
+ this.setLineActionBuffer({
1060
+ rowPath: null,
1061
+ operation: null
1062
+ });
1063
+ sap.m.MessageToast.show(this.oBundle.getText("deleteRowSuccess"));
1064
+ },
1065
+
1066
+ _deleteRowWorkaround: function () {
1067
+ var oModel = this._getModel();
1068
+ if (oModel.hasPendingChanges()) {
1069
+ // save all model's changes before row removal
1070
+ this._saveWorkAround({
1071
+ success: function () {
1072
+ this._deleteRow();
1073
+ }.bind(this)
1074
+ });
1075
+ } else {
1076
+ this._deleteRow();
1077
+ }
1078
+ },
1079
+
1080
+ _displayErrorMessages: function (headerErrorsArray, columnErrorsMap) {
1081
+ // I commnted this call in order to remove the header error message, next we'll add here a different errors control
1082
+ //this._displayHeaderErrorMessages(headerErrorsArray, columnErrorsMap);
1083
+ },
1084
+
1085
+ _displayHeaderErrorMessages: function (headerErrorsArray, columnErrorsMap) {
1086
+ var oText = this.getAggregation("_errorsText");
1087
+ this.oBundle = sap.ui.getCore().getLibraryResourceBundle("sap.rules.ui.i18n");
1088
+ var errorHeaderMessage = this._concatinateHeaderErrors(headerErrorsArray);
1089
+ oText.setText(this.oBundle.getText("errorInTableHeader") + errorHeaderMessage); // + "\n" + errorColumnsHeaderMessage);
1090
+ oText.setVisible(true);
1091
+ },
1092
+
1093
+ /**
1094
+ * @private
1095
+ * Gets a rule in deep format (as returned from the parser), and flats the rule to the format of the oDataModel.
1096
+ * e.g. DecisionTableRowCell(RuleId='0050569181751ED683EFEEC6AA2B73C5', Version='000001', RowId='1', ColId='1')
1097
+ * @param {oRule} oRule in deep format
1098
+ * @returns {object} rule in oDataModel flatted format
1099
+ */
1100
+ _flatRule: function (oRule) {
1101
+ var oModel = this._getModel();
1102
+ var oRuleFlat = {};
1103
+ var createEntry = function (oData, entryName, properties) {
1104
+ var key = oModel.createKey(entryName, properties);
1105
+ oData[key] = properties;
1106
+ };
1107
+
1108
+ // Flat columns
1109
+ oRule.DecisionTable.DecisionTableColumns.results.forEach(function (col, index) {
1110
+ if (col.Type === "CONDITION") {
1111
+ var condition = col.Condition;
1112
+ if (condition.parserResults && condition.parserResults.status === "Success") {
1113
+ condition.Expression = condition.parserResults.converted.Expression;
1114
+ if (condition.parserResults.converted.FixedOperator || condition.parserResults.converted.FixedOperator === "") {
1115
+ condition.FixedOperator = condition.parserResults.converted.FixedOperator;
1116
+ } else {
1117
+ condition.FixedOperator = condition.FixedOperator;
1118
+ }
1119
+ } else {
1120
+ try {
1121
+ condition.Expression = JSON.parse(condition.Expression).text;
1122
+ } catch (err) {
1123
+ condition.Expression = condition.Expression;
1124
+ }
1125
+ try {
1126
+ condition.FixedOperator = JSON.parse(condition.FixedOperator).text;
1127
+ } catch (err) {
1128
+ condition.Expression = condition.Expression;
1129
+ }
1130
+ }
1131
+ delete condition.parserResults;
1132
+ createEntry(oRuleFlat, "DecisionTableColumnConditions", condition);
1133
+ } else if (col.Type === "RESULT") {
1134
+ var result = col.Result;
1135
+ createEntry(oRuleFlat, "DecisionTableColumnResults", result);
1136
+ }
1137
+ });
1138
+
1139
+ // Flat cells
1140
+ oRule.DecisionTable.DecisionTableRows.results.forEach(function (row) {
1141
+ var cellArr = row.Cells;
1142
+ cellArr.results.forEach(function (cell) {
1143
+ if (cell.parserResults && cell.parserResults.status === "Success") {
1144
+ if(cell.parserResults.converted.Content){
1145
+ cell.Content = cell.parserResults.converted.Content;
1146
+ }else{
1147
+ cell.Content = cell.Content;
1148
+ }
1149
+ } else if (cell.parserResults && cell.parserResults.status === "Error") {
1150
+ try {
1151
+ if (cell.Content === Object) {
1152
+ cell.Content = JSON.parse(cell.Content).text;
1153
+ } else {
1154
+ cell.Content = cell.Content;
1155
+ }
1156
+
1157
+ } catch (err) {
1158
+ cell.Content = "";
1159
+ Log.error("failed to pars AST cell in ColId " + cell.ColId + " RowId " + cell.RowId +
1160
+ " set cell content to empty");
1161
+ }
1162
+ }
1163
+ delete cell.parserResults;
1164
+ createEntry(oRuleFlat, "DecisionTableRowCells", cell);
1165
+ });
1166
+ });
1167
+
1168
+ return oRuleFlat;
1169
+ },
1170
+
1171
+ _getBindModelName: function () {
1172
+ var path = "";
1173
+ var modelName = this.getModelName();
1174
+ if (modelName) {
1175
+ path = modelName + ">";
1176
+ }
1177
+ return path;
1178
+ },
1179
+
1180
+ _getBlankContent: function () {
1181
+ var oLabelContent = new Label({
1182
+ text: this.oBundle.getText("start")
1183
+ });
1184
+ var oSpaceTextContent = new Text();
1185
+ oSpaceTextContent.setText("\u00a0");
1186
+ var oLinkToSettingsFromBlank = new Link({
1187
+ enabled: {
1188
+ parts: [{
1189
+ path: "dtModel>/enableSettings"
1190
+ }, {
1191
+ path: "dtModel>/editable"
1192
+ }],
1193
+ formatter: this._decideSettingsEnablement
1194
+ },
1195
+ text: " " + this.oBundle.getText("settings"),
1196
+ press: [this._openTableSettings, this]
1197
+ }).addStyleClass("sapRULDecisionTableLink");
1198
+
1199
+ var oFlexBox = new FlexBox({
1200
+ justifyContent: "Center",
1201
+ items: [oLabelContent, oSpaceTextContent, oLinkToSettingsFromBlank],
1202
+ visible: {
1203
+ parts: [{
1204
+ path: "dtModel>/enableSettings"
1205
+ }, {
1206
+ path: "dtModel>/editable"
1207
+ }],
1208
+ formatter: this._decideSettingsEnablement
1209
+ }
1210
+ }).addStyleClass("sapUiMediumMargin");
1211
+
1212
+ return oFlexBox;
1213
+ },
1214
+
1215
+ _getDataLoadedPromise: function () {
1216
+ if (!this._dataLoaded) {
1217
+ this._setDataLoadedPromise();
1218
+ }
1219
+ return this._dataLoaded.promise();
1220
+ },
1221
+
1222
+ _getExpressionFromAstNodes: function (oContext) {
1223
+ var that = this;
1224
+ var oAstExpressionLanguage = sap.ui.getCore().byId(this.getAstExpressionLanguage());
1225
+ var termsProvider = oAstExpressionLanguage._astBunldeInstance.TermsProvider.TermsProvider;
1226
+ var displayExpression = "";
1227
+ var displayTermExpression = "";
1228
+ var sPath = oContext.getPath();
1229
+ var oData = oContext.getObject(sPath);
1230
+ var astList = oData.DecisionTableColumnConditionASTs;
1231
+ var oAstUtil = oAstExpressionLanguage._astBunldeInstance.ASTUtil;
1232
+ var columnArray = this._internalModel.getProperty("/conditionCellAstValues");
1233
+ var len = 0;
1234
+ var jsonLength = 0;
1235
+ var aFunction = [ConstantUtils.AVG, ConstantUtils.SUM, ConstantUtils.COUNT, ConstantUtils.COUNTDISTINCT, ConstantUtils.DISTINCT,
1236
+ ConstantUtils.MIN, ConstantUtils.MAX, ConstantUtils.FILTER, ConstantUtils.TOP, ConstantUtils.BOTTOM, ConstantUtils.FIRST, ConstantUtils.SELECT, ConstantUtils.SORTASC, ConstantUtils.SORTDESC];
1237
+ oAstUtil.clearNodes();
1238
+ astList = astList.__list;
1239
+ if (astList && astList.length > 0) {
1240
+ for (var entry in astList) {
1241
+ var path = astList[entry];
1242
+ that._addNodeObject(oContext.getObject("/" + path));
1243
+ }
1244
+ var astNodes = oAstUtil.getNodes();
1245
+ //displayExpression = oAstUtil.toAstExpressionString(astNodes);
1246
+ var dateFormat = that._getDateFormatter();
1247
+ var timeFormat = that._getDateTimeFormatter();
1248
+ displayExpression = oAstUtil.toAstExpressionStringForDt(astNodes, dateFormat, timeFormat);
1249
+ jsonLength = displayExpression.JSON.length;
1250
+ var fixedOperator = oContext.getObject(oContext.getPath()).FixedOperator;
1251
+ var sOperator = that.astUtil._getCapitalOperatorName(fixedOperator);
1252
+ if(displayExpression && displayExpression.relString) {
1253
+ displayExpression.relString = displayExpression.relString.replace(/\\/g,"\\\\").replace(/{/g, "\\{").replace(/}/g, "\\}");
1254
+ }
1255
+ columnArray[oContext.getPath()] = {
1256
+ "headerValue": displayExpression.relString + " " + sOperator
1257
+ };
1258
+ var termsArray = displayExpression.shortRELString ? displayExpression.shortRELString.split(" ") : [];
1259
+ termsArray = displayExpression.displayString ? displayExpression.displayString.split(" ") : [];
1260
+ for (var term in termsArray) {
1261
+ var referenceExpression = "";
1262
+ if (termsArray[term].startsWith("./") || termsArray[term].startsWith("/")) {
1263
+ referenceExpression = termsProvider.getTermNameFromASTNodeReference(termsArray[term]);
1264
+ }
1265
+ if (referenceExpression !== "") {
1266
+ displayTermExpression = displayTermExpression + " " + referenceExpression;
1267
+ } else {
1268
+ var splitArray = termsArray[term].split("(");
1269
+ if(that.includes(aFunction,splitArray[0]) && len < jsonLength){
1270
+ termsArray[term] = termsArray[term].replace(displayExpression.JSON[len].dataObject,
1271
+ termsProvider.getTermNameFromASTNodeReference(displayExpression.JSON[len].dataObject));
1272
+ len++;
1273
+ }
1274
+ displayTermExpression = displayTermExpression + " " + termsArray[term];
1275
+ }
1276
+ }
1277
+ if (displayTermExpression != "") {
1278
+ displayExpression = displayTermExpression;
1279
+ }
1280
+ }
1281
+ if (!columnArray[oContext.getPath()]) {
1282
+ columnArray[oContext.getPath()] = {
1283
+ "headerValue": ""
1284
+ };
1285
+ }
1286
+ this._internalModel.setProperty("/conditionCellAstValues", columnArray);
1287
+ return (displayExpression instanceof Object ? displayExpression.shortRELString : displayExpression.trim());
1288
+ },
1289
+
1290
+ _getMenuItems: function () {
1291
+ var oMenuItems = [
1292
+ new MenuItem({
1293
+ text: this.oBundle.getText("insertFirst"),
1294
+ enabled: true,
1295
+ press: this._addNewRowWorkaround.bind(this, true)
1296
+ }),
1297
+ new MenuItem({
1298
+ text: this.oBundle.getText("insertAfter"),
1299
+ enabled: {
1300
+ parts: [{
1301
+ path: "dtModel>/newTable"
1302
+ }, {
1303
+ path: "dtModel>/isExactlyOneRowSelected"
1304
+ }],
1305
+ formatter: this._decideCopyRowEnablement
1306
+ },
1307
+ // select: this._addNewRow.bind(this, oSelectedRows[0], false)
1308
+ press: this._addNewRowWorkaround.bind(this, false)
1309
+ })
1310
+ ];
1311
+ return oMenuItems;
1312
+ },
1313
+
1314
+ _getModel: function () {
1315
+ var modelName = this.getModelName();
1316
+ if (modelName) {
1317
+ return this.getModel(modelName);
1318
+ }
1319
+ return this.getModel();
1320
+ },
1321
+
1322
+ _getOutputColumnDescription: function (oName, oLabel) {
1323
+ var expLanguage;
1324
+ if (this.getExpressionLanguage()) {
1325
+ expLanguage = sap.ui.getCore().byId(this.getExpressionLanguage());
1326
+ if (expLanguage && expLanguage._isDataExist()) {
1327
+ var ResultID = this.getBindingContext().getProperty("ResultDataObjectId");
1328
+ var desc = expLanguage.getResultColumnDescription(oName, ResultID, oLabel);
1329
+ return desc;
1330
+ }
1331
+ }
1332
+ return (oLabel ? oLabel : oName);
1333
+ },
1334
+
1335
+ _getPasteMenuItems: function () {
1336
+ var oMenuItems = [
1337
+ new MenuItem({
1338
+ text: this.oBundle.getText("pasteRowAction"),
1339
+ enabled: {
1340
+ parts: [{
1341
+ path: "dtModel>/newTable"
1342
+ }, {
1343
+ path: "dtModel>/isExactlyOneRowSelected"
1344
+ }],
1345
+ formatter: this._decideCopyRowEnablement
1346
+ },
1347
+ // select: this._addNewRow.bind(this, oSelectedRows[0], true)
1348
+ press: this._rowAction.bind(this, "paste")
1349
+ }),
1350
+ new MenuItem({
1351
+ text: this.oBundle.getText("insertBeforeRowAction"),
1352
+ enabled: {
1353
+ parts: [{
1354
+ path: "dtModel>/newTable"
1355
+ }, {
1356
+ path: "dtModel>/isExactlyOneRowSelected"
1357
+ }],
1358
+ formatter: this._decideCopyRowEnablement
1359
+ },
1360
+ // select: this._addNewRow.bind(this, oSelectedRows[0], false)
1361
+ press: this._rowAction.bind(this, "insertBefore")
1362
+ }),
1363
+ new MenuItem({
1364
+ text: this.oBundle.getText("insertAfterRowAction"),
1365
+ enabled: {
1366
+ parts: [{
1367
+ path: "dtModel>/newTable"
1368
+ }, {
1369
+ path: "dtModel>/isExactlyOneRowSelected"
1370
+ }],
1371
+ formatter: this._decideCopyRowEnablement
1372
+ },
1373
+ // select: this._addNewRow.bind(this, oSelectedRows[0], false)
1374
+ press: this._rowAction.bind(this, "insertAfter")
1375
+ })
1376
+ ];
1377
+ return oMenuItems;
1378
+ },
1379
+
1380
+ _getRuleData: function () {
1381
+ var contextPath = this.getBindingContextPath();
1382
+ var oModel = this._getModel();
1383
+ var ruleData = jQuery.extend({}, true, oModel.getProperty(contextPath, null, true));
1384
+ var dtData = ruleData.DecisionTable;
1385
+ dtData.DecisionTableColumns = this.dataBucket.columns;
1386
+ dtData.DecisionTableRows = this.dataBucket.rows;
1387
+ return ruleData;
1388
+ },
1389
+
1390
+ // cols
1391
+ _handleColumnsDataReceived: function (oEvent) {
1392
+ var data = oEvent.getParameter("data");
1393
+ if (!data) {
1394
+ return;
1395
+ }
1396
+ // change newTable flag
1397
+ // set table.noData according to newTable flag
1398
+ var oTable = this.getAggregation("_table");
1399
+ if (data.results && data.results.length > 0) {
1400
+ this._internalModel.setProperty("/newTable", false);
1401
+ oTable.setNoData(null);
1402
+ this._setExpressionLanguageVersionOnoData(false);
1403
+ } else {
1404
+ this._internalModel.setProperty("/newTable", true);
1405
+ var blankContent = this._getBlankContent();
1406
+ oTable.setNoData(blankContent);
1407
+ this._setExpressionLanguageVersionOnoData(true);
1408
+ }
1409
+ this.dataBucket[dataPartName.columns] = data;
1410
+ this._dataPartReceived(dataPartName.columns);
1411
+ this._handleHeaderSpan();
1412
+ },
1413
+
1414
+ _handleColumnsDataRequested: function (oEvent) {
1415
+ this._dataPartRequested(dataPartName.columns);
1416
+ },
1417
+
1418
+ // rows
1419
+ _handleRowsDataReceived: function (oEvent) {
1420
+ var data = oEvent.getParameter("data");
1421
+ if (data) {
1422
+ if (this.dataBucket.collectRowsMode === "replace") {
1423
+ this.dataBucket[dataPartName.rows] = data;
1424
+ this.dataBucket.collectRowsMode = "append";
1425
+ } else {
1426
+ // "append"
1427
+ var previousData = this.dataBucket[dataPartName.rows];
1428
+ var newData = {
1429
+ results: (previousData.results) ? previousData.results.concat(data.results) : data.results
1430
+ };
1431
+ this.dataBucket[dataPartName.rows] = newData;
1432
+ }
1433
+ this._dataPartReceived(dataPartName.rows);
1434
+ }
1435
+ this._setTableRows();
1436
+ },
1437
+
1438
+ _handleRowsDataRequested: function (oEvent) {
1439
+ this._dataPartRequested(dataPartName.rows);
1440
+ },
1441
+
1442
+ // rule
1443
+ _handleRuleDataReceived: function (data) {
1444
+ if (data) {
1445
+ this._dataPartReceived(dataPartName.rule);
1446
+ }
1447
+ },
1448
+
1449
+ _handleRuleDataRequested: function () {
1450
+ this._dataPartRequested(dataPartName.rule);
1451
+ },
1452
+
1453
+ // vocabulary
1454
+ _handleVocabularyDataChanged: function (oEvent) {
1455
+ var data = oEvent.getParameter("data");
1456
+ if (data) {
1457
+ this._handleVocabularyDataReceived(data);
1458
+ } else {
1459
+ this._handleVocabularyDataRequested();
1460
+ }
1461
+ },
1462
+
1463
+ _handleVocabularyDataReceived: function (data) {
1464
+ if (data) {
1465
+ this._dataPartReceived(dataPartName.vocabulary);
1466
+ }
1467
+ },
1468
+
1469
+ _handleVocabularyDataRequested: function () {
1470
+ this._dataPartRequested(dataPartName.vocabulary);
1471
+ },
1472
+
1473
+ _handleHeaderSpan: function () {
1474
+ if (!this.multiHeaderFlag) {
1475
+ var i;
1476
+ this.multiHeaderFlag = true;
1477
+ var aColumns = this.dataBucket.columns.results;
1478
+ this.iNumOfCondition = 0;
1479
+ this.iNumOfResults = 0;
1480
+ for (i = 0; i < aColumns.length; i++) {
1481
+ if (aColumns[i].Type === sap.rules.ui.DecisionTableColumn.Condition) {
1482
+ this.iNumOfCondition++;
1483
+ } else if (aColumns[i].Type === sap.rules.ui.DecisionTableColumn.Result) {
1484
+ this.iNumOfResults++;
1485
+ }
1486
+ }
1487
+ var oTable = this.getAggregation('_table');
1488
+ aColumns = oTable.getAggregation('columns');
1489
+ for (i = 0; i < this.iNumOfCondition; i++) {
1490
+ aColumns[i].setHeaderSpan([this.iNumOfCondition, 1]);
1491
+ }
1492
+ for (; i < aColumns.length; i++) {
1493
+ aColumns[i].setHeaderSpan([this.iNumOfResults, 1]);
1494
+ }
1495
+ }
1496
+ },
1497
+
1498
+ _initDataBucket: function () {
1499
+ var vocaDataReceived = false;
1500
+ var oEL;
1501
+ if (this.getAstExpressionLanguage()) {
1502
+ oEL = sap.ui.getCore().byId(this.getAstExpressionLanguage());
1503
+ } else {
1504
+ oEL = sap.ui.getCore().byId(this.getExpressionLanguage());
1505
+ }
1506
+ if (oEL && oEL._isDataExist()) {
1507
+ vocaDataReceived = true;
1508
+ }
1509
+ this.dataBucket = {
1510
+ dataReceived: {
1511
+ vocabulary: vocaDataReceived,
1512
+ rule: false,
1513
+ rows: false,
1514
+ columns: false
1515
+ },
1516
+ rows: {},
1517
+ columns: {},
1518
+ collectRowsMode: "replace" // "append"
1519
+ };
1520
+ },
1521
+
1522
+ _initDisplayModel: function () {
1523
+ this._displayModel = new sap.ui.model.json.JSONModel();
1524
+ this.setModel(this._displayModel, "displayModel");
1525
+ this._settingsModel = new sap.ui.model.json.JSONModel();
1526
+ this.setModel(this._settingsModel, "settingModel");
1527
+ },
1528
+
1529
+ _initInternalModel: function () {
1530
+ var data = {};
1531
+ data.editable = this.getEditable();
1532
+ data.newTable = true;
1533
+ data.sequenceExist = true;
1534
+ data.busyState = true;
1535
+ data.busyTableState = true;
1536
+ data.cellFormat = this.getCellFormat();
1537
+ data.hitPolicies = this.getHitPolicies();
1538
+ data.enableSettings = this.getEnableSettings();
1539
+ data.isAtLeastOneRowSelected = false;
1540
+ data.isExactlyOneRowSelected = false;
1541
+ data.isSelection = false;
1542
+ data.validationStatus = {};
1543
+ data.valueState = {};
1544
+ data.selectedRow = null;
1545
+ data.conditionCellAstValues = [];
1546
+ data.ruleBindingPath = "";
1547
+ this._internalModel = new sap.ui.model.json.JSONModel(data);
1548
+ this.setModel(this._internalModel, "dtModel");
1549
+ },
1550
+
1551
+ _isAllDataReceived: function () {
1552
+ var dataParts = this.dataBucket.dataReceived;
1553
+ return dataParts.rule && dataParts.rows && dataParts.columns && dataParts.vocabulary;
1554
+ },
1555
+
1556
+ _markSelection: function (bMarkSelection) {
1557
+ var rowPath = this.getLineActionBuffer().rowPath;
1558
+ var oTable = this.getAggregation("_table");
1559
+ var oModel = this._getModel();
1560
+ if (rowPath) {
1561
+ var firstVisibleRow = oTable.getFirstVisibleRow();
1562
+ var rowIndex = oModel.getProperty(rowPath).Sequence - 1;
1563
+ if ((rowIndex - firstVisibleRow > -1) && (rowIndex - firstVisibleRow < oTable.getVisibleRowCount())) {
1564
+ var oRow = oTable.getRows()[rowIndex - firstVisibleRow];
1565
+ var oCells = oRow.getCells();
1566
+ if (oCells) {
1567
+ for (var i = 0; i < oCells.length; i++) {
1568
+ if (bMarkSelection) {
1569
+ //jQuery(oCells[i].getDomRef()).parent().parent().parent().addClass("sapRULDecisionTableSCellMarked");
1570
+ oCells[i].addStyleClass("sapRULDecisionTableSCellMarked");
1571
+ } else {
1572
+ //jQuery(oCells[i].getDomRef()).parent().parent().parent().removeClass("sapRULDecisionTableSCellMarked");
1573
+ oCells[i].removeStyleClass("sapRULDecisionTableSCellMarked");
1574
+ }
1575
+ }
1576
+ }
1577
+ }
1578
+ }
1579
+ },
1580
+
1581
+ _openTableSettings: function () {
1582
+ //bug 5230 - after apply we call twice to validateRule - need to clear dataBucket.rows
1583
+ this.dataBucket.dataReceived.rows = false;
1584
+ var decisionTableSettings = this._createDecisionTableSettings();
1585
+ var oDialog = new Dialog({
1586
+ contentWidth: "70%",
1587
+ contentHeight: "490px",
1588
+ title: this.oBundle.getText("tableSettings")
1589
+ });
1590
+ oDialog.addContent(decisionTableSettings);
1591
+ var aButtons = decisionTableSettings.getButtons(oDialog);
1592
+ for (var i = 0; i < aButtons.length; i++) {
1593
+ oDialog.addButton(aButtons[i]);
1594
+ }
1595
+ oDialog.attachBeforeClose(function (oData) {
1596
+ var dialogState = oDialog.getState();
1597
+ oDialog.destroy();
1598
+ //User press on "Apply" (and not on "Cancel")
1599
+ if (dialogState === sap.ui.core.ValueState.Success) {
1600
+ this._initDisplayModel();
1601
+ this._refreshBinding();
1602
+ }
1603
+ }, this);
1604
+ this._closePopover();
1605
+ oDialog.open();
1606
+ },
1607
+
1608
+ /**
1609
+ * @private
1610
+ * @param {validateResults} validateResults -
1611
+ * @param {ruleData} ruleData -
1612
+ */
1613
+ _processValidationResults: function (validateResults, ruleData) {
1614
+ if (validateResults && validateResults.output) {
1615
+ if (validateResults.output.status === "Error") {
1616
+ var headerErrorsArray = [];
1617
+ var columnErrorsMap = this._internalModel.getProperty("/validationStatus");
1618
+ var cellValueStateMap = {};
1619
+ columnErrorsMap = this._buildMessagesStructure(validateResults, columnErrorsMap, headerErrorsArray);
1620
+ for (var cell in columnErrorsMap) {
1621
+ if (columnErrorsMap.hasOwnProperty(cell) && (typeof columnErrorsMap[cell] === "string") && columnErrorsMap[cell] !== "null") {
1622
+ cellValueStateMap[cell] = sap.ui.core.ValueState.Error;
1623
+ }
1624
+ }
1625
+ this._displayErrorMessages(headerErrorsArray, columnErrorsMap);
1626
+
1627
+ this._internalModel.setProperty("/validationStatus", columnErrorsMap, null, true);
1628
+ this._internalModel.setProperty("/valueState", cellValueStateMap, null, true);
1629
+ }
1630
+
1631
+ var flatData = this._flatRule(validateResults.output.decisionTableData);
1632
+ //validateResults.output.decisionTableData.DecisionTable.DecisionTableRows = null;
1633
+ this._settingsModel.setData(validateResults.output.decisionTableData);
1634
+ if (this.dataBucket.rows.results) {
1635
+ this._settingsModel.rowLength = this.dataBucket.rows.results.length;
1636
+ }
1637
+ this._displayModel.setData(flatData, true);
1638
+ }
1639
+ },
1640
+
1641
+ _rowAction: function (operation) {
1642
+ this._rowActionWorkAround(operation);
1643
+ },
1644
+
1645
+ _rowActionWorkAround: function (operation) {
1646
+ var selectedRow = this._internalModel.getProperty("/selectedRow");
1647
+ this._markSelection(false);
1648
+ var buffer = this.getLineActionBuffer();
1649
+ this.setLineActionBuffer({
1650
+ rowPath: null,
1651
+ operation: null
1652
+ });
1653
+ var oTable = this.getAggregation("_table");
1654
+
1655
+ var sTargetRowSeq = selectedRow + 1;
1656
+ if (operation === "insertAfter") {
1657
+ sTargetRowSeq++;
1658
+ }
1659
+ var oModel = this._getModel();
1660
+ var sSourceRowId = oModel.getProperty(buffer.rowPath).Id;
1661
+ var sRuleId = oModel.getProperty(buffer.rowPath).RuleId;
1662
+ var sVersion = oModel.getProperty(buffer.rowPath).Version;
1663
+ this._internalModel.setProperty("/busyState", true);
1664
+ var isCut = (buffer.operation === "cut");
1665
+ if (operation === "paste") {
1666
+ this._callCopyRuleRow(sRuleId, sVersion, sSourceRowId, sTargetRowSeq, isCut, true);
1667
+ } else {
1668
+ this._callCopyRuleRow(sRuleId, sVersion, sSourceRowId, sTargetRowSeq, isCut, false);
1669
+ }
1670
+ oTable.setSelectedIndex(-1);
1671
+ if (operation === "insertBefore" || operation === "insertAfter") {
1672
+ sap.m.MessageToast.show(this.oBundle.getText("addRowSuccess"));
1673
+ }
1674
+ if (operation === "paste") {
1675
+ sap.m.MessageToast.show(this.oBundle.getText("pasteSuccess"));
1676
+ }
1677
+ },
1678
+
1679
+ _refreshBinding: function () {
1680
+ var oTable = this.getAggregation("_table");
1681
+ var ruleBinding = this.getElementBinding();
1682
+ if (ruleBinding) {
1683
+ ruleBinding.refresh();
1684
+ }
1685
+ var columnBinding = oTable.getBinding("columns");
1686
+ if (columnBinding) {
1687
+ columnBinding.refresh();
1688
+ }
1689
+ var rowBinding = oTable.getBinding("rows");
1690
+ if (rowBinding) {
1691
+ rowBinding.refresh();
1692
+ }
1693
+ var oEventBus = sap.ui.getCore().getEventBus();
1694
+ oEventBus.publish("sap.ui.rules", "refreshDTRuleModel");
1695
+ },
1696
+
1697
+ _rowSelectionChange: function () {
1698
+ var oTable = this.getAggregation("_table");
1699
+ var oSelectedRows = [];
1700
+ if (oTable) {
1701
+ oSelectedRows = oTable.getSelectedIndices();
1702
+ }
1703
+ if (oSelectedRows.length > 0) {
1704
+ this._internalModel.setProperty("/isAtLeastOneRowSelected", true);
1705
+ this._internalModel.setProperty("/selectedRow", oSelectedRows[0]);
1706
+ } else {
1707
+ this._internalModel.setProperty("/isAtLeastOneRowSelected", false);
1708
+ }
1709
+ if (oSelectedRows.length == 1) {
1710
+ this._internalModel.setProperty("/isExactlyOneRowSelected", true);
1711
+ } else {
1712
+ this._internalModel.setProperty("/isExactlyOneRowSelected", false);
1713
+ }
1714
+ if (this.getLineActionBuffer().rowPath) {
1715
+ this._internalModel.setProperty("/isSelection", true);
1716
+ } else {
1717
+ this._internalModel.setProperty("/isSelection", false);
1718
+ }
1719
+ },
1720
+
1721
+ _setDataLoadedPromise: function () {
1722
+ if (!this._dataLoaded || this._dataLoaded.state() !== "pending") {
1723
+ this._dataLoaded = new jQuery.Deferred();
1724
+ }
1725
+ },
1726
+
1727
+ // set the ExpressionLanguageVersion for new rule on oData model according to the parser version, for old rule without ExpressionLanguageVersion we set old parser version on type and not on the model.
1728
+ _setExpressionLanguageVersionOnoData: function (bNewRule) {
1729
+ var oModel = this._getModel();
1730
+ var oContext = this.getBindingContext();
1731
+ var sVersion = "1.0.0";
1732
+ if (bNewRule) {
1733
+ var oEL;
1734
+ if (this.getAstExpressionLanguage()) {
1735
+ oEL = sap.ui.getCore().byId(this.getAstExpressionLanguage());
1736
+ sVersion = "2.0.0";
1737
+ } else {
1738
+ oEL = sap.ui.getCore().byId(this.getExpressionLanguage());
1739
+ sVersion = oEL.getExpressionLanguageVersion();
1740
+ }
1741
+ oModel.setProperty("ExpressionLanguageVersion", sVersion, oContext, true);
1742
+ } else {
1743
+ sVersion = oModel.getProperty(this.getBindingContextPath() + '/ExpressionLanguageVersion');
1744
+ if (!sVersion) {
1745
+ sVersion = "1.0.0";
1746
+ }
1747
+ }
1748
+ this._decisionTableCellFormatter.setExpressionLanguageVersion(sVersion);
1749
+ },
1750
+
1751
+ _setTableRows: function () {
1752
+ var oTable = this.getAggregation("_table");
1753
+ var oRowBinding = oTable.getBinding("rows");
1754
+ var iVisibleRowCount = emptyTable;
1755
+ if (oRowBinding && oRowBinding.getLength()) {
1756
+ iVisibleRowCount = Math.min(oRowBinding.getLength(), this.VISIBLEROWCOUNT);
1757
+ }
1758
+
1759
+ var currVisibleRowCount = oTable.getVisibleRowCount();
1760
+ if (currVisibleRowCount !== iVisibleRowCount) {
1761
+ oTable.setVisibleRowCount(iVisibleRowCount);
1762
+ }
1763
+ if ((this.dataBucket && this.dataBucket.rows && this.dataBucket.rows.results.length === 0) || !this.getEditable()) {
1764
+ oTable.setSelectionMode(sap.ui.table.SelectionMode.None);
1765
+ } else {
1766
+ oTable.setSelectionMode(sap.ui.table.SelectionMode.MultiToggle);
1767
+ }
1768
+ },
1769
+
1770
+ _unbindColumns: function () {
1771
+ var oTable = this.getAggregation("_table");
1772
+ oTable.unbindColumns();
1773
+ },
1774
+
1775
+ _unbindRows: function () {
1776
+ var oTable = this.getAggregation("_table");
1777
+ oTable.unbindRows();
1778
+ },
1779
+
1780
+ _unbindRule: function () {
1781
+ this.unbindElement();
1782
+ },
1783
+
1784
+ _updateBusyState: function () {
1785
+ var dataParts = this.dataBucket.dataReceived;
1786
+ var dataReceived = dataParts.rule && dataParts.columns && dataParts.vocabulary;
1787
+ var isBusy = !dataReceived;
1788
+ this._internalModel.setProperty("/busyState", isBusy);
1789
+ var tableIsBusy = !dataParts.rows;
1790
+ this._internalModel.setProperty("/busyTableState", tableIsBusy);
1791
+ },
1792
+
1793
+ _updateTableCell: function (oCell, oRowContext, dtDomElement, rowIndex) {
1794
+ //jQuery(oCell.getDomRef()).parent().parent().parent().removeClass("sapRULDecisionTableSCellMarked");
1795
+ oCell.removeStyleClass("sapRULDecisionTableSCellMarked");
1796
+ var path = "null";
1797
+ var that = this;
1798
+ var oParent = this.getParent();
1799
+
1800
+ if (oRowContext) {
1801
+ var colId = oCell.data("colId");
1802
+ var rowId = oRowContext.getProperty("Id");
1803
+ var ruleId = oRowContext.getProperty("RuleId");
1804
+ var version = oRowContext.getProperty("Version");
1805
+ var oModel = oRowContext.getModel();
1806
+
1807
+ var headerPath = '';
1808
+ var rulePath = '';
1809
+ // NOTE: we assume that colId represents also the order of Columns and starts from 1
1810
+ var oCellProperties = {
1811
+ RuleId :ruleId,
1812
+ ColId: colId,
1813
+ RowId: rowId,
1814
+ Version: version
1815
+ };
1816
+ var cellBindingPath = oModel.createKey("/DecisionTableRowCells", oCellProperties);
1817
+ var oCellContext = new sap.ui.model.Context(oModel, cellBindingPath);
1818
+
1819
+ //Condition path from model
1820
+ var oProperties = {
1821
+ RuleId: ruleId,
1822
+ Id: colId,
1823
+ Version: version
1824
+ };
1825
+ var sConditionPath = oModel.createKey("/DecisionTableColumnConditions", oProperties);
1826
+ var columnArray = oParent.getModel("dtModel").getData().conditionCellAstValues;
1827
+
1828
+ //var bindModelName = oCell.data("bindModelName");
1829
+
1830
+ var cellKeyProperties = {
1831
+ RuleId: ruleId,
1832
+ Id: colId,
1833
+ Version: version
1834
+ };
1835
+
1836
+ var ruleKeyProperties = {
1837
+ Id: ruleId,
1838
+ Version: version
1839
+ };
1840
+
1841
+ path = cellBindingPath + "/Content";
1842
+
1843
+ switch (oCell.data("colType")) {
1844
+ case "CONDITION":
1845
+ headerPath = "/" + oModel.createKey("DecisionTableColumnConditions", cellKeyProperties);
1846
+ rulePath = "/" + oModel.createKey("Rules", ruleKeyProperties);
1847
+ oCell.setHeaderValuePath(headerPath + '/Expression');
1848
+ oCell.setFixedOperatorPath(headerPath + '/FixedOperator');
1849
+ oCell.setRuleFormatPath(rulePath + '/RuleFormat');
1850
+ oCell.setDecisionTableFormat(that.getParent().getDecisionTableFormat());
1851
+ oCell.setValueOnlyPath(headerPath + '/ValueOnly');
1852
+ if (columnArray[sConditionPath]) {
1853
+ oCell.setHeaderInfo(columnArray[sConditionPath]);
1854
+ }
1855
+ break;
1856
+ case "RESULT":
1857
+ headerPath = "/" + oModel.createKey("DecisionTableColumnResults", cellKeyProperties);
1858
+ rulePath = "/" + oModel.createKey("Rules", ruleKeyProperties);
1859
+ oCell.setTypePath(headerPath + '/BusinessDataType');
1860
+ if (sap.ui.getCore().byId(oParent.getAstExpressionLanguage())) {
1861
+ var sResultDataObjectId = oParent.getModel("settingModel").getData().ResultDataObjectId;
1862
+ var sAttributeId = oModel.getProperty(headerPath + '/DataObjectAttributeId');
1863
+ oCell.setAttributeInfoPath("/" + sResultDataObjectId + "/" + that.getParent()._formatAttributeId(sAttributeId));
1864
+ } else {
1865
+ oCell.setAttributeInfoPath(headerPath + '/DataObjectAttributeId');
1866
+ }
1867
+ oCell.setAttributeNamePath(headerPath + '/DataObjectAttributeName');
1868
+ oCell.setRuleFormatPath(rulePath + '/RuleFormat');
1869
+ oCell.setDecisionTableFormat(that.getParent().getDecisionTableFormat());
1870
+ break;
1871
+
1872
+ default:
1873
+ break;
1874
+ }
1875
+
1876
+ oCell.setKeyProperties(oCellProperties);
1877
+ oCell.setValueStateTextPath("dtModel>/validationStatus/" + "RowId=" + rowId + ",ColId=" + colId);
1878
+ oCell.setValueStatePath("dtModel>/valueState/" + "RowId=" + rowId + ",ColId=" + colId);
1879
+ }
1880
+
1881
+ oCell.setValuePath(path);
1882
+ },
1883
+
1884
+ //In case of reference object we will have attribues with ":" which should be replace by /
1885
+ _formatAttributeId: function (attributeId) {
1886
+ var formattedAttributeId = attributeId;
1887
+ if(formattedAttributeId && formattedAttributeId.indexOf(":") > -1) {
1888
+ formattedAttributeId = formattedAttributeId.replace(/:/g, "/");
1889
+ }
1890
+ return formattedAttributeId
1891
+ },
1892
+
1893
+ exit: function () {
1894
+ var oMenu = this.oMenu;
1895
+ if (oMenu) {
1896
+ oMenu.destroy();
1897
+ }
1898
+ },
1899
+
1900
+ init: function () {
1901
+ this.multiHeaderFlag = false; //flag for calculate only once header span for multi header in columnFactory function
1902
+ this.resetContent = true;
1903
+ this.astUtil = new AstUtil();
1904
+ this._initInternalModel();
1905
+ this._initDisplayModel();
1906
+ this._initDataBucket();
1907
+ this.bindProperty("busy", "dtModel>/busyState");
1908
+ this.oBundle = sap.ui.getCore().getLibraryResourceBundle("sap.rules.ui.i18n");
1909
+ this._addToolBar();
1910
+ this._addTable();
1911
+ this._addErrorLabel();
1912
+ this._decisionTableCellFormatter = new DecisionTableCellFormatter();
1913
+ this.setBusyIndicatorDelay(0);
1914
+ },
1915
+
1916
+ isSequenceExistsInOdataMetadata: function () {
1917
+ var model = this.getModel();
1918
+ if (model) {
1919
+ var serviceMetadata = model.getServiceMetadata();
1920
+ if (serviceMetadata) {
1921
+ var aEntities = serviceMetadata.dataServices.schema[0].entityType;
1922
+ var entity;
1923
+ var aProperties;
1924
+ var property;
1925
+
1926
+ for (var i = 0; i < aEntities.length; i++) {
1927
+ entity = aEntities[i];
1928
+
1929
+ if (entity.name !== "DecisionTableColumn") {
1930
+ continue;
1931
+ }
1932
+
1933
+ aProperties = entity.property;
1934
+
1935
+ for (var j = 0; j < aProperties.length; j++) {
1936
+ property = aProperties[j];
1937
+
1938
+ if (property.name === "Sequence") {
1939
+ return true;
1940
+ }
1941
+ }
1942
+ }
1943
+ }
1944
+ }
1945
+ return false;
1946
+ },
1947
+
1948
+ onBeforeRendering: function () {
1949
+ if (this.resetContent) {
1950
+ this.resetControl();
1951
+ this.resetContent = false;
1952
+ }
1953
+ },
1954
+
1955
+ resetControl: function () {
1956
+ this._unbindRule();
1957
+ this._unbindRows();
1958
+ this._unbindColumns();
1959
+ this._clearErrorMessages();
1960
+ this._initDataBucket();
1961
+ this._initDisplayModel();
1962
+ this._updateBusyState();
1963
+ var oModel = this._getModel();
1964
+ var bindingContextPath = this.getBindingContextPath();
1965
+ if (!bindingContextPath || !oModel) {
1966
+ return;
1967
+ }
1968
+ var oContext = new sap.ui.model.Context(oModel, bindingContextPath);
1969
+ this._internalModel.setProperty("/ruleBindingPath", bindingContextPath);
1970
+ this.setBindingContext(oContext);
1971
+ this._bindRule();
1972
+ this._bindRows();
1973
+ this._bindColumns();
1974
+ },
1975
+
1976
+ /** Control's properties getters/setters */
1977
+ setAstExpressionLanguage: function (value) {
1978
+ this.setAssociation("astExpressionLanguage", value, true);
1979
+ var astExpressionLanguage = (value instanceof Object) ? value : sap.ui.getCore().byId(value);
1980
+ if (!astExpressionLanguage) {
1981
+ return this;
1982
+ }
1983
+
1984
+ // if table has been built already - refresh it
1985
+ var oTable = this.getAggregation("_table");
1986
+ if (oTable) {
1987
+ var columnBinding = oTable.getBinding("columns");
1988
+ if (columnBinding) {
1989
+ columnBinding.refresh();
1990
+ }
1991
+ }
1992
+
1993
+ if (astExpressionLanguage._isDataExist()) {
1994
+ var oEvent = new sap.ui.base.Event("", "", {
1995
+ data: true
1996
+ });
1997
+ this._handleVocabularyDataChanged(oEvent);
1998
+ }
1999
+ astExpressionLanguage.attachDataChange(this._handleVocabularyDataChanged.bind(this));
2000
+
2001
+ return this;
2002
+ },
2003
+
2004
+ setBindingContextPath: function (value) {
2005
+ var oldValue = this.getBindingContextPath();
2006
+ if (value && (oldValue !== value)) {
2007
+ this._unbindRule();
2008
+ this._unbindRows();
2009
+ this._unbindColumns();
2010
+ this.setProperty("bindingContextPath", value);
2011
+ this.resetContent = true;
2012
+
2013
+ // reset dataBucket now (don't wait for onBeforeRendering),
2014
+ // attemption for preventing possible convertAndFormat with wrong data
2015
+ this._initDataBucket();
2016
+ var oModel = this.getModel()
2017
+ if (!oModel.isMetadataLoadingFailed()) {
2018
+ if (oModel.getServiceMetadata()) {
2019
+ this._internalModel.setProperty("/sequenceExist", this.isSequenceExistsInOdataMetadata());
2020
+ } else {
2021
+ oModel.attachMetadataLoaded(function () {
2022
+ this._internalModel.setProperty("/sequenceExist", this.isSequenceExistsInOdataMetadata());
2023
+ }.bind(this));
2024
+ }
2025
+ }
2026
+ }
2027
+ return this;
2028
+ },
2029
+
2030
+ setCellFormat: function (value) {
2031
+ this.setProperty("cellFormat", value, true);
2032
+ this._internalModel.setProperty("/cellFormat", value);
2033
+ return this;
2034
+ },
2035
+
2036
+ setEditable: function (value) {
2037
+ this.setProperty("editable", value, true);
2038
+ this._internalModel.setProperty("/editable", value);
2039
+ this._internalModel.setProperty("/sequenceExist", this.isSequenceExistsInOdataMetadata());
2040
+ var oTable = this.getAggregation("_table");
2041
+ var oToolbar = this.getAggregation("_toolbar");
2042
+ if (value === false) {
2043
+ oTable.addStyleClass("sapRULDecisionTableEdit");
2044
+ oToolbar.removeStyleClass("sapRULDecisionTableToolBar");
2045
+ } else {
2046
+ oTable.removeStyleClass("sapRULDecisionTableEdit");
2047
+ oToolbar.addStyleClass("sapRULDecisionTableToolBar");
2048
+ }
2049
+ if (value === false) {
2050
+ this._clearErrorMessages();
2051
+ }
2052
+ return this;
2053
+ },
2054
+
2055
+ setEnableSettings: function (value) {
2056
+ this.setProperty("enableSettings", value, true);
2057
+ this._internalModel.setProperty("/enableSettings", value);
2058
+ return this;
2059
+ },
2060
+
2061
+ setEnableSettingResult: function (value) {
2062
+ this.setProperty("enableSettingResult", value, true);
2063
+ return this;
2064
+ },
2065
+
2066
+ setExpressionLanguage: function (value) {
2067
+ this.setAssociation("expressionLanguage", value, true);
2068
+ this._decisionTableCellFormatter.setExpressionLanguage(this.getExpressionLanguage());
2069
+ var expressionLanguage = (value instanceof Object) ? value : sap.ui.getCore().byId(value);
2070
+ if (!expressionLanguage) {
2071
+ return this;
2072
+ }
2073
+
2074
+ // if table has been built already - refresh it
2075
+ var oTable = this.getAggregation("_table");
2076
+ if (oTable) {
2077
+ var columnBinding = oTable.getBinding("columns");
2078
+ if (columnBinding) {
2079
+ columnBinding.refresh();
2080
+ }
2081
+ }
2082
+
2083
+ if (expressionLanguage._isDataExist()) {
2084
+ var oEvent = new sap.ui.base.Event("", "", {
2085
+ data: true
2086
+ });
2087
+ this._handleVocabularyDataChanged(oEvent);
2088
+ }
2089
+ expressionLanguage.attachDataChange(this._handleVocabularyDataChanged.bind(this));
2090
+
2091
+ return this;
2092
+ },
2093
+
2094
+ setHitPolicies: function (value) {
2095
+ this.setProperty("hitPolicies", value, true);
2096
+ this._internalModel.setProperty("/hitPolicies", value);
2097
+ return this;
2098
+ },
2099
+
2100
+ setModelName: function (value) {
2101
+ this.setProperty("modelName", value);
2102
+ this.resetContent = true;
2103
+ return this;
2104
+ },
2105
+
2106
+ renderer: DecisionTableRenderer
2107
+
2108
+ });
2109
+
2110
+ /**
2111
+ * @private
2112
+ * @param {map} mParameters? -
2113
+ */
2114
+ sap.rules.ui.DecisionTable.prototype._saveWorkAround = function (mParameters, toastMessage) {
2115
+ var oModel = this._getModel();
2116
+ oModel.submitChanges(mParameters);
2117
+ sap.m.MessageToast.show(toastMessage);
2118
+ };
2119
+
2120
+ sap.rules.ui.DecisionTable.prototype.includes = function (parent, str) {
2121
+ var returnValue = false;
2122
+
2123
+ if (parent.indexOf(str) !== -1) {
2124
+ returnValue = true;
2125
+ }
2126
+
2127
+ return returnValue;
2128
+ };
2129
+
2130
+ sap.rules.ui.DecisionTable.prototype._getLocaleData = function () {
2131
+ var oLocale = sap.ui.getCore().getConfiguration().getFormatSettings().getFormatLocale();
2132
+ return LocaleData.getInstance(oLocale);
2133
+ };
2134
+
2135
+ sap.rules.ui.DecisionTable.prototype._getDateFormatter = function () {
2136
+ var oLocaleData = this._getLocaleData();
2137
+ var datePattern = oLocaleData.getDatePattern('medium');
2138
+ var dateFormatter = sap.ui.core.format.DateFormat.getDateInstance({
2139
+ pattern: datePattern
2140
+ });
2141
+ return dateFormatter;
2142
+ };
2143
+
2144
+ sap.rules.ui.DecisionTable.prototype._getDateTimeFormatter = function () {
2145
+ var oLocaleData = this._getLocaleData();
2146
+ var datePattern = oLocaleData.getDatePattern('medium');
2147
+ var timePattern = oLocaleData.getTimePattern('medium');
2148
+ var dateTimeFormatter = sap.ui.core.format.DateFormat.getDateTimeInstance({
2149
+ pattern: datePattern + " " + timePattern
2150
+ });
2151
+ return dateTimeFormatter;
2152
+ };
2153
+
2154
+ sap.rules.ui.DecisionTable.prototype.VISIBLEROWCOUNT = 30;
2155
+
2156
+ sap.rules.ui.DecisionTable.prototype.THRESHOLD = 30;
2157
+
2158
+ return oDecisionTable;
2159
+
2160
+ }, /* bExport= */ true);