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.
Modules have been published:
Michel, I am working in a task similar to yours, can you help me with the connector between Backbone sync and openerp JsonRPC object?