[ADD] default_get support on new row creation
bzr revid: xmo@openerp.com-20120716110430-9uv352m46d3mn1bx
This commit is contained in:
parent
0c872cf469
commit
75c2845fb5
|
@ -2382,6 +2382,19 @@
|
||||||
.kitten-mode-activated > * {
|
.kitten-mode-activated > * {
|
||||||
opacity: 0.7;
|
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 {
|
div.ui-widget-overlay {
|
||||||
background: black;
|
background: black;
|
||||||
|
|
|
@ -1879,6 +1879,19 @@ $sheet-max-width: 860px
|
||||||
background-attachment: fixed
|
background-attachment: fixed
|
||||||
>*
|
>*
|
||||||
opacity: 0.70
|
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
|
div.ui-widget-overlay
|
||||||
|
|
|
@ -336,6 +336,20 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||||
self.$element.add(self.$buttons).removeClass('oe_form_dirty');
|
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() {
|
on_form_changed: function() {
|
||||||
this.trigger("view_content_has_changed");
|
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"});
|
this.set({mode: "edit"});
|
||||||
return $.when(this.has_been_loaded).pipe(function() {
|
return $.when(this.has_been_loaded).pipe(function() {
|
||||||
if (self.can_be_discarded()) {
|
if (self.can_be_discarded()) {
|
||||||
var keys = _.keys(self.fields_view.fields);
|
return self.load_defaults();
|
||||||
if (keys.length) {
|
|
||||||
return self.dataset.default_get(keys)
|
|
||||||
.pipe(self.on_record_loaded);
|
|
||||||
}
|
|
||||||
return self.on_record_loaded({});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -163,7 +163,10 @@ openerp.web.list_editable = function (instance) {
|
||||||
*/
|
*/
|
||||||
startEdition: function (record) {
|
startEdition: function (record) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (!record) {
|
var item = false;
|
||||||
|
if (record) {
|
||||||
|
item = record.attributes;
|
||||||
|
} else {
|
||||||
var attrs = {id: false};
|
var attrs = {id: false};
|
||||||
_(this.columns).chain()
|
_(this.columns).chain()
|
||||||
.filter(function (x) { return x.tag === 'field'})
|
.filter(function (x) { return x.tag === 'field'})
|
||||||
|
@ -182,7 +185,7 @@ openerp.web.list_editable = function (instance) {
|
||||||
record: record.attributes,
|
record: record.attributes,
|
||||||
cancel: false
|
cancel: false
|
||||||
}, function () {
|
}, 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];
|
var cell = cells[field_name];
|
||||||
if (!cell || field.get('effective_readonly')) {
|
if (!cell || field.get('effective_readonly')) {
|
||||||
// Readonly fields can just remain the list's, form's
|
// 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
|
// TODO: specify sequence of edit calls
|
||||||
var self = this;
|
var self = this;
|
||||||
var form = self.form;
|
var form = self.form;
|
||||||
record = _.extend({}, record);
|
var loaded = record
|
||||||
return form.on_record_loaded(record).pipe(function () {
|
? form.on_record_loaded(_.extend({}, record))
|
||||||
|
: form.load_defaults();
|
||||||
|
|
||||||
|
return loaded.pipe(function () {
|
||||||
return form.do_show({reload: false});
|
return form.do_show({reload: false});
|
||||||
}).pipe(function () {
|
}).pipe(function () {
|
||||||
self.record = record;
|
self.record = form.datarecord;
|
||||||
_(form.fields).each(function (field, name) {
|
_(form.fields).each(function (field, name) {
|
||||||
configureField(name, field);
|
configureField(name, field);
|
||||||
});
|
});
|
||||||
|
|
|
@ -108,7 +108,7 @@ $(document).ready(function () {
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
e.appendTo($fix)
|
e.appendTo($fix)
|
||||||
.pipe(function () {
|
.pipe(function () {
|
||||||
return e.edit(null, function () {
|
return e.edit({}, function () {
|
||||||
++counter;
|
++counter;
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -138,7 +138,7 @@ $(document).ready(function () {
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
e.appendTo($fix)
|
e.appendTo($fix)
|
||||||
.pipe(function () {
|
.pipe(function () {
|
||||||
return e.edit(null, function () {
|
return e.edit({}, function () {
|
||||||
++counter;
|
++counter;
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -171,7 +171,7 @@ $(document).ready(function () {
|
||||||
var warnings = 0;
|
var warnings = 0;
|
||||||
e.appendTo($fix)
|
e.appendTo($fix)
|
||||||
.pipe(function () {
|
.pipe(function () {
|
||||||
return e.edit(null, function () {
|
return e.edit({}, function () {
|
||||||
++counter;
|
++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', {
|
module('list-edition-events', {
|
||||||
setup: function () {
|
setup: function () {
|
||||||
baseSetup();
|
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 ds = new instance.web.DataSetStatic(null, 'demo', null, [1]);
|
||||||
var o = {
|
var o = {
|
||||||
counter: 0,
|
counter: 0,
|
||||||
|
@ -235,7 +314,7 @@ $(document).ready(function () {
|
||||||
.pipe(function () {
|
.pipe(function () {
|
||||||
ok(l.options.editable, "should be editable");
|
ok(l.options.editable, "should be editable");
|
||||||
equal(o.counter, 0, "should have seen no event yet");
|
equal(o.counter, 0, "should have seen no event yet");
|
||||||
return l.startEdition();
|
return l.startEdition(l.records.get(1));
|
||||||
})
|
})
|
||||||
.pipe(function () {
|
.pipe(function () {
|
||||||
ok(l.editor.isEditing(), "should be editing");
|
ok(l.editor.isEditing(), "should be editing");
|
||||||
|
|
Loading…
Reference in New Issue