[REF] web: move _loadSubviews() from FormView
... as this function is only used by the FormView.
This commit is contained in:
committed by
Aaron Bohy
parent
5f17f0184a
commit
12fa4e565a
@@ -25,7 +25,6 @@ odoo.define('web.AbstractView', function (require) {
|
||||
|
||||
var ajax = require('web.ajax');
|
||||
var Class = require('web.Class');
|
||||
var Context = require('web.Context');
|
||||
var AbstractModel = require('web.AbstractModel');
|
||||
var AbstractRenderer = require('web.AbstractRenderer');
|
||||
var AbstractController = require('web.AbstractController');
|
||||
@@ -236,64 +235,6 @@ var AbstractView = Class.extend({
|
||||
var model = this.getModel(parent);
|
||||
return model.load(this.loadParams);
|
||||
},
|
||||
/**
|
||||
* Loads the subviews for x2many fields when they are not inline
|
||||
*
|
||||
* @private
|
||||
* @param {Widget} parent the parent of the model, if it has to be created
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
_loadSubviews: function (parent) {
|
||||
var self = this;
|
||||
var defs = [];
|
||||
if (this.loadParams && this.loadParams.fieldsInfo) {
|
||||
var fields = this.loadParams.fields;
|
||||
|
||||
_.each(this.loadParams.fieldsInfo.form, function (attrs, fieldName) {
|
||||
var field = fields[fieldName];
|
||||
if (field.type !== 'one2many' && field.type !== 'many2many') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (attrs.Widget.prototype.useSubview && !attrs.__no_fetch && !attrs.views[attrs.mode]) {
|
||||
var context = {};
|
||||
var regex = /'([a-z]*_view_ref)' *: *'(.*?)'/g;
|
||||
var matches;
|
||||
while (matches = regex.exec(attrs.context)) {
|
||||
context[matches[1]] = matches[2];
|
||||
}
|
||||
defs.push(parent.loadViews(
|
||||
field.relation,
|
||||
new Context(context, self.userContext, self.loadParams.context).eval(),
|
||||
[[null, attrs.mode === 'tree' ? 'list' : attrs.mode]])
|
||||
.then(function (views) {
|
||||
for (var viewName in views) {
|
||||
attrs.views[viewName] = views[viewName];
|
||||
}
|
||||
self._setSubViewLimit(attrs);
|
||||
}));
|
||||
} else {
|
||||
self._setSubViewLimit(attrs);
|
||||
}
|
||||
});
|
||||
}
|
||||
return $.when.apply($, defs);
|
||||
},
|
||||
/**
|
||||
* We set here the limit for the number of records fetched (in one page).
|
||||
* This method is only called for subviews, not for main views.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} attrs
|
||||
*/
|
||||
_setSubViewLimit: function (attrs) {
|
||||
var view = attrs.views && attrs.views[attrs.mode];
|
||||
var limit = view && view.arch.attrs.limit && parseInt(view.arch.attrs.limit);
|
||||
if (!limit && attrs.widget === 'many2many_tags') {
|
||||
limit = 1000;
|
||||
}
|
||||
attrs.limit = limit || 40;
|
||||
},
|
||||
});
|
||||
|
||||
return AbstractView;
|
||||
|
||||
@@ -2,6 +2,7 @@ odoo.define('web.FormView', function (require) {
|
||||
"use strict";
|
||||
|
||||
var BasicView = require('web.BasicView');
|
||||
var Context = require('web.Context');
|
||||
var core = require('web.core');
|
||||
var FormController = require('web.FormController');
|
||||
var FormRenderer = require('web.FormRenderer');
|
||||
@@ -52,6 +53,69 @@ var FormView = BasicView.extend({
|
||||
getController: function (parent) {
|
||||
return this._loadSubviews(parent).then(this._super.bind(this, parent));
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Loads the subviews for x2many fields when they are not inline
|
||||
*
|
||||
* @private
|
||||
* @param {Widget} parent the parent of the model, if it has to be created
|
||||
* @returns {Deferred}
|
||||
*/
|
||||
_loadSubviews: function (parent) {
|
||||
var self = this;
|
||||
var defs = [];
|
||||
if (this.loadParams && this.loadParams.fieldsInfo) {
|
||||
var fields = this.loadParams.fields;
|
||||
|
||||
_.each(this.loadParams.fieldsInfo.form, function (attrs, fieldName) {
|
||||
var field = fields[fieldName];
|
||||
if (field.type !== 'one2many' && field.type !== 'many2many') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (attrs.Widget.prototype.useSubview && !attrs.__no_fetch && !attrs.views[attrs.mode]) {
|
||||
var context = {};
|
||||
var regex = /'([a-z]*_view_ref)' *: *'(.*?)'/g;
|
||||
var matches;
|
||||
while (matches = regex.exec(attrs.context)) {
|
||||
context[matches[1]] = matches[2];
|
||||
}
|
||||
defs.push(parent.loadViews(
|
||||
field.relation,
|
||||
new Context(context, self.userContext, self.loadParams.context).eval(),
|
||||
[[null, attrs.mode === 'tree' ? 'list' : attrs.mode]])
|
||||
.then(function (views) {
|
||||
for (var viewName in views) {
|
||||
attrs.views[viewName] = views[viewName];
|
||||
}
|
||||
self._setSubViewLimit(attrs);
|
||||
}));
|
||||
} else {
|
||||
self._setSubViewLimit(attrs);
|
||||
}
|
||||
});
|
||||
}
|
||||
return $.when.apply($, defs);
|
||||
},
|
||||
/**
|
||||
* We set here the limit for the number of records fetched (in one page).
|
||||
* This method is only called for subviews, not for main views.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} attrs
|
||||
*/
|
||||
_setSubViewLimit: function (attrs) {
|
||||
var view = attrs.views && attrs.views[attrs.mode];
|
||||
var limit = view && view.arch.attrs.limit && parseInt(view.arch.attrs.limit);
|
||||
if (!limit && attrs.widget === 'many2many_tags') {
|
||||
limit = 1000;
|
||||
}
|
||||
attrs.limit = limit || 40;
|
||||
},
|
||||
});
|
||||
|
||||
return FormView;
|
||||
|
||||
Reference in New Issue
Block a user