Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload on context screen change [PREVIEW] #340

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions sao/src/screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
this.el = jQuery('<div/>', {
'class': 'screen-container'
});
this.context_container = null;
this.filter_box = jQuery('<form/>', {
'class': 'filter-box hidden-xs'
}).submit(e => {
Expand Down Expand Up @@ -400,6 +401,19 @@
jQuery.isEmptyObject(this.bookmarks()));
this.bookmark_match();
},
set_context_screen: function(screen) {
this.context_container = jQuery('<fieldset/>');
this.context_container.append(screen.screen_container.el);
jQuery('<div/>', {
'class': 'row',
}).append(jQuery('<div/>', {
'class': 'col-md-12',
}).append(this.context_container))
.prependTo(this.filter_box);
},
set_context_active: function(active) {
this.context_container.prop('disabled', !active);
},
show_filter: function() {
this.filter_box.show();
if (this.tab) {
Expand Down Expand Up @@ -792,6 +806,7 @@
init: function(model_name, attributes) {
this.model_name = model_name;
this.windows = [];
this.context_screen = null;
this.model = new Sao.Model(model_name, attributes);
this.attributes = jQuery.extend({}, attributes);
this.view_ids = jQuery.extend([], attributes.view_ids);
Expand Down Expand Up @@ -825,7 +840,6 @@
attributes.tab_domain, attributes.show_filter);
this.breadcrumb = attributes.breadcrumb || [];

this.context_screen = null;
if (attributes.context_model) {
this.context_screen = new Sao.Screen(
attributes.context_model, {
Expand All @@ -835,12 +849,14 @@

this.context_screen_prm = this.context_screen.switch_view()
.then(() => {
jQuery('<div/>', {
'class': 'row'
}).append(jQuery('<div/>', {
'class': 'col-md-12'
}).append(this.context_screen.screen_container.el))
.prependTo(this.screen_container.filter_box);
this.screen_container.set_context_screen(
this.context_screen);
for (let field_widgets of
Object.values(this.context_screen.current_view.widgets)) {
for (let widget of field_widgets) {
widget.connect(() => this.screen_container.do_search());
}
}
return this.context_screen.new_(false).then(
// Set manually default to get context_screen_prm
// resolved when default is set.
Expand Down Expand Up @@ -1267,6 +1283,10 @@
window_.record_modified();
}
}
if (this.context_screen) {
this.screen_container.set_context_active(
!this.current_record || !this.modified());
}
if (display) {
return this.display();
}
Expand Down Expand Up @@ -1296,6 +1316,10 @@
window_.record_saved();
}
}
if (this.context_screen) {
this.screen_container.set_context_active(
!this.current_record || !this.modified());
}
},
update_resources: function(resources) {
for (const window_ of this.windows) {
Expand Down
30 changes: 28 additions & 2 deletions sao/src/view/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,8 @@ function hide_x2m_body(widget) {
focus: function() {
this.el.focus();
},
connect: function(callback) {
}
});

// [Coog] widget Source (engine)
Expand Down Expand Up @@ -2175,6 +2177,9 @@ function hide_x2m_body(widget) {
'readonly': 'readonly',
'name': this.attributes.name,
});
},
connect: function(callback) {
this.el.change(callback);
}
});

Expand Down Expand Up @@ -2379,6 +2384,9 @@ function hide_x2m_body(widget) {
}
return value;
},
connect: function(callback) {
this.input.change(callback);
}
});

Sao.View.Form.DateTime = Sao.class_(Sao.View.Form.Date, {
Expand Down Expand Up @@ -2471,6 +2479,9 @@ function hide_x2m_body(widget) {
set_readonly: function(readonly) {
Sao.View.Form.TimeDelta._super.set_readonly.call(this, readonly);
this.input.prop('readonly', readonly);
},
connect: function(callback) {
this.el.change(callback);
}
});

Expand Down Expand Up @@ -2757,7 +2768,10 @@ function hide_x2m_body(widget) {
set_readonly: function(readonly) {
Sao.View.Form.Selection._super.set_readonly.call(this, readonly);
this.select.prop('disabled', readonly);
}
},
connect: function(callback) {
this.select.change(callback);
},
});

Sao.View.Form.Boolean = Sao.class_(Sao.View.Form.Widget, {
Expand Down Expand Up @@ -2799,6 +2813,9 @@ function hide_x2m_body(widget) {
set_readonly: function(readonly) {
Sao.View.Form.Boolean._super.set_readonly.call(this, readonly);
this.input.prop('readonly', readonly);
},
connect: function(callback) {
this.input.change(callback);
}
});

Expand Down Expand Up @@ -2880,6 +2897,9 @@ function hide_x2m_body(widget) {
widget.css('min-height', this.el.height());
widget.css('max-height', this.el.height());
return widget;
},
connect: function(callback) {
this.input.change(callback);
}
});

Expand Down Expand Up @@ -3012,6 +3032,9 @@ function hide_x2m_body(widget) {
translate_widget_get: function(el) {
return this._normalize_markup(
el.find('div[contenteditable]').html());
},
connect: function(callback) {
this.group.focusout(callback);
}
});

Expand Down Expand Up @@ -3485,7 +3508,10 @@ function hide_x2m_body(widget) {
} else if (action == 'create') {
this.new_();
}
}
},
connect: function(callback) {
this.el.change(callback);
},
});

Sao.View.Form.One2One = Sao.class_(Sao.View.Form.Many2One, {
Expand Down
34 changes: 12 additions & 22 deletions tryton/tryton/gui/window/view_form/screen/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import logging
import urllib.parse
import xml.dom.minidom
from itertools import chain
from operator import itemgetter

from gi.repository import GLib, Gtk
Expand Down Expand Up @@ -48,6 +49,7 @@ def __init__(self, model_name, **attributes):
self.position = 0
self.offset = 0
self.windows = []
self.context_screen = None

self.readonly = attributes.get('readonly', False)
if not (MODELACCESS[model_name]['write']
Expand Down Expand Up @@ -85,29 +87,14 @@ def __init__(self, model_name, **attributes):
self.widget = self.screen_container.widget_get()
self.breadcrumb = attributes.get('breadcrumb') or []

self.context_screen = None
if attributes.get('context_model'):
self.context_screen = Screen(
attributes['context_model'], mode=['form'], context=context)
self.context_screen.parent_screen = self
self.context_screen.new()
context_widget = self.context_screen.widget

def walk_descendants(widget):
yield widget
if not hasattr(widget, 'get_children'):
return
for child in widget.get_children():
for widget in walk_descendants(child):
yield widget

for widget in reversed(list(walk_descendants(context_widget))):
if isinstance(widget, Gtk.Entry):
widget.connect_after(
'activate', self.screen_container.activate)
elif isinstance(widget, Gtk.CheckButton):
widget.connect_after(
'toggled', self.screen_container.activate)
ctx_widgets = self.context_screen.current_view.widgets.values()
for ctx_widget in chain.from_iterable(ctx_widgets):
ctx_widget.connect(self.screen_container.activate)

def remove_bin(widget):
assert isinstance(widget, (Gtk.ScrolledWindow, Gtk.Viewport))
Expand All @@ -126,10 +113,7 @@ def remove_bin(widget):
remove_bin(
self.context_screen.current_view.widget.get_children()[0])

self.screen_container.filter_vbox.pack_start(
context_widget, expand=False, fill=True, padding=0)
self.screen_container.filter_vbox.reorder_child(
context_widget, 0)
self.screen_container.set_context_screen(self.context_screen)
self.context_screen.widget.show()

self.__current_view = 0
Expand Down Expand Up @@ -454,6 +438,9 @@ def record_modified(self, display=True):
for window in self.windows:
if hasattr(window, 'record_modified'):
window.record_modified()
if self.context_screen:
self.screen_container.set_context_active(
not self.current_record or not self.modified())
if display:
self.display()

Expand All @@ -478,6 +465,9 @@ def record_saved(self):
for window in self.windows:
if hasattr(window, 'record_saved'):
window.record_saved()
if self.context_screen:
self.screen_container.set_context_active(
not self.current_record or not self.modified())

def update_resources(self, resources):
for window in self.windows:
Expand Down
4 changes: 4 additions & 0 deletions tryton/tryton/gui/window/view_form/view/form_gtk/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ def sig_icon_press(self, widget, icon_pos, event):
if icon_pos == Gtk.EntryIconPosition.PRIMARY:
self.open_()

def callback(self, callback):
if self.mnemonic_widget:
self.mnemonic_widget.connect('focus-out-event', callback)

def display(self):
super(Binary, self).display()
if not self.field:
Expand Down
3 changes: 3 additions & 0 deletions tryton/tryton/gui/window/view_form/view/form_gtk/calendar_.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def set_format(self):
self.view.screen.context.get('date_format'))
self.entry.props.format = format_

def connect(self, callback):
self.entry.connect(self._changed_signal, callback)

def display(self):
super(Date, self).display()
if self.field and self.record:
Expand Down
7 changes: 7 additions & 0 deletions tryton/tryton/gui/window/view_form/view/form_gtk/char.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ def get_client_value(self):
value = self.field.get_client(self.record)
return value

def connect(self, callback):
if self.autocomplete:
focus_entry = self.entry.get_child()
else:
focus_entry = self.entry
focus_entry.connect('focus-out-event', callback)

def display(self):
super(Char, self).display()
if self.autocomplete:
Expand Down
3 changes: 3 additions & 0 deletions tryton/tryton/gui/window/view_form/view/form_gtk/checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def _readonly_set(self, value):
def set_value(self):
self.field.set_client(self.record, self.widget.get_active())

def connect(self, callback):
self.widget.connect('toggled', callback)

def display(self):
super(CheckBox, self).display()
if not self.field:
Expand Down
3 changes: 3 additions & 0 deletions tryton/tryton/gui/window/view_form/view/form_gtk/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def update_img(self):
self.image.set_from_pixbuf(pixbuf)
return bool(value)

def connect(self, callback):
self.event.connect('drag_data_received', callback)

def display(self):
super(Image, self).display()
value = self.update_img()
Expand Down
3 changes: 3 additions & 0 deletions tryton/tryton/gui/window/view_form/view/form_gtk/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def get_client_value(self):
def width(self):
return self.attrs.get('width', 8)

def connect(self, callback):
self.entry.connect('focus-out-event', callback)

def display(self):
def set_symbol(entry, text):
if text:
Expand Down
3 changes: 3 additions & 0 deletions tryton/tryton/gui/window/view_form/view/form_gtk/many2one.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ def set_text(self, value):
self.wid_text.set_text(value)
reset_position(self.wid_text)

def connect(self, callback):
self.wid_text.connect('focus-out-event', callback)

def display(self):
self.changed = False
super(Many2One, self).display()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def get_value(self):
def set_value(self):
self.field.set_client(self.record, self.get_value())

def connect(self, callback):
selection = self.tree.get_selection()
selection.connect('changed', callback)

def display(self):
selection = self.tree.get_selection()
selection.handler_block_by_func(self.changed)
Expand Down
5 changes: 5 additions & 0 deletions tryton/tryton/gui/window/view_form/view/form_gtk/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ def set_text(self, value):
self.set_popdown_value(self.widget_combo, value)
self.widget_combo.handler_unblock_by_func(self.sig_changed_combo)

def connect(self, callback):
super().connect(callback)
child = self.widget_combo.get_child()
child.connect('focus-out-event', callback)

def display(self):
self.update_selection(self.record, self.field)
self.set_popdown(self.selection, self.widget_combo)
Expand Down
3 changes: 3 additions & 0 deletions tryton/tryton/gui/window/view_form/view/form_gtk/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def set_value(self):
value = (value, self.get_popdown_text(self.entry))
self.field.set_client(self.record, value)

def connect(self, callback):
self.entry.connect('changed', callback)

def display(self):
self.update_selection(self.record, self.field)
self.set_popdown(self.selection, self.entry)
Expand Down
3 changes: 3 additions & 0 deletions tryton/tryton/gui/window/view_form/view/form_gtk/textbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ def get_buffer(self, textview):
iter_end = buf.get_end_iter()
return buf.get_text(iter_start, iter_end, False)

def connect(self, callback):
self.textview.connect('focus-out-event', callback)

def display(self):
super(TextBox, self).display()
value = self.field and self.field.get(self.record)
Expand Down
3 changes: 3 additions & 0 deletions tryton/tryton/gui/window/view_form/view/form_gtk/timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def set_value(self):
def get_value(self):
return self.entry.get_text()

def connect(self, callback):
self.entry.connect('focus-out-event', callback)

def display(self):
super(TimeDelta, self).display()
if not self.field:
Expand Down
3 changes: 3 additions & 0 deletions tryton/tryton/gui/window/view_form/view/form_gtk/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ def _format_set(self):
raise ValueError(FORMAT_ERROR + attr)
functions[key[0]](key[1])

def connect(self, callback):
pass

def display(self):
if not self.field:
self._readonly_set(self.attrs.get('readonly', True))
Expand Down
Loading