(i, holder)
| 576 | } |
| 577 | |
| 578 | _createCopyButton (i, holder) { |
| 579 | const button = this.getButton(this.getItemTitle(), 'copy', 'button_copy_row_title', [this.getItemTitle()]) |
| 580 | const schema = this.schema |
| 581 | button.classList.add('copy', 'json-editor-btntype-copy') |
| 582 | button.setAttribute('data-i', i) |
| 583 | button.addEventListener('click', e => { |
| 584 | const value = this.getValue() |
| 585 | e.preventDefault() |
| 586 | e.stopPropagation() |
| 587 | const i = e.currentTarget.getAttribute('data-i') * 1 |
| 588 | |
| 589 | value.forEach((row, j) => { |
| 590 | if (j === i) { |
| 591 | let duplicatedRow = (typeof row === 'object' && row !== null) ? { ...row } : row |
| 592 | /* Force generation of new UUID if the item has been cloned. */ |
| 593 | if (schema.items.type === 'string' && schema.items.format === 'uuid') { |
| 594 | duplicatedRow = generateUUID() |
| 595 | } else if (schema.items.type === 'object' && schema.items.properties) { |
| 596 | for (const key of Object.keys(duplicatedRow)) { |
| 597 | if (schema.items.properties && schema.items.properties[key] && schema.items.properties[key].format === 'uuid') { |
| 598 | duplicatedRow[key] = generateUUID() |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | value.push(duplicatedRow) |
| 603 | } |
| 604 | }) |
| 605 | |
| 606 | this.setValue(value) |
| 607 | this.refreshValue(true) |
| 608 | this.onChange(true) |
| 609 | this.jsoneditor.trigger('copyRow', this.rows[i - 1]) |
| 610 | }) |
| 611 | |
| 612 | holder.appendChild(button) |
| 613 | return button |
| 614 | } |
| 615 | |
| 616 | _createMoveUpButton (i, holder) { |
| 617 | const button = this.getButton('', (this.schema.format === 'tabs-top' ? 'moveleft' : 'moveup'), 'button_move_up_title') |
no test coverage detected