@@ -2,82 +2,109 @@ pimcore.registerNS("neusta_pimcore_import_export.plugin.page.import");
22
33neusta_pimcore_import_export . plugin . page . import = Class . create ( {
44 initialize : function ( ) {
5- document . addEventListener ( pimcore . events . prepareDocumentTreeContextMenu , this . onPrepareDocumentTreeContextMenu . bind ( this ) ) ;
5+ document . addEventListener ( pimcore . events . preMenuBuild , this . preMenuBuild . bind ( this ) ) ;
66 } ,
77
8- onPrepareDocumentTreeContextMenu : function ( e ) {
8+ preMenuBuild : function ( e ) {
99 let menu = e . detail . menu ;
10- let document = e . detail . document ;
1110
12- menu . add ( new Ext . menu . Item ( {
13- text : t ( 'neusta_pimcore_import_export_import_menu_label' ) ,
14- iconCls : "pimcore_icon_import" ,
15- handler : function ( ) {
16- let uploadDialog = new Ext . Window ( {
17- title : t ( 'neusta_pimcore_import_export_import_dialog_title' ) ,
18- width : 600 ,
19- layout : 'fit' ,
20- modal : true ,
11+ menu . neusta_pimcore_import_export = {
12+ label : t ( 'neusta_pimcore_import_export_import_menu_label' ) ,
13+ iconCls : 'pimcore_icon_import' , // Pimcore-Icon für Konsistenz
14+ priority : 50 , // Position im Menü (höher = weiter oben)
15+ handler : this . openImportDialog . bind ( this ) ,
16+ noSubmenus : true // Kein Submenü, direkter Klick öffnet das Fenster
17+ } ;
18+ } ,
19+
20+ openImportDialog : function ( ) {
21+ let uploadDialog = new Ext . Window ( {
22+ title : t ( 'neusta_pimcore_import_export_import_dialog_title' ) ,
23+ width : 600 ,
24+ layout : 'fit' ,
25+ modal : true ,
26+ items : [
27+ new Ext . form . Panel ( {
28+ bodyPadding : 10 ,
2129 items : [
22- new Ext . form . Panel ( {
23- bodyPadding : 10 ,
24- items : [
25- {
26- xtype : 'filefield' ,
27- name : 'file' ,
28- width : 450 ,
29- fieldLabel : t ( 'neusta_pimcore_import_export_import_dialog_file_label' ) ,
30- labelWidth : 100 ,
31- allowBlank : false ,
32- buttonText : t ( 'neusta_pimcore_import_export_import_dialog_file_button' ) ,
33- accept : '.yaml,.yml'
34- } ,
35- {
36- xtype : 'checkbox' ,
37- name : 'overwrite' ,
38- fieldLabel : t ( 'neusta_pimcore_import_export_import_dialog_overwrite_label' ) ,
30+ {
31+ xtype : 'filefield' ,
32+ name : 'file' ,
33+ width : 450 ,
34+ fieldLabel : t ( 'neusta_pimcore_import_export_import_dialog_file_label' ) ,
35+ labelWidth : 100 ,
36+ allowBlank : false ,
37+ buttonText : t ( 'neusta_pimcore_import_export_import_dialog_file_button' ) ,
38+ accept : '.yaml,.yml'
39+ } ,
40+ {
41+ xtype : 'checkbox' ,
42+ name : 'overwrite' ,
43+ fieldLabel : t ( 'neusta_pimcore_import_export_import_dialog_overwrite_label' ) ,
44+ }
45+ ] ,
46+ buttons : [
47+ {
48+ text : 'Import' ,
49+ handler : function ( btn ) {
50+ let form = btn . up ( 'form' ) . getForm ( ) ;
51+ if ( ! form . isValid ( ) ) {
52+ return ;
3953 }
40- ] ,
41- buttons : [
42- {
43- text : 'Import' ,
44- handler : function ( btn ) {
45- let form = btn . up ( 'form' ) . getForm ( ) ;
46- if ( ! form . isValid ( ) ) {
47- return ;
48- }
4954
50- form . submit ( {
51- url : Routing . generate ( 'neusta_pimcore_import_export_page_import' ) ,
52- method : 'POST' ,
53- waitMsg : t ( 'neusta_pimcore_import_export_import_dialog_wait_message' ) ,
54- headers : {
55- 'X-Requested-With' : 'XMLHttpRequest' // ✅ important for AJAX-Requests
56- } ,
57- params : {
58- 'csrfToken' : parent . pimcore . settings [ "csrfToken" ]
59- } ,
60- success : function ( form , action ) {
61- let response = Ext . decode ( action . response . responseText ) ;
62- pimcore . helpers . showNotification ( t ( 'neusta_pimcore_import_export_import_dialog_notification_success' ) , response . message , 'success' ) ;
63- pimcore . globalmanager . get ( 'layout_document_tree' ) . tree . getStore ( ) . reload ( ) ;
64- uploadDialog . close ( ) ;
65- } ,
66- failure : function ( form , action ) {
67- let response = Ext . decode ( action . response . responseText ) ;
68- pimcore . helpers . showNotification ( t ( 'neusta_pimcore_import_export_import_dialog_notification_error' ) , response . message || 'Import failed' , 'error' ) ;
69- }
55+ form . submit ( {
56+ url : Routing . generate ( 'neusta_pimcore_import_export_page_import' ) ,
57+ method : 'POST' ,
58+ waitMsg : t ( 'neusta_pimcore_import_export_import_dialog_wait_message' ) ,
59+ headers : {
60+ 'X-Requested-With' : 'XMLHttpRequest' // ✅ important for AJAX-Requests
61+ } ,
62+ params : {
63+ 'csrfToken' : parent . pimcore . settings [ "csrfToken" ]
64+ } ,
65+ success : function ( form , action ) {
66+ let response = Ext . decode ( action . response . responseText ) ;
67+ // pimcore.helpers.showNotification(t('neusta_pimcore_import_export_import_dialog_notification_success'), response.message, 'success');
68+ let successDialog = new Ext . Window ( {
69+ title : t ( 'neusta_pimcore_import_export_import_dialog_notification_success' ) ,
70+ width : 300 ,
71+ height : 200 ,
72+ modal : true , // ✅ Modal = Benutzer muss interagieren
73+ layout : 'fit' ,
74+ items : [
75+ {
76+ xtype : 'panel' ,
77+ html : `${ response . message } ` ,
78+ }
79+ ] ,
80+ buttons : [
81+ {
82+ text : 'OK' ,
83+ handler : function ( ) {
84+ successDialog . close ( ) ;
85+ }
86+ }
87+ ]
7088 } ) ;
89+
90+ successDialog . show ( ) ;
91+
92+ pimcore . globalmanager . get ( 'layout_document_tree' ) . tree . getStore ( ) . reload ( ) ;
93+ uploadDialog . close ( ) ;
94+ } ,
95+ failure : function ( form , action ) {
96+ let response = Ext . decode ( action . response . responseText ) ;
97+ pimcore . helpers . showNotification ( t ( 'neusta_pimcore_import_export_import_dialog_notification_error' ) , response . message || 'Import failed' , 'error' ) ;
7198 }
72- }
73- ]
74- } )
99+ } ) ;
100+ }
101+ }
75102 ]
76- } ) ;
103+ } )
104+ ]
105+ } ) ;
77106
78- uploadDialog . show ( ) ;
79- }
80- } ) ) ;
107+ uploadDialog . show ( ) ;
81108 }
82109} ) ;
83110
0 commit comments