@datarailsshared/dr_renderer 1.2.111-dev → 1.2.113

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.
@@ -1,387 +1,387 @@
1
- let getPublishedItemsRenderer = function (publishedItemsRenderer) {
2
-
3
- this.document = {};
4
- this.scope = {};
5
- this.options = {};
6
- this.isScenarioMode = null;
7
-
8
- publishedItemsRenderer.formulaCellClicked = function (event, scope, options, window) {
9
- event.stopPropagation();
10
- event.preventDefault();
11
- try {
12
- const td = event.currentTarget;
13
- const a = td.querySelector('a');
14
- const locationId = a.getAttribute('location_id');
15
- scope.callFromPublishItem(event, options.widgetId, options.dashboardId, locationId, window.published_item_sheetname);
16
- } catch (e) {
17
- }
18
- return false;
19
- }
20
-
21
- publishedItemsRenderer.resizeTable = function (options, iframeWindow) {
22
- options.alreadySetTimeout = null;
23
- const publish_item_image = iframeWindow.document.getElementById('publish_item_image');
24
- const table = iframeWindow.document.getElementsByTagName("table")[0];
25
- const body = iframeWindow.document.getElementsByTagName("body")[0];
26
-
27
- if (table && options.responsive) {
28
- publishedItemsRenderer.zoomTable(iframeWindow, table, body);
29
- }
30
-
31
- publishedItemsRenderer.resizePublishedImage(publish_item_image, iframeWindow, body);
32
- }
33
-
34
- publishedItemsRenderer.zoomTable = function(iframeWindow, table, body) {
35
- let body_zoom = body.style.zoom;
36
- body_zoom = parseFloat(body_zoom) || 1;
37
-
38
- let zoom = table.style.zoom;
39
- zoom = parseFloat(zoom) || 1;
40
-
41
- const positionInfo = table.getBoundingClientRect();
42
- let width = Math.ceil((positionInfo.width + iframeWindow.innerWidth - iframeWindow.document.body.offsetWidth) * zoom * body_zoom);
43
-
44
- if (width < iframeWindow.innerWidth) {
45
- zoom += 0.05;
46
-
47
- width = Math.ceil((positionInfo.width + iframeWindow.innerWidth - iframeWindow.document.body.offsetWidth) * zoom * body_zoom);
48
- if (width < iframeWindow.innerWidth) {
49
- table.style.zoom = zoom;
50
- setTimeout(function () {
51
- publishedItemsRenderer.zoomTable(iframeWindow, table, body);
52
- }, 10);
53
- }
54
- } else if (width >= iframeWindow.innerWidth) {
55
- zoom -= 0.05;
56
-
57
- width = Math.ceil((positionInfo.width + iframeWindow.innerWidth - iframeWindow.document.body.offsetWidth) * zoom * body_zoom);
58
- table.style.zoom = zoom;
59
- if (width >= iframeWindow.innerWidth) {
60
- setTimeout(function () {
61
- publishedItemsRenderer.zoomTable(iframeWindow, table, body);
62
- }, 10);
63
- }
64
- }
65
- }
66
-
67
- publishedItemsRenderer.resizePublishedImage = function(publish_item_image, iframeWindow, body) {
68
- if (!publish_item_image) return;
69
-
70
- let body_zoom = body.style.zoom;
71
- body_zoom = parseFloat(body_zoom) || 1;
72
-
73
- if (publish_item_image.style.height === '100%') {
74
- publish_item_image.style.height = 'auto';
75
- publish_item_image.style.width = '100%';
76
- publish_item_image.style.marginTop = "";
77
- setTimeout(function () {
78
- publishedItemsRenderer.resizePublishedImage(publish_item_image, iframeWindow, body);
79
- }, 10);
80
- }
81
-
82
- const imgPositionInfo = publish_item_image.getBoundingClientRect();
83
- const height = (imgPositionInfo.height + imgPositionInfo.y * 2) * body_zoom;
84
- if (height > iframeWindow.innerHeight) {
85
- publish_item_image.style.height = '100%';
86
- publish_item_image.style.width = 'auto';
87
- } else if (height < iframeWindow.innerHeight) {
88
- const temp = (iframeWindow.innerHeight - height) / 2;
89
- publish_item_image.style.marginTop = (temp / body_zoom + imgPositionInfo.y) + "px";
90
- }
91
- }
92
-
93
- publishedItemsRenderer.resetTableZoom = function (document) {
94
- const table = document.getElementsByTagName("table")[0];
95
- if (table) {
96
- table.style.zoom = 1;
97
- }
98
- }
99
-
100
- publishedItemsRenderer.changedAutoResize = function (options, iframeWindow, document) {
101
- Object.assign(iframeWindow.__options__, options);
102
- const table = document.getElementsByTagName("table")[0];
103
- if (table) {
104
- table.style.margin = options.responsive ? '0 auto' : '';
105
- }
106
-
107
- if (!options.responsive) {
108
- publishedItemsRenderer.resetTableZoom(document);
109
- } else {
110
- if (!options.alreadySetTimeout) {
111
- options.alreadySetTimeout = setTimeout(function () {
112
- publishedItemsRenderer.resizeTable(options, iframeWindow);
113
- }, 100);
114
- }
115
- }
116
- }
117
-
118
- publishedItemsRenderer.changedInputValue = function (firstTime, scope, options) {
119
- const input_values = [];
120
- if (options.inputValuesData) {
121
- for (let key in options.inputValuesData) {
122
- input_values.push(options.inputValuesData[key]);
123
- }
124
- }
125
-
126
- try {
127
- scope.changedInputValues(input_values, options.widgetId, options.dashboardId, firstTime);
128
- } catch (e) {
129
- console.error(e);
130
- }
131
- }
132
-
133
- publishedItemsRenderer.changedInputElement = function (event, scope, options) {
134
- const inputElement = event.currentTarget;
135
- const name = inputElement.getAttribute('name');
136
- const metaData = options.inputValuesData ? options.inputValuesData[name] : null;
137
- let newValue = inputElement.value;
138
- if (metaData) {
139
- if (metaData.type === 'editInput') {
140
- newValue = parseFloat(newValue);
141
- } else if (metaData.type === 'editInputPercent') {
142
- newValue = parseFloat(newValue) + '%';
143
- }
144
-
145
- if (metaData.value !== newValue) {
146
- metaData.value = newValue;
147
- publishedItemsRenderer.changedInputValue(false, scope, options);
148
- }
149
- }
150
- }
151
-
152
- publishedItemsRenderer.createInputElement = function (tdElement, inputMetaData, formatValue, scope, options, document) {
153
- const _this = this;
154
- tdElement.innerHTML = '';
155
- if (inputMetaData) {
156
- switch (inputMetaData.type) {
157
- case "editInput":
158
- case "editInputPercent":
159
- let inEl = document.createElement("INPUT");
160
- let labelEl = document.createElement("LABEL");
161
-
162
- if (inputMetaData.value === 'DR_INPUT') {
163
- labelEl.innerText = null;
164
- } else {
165
- labelEl.innerText = inputMetaData.format ? formatValue('n', inputMetaData.format, inputMetaData.value).value : inputMetaData.value;
166
- }
167
- if (_this.isScenarioMode) {
168
- labelEl.setAttribute("style", "background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;width: calc(100% - 15px);margin: 6px;text-align: inherit;display: block; cursor: pointer;");
169
- } else {
170
- labelEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 6px;text-align: inherit;display: block; cursor: pointer;");
171
- }
172
- const onLabelClick = function (event, isScenarioMode) {
173
- event.stopPropagation();
174
- if (isScenarioMode) {
175
- inEl.setAttribute("style", "background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: block;");
176
- } else {
177
- inEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: block;");
178
- }
179
- labelEl.style.display = 'none';
180
- setTimeout(function () {
181
- inEl.focus();
182
- }, 1)
183
- }
184
- labelEl.addEventListener("click", (event) => onLabelClick(event, _this.isScenarioMode));
185
-
186
- inEl.setAttribute("type", "number");
187
- inEl.setAttribute("name", inputMetaData.name);
188
- if (_this.isScenarioMode) {
189
- inEl.setAttribute("style", "background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: none;");
190
- } else {
191
- inEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: none;");
192
- }
193
- inEl.value = inputMetaData.type === 'editInputPercent' ? parseFloat(inputMetaData.value.replace('%', '')) : inputMetaData.value;
194
- inEl.addEventListener("focusout", function (event) {
195
- event.preventDefault();
196
- publishedItemsRenderer.changedInputElement(event, scope, options);
197
- inEl.style.display = 'none';
198
- labelEl.innerText = inputMetaData.format ? formatValue('n', inputMetaData.format, inEl.value).value : inputMetaData.value;
199
- labelEl.style.display = 'block';
200
- });
201
- inEl.addEventListener("keyup", function (event) {
202
- // Number 13 is the "Enter" key on the keyboard
203
- if (event.keyCode === 13) {
204
- // Cancel the default action, if needed
205
- event.preventDefault();
206
- publishedItemsRenderer.changedInputElement(event, scope, options);
207
- inEl.style.display = 'none';
208
- labelEl.innerText = inputMetaData.format ? formatValue('n', inputMetaData.format, inEl.value).value : inputMetaData.value;
209
- labelEl.style.display = 'block';
210
- }
211
- });
212
- tdElement.appendChild(inEl);
213
- tdElement.appendChild(labelEl);
214
- break;
215
- case "dateInput":
216
- let dateEl = document.createElement("DIV");
217
- const format = inputMetaData.format ? inputMetaData.format.toUpperCase() : 'MM/DD/YYYY';
218
- const formattedDate = formatValue('d', format, inputMetaData.value).value
219
- if (_this.isScenarioMode) {
220
- dateEl.innerHTML = '<label class="value dateInput" style="background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;cursor:pointer;">' + formattedDate + '</label>';
221
- } else {
222
- dateEl.innerHTML = '<label class="value dateInput" style="cursor: pointer;">' + formattedDate + '</label>';
223
- }
224
- tdElement.appendChild(dateEl);
225
- tdElement.classList.toggle("input-filter-list-td");
226
- tdElement.setAttribute("name", inputMetaData.name);
227
- tdElement.addEventListener("click", function (event) {
228
- try {
229
- scope.openDatePickerFromPublishedItem(event, options.widgetId, options.dashboardId, inputMetaData, format);
230
- } catch (e) {
231
- console.error(e);
232
- }
233
- })
234
- break;
235
- case "excelList":
236
- let selectEl = document.createElement("SELECT");
237
- selectEl.setAttribute("name", inputMetaData.name);
238
- selectEl.setAttribute("class", "dr_input");
239
- for (let i = 0; i < inputMetaData.values.length; i++) {
240
- let option = document.createElement("option");
241
- option.setAttribute("value", inputMetaData.values[i]);
242
- option.innerText = inputMetaData.values[i];
243
- if (inputMetaData.values[i] === inputMetaData.value) {
244
- option.setAttribute("selected", "");
245
- }
246
- selectEl.appendChild(option);
247
- }
248
- selectEl.addEventListener("change", function (event) {
249
- publishedItemsRenderer.changedInputElement(event, scope, options)
250
- });
251
- tdElement.appendChild(selectEl);
252
- break;
253
- case "filterList":
254
- let listHolderEl = document.createElement("DIV");
255
- listHolderEl.setAttribute("class", "filter_list_holder");
256
- if (_this.isScenarioMode) {
257
- listHolderEl.innerHTML = '<label class="value filterList" style="background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;cursor: pointer;">' + inputMetaData.value + '</label><i class="filter_icon"></i>';
258
- } else {
259
- listHolderEl.innerHTML = '<label class="value filterList" style="cursor: pointer;">' + inputMetaData.value + '</label><i class="filter_icon"></i>';
260
- }
261
- tdElement.appendChild(listHolderEl);
262
- tdElement.classList.toggle("input-filter-list-td");
263
- tdElement.setAttribute("name", inputMetaData.name);
264
- tdElement.addEventListener("click", function (event) {
265
- let inputElement = event.currentTarget;
266
- let name = inputElement.getAttribute('name');
267
- let metaData = options.inputValuesData ? options.inputValuesData[name] : null;
268
- if (metaData) {
269
- try {
270
- scope.openFilterListFromPublishedItem(event, options.widgetId, options.dashboardId, metaData);
271
- } catch (e) {
272
- console.error(e);
273
- }
274
- }
275
- });
276
- break;
277
- }
278
- }
279
- }
280
-
281
- publishedItemsRenderer.changedInputFilterValue = function (metaData, newValue, document) {
282
- let tdLabelElement = document.querySelector('td[name="' + metaData.name + '"]>div>label[class="value"]');
283
- if (tdLabelElement) {
284
- tdLabelElement.innerText = newValue;
285
- }
286
- console.log(tdLabelElement, newValue);
287
- }
288
-
289
- publishedItemsRenderer.changeStylesForLabel = function (elementsArray, styles, isScenarioMode) {
290
- if (elementsArray.length) {
291
- elementsArray.forEach(element => {
292
- element.setAttribute("style", isScenarioMode ? styles : "cursor:pointer;");
293
- })
294
- }
295
- }
296
-
297
- publishedItemsRenderer.prepareInputCells = function (document, scope, options, isScenarioMode) {
298
- const inputCells = document.querySelectorAll('td>a[href="DR_INPUT"], td>div>a[href="DR_INPUT"]');
299
- const inputs = document.querySelectorAll('td>input');
300
- const dateInputs = document.querySelectorAll('.dateInput');
301
- const filterList = document.querySelectorAll('.filterList');
302
- const styleForLabel = "background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;cursor:pointer;";
303
- if (!options.inputValuesData) {
304
- options.inputValuesData = {};
305
- }
306
- publishedItemsRenderer.changeStylesForLabel(filterList, styleForLabel, isScenarioMode);
307
- publishedItemsRenderer.changeStylesForLabel(dateInputs, styleForLabel, isScenarioMode);
308
- if (inputs.length) {
309
- inputs.forEach(element => {
310
- const labelElement = element.nextSibling;
311
- labelElement.setAttribute("style", isScenarioMode ?
312
- "background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;width: calc(100% - 15px);margin: 6px;text-align: inherit;display: block; cursor: pointer;" :
313
- "background: transparent;width: calc(100% - 15px);border: 0;margin: 6px;text-align: inherit;display: block; cursor: pointer;");
314
- });
315
- }
316
- if (inputCells.length) {
317
- for (let i = 0; i < inputCells.length; i++) {
318
- let tdElement = inputCells[i].parentElement;
319
- let inputId = inputCells[i].getAttribute('name') || 'no_attribute';
320
- publishedItemsRenderer.createInputElement(tdElement, options.inputValuesData[inputId], scope.highchartsRenderer.formatValue, scope, options, document, isScenarioMode);
321
- }
322
- }
323
- }
324
-
325
- publishedItemsRenderer.addEventListeners = function (document, iframeWindow, scope, options) {
326
- document.addEventListener("DOMContentLoaded", function () {
327
- if (!options.alreadySetTimeout) {
328
- options.alreadySetTimeout = setTimeout(function () {
329
- publishedItemsRenderer.resizeTable(options, iframeWindow);
330
- }, 50);
331
- }
332
- });
333
- iframeWindow.addEventListener("resize", function () {
334
- if (!options.alreadySetTimeout) {
335
- options.alreadySetTimeout = setTimeout(function () {
336
- publishedItemsRenderer.resizeTable(iframeWindow.__options__, iframeWindow);
337
- }, 100);
338
- }
339
- });
340
-
341
- // Add click event to cell with formula
342
- let all_a_hrefs = document.querySelectorAll('td a[location_id]');
343
- for (let i = 0; i < all_a_hrefs.length; i++) {
344
- let td_elem = all_a_hrefs[i].closest('td');
345
- td_elem.classList.add("apply_hover");
346
- td_elem.addEventListener('click', function (event) {
347
- publishedItemsRenderer.formulaCellClicked(event, scope, options, iframeWindow)
348
- });
349
- }
350
- }
351
-
352
- publishedItemsRenderer.scenarioModeChange = function (flag, document) {
353
- this.isScenarioMode = flag;
354
- publishedItemsRenderer.prepareInputCells(document, this.scope, this.options, this.isScenarioMode);
355
- }
356
-
357
- publishedItemsRenderer.getInputValues = function () {
358
- return this.options.inputValuesData;
359
- }
360
-
361
- publishedItemsRenderer.initPublishedItem = function (document, iframeWindow, scope, options) {
362
- this.document = document;
363
- this.scope = scope;
364
- this.options = options;
365
- iframeWindow.__options__ = options;
366
- publishedItemsRenderer.prepareInputCells(document, scope, options, this.isScenarioMode);
367
- publishedItemsRenderer.applyInitDocumentStyles(document, iframeWindow);
368
- publishedItemsRenderer.addEventListeners(document, iframeWindow, scope, options);
369
-
370
- setTimeout(function () {
371
- publishedItemsRenderer.changedInputValue(true, scope, options);
372
- }, 500);
373
- }
374
-
375
- publishedItemsRenderer.applyInitDocumentStyles = function(document, iframeWindow) {
376
- const table = document.getElementsByTagName('table')[0];
377
- if (table) {
378
- table.style.overflow = 'hidden';
379
- table.style.margin = iframeWindow.__options__.responsive ? '0 auto' : '';
380
- }
381
-
382
- const body = document.body;
383
- body.style.margin = '0';
384
- }
385
- }
386
-
387
- module.exports = getPublishedItemsRenderer;
1
+ let getPublishedItemsRenderer = function (publishedItemsRenderer) {
2
+
3
+ this.document = {};
4
+ this.scope = {};
5
+ this.options = {};
6
+ this.isScenarioMode = null;
7
+
8
+ publishedItemsRenderer.formulaCellClicked = function (event, scope, options, window) {
9
+ event.stopPropagation();
10
+ event.preventDefault();
11
+ try {
12
+ const td = event.currentTarget;
13
+ const a = td.querySelector('a');
14
+ const locationId = a.getAttribute('location_id');
15
+ scope.callFromPublishItem(event, options.widgetId, options.dashboardId, locationId, window.published_item_sheetname);
16
+ } catch (e) {
17
+ }
18
+ return false;
19
+ }
20
+
21
+ publishedItemsRenderer.resizeTable = function (options, iframeWindow) {
22
+ options.alreadySetTimeout = null;
23
+ const publish_item_image = iframeWindow.document.getElementById('publish_item_image');
24
+ const table = iframeWindow.document.getElementsByTagName("table")[0];
25
+ const body = iframeWindow.document.getElementsByTagName("body")[0];
26
+
27
+ if (table && options.responsive) {
28
+ publishedItemsRenderer.zoomTable(iframeWindow, table, body);
29
+ }
30
+
31
+ publishedItemsRenderer.resizePublishedImage(publish_item_image, iframeWindow, body);
32
+ }
33
+
34
+ publishedItemsRenderer.zoomTable = function(iframeWindow, table, body) {
35
+ let body_zoom = body.style.zoom;
36
+ body_zoom = parseFloat(body_zoom) || 1;
37
+
38
+ let zoom = table.style.zoom;
39
+ zoom = parseFloat(zoom) || 1;
40
+
41
+ const positionInfo = table.getBoundingClientRect();
42
+ let width = Math.ceil((positionInfo.width + iframeWindow.innerWidth - iframeWindow.document.body.offsetWidth) * zoom * body_zoom);
43
+
44
+ if (width < iframeWindow.innerWidth) {
45
+ zoom += 0.05;
46
+
47
+ width = Math.ceil((positionInfo.width + iframeWindow.innerWidth - iframeWindow.document.body.offsetWidth) * zoom * body_zoom);
48
+ if (width < iframeWindow.innerWidth) {
49
+ table.style.zoom = zoom;
50
+ setTimeout(function () {
51
+ publishedItemsRenderer.zoomTable(iframeWindow, table, body);
52
+ }, 10);
53
+ }
54
+ } else if (width >= iframeWindow.innerWidth) {
55
+ zoom -= 0.05;
56
+
57
+ width = Math.ceil((positionInfo.width + iframeWindow.innerWidth - iframeWindow.document.body.offsetWidth) * zoom * body_zoom);
58
+ table.style.zoom = zoom;
59
+ if (width >= iframeWindow.innerWidth) {
60
+ setTimeout(function () {
61
+ publishedItemsRenderer.zoomTable(iframeWindow, table, body);
62
+ }, 10);
63
+ }
64
+ }
65
+ }
66
+
67
+ publishedItemsRenderer.resizePublishedImage = function(publish_item_image, iframeWindow, body) {
68
+ if (!publish_item_image) return;
69
+
70
+ let body_zoom = body.style.zoom;
71
+ body_zoom = parseFloat(body_zoom) || 1;
72
+
73
+ if (publish_item_image.style.height === '100%') {
74
+ publish_item_image.style.height = 'auto';
75
+ publish_item_image.style.width = '100%';
76
+ publish_item_image.style.marginTop = "";
77
+ setTimeout(function () {
78
+ publishedItemsRenderer.resizePublishedImage(publish_item_image, iframeWindow, body);
79
+ }, 10);
80
+ }
81
+
82
+ const imgPositionInfo = publish_item_image.getBoundingClientRect();
83
+ const height = (imgPositionInfo.height + imgPositionInfo.y * 2) * body_zoom;
84
+ if (height > iframeWindow.innerHeight) {
85
+ publish_item_image.style.height = '100%';
86
+ publish_item_image.style.width = 'auto';
87
+ } else if (height < iframeWindow.innerHeight) {
88
+ const temp = (iframeWindow.innerHeight - height) / 2;
89
+ publish_item_image.style.marginTop = (temp / body_zoom + imgPositionInfo.y) + "px";
90
+ }
91
+ }
92
+
93
+ publishedItemsRenderer.resetTableZoom = function (document) {
94
+ const table = document.getElementsByTagName("table")[0];
95
+ if (table) {
96
+ table.style.zoom = 1;
97
+ }
98
+ }
99
+
100
+ publishedItemsRenderer.changedAutoResize = function (options, iframeWindow, document) {
101
+ Object.assign(iframeWindow.__options__, options);
102
+ const table = document.getElementsByTagName("table")[0];
103
+ if (table) {
104
+ table.style.margin = options.responsive ? '0 auto' : '';
105
+ }
106
+
107
+ if (!options.responsive) {
108
+ publishedItemsRenderer.resetTableZoom(document);
109
+ } else {
110
+ if (!options.alreadySetTimeout) {
111
+ options.alreadySetTimeout = setTimeout(function () {
112
+ publishedItemsRenderer.resizeTable(options, iframeWindow);
113
+ }, 100);
114
+ }
115
+ }
116
+ }
117
+
118
+ publishedItemsRenderer.changedInputValue = function (firstTime, scope, options) {
119
+ const input_values = [];
120
+ if (options.inputValuesData) {
121
+ for (let key in options.inputValuesData) {
122
+ input_values.push(options.inputValuesData[key]);
123
+ }
124
+ }
125
+
126
+ try {
127
+ scope.changedInputValues(input_values, options.widgetId, options.dashboardId, firstTime);
128
+ } catch (e) {
129
+ console.error(e);
130
+ }
131
+ }
132
+
133
+ publishedItemsRenderer.changedInputElement = function (event, scope, options) {
134
+ const inputElement = event.currentTarget;
135
+ const name = inputElement.getAttribute('name');
136
+ const metaData = options.inputValuesData ? options.inputValuesData[name] : null;
137
+ let newValue = inputElement.value;
138
+ if (metaData) {
139
+ if (metaData.type === 'editInput') {
140
+ newValue = parseFloat(newValue);
141
+ } else if (metaData.type === 'editInputPercent') {
142
+ newValue = parseFloat(newValue) + '%';
143
+ }
144
+
145
+ if (metaData.value !== newValue) {
146
+ metaData.value = newValue;
147
+ publishedItemsRenderer.changedInputValue(false, scope, options);
148
+ }
149
+ }
150
+ }
151
+
152
+ publishedItemsRenderer.createInputElement = function (tdElement, inputMetaData, formatValue, scope, options, document) {
153
+ const _this = this;
154
+ tdElement.innerHTML = '';
155
+ if (inputMetaData) {
156
+ switch (inputMetaData.type) {
157
+ case "editInput":
158
+ case "editInputPercent":
159
+ let inEl = document.createElement("INPUT");
160
+ let labelEl = document.createElement("LABEL");
161
+
162
+ if (inputMetaData.value === 'DR_INPUT') {
163
+ labelEl.innerText = null;
164
+ } else {
165
+ labelEl.innerText = inputMetaData.format ? formatValue('n', inputMetaData.format, inputMetaData.value).value : inputMetaData.value;
166
+ }
167
+ if (_this.isScenarioMode) {
168
+ labelEl.setAttribute("style", "background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;width: calc(100% - 15px);margin: 6px;text-align: inherit;display: block; cursor: pointer;");
169
+ } else {
170
+ labelEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 6px;text-align: inherit;display: block; cursor: pointer;");
171
+ }
172
+ const onLabelClick = function (event, isScenarioMode) {
173
+ event.stopPropagation();
174
+ if (isScenarioMode) {
175
+ inEl.setAttribute("style", "background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: block;");
176
+ } else {
177
+ inEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: block;");
178
+ }
179
+ labelEl.style.display = 'none';
180
+ setTimeout(function () {
181
+ inEl.focus();
182
+ }, 1)
183
+ }
184
+ labelEl.addEventListener("click", (event) => onLabelClick(event, _this.isScenarioMode));
185
+
186
+ inEl.setAttribute("type", "number");
187
+ inEl.setAttribute("name", inputMetaData.name);
188
+ if (_this.isScenarioMode) {
189
+ inEl.setAttribute("style", "background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: none;");
190
+ } else {
191
+ inEl.setAttribute("style", "background: transparent;width: calc(100% - 15px);border: 0;margin: 5px;text-align: inherit;display: none;");
192
+ }
193
+ inEl.value = inputMetaData.type === 'editInputPercent' ? parseFloat(inputMetaData.value.replace('%', '')) : inputMetaData.value;
194
+ inEl.addEventListener("focusout", function (event) {
195
+ event.preventDefault();
196
+ publishedItemsRenderer.changedInputElement(event, scope, options);
197
+ inEl.style.display = 'none';
198
+ labelEl.innerText = inputMetaData.format ? formatValue('n', inputMetaData.format, inEl.value).value : inputMetaData.value;
199
+ labelEl.style.display = 'block';
200
+ });
201
+ inEl.addEventListener("keyup", function (event) {
202
+ // Number 13 is the "Enter" key on the keyboard
203
+ if (event.keyCode === 13) {
204
+ // Cancel the default action, if needed
205
+ event.preventDefault();
206
+ publishedItemsRenderer.changedInputElement(event, scope, options);
207
+ inEl.style.display = 'none';
208
+ labelEl.innerText = inputMetaData.format ? formatValue('n', inputMetaData.format, inEl.value).value : inputMetaData.value;
209
+ labelEl.style.display = 'block';
210
+ }
211
+ });
212
+ tdElement.appendChild(inEl);
213
+ tdElement.appendChild(labelEl);
214
+ break;
215
+ case "dateInput":
216
+ let dateEl = document.createElement("DIV");
217
+ const format = inputMetaData.format ? inputMetaData.format.toUpperCase() : 'MM/DD/YYYY';
218
+ const formattedDate = formatValue('d', format, inputMetaData.value).value
219
+ if (_this.isScenarioMode) {
220
+ dateEl.innerHTML = '<label class="value dateInput" style="background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;cursor:pointer;">' + formattedDate + '</label>';
221
+ } else {
222
+ dateEl.innerHTML = '<label class="value dateInput" style="cursor: pointer;">' + formattedDate + '</label>';
223
+ }
224
+ tdElement.appendChild(dateEl);
225
+ tdElement.classList.toggle("input-filter-list-td");
226
+ tdElement.setAttribute("name", inputMetaData.name);
227
+ tdElement.addEventListener("click", function (event) {
228
+ try {
229
+ scope.openDatePickerFromPublishedItem(event, options.widgetId, options.dashboardId, inputMetaData, format);
230
+ } catch (e) {
231
+ console.error(e);
232
+ }
233
+ })
234
+ break;
235
+ case "excelList":
236
+ let selectEl = document.createElement("SELECT");
237
+ selectEl.setAttribute("name", inputMetaData.name);
238
+ selectEl.setAttribute("class", "dr_input");
239
+ for (let i = 0; i < inputMetaData.values.length; i++) {
240
+ let option = document.createElement("option");
241
+ option.setAttribute("value", inputMetaData.values[i]);
242
+ option.innerText = inputMetaData.values[i];
243
+ if (inputMetaData.values[i] === inputMetaData.value) {
244
+ option.setAttribute("selected", "");
245
+ }
246
+ selectEl.appendChild(option);
247
+ }
248
+ selectEl.addEventListener("change", function (event) {
249
+ publishedItemsRenderer.changedInputElement(event, scope, options)
250
+ });
251
+ tdElement.appendChild(selectEl);
252
+ break;
253
+ case "filterList":
254
+ let listHolderEl = document.createElement("DIV");
255
+ listHolderEl.setAttribute("class", "filter_list_holder");
256
+ if (_this.isScenarioMode) {
257
+ listHolderEl.innerHTML = '<label class="value filterList" style="background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;cursor: pointer;">' + inputMetaData.value + '</label><i class="filter_icon"></i>';
258
+ } else {
259
+ listHolderEl.innerHTML = '<label class="value filterList" style="cursor: pointer;">' + inputMetaData.value + '</label><i class="filter_icon"></i>';
260
+ }
261
+ tdElement.appendChild(listHolderEl);
262
+ tdElement.classList.toggle("input-filter-list-td");
263
+ tdElement.setAttribute("name", inputMetaData.name);
264
+ tdElement.addEventListener("click", function (event) {
265
+ let inputElement = event.currentTarget;
266
+ let name = inputElement.getAttribute('name');
267
+ let metaData = options.inputValuesData ? options.inputValuesData[name] : null;
268
+ if (metaData) {
269
+ try {
270
+ scope.openFilterListFromPublishedItem(event, options.widgetId, options.dashboardId, metaData);
271
+ } catch (e) {
272
+ console.error(e);
273
+ }
274
+ }
275
+ });
276
+ break;
277
+ }
278
+ }
279
+ }
280
+
281
+ publishedItemsRenderer.changedInputFilterValue = function (metaData, newValue, document) {
282
+ let tdLabelElement = document.querySelector('td[name="' + metaData.name + '"]>div>label[class="value"]');
283
+ if (tdLabelElement) {
284
+ tdLabelElement.innerText = newValue;
285
+ }
286
+ console.log(tdLabelElement, newValue);
287
+ }
288
+
289
+ publishedItemsRenderer.changeStylesForLabel = function (elementsArray, styles, isScenarioMode) {
290
+ if (elementsArray.length) {
291
+ elementsArray.forEach(element => {
292
+ element.setAttribute("style", isScenarioMode ? styles : "cursor:pointer;");
293
+ })
294
+ }
295
+ }
296
+
297
+ publishedItemsRenderer.prepareInputCells = function (document, scope, options, isScenarioMode) {
298
+ const inputCells = document.querySelectorAll('td>a[href="DR_INPUT"], td>div>a[href="DR_INPUT"]');
299
+ const inputs = document.querySelectorAll('td>input');
300
+ const dateInputs = document.querySelectorAll('.dateInput');
301
+ const filterList = document.querySelectorAll('.filterList');
302
+ const styleForLabel = "background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;cursor:pointer;";
303
+ if (!options.inputValuesData) {
304
+ options.inputValuesData = {};
305
+ }
306
+ publishedItemsRenderer.changeStylesForLabel(filterList, styleForLabel, isScenarioMode);
307
+ publishedItemsRenderer.changeStylesForLabel(dateInputs, styleForLabel, isScenarioMode);
308
+ if (inputs.length) {
309
+ inputs.forEach(element => {
310
+ const labelElement = element.nextSibling;
311
+ labelElement.setAttribute("style", isScenarioMode ?
312
+ "background: #FFEDBF;padding: 2px 1px 2px 6px;border: 1px solid #FABC5F;border-radius: 6px;width: calc(100% - 15px);margin: 6px;text-align: inherit;display: block; cursor: pointer;" :
313
+ "background: transparent;width: calc(100% - 15px);border: 0;margin: 6px;text-align: inherit;display: block; cursor: pointer;");
314
+ });
315
+ }
316
+ if (inputCells.length) {
317
+ for (let i = 0; i < inputCells.length; i++) {
318
+ let tdElement = inputCells[i].parentElement;
319
+ let inputId = inputCells[i].getAttribute('name') || 'no_attribute';
320
+ publishedItemsRenderer.createInputElement(tdElement, options.inputValuesData[inputId], scope.highchartsRenderer.formatValue, scope, options, document, isScenarioMode);
321
+ }
322
+ }
323
+ }
324
+
325
+ publishedItemsRenderer.addEventListeners = function (document, iframeWindow, scope, options) {
326
+ document.addEventListener("DOMContentLoaded", function () {
327
+ if (!options.alreadySetTimeout) {
328
+ options.alreadySetTimeout = setTimeout(function () {
329
+ publishedItemsRenderer.resizeTable(options, iframeWindow);
330
+ }, 50);
331
+ }
332
+ });
333
+ iframeWindow.addEventListener("resize", function () {
334
+ if (!options.alreadySetTimeout) {
335
+ options.alreadySetTimeout = setTimeout(function () {
336
+ publishedItemsRenderer.resizeTable(iframeWindow.__options__, iframeWindow);
337
+ }, 100);
338
+ }
339
+ });
340
+
341
+ // Add click event to cell with formula
342
+ let all_a_hrefs = document.querySelectorAll('td a[location_id]');
343
+ for (let i = 0; i < all_a_hrefs.length; i++) {
344
+ let td_elem = all_a_hrefs[i].closest('td');
345
+ td_elem.classList.add("apply_hover");
346
+ td_elem.addEventListener('click', function (event) {
347
+ publishedItemsRenderer.formulaCellClicked(event, scope, options, iframeWindow)
348
+ });
349
+ }
350
+ }
351
+
352
+ publishedItemsRenderer.scenarioModeChange = function (flag, document) {
353
+ this.isScenarioMode = flag;
354
+ publishedItemsRenderer.prepareInputCells(document, this.scope, this.options, this.isScenarioMode);
355
+ }
356
+
357
+ publishedItemsRenderer.getInputValues = function () {
358
+ return this.options.inputValuesData;
359
+ }
360
+
361
+ publishedItemsRenderer.initPublishedItem = function (document, iframeWindow, scope, options) {
362
+ this.document = document;
363
+ this.scope = scope;
364
+ this.options = options;
365
+ iframeWindow.__options__ = options;
366
+ publishedItemsRenderer.prepareInputCells(document, scope, options, this.isScenarioMode);
367
+ publishedItemsRenderer.applyInitDocumentStyles(document, iframeWindow);
368
+ publishedItemsRenderer.addEventListeners(document, iframeWindow, scope, options);
369
+
370
+ setTimeout(function () {
371
+ publishedItemsRenderer.changedInputValue(true, scope, options);
372
+ }, 500);
373
+ }
374
+
375
+ publishedItemsRenderer.applyInitDocumentStyles = function(document, iframeWindow) {
376
+ const table = document.getElementsByTagName('table')[0];
377
+ if (table) {
378
+ table.style.overflow = 'hidden';
379
+ table.style.margin = iframeWindow.__options__.responsive ? '0 auto' : '';
380
+ }
381
+
382
+ const body = document.body;
383
+ body.style.margin = '0';
384
+ }
385
+ }
386
+
387
+ module.exports = getPublishedItemsRenderer;