diff --git a/src/screen.js b/src/screen.js index 166b804e..a7e8f39f 100644 --- a/src/screen.js +++ b/src/screen.js @@ -826,6 +826,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; @@ -862,9 +864,6 @@ this._domain_parser = {}; this.pre_validate = false; this.tab = null; - // [Coog specific] used for group_sync - this.parent = null; - // end this.message_callback = null; this.switch_callback = null; this.group_changed_callback = null; @@ -1248,12 +1247,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); var views_add = function(view) { this.group.model.fields[name].views.add(view); }.bind(this); @@ -1276,6 +1275,7 @@ }, set current_record(record) { // [Coog specific] multi_mixed_view + var validate = this.current_record === null; var changed = this.current_record !== record; this.__current_record = record; if (this.message_callback){ @@ -1307,8 +1307,44 @@ this.tab.record_message(); } // [Coog specific] multi_mixed_view - if (this.parent && changed){ - this.parent.group_sync(this, this.current_record); + if (changed && this._multiview_form && + (this.current_view.view_type == 'tree')) { + var view = this._multiview_form; + var wgroup = view.widget_groups[this._multiview_group]; + this._sync_group(view, wgroup, this.current_record, validate); + } + }, + // [Coog specific] + // > multi_mixed_view see tryton/8fa02ed59d03aa52600fb8332973f6a88d46d8c0 + _sync_group: function(view, widgets_group, record, validate) { + if (!record) { + return ; + } + + var widget; + var to_sync = []; + var forms = widgets_group.slice(1); + + for (widget of forms) { + if (validate && !widget.validate()) { + return; + } + to_sync.push(widget); + } + + var new_record_fields = {}; + for (widget of to_sync) { + new_record_fields = {}; + for (var fname in widget.screen.model.fields) { + if (!(fname in record.model.fields)) { + new_record_fields[fname] = widget.screen.model.fields[fname].description; + } + } + if (new_record_fields) { + record.group.add_fields(new_record_fields); + } + widget.screen.current_record = record; + widget.display(); } }, load: function(ids, set_cursor, modified) { diff --git a/src/view/form.js b/src/view/form.js index ab312be1..9298cbfd 100644 --- a/src/view/form.js +++ b/src/view/form.js @@ -242,6 +242,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); }, @@ -3501,15 +3502,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.message_callback = this.record_label.bind(this); this.prm = this.screen.switch_view().done(function() { 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); + } + } }.bind(this)); if (attributes.add_remove) { @@ -3519,108 +3532,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 modified() { return this.screen.current_view.modified; }, @@ -3713,9 +3624,8 @@ 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) { + 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) { diff --git a/src/window.js b/src/window.js index 553f8ba2..d7a36456 100644 --- a/src/window.js +++ b/src/window.js @@ -157,6 +157,7 @@ this.screen.group.readonly); this._initial_value = null; + this.view_type = view_type; if (view_type == 'form') { var button_text; if (kwargs.new_) {