diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 2d27b380386..97d2fcf57a7 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -2382,6 +2382,19 @@ .kitten-mode-activated > * { opacity: 0.7; } +.kitten-mode-activated .oe_footer a { + background-image: url(http://www.risacher.com/la-rache/zfiles/la-rache.png); + font-size: 1px; + letter-spacing: -1px; + color: transparent; + display: inline-block; + height: 15px; + width: 80px; + vertical-align: top; +} +.kitten-mode-activated .oe_footer a span { + display: none; +} div.ui-widget-overlay { background: black; diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index 52b28b7da4f..c5197743acd 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -1879,6 +1879,19 @@ $sheet-max-width: 860px background-attachment: fixed >* opacity: 0.70 + + .oe_footer a + background-image: url(http://www.risacher.com/la-rache/zfiles/la-rache.png) + font-size: 1px + letter-spacing: -1px + color: transparent + display: inline-block + height: 15px + width: 80px + vertical-align: top + + span + display: none // }}} div.ui-widget-overlay diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index d10990b1717..b090c1c18ec 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -336,6 +336,20 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM self.$element.add(self.$buttons).removeClass('oe_form_dirty'); }); }, + /** + * Loads and sets up the default values for the model as the current + * record + * + * @return {$.Deferred} + */ + load_defaults: function () { + var keys = _.keys(this.fields_view.fields); + if (keys.length) { + return this.dataset.default_get(keys) + .pipe(this.on_record_loaded); + } + return this.on_record_loaded({}); + }, on_form_changed: function() { this.trigger("view_content_has_changed"); }, @@ -608,12 +622,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM this.set({mode: "edit"}); return $.when(this.has_been_loaded).pipe(function() { if (self.can_be_discarded()) { - var keys = _.keys(self.fields_view.fields); - if (keys.length) { - return self.dataset.default_get(keys) - .pipe(self.on_record_loaded); - } - return self.on_record_loaded({}); + return self.load_defaults(); } }); }, diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js index 93b7d38e3bb..bad3f939db2 100644 --- a/addons/web/static/src/js/view_list_editable.js +++ b/addons/web/static/src/js/view_list_editable.js @@ -163,7 +163,10 @@ openerp.web.list_editable = function (instance) { */ startEdition: function (record) { var self = this; - if (!record) { + var item = false; + if (record) { + item = record.attributes; + } else { var attrs = {id: false}; _(this.columns).chain() .filter(function (x) { return x.tag === 'field'}) @@ -182,7 +185,7 @@ openerp.web.list_editable = function (instance) { record: record.attributes, cancel: false }, function () { - return self.editor.edit(record.attributes, function (field_name, field) { + return self.editor.edit(item, function (field_name, field) { var cell = cells[field_name]; if (!cell || field.get('effective_readonly')) { // Readonly fields can just remain the list's, form's @@ -466,11 +469,14 @@ openerp.web.list_editable = function (instance) { // TODO: specify sequence of edit calls var self = this; var form = self.form; - record = _.extend({}, record); - return form.on_record_loaded(record).pipe(function () { + var loaded = record + ? form.on_record_loaded(_.extend({}, record)) + : form.load_defaults(); + + return loaded.pipe(function () { return form.do_show({reload: false}); }).pipe(function () { - self.record = record; + self.record = form.datarecord; _(form.fields).each(function (field, name) { configureField(name, field); }); diff --git a/addons/web/static/test/list-editable.js b/addons/web/static/test/list-editable.js index 5a03f263ffe..5b702c36f96 100644 --- a/addons/web/static/test/list-editable.js +++ b/addons/web/static/test/list-editable.js @@ -108,7 +108,7 @@ $(document).ready(function () { var counter = 0; e.appendTo($fix) .pipe(function () { - return e.edit(null, function () { + return e.edit({}, function () { ++counter; }); }) @@ -138,7 +138,7 @@ $(document).ready(function () { var counter = 0; e.appendTo($fix) .pipe(function () { - return e.edit(null, function () { + return e.edit({}, function () { ++counter; }); }) @@ -171,7 +171,7 @@ $(document).ready(function () { var warnings = 0; e.appendTo($fix) .pipe(function () { - return e.edit(null, function () { + return e.edit({}, function () { ++counter; }); }) @@ -186,6 +186,85 @@ $(document).ready(function () { }) }); + module('list-edition', { + setup: function () { + baseSetup(); + + var records = {}; + _.extend(instance.connection.responses, { + '/web/listview/load': function () { + return {result: { + type: 'tree', + fields: { + a: {type: 'char', string: "A"}, + b: {type: 'char', string: "B"}, + c: {type: 'char', string: "C"} + }, + arch: { + tag: 'tree', + attrs: {}, + children: [ + {tag: 'field', attrs: {name: 'a'}}, + {tag: 'field', attrs: {name: 'b'}}, + {tag: 'field', attrs: {name: 'c'}} + ] + } + }}; + }, + '/web/dataset/call_kw:create': function (params) { + records[42] = _.extend({}, params.params.args[0]); + return {result: 42}; + }, + '/web/dataset/call_kw:read': function (params) { + var id = params.params.args[0][0]; + if (id in records) { + return {result: [records[id]]}; + } + return {result: []}; + } + }) + } + }); + asyncTest('newrecord', 6, function () { + var got_defaults = false; + instance.connection.responses['/web/dataset/call_kw:default_get'] = function (params) { + var fields = params.params.args[0]; + deepEqual( + fields, ['a', 'b', 'c'], + "should ask defaults for all fields"); + got_defaults = true; + return {result: { + a: "qux", + b: "quux" + }}; + }; + + var ds = new instance.web.DataSetStatic(null, 'demo', null, [1]); + var l = new instance.web.ListView({}, ds); + l.set_editable(true); + + l.appendTo($fix) + .pipe(l.proxy('reload_content')) + .pipe(function () { + return l.startEdition(); + }) + .always(start) + .pipe(function () { + ok(got_defaults, "should have fetched default values for form"); + return l.saveEdition(); + }) + .pipe(function (result) { + ok(result.created, "should yield newly created record"); + equal(result.record.get('a'), "qux", + "should have used default values"); + equal(result.record.get('b'), "quux", + "should have used default values"); + ok(!result.record.get('c'), + "should have no value if there was no default"); + }) + .fail(function (e) { ok(false, e && e.message || e); }); + }); + module('list-edition-events', { setup: function () { baseSetup(); @@ -220,7 +299,7 @@ $(document).ready(function () { }); } }); - asyncTest('edition events', function () { + asyncTest('edition events', 4, function () { var ds = new instance.web.DataSetStatic(null, 'demo', null, [1]); var o = { counter: 0, @@ -235,7 +314,7 @@ $(document).ready(function () { .pipe(function () { ok(l.options.editable, "should be editable"); equal(o.counter, 0, "should have seen no event yet"); - return l.startEdition(); + return l.startEdition(l.records.get(1)); }) .pipe(function () { ok(l.editor.isEditing(), "should be editing");