gd-sprest-bs 10.2.4 → 10.2.7

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.
@@ -201,45 +201,54 @@ exports.ListForm.renderDisplayForm = function (props) {
201
201
  });
202
202
  var mapper = {};
203
203
  var rows = [];
204
- // See if we are rendering attachments
205
- var displayAttachments = typeof (props.displayAttachments) === "boolean" ? props.displayAttachments : true;
206
- if (props.info.attachments && displayAttachments) {
207
- // Render the attachments
208
- rows.push({
209
- columns: [{
210
- control: {
211
- id: "ListFormAttachments",
212
- label: "Attachments",
213
- name: "Attachments",
214
- onControlRendered: function (control) {
215
- var items = [];
216
- // Parse the attachments
217
- for (var i = 0; i < props.info.attachments.length; i++) {
218
- var attachment = props.info.attachments[i];
219
- // Add the item
220
- items.push({
221
- buttons: [{
222
- className: "me-1",
223
- href: attachment.ServerRelativeUrl,
224
- isSmall: true,
225
- text: attachment.FileName
226
- }]
204
+ // Method to generate the attachments row
205
+ var generateAttachmentsRow = function () {
206
+ // See if we are rendering attachments
207
+ var displayAttachments = typeof (props.displayAttachments) === "boolean" ? props.displayAttachments : true;
208
+ if (props.info.attachments && displayAttachments) {
209
+ // Render the attachments
210
+ rows.push({
211
+ columns: [{
212
+ control: {
213
+ id: "ListFormAttachments",
214
+ label: "Attachments",
215
+ name: "Attachments",
216
+ onControlRendered: function (control) {
217
+ var items = [];
218
+ // Parse the attachments
219
+ for (var i = 0; i < props.info.attachments.length; i++) {
220
+ var attachment = props.info.attachments[i];
221
+ // Add the item
222
+ items.push({
223
+ buttons: [{
224
+ className: "me-1",
225
+ href: attachment.ServerRelativeUrl,
226
+ isSmall: true,
227
+ text: attachment.FileName
228
+ }]
229
+ });
230
+ }
231
+ // Render a toolbar
232
+ core_1.Components.Toolbar({
233
+ el: control.el,
234
+ items: items
227
235
  });
228
236
  }
229
- // Render a toolbar
230
- core_1.Components.Toolbar({
231
- el: control.el,
232
- items: items
233
- });
234
237
  }
235
- }
236
- }]
237
- });
238
- }
238
+ }]
239
+ });
240
+ }
241
+ };
239
242
  // Parse the fields to render
240
243
  var fieldNames = getFieldsToRender(props);
241
244
  for (var i = 0; i < fieldNames.length; i++) {
242
245
  var fieldName = fieldNames[i];
246
+ // See if this is the attachment field
247
+ if (fieldName == "Attachments") {
248
+ // Generate the attachments row
249
+ generateAttachmentsRow();
250
+ continue;
251
+ }
243
252
  // Generate the control
244
253
  var control = renderDisplay(fieldName, props);
245
254
  if (control) {
@@ -432,158 +441,163 @@ exports.ListForm.renderEditForm = function (props) {
432
441
  label: "Loading the Form",
433
442
  size: 100
434
443
  });
435
- // See if we are rendering attachments
436
- var displayAttachments = typeof (props.displayAttachments) === "boolean" ? props.displayAttachments : true;
437
- if (props.info.attachments && displayAttachments) {
438
- // Set a default field
439
- // This will help w/ the onControlRendering/ed events to not have a null value for this parameter
440
- props.info.fields["Attachments"] = {};
441
- // Render the attachments
442
- rows.push({
443
- columns: [{
444
- control: {
445
- id: "ListFormAttachments",
446
- label: "Attachments",
447
- name: "Attachments",
448
- onControlRendered: function (control) {
449
- // Render a toolbar
450
- var toolbar = core_1.Components.Toolbar({
451
- el: control.el,
452
- items: [{
453
- buttons: [{
454
- className: "upload-btn me-1",
455
- isSmall: true,
456
- text: "Upload",
457
- type: core_1.Components.ButtonTypes.Secondary,
458
- onClick: function (btn, ev) {
459
- var elUpload = ev.currentTarget;
460
- // Display an upload dialog
461
- gd_sprest_1.Helper.ListForm.showFileDialog().then(function (fileInfo) {
462
- // Get the buttons and remove any duplicates
463
- var buttons = elUpload.parentElement.querySelectorAll(".btn");
464
- for (var i = 0; i < buttons.length; i++) {
465
- var button = buttons[i];
466
- // See if this is the associated button
467
- if (button.innerText.replace(/X$/, '') == fileInfo.name) {
468
- // Get the badge
469
- var badge = button.querySelector(".badge");
470
- if (badge) {
471
- // Remove the button
472
- badge.click();
444
+ // Generates the attachments row
445
+ var generateAttachmentsRow = function () {
446
+ // See if we are rendering attachments
447
+ var displayAttachments = typeof (props.displayAttachments) === "boolean" ? props.displayAttachments : true;
448
+ if (props.info.attachments && displayAttachments) {
449
+ // Set a default field
450
+ // This will help w/ the onControlRendering/ed events to not have a null value for this parameter
451
+ props.info.fields["Attachments"] = {};
452
+ // Render the attachments
453
+ rows.push({
454
+ columns: [{
455
+ control: {
456
+ id: "ListFormAttachments",
457
+ label: "Attachments",
458
+ name: "Attachments",
459
+ onControlRendered: function (control) {
460
+ // Render a toolbar
461
+ var toolbar = core_1.Components.Toolbar({
462
+ el: control.el,
463
+ items: [{
464
+ buttons: [{
465
+ className: "upload-btn me-1",
466
+ isSmall: true,
467
+ text: "Upload",
468
+ type: core_1.Components.ButtonTypes.Secondary,
469
+ onClick: function (btn, ev) {
470
+ var elUpload = ev.currentTarget;
471
+ // Display an upload dialog
472
+ gd_sprest_1.Helper.ListForm.showFileDialog().then(function (fileInfo) {
473
+ // Get the buttons and remove any duplicates
474
+ var buttons = elUpload.parentElement.querySelectorAll(".btn");
475
+ for (var i = 0; i < buttons.length; i++) {
476
+ var button = buttons[i];
477
+ // See if this is the associated button
478
+ if (button.innerText.replace(/X$/, '') == fileInfo.name) {
479
+ // Get the badge
480
+ var badge = button.querySelector(".badge");
481
+ if (badge) {
482
+ // Remove the button
483
+ badge.click();
484
+ }
485
+ break;
473
486
  }
474
- break;
475
487
  }
476
- }
477
- // Save the file information
478
- attachments.new.push(fileInfo);
479
- // Append the attachment
480
- elUpload.parentElement.appendChild(core_1.Components.Popover({
481
- isDismissible: true,
482
- type: core_1.Components.PopoverPlacements.Bottom,
483
- btnProps: {
484
- className: "me-1 file-attachment",
485
- isSmall: true,
486
- text: fileInfo.name
487
- },
488
- options: {
489
- content: core_1.Components.Button({
490
- data: fileInfo,
488
+ // Save the file information
489
+ attachments.new.push(fileInfo);
490
+ // Append the attachment
491
+ elUpload.parentElement.appendChild(core_1.Components.Popover({
492
+ isDismissible: true,
493
+ type: core_1.Components.PopoverPlacements.Bottom,
494
+ btnProps: {
495
+ className: "me-1 file-attachment",
491
496
  isSmall: true,
492
- text: "Remove",
493
- type: core_1.Components.ButtonTypes.Danger,
494
- onClick: function (btn, ev) {
495
- var fileName = btn.data.name;
496
- // Parse the array
497
- for (var i = 0; i < attachments.new.length; i++) {
498
- // See if this is the target attachment
499
- if (attachments.new[i].name == fileName) {
500
- // Remove this attachment
501
- attachments.new.splice(i, 1);
502
- break;
497
+ text: fileInfo.name
498
+ },
499
+ options: {
500
+ content: core_1.Components.Button({
501
+ data: fileInfo,
502
+ isSmall: true,
503
+ text: "Remove",
504
+ type: core_1.Components.ButtonTypes.Danger,
505
+ onClick: function (btn, ev) {
506
+ var fileName = btn.data.name;
507
+ // Parse the array
508
+ for (var i = 0; i < attachments.new.length; i++) {
509
+ // See if this is the target attachment
510
+ if (attachments.new[i].name == fileName) {
511
+ // Remove this attachment
512
+ attachments.new.splice(i, 1);
513
+ break;
514
+ }
503
515
  }
504
- }
505
- // Get the files
506
- var files = btnGroup.querySelectorAll(".btn.file-attachment");
507
- for (var i = 0; i < files.length; i++) {
508
- var file = files[i];
509
- // See if this is the target button
510
- if (file.innerText == fileName) {
511
- // Remove this popover
512
- file.parentElement.removeChild(file);
513
- break;
516
+ // Get the files
517
+ var files = btnGroup.querySelectorAll(".btn.file-attachment");
518
+ for (var i = 0; i < files.length; i++) {
519
+ var file = files[i];
520
+ // See if this is the target button
521
+ if (file.innerText == fileName) {
522
+ // Remove this popover
523
+ file.parentElement.removeChild(file);
524
+ break;
525
+ }
514
526
  }
515
527
  }
516
- }
517
- }).el
518
- }
519
- }).el);
520
- });
521
- }
522
- }]
523
- }]
524
- });
525
- // Get the button group
526
- var btnGroup = toolbar.el.querySelector(".btn-group");
527
- if (btnGroup) {
528
- // Parse the attachments
529
- for (var i = 0; i < props.info.attachments.length; i++) {
530
- var attachment = props.info.attachments[i];
531
- // Add the attachment
532
- btnGroup.appendChild(core_1.Components.Popover({
533
- isDismissible: true,
534
- type: core_1.Components.PopoverPlacements.Bottom,
535
- btnProps: {
536
- className: "me-1 file-attachment",
537
- isSmall: true,
538
- text: attachment.FileName,
539
- },
540
- options: {
541
- content: core_1.Components.Button({
542
- data: attachment,
528
+ }).el
529
+ }
530
+ }).el);
531
+ });
532
+ }
533
+ }]
534
+ }]
535
+ });
536
+ // Get the button group
537
+ var btnGroup = toolbar.el.querySelector(".btn-group");
538
+ if (btnGroup) {
539
+ // Parse the attachments
540
+ for (var i = 0; i < props.info.attachments.length; i++) {
541
+ var attachment = props.info.attachments[i];
542
+ // Add the attachment
543
+ btnGroup.appendChild(core_1.Components.Popover({
544
+ isDismissible: true,
545
+ type: core_1.Components.PopoverPlacements.Bottom,
546
+ btnProps: {
547
+ className: "me-1 file-attachment",
543
548
  isSmall: true,
544
- text: "Remove",
545
- type: core_1.Components.ButtonTypes.Danger,
546
- onClick: function (btn, ev) {
547
- var attachment = btn.data;
548
- // Add this file for deletion
549
- attachments.delete.push(attachment);
550
- // Get the files
551
- var files = btnGroup.querySelectorAll(".btn.file-attachment");
552
- for (var i_1 = 0; i_1 < files.length; i_1++) {
553
- var file = files[i_1];
554
- // See if this is the target button
555
- if (file.innerText == attachment.FileName) {
556
- // Remove this popover
557
- file.parentElement.removeChild(file);
558
- break;
549
+ text: attachment.FileName,
550
+ },
551
+ options: {
552
+ content: core_1.Components.Button({
553
+ data: attachment,
554
+ isSmall: true,
555
+ text: "Remove",
556
+ type: core_1.Components.ButtonTypes.Danger,
557
+ onClick: function (btn, ev) {
558
+ var attachment = btn.data;
559
+ // Add this file for deletion
560
+ attachments.delete.push(attachment);
561
+ // Get the files
562
+ var files = btnGroup.querySelectorAll(".btn.file-attachment");
563
+ for (var i_1 = 0; i_1 < files.length; i_1++) {
564
+ var file = files[i_1];
565
+ // See if this is the target button
566
+ if (file.innerText == attachment.FileName) {
567
+ // Remove this popover
568
+ file.parentElement.removeChild(file);
569
+ break;
570
+ }
559
571
  }
560
572
  }
561
- }
562
- }).el
563
- }
564
- }).el);
573
+ }).el
574
+ }
575
+ }).el);
576
+ }
565
577
  }
566
578
  }
567
579
  }
568
- }
569
- }]
570
- });
571
- }
580
+ }]
581
+ });
582
+ }
583
+ };
572
584
  // Parse the fields to render
573
585
  var fieldNames = getFieldsToRender(props);
574
586
  var _loop_1 = function (i) {
575
587
  var fieldName = fieldNames[i];
576
588
  var field = props.info.fields[fieldName];
589
+ // See if this is the attachment field
590
+ if (fieldName == "Attachments") {
591
+ // Generate the attachments row
592
+ generateAttachmentsRow();
593
+ return "continue";
594
+ }
577
595
  // Ensure the field exists
578
596
  if (field == null) {
579
597
  // Log
580
598
  console.error("[List Form] Field '" + fieldName + "' does not exist. Check the list or query.");
581
599
  return "continue";
582
600
  }
583
- // Skip the attachment field
584
- if (fieldName == "Attachments") {
585
- return "continue";
586
- }
587
601
  // See if the item exists
588
602
  value[fieldName] = null;
589
603
  if (props.info.item) {
@@ -878,6 +892,12 @@ exports.ListForm.renderEditForm = function (props) {
878
892
  }
879
893
  // Validate the form field and update the status flag
880
894
  var controlIsValid = formField.isValid();
895
+ // See if there is a custom method
896
+ if (formField.controlProps.onValidate) {
897
+ // Call the event
898
+ controlIsValid = formField.controlProps.onValidate(formField.controlProps, formField.getValue());
899
+ }
900
+ // Update the flag
881
901
  isValid = isValid && controlIsValid;
882
902
  }
883
903
  // Parse the custom controls