Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

17

Plan to really support Backbone or any frontend MVC framework ?

By
Michel Meyer
on 8/13/13, 4:53 AM 7,113 views

During the last 3 months, I worked on brand new views in OpenERP v7. Most of my work was on frontend side, so I had the time to look deeply in the OpenERP web module.

I build my new web modules based on Backbone and Marionette framework. I also had to integrate my own web module handler because I really need to have a well organized code and to separate each module in his own file... I think it's mandatory for a web app.

I totally understand that there is some historic on this platform with certainly strong constraints, but a lot of questions come to me when I start to work on my web module projects and I'm pretty sure that the core team have good answers for most of them ;)

Code organization

I worked for some web app before, a main issue is the code organization. The common way to organize a web app is to use a module loader like RequireJS, you can easily put each module in one file and keep your file/module organization clean and clear. It's also a nice way to make the code reusable.

A better explanation of why using AMD friendly module is a most here: requirejs.org/docs/whyamd.html

In OpenERP, everything is loaded once, and code is organized in a global namespace. also some core files have more than 2000 lines with many object declarations....
An effort has been made to have an inherence system and to use Widget and other components to create the architecture, but there's lot of dependencies and code quality is very different from one widget to an other...

Some part should really be reusable, for example the pager should be a view that take a paginated model in parameter, for now the view look like that: bazaar.launchpad.net/~openerp/openerp-web/trunk/view/head:/addons/web/static/src/js/view_list.js#L300

  • why OpenERP is not using a module loader instead of managing this on the server side by loading all at once ?
  • some refactoring is planed to make the code more reusable ?
  • is there any plane to allow a well organized code for our web module in the future ?

Frontend MVC Framework

I notice in different places that you are rebuilding a "backbone like" framework (ie. search module), we can even read this in some comments like (in view_list.js):

Smarter collections, with events, very strongly inspired by Backbone's.

I'm a big fan of Backbone, I did my 2 OpenERP web modules with Backbone and Marionette, and I'm pretty sure that it was impossible to do the same by using OpenERP web "framework", because of the lack of documentation and non modular code.

One core feature I added is the support of the JSON-RPC API by Backbone, simply by using connector between the Backbone Model sync function and the JSON-RPC object provided by OpenERP. It's seems so obvious, why is it not supported by OpenERP by default...

  • why don't you use directly Backbone instead of redoing something similar... without the community support and nearly without documentation ?
  • it's seems to me that Marionette is the perfect layer that is missing in OpenERP to build the application layout, isn't it ?
  • there's tons of template engine out there, why reinventing the wheel with QWEB ?

DOM organization

Just one question, why table layout ?

New views in OpenERP

I think (and maybe I didn't found out how to do) there's no real way to add a custom view type in OpenERP without using a dirty trick.

For my needs, i did it like this:

register a js view:

instance.web.views.add('foobar_view', 'instance.foobar.FooBarView');
instance.foobar.FooBarView = instance.web.View.extend({...})

add a act_window entry:

<record id="action_view_foobar" model="ir.actions.act_window">
    <field name="name">FooBar</field>
    <field name="view_mode">foobar_view</field>
    <field name="res_model">foo.bar</field>
</record>

It works fine for a fully new view, not integrated with other views, but the problem is if I want to use my foobar_view as a view_type and use some archi parameters to configure it...

  • is there any plane to fully support custom view type in the future ?

My goal is to make a constructive criticism, I hope my initiative will achieve this.

Actually this is "not a real question", but I do hope it generates useful discussion before being closed.

Daniel Reis
on 11/10/13, 1:07 PM

Michel, I am working in a task similar to yours, can you help me with the connector between Backbone sync and openerp JsonRPC object?

Yuri Quintana
on 8/19/16, 5:32 AM
1
Nhomar Hernandez
On 11/10/13, 5:34 PM

It should be really cool get an answer from al@openerp because IMHO i saw some especific things that really differenciate what is done in openerp-web than in backbone needs to be extended.

I think __exactly__ the same way you do, I just want to remark some important leaks in backbone than in OpenERP are by default.

1.- super:

Brief aside on super: JavaScript does not provide a simple way to call super — the function of the same name defined higher on the prototype chain. If you override a core function like set, or save, and you want to invoke the parent object's implementation, you'll have to explicitly call it, along these lines:

var Note = Backbone.Model.extend({
  set: function(attributes, options) {
    Backbone.Model.prototype.set.apply(this, arguments);
    ...
  }
});

In openerp:

this._super(this, arguments);

2.- Include:

In backbone to overwrite just one attribute in the original object you need to use a little trick.

backbone:

orignal.Object = original.Object.extend({})

Openerp

originalObject.include({})

With this little resume I need to ask with you to Anthony or Nicolas help us to understand this decistion.

IMHO, may be the release cycle of backbone is a problem too! because both tools have different approaches and objectives.

3.- May be, licence issues :-s?:

https://github.com/jashkenas/backbone/blob/master/LICENSE

The licence is open but not comply with (A)GPL + private modules [Due to basic restrictions.], I am not sure of this, may be I am speculating.

Falling apart this 3 points, We can list "What backbone has that opener doesn't" but it is not the point, I think it should be great if the decide to use "Flask-tunning + Backbone-tunning" A lot of effort will be reduced, and we can have several benefits (they did already with bootstrap 3 in trunk.

But By far, if you know BackboneJS and read the code, you will be able to work with openerp-web (you are a good example), the big fail here from OpenERP side, is that they should say "We work something like backbone" and since the beginning we can read both documentations and it helps a lot ;-)

Hoping this questions are answered by OpenERP ASAP (because it is important to have documented the technical decistions too!)

Regards.

About "important leaks", I just see _super and incude as some sugar... and they can be implemented in backbone too.

About the license, backbone is already included in openerp

"What backbone has that openerp doesn't": - documentation vs "read the code, you will be able to work with openerp-web" - unit tested (code coverage ~100%) - large community - framework like Marionette

I did web-unleashed specially because I want to be free from openerp-web code, I wrap core things I need (connector, qweb,..) and use openerp view just has an interface. (http://bit.ly/19TQiVA)

Michel Meyer
on 11/10/13, 10:50 PM
0
David Arnold
On 11/28/14, 6:39 PM

Ping on this very intersting and complete discussion input.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

6 follower(s)

Stats

Asked: 8/13/13, 4:53 AM
Seen: 7113 times
Last updated: 11/6/15, 12:36 AM