@sankhyalabs/sankhyablocks 5.17.0 → 5.18.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 (134) hide show
  1. package/dist/cjs/ParamType-90b440a0.js +13 -0
  2. package/dist/cjs/{SnkMessageBuilder-cf80308c.js → SnkMessageBuilder-3b5b5614.js} +30 -1
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/sankhyablocks.cjs.js +1 -1
  5. package/dist/cjs/snk-actions-button.cjs.entry.js +704 -0
  6. package/dist/cjs/snk-actions-form.cjs.entry.js +200 -0
  7. package/dist/cjs/snk-application.cjs.entry.js +1 -1
  8. package/dist/cjs/snk-attach.cjs.entry.js +1 -1
  9. package/dist/cjs/snk-client-confirm.cjs.entry.js +52 -0
  10. package/dist/cjs/snk-crud.cjs.entry.js +1 -1
  11. package/dist/cjs/snk-data-exporter.cjs.entry.js +2 -2
  12. package/dist/cjs/{snk-data-unit-bd271acd.js → snk-data-unit-e9c20097.js} +1 -1
  13. package/dist/cjs/snk-data-unit.cjs.entry.js +2 -2
  14. package/dist/cjs/snk-detail-view.cjs.entry.js +4 -4
  15. package/dist/cjs/snk-grid.cjs.entry.js +4 -4
  16. package/dist/cjs/{snk-guides-viewer-0ab3746e.js → snk-guides-viewer-c8843478.js} +2 -2
  17. package/dist/cjs/snk-guides-viewer.cjs.entry.js +3 -3
  18. package/dist/cjs/snk-simple-bar_2.cjs.entry.js +2 -2
  19. package/dist/cjs/snk-taskbar.cjs.entry.js +1 -1
  20. package/dist/cjs/{taskbar-elements-bc2598f9.js → taskbar-elements-3be287d6.js} +3 -0
  21. package/dist/cjs/{taskbar-processor-e1e3bbf7.js → taskbar-processor-02f0fc84.js} +1 -1
  22. package/dist/collection/collection-manifest.json +3 -0
  23. package/dist/collection/components/snk-actions-button/actions/enum/ActionsType.js +8 -0
  24. package/dist/collection/components/snk-actions-button/actions/enum/ParamType.js +11 -0
  25. package/dist/collection/components/snk-actions-button/actions/enum/RefreshType.js +7 -0
  26. package/dist/collection/components/snk-actions-button/actions/executor/java.executor.js +22 -0
  27. package/dist/collection/components/snk-actions-button/actions/executor/javascript.executor.js +20 -0
  28. package/dist/collection/components/snk-actions-button/actions/executor/launch-screen.executor.js +42 -0
  29. package/dist/collection/components/snk-actions-button/actions/executor/procedure.executor.js +26 -0
  30. package/dist/collection/components/snk-actions-button/actions/factory/executor.factory.js +26 -0
  31. package/dist/collection/components/snk-actions-button/actions/index.js +343 -0
  32. package/dist/collection/components/snk-actions-button/actions/interfaces/IAction.js +7 -0
  33. package/dist/collection/components/snk-actions-button/actions/interfaces/IExecSource.js +1 -0
  34. package/dist/collection/components/snk-actions-button/actions/interfaces/IExecuteActions.js +1 -0
  35. package/dist/collection/components/snk-actions-button/actions/interfaces/IExecuteActionsProps.js +1 -0
  36. package/dist/collection/components/snk-actions-button/actions/interfaces/IResultParam.js +1 -0
  37. package/dist/collection/components/snk-actions-button/clientEvent/index.js +87 -0
  38. package/dist/collection/components/snk-actions-button/clientEvent/interfaces/IClientEventConfirm.js +1 -0
  39. package/dist/collection/components/snk-actions-button/snk-actions-button.css +38 -0
  40. package/dist/collection/components/snk-actions-button/snk-actions-button.js +139 -0
  41. package/dist/collection/components/snk-actions-button/subcomponents/snk-actions-form.js +263 -0
  42. package/dist/collection/components/snk-actions-button/subcomponents/snk-client-confirm.js +134 -0
  43. package/dist/collection/components/snk-grid/snk-grid.js +2 -2
  44. package/dist/collection/components/snk-taskbar/elements/taskbar-elements.js +3 -0
  45. package/dist/collection/lib/message/SnkMessageBuilder.js +3 -1
  46. package/dist/collection/lib/message/resources/snk-actions-button.msg.js +27 -0
  47. package/dist/components/ParamType.js +13 -0
  48. package/dist/components/SnkMessageBuilder.js +30 -1
  49. package/dist/components/index.d.ts +3 -0
  50. package/dist/components/index.js +3 -0
  51. package/dist/components/snk-actions-button.d.ts +11 -0
  52. package/dist/components/snk-actions-button.js +6 -0
  53. package/dist/components/snk-actions-button2.js +718 -0
  54. package/dist/components/snk-actions-form.d.ts +11 -0
  55. package/dist/components/snk-actions-form.js +218 -0
  56. package/dist/components/snk-attach2.js +7 -1
  57. package/dist/components/snk-client-confirm.d.ts +11 -0
  58. package/dist/components/snk-client-confirm.js +71 -0
  59. package/dist/components/snk-crud.js +7 -1
  60. package/dist/components/snk-detail-view2.js +13 -2
  61. package/dist/components/snk-grid2.js +9 -3
  62. package/dist/components/snk-simple-crud2.js +7 -1
  63. package/dist/components/snk-taskbar2.js +10 -1
  64. package/dist/esm/ParamType-d5152b06.js +13 -0
  65. package/dist/esm/{SnkMessageBuilder-1a169545.js → SnkMessageBuilder-188a38bb.js} +30 -1
  66. package/dist/esm/loader.js +1 -1
  67. package/dist/esm/sankhyablocks.js +1 -1
  68. package/dist/esm/snk-actions-button.entry.js +700 -0
  69. package/dist/esm/snk-actions-form.entry.js +196 -0
  70. package/dist/esm/snk-application.entry.js +1 -1
  71. package/dist/esm/snk-attach.entry.js +1 -1
  72. package/dist/esm/snk-client-confirm.entry.js +48 -0
  73. package/dist/esm/snk-crud.entry.js +1 -1
  74. package/dist/esm/snk-data-exporter.entry.js +2 -2
  75. package/dist/esm/{snk-data-unit-476024e9.js → snk-data-unit-79b1583a.js} +1 -1
  76. package/dist/esm/snk-data-unit.entry.js +2 -2
  77. package/dist/esm/snk-detail-view.entry.js +4 -4
  78. package/dist/esm/snk-grid.entry.js +4 -4
  79. package/dist/esm/{snk-guides-viewer-767f5a74.js → snk-guides-viewer-59d3a78c.js} +2 -2
  80. package/dist/esm/snk-guides-viewer.entry.js +3 -3
  81. package/dist/esm/snk-simple-bar_2.entry.js +2 -2
  82. package/dist/esm/snk-taskbar.entry.js +1 -1
  83. package/dist/esm/{taskbar-elements-e6af3e93.js → taskbar-elements-8ff33c26.js} +3 -0
  84. package/dist/esm/{taskbar-processor-a40798b8.js → taskbar-processor-20de6616.js} +1 -1
  85. package/dist/sankhyablocks/{p-3e17b147.js → p-0b40c655.js} +1 -1
  86. package/dist/sankhyablocks/{p-de9caf1e.entry.js → p-0b6ddb67.entry.js} +1 -1
  87. package/dist/sankhyablocks/p-19692f92.js +1 -0
  88. package/dist/sankhyablocks/{p-6df8c88b.entry.js → p-257c71a7.entry.js} +1 -1
  89. package/dist/sankhyablocks/{p-551165d8.js → p-28c12f65.js} +1 -1
  90. package/dist/sankhyablocks/{p-78de64fb.entry.js → p-2d0fc912.entry.js} +1 -1
  91. package/dist/sankhyablocks/p-384c4a6b.js +1 -0
  92. package/dist/sankhyablocks/{p-f43629f3.entry.js → p-44c2ed16.entry.js} +1 -1
  93. package/dist/sankhyablocks/{p-ec1c64be.entry.js → p-8ce9ea9f.entry.js} +1 -1
  94. package/dist/sankhyablocks/{p-e0c04667.entry.js → p-9c7f7214.entry.js} +1 -1
  95. package/dist/sankhyablocks/p-9f66bc54.entry.js +1 -0
  96. package/dist/sankhyablocks/{p-c74fca58.js → p-b34d23fa.js} +1 -1
  97. package/dist/sankhyablocks/p-b680fa7a.entry.js +1 -0
  98. package/dist/sankhyablocks/p-b75ce8b8.entry.js +1 -0
  99. package/dist/sankhyablocks/{p-9e92ed74.entry.js → p-cbe93a18.entry.js} +2 -2
  100. package/dist/sankhyablocks/p-eaad0aa8.js +1 -0
  101. package/dist/sankhyablocks/{p-7956b9dd.entry.js → p-eb07d0eb.entry.js} +1 -1
  102. package/dist/sankhyablocks/p-f27dc5e9.entry.js +1 -0
  103. package/dist/sankhyablocks/p-fa2d0376.entry.js +1 -0
  104. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  105. package/dist/types/components/snk-actions-button/actions/enum/ActionsType.d.ts +7 -0
  106. package/dist/types/components/snk-actions-button/actions/enum/ParamType.d.ts +10 -0
  107. package/dist/types/components/snk-actions-button/actions/enum/RefreshType.d.ts +6 -0
  108. package/dist/types/components/snk-actions-button/actions/executor/java.executor.d.ts +6 -0
  109. package/dist/types/components/snk-actions-button/actions/executor/javascript.executor.d.ts +6 -0
  110. package/dist/types/components/snk-actions-button/actions/executor/launch-screen.executor.d.ts +10 -0
  111. package/dist/types/components/snk-actions-button/actions/executor/procedure.executor.d.ts +6 -0
  112. package/dist/types/components/snk-actions-button/actions/factory/executor.factory.d.ts +7 -0
  113. package/dist/types/components/snk-actions-button/actions/index.d.ts +27 -0
  114. package/dist/types/components/snk-actions-button/actions/interfaces/IAction.d.ts +55 -0
  115. package/dist/types/components/snk-actions-button/actions/interfaces/IExecSource.d.ts +17 -0
  116. package/dist/types/components/snk-actions-button/actions/interfaces/IExecuteActions.d.ts +4 -0
  117. package/dist/types/components/snk-actions-button/actions/interfaces/IExecuteActionsProps.d.ts +4 -0
  118. package/dist/types/components/snk-actions-button/actions/interfaces/IResultParam.d.ts +14 -0
  119. package/dist/types/components/snk-actions-button/clientEvent/index.d.ts +4 -0
  120. package/dist/types/components/snk-actions-button/clientEvent/interfaces/IClientEventConfirm.d.ts +35 -0
  121. package/dist/types/components/snk-actions-button/snk-actions-button.d.ts +27 -0
  122. package/dist/types/components/snk-actions-button/subcomponents/snk-actions-form.d.ts +41 -0
  123. package/dist/types/components/snk-actions-button/subcomponents/snk-client-confirm.d.ts +31 -0
  124. package/dist/types/components/snk-taskbar/elements/taskbar-elements.d.ts +2 -1
  125. package/dist/types/components.d.ts +96 -0
  126. package/dist/types/lib/message/resources/snk-actions-button.msg.d.ts +1 -0
  127. package/package.json +1 -1
  128. package/react/components.d.ts +3 -0
  129. package/react/components.js +3 -0
  130. package/react/components.js.map +1 -1
  131. package/dist/sankhyablocks/p-1c5d5e5c.entry.js +0 -1
  132. package/dist/sankhyablocks/p-39082fc3.js +0 -1
  133. package/dist/sankhyablocks/p-8d40909d.entry.js +0 -1
  134. package/dist/sankhyablocks/p-d410f45a.js +0 -1
@@ -0,0 +1,718 @@
1
+ import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
2
+ import { ApplicationContext, StringUtils, ErrorException, WarningException, ObjectUtils, DateUtils, ArrayUtils, ElementIDUtils } from '@sankhyalabs/core';
3
+ import { D as DataFetcher } from './DataFetcher.js';
4
+ import { P as ParamType } from './ParamType.js';
5
+ import './pesquisa-fetcher.js';
6
+ import './index2.js';
7
+
8
+ const SERVICE_ACTION_EXECUTE_JAVA = 'ActionButtonsSP.executeJava';
9
+ class JavaExecutor {
10
+ execute(action) {
11
+ var _a;
12
+ const execSource = {
13
+ actionID: action.actionID,
14
+ refreshType: (_a = action.actionConfig.javaCall) === null || _a === void 0 ? void 0 : _a.refreshType
15
+ };
16
+ return new Promise((resolve) => {
17
+ resolve({ execSource, callback: this.callExecJava });
18
+ });
19
+ }
20
+ callExecJava(execSource) {
21
+ const request = {
22
+ requestBody: {
23
+ javaCall: execSource
24
+ }
25
+ };
26
+ DataFetcher.get().callServiceBroker(SERVICE_ACTION_EXECUTE_JAVA, JSON.stringify(request));
27
+ }
28
+ }
29
+
30
+ const SERVICE_ACTION_EXECUTE_SCRIPT = 'ActionButtonsSP.executeScript';
31
+ class JavascriptExecutor {
32
+ execute(action) {
33
+ var _a;
34
+ const execSource = {
35
+ actionID: action.actionID,
36
+ refreshType: (_a = action.actionConfig.runScript) === null || _a === void 0 ? void 0 : _a.refreshType
37
+ };
38
+ return new Promise((resolve) => {
39
+ resolve({ execSource, callback: this.callExecScript });
40
+ });
41
+ }
42
+ callExecScript(execSource) {
43
+ const request = {
44
+ runScript: execSource
45
+ };
46
+ DataFetcher.get().callServiceBroker(SERVICE_ACTION_EXECUTE_SCRIPT, request);
47
+ }
48
+ }
49
+
50
+ class LaunchScreenExecutor {
51
+ constructor() {
52
+ this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
53
+ }
54
+ async execute(action, dataUnit) {
55
+ const resourceID = action.resourceID;
56
+ if (!resourceID)
57
+ return;
58
+ let launchObject = await this.buildLaunchObject(action, dataUnit);
59
+ this._application.openApp(resourceID, launchObject);
60
+ return null;
61
+ }
62
+ buildLaunchObject(action, dataUnit) {
63
+ return new Promise((resolve) => {
64
+ let params = action.actionConfig.params.param;
65
+ if (params && params.length > 0) {
66
+ let launchObject = {};
67
+ let processedParams = [];
68
+ params.forEach(param => {
69
+ const localField = param.localField;
70
+ let value = dataUnit.getFieldValue(localField);
71
+ if (!value) {
72
+ let localFieldLabel = dataUnit.getField(localField).label;
73
+ localFieldLabel = StringUtils.isEmpty(dataUnit.getField(localField).label) ? localField : localFieldLabel;
74
+ throw new ErrorException(this._application.messagesBuilder.getMessage("snkActionsButton.title.error", undefined), this._application.messagesBuilder.getMessage("snkActionsButton.launchScreen.emptyField", { description: action.description, localFieldLabel: localFieldLabel }));
75
+ }
76
+ value = StringUtils.isEmpty(value.toString()) ? undefined : value.toString();
77
+ launchObject[param.targetField] = value;
78
+ processedParams.push({
79
+ fieldName: param.targetField,
80
+ value: value
81
+ });
82
+ });
83
+ launchObject.ACTION_PARAMETERS = processedParams;
84
+ launchObject.call_time = Date.now();
85
+ resolve(launchObject);
86
+ }
87
+ resolve(null);
88
+ });
89
+ }
90
+ }
91
+
92
+ const SERVICE_ACTION_EXECUTE_STP = 'ActionButtonsSP.executeSTP';
93
+ class ProcedureExecutor {
94
+ execute(action) {
95
+ var _a, _b, _c;
96
+ const procName = (_a = action.actionConfig.dbCall) === null || _a === void 0 ? void 0 : _a.name;
97
+ const rootEntity = (_b = action.actionConfig.dbCall) === null || _b === void 0 ? void 0 : _b.rootEntity;
98
+ const execSource = {
99
+ actionID: action.actionID,
100
+ refreshType: (_c = action.actionConfig.dbCall) === null || _c === void 0 ? void 0 : _c.refreshType,
101
+ procName: procName,
102
+ rootEntity: rootEntity
103
+ };
104
+ return new Promise((resolve) => {
105
+ resolve({ execSource, callback: this.callExecProcedure });
106
+ });
107
+ }
108
+ callExecProcedure(execSource) {
109
+ const request = {
110
+ requestBody: {
111
+ stpCall: execSource
112
+ }
113
+ };
114
+ DataFetcher.get().callServiceBroker(SERVICE_ACTION_EXECUTE_STP, JSON.stringify(request));
115
+ }
116
+ }
117
+
118
+ var ActionsType;
119
+ (function (ActionsType) {
120
+ ActionsType["LAUNCH_SCREEN"] = "LC";
121
+ ActionsType["JAVASCRIPT"] = "SC";
122
+ ActionsType["JAVA"] = "RJ";
123
+ ActionsType["PROCEDURE"] = "SP";
124
+ ActionsType["EMBEDDED"] = "EB";
125
+ })(ActionsType || (ActionsType = {}));
126
+
127
+ class ExecutorFactory {
128
+ constructor(actionType) {
129
+ this.actionType = actionType;
130
+ this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
131
+ }
132
+ get executor() {
133
+ switch (this.actionType) {
134
+ case ActionsType.LAUNCH_SCREEN:
135
+ return new LaunchScreenExecutor();
136
+ case ActionsType.JAVASCRIPT:
137
+ return new JavascriptExecutor();
138
+ case ActionsType.JAVA:
139
+ return new JavaExecutor();
140
+ case ActionsType.PROCEDURE:
141
+ return new ProcedureExecutor();
142
+ default:
143
+ throw new ErrorException(this._application.messagesBuilder.getMessage("snkActionsButton.title.error", undefined), this._application.messagesBuilder.getMessage("snkActionsButton.action.nonExistentType", { actionType: this.actionType }));
144
+ }
145
+ }
146
+ }
147
+
148
+ var RefreshType;
149
+ (function (RefreshType) {
150
+ RefreshType["NONE"] = "NONE";
151
+ RefreshType["PARENT"] = "PARENT";
152
+ RefreshType["MASTER"] = "MASTER";
153
+ RefreshType["ALL"] = "ALL";
154
+ })(RefreshType || (RefreshType = {}));
155
+
156
+ const MASTER_ROW_PROPERTY = "__MASTER_ROW__";
157
+ const ENTITY_NAME_PROPERTY = '__ENTITY_NAME__';
158
+ const NUFIN_COLUMN = 'NUFIN';
159
+ const SERVICE_GET_CONFIGURATIONS = 'SystemUtilsSP.getConf';
160
+ class Actions {
161
+ constructor(actionsExecuteInterface, dataUnit) {
162
+ var _a;
163
+ this._lastValuesCache = {};
164
+ this._actionsExecuteInterface = actionsExecuteInterface;
165
+ this._dataUnit = dataUnit;
166
+ this._selectedRows = ((_a = dataUnit === null || dataUnit === void 0 ? void 0 : dataUnit.getSelectionInfo()) === null || _a === void 0 ? void 0 : _a.isAllRecords()) ? [] : dataUnit === null || dataUnit === void 0 ? void 0 : dataUnit.getSelectionInfo().records;
167
+ this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
168
+ }
169
+ apply(action, hasParamsToSave) {
170
+ this._application.closePopUp();
171
+ this._actionsExecuteInterface.execute(action, this._dataUnit)
172
+ .then(({ execSource, callback }) => {
173
+ this.resolvePromptParams(action, execSource, hasParamsToSave)
174
+ .then(() => {
175
+ this.actionExecute(execSource, callback);
176
+ });
177
+ });
178
+ }
179
+ ;
180
+ async execute(action) {
181
+ var _a;
182
+ if (!action.actionConfig) {
183
+ throw new WarningException(this._application.messagesBuilder.getMessage("snkActionsButton.title.warning", undefined), this._application.messagesBuilder.getMessage("snkActionsButton.action.incorrectAction", { description: action.description }));
184
+ }
185
+ if (!!((_a = action.actionConfig.params) === null || _a === void 0 ? void 0 : _a.promptParam)) {
186
+ const paramsSource = action.actionConfig.params.promptParam;
187
+ let hasParamsToSave = false;
188
+ for (let i = 0; i < paramsSource.length; i++) {
189
+ let paramSource = paramsSource[i];
190
+ if (!hasParamsToSave && paramSource.saveLast === 'true') {
191
+ hasParamsToSave = true;
192
+ break;
193
+ }
194
+ }
195
+ if (hasParamsToSave) {
196
+ action.actionConfig.params.promptParam = await this.loadSavedValuesIntoParams(action);
197
+ }
198
+ const form = document.createElement("snk-actions-form");
199
+ window.document.body.appendChild(form);
200
+ form.action = ObjectUtils.copy(action);
201
+ form.applyParameters = (resultAction) => {
202
+ this.apply(resultAction, hasParamsToSave);
203
+ };
204
+ form.openPopup();
205
+ }
206
+ else if (action.type != ActionsType.LAUNCH_SCREEN) {
207
+ this._actionsExecuteInterface.execute(action, this._dataUnit)
208
+ .then(({ execSource, callback }) => {
209
+ this.actionExecute(execSource, callback);
210
+ });
211
+ }
212
+ else {
213
+ this._actionsExecuteInterface.execute(action, this._dataUnit);
214
+ }
215
+ }
216
+ loadSavedValuesIntoParams(action) {
217
+ return this.loadLastValues(action)
218
+ .then((lastParams) => {
219
+ let resultParams = action.actionConfig.params.promptParam;
220
+ if (lastParams) {
221
+ lastParams.param.forEach(lastParam => {
222
+ resultParams = resultParams.map((param) => {
223
+ if (param.name !== lastParam.paramName)
224
+ return param;
225
+ if (param.paramType === 'B') {
226
+ return Object.assign(Object.assign({}, param), { value: lastParam.$ === 'S' });
227
+ }
228
+ return Object.assign(Object.assign({}, param), { value: lastParam.$ });
229
+ });
230
+ });
231
+ }
232
+ return resultParams;
233
+ });
234
+ }
235
+ actionExecute(execSource, callback) {
236
+ execSource.virtualPage = this.buildVirtualPage();
237
+ this.prepareAndExecute(execSource, callback);
238
+ this.recordsReloader(execSource.refreshType);
239
+ }
240
+ resolvePromptParams(action, execSource, hasParamsToSave) {
241
+ return new Promise(resolve => {
242
+ const paramsSource = action.actionConfig.params.promptParam;
243
+ let params = [];
244
+ paramsSource.forEach(paramSource => {
245
+ params.push(this.buildPromptParam(paramSource));
246
+ });
247
+ this.putParamsOnExecSource(params, execSource);
248
+ if (hasParamsToSave) {
249
+ this.saveLastValues(action, params);
250
+ }
251
+ resolve();
252
+ });
253
+ }
254
+ buildPromptParam(param) {
255
+ let type = param.paramType;
256
+ let isCheckbox = false;
257
+ let fieldProps;
258
+ let entityPK;
259
+ let value = param.value;
260
+ switch (type) {
261
+ case ParamType.DATE:
262
+ type = 'D';
263
+ break;
264
+ case ParamType.DATETIME:
265
+ type = 'H';
266
+ break;
267
+ case ParamType.DECIMAL:
268
+ type = 'F';
269
+ fieldProps = {
270
+ 'sk-precision': Number(param.precision)
271
+ };
272
+ break;
273
+ case ParamType.BOOLEAN:
274
+ type = 'S';
275
+ isCheckbox = true;
276
+ value = param.value ? 'S' : 'N';
277
+ break;
278
+ case ParamType.ENTITY:
279
+ fieldProps = {
280
+ 'sk-entity-name': param.entityName,
281
+ 'sk-allow-show-hierarchical-mode': param.hierarchyEntity,
282
+ 'sk-data-type': 'S'
283
+ };
284
+ if (param.hierarchyEntity && param.entityPK) {
285
+ entityPK = param.entityPK;
286
+ }
287
+ value = param.value ? Number(param.value) : null;
288
+ break;
289
+ case ParamType.OPTIONS:
290
+ type = 'O';
291
+ let options = param.options.split(';').map(function (opc, index) {
292
+ let data;
293
+ let value;
294
+ if (opc.indexOf('=') > -1) {
295
+ let opcArr = opc.split('=');
296
+ data = opcArr[0];
297
+ value = opcArr[1];
298
+ }
299
+ else {
300
+ data = (index + 1);
301
+ value = opc;
302
+ }
303
+ return {
304
+ data: data,
305
+ value: value
306
+ };
307
+ });
308
+ fieldProps = {
309
+ 'sk-options': options
310
+ };
311
+ break;
312
+ }
313
+ return {
314
+ description: param.label,
315
+ required: param.required == 'true',
316
+ fieldName: param.name,
317
+ fieldNameOri: param.name,
318
+ entityPK: entityPK,
319
+ paramType: param.paramType,
320
+ type: type,
321
+ isCheckbox: isCheckbox,
322
+ saveLast: param.saveLast,
323
+ fieldProp: fieldProps,
324
+ value: value,
325
+ isGeneratedName: param.isGeneratedName
326
+ };
327
+ }
328
+ putParamsOnExecSource(params, execSource) {
329
+ execSource.params = {
330
+ param: []
331
+ };
332
+ params.forEach(param => {
333
+ if (param.isGeneratedName && param.value) {
334
+ throw new ErrorException(this._application.messagesBuilder.getMessage("snkActionsButton.title.error", undefined), this._application.messagesBuilder.getMessage("snkActionsButton.action.emptyParamName", undefined));
335
+ }
336
+ if (!StringUtils.isEmpty(param.value)) {
337
+ execSource.params.param.push({
338
+ type: this.getParamDataType(param.paramType),
339
+ paramName: param.fieldName,
340
+ $: this.getParamValue(param)
341
+ });
342
+ }
343
+ });
344
+ }
345
+ getParamDataType(type) {
346
+ let dataType;
347
+ switch (type) {
348
+ case "D":
349
+ dataType = "F";
350
+ break;
351
+ case "DT":
352
+ case "DH":
353
+ dataType = "D";
354
+ break;
355
+ case "B":
356
+ case "ENTITY":
357
+ case "SO":
358
+ dataType = "S";
359
+ break;
360
+ default:
361
+ dataType = type;
362
+ }
363
+ return dataType;
364
+ }
365
+ getParamValue(param) {
366
+ let value = param.value;
367
+ if (!value) {
368
+ return value;
369
+ }
370
+ if (param.paramType == 'DT') {
371
+ value = DateUtils.formatDate(value);
372
+ }
373
+ else if (param.paramType == 'DH') {
374
+ value = DateUtils.formatDateTime(value);
375
+ }
376
+ return value;
377
+ }
378
+ async loadLastValues(action) {
379
+ const resourceId = await this.buildResourceId(action.actionID);
380
+ return new Promise((resolve, reject) => {
381
+ if (this._lastValuesCache[resourceId]) {
382
+ resolve(this._lastValuesCache[resourceId]);
383
+ }
384
+ else {
385
+ const config = {
386
+ config: {
387
+ chave: resourceId,
388
+ tipo: 'T'
389
+ }
390
+ };
391
+ DataFetcher.get().callServiceBroker(SERVICE_GET_CONFIGURATIONS, config)
392
+ .then((result) => {
393
+ var _a, _b;
394
+ let lastParams;
395
+ if ((_b = (_a = result.config) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.params) {
396
+ lastParams = result.config.data.params;
397
+ if (!Array.isArray(lastParams.param)) {
398
+ lastParams.param = [lastParams.param];
399
+ }
400
+ }
401
+ this._lastValuesCache[resourceId] = lastParams;
402
+ resolve(lastParams);
403
+ }).catch((error) => {
404
+ reject(error);
405
+ });
406
+ }
407
+ });
408
+ }
409
+ async saveLastValues(action, params) {
410
+ if (this._application) {
411
+ let config = {
412
+ params: {
413
+ param: []
414
+ }
415
+ };
416
+ params.forEach(param => {
417
+ if (param.saveLast == 'true') {
418
+ config.params.param.push({
419
+ paramName: param.fieldName,
420
+ $: param.value
421
+ });
422
+ }
423
+ });
424
+ const resourceId = await this.buildResourceId(action.actionID);
425
+ this._lastValuesCache[resourceId] = config.params;
426
+ this._application.saveConfig(resourceId, config);
427
+ }
428
+ }
429
+ async buildResourceId(actionId) {
430
+ let appResId = '';
431
+ appResId = await this._application.getResourceID();
432
+ return appResId + '.actionconfig.' + actionId;
433
+ }
434
+ prepareAndExecute(execSource, executeAction) {
435
+ this.addRows(execSource);
436
+ executeAction(execSource);
437
+ }
438
+ addRows(execSource) {
439
+ const rows = {
440
+ row: []
441
+ };
442
+ const sourceRows = this._selectedRows;
443
+ for (const i in sourceRows) {
444
+ const sourceRow = sourceRows[i];
445
+ const row = {};
446
+ if (sourceRow.hasOwnProperty(MASTER_ROW_PROPERTY)) {
447
+ row.master = 'S';
448
+ row.entityName = sourceRow.__ENTITY_NAME__;
449
+ delete sourceRow[MASTER_ROW_PROPERTY];
450
+ delete sourceRow[ENTITY_NAME_PROPERTY];
451
+ }
452
+ for (const fieldName in sourceRow) {
453
+ if (fieldName !== NUFIN_COLUMN)
454
+ continue;
455
+ if (!row.field) {
456
+ row.field = [];
457
+ }
458
+ row.field.push({
459
+ fieldName: fieldName,
460
+ $: sourceRow[fieldName]
461
+ });
462
+ }
463
+ rows.row.push(row);
464
+ }
465
+ if (rows.row.length > 0) {
466
+ execSource.rows = rows;
467
+ }
468
+ }
469
+ recordsReloader(refreshType) {
470
+ switch (refreshType) {
471
+ case RefreshType.NONE:
472
+ break;
473
+ case RefreshType.PARENT:
474
+ case RefreshType.MASTER:
475
+ case RefreshType.ALL:
476
+ this._dataUnit.loadData();
477
+ break;
478
+ default:
479
+ this._dataUnit.reloadCurrentRecord();
480
+ }
481
+ }
482
+ ;
483
+ buildVirtualPage() {
484
+ var _a, _b, _c, _d;
485
+ if ((_b = (_a = this._dataUnit) === null || _a === void 0 ? void 0 : _a.getSelectionInfo()) === null || _b === void 0 ? void 0 : _b.isAllRecords()) {
486
+ const virtualPage = {
487
+ filters: { filters: (_c = this._dataUnit) === null || _c === void 0 ? void 0 : _c.getAppliedFilters() },
488
+ orders: { orders: (_d = this._dataUnit) === null || _d === void 0 ? void 0 : _d.getSort() },
489
+ };
490
+ return virtualPage;
491
+ }
492
+ }
493
+ }
494
+
495
+ const CONFIRMACAO = "__CONFIRMACAO__";
496
+ const ESCOLHA_SIM_NAO = "__ESCOLHA_SIMNAO__";
497
+ class ClientEventConfirm {
498
+ clientConfirm(clientEvent, recaller) {
499
+ const application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
500
+ let actionType = "";
501
+ if (clientEvent.content.event.hasOwnProperty('stpCall')) {
502
+ recaller.requestBody = clientEvent.content.event.stpCall;
503
+ actionType = ActionsType.PROCEDURE;
504
+ }
505
+ else if (clientEvent.content.event.hasOwnProperty('runScript')) {
506
+ recaller.requestBody = clientEvent.content.event.runScript;
507
+ actionType = ActionsType.JAVASCRIPT;
508
+ }
509
+ else if (clientEvent.content.event.hasOwnProperty('javaCall')) {
510
+ recaller.requestBody = clientEvent.content.event.javaCall;
511
+ actionType = ActionsType.JAVA;
512
+ }
513
+ let param = {
514
+ type: 'S',
515
+ sequence: clientEvent.content.event.sequence
516
+ };
517
+ if (!recaller.requestBody.params) {
518
+ recaller.requestBody.params = {
519
+ param: []
520
+ };
521
+ }
522
+ else {
523
+ if (!Array.isArray(recaller.requestBody.params.param)) {
524
+ recaller.requestBody.params.param = [recaller.requestBody.params.param];
525
+ }
526
+ }
527
+ recaller.requestBody.params.param.push(param);
528
+ const title = clientEvent.content.event.title.$;
529
+ const message = clientEvent.content.event.message.$;
530
+ let requestBody;
531
+ switch (actionType) {
532
+ case ActionsType.JAVASCRIPT:
533
+ requestBody = { runScript: recaller.requestBody };
534
+ break;
535
+ case ActionsType.PROCEDURE:
536
+ requestBody = {
537
+ requestBody: {
538
+ stpCall: recaller.requestBody
539
+ }
540
+ };
541
+ break;
542
+ case ActionsType.JAVA:
543
+ requestBody = {
544
+ requestBody: {
545
+ javaCall: recaller.requestBody
546
+ }
547
+ };
548
+ break;
549
+ }
550
+ if (clientEvent.content.event.showNoOption == 'S') {
551
+ param.paramName = ESCOLHA_SIM_NAO;
552
+ const form = document.createElement("snk-client-confirm");
553
+ window.document.body.appendChild(form);
554
+ form.titleMessage = title;
555
+ form.message = message;
556
+ form.accept = () => {
557
+ param.$ = 'S';
558
+ recaller.reCall(requestBody);
559
+ };
560
+ form.cancel = () => {
561
+ param.$ = 'N';
562
+ recaller.reCall(requestBody);
563
+ };
564
+ form.openPopup();
565
+ }
566
+ else {
567
+ application.confirm(title, message, null, 'warn', {
568
+ labelCancel: "Cancelar",
569
+ labelConfirm: "Sim"
570
+ }).then((confirmResult) => {
571
+ if (confirmResult) {
572
+ param.paramName = CONFIRMACAO;
573
+ param.$ = 'S';
574
+ recaller.reCall(requestBody);
575
+ }
576
+ });
577
+ }
578
+ }
579
+ }
580
+
581
+ const snkActionsButtonCss = ".sc-snk-actions-button-h{--snk-actions-button--z-index:var(--most-visible, 3);display:flex;width:fit-content;height:fit-content}.snk-actions-button.sc-snk-actions-button{display:flex;width:fit-content;height:fit-content}.snk-actions-button__dropdown--show.sc-snk-actions-button{display:flex;flex-direction:column;position:fixed}.snk-actions-button__dropdown.sc-snk-actions-button>ez-dropdown.sc-snk-actions-button{position:relative}.snk-actions-button--overlap.sc-snk-actions-button{z-index:var(--snk-actions-button--z-index)}.snk-actions-button__dropdown.sc-snk-actions-button{display:none}";
582
+
583
+ const SnkActionsButton = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
584
+ constructor() {
585
+ super();
586
+ this.__registerHost();
587
+ this.CLIENT_EVENT_CONFIRM_NAME = "br.com.sankhya.actionbutton.clientconfirm";
588
+ this.handleClick = (evt) => {
589
+ const selectedAction = this._actions.find((action) => action.actionID == evt.detail.id);
590
+ const executor = new ExecutorFactory(selectedAction.type).executor;
591
+ const action = new Actions(executor, this._dataUnit);
592
+ action.execute(Object.assign({}, selectedAction));
593
+ this._showDropdown = false;
594
+ };
595
+ this._items = [];
596
+ this._showDropdown = false;
597
+ this._actions = [];
598
+ this._isOrderActions = false;
599
+ }
600
+ async getActions() {
601
+ let param = {
602
+ param: {
603
+ entityName: this._entityName,
604
+ resourceID: this._resourceID
605
+ }
606
+ };
607
+ return DataFetcher.get().callServiceBroker('ActionButtonsSP.getActions', param).then((result) => {
608
+ var _a;
609
+ if (!((_a = result.actions) === null || _a === void 0 ? void 0 : _a.action))
610
+ return;
611
+ if (this._isOrderActions) {
612
+ this._actions = ArrayUtils.sortAlphabetically(result.actions.action, 'description');
613
+ }
614
+ else {
615
+ this._actions = result.actions.action;
616
+ }
617
+ });
618
+ }
619
+ controlDropdown() {
620
+ this._showDropdown = !this._showDropdown;
621
+ }
622
+ canShowDropdown() {
623
+ var _a;
624
+ return this._showDropdown && ((_a = this._items) === null || _a === void 0 ? void 0 : _a.length) > 0;
625
+ }
626
+ positionDropdown() {
627
+ var _a;
628
+ const bounding = (_a = this._ezButton) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
629
+ if (!bounding || !this._dropdownParent)
630
+ return;
631
+ this._dropdownParent.style.top = (bounding.y + bounding.height + 5) + "px";
632
+ this._dropdownParent.style.left = bounding.x + "px";
633
+ }
634
+ closeDropdown(evt) {
635
+ const target = evt === null || evt === void 0 ? void 0 : evt.target;
636
+ if (!target)
637
+ return;
638
+ if (!target.closest(".snk-actions-button")) {
639
+ this._showDropdown = false;
640
+ }
641
+ }
642
+ setEvents() {
643
+ document.removeEventListener("click", this.closeDropdown.bind(this));
644
+ document.addEventListener("click", this.closeDropdown.bind(this));
645
+ document.removeEventListener("scroll", this.positionDropdown.bind(this));
646
+ document.addEventListener("scroll", this.positionDropdown.bind(this));
647
+ }
648
+ async componentWillLoad() {
649
+ var _a;
650
+ this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
651
+ this._resourceID = await this._application.getResourceID();
652
+ this._isOrderActions = await this._application.getBooleanParam('global.ordenar.acoes.personalizadas');
653
+ this._dataUnit = (_a = this._element.parentElement) === null || _a === void 0 ? void 0 : _a.dataUnit;
654
+ this._entityName = this._dataUnit.name.split('/')[2];
655
+ this.setEvents();
656
+ this.getActions().then(() => {
657
+ this.loadItems();
658
+ });
659
+ }
660
+ async componentDidLoad() {
661
+ if (!this._element)
662
+ return;
663
+ ElementIDUtils.addIDInfo(this._element);
664
+ this.positionDropdown();
665
+ if (!(await this._application.hasClientEvent(this.CLIENT_EVENT_CONFIRM_NAME))) {
666
+ const clientEventConfirm = new ClientEventConfirm();
667
+ this._application.addClientEvent(this.CLIENT_EVENT_CONFIRM_NAME, clientEventConfirm.clientConfirm);
668
+ }
669
+ }
670
+ componentDidUpdate() {
671
+ this.positionDropdown();
672
+ }
673
+ loadItems() {
674
+ if (!this._actions || this._actions.length == 0)
675
+ return;
676
+ this._actions.forEach(action => {
677
+ this._items.push({ id: action.actionID, label: action.description });
678
+ });
679
+ }
680
+ getElementID(sufix) {
681
+ return {
682
+ [ElementIDUtils.DATA_ELEMENT_ID_ATTRIBUTE_NAME]: ElementIDUtils.getInternalIDInfo(sufix)
683
+ };
684
+ }
685
+ render() {
686
+ return (h(Host, null, (this._actions && this._actions.length > 0) &&
687
+ (h("div", { class: `ez-padding-left--medium snk-actions-button
688
+ ${this.canShowDropdown() ? " snk-actions-button--overlap" : ""}
689
+ ` }, h("ez-button", Object.assign({ ref: (ref) => this._ezButton = ref, iconName: "acao", size: "small", mode: "icon", title: this._application.messagesBuilder.getMessage("snkActionsButton.title.actions", undefined), onClick: () => this.controlDropdown() }, this.getElementID("button"))), h("div", Object.assign({ ref: (ref) => this._dropdownParent = ref, class: `${this.canShowDropdown() ?
690
+ "snk-actions-button__dropdown--show" :
691
+ "snk-actions-button__dropdown"}
692
+ ` }, this.getElementID("dropdown")), (this.canShowDropdown()) &&
693
+ (h("ez-dropdown", Object.assign({ items: this._items, onEzClick: (evt) => this.handleClick(evt) }, this.getElementID("dropdown"))))))), (this.canShowDropdown()) &&
694
+ (h("div", Object.assign({ class: "ez-scrim ez-scrim--light" }, this.getElementID("ezScrim"))))));
695
+ }
696
+ get _element() { return this; }
697
+ static get style() { return snkActionsButtonCss; }
698
+ }, [2, "snk-actions-button", {
699
+ "_items": [32],
700
+ "_showDropdown": [32],
701
+ "_actions": [32],
702
+ "_isOrderActions": [32]
703
+ }]);
704
+ function defineCustomElement() {
705
+ if (typeof customElements === "undefined") {
706
+ return;
707
+ }
708
+ const components = ["snk-actions-button"];
709
+ components.forEach(tagName => { switch (tagName) {
710
+ case "snk-actions-button":
711
+ if (!customElements.get(tagName)) {
712
+ customElements.define(tagName, SnkActionsButton);
713
+ }
714
+ break;
715
+ } });
716
+ }
717
+
718
+ export { SnkActionsButton as S, defineCustomElement as d };