Prevent the CSV import and export windows from being clicked on multiple times

Closes #14205
This commit is contained in:
Cédric Krier
2025-08-28 19:20:03 +02:00
parent 2ae56ac164
commit 91b88aed85
4 changed files with 27 additions and 13 deletions
+20 -12
View File
@@ -1466,17 +1466,16 @@
'class': 'btn btn-link',
'type': 'button',
'title': Sao.i18n.gettext("Cancel"),
}).text(Sao.i18n.gettext("Cancel")).click(() => {
this.response('RESPONSE_CANCEL');
}).text(Sao.i18n.gettext("Cancel")).on('click', (evt) => {
this.response(evt, 'RESPONSE_CANCEL');
}).appendTo(this.dialog.footer);
jQuery('<button/>', {
'class': 'btn btn-primary',
'type': 'submit',
'title': Sao.i18n.gettext("Import"),
}).text(Sao.i18n.gettext("Import")).click(e => {
e.preventDefault();
this.response('RESPONSE_OK');
}).text(Sao.i18n.gettext("Import")).on('click', (evt) => {
this.response(evt, 'RESPONSE_OK');
}).appendTo(this.dialog.footer);
jQuery('<button/>', {
@@ -1758,7 +1757,10 @@
}
}
},
response: function(response_id) {
response: function(evt, response_id) {
evt.preventDefault();
let button = jQuery(evt.currentTarget);
button.prop('disabled', true);
if(response_id == 'RESPONSE_OK') {
var fields = [];
this.fields_selected.children('li').each((i, field_el) => {
@@ -1768,6 +1770,8 @@
if(fname) {
this.import_csv(fname, fields).then(() => {
this.destroy();
}, () => {
button.prop('disabled', false);
});
} else {
this.destroy();
@@ -1821,17 +1825,16 @@
'class': 'btn btn-link',
'type': 'button',
'title': Sao.i18n.gettext("Close"),
}).text(Sao.i18n.gettext("Close")).click(() => {
this.response('RESPONSE_CLOSE');
}).text(Sao.i18n.gettext("Close")).on('click', (evt) => {
this.response(evt, 'RESPONSE_CLOSE');
}).appendTo(this.dialog.footer);
jQuery('<button/>', {
'class': 'btn btn-primary',
'type': 'submit',
'title': Sao.i18n.gettext("Save As..."),
}).text(Sao.i18n.gettext("Save As...")).click(e => {
e.preventDefault();
this.response('RESPONSE_OK');
}).text(Sao.i18n.gettext("Save As...")).on('click', (evt) => {
this.response(evt, 'RESPONSE_OK');
}).appendTo(this.dialog.footer);
this.info_bar = new Sao.Window.InfoBar();
@@ -2286,7 +2289,10 @@
Sao.common.ICONFACTORY.get_icon_img('tryton-drag')
).appendTo(this.fields_selected);
},
response: function(response_id) {
response: function(evt, response_id) {
evt.preventDefault();
let button = jQuery(evt.currentTarget);
button.prop('disabled', true);
this.info_bar.clear();
if(response_id == 'RESPONSE_OK') {
var fields = [];
@@ -2339,6 +2345,8 @@
}
prm.then(data => {
this.export_csv(data, paths, header);
}).always(() => {
button.prop('disabled', false);
});
} else {
this.destroy();
+5 -1
View File
@@ -5,7 +5,7 @@ import locale
import os
import sys
from gi.repository import Gdk, GObject, Gtk
from gi.repository import Gdk, GLib, GObject, Gtk
from tryton.common import IconFactory, RPCExecute
from tryton.config import TRYTON_ICON
@@ -318,3 +318,7 @@ class WinCSV(NoModal):
def hide(self):
self.dialog.hide()
def response(self, dialog, response):
dialog.set_sensitive(False)
GLib.idle_add(lambda: dialog.set_sensitive(True) or False)
+1
View File
@@ -360,6 +360,7 @@ class WinExport(WinCSV, InfoBar):
self.model2.append((string_, name))
def response(self, dialog, response):
super().response(dialog, response)
self.info_bar_clear()
if response in {Gtk.ResponseType.OK, Gtk.ResponseType.ACCEPT}:
fields = []
+1
View File
@@ -200,6 +200,7 @@ class WinImport(WinCSV):
self.model2.clear()
def response(self, dialog, response):
super().response(dialog, response)
if response == Gtk.ResponseType.OK:
fields = []
iter = self.model2.get_iter_first()