diff --git a/src/model.js b/src/model.js index da6f6e7d68..d75ca42451 100644 --- a/src/model.js +++ b/src/model.js @@ -120,8 +120,7 @@ } }; array.new_ = function(default_, id) { - var record = new Sao.Record(this.name, id); - record.model = this.model; + var record = new Sao.Record(this.model, id); record.group = this; if (default_) { record.default_get(); @@ -159,26 +158,26 @@ var idx = this.indexOf(record); if (record.id >= 0) { if (remove) { - if (record in this.record_deleted) { + if (this.record_deleted.indexOf(record) != -1) { this.record_deleted.splice( this.record_deleted.indexOf(record), 1); } this.record_removed.push(record); } else { - if (record in this.record_removed) { + if (this.record_removed.indexOf(record) != -1) { this.record_removed.splice( this.record_removed.indexOf(record), 1); } this.record_deleted.push(record); } } - if (record.parent) { - record.parent._changed.id = true; + if (record.group.parent) { + record.group.parent._changed.id = true; } if (modified) { record._changed.id = true; } - if (!(record.parent) || (record.id < 0) || force_remove) { + if (!(record.group.parent) || (record.id < 0) || force_remove) { this._remove(record); } record.group.changed(); @@ -190,6 +189,14 @@ var idx = this.indexOf(record); this.splice(idx, 1); }; + array.unremove = function(record) { + this.record_removed.splice(this.record_removed.indexOf(record), 1); + this.record_deleted.splice(this.record_deleted.indexOf(record), 1); + record.group.changed(); + record.group.root_group().screens.forEach(function(screen) { + screen.display(); + }); + }; array.changed = function() { if (!this.parent) { return; @@ -685,6 +692,12 @@ cancel: function() { this._loaded = {}; this._changed = {}; + }, + deleted: function() { + return this.group.record_deleted.indexOf(this) != -1; + }, + removed: function() { + return this.group.record_removed.indexOf(this) != -1; } }); @@ -782,8 +795,8 @@ }, get_context: function(record) { var context = jQuery.extend({}, record.get_context()); - if (record.parent) { - jQuery.extend(context, record.parent.get_context()); + if (record.group.parent) { + jQuery.extend(context, record.group.parent.get_context()); } // TODO eval context attribute return context; @@ -1302,7 +1315,7 @@ for (var i = 0, len = record._values[this.name].length; i < len; i++) { var record2 = group[i]; - if (!record2.deleted || !record2.removed) + if (!record2.deleted() || !record2.removed()) result.push(record2.get_on_change_value()); } return result; diff --git a/src/screen.js b/src/screen.js index 052a46b79e..93c9b017e5 100644 --- a/src/screen.js +++ b/src/screen.js @@ -5,6 +5,10 @@ Sao.ScreenContainer = Sao.class_(Object, { init: function(tab_domain) { + this.alternate_viewport = jQuery('
', { + 'class': 'screen-container' + }); + this.alternate_view = false; this.tab_domain = tab_domain || []; this.el = jQuery('
', { 'class': 'screen-container' @@ -109,8 +113,14 @@ } }, set: function(widget) { - this.content_box.children().detach(); - this.content_box.append(widget); + if (this.alternate_view) { + this.alternate_viewport.children().detach(); + // TODO test if widget is content_box widget + this.alternate_viewport.append(widget); + } else { + this.content_box.children().detach(); + this.content_box.append(widget); + } } }); @@ -124,6 +134,7 @@ this.view_to_load = jQuery.extend([], attributes.mode || ['tree', 'form']); this.views = []; + this.exclude_field = attributes.exclude_field; this.context = attributes.context || {}; this.new_group(); this.current_view = null; @@ -143,9 +154,9 @@ this.domain_parser = null; }, load_next_view: function() { - if (this.view_to_load) { + if (!jQuery.isEmptyObject(this.view_to_load)) { var view_id; - if (this.view_ids) { + if (!jQuery.isEmptyObject(this.view_ids)) { view_id = this.view_ids.shift(); } var view_type = this.view_to_load.shift(); @@ -263,11 +274,13 @@ }, set_group: function(group) { if (this.group) { + jQuery.extend(group.model.fields, this.group.model.fields); this.group.screens.splice( this.group.screens.indexOf(this), 1); } group.screens.push(this); this.group = group; + this.model = group.model; if (jQuery.isEmptyObject(group)) { this.current_record = null; } else { @@ -285,11 +298,19 @@ if (this.views) { this.search_active(['tree', 'graph', 'calendar'].indexOf( this.current_view.view_type) > -1); - for (var i = 0; i < this.views.length; i++) - if (this.views[i]) + for (var i = 0; i < this.views.length; i++) { + if (this.views[i]) { this.views[i].display(); + } + } } }, + display_next: function() { + // TODO + }, + display_previous: function() { + // TODO + }, default_row_activate: function() { if ((this.current_view.view_type == 'tree') && this.current_view.keyword_open) { @@ -394,6 +415,12 @@ // TODO test view modified return false; }, + unremove: function() { + var records = this.current_view.selected_records(); + records.forEach(function(record) { + record.group.unremove(record); + }); + }, remove: function(delete_, remove, force_remove) { var result = jQuery.Deferred(); var records = null; @@ -418,14 +445,14 @@ var prms = []; if (delete_) { records.forEach(function(record) { - if (record.parent) { - prms.push(record.parent.save()); + if (record.group.parent) { + prms.push(record.group.parent.save()); } - if (record in record.group.record_deleted) { + if (record.group.record_deleted.indexOf(record) != -1) { record.group.record_deleted.splice( record.group.record_deleted.indexOf(record), 1); } - if (record in record.group.record_removed) { + if (record.group.record_removed.indexOf(record) != -1) { record.group.record_removed.splice( record.group.record_removed.indexOf(record), 1); } @@ -443,7 +470,7 @@ return result; }, search_active: function(active) { - if (active && !this.parent) { + if (active && !this.group.parent) { if (!this.fields_view_tree) { this.model.execute('fields_view_get', [false, 'tree'], this.context) diff --git a/src/view.js b/src/view.js index cf41649791..78739120b1 100644 --- a/src/view.js +++ b/src/view.js @@ -134,9 +134,12 @@ 'width': child.getAttribute('width'), 'orientation': child.getAttribute('orientation'), 'float_time': child.getAttribute('float_time'), - 'pre_validate': child.getAttribute('pre_validate') == 1, 'completion': child.getAttribute('completion') == 1 }; + if (name == this.screen.exclude_field) { + // TODO is it really the way to do it + return; + } if (attributes.widget === null) { attributes.widget = model.fields[name].description.type; } @@ -276,6 +279,11 @@ this.record.load(this.children_field).done( add_children.bind(this)); } + if (this.record.deleted() || this.record.removed()) { + this.el.css('text-decoration', 'line-through'); + } else { + this.el.css('text-decoration', 'inherit'); + } }, toggle_row: function() { if (this.is_expanded()) { @@ -508,7 +516,8 @@ 'name': child.getAttribute('name'), 'widget': child.getAttribute('widget'), 'string': child.getAttribute('string'), - 'states': child.getAttribute('states') + 'states': child.getAttribute('states'), + 'mode': child.getAttribute('mode') }; ['readonly', 'invisible'].forEach(function(name) { if (child.getAttribute(name)) { @@ -580,7 +589,11 @@ var name = attributes.name; var text = attributes.string; if (name in model.fields) { - // TODO exclude field + if (name == this.screen.exclude_field) { + container.add( + Number(node.getAttribute('colspan') || 1)); + return; + } if (!attributes.states && (name in model.fields)) { attributes.states = model.fields[name].description.states; } @@ -642,8 +655,7 @@ }, _parse_field: function(model, node, container, attributes) { var name = attributes.name; - // TODO exclude field - if (!(name in model.fields)) { + if (!(name in model.fields) || name == this.screen.exclude_field) { container.add( Number(node.getAttribute('colspan') || 1)); return; @@ -780,6 +792,12 @@ } else { this.screen.button(button.attributes); } + }, + selected_records: function() { + if (this.screen.current_record) { + return [this.screen.current_record]; + } + return []; } }); @@ -948,6 +966,10 @@ return Sao.View.Form.Text; case 'many2one': return Sao.View.Form.Many2One; + case 'one2many': + return Sao.View.Form.One2Many; + case 'many2many': + return Sao.View.Form.Many2Many; } }; @@ -1519,4 +1541,401 @@ } }); + Sao.View.Form.One2Many = Sao.class_(Sao.View.Form.Widget, { + class_: 'form-one2many', + init: function(field_name, model, attributes) { + Sao.View.Form.One2Many._super.init.call(this, field_name, model, + attributes); + + this.el = jQuery('
', { + 'class': this.class_ + }); + this.menu = jQuery('
', { + 'class': this.class_ + '-menu' + }); + this.el.append(this.menu); + + if (attributes.add_remove) { + this.wid_text = jQuery('', { + type: 'input' + }); + // TODO add completion + + this.but_add = jQuery('