|
434 | 434 | <button type="button" class="btn btn-xs btn-default disabled" id="modifica_iva_righe" onclick="modificaIvaRighe(getSelectData());"> |
435 | 435 | <i class="fa fa-percent"></i> '.tr('Modifica IVA').' |
436 | 436 | </button> |
| 437 | +
|
| 438 | + <button type="button" class="btn btn-xs btn-primary disabled" id="copia_righe" onclick="copiaRighe(getSelectData());" title="'.tr('Copia righe selezionate negli appunti').'"> |
| 439 | + <i class="fa fa-clipboard"></i> '.tr('Copia').' |
| 440 | + </button> |
| 441 | +
|
| 442 | + <button type="button" class="btn btn-xs btn-primary" id="incolla_righe" onclick="incollaRighe();" title="'.tr('Incolla righe dagli appunti').'"> |
| 443 | + <i class="fa fa-paste"></i> '.tr('Incolla').' |
| 444 | + </button> |
| 445 | + </div>'; |
| 446 | +} |
| 447 | +if (!$block_edit && sizeof($righe) == 0) { |
| 448 | + echo ' |
| 449 | + <div class="btn-group"> |
| 450 | + <button type="button" class="btn btn-xs btn-primary" id="incolla_righe" onclick="incollaRighe();" title="'.tr('Incolla righe dagli appunti').'"> |
| 451 | + <i class="fa fa-paste"></i> '.tr('Incolla').' |
| 452 | + </button> |
437 | 453 | </div>'; |
438 | 454 | } |
439 | 455 | echo ' |
@@ -609,13 +625,15 @@ function duplicaRiga(id) { |
609 | 625 | $("#confronta_righe").removeClass("disabled"); |
610 | 626 | $("#aggiorna_righe").removeClass("disabled"); |
611 | 627 | $("#modifica_iva_righe").removeClass("disabled"); |
| 628 | + $("#copia_righe").removeClass("disabled"); |
612 | 629 | $("#elimina").addClass("disabled"); |
613 | 630 | } else { |
614 | 631 | $("#elimina_righe").addClass("disabled"); |
615 | 632 | $("#duplica_righe").addClass("disabled"); |
616 | 633 | $("#confronta_righe").addClass("disabled"); |
617 | 634 | $("#aggiorna_righe").addClass("disabled"); |
618 | 635 | $("#modifica_iva_righe").addClass("disabled"); |
| 636 | + $("#copia_righe").addClass("disabled"); |
619 | 637 | $("#elimina").removeClass("disabled"); |
620 | 638 | } |
621 | 639 | }); |
@@ -702,4 +720,107 @@ function modificaIvaRighe(righe) { |
702 | 720 | openModal("'.tr('Modifica IVA').'", "'.$module->fileurl('modals/modifica_iva.php').'?id_module=" + globals.id_module + "&id_record=" + globals.id_record + "&righe=" + righe.join(',')); |
703 | 721 | } |
704 | 722 | } |
| 723 | +
|
| 724 | +function copiaRighe(righe) { |
| 725 | + if (righe.length === 0) { |
| 726 | + return; |
| 727 | + } |
| 728 | +
|
| 729 | + $.ajax({ |
| 730 | + url: globals.rootdir + "/actions.php", |
| 731 | + type: "POST", |
| 732 | + dataType: "json", |
| 733 | + data: { |
| 734 | + id_module: globals.id_module, |
| 735 | + id_record: globals.id_record, |
| 736 | + op: "get_righe_data", |
| 737 | + righe: righe, |
| 738 | + }, |
| 739 | + success: function (response) { |
| 740 | + if (response && response.data) { |
| 741 | + navigator.clipboard.writeText(JSON.stringify(response.data)).then(function() { |
| 742 | + swal({ |
| 743 | + title: "'.tr('Righe copiate!').'", |
| 744 | + text: "'.tr('Le righe selezionate sono state copiate negli appunti').'", |
| 745 | + type: "success", |
| 746 | + timer: 2000, |
| 747 | + showConfirmButton: false |
| 748 | + }); |
| 749 | + }).catch(function(err) { |
| 750 | + swal({ |
| 751 | + title: "'.tr('Errore').'", |
| 752 | + text: "'.tr('Impossibile copiare negli appunti').': " + err, |
| 753 | + type: "error" |
| 754 | + }); |
| 755 | + }); |
| 756 | + } |
| 757 | + }, |
| 758 | + error: function() { |
| 759 | + swal({ |
| 760 | + title: "'.tr('Errore').'", |
| 761 | + text: "'.tr('Errore durante il recupero dei dati delle righe').'", |
| 762 | + type: "error" |
| 763 | + }); |
| 764 | + } |
| 765 | + }); |
| 766 | +} |
| 767 | +
|
| 768 | +function incollaRighe() { |
| 769 | + navigator.clipboard.readText().then(function(text) { |
| 770 | + try { |
| 771 | + let righe_data = JSON.parse(text); |
| 772 | +
|
| 773 | + swal({ |
| 774 | + title: "'.tr('Incollare le righe?').'", |
| 775 | + html: "'.tr('Sei sicuro di voler incollare').' " + righe_data.length + " '.tr('righe in questo documento?').'", |
| 776 | + type: "warning", |
| 777 | + showCancelButton: true, |
| 778 | + confirmButtonText: "'.tr('Sì').'" |
| 779 | + }).then(function () { |
| 780 | + $.ajax({ |
| 781 | + url: globals.rootdir + "/actions.php", |
| 782 | + type: "POST", |
| 783 | + dataType: "json", |
| 784 | + data: { |
| 785 | + id_module: globals.id_module, |
| 786 | + id_record: globals.id_record, |
| 787 | + op: "paste_righe", |
| 788 | + righe_data: JSON.stringify(righe_data), |
| 789 | + }, |
| 790 | + success: function (response) { |
| 791 | + renderMessages(); |
| 792 | + caricaRighe(null); |
| 793 | + swal({ |
| 794 | + title: "'.tr('Righe incollate!').'", |
| 795 | + text: "'.tr('Le righe sono state incollate con successo').'", |
| 796 | + type: "success", |
| 797 | + timer: 2000, |
| 798 | + showConfirmButton: false |
| 799 | + }); |
| 800 | + }, |
| 801 | + error: function() { |
| 802 | + renderMessages(); |
| 803 | + swal({ |
| 804 | + title: "'.tr('Errore').'", |
| 805 | + text: "'.tr('Errore durante l\'incollaggio delle righe').'", |
| 806 | + type: "error" |
| 807 | + }); |
| 808 | + } |
| 809 | + }); |
| 810 | + }).catch(swal.noop); |
| 811 | + } catch (e) { |
| 812 | + swal({ |
| 813 | + title: "'.tr('Errore').'", |
| 814 | + text: "'.tr('I dati negli appunti non sono validi').'", |
| 815 | + type: "error" |
| 816 | + }); |
| 817 | + } |
| 818 | + }).catch(function(err) { |
| 819 | + swal({ |
| 820 | + title: "'.tr('Errore').'", |
| 821 | + text: "'.tr('Impossibile leggere dagli appunti').': " + err, |
| 822 | + type: "error" |
| 823 | + }); |
| 824 | + }); |
| 825 | +} |
705 | 826 | </script>'; |
0 commit comments