gd-sprest-bs 10.2.2 → 10.2.5

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