diff --git a/sao/src/common.js b/sao/src/common.js
index 41e0fadd78..40115b9136 100644
--- a/sao/src/common.js
+++ b/sao/src/common.js
@@ -127,7 +127,8 @@
return result;
};
- Sao.common.selection = function(title, values, alwaysask=false) {
+ Sao.common.selection = function(
+ title, values, alwaysask=false, default_=null) {
var prm = jQuery.Deferred();
if (jQuery.isEmptyObject(values)) {
prm.reject();
@@ -152,11 +153,14 @@
.prepend(jQuery('', {
'type': 'radio',
'name': 'selection-' + dialog.modal.attr('id'),
- 'value': i
+ 'value': i,
+ 'checked': values[keys[i]] == default_,
})))
.appendTo(dialog.body);
});
- dialog.body.find('input').first().prop('checked', true);
+ if (!default_) {
+ dialog.body.find('input').first().prop('checked', true);
+ }
jQuery('', {
'class': 'btn btn-link',
diff --git a/tryton/tryton/common/common.py b/tryton/tryton/common/common.py
index d2610a9998..b36ea9ab98 100644
--- a/tryton/tryton/common/common.py
+++ b/tryton/tryton/common/common.py
@@ -400,7 +400,7 @@ def get_sensible_widget(window):
return window
-def selection(title, values, alwaysask=False):
+def selection(title, values, alwaysask=False, default=None):
if not values or len(values) == 0:
return None
elif len(values) == 1 and (not alwaysask):
@@ -439,14 +439,18 @@ def selection(title, values, alwaysask=False):
model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_INT)
keys = list(values.keys())
keys.sort()
- i = 0
- for val in keys:
+ selected = None
+ for i, val in enumerate(keys):
model.append([str(val), i])
- i += 1
+ if default:
+ if values[keys[i]] == default:
+ selected = i
treeview.set_model(model)
treeview.connect('row-activated',
lambda x, y, z: dialog.response(Gtk.ResponseType.OK) or True)
+ if selected is not None:
+ treeview.get_selection().select_path(selected)
dialog.show_all()
response = dialog.run()