[REF] *: remove many performModelRPC calls

The performModelRPC method has been deprecated, and replaced by call to
the this.rpc method.
This commit is contained in:
Géry Debongnie
2017-04-11 19:42:23 +02:00
committed by Aaron Bohy
parent 69bf1c2e38
commit 3565a3f44a
2 changed files with 78 additions and 80 deletions
+74 -76
View File
@@ -60,23 +60,20 @@ odoo.define('website_form_editor', function (require) {
fetch_model_fields: function() {
var self = this;
this.fields_deferred = new $.Deferred();
this.performModelRPC("ir.model", "get_authorized_fields",
[
this.$target.closest('form').attr('data-model_name')
],
{
context: base.get_context()
}
).then(function(fields) {
// The get_fields function doesn't return the name
// in the field dict since it uses it has the key
_.map(fields, function(field, field_name){
field.name = field_name;
return field;
});
this.rpc("ir.model", "get_authorized_fields")
.args([this.$target.closest('form').attr('data-model_name')])
.withContext(base.get_context())
.exec()
.then(function(fields) {
// The get_fields function doesn't return the name
// in the field dict since it uses it has the key
_.map(fields, function(field, field_name){
field.name = field_name;
return field;
});
self.fields_deferred.resolve(fields)
});
self.fields_deferred.resolve(fields)
});
return this.fields_deferred;
},
@@ -86,73 +83,72 @@ odoo.define('website_form_editor', function (require) {
if (type !== 'click') return;
var self = this;
this.performModelRPC("ir.model", "search_read",
[
this.rpc("ir.model", "search_read")
.args([
[['website_form_access', '=', true]],
['id', 'model', 'name', 'website_form_label']
],
{
context: base.get_context()
}
).then(function(models) {
// Models selection input
var model_selection = qweb.render("website_form_editor.field_many2one", {
field: {
name: 'model_selection',
string: 'Action',
records: _.map(models, function(m){
return {
id: m.model,
display_name: m.website_form_label || m.name,
selected: (m.model == self.$target.attr('data-model_name')) ? 1: null
}
})
}
});
// Success page input
var success_page = qweb.render("website_form_editor.field_char", {
field: {
name: 'success_page',
string: 'Thank You Page',
value: self.$target.attr('data-success_page')
}
});
// Form parameters modal
self.build_modal(
"Form Parameters",
model_selection + success_page,
function(){
var model_name = self.$modal.find("[name='model_selection']").val();
var success_page = self.$modal.find("[name='success_page']").val();
self.init_form(model_name);
self.$target.attr('data-success_page', success_page);
// Add magic email_to input if model is mail.mail
self.$target.find("input.form-field[name='email_to']").remove();
if (model_name == 'mail.mail') {
var email_to = self.$modal.find("input[name='email_to']").val();
self.$target.append("<input class='form-field' type='hidden' name='email_to' value=" + email_to + ">");
])
.withContext(base.get_context())
.exec()
.then(function(models) {
// Models selection input
var model_selection = qweb.render("website_form_editor.field_many2one", {
field: {
name: 'model_selection',
string: 'Action',
records: _.map(models, function(m){
return {
id: m.model,
display_name: m.website_form_label || m.name,
selected: (m.model == self.$target.attr('data-model_name')) ? 1: null
}
})
}
}
);
});
self.toggle_email_to();
// Success page input
var success_page = qweb.render("website_form_editor.field_char", {
field: {
name: 'success_page',
string: 'Thank You Page',
value: self.$target.attr('data-success_page')
}
});
// Form parameters modal
self.build_modal(
"Form Parameters",
model_selection + success_page,
function(){
var model_name = self.$modal.find("[name='model_selection']").val();
var success_page = self.$modal.find("[name='success_page']").val();
self.init_form(model_name);
self.$target.attr('data-success_page', success_page);
// Add magic email_to input if model is mail.mail
self.$target.find("input.form-field[name='email_to']").remove();
if (model_name == 'mail.mail') {
var email_to = self.$modal.find("input[name='email_to']").val();
self.$target.append("<input class='form-field' type='hidden' name='email_to' value=" + email_to + ">");
}
}
);
self.$modal.find("[name='model_selection']").on('change', function() {
self.toggle_email_to();
});
// On modal close, if there is no data-model, it means
// that the user refused to configure the form on the
// first modal, so we remove the snippet.
self.$modal.on('hidden.bs.modal', function (e) {
if (!self.$target.attr('data-model_name')){
self.$target.remove();
}
self.$modal.find("[name='model_selection']").on('change', function() {
self.toggle_email_to();
});
// On modal close, if there is no data-model, it means
// that the user refused to configure the form on the
// first modal, so we remove the snippet.
self.$modal.on('hidden.bs.modal', function (e) {
if (!self.$target.attr('data-model_name')){
self.$target.remove();
}
});
});
})
},
// Choose a field modal
@@ -345,7 +341,9 @@ odoo.define('website_form_editor', function (require) {
if (fields.length) {
// ideally we'd only do this if saving the form
// succeeds... but no idea how to do that
this.performModelRPC('ir.model.fields', 'formbuilder_whitelist', [model, _.uniq(fields)]);
this.rpc('ir.model.fields', 'formbuilder_whitelist')
.args([model, _.uniq(fields)])
.exec();
}
}
+4 -4
View File
@@ -601,8 +601,8 @@ odoo.define('website_form_editor.tour', function(require) {
content: "Check mail.mail records have been created",
trigger: "body",
run: function () {
var mailDef = this.performModelRPC("mail.mail", "search_read",
[
var mailDef = this.rpc("mail.mail", "search_read")
.args([
// TODO: add other fields in domain !
[
['email_to', '=', 'test@test.test'],
@@ -612,8 +612,8 @@ odoo.define('website_form_editor.tour', function(require) {
['body_html', 'like', 'Products : Xperia,Wiko Stairway']
],
[]
]
);
])
.exec();
var success = function(model, data) {
if(data.length) {
$('body').append('<div id="website_form_editor_success_test_tour_'+model+'"></div>');