[MERGE] Merged with main addons.
[odoo/odoo.git] / addons / web_tests / static / src / js / web_tests.js
1 openerp.web_tests = function (instance) {
2     instance.web.client_actions.add(
3         'buncha-forms', 'instance.web_tests.BunchaForms');
4     instance.web_tests = {};
5     instance.web_tests.BunchaForms = instance.web.OldWidget.extend({
6         init: function (parent) {
7             this._super(parent);
8             this.dataset = new instance.web.DataSetSearch(this, 'test.listview.relations');
9             this.form = new instance.web.FormView(this, this.dataset, false, {
10                 action_buttons: false,
11                 pager: false
12             });
13             this.form.registry = instance.web.form.readonly;
14         },
15         render: function () {
16             return '<div class="oe-bunchaforms"></div>';
17         },
18         start: function () {
19             $.when(
20                 this.dataset.read_slice(),
21                 this.form.appendTo(this.$element)).then(this.on_everything_loaded);
22         },
23         on_everything_loaded: function (slice) {
24             var records = slice[0].records;
25             if (!records.length) {
26                 this.form.on_record_loaded({});
27                 return;
28             }
29             this.form.on_record_loaded(records[0]);
30             _(records.slice(1)).each(function (record, index) {
31                 this.dataset.index = index+1;
32                 this.form.reposition($('<div>').appendTo(this.$element));
33                 this.form.on_record_loaded(record);
34             }, this);
35         }
36     });
37 };