openerp-dev-web team mailing list archive
-
openerp-dev-web team
-
Mailing list archive
-
Message #07764
Refactoring of the Controller class, now called the Widget class
Hi everyone,
I would like to inform you that Antony, Xavier, Fabien and myself
created a new design for the Controller class, which is now the Widget
class. The purpose is to unify the way everyone creates visual components.
That class contains retro-compatibility features to avoid breaking the
old code, but you should use the new style of coding for all new
widgets, so please read the documentation of that class carefully. Here
is a copy paste of the coding guide written in the documention:
* Guide to create implementations of the Widget class:
* ==============================================
*
* Here is a sample child class:
*
* MyWidget = openerp.base.Widget.extend({
* // the name of the QWeb template to use for rendering
* template: "MyQWebTemplate",
* // identifier prefix, it is useful to put an obvious one for
debugging
* identifier_prefix: 'my-id-prefix-',
*
* init: function(parent) {
* this._super(parent);
* // stuff that you want to init before the rendering
* },
* start: function() {
* this._super();
* // stuff you want to make after the rendering,
`this.$element` holds a correct value
* this.$element.find(".my_button").click(/* an example of
event binding * /);
*
* // if you have some asynchronous operations, it's a good
idea to return
* // a promise in start()
* var promise = this.rpc(...);
* return promise;
* }
* });
*
* Now this class can simply be used with the following syntax:
*
* var my_widget = new MyWidget(this);
* my_widget.appendTo($(".some-div"));
*
* With these two lines, the MyWidget instance was inited, rendered, it
was inserted into the
* DOM inside the ".some-div" div and its events were binded.
*
* And of course, when you don't need that widget anymore, just do:
*
* my_widget.stop();
*
* That will kill the widget in a clean way and erase its content from
the dom.
* Now this class can simply be used with the following syntax:
*
* var my_widget = new MyWidget(this);
* my_widget.appendTo($(".some-div"));
*
* With these two lines, the MyWidget instance was inited, rendered, it
was inserted into the
* DOM inside the ".some-div" div and its events were binded.
*
* And of course, when you don't need that widget anymore, just do:
*
* my_widget.stop();
*
* That will kill the widget in a clean way and erase its content from
the dom.
--
Nicolas Vanhoren
Developer OpenERP
Chaussée de Namur 40
B-1367 Grand-Rosière
Belgium
Phone: +32.81.81.37.00
Fax: +32.81.73.35.01
Web: http://openerp.com