@progress/telerik-jquery-report-viewer 31.26.1007 → 32.26.1110

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.
@@ -9,6 +9,15 @@ var command = require('./command.js');
9
9
  var utils = require('./utils.js');
10
10
 
11
11
  const PAGE_SELECTION_FIELD = "__trvPageSelection";
12
+ const PAGE_RANGE_FIELD = "__trvPageRange";
13
+ const SUBGROUP_FIELD_PREFIX = "__trvSubgroup_";
14
+ const SUBGROUP_HEADER_PREFIX = "__trvSubgroupHeader_";
15
+ const CONFIRM_FIELD_PREFIX = "__trvConfirm_";
16
+ const PRESET_FIELD_PREFIX = "__trvPreset_";
17
+ const REQUIRED_RULE = "trvrequired";
18
+ const CONFIRM_RULE = "trvconfirm";
19
+ const PAGE_RANGE_RULE = "trvpagerange";
20
+ const DIFFER_RULE = "trvdiffer";
12
21
  function replaceStringResources($dialog) {
13
22
  if (!$dialog) {
14
23
  return;
@@ -34,8 +43,8 @@ function replaceStringResources($dialog) {
34
43
  });
35
44
  }
36
45
  }
37
- function isPasswordSetting(name) {
38
- return typeof name === "string" && name.toLowerCase().includes("password");
46
+ function isSameValue(value, other) {
47
+ return String(value ?? "").toLowerCase() === String(other ?? "").toLowerCase();
39
48
  }
40
49
  function createEditorInput(container, options, type) {
41
50
  return $("<input />").attr({
@@ -46,14 +55,81 @@ function createEditorInput(container, options, type) {
46
55
  }).appendTo(container);
47
56
  }
48
57
  function createPasswordEditor(container, options) {
49
- createEditorInput(container, options, "password").attr("autocomplete", "new-password").kendoTextBox({ enable: options.editorOptions.enabled });
58
+ createEditorInput(container, options, "password").attr("autocomplete", "new-password").kendoTextBox({
59
+ placeholder: options.editorOptions.placeholder,
60
+ enable: options.editorOptions.enabled
61
+ });
62
+ }
63
+ function createSwitchEditor(container, options) {
64
+ container.closest(".k-form-field").addClass("trv-export-switch-field");
65
+ createEditorInput(container, options, "checkbox").kendoSwitch({
66
+ enabled: options.editorOptions.enabled,
67
+ messages: {
68
+ checked: stringResources.stringResources.exportDialogSwitchOnLabel,
69
+ unchecked: stringResources.stringResources.exportDialogSwitchOffLabel
70
+ }
71
+ });
50
72
  }
51
73
  function createDropDownEditor(container, options) {
52
74
  createEditorInput(container, options, "text").kendoDropDownList({
53
75
  dataSource: options.editorOptions.dataSource,
76
+ dataTextField: "text",
77
+ dataValueField: "value",
78
+ valuePrimitive: true,
54
79
  enable: options.editorOptions.enabled
55
80
  });
56
81
  }
82
+ function createRadioGroupEditor(container, options) {
83
+ const groupName = `${options.field}-${kendo.guid()}`;
84
+ const radios = [];
85
+ const $group = $('<div class="trv-export-radio-group" role="radiogroup"></div>').attr("aria-labelledby", `${options.field}-form-label`).appendTo(container);
86
+ container.closest(".k-form-field").addClass("trv-export-radio-field");
87
+ options.editorOptions.dataSource.forEach((item, index) => {
88
+ const option = $('<label class="trv-export-radio-option"></label>').appendTo($group);
89
+ const input = $('<input type="radio" />').attr({
90
+ id: kendo.guid(),
91
+ name: groupName,
92
+ [kendo.attr("skip")]: true
93
+ }).appendTo(option).kendoRadioButton({
94
+ checked: isSameValue(options.model.get(options.field), item.value),
95
+ enabled: options.editorOptions.enabled
96
+ });
97
+ $("<span></span>").text(item.text).appendTo(option);
98
+ input.on("change", () => options.model.set(options.field, item.value));
99
+ radios.push({ input, value: item.value });
100
+ });
101
+ options.model.bind("change", (event) => {
102
+ if (event.field === options.field) {
103
+ radios.forEach((radio) => radio.input.prop("checked", isSameValue(options.model.get(options.field), radio.value)));
104
+ }
105
+ });
106
+ }
107
+ function createSubgroupHeaderEditor(container, options) {
108
+ container.closest(".k-form-field").addClass("trv-export-subgroup-header");
109
+ $('<div class="k-form-label trv-export-subgroup-title" role="heading" aria-level="4"></div>').text(options.editorOptions.text).appendTo(container);
110
+ }
111
+ function createInfoIcon(description) {
112
+ return $('<span class="trv-export-setting-info" tabindex="0" role="img"></span>').attr({
113
+ "aria-label": description,
114
+ "data-description": description
115
+ }).append(kendo.ui.icon({ icon: "info-circle", size: "small" })).on("click", (event) => event.preventDefault());
116
+ }
117
+ function appendInfoIcon($label, description) {
118
+ let $text = $label.children(".trv-export-setting-label-text");
119
+ if (!$text.length) {
120
+ $text = $('<span class="trv-export-setting-label-text"></span>').attr("id", kendo.guid());
121
+ $label.contents().filter((index, node) => node.nodeType === Node.TEXT_NODE).wrapAll($text);
122
+ $text = $label.children(".trv-export-setting-label-text");
123
+ }
124
+ $label.append(createInfoIcon(description));
125
+ if ($label.hasClass("trv-export-subgroup-title")) {
126
+ return;
127
+ }
128
+ const $field = $label.closest(".k-form-field");
129
+ const $widgets = $field.find('[role="combobox"], [role="switch"], [role="radiogroup"], [role="spinbutton"]');
130
+ const $inputs = $field.find('input:not([type="hidden"]):not([type="radio"])').filter((index, element) => $(element).closest('[role="combobox"], [role="switch"], [role="spinbutton"]').length === 0);
131
+ $widgets.add($inputs).attr("aria-labelledby", $text.attr("id"));
132
+ }
57
133
  function createCheckBoxEditor(container, options) {
58
134
  container.closest(".k-form-field").addClass("trv-export-boolean-field");
59
135
  createEditorInput(container, options, "checkbox").kendoCheckBox({
@@ -64,7 +140,8 @@ function createNumericEditor(container, options) {
64
140
  createEditorInput(container, options, "text").kendoNumericTextBox({
65
141
  format: "n0",
66
142
  decimals: 0,
67
- min: 0,
143
+ min: options.editorOptions.min ?? 0,
144
+ max: options.editorOptions.max ?? null,
68
145
  step: 1,
69
146
  autoAdjust: true,
70
147
  enable: options.editorOptions.enabled
@@ -72,7 +149,26 @@ function createNumericEditor(container, options) {
72
149
  }
73
150
  function createTextEditor(container, options) {
74
151
  createEditorInput(container, options, "text").kendoTextBox({
75
- placeholder: stringResources.stringResources.exportDialogTextPlaceholder,
152
+ placeholder: options.editorOptions.placeholder || stringResources.stringResources.exportDialogTextPlaceholder,
153
+ enable: options.editorOptions.enabled
154
+ });
155
+ }
156
+ function createPageRangeEditor(container, options) {
157
+ container.closest(".k-form-field").addClass("trv-export-page-range");
158
+ createEditorInput(container, options, "text").attr("aria-label", options.editorOptions.ariaLabel).kendoTextBox({
159
+ placeholder: options.editorOptions.placeholder,
160
+ enable: options.editorOptions.enabled
161
+ });
162
+ }
163
+ function createCustomValueEditor(container, options) {
164
+ container.closest(".k-form-field").addClass("trv-export-custom-value");
165
+ if (options.editorOptions.numeric) {
166
+ createNumericEditor(container, options);
167
+ container.find("input").attr("aria-label", options.editorOptions.ariaLabel);
168
+ return;
169
+ }
170
+ createEditorInput(container, options, "text").attr("aria-label", options.editorOptions.ariaLabel).kendoTextBox({
171
+ placeholder: options.editorOptions.placeholder,
76
172
  enable: options.editorOptions.enabled
77
173
  });
78
174
  }
@@ -116,6 +212,11 @@ class ExportDialog {
116
212
  this.settingsForm = void 0;
117
213
  this.currentValues = void 0;
118
214
  this.pagingSettingNames = [];
215
+ this.pageRangeSelected = false;
216
+ this.settingsLayout = [];
217
+ this.subgroupFields = [];
218
+ this.confirmFields = [];
219
+ this.presetFields = [];
119
220
  this.windowLocation = void 0;
120
221
  if (!this.controller) {
121
222
  throw "No controller (telerikReporting.ReportViewerController) has been specified.";
@@ -164,19 +265,24 @@ class ExportDialog {
164
265
  });
165
266
  this.kendoExportDialog.element.removeClass("trv-export-dialog k-hidden");
166
267
  this.kendoExportDialog.wrapper.addClass("trv-export-dialog");
167
- this.kendoExportDialog.wrapper.find(".k-window-title").prepend(
168
- $('<span aria-hidden="true"></span>').addClass(
169
- `k-sprite rendering-extension-icon ${utils.getExportOptionsIconClass()}`
170
- )
171
- );
268
+ const $title = this.kendoExportDialog.wrapper.find(".k-window-title");
269
+ const titleId = $title.attr("id") || kendo.guid();
270
+ $title.attr("id", titleId).prepend(utils.renderExportOptionsIcon());
271
+ this.kendoExportDialog.wrapper.attr({
272
+ role: "dialog",
273
+ "aria-modal": "true",
274
+ "aria-labelledby": titleId
275
+ });
172
276
  this.$element.find(".trv-export-dialog-reset").kendoButton({
173
277
  icon: "arrow-rotate-cw",
174
- fillMode: "flat",
278
+ size: "small",
279
+ rounded: "medium",
280
+ fillMode: "outline",
175
281
  themeColor: "base"
176
282
  });
177
283
  this.$element.find(".trv-export-dialog-documentation").attr("title", stringResources.stringResources.exportDialogDocumentationLabel).prepend(kendo.ui.icon({ icon: "hyperlink-open" }));
178
284
  this.$element.find('[data-command="telerik_ReportViewer_exportDialog_Close"]').kendoButton({
179
- fillMode: "solid",
285
+ fillMode: "outline",
180
286
  themeColor: "base"
181
287
  });
182
288
  this.$element.find('[data-command="telerik_ReportViewer_exportDialog_Save"]').kendoButton({
@@ -263,11 +369,10 @@ class ExportDialog {
263
369
  const selectedFormat = this.formats.some((item) => item.name === this.format) ? this.format : this.formats[0]?.name;
264
370
  const drawerItems = this.formats.map((format) => ({
265
371
  format: format.name,
266
- text: format.localizedName,
372
+ text: RCV.getExportFormatName(format, stringResources.stringResources),
267
373
  selected: format.name === selectedFormat,
268
374
  miniTemplate: () => {
269
- const iconClass = utils.getRenderingExtensionIconClass(format.name);
270
- const icon = iconClass ? `<span aria-hidden="true" class="k-sprite rendering-extension-icon ${iconClass}"></span>` : `<span aria-hidden="true">${kendo.htmlEncode(format.name.slice(0, 3))}</span>`;
375
+ const icon = utils.renderExportFormatIcon(format.name) || `<span aria-hidden="true">${kendo.htmlEncode(format.name.slice(0, 3))}</span>`;
271
376
  return `<li data-role="drawer-item">${icon}</li>`;
272
377
  }
273
378
  }));
@@ -285,9 +390,14 @@ class ExportDialog {
285
390
  swipeToOpen: false,
286
391
  navigatable: true,
287
392
  itemClick: (event) => {
288
- if (event.dataItem?.format) {
289
- this.showFormat(event.dataItem.format);
393
+ if (!event.dataItem?.format || event.dataItem.format === this.format) {
394
+ return;
395
+ }
396
+ if (!this.validateSettingsForm()) {
397
+ this.selectDrawerFormat(this.format);
398
+ return;
290
399
  }
400
+ this.showFormat(event.dataItem.format);
291
401
  }
292
402
  }).data("kendoDrawer");
293
403
  }
@@ -315,15 +425,11 @@ class ExportDialog {
315
425
  const drawerElements = this.formatDrawer.drawerItemsWrapper.find('[data-role="drawer-item"]');
316
426
  drawerElements.each((index, element) => {
317
427
  const format = this.formats[index];
318
- const iconClass = utils.getRenderingExtensionIconClass(format?.name);
428
+ const icon = utils.renderExportFormatIcon(format?.name);
319
429
  const $element = $(element);
320
- $element.find(".k-item-text").attr("title", format?.localizedName || "");
321
- if (iconClass && !$element.find(".rendering-extension-icon").length) {
322
- $element.prepend(
323
- $('<span aria-hidden="true"></span>').addClass(
324
- `k-sprite rendering-extension-icon ${iconClass}`
325
- )
326
- );
430
+ $element.find(".k-item-text").attr("title", RCV.getExportFormatName(format, stringResources.stringResources));
431
+ if (icon && !$element.find(".trv-export-format-icon").length) {
432
+ $element.prepend(icon);
327
433
  }
328
434
  });
329
435
  }
@@ -332,14 +438,16 @@ class ExportDialog {
332
438
  this.format = format;
333
439
  const extension = this.formats.find((item) => item.name === format);
334
440
  this.$element.find(".trv-export-dialog-format-name").text(
335
- `${extension?.localizedName || format || ""}${stringResources.stringResources.exportDialogSettingsSuffix}`
441
+ `${RCV.getExportFormatName(extension, stringResources.stringResources) || format || ""}${stringResources.stringResources.exportDialogSettingsSuffix}`
336
442
  );
337
443
  this.$element.find(".trv-export-dialog-reset").attr("title", stringResources.stringResources.ariaLabelExportDialogReset);
338
- this.buildSettingsForm(extension ? extension.settings : []);
444
+ this.$element.find(".trv-export-dialog-documentation").attr("href", RCV.getExportDocumentationUrl(format));
445
+ this.buildSettingsForm(extension);
339
446
  }
340
- buildSettingsForm(settings) {
447
+ buildSettingsForm(extension) {
341
448
  this.destroySettingsForm();
342
- if (!settings || settings.length === 0) {
449
+ const settings = extension?.settings || [];
450
+ if (settings.length === 0) {
343
451
  this.$noSettingsMessage.removeClass("k-hidden");
344
452
  return;
345
453
  }
@@ -350,71 +458,393 @@ class ExportDialog {
350
458
  return;
351
459
  }
352
460
  const formData = {};
353
- const groups = /* @__PURE__ */ new Map();
354
461
  settings.forEach((setting) => {
355
- const pendingValues = this.pendingValues[this.format];
356
- const savedValue = this.exportSettingsStore ? this.exportSettingsStore.getValue(this.format, setting) : setting.value;
357
- const initialValue = pendingValues && Object.prototype.hasOwnProperty.call(pendingValues, setting.name) ? pendingValues[setting.name] : savedValue ?? this.getDefaultValue(setting.type);
358
- const groupName = setting.group?.trim() || "General";
359
- const groupSettings = groups.get(groupName) || [];
360
- formData[setting.name] = initialValue;
361
- groupSettings.push(setting);
362
- groups.set(groupName, groupSettings);
462
+ formData[setting.name] = this.getInitialValue(setting);
363
463
  });
364
- const pageRangeSelected = Number(formData.StartPage) > 0;
464
+ const layout = RCV.createExportSettingsLayout(extension);
465
+ this.settingsLayout = layout;
466
+ this.initSubgroupFields(layout, formData);
467
+ this.initConfirmFields(settings, formData);
468
+ this.initPresetFields(settings, formData);
469
+ this.pageRangeSelected = RCV.formatExportPageRange(formData.StartPage, formData.EndPage) !== "";
365
470
  if (!Object.prototype.hasOwnProperty.call(this.initialValues, this.format)) {
366
471
  this.initialValues[this.format] = { ...formData };
367
472
  }
368
473
  this.currentValues = { ...formData };
369
- formData[PAGE_SELECTION_FIELD] = pageRangeSelected;
370
- const formElement = $('<div class="trv-export-settings-form"></div>').appendTo(this.$settingsContainer.empty());
371
- const items = Array.from(groups, ([name, groupSettings]) => {
372
- const isPagingGroup = name === "Paging";
373
- const groupItems = groupSettings.map((setting) => this.createFormItem(setting));
374
- if (isPagingGroup) {
375
- this.pagingSettingNames = groupSettings.map((setting) => setting.name);
376
- groupItems.reverse();
377
- groupItems.unshift(this.createPageSelectionFormItem(pageRangeSelected));
378
- }
379
- return {
380
- type: "group",
381
- label: name,
382
- layout: "grid",
383
- grid: { cols: 1, gutter: 12 },
384
- items: groupItems
385
- };
474
+ this.presetFields.forEach((entry) => {
475
+ formData[entry.field] = entry.key;
476
+ });
477
+ formData[PAGE_SELECTION_FIELD] = this.pageRangeSelected;
478
+ formData[PAGE_RANGE_FIELD] = RCV.formatExportPageRange(formData.StartPage, formData.EndPage);
479
+ this.subgroupFields.filter((entry) => entry.headerField).forEach((entry) => {
480
+ formData[entry.headerField] = null;
386
481
  });
482
+ const formElement = $('<div class="trv-export-settings-form"></div>').appendTo(this.$settingsContainer.empty());
483
+ const items = layout.map((group) => ({
484
+ type: "group",
485
+ label: RCV.getExportGroupLabel(group, this.format, stringResources.stringResources),
486
+ layout: "grid",
487
+ grid: { cols: 1, gutter: 12 },
488
+ items: this.createGroupItems(group)
489
+ }));
387
490
  this.settingsForm = formElement.kendoForm({
388
491
  formData: { ...formData },
389
492
  items,
390
493
  renderButtons: false,
391
494
  focusFirst: false,
392
495
  validatable: {
393
- validateOnBlur: false,
496
+ validateOnBlur: true,
394
497
  validationSummary: false
395
498
  },
396
- change: (event) => {
397
- if (event.field !== PAGE_SELECTION_FIELD) {
398
- this.currentValues[event.field] = event.value;
399
- }
400
- }
499
+ change: (event) => this.onFormChange(event)
401
500
  }).data("kendoForm");
402
501
  this.renderSettingInfoIcons(settings);
403
- this.togglePagingSettings(pageRangeSelected);
502
+ this.updateFieldVisibility();
503
+ }
504
+ getInitialValue(setting) {
505
+ if (this.hasPendingValue(setting.name)) {
506
+ return this.pendingValues[this.format][setting.name];
507
+ }
508
+ const savedValue = this.exportSettingsStore ? this.exportSettingsStore.getValue(this.format, setting) : setting.value;
509
+ return savedValue ?? this.getDefaultValue(setting.type);
510
+ }
511
+ hasPendingValue(name) {
512
+ const pendingValues = this.pendingValues[this.format];
513
+ return Boolean(pendingValues) && Object.prototype.hasOwnProperty.call(pendingValues, name);
514
+ }
515
+ initSubgroupFields(layout, formData) {
516
+ layout.forEach((group) => {
517
+ group.subgroups.forEach((subgroup) => {
518
+ const index = this.subgroupFields.length;
519
+ const entry = { layout: subgroup, field: void 0, headerField: void 0, locked: false };
520
+ if (subgroup.hasSwitch) {
521
+ entry.field = `${SUBGROUP_FIELD_PREFIX}${index}`;
522
+ entry.locked = RCV.isExportSubgroupLocked(subgroup, formData);
523
+ formData[entry.field] = entry.locked || (this.hasPendingValue(entry.field) ? this.pendingValues[this.format][entry.field] === true : RCV.isExportSubgroupOn(subgroup, formData));
524
+ } else if (!this.usesSubgroupLabel(subgroup)) {
525
+ entry.headerField = `${SUBGROUP_HEADER_PREFIX}${index}`;
526
+ }
527
+ this.subgroupFields.push(entry);
528
+ });
529
+ });
530
+ }
531
+ initConfirmFields(settings, formData) {
532
+ settings.filter((setting) => RCV.isExportConfirmedPasswordSetting(setting)).forEach((setting) => {
533
+ const confirmField = `${CONFIRM_FIELD_PREFIX}${setting.name}`;
534
+ formData[confirmField] = this.hasPendingValue(confirmField) ? this.pendingValues[this.format][confirmField] : formData[setting.name];
535
+ this.confirmFields.push({ field: confirmField, setting });
536
+ });
537
+ }
538
+ // Settings whose values cannot be bound directly to a dropdown get a preset field; a custom or unlisted current value gets its own item.
539
+ initPresetFields(settings, formData) {
540
+ settings.forEach((setting) => {
541
+ const presets = RCV.createExportSettingPresets(setting, formData[setting.name], this.format, stringResources.stringResources);
542
+ if (presets) {
543
+ this.presetFields.push({ setting, field: `${PRESET_FIELD_PREFIX}${setting.name}`, ...presets });
544
+ }
545
+ });
546
+ }
547
+ // The editor of a setting is bound to its own field when the setting is edited through a preset.
548
+ getSettingFieldName(setting) {
549
+ return this.presetFields.find((entry) => entry.setting === setting)?.field ?? setting.name;
550
+ }
551
+ getPresetDataSource(presetField) {
552
+ const items = presetField.items.map((item) => ({ text: item.text, value: item.key }));
553
+ if (presetField.allowCustom) {
554
+ items.push({ text: stringResources.stringResources.exportDialogCustomOption, value: RCV.EXPORT_CUSTOM_PRESET_KEY });
555
+ }
556
+ return items;
557
+ }
558
+ // An empty preset value means that the setting is not sent, so the renderer uses its own default.
559
+ applyPresetKey(presetField, key) {
560
+ const value = RCV.getExportPresetValue(presetField.setting, presetField, key);
561
+ if (value !== void 0) {
562
+ this.getFormModel().set(presetField.setting.name, value);
563
+ }
564
+ }
565
+ onPresetChange(presetField, key) {
566
+ presetField.key = key;
567
+ this.applyPresetKey(presetField, key);
568
+ this.updateFieldVisibility();
569
+ const $custom = this.getFieldInput(presetField.setting.name);
570
+ if (key === RCV.EXPORT_CUSTOM_PRESET_KEY) {
571
+ $custom.trigger("focus");
572
+ } else if ($custom.length > 0) {
573
+ this.settingsForm.validator.validateInput($custom);
574
+ }
575
+ }
576
+ // Turning a switch on selects the first preset of settings without a value, so the switch is never on with nothing chosen.
577
+ selectDefaultPresets(subgroupField) {
578
+ this.presetFields.filter((entry) => subgroupField.layout.settings.includes(entry.setting)).forEach((entry) => {
579
+ if (!RCV.hasExportSettingValue(this.getFormModel().get(entry.setting.name))) {
580
+ this.getFormModel().set(entry.field, entry.items[0].key);
581
+ this.onPresetChange(entry, entry.items[0].key);
582
+ }
583
+ });
584
+ }
585
+ usesSubgroupLabel(subgroup) {
586
+ return RCV.usesExportSubgroupLabel(subgroup, this.format, stringResources.stringResources);
587
+ }
588
+ createGroupItems(group) {
589
+ let settings = group.settings;
590
+ const items = [];
591
+ if (group.name === "Paging") {
592
+ const pagingSettings = settings.filter((setting) => RCV.EXPORT_PAGING_SETTINGS.includes(setting.name));
593
+ if (pagingSettings.length > 0) {
594
+ this.pagingSettingNames = pagingSettings.map((setting) => setting.name);
595
+ settings = settings.filter((setting) => !RCV.EXPORT_PAGING_SETTINGS.includes(setting.name));
596
+ items.push(
597
+ this.createPageSelectionFormItem(this.pageRangeSelected),
598
+ this.createPageRangeFormItem(pagingSettings)
599
+ );
600
+ }
601
+ }
602
+ settings.forEach((setting) => this.pushSettingItems(items, setting));
603
+ group.subgroups.forEach((subgroup) => {
604
+ const entry = this.subgroupFields.find((candidate) => candidate.layout === subgroup);
605
+ if (entry.field) {
606
+ items.push(this.createSubgroupSwitchItem(entry));
607
+ } else if (entry.headerField) {
608
+ items.push(this.createSubgroupHeaderItem(entry));
609
+ }
610
+ subgroup.settings.forEach((setting) => {
611
+ const label = this.usesSubgroupLabel(subgroup) ? this.getSubgroupLabel(subgroup) : void 0;
612
+ this.pushSettingItems(items, setting, label);
613
+ });
614
+ });
615
+ return items;
616
+ }
617
+ pushSettingItems(items, setting, label) {
618
+ const item = this.createFormItem(setting);
619
+ if (label) {
620
+ item.label = label;
621
+ }
622
+ items.push(item);
623
+ const presetField = this.presetFields.find((entry) => entry.setting === setting);
624
+ if (presetField?.allowCustom) {
625
+ items.push(this.createCustomValueFormItem(setting));
626
+ }
627
+ const confirmField = this.confirmFields.find((entry) => entry.setting === setting);
628
+ if (confirmField) {
629
+ items.push(this.createConfirmFormItem(confirmField));
630
+ }
631
+ }
632
+ onFormChange(event) {
633
+ if (event.field === PAGE_SELECTION_FIELD || !this.currentValues) {
634
+ return;
635
+ }
636
+ if (event.field === PAGE_RANGE_FIELD) {
637
+ this.applyPageRange(event.value);
638
+ return;
639
+ }
640
+ const presetField = this.presetFields.find((entry) => entry.field === event.field);
641
+ if (presetField) {
642
+ if (presetField.key !== event.value) {
643
+ this.onPresetChange(presetField, event.value);
644
+ }
645
+ return;
646
+ }
647
+ this.currentValues[event.field] = event.value;
648
+ this.updateSameValueSettings(event.field, event.value);
649
+ this.updateFieldVisibility();
650
+ this.revalidateDifferingSetting(event.field);
651
+ const subgroupField = this.subgroupFields.find((entry) => entry.field && entry.field === event.field);
652
+ if (subgroupField && event.value === false) {
653
+ this.clearSubgroupSettings(subgroupField);
654
+ } else if (subgroupField) {
655
+ this.selectDefaultPresets(subgroupField);
656
+ }
657
+ const confirmField = this.confirmFields.find((entry) => entry.setting.name === event.field);
658
+ if (confirmField) {
659
+ this.revalidateConfirmField(confirmField);
660
+ }
661
+ }
662
+ // Settings that are not displayed because they take the value of the changed setting.
663
+ updateSameValueSettings(name, value) {
664
+ const settings = this.formats.find((item) => item.name === this.format)?.settings || [];
665
+ RCV.getExportSameValueSettings(name, settings).forEach((setting) => this.getFormModel().set(setting.name, value));
666
+ }
667
+ // Turning off a subgroup switch clears its settings, so hidden values are not applied on export.
668
+ clearSubgroupSettings(subgroupField) {
669
+ const model = this.getFormModel();
670
+ subgroupField.layout.settings.forEach((setting) => {
671
+ if (!setting.readOnly) {
672
+ model.set(setting.name, this.getDefaultValue(setting.type));
673
+ }
674
+ });
675
+ this.confirmFields.filter((entry) => subgroupField.layout.settings.includes(entry.setting)).forEach((entry) => model.set(entry.field, ""));
676
+ }
677
+ // Re-checks a confirmation the user already typed, because changing the password does not validate it.
678
+ revalidateConfirmField(confirmField) {
679
+ const $input = this.getFieldInput(confirmField.field);
680
+ if ($input.val() || $input.hasClass("k-invalid")) {
681
+ this.settingsForm.validator.validateInput($input);
682
+ }
683
+ }
684
+ validateSettingsForm() {
685
+ if (!this.settingsForm || this.settingsForm.validate()) {
686
+ return true;
687
+ }
688
+ this.$settingsContainer.find(".k-invalid").first().trigger("focus");
689
+ return false;
690
+ }
691
+ getValidationRules() {
692
+ return {
693
+ [REQUIRED_RULE]: (input) => this.validateRequired(input),
694
+ [CONFIRM_RULE]: (input) => this.validateConfirmation(input),
695
+ [PAGE_RANGE_RULE]: (input) => this.validatePageRange(input),
696
+ [DIFFER_RULE]: (input) => this.validateDifferingValue(input)
697
+ };
698
+ }
699
+ // Re-checks the setting that must differ from the changed one, because changing a value does not validate the other.
700
+ revalidateDifferingSetting(name) {
701
+ const partner = this.getExportSetting(name)?.mustDifferFrom;
702
+ if (!partner) {
703
+ return;
704
+ }
705
+ const $input = this.getFieldInput(partner);
706
+ if ($input.length > 0 && this.isFieldShown(partner) && ($input.val() || $input.hasClass("k-invalid"))) {
707
+ this.settingsForm.validator.validateInput($input);
708
+ }
709
+ }
710
+ validateDifferingValue(input) {
711
+ const setting = this.getExportSetting(input.attr("name"));
712
+ const other = setting?.mustDifferFrom ? this.getExportSetting(setting.mustDifferFrom) : void 0;
713
+ if (!other || !this.isFieldShown(setting.name) || !input.val() || input.val() !== String(this.getFormModel().get(other.name) ?? "")) {
714
+ return true;
715
+ }
716
+ input.attr(
717
+ kendo.attr(`${DIFFER_RULE}-msg`),
718
+ kendo.format(stringResources.stringResources.exportDialogMustDiffer, this.getSettingLabel(setting), this.getSettingLabel(other))
719
+ );
720
+ return false;
721
+ }
722
+ getExportSetting(name) {
723
+ return this.formats.find((item) => item.name === this.format)?.settings.find((candidate) => candidate.name === name);
724
+ }
725
+ validatePageRange(input) {
726
+ if (input.attr("name") !== PAGE_RANGE_FIELD || !this.isFieldShown(PAGE_RANGE_FIELD) || RCV.parseExportPageRange(input.val())) {
727
+ return true;
728
+ }
729
+ input.attr(kendo.attr(`${PAGE_RANGE_RULE}-msg`), stringResources.stringResources.exportDialogPageRangeInvalid);
730
+ return false;
731
+ }
732
+ // Invalid text keeps the last valid pages; validation blocks saving until the text is fixed.
733
+ applyPageRange(text) {
734
+ const range = RCV.parseExportPageRange(text);
735
+ if (!range) {
736
+ return;
737
+ }
738
+ const model = this.getFormModel();
739
+ if (this.pagingSettingNames.includes("StartPage")) {
740
+ model.set("StartPage", range.start);
741
+ }
742
+ if (this.pagingSettingNames.includes("EndPage")) {
743
+ model.set("EndPage", range.end);
744
+ }
745
+ }
746
+ validateRequired(input) {
747
+ const name = input.attr("name");
748
+ const setting = this.getExportSetting(name);
749
+ if (!setting || !(setting.required || setting.allowCustom) || !this.isFieldShown(name) || input.val() !== "") {
750
+ return true;
751
+ }
752
+ input.attr(kendo.attr(`${REQUIRED_RULE}-msg`), RCV.isExportPasswordSetting(name) ? stringResources.stringResources.exportDialogPasswordRequired : this.getSettingText(setting, "RequiredMessage") || stringResources.stringResources.exportDialogValueRequired);
753
+ return false;
754
+ }
755
+ validateConfirmation(input) {
756
+ const name = input.attr("name");
757
+ const confirmField = this.confirmFields.find((entry) => entry.field === name);
758
+ if (!confirmField || !this.isFieldShown(name)) {
759
+ return true;
760
+ }
761
+ const password = this.getFormModel().get(confirmField.setting.name) || "";
762
+ if ((input.val() || "") === password) {
763
+ return true;
764
+ }
765
+ input.attr(kendo.attr(`${CONFIRM_RULE}-msg`), stringResources.stringResources.exportDialogPasswordMismatch);
766
+ return false;
767
+ }
768
+ isFieldShown(name) {
769
+ const $field = this.getFormField(name);
770
+ return $field.length > 0 && !$field.hasClass("k-hidden");
771
+ }
772
+ getFormModel() {
773
+ return this.settingsForm.editable.options.model;
774
+ }
775
+ getFormField(name) {
776
+ return this.$settingsContainer.find("[data-container-for]").filter((index, element) => element.getAttribute("data-container-for") === name).closest(".k-form-field");
777
+ }
778
+ getFieldInput(name) {
779
+ return this.$settingsContainer.find("input").filter((index, element) => element.getAttribute("name") === name);
780
+ }
781
+ updateFieldVisibility() {
782
+ if (!this.settingsForm || !this.currentValues) {
783
+ return;
784
+ }
785
+ const values = this.currentValues;
786
+ const visibleSettings = /* @__PURE__ */ new Set();
787
+ const isSettingVisible = (setting) => RCV.isExportSettingVisible(setting, values) && (!this.pagingSettingNames.includes(setting.name) || this.pageRangeSelected);
788
+ const setSettingVisible = (setting, visible) => {
789
+ if (visible) {
790
+ visibleSettings.add(setting);
791
+ }
792
+ this.getFormField(this.getSettingFieldName(setting)).toggleClass("k-hidden", !visible);
793
+ const presetField = this.presetFields.find((entry) => entry.setting === setting);
794
+ if (presetField?.allowCustom) {
795
+ this.getFormField(setting.name).toggleClass("k-hidden", !visible || presetField.key !== RCV.EXPORT_CUSTOM_PRESET_KEY);
796
+ }
797
+ };
798
+ this.settingsLayout.forEach((group) => {
799
+ group.settings.forEach((setting) => setSettingVisible(setting, isSettingVisible(setting)));
800
+ group.subgroups.forEach((subgroup) => {
801
+ const entry = this.subgroupFields.find((candidate) => candidate.layout === subgroup);
802
+ const switchOn = !entry.field || values[entry.field] === true;
803
+ let anyVisible = false;
804
+ subgroup.settings.forEach((setting) => {
805
+ const visible = switchOn && isSettingVisible(setting);
806
+ anyVisible = anyVisible || visible;
807
+ setSettingVisible(setting, visible);
808
+ });
809
+ if (entry.field) {
810
+ this.getFormField(entry.field).toggleClass("k-hidden", !subgroup.settings.some(isSettingVisible));
811
+ } else if (entry.headerField) {
812
+ this.getFormField(entry.headerField).toggleClass("k-hidden", !anyVisible);
813
+ }
814
+ });
815
+ });
816
+ this.confirmFields.forEach((entry) => {
817
+ this.getFormField(entry.field).toggleClass("k-hidden", !visibleSettings.has(entry.setting));
818
+ });
819
+ this.getFormField(PAGE_RANGE_FIELD).toggleClass("k-hidden", !this.pageRangeSelected);
820
+ this.$settingsContainer.find(".k-form-fieldset").each((index, element) => {
821
+ const $fieldset = $(element);
822
+ $fieldset.toggleClass("k-hidden", $fieldset.find(".k-form-field").not(".k-hidden").length === 0);
823
+ });
824
+ }
825
+ selectDrawerFormat(format) {
826
+ const index = this.formats.findIndex((item) => item.name === format);
827
+ this.formatDrawer?.drawerItemsWrapper.find('[data-role="drawer-item"]').removeClass("k-selected").eq(index).addClass("k-selected");
404
828
  }
405
829
  renderSettingInfoIcons(settings) {
830
+ const describedSubgroups = this.subgroupFields.map((entry) => ({ entry, description: RCV.getExportSubgroupDescription(entry.layout, this.format, stringResources.stringResources) })).filter((item) => item.description);
406
831
  settings.forEach((setting) => {
407
- if (!setting.description) {
832
+ const description = this.getSettingText(setting, "Description") || setting.description;
833
+ if (!description || describedSubgroups.some((item) => item.entry.layout.settings.includes(setting))) {
408
834
  return;
409
835
  }
410
- const label = this.$settingsContainer.find(".k-form-label").filter((index, element) => element.htmlFor === setting.name);
411
- const info = $('<span class="trv-export-setting-info" tabindex="0" role="img"></span>').attr({
412
- "aria-label": setting.description,
413
- "data-description": setting.description
414
- }).append(kendo.ui.icon({ icon: "info-circle", type: "font" })).on("click", (event) => event.preventDefault());
415
- label.append(info);
836
+ const switchField = this.subgroupFields.find((entry) => entry.field && entry.layout.settings.length === 1 && entry.layout.settings[0] === setting);
837
+ const fieldName = switchField ? switchField.field : this.getSettingFieldName(setting);
838
+ this.findFieldLabel(fieldName).each((index, label) => appendInfoIcon($(label), description));
839
+ });
840
+ describedSubgroups.forEach(({ entry, description }) => {
841
+ const label = entry.field ? this.findFieldLabel(entry.field) : this.getFormField(entry.headerField).find(".trv-export-subgroup-title");
842
+ label.each((index, element) => appendInfoIcon($(element), description));
416
843
  });
417
844
  }
845
+ findFieldLabel(fieldName) {
846
+ return this.$settingsContainer.find(".k-form-label").filter((index, element) => element.htmlFor === fieldName);
847
+ }
418
848
  createPageSelectionFormItem(pageRangeSelected) {
419
849
  return {
420
850
  field: PAGE_SELECTION_FIELD,
@@ -428,47 +858,120 @@ class ExportDialog {
428
858
  }
429
859
  };
430
860
  }
861
+ createPageRangeFormItem(pagingSettings) {
862
+ return {
863
+ field: PAGE_RANGE_FIELD,
864
+ label: "",
865
+ editor: createPageRangeEditor,
866
+ editorOptions: {
867
+ enabled: !pagingSettings.some((setting) => setting.readOnly),
868
+ placeholder: stringResources.stringResources.exportDialogPageRangePlaceholder,
869
+ ariaLabel: stringResources.stringResources.exportDialogPageRangeLabel
870
+ },
871
+ validation: this.getValidationRules()
872
+ };
873
+ }
431
874
  onPageSelectionChange(pageRangeSelected, model) {
432
875
  model.set(PAGE_SELECTION_FIELD, pageRangeSelected);
433
876
  if (pageRangeSelected) {
434
- if (this.pagingSettingNames.includes("StartPage") && Number(model.get("StartPage")) <= 0) {
435
- model.set("StartPage", 1);
436
- }
877
+ this.applyPageRange(model.get(PAGE_RANGE_FIELD));
437
878
  } else {
438
- if (this.pagingSettingNames.includes("StartPage")) {
439
- model.set("StartPage", 0);
879
+ this.pagingSettingNames.forEach((name) => model.set(name, 0));
880
+ }
881
+ this.pageRangeSelected = pageRangeSelected;
882
+ this.updateFieldVisibility();
883
+ if (!pageRangeSelected) {
884
+ this.settingsForm.validator.validateInput(this.getFieldInput(PAGE_RANGE_FIELD));
885
+ }
886
+ }
887
+ createSubgroupSwitchItem(subgroupField) {
888
+ return {
889
+ field: subgroupField.field,
890
+ label: this.getSubgroupLabel(subgroupField.layout),
891
+ editor: createSwitchEditor,
892
+ editorOptions: {
893
+ enabled: !subgroupField.locked
440
894
  }
441
- if (this.pagingSettingNames.includes("EndPage")) {
442
- model.set("EndPage", 0);
895
+ };
896
+ }
897
+ createSubgroupHeaderItem(subgroupField) {
898
+ return {
899
+ field: subgroupField.headerField,
900
+ label: "",
901
+ editor: createSubgroupHeaderEditor,
902
+ editorOptions: {
903
+ text: this.getSubgroupLabel(subgroupField.layout)
443
904
  }
444
- }
445
- this.togglePagingSettings(pageRangeSelected);
905
+ };
446
906
  }
447
- togglePagingSettings(pageRangeSelected) {
448
- this.pagingSettingNames.forEach((name) => {
449
- this.$settingsContainer.find(`[data-container-for="${name}"]`).closest(".k-form-field").toggleClass("k-hidden", !pageRangeSelected);
450
- });
907
+ createConfirmFormItem(confirmField) {
908
+ return {
909
+ field: confirmField.field,
910
+ label: stringResources.stringResources.exportDialogConfirmPasswordLabel,
911
+ editor: createPasswordEditor,
912
+ editorOptions: {
913
+ enabled: true,
914
+ placeholder: stringResources.stringResources.exportDialogConfirmPasswordPlaceholder
915
+ },
916
+ validation: this.getValidationRules()
917
+ };
918
+ }
919
+ createCustomValueFormItem(setting) {
920
+ return {
921
+ field: setting.name,
922
+ label: this.getSettingText(setting, "CustomLabel") || "",
923
+ editor: createCustomValueEditor,
924
+ editorOptions: {
925
+ enabled: !setting.readOnly,
926
+ numeric: setting.type === "number",
927
+ min: RCV.getExportSettingRange(setting)?.min,
928
+ max: RCV.getExportSettingRange(setting)?.max,
929
+ placeholder: this.getSettingText(setting, "Placeholder") || stringResources.stringResources.exportDialogTextPlaceholder,
930
+ ariaLabel: this.getSettingLabel(setting)
931
+ },
932
+ validation: this.getValidationRules()
933
+ };
451
934
  }
452
935
  createFormItem(setting) {
936
+ const presetField = this.presetFields.find((entry) => entry.setting === setting);
937
+ const placeholder = this.getSettingText(setting, "Placeholder");
938
+ const hint = this.getSettingText(setting, "Hint");
453
939
  const item = {
454
- field: setting.name,
455
- label: this.getSettingLabel(setting.name),
940
+ field: this.getSettingFieldName(setting),
941
+ label: this.getSettingLabel(setting),
456
942
  editorOptions: {
457
- enabled: !setting.readOnly
943
+ enabled: !setting.readOnly,
944
+ placeholder: placeholder || void 0
458
945
  }
459
946
  };
460
- if (isPasswordSetting(setting.name)) {
947
+ if (hint) {
948
+ item.hint = hint;
949
+ }
950
+ if (setting.required) {
951
+ item.validation = this.getValidationRules();
952
+ }
953
+ const options = this.getSettingOptions(setting);
954
+ if (presetField) {
955
+ item.editor = createDropDownEditor;
956
+ item.editorOptions.dataSource = this.getPresetDataSource(presetField);
957
+ } else if (RCV.isExportPasswordSetting(setting.name)) {
461
958
  item.editor = createPasswordEditor;
462
- } else if (Array.isArray(setting.availableValues) && setting.availableValues.length > 0) {
959
+ item.editorOptions.placeholder = placeholder || stringResources.stringResources.exportDialogPasswordPlaceholder;
960
+ } else if (options && options.length === 2) {
961
+ item.editor = createRadioGroupEditor;
962
+ item.editorOptions.dataSource = options;
963
+ } else if (options) {
463
964
  item.editor = createDropDownEditor;
464
- item.editorOptions.dataSource = [...setting.availableValues];
965
+ item.editorOptions.dataSource = options;
465
966
  } else {
466
967
  switch (setting.type) {
467
968
  case "boolean":
468
- item.editor = createCheckBoxEditor;
969
+ item.editor = setting.useSwitch ? createSwitchEditor : createCheckBoxEditor;
469
970
  break;
470
971
  case "number":
471
972
  item.editor = createNumericEditor;
973
+ item.editorOptions.min = RCV.getExportSettingRange(setting)?.min;
974
+ item.editorOptions.max = RCV.getExportSettingRange(setting)?.max;
472
975
  break;
473
976
  default:
474
977
  item.editor = createTextEditor;
@@ -489,9 +992,12 @@ class ExportDialog {
489
992
  delete this.pendingValues[this.format];
490
993
  delete this.initialValues[this.format];
491
994
  const extension = this.formats.find((item) => item.name === this.format);
492
- this.buildSettingsForm(extension ? extension.settings : []);
995
+ this.buildSettingsForm(extension);
493
996
  }
494
997
  save() {
998
+ if (!this.validateSettingsForm()) {
999
+ return;
1000
+ }
495
1001
  this.capturePendingValues();
496
1002
  let saved = true;
497
1003
  this.formats.forEach((extension) => {
@@ -528,8 +1034,17 @@ class ExportDialog {
528
1034
  return "";
529
1035
  }
530
1036
  }
531
- getSettingLabel(name) {
532
- return stringResources.stringResources["exportSetting_" + name] || RCV.splitPascalCase(name);
1037
+ getSettingLabel(setting) {
1038
+ return RCV.getExportSettingLabel(setting, this.format, stringResources.stringResources);
1039
+ }
1040
+ getSettingText(setting, kind) {
1041
+ return RCV.getExportSettingText(setting, kind, this.format, stringResources.stringResources);
1042
+ }
1043
+ getSettingOptions(setting) {
1044
+ return RCV.getExportSettingOptions(setting, this.format, stringResources.stringResources);
1045
+ }
1046
+ getSubgroupLabel(subgroup) {
1047
+ return RCV.getExportSubgroupLabel(subgroup, this.format, stringResources.stringResources);
533
1048
  }
534
1049
  destroySettingsForm() {
535
1050
  if (this.settingsForm) {
@@ -538,6 +1053,11 @@ class ExportDialog {
538
1053
  }
539
1054
  this.currentValues = void 0;
540
1055
  this.pagingSettingNames = [];
1056
+ this.pageRangeSelected = false;
1057
+ this.settingsLayout = [];
1058
+ this.subgroupFields = [];
1059
+ this.confirmFields = [];
1060
+ this.presetFields = [];
541
1061
  if (this.$settingsContainer) {
542
1062
  this.$settingsContainer.empty();
543
1063
  }