@sankhyalabs/sankhyablocks 5.17.0 → 5.18.1

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 (140) 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-filter-binary-select.cjs.entry.js +1 -1
  16. package/dist/cjs/snk-grid.cjs.entry.js +4 -4
  17. package/dist/cjs/{snk-guides-viewer-0ab3746e.js → snk-guides-viewer-c8843478.js} +2 -2
  18. package/dist/cjs/snk-guides-viewer.cjs.entry.js +3 -3
  19. package/dist/cjs/snk-simple-bar_2.cjs.entry.js +2 -2
  20. package/dist/cjs/snk-taskbar.cjs.entry.js +1 -1
  21. package/dist/cjs/{taskbar-elements-bc2598f9.js → taskbar-elements-3be287d6.js} +3 -0
  22. package/dist/cjs/{taskbar-processor-e1e3bbf7.js → taskbar-processor-02f0fc84.js} +1 -1
  23. package/dist/collection/collection-manifest.json +3 -0
  24. package/dist/collection/components/snk-actions-button/actions/enum/ActionsType.js +8 -0
  25. package/dist/collection/components/snk-actions-button/actions/enum/ParamType.js +11 -0
  26. package/dist/collection/components/snk-actions-button/actions/enum/RefreshType.js +7 -0
  27. package/dist/collection/components/snk-actions-button/actions/executor/java.executor.js +22 -0
  28. package/dist/collection/components/snk-actions-button/actions/executor/javascript.executor.js +20 -0
  29. package/dist/collection/components/snk-actions-button/actions/executor/launch-screen.executor.js +42 -0
  30. package/dist/collection/components/snk-actions-button/actions/executor/procedure.executor.js +26 -0
  31. package/dist/collection/components/snk-actions-button/actions/factory/executor.factory.js +26 -0
  32. package/dist/collection/components/snk-actions-button/actions/index.js +343 -0
  33. package/dist/collection/components/snk-actions-button/actions/interfaces/IAction.js +7 -0
  34. package/dist/collection/components/snk-actions-button/actions/interfaces/IExecSource.js +1 -0
  35. package/dist/collection/components/snk-actions-button/actions/interfaces/IExecuteActions.js +1 -0
  36. package/dist/collection/components/snk-actions-button/actions/interfaces/IExecuteActionsProps.js +1 -0
  37. package/dist/collection/components/snk-actions-button/actions/interfaces/IResultParam.js +1 -0
  38. package/dist/collection/components/snk-actions-button/clientEvent/index.js +87 -0
  39. package/dist/collection/components/snk-actions-button/clientEvent/interfaces/IClientEventConfirm.js +1 -0
  40. package/dist/collection/components/snk-actions-button/snk-actions-button.css +38 -0
  41. package/dist/collection/components/snk-actions-button/snk-actions-button.js +139 -0
  42. package/dist/collection/components/snk-actions-button/subcomponents/snk-actions-form.js +263 -0
  43. package/dist/collection/components/snk-actions-button/subcomponents/snk-client-confirm.js +134 -0
  44. package/dist/collection/components/snk-filter-bar/filter-item/editors/snk-filter-binary-select.js +1 -1
  45. package/dist/collection/components/snk-grid/snk-grid.js +2 -2
  46. package/dist/collection/components/snk-taskbar/elements/taskbar-elements.js +3 -0
  47. package/dist/collection/lib/message/SnkMessageBuilder.js +3 -1
  48. package/dist/collection/lib/message/resources/snk-actions-button.msg.js +27 -0
  49. package/dist/components/ParamType.js +13 -0
  50. package/dist/components/SnkMessageBuilder.js +30 -1
  51. package/dist/components/index.d.ts +3 -0
  52. package/dist/components/index.js +3 -0
  53. package/dist/components/snk-actions-button.d.ts +11 -0
  54. package/dist/components/snk-actions-button.js +6 -0
  55. package/dist/components/snk-actions-button2.js +718 -0
  56. package/dist/components/snk-actions-form.d.ts +11 -0
  57. package/dist/components/snk-actions-form.js +218 -0
  58. package/dist/components/snk-attach2.js +7 -1
  59. package/dist/components/snk-client-confirm.d.ts +11 -0
  60. package/dist/components/snk-client-confirm.js +71 -0
  61. package/dist/components/snk-crud.js +7 -1
  62. package/dist/components/snk-detail-view2.js +13 -2
  63. package/dist/components/snk-filter-binary-select.js +1 -1
  64. package/dist/components/snk-grid2.js +9 -3
  65. package/dist/components/snk-simple-crud2.js +7 -1
  66. package/dist/components/snk-taskbar2.js +10 -1
  67. package/dist/esm/ParamType-d5152b06.js +13 -0
  68. package/dist/esm/{SnkMessageBuilder-1a169545.js → SnkMessageBuilder-188a38bb.js} +30 -1
  69. package/dist/esm/loader.js +1 -1
  70. package/dist/esm/sankhyablocks.js +1 -1
  71. package/dist/esm/snk-actions-button.entry.js +700 -0
  72. package/dist/esm/snk-actions-form.entry.js +196 -0
  73. package/dist/esm/snk-application.entry.js +1 -1
  74. package/dist/esm/snk-attach.entry.js +1 -1
  75. package/dist/esm/snk-client-confirm.entry.js +48 -0
  76. package/dist/esm/snk-crud.entry.js +1 -1
  77. package/dist/esm/snk-data-exporter.entry.js +2 -2
  78. package/dist/esm/{snk-data-unit-476024e9.js → snk-data-unit-79b1583a.js} +1 -1
  79. package/dist/esm/snk-data-unit.entry.js +2 -2
  80. package/dist/esm/snk-detail-view.entry.js +4 -4
  81. package/dist/esm/snk-filter-binary-select.entry.js +1 -1
  82. package/dist/esm/snk-grid.entry.js +4 -4
  83. package/dist/esm/{snk-guides-viewer-767f5a74.js → snk-guides-viewer-59d3a78c.js} +2 -2
  84. package/dist/esm/snk-guides-viewer.entry.js +3 -3
  85. package/dist/esm/snk-simple-bar_2.entry.js +2 -2
  86. package/dist/esm/snk-taskbar.entry.js +1 -1
  87. package/dist/esm/{taskbar-elements-e6af3e93.js → taskbar-elements-8ff33c26.js} +3 -0
  88. package/dist/esm/{taskbar-processor-a40798b8.js → taskbar-processor-20de6616.js} +1 -1
  89. package/dist/sankhyablocks/{p-3e17b147.js → p-0b40c655.js} +1 -1
  90. package/dist/sankhyablocks/{p-de9caf1e.entry.js → p-0b6ddb67.entry.js} +1 -1
  91. package/dist/sankhyablocks/p-19692f92.js +1 -0
  92. package/dist/sankhyablocks/{p-6df8c88b.entry.js → p-257c71a7.entry.js} +1 -1
  93. package/dist/sankhyablocks/{p-551165d8.js → p-28c12f65.js} +1 -1
  94. package/dist/sankhyablocks/{p-78de64fb.entry.js → p-2d0fc912.entry.js} +1 -1
  95. package/dist/sankhyablocks/p-384c4a6b.js +1 -0
  96. package/dist/sankhyablocks/{p-f43629f3.entry.js → p-44c2ed16.entry.js} +1 -1
  97. package/dist/sankhyablocks/{p-ec1c64be.entry.js → p-8ce9ea9f.entry.js} +1 -1
  98. package/dist/sankhyablocks/{p-e0c04667.entry.js → p-9c7f7214.entry.js} +1 -1
  99. package/dist/sankhyablocks/p-9f66bc54.entry.js +1 -0
  100. package/dist/sankhyablocks/{p-c74fca58.js → p-b34d23fa.js} +1 -1
  101. package/dist/sankhyablocks/p-b680fa7a.entry.js +1 -0
  102. package/dist/sankhyablocks/p-b75ce8b8.entry.js +1 -0
  103. package/dist/sankhyablocks/{p-9e92ed74.entry.js → p-cbe93a18.entry.js} +2 -2
  104. package/dist/sankhyablocks/p-eaad0aa8.js +1 -0
  105. package/dist/sankhyablocks/{p-7956b9dd.entry.js → p-eb07d0eb.entry.js} +1 -1
  106. package/dist/sankhyablocks/p-f27dc5e9.entry.js +1 -0
  107. package/dist/sankhyablocks/p-fa2d0376.entry.js +1 -0
  108. package/dist/sankhyablocks/p-ff398057.entry.js +1 -0
  109. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  110. package/dist/types/components/snk-actions-button/actions/enum/ActionsType.d.ts +7 -0
  111. package/dist/types/components/snk-actions-button/actions/enum/ParamType.d.ts +10 -0
  112. package/dist/types/components/snk-actions-button/actions/enum/RefreshType.d.ts +6 -0
  113. package/dist/types/components/snk-actions-button/actions/executor/java.executor.d.ts +6 -0
  114. package/dist/types/components/snk-actions-button/actions/executor/javascript.executor.d.ts +6 -0
  115. package/dist/types/components/snk-actions-button/actions/executor/launch-screen.executor.d.ts +10 -0
  116. package/dist/types/components/snk-actions-button/actions/executor/procedure.executor.d.ts +6 -0
  117. package/dist/types/components/snk-actions-button/actions/factory/executor.factory.d.ts +7 -0
  118. package/dist/types/components/snk-actions-button/actions/index.d.ts +27 -0
  119. package/dist/types/components/snk-actions-button/actions/interfaces/IAction.d.ts +55 -0
  120. package/dist/types/components/snk-actions-button/actions/interfaces/IExecSource.d.ts +17 -0
  121. package/dist/types/components/snk-actions-button/actions/interfaces/IExecuteActions.d.ts +4 -0
  122. package/dist/types/components/snk-actions-button/actions/interfaces/IExecuteActionsProps.d.ts +4 -0
  123. package/dist/types/components/snk-actions-button/actions/interfaces/IResultParam.d.ts +14 -0
  124. package/dist/types/components/snk-actions-button/clientEvent/index.d.ts +4 -0
  125. package/dist/types/components/snk-actions-button/clientEvent/interfaces/IClientEventConfirm.d.ts +35 -0
  126. package/dist/types/components/snk-actions-button/snk-actions-button.d.ts +27 -0
  127. package/dist/types/components/snk-actions-button/subcomponents/snk-actions-form.d.ts +41 -0
  128. package/dist/types/components/snk-actions-button/subcomponents/snk-client-confirm.d.ts +31 -0
  129. package/dist/types/components/snk-taskbar/elements/taskbar-elements.d.ts +2 -1
  130. package/dist/types/components.d.ts +96 -0
  131. package/dist/types/lib/message/resources/snk-actions-button.msg.d.ts +1 -0
  132. package/package.json +1 -1
  133. package/react/components.d.ts +3 -0
  134. package/react/components.js +3 -0
  135. package/react/components.js.map +1 -1
  136. package/dist/sankhyablocks/p-1c5d5e5c.entry.js +0 -1
  137. package/dist/sankhyablocks/p-39082fc3.js +0 -1
  138. package/dist/sankhyablocks/p-8d40909d.entry.js +0 -1
  139. package/dist/sankhyablocks/p-9cbc3925.entry.js +0 -1
  140. package/dist/sankhyablocks/p-d410f45a.js +0 -1
@@ -0,0 +1,700 @@
1
+ import { r as registerInstance, h, H as Host, g as getElement } from './index-cfd4bb13.js';
2
+ import { ApplicationContext, StringUtils, ErrorException, WarningException, ObjectUtils, DateUtils, ArrayUtils, ElementIDUtils } from '@sankhyalabs/core';
3
+ import { D as DataFetcher } from './DataFetcher-b3d8b2d5.js';
4
+ import { P as ParamType } from './ParamType-d5152b06.js';
5
+ import './pesquisa-fetcher-bd6af0e3.js';
6
+ import './index-507e19ec.js';
7
+ import './_commonjsHelpers-9943807e.js';
8
+
9
+ const SERVICE_ACTION_EXECUTE_JAVA = 'ActionButtonsSP.executeJava';
10
+ class JavaExecutor {
11
+ execute(action) {
12
+ var _a;
13
+ const execSource = {
14
+ actionID: action.actionID,
15
+ refreshType: (_a = action.actionConfig.javaCall) === null || _a === void 0 ? void 0 : _a.refreshType
16
+ };
17
+ return new Promise((resolve) => {
18
+ resolve({ execSource, callback: this.callExecJava });
19
+ });
20
+ }
21
+ callExecJava(execSource) {
22
+ const request = {
23
+ requestBody: {
24
+ javaCall: execSource
25
+ }
26
+ };
27
+ DataFetcher.get().callServiceBroker(SERVICE_ACTION_EXECUTE_JAVA, JSON.stringify(request));
28
+ }
29
+ }
30
+
31
+ const SERVICE_ACTION_EXECUTE_SCRIPT = 'ActionButtonsSP.executeScript';
32
+ class JavascriptExecutor {
33
+ execute(action) {
34
+ var _a;
35
+ const execSource = {
36
+ actionID: action.actionID,
37
+ refreshType: (_a = action.actionConfig.runScript) === null || _a === void 0 ? void 0 : _a.refreshType
38
+ };
39
+ return new Promise((resolve) => {
40
+ resolve({ execSource, callback: this.callExecScript });
41
+ });
42
+ }
43
+ callExecScript(execSource) {
44
+ const request = {
45
+ runScript: execSource
46
+ };
47
+ DataFetcher.get().callServiceBroker(SERVICE_ACTION_EXECUTE_SCRIPT, request);
48
+ }
49
+ }
50
+
51
+ class LaunchScreenExecutor {
52
+ constructor() {
53
+ this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
54
+ }
55
+ async execute(action, dataUnit) {
56
+ const resourceID = action.resourceID;
57
+ if (!resourceID)
58
+ return;
59
+ let launchObject = await this.buildLaunchObject(action, dataUnit);
60
+ this._application.openApp(resourceID, launchObject);
61
+ return null;
62
+ }
63
+ buildLaunchObject(action, dataUnit) {
64
+ return new Promise((resolve) => {
65
+ let params = action.actionConfig.params.param;
66
+ if (params && params.length > 0) {
67
+ let launchObject = {};
68
+ let processedParams = [];
69
+ params.forEach(param => {
70
+ const localField = param.localField;
71
+ let value = dataUnit.getFieldValue(localField);
72
+ if (!value) {
73
+ let localFieldLabel = dataUnit.getField(localField).label;
74
+ localFieldLabel = StringUtils.isEmpty(dataUnit.getField(localField).label) ? localField : localFieldLabel;
75
+ throw new ErrorException(this._application.messagesBuilder.getMessage("snkActionsButton.title.error", undefined), this._application.messagesBuilder.getMessage("snkActionsButton.launchScreen.emptyField", { description: action.description, localFieldLabel: localFieldLabel }));
76
+ }
77
+ value = StringUtils.isEmpty(value.toString()) ? undefined : value.toString();
78
+ launchObject[param.targetField] = value;
79
+ processedParams.push({
80
+ fieldName: param.targetField,
81
+ value: value
82
+ });
83
+ });
84
+ launchObject.ACTION_PARAMETERS = processedParams;
85
+ launchObject.call_time = Date.now();
86
+ resolve(launchObject);
87
+ }
88
+ resolve(null);
89
+ });
90
+ }
91
+ }
92
+
93
+ const SERVICE_ACTION_EXECUTE_STP = 'ActionButtonsSP.executeSTP';
94
+ class ProcedureExecutor {
95
+ execute(action) {
96
+ var _a, _b, _c;
97
+ const procName = (_a = action.actionConfig.dbCall) === null || _a === void 0 ? void 0 : _a.name;
98
+ const rootEntity = (_b = action.actionConfig.dbCall) === null || _b === void 0 ? void 0 : _b.rootEntity;
99
+ const execSource = {
100
+ actionID: action.actionID,
101
+ refreshType: (_c = action.actionConfig.dbCall) === null || _c === void 0 ? void 0 : _c.refreshType,
102
+ procName: procName,
103
+ rootEntity: rootEntity
104
+ };
105
+ return new Promise((resolve) => {
106
+ resolve({ execSource, callback: this.callExecProcedure });
107
+ });
108
+ }
109
+ callExecProcedure(execSource) {
110
+ const request = {
111
+ requestBody: {
112
+ stpCall: execSource
113
+ }
114
+ };
115
+ DataFetcher.get().callServiceBroker(SERVICE_ACTION_EXECUTE_STP, JSON.stringify(request));
116
+ }
117
+ }
118
+
119
+ var ActionsType;
120
+ (function (ActionsType) {
121
+ ActionsType["LAUNCH_SCREEN"] = "LC";
122
+ ActionsType["JAVASCRIPT"] = "SC";
123
+ ActionsType["JAVA"] = "RJ";
124
+ ActionsType["PROCEDURE"] = "SP";
125
+ ActionsType["EMBEDDED"] = "EB";
126
+ })(ActionsType || (ActionsType = {}));
127
+
128
+ class ExecutorFactory {
129
+ constructor(actionType) {
130
+ this.actionType = actionType;
131
+ this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
132
+ }
133
+ get executor() {
134
+ switch (this.actionType) {
135
+ case ActionsType.LAUNCH_SCREEN:
136
+ return new LaunchScreenExecutor();
137
+ case ActionsType.JAVASCRIPT:
138
+ return new JavascriptExecutor();
139
+ case ActionsType.JAVA:
140
+ return new JavaExecutor();
141
+ case ActionsType.PROCEDURE:
142
+ return new ProcedureExecutor();
143
+ default:
144
+ throw new ErrorException(this._application.messagesBuilder.getMessage("snkActionsButton.title.error", undefined), this._application.messagesBuilder.getMessage("snkActionsButton.action.nonExistentType", { actionType: this.actionType }));
145
+ }
146
+ }
147
+ }
148
+
149
+ var RefreshType;
150
+ (function (RefreshType) {
151
+ RefreshType["NONE"] = "NONE";
152
+ RefreshType["PARENT"] = "PARENT";
153
+ RefreshType["MASTER"] = "MASTER";
154
+ RefreshType["ALL"] = "ALL";
155
+ })(RefreshType || (RefreshType = {}));
156
+
157
+ const MASTER_ROW_PROPERTY = "__MASTER_ROW__";
158
+ const ENTITY_NAME_PROPERTY = '__ENTITY_NAME__';
159
+ const NUFIN_COLUMN = 'NUFIN';
160
+ const SERVICE_GET_CONFIGURATIONS = 'SystemUtilsSP.getConf';
161
+ class Actions {
162
+ constructor(actionsExecuteInterface, dataUnit) {
163
+ var _a;
164
+ this._lastValuesCache = {};
165
+ this._actionsExecuteInterface = actionsExecuteInterface;
166
+ this._dataUnit = dataUnit;
167
+ 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;
168
+ this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
169
+ }
170
+ apply(action, hasParamsToSave) {
171
+ this._application.closePopUp();
172
+ this._actionsExecuteInterface.execute(action, this._dataUnit)
173
+ .then(({ execSource, callback }) => {
174
+ this.resolvePromptParams(action, execSource, hasParamsToSave)
175
+ .then(() => {
176
+ this.actionExecute(execSource, callback);
177
+ });
178
+ });
179
+ }
180
+ ;
181
+ async execute(action) {
182
+ var _a;
183
+ if (!action.actionConfig) {
184
+ throw new WarningException(this._application.messagesBuilder.getMessage("snkActionsButton.title.warning", undefined), this._application.messagesBuilder.getMessage("snkActionsButton.action.incorrectAction", { description: action.description }));
185
+ }
186
+ if (!!((_a = action.actionConfig.params) === null || _a === void 0 ? void 0 : _a.promptParam)) {
187
+ const paramsSource = action.actionConfig.params.promptParam;
188
+ let hasParamsToSave = false;
189
+ for (let i = 0; i < paramsSource.length; i++) {
190
+ let paramSource = paramsSource[i];
191
+ if (!hasParamsToSave && paramSource.saveLast === 'true') {
192
+ hasParamsToSave = true;
193
+ break;
194
+ }
195
+ }
196
+ if (hasParamsToSave) {
197
+ action.actionConfig.params.promptParam = await this.loadSavedValuesIntoParams(action);
198
+ }
199
+ const form = document.createElement("snk-actions-form");
200
+ window.document.body.appendChild(form);
201
+ form.action = ObjectUtils.copy(action);
202
+ form.applyParameters = (resultAction) => {
203
+ this.apply(resultAction, hasParamsToSave);
204
+ };
205
+ form.openPopup();
206
+ }
207
+ else if (action.type != ActionsType.LAUNCH_SCREEN) {
208
+ this._actionsExecuteInterface.execute(action, this._dataUnit)
209
+ .then(({ execSource, callback }) => {
210
+ this.actionExecute(execSource, callback);
211
+ });
212
+ }
213
+ else {
214
+ this._actionsExecuteInterface.execute(action, this._dataUnit);
215
+ }
216
+ }
217
+ loadSavedValuesIntoParams(action) {
218
+ return this.loadLastValues(action)
219
+ .then((lastParams) => {
220
+ let resultParams = action.actionConfig.params.promptParam;
221
+ if (lastParams) {
222
+ lastParams.param.forEach(lastParam => {
223
+ resultParams = resultParams.map((param) => {
224
+ if (param.name !== lastParam.paramName)
225
+ return param;
226
+ if (param.paramType === 'B') {
227
+ return Object.assign(Object.assign({}, param), { value: lastParam.$ === 'S' });
228
+ }
229
+ return Object.assign(Object.assign({}, param), { value: lastParam.$ });
230
+ });
231
+ });
232
+ }
233
+ return resultParams;
234
+ });
235
+ }
236
+ actionExecute(execSource, callback) {
237
+ execSource.virtualPage = this.buildVirtualPage();
238
+ this.prepareAndExecute(execSource, callback);
239
+ this.recordsReloader(execSource.refreshType);
240
+ }
241
+ resolvePromptParams(action, execSource, hasParamsToSave) {
242
+ return new Promise(resolve => {
243
+ const paramsSource = action.actionConfig.params.promptParam;
244
+ let params = [];
245
+ paramsSource.forEach(paramSource => {
246
+ params.push(this.buildPromptParam(paramSource));
247
+ });
248
+ this.putParamsOnExecSource(params, execSource);
249
+ if (hasParamsToSave) {
250
+ this.saveLastValues(action, params);
251
+ }
252
+ resolve();
253
+ });
254
+ }
255
+ buildPromptParam(param) {
256
+ let type = param.paramType;
257
+ let isCheckbox = false;
258
+ let fieldProps;
259
+ let entityPK;
260
+ let value = param.value;
261
+ switch (type) {
262
+ case ParamType.DATE:
263
+ type = 'D';
264
+ break;
265
+ case ParamType.DATETIME:
266
+ type = 'H';
267
+ break;
268
+ case ParamType.DECIMAL:
269
+ type = 'F';
270
+ fieldProps = {
271
+ 'sk-precision': Number(param.precision)
272
+ };
273
+ break;
274
+ case ParamType.BOOLEAN:
275
+ type = 'S';
276
+ isCheckbox = true;
277
+ value = param.value ? 'S' : 'N';
278
+ break;
279
+ case ParamType.ENTITY:
280
+ fieldProps = {
281
+ 'sk-entity-name': param.entityName,
282
+ 'sk-allow-show-hierarchical-mode': param.hierarchyEntity,
283
+ 'sk-data-type': 'S'
284
+ };
285
+ if (param.hierarchyEntity && param.entityPK) {
286
+ entityPK = param.entityPK;
287
+ }
288
+ value = param.value ? Number(param.value) : null;
289
+ break;
290
+ case ParamType.OPTIONS:
291
+ type = 'O';
292
+ let options = param.options.split(';').map(function (opc, index) {
293
+ let data;
294
+ let value;
295
+ if (opc.indexOf('=') > -1) {
296
+ let opcArr = opc.split('=');
297
+ data = opcArr[0];
298
+ value = opcArr[1];
299
+ }
300
+ else {
301
+ data = (index + 1);
302
+ value = opc;
303
+ }
304
+ return {
305
+ data: data,
306
+ value: value
307
+ };
308
+ });
309
+ fieldProps = {
310
+ 'sk-options': options
311
+ };
312
+ break;
313
+ }
314
+ return {
315
+ description: param.label,
316
+ required: param.required == 'true',
317
+ fieldName: param.name,
318
+ fieldNameOri: param.name,
319
+ entityPK: entityPK,
320
+ paramType: param.paramType,
321
+ type: type,
322
+ isCheckbox: isCheckbox,
323
+ saveLast: param.saveLast,
324
+ fieldProp: fieldProps,
325
+ value: value,
326
+ isGeneratedName: param.isGeneratedName
327
+ };
328
+ }
329
+ putParamsOnExecSource(params, execSource) {
330
+ execSource.params = {
331
+ param: []
332
+ };
333
+ params.forEach(param => {
334
+ if (param.isGeneratedName && param.value) {
335
+ throw new ErrorException(this._application.messagesBuilder.getMessage("snkActionsButton.title.error", undefined), this._application.messagesBuilder.getMessage("snkActionsButton.action.emptyParamName", undefined));
336
+ }
337
+ if (!StringUtils.isEmpty(param.value)) {
338
+ execSource.params.param.push({
339
+ type: this.getParamDataType(param.paramType),
340
+ paramName: param.fieldName,
341
+ $: this.getParamValue(param)
342
+ });
343
+ }
344
+ });
345
+ }
346
+ getParamDataType(type) {
347
+ let dataType;
348
+ switch (type) {
349
+ case "D":
350
+ dataType = "F";
351
+ break;
352
+ case "DT":
353
+ case "DH":
354
+ dataType = "D";
355
+ break;
356
+ case "B":
357
+ case "ENTITY":
358
+ case "SO":
359
+ dataType = "S";
360
+ break;
361
+ default:
362
+ dataType = type;
363
+ }
364
+ return dataType;
365
+ }
366
+ getParamValue(param) {
367
+ let value = param.value;
368
+ if (!value) {
369
+ return value;
370
+ }
371
+ if (param.paramType == 'DT') {
372
+ value = DateUtils.formatDate(value);
373
+ }
374
+ else if (param.paramType == 'DH') {
375
+ value = DateUtils.formatDateTime(value);
376
+ }
377
+ return value;
378
+ }
379
+ async loadLastValues(action) {
380
+ const resourceId = await this.buildResourceId(action.actionID);
381
+ return new Promise((resolve, reject) => {
382
+ if (this._lastValuesCache[resourceId]) {
383
+ resolve(this._lastValuesCache[resourceId]);
384
+ }
385
+ else {
386
+ const config = {
387
+ config: {
388
+ chave: resourceId,
389
+ tipo: 'T'
390
+ }
391
+ };
392
+ DataFetcher.get().callServiceBroker(SERVICE_GET_CONFIGURATIONS, config)
393
+ .then((result) => {
394
+ var _a, _b;
395
+ let lastParams;
396
+ if ((_b = (_a = result.config) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.params) {
397
+ lastParams = result.config.data.params;
398
+ if (!Array.isArray(lastParams.param)) {
399
+ lastParams.param = [lastParams.param];
400
+ }
401
+ }
402
+ this._lastValuesCache[resourceId] = lastParams;
403
+ resolve(lastParams);
404
+ }).catch((error) => {
405
+ reject(error);
406
+ });
407
+ }
408
+ });
409
+ }
410
+ async saveLastValues(action, params) {
411
+ if (this._application) {
412
+ let config = {
413
+ params: {
414
+ param: []
415
+ }
416
+ };
417
+ params.forEach(param => {
418
+ if (param.saveLast == 'true') {
419
+ config.params.param.push({
420
+ paramName: param.fieldName,
421
+ $: param.value
422
+ });
423
+ }
424
+ });
425
+ const resourceId = await this.buildResourceId(action.actionID);
426
+ this._lastValuesCache[resourceId] = config.params;
427
+ this._application.saveConfig(resourceId, config);
428
+ }
429
+ }
430
+ async buildResourceId(actionId) {
431
+ let appResId = '';
432
+ appResId = await this._application.getResourceID();
433
+ return appResId + '.actionconfig.' + actionId;
434
+ }
435
+ prepareAndExecute(execSource, executeAction) {
436
+ this.addRows(execSource);
437
+ executeAction(execSource);
438
+ }
439
+ addRows(execSource) {
440
+ const rows = {
441
+ row: []
442
+ };
443
+ const sourceRows = this._selectedRows;
444
+ for (const i in sourceRows) {
445
+ const sourceRow = sourceRows[i];
446
+ const row = {};
447
+ if (sourceRow.hasOwnProperty(MASTER_ROW_PROPERTY)) {
448
+ row.master = 'S';
449
+ row.entityName = sourceRow.__ENTITY_NAME__;
450
+ delete sourceRow[MASTER_ROW_PROPERTY];
451
+ delete sourceRow[ENTITY_NAME_PROPERTY];
452
+ }
453
+ for (const fieldName in sourceRow) {
454
+ if (fieldName !== NUFIN_COLUMN)
455
+ continue;
456
+ if (!row.field) {
457
+ row.field = [];
458
+ }
459
+ row.field.push({
460
+ fieldName: fieldName,
461
+ $: sourceRow[fieldName]
462
+ });
463
+ }
464
+ rows.row.push(row);
465
+ }
466
+ if (rows.row.length > 0) {
467
+ execSource.rows = rows;
468
+ }
469
+ }
470
+ recordsReloader(refreshType) {
471
+ switch (refreshType) {
472
+ case RefreshType.NONE:
473
+ break;
474
+ case RefreshType.PARENT:
475
+ case RefreshType.MASTER:
476
+ case RefreshType.ALL:
477
+ this._dataUnit.loadData();
478
+ break;
479
+ default:
480
+ this._dataUnit.reloadCurrentRecord();
481
+ }
482
+ }
483
+ ;
484
+ buildVirtualPage() {
485
+ var _a, _b, _c, _d;
486
+ if ((_b = (_a = this._dataUnit) === null || _a === void 0 ? void 0 : _a.getSelectionInfo()) === null || _b === void 0 ? void 0 : _b.isAllRecords()) {
487
+ const virtualPage = {
488
+ filters: { filters: (_c = this._dataUnit) === null || _c === void 0 ? void 0 : _c.getAppliedFilters() },
489
+ orders: { orders: (_d = this._dataUnit) === null || _d === void 0 ? void 0 : _d.getSort() },
490
+ };
491
+ return virtualPage;
492
+ }
493
+ }
494
+ }
495
+
496
+ const CONFIRMACAO = "__CONFIRMACAO__";
497
+ const ESCOLHA_SIM_NAO = "__ESCOLHA_SIMNAO__";
498
+ class ClientEventConfirm {
499
+ clientConfirm(clientEvent, recaller) {
500
+ const application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
501
+ let actionType = "";
502
+ if (clientEvent.content.event.hasOwnProperty('stpCall')) {
503
+ recaller.requestBody = clientEvent.content.event.stpCall;
504
+ actionType = ActionsType.PROCEDURE;
505
+ }
506
+ else if (clientEvent.content.event.hasOwnProperty('runScript')) {
507
+ recaller.requestBody = clientEvent.content.event.runScript;
508
+ actionType = ActionsType.JAVASCRIPT;
509
+ }
510
+ else if (clientEvent.content.event.hasOwnProperty('javaCall')) {
511
+ recaller.requestBody = clientEvent.content.event.javaCall;
512
+ actionType = ActionsType.JAVA;
513
+ }
514
+ let param = {
515
+ type: 'S',
516
+ sequence: clientEvent.content.event.sequence
517
+ };
518
+ if (!recaller.requestBody.params) {
519
+ recaller.requestBody.params = {
520
+ param: []
521
+ };
522
+ }
523
+ else {
524
+ if (!Array.isArray(recaller.requestBody.params.param)) {
525
+ recaller.requestBody.params.param = [recaller.requestBody.params.param];
526
+ }
527
+ }
528
+ recaller.requestBody.params.param.push(param);
529
+ const title = clientEvent.content.event.title.$;
530
+ const message = clientEvent.content.event.message.$;
531
+ let requestBody;
532
+ switch (actionType) {
533
+ case ActionsType.JAVASCRIPT:
534
+ requestBody = { runScript: recaller.requestBody };
535
+ break;
536
+ case ActionsType.PROCEDURE:
537
+ requestBody = {
538
+ requestBody: {
539
+ stpCall: recaller.requestBody
540
+ }
541
+ };
542
+ break;
543
+ case ActionsType.JAVA:
544
+ requestBody = {
545
+ requestBody: {
546
+ javaCall: recaller.requestBody
547
+ }
548
+ };
549
+ break;
550
+ }
551
+ if (clientEvent.content.event.showNoOption == 'S') {
552
+ param.paramName = ESCOLHA_SIM_NAO;
553
+ const form = document.createElement("snk-client-confirm");
554
+ window.document.body.appendChild(form);
555
+ form.titleMessage = title;
556
+ form.message = message;
557
+ form.accept = () => {
558
+ param.$ = 'S';
559
+ recaller.reCall(requestBody);
560
+ };
561
+ form.cancel = () => {
562
+ param.$ = 'N';
563
+ recaller.reCall(requestBody);
564
+ };
565
+ form.openPopup();
566
+ }
567
+ else {
568
+ application.confirm(title, message, null, 'warn', {
569
+ labelCancel: "Cancelar",
570
+ labelConfirm: "Sim"
571
+ }).then((confirmResult) => {
572
+ if (confirmResult) {
573
+ param.paramName = CONFIRMACAO;
574
+ param.$ = 'S';
575
+ recaller.reCall(requestBody);
576
+ }
577
+ });
578
+ }
579
+ }
580
+ }
581
+
582
+ 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}";
583
+
584
+ const SnkActionsButton = class {
585
+ constructor(hostRef) {
586
+ registerInstance(this, hostRef);
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 getElement(this); }
697
+ };
698
+ SnkActionsButton.style = snkActionsButtonCss;
699
+
700
+ export { SnkActionsButton as snk_actions_button };