diff --git a/src/screen.js b/src/screen.js index a68a557d..db15b32f 100644 --- a/src/screen.js +++ b/src/screen.js @@ -817,6 +817,8 @@ this.search_count = 0; this.screen_container = new Sao.ScreenContainer( attributes.tab_domain); + this._multiview_form = null; + this._multiview_group = null; this.breadcrumb = attributes.breadcrumb || []; this.context_screen = null; @@ -851,9 +853,6 @@ this.fields_view_tree = {}; this._domain_parser = {}; this.pre_validate = false; - // [Coog specific] used for group_sync - this.parent = null; - // end this.switch_callback = null; }, get readonly() { @@ -1218,12 +1217,12 @@ if (this.group.parent) { this.order = null; } + this.group.add_fields(fields); if (group && group.length) { this.current_record = group[0]; } else { this.current_record = null; } - this.group.add_fields(fields); for (name in fields_views) { var views = fields_views[name]; for (const view of views) { @@ -1321,8 +1320,39 @@ } } // [Coog specific] multi_mixed_view - if (this.parent && changed){ - this.parent.group_sync(this, this.current_record); + if (changed){ + this._sync_group(); + } + }, + _sync_group: function() { + if (!this._multiview_form || (this.current_view.view_type != "tree")) { + return; + } + if (!this.current_record) { + return; + } + + var to_sync = []; + let [tree, ...forms] = this._multiview_form.widget_groups[this._multiview_group]; + for (const form of forms) { + if (form.screen.current_view.view_type != "form") { + continue; + } + to_sync.push(form); + } + + var new_record_fields = {}; + for (const form of to_sync) { + for (var fname in form.screen.model.fields) { + if (!(fname in this.current_record.model.fields)) { + new_record_fields[fname] = form.screen.model.fields[fname].description; + } + } + if (new_record_fields) { + this.current_record.group.add_fields(new_record_fields); + } + form.screen.current_record = this.current_record; + form.display(); } }, load: function(ids, set_cursor=true, modified=false, position=-1) { @@ -1929,6 +1959,10 @@ if (this.group.parent) { promises.push(this.group.parent.root_parent.reload()); } + if (this._multiview_form) { + var root_parent = this.current_record.root_parent; + this._multiview_form.screen.reload([root_parent.id]); + } return jQuery.when.apply(jQuery, promises).then(() => { this.display(); }); diff --git a/src/view/form.js b/src/view/form.js index 08ea433d..504b0a44 100644 --- a/src/view/form.js +++ b/src/view/form.js @@ -285,6 +285,7 @@ function eval_pyson(value){ this.notebooks = []; this.expandables = []; this.containers = []; + this.widget_groups = {}; this.widget_id = 0; Sao.View.Form._super.init.call(this, view_id, screen, xml); if (this.attributes.creatable) { @@ -3588,15 +3589,27 @@ function eval_pyson(value){ pre_validate: attributes.pre_validate, breadcrumb: breadcrumb, }); - // [Coog specific] - // > multi_mixed_view see tryton/8fa02ed59d03aa52600fb8332973f6a88d46d8c0 - if (attributes.group) - this.screen.parent = this; this.screen.pre_validate = attributes.pre_validate == 1; this.screen.windows.push(this); this.prm = this.screen.switch_view().done(() => { this.content.append(this.screen.screen_container.el); + + // [Coog Specific] + var wgroup; + if (attributes.group) { + this.screen._multiview_form = view; + this.screen._multiview_group = attributes.group; + if (!(attributes.group in view.widget_groups)) { + view.widget_groups[attributes.group] = []; + } + wgroup = view.widget_groups[attributes.group]; + if (this.screen.current_view.view_type == 'tree') { + wgroup.unshift(this); + } else { + wgroup.push(this); + } + } }); if (attributes.add_remove) { @@ -3606,108 +3619,6 @@ function eval_pyson(value){ this.but_switch.prop('disabled', this.screen.number_of_views <= 0); }, - // [Coog specific] - // > multi_mixed_view see tryton/8fa02ed59d03aa52600fb8332973f6a88d46d8c0 - group_sync: function(screen, current_record){ - if (this.attributes.mode == 'form') - return; - if (!this.view || !this.view.widgets) - return; - - function is_compatible(screen, record){ - if (!screen.current_view) - return false; - - return (!(screen.current_view.view_type == 'form' && - record && - screen.model_name != record.model.name)); - } - - var key; - var record; - var widget; - var widgets = this.view.widgets[this.field_name]; - var to_sync = []; - - for (var j = 0; j < widgets.length; j++){ - widget = widgets[j]; - if (!widget.hasOwnProperty('attributes')){ - return; - } - - if (widget == this || - widget.attributes.group != this.attributes.group || - !widget.hasOwnProperty('screen')){ - continue; - } - - if (widget.screen.current_record == current_record){ - continue; - } - - record = current_record; - if (!is_compatible(widget.screen, record)) - record = null; - if (!widget.validate()) - return; - - to_sync.push({'widget': widget, 'record': record}); - } - widget = null; - var to_display = null; - var to_display_prm = jQuery.when(); - var record_load_promises, display_prm; - - function display_form(widget, record) { - return function () { - widget.display(widget.record, widget.field); - }; - } - - for (var i = 0; i < to_sync.length; i++){ - widget = to_sync[i].widget; - record = to_sync[i].record; - record_load_promises = []; - - if (!widget.screen.current_view) - continue; - - if (widget.screen.current_view.view_type == 'form' && - record && - widget.screen.group.model.name == record.group.model.name){ - var fields = widget.screen.group.model.fields; - var ret = []; - for(var name in fields){ - ret[name] = fields[name].description; - } - record.group.model.add_fields(ret); - - for (var field_name in fields) { - if (!fields.hasOwnProperty(field_name)) { - continue; - } - record_load_promises.push(record.load(field_name)); - } - } - - widget.screen.current_record = record; - display_prm = jQuery.when.apply(jQuery, record_load_promises); - display_prm.done(display_form(widget, record).bind(this)); - if (record){ - to_display = widget; - to_display_prm = display_prm; - } - } - if (to_display) { - to_display_prm.done(function() { - for (var j in to_display.view.containers) { - var container = widget.view.containers[j]; - container.resize(); - } - to_display.display(to_display.record, to_display.field); - }); - } - }, get_access: function(type) { var model = this.attributes.relation; if (model) { @@ -3844,10 +3755,9 @@ function eval_pyson(value){ // [Coog specific] // > multi_mixed_view see tryton/8fa02ed59d03aa52600fb8332973f6a88d46d8c0 - if (this.attributes.group && this.attributes.mode == 'form'){ - if (!this.screen.current_record) - this.set_invisible(true); - }else if (new_group && new_group != this.screen.group) { + if (this.attributes.group && this.attributes.mode == 'form') { + this.set_invisible(!this.visible); + } else if (new_group && new_group != this.screen.group) { this.screen.set_group(new_group); if ((this.screen.current_view.view_type == 'tree') && this.screen.current_view.editable) {