[IMP] replace ad-hoc patch display by patchqueue

bzr revid: xmo@openerp.com-20130211075200-lwd79pktewqf0wkk
This commit is contained in:
Xavier Morel 2013-02-11 08:52:00 +01:00
parent eff1708704
commit 06954ded48
32 changed files with 232 additions and 204 deletions

View File

@ -27,7 +27,11 @@ sys.path.insert(0, os.path.abspath('..'))
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.viewcode']
extensions = [
'sphinx.ext.autodoc', 'sphinx.ext.intersphinx',
'sphinx.ext.todo', 'sphinx.ext.viewcode',
'patchqueue'
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

View File

@ -1,5 +1,7 @@
.. _module:
.. queue:: module/series
Building an OpenERP Web module
==============================
@ -19,8 +21,7 @@ A very basic OpenERP module structure will be our starting point:
├── __init__.py
└── __openerp__.py
.. literalinclude:: module/__openerp__.py
:language: python
.. patch::
This is a sufficient minimal declaration of a valid OpenERP module.
@ -41,8 +42,7 @@ module is automatically recognized as "web-enabled" if it contains a
is the extent of it. You should also change the dependency to list
``web``:
.. literalinclude:: module/__openerp__.py.1.diff
:language: diff
.. patch::
.. note::
@ -67,15 +67,13 @@ The first one is to add javascript code. It's customary to put it in
``static/src/js``, to have room for e.g. other file types, or
third-party libraries.
.. literalinclude:: module/static/src/js/first_module.js
:language: javascript
.. patch::
The client won't load any file unless specified, thus the new file
should be listed in the module's manifest file, under a new key ``js``
(a list of file names, or glob patterns):
.. literalinclude:: module/__openerp__.py.2.diff
:language: diff
.. patch::
At this point, if the module is installed and the client reloaded the
message should appear in your browser's development console.
@ -100,8 +98,7 @@ initialized, and it can't get access to the various APIs of the web
client (such as making RPC requests to the server). This is done by
providing a `javascript module`_:
.. literalinclude:: module/static/src/js/first_module.js.1.diff
:language: diff
.. patch::
If you reload the client, you'll see a message in the console exactly
as previously. The differences, though invisible at this point, are:
@ -122,17 +119,12 @@ To demonstrate, let's build a simple :doc:`client action
First, the action declaration:
.. literalinclude:: module/__openerp__.py.3.diff
:language: diff
.. literalinclude:: module/web_example.xml
:language: xml
.. patch::
then set up the :doc:`client action hook <client_action>` to register
a function (for now):
.. literalinclude:: module/static/src/js/first_module.js.2.diff
:language: diff
.. patch::
Updating the module (in order to load the XML description) and
re-starting the server should display a new menu *Example Client
@ -148,8 +140,7 @@ client action function by a :doc:`widget`. Our widget will simply use
its :js:func:`~openerp.web.Widget.start` to add some content to its
DOM:
.. literalinclude:: module/static/src/js/first_module.js.3.diff
:language: diff
.. patch::
after reloading the client (to update the javascript file), instead of
printing to the console the menu item clears the whole screen and
@ -159,15 +150,13 @@ Since we've added a class on the widget's :ref:`DOM root
<widget-dom_root>` we can now see how to add a stylesheet to a module:
first create the stylesheet file:
.. literalinclude:: module/static/src/css/web_example.css
:language: css
.. patch::
then add a reference to the stylesheet in the module's manifest (which
will require restarting the OpenERP Server to see the changes, as
usual):
.. literalinclude:: module/__openerp__.py.4.diff
:language: diff
.. patch::
the text displayed by the menu item should now be huge, and
white-on-black (instead of small and black-on-white). From there on,
@ -204,22 +193,16 @@ integration to OpenERP Web widgets.
Adding a template file is similar to adding a style sheet:
.. literalinclude:: module/static/src/xml/web_example.xml
:language: xml
.. literalinclude:: module/__openerp__.py.5.diff
:language: diff
.. patch::
The template can then easily be hooked in the widget:
.. literalinclude:: module/static/src/js/first_module.js.4.diff
:language: diff
.. patch::
And finally the CSS can be altered to style the new (and more complex)
template-generated DOM, rather than the code-generated one:
.. literalinclude:: module/static/src/css/web_example.css.1.diff
:language: diff
.. patch::
.. note::
@ -238,15 +221,13 @@ The last step (until the next one) is to add some behavior and make
our stopwatch watch. First hook some events on the buttons to toggle
the widget's state:
.. literalinclude:: module/static/src/js/first_module.js.5.diff
:language: diff
.. patch::
This demonstrates the use of the "events hash" and event delegation to
declaratively handle events on the widget's DOM. And already changes
the button displayed in the UI. Then comes some actual logic:
.. literalinclude:: module/static/src/js/first_module.js.6.diff
:language: diff
.. patch::
* An initializer (the ``init`` method) is introduced to set-up a few
internal variables: ``_start`` will hold the start of the timer (as
@ -288,15 +269,13 @@ storing data as a model, allowing so that we don't lose our data and
can later retrieve, query and manipulate it. First let's create a
basic OpenERP model in which our data will be stored:
.. literalinclude:: module/__init__.py.1.diff
:language: diff
.. patch::
then let's add saving times to the database every time the stopwatch
is stopped, using :js:class:`the "high-level" Model API
<openerp.web.Model.call>`:
.. literalinclude:: module/static/src/js/first_module.js.7.diff
:language: diff
.. patch::
A look at the "Network" tab of your preferred browser's developer
tools while playing with the stopwatch will show that the save

17
addons/web/doc/module/0 Normal file
View File

@ -0,0 +1,17 @@
# HG changeset patch
# Parent 0000000000000000000000000000000000000000
diff --git a/__init__.py b/__init__.py
new file mode 100644
diff --git a/__openerp__.py b/__openerp__.py
new file mode 100644
--- /dev/null
+++ b/__openerp__.py
@@ -0,0 +1,7 @@
+# __openerp__.py
+{
+ 'name': "Web Example",
+ 'description': "Basic example of a (future) web module",
+ 'category': 'Hidden',
+ 'depends': ['base'],
+}

13
addons/web/doc/module/10 Normal file
View File

@ -0,0 +1,13 @@
# HG changeset patch
# Parent 72d9d59a93fcee06ba28cf0b98a1075331dcc8f4
diff --git a/static/src/css/web_example.css b/static/src/css/web_example.css
new file mode 100644
--- /dev/null
+++ b/static/src/css/web_example.css
@@ -0,0 +1,6 @@
+.openerp .oe_web_example {
+ color: white;
+ background-color: black;
+ height: 100%;
+ font-size: 400%;
+}

11
addons/web/doc/module/11 Normal file
View File

@ -0,0 +1,11 @@
# HG changeset patch
# Parent 3ed382d9a8fe64fbb8e2bf4045e3fcd5c74c92bc
diff --git a/__openerp__.py b/__openerp__.py
--- a/__openerp__.py
+++ b/__openerp__.py
@@ -6,4 +6,5 @@
'depends': ['web'],
'data': ['web_example.xml'],
'js': ['static/src/js/first_module.js'],
+ 'css': ['static/src/css/web_example.css'],
}

28
addons/web/doc/module/12 Normal file
View File

@ -0,0 +1,28 @@
# HG changeset patch
# Parent 43f21611dacb7c2b2f3810baeeef359ad7c329f0
diff --git a/__openerp__.py b/__openerp__.py
--- a/__openerp__.py
+++ b/__openerp__.py
@@ -7,4 +7,5 @@
'data': ['web_example.xml'],
'js': ['static/src/js/first_module.js'],
'css': ['static/src/css/web_example.css'],
+ 'qweb': ['static/src/xml/web_example.xml'],
}
diff --git a/static/src/xml/web_example.xml b/static/src/xml/web_example.xml
new file mode 100644
--- /dev/null
+++ b/static/src/xml/web_example.xml
@@ -0,0 +1,11 @@
+<templates>
+<div t-name="web_example.action" class="oe_web_example oe_web_example_stopped">
+ <h4 class="oe_web_example_timer">00:00:00</h4>
+ <p class="oe_web_example_start">
+ <button type="button">Start</button>
+ </p>
+ <p class="oe_web_example_stop">
+ <button type="button">Stop</button>
+ </p>
+</div>
+</templates>

View File

@ -1,15 +1,17 @@
--- web_example/static/src/js/first_module.js
+++ web_example/static/src/js/first_module.js
@@ -1,11 +1,7 @@
// static/src/js/first_module.js
# HG changeset patch
# Parent ae3b427c96b532794a65357b3f075129cc991276
diff --git a/static/src/js/first_module.js b/static/src/js/first_module.js
--- a/static/src/js/first_module.js
+++ b/static/src/js/first_module.js
@@ -2,10 +2,6 @@
openerp.web_example = function (instance) {
instance.web.client_actions.add('example.action', 'instance.web_example.Action');
instance.web_example.Action = instance.web.Widget.extend({
+ template: 'web_example.action'
- className: 'oe_web_example',
- start: function () {
- this.$el.text("Hello, world!");
- return this._super();
- }
+ template: 'web_example.action'
});
};

View File

@ -1,7 +1,9 @@
--- web_example/static/src/css/web_example.css
+++ web_example/static/src/css/web_example.css
@@ -1,6 +1,13 @@
.openerp .oe_web_example {
# HG changeset patch
# Parent e2d2e1a4cc2d2496aebeb05d94768384427c9e8b
diff --git a/static/src/css/web_example.css b/static/src/css/web_example.css
--- a/static/src/css/web_example.css
+++ b/static/src/css/web_example.css
@@ -2,5 +2,12 @@
color: white;
background-color: black;
height: 100%;

View File

@ -1,7 +1,9 @@
--- web_example/static/src/js/first_module.js
+++ web_example/static/src/js/first_module.js
@@ -1,7 +1,19 @@
// static/src/js/first_module.js
# HG changeset patch
# Parent 2645d7a09dcba7f6d6074a33252c16c03c56fdf3
diff --git a/static/src/js/first_module.js b/static/src/js/first_module.js
--- a/static/src/js/first_module.js
+++ b/static/src/js/first_module.js
@@ -2,6 +2,18 @@
openerp.web_example = function (instance) {
instance.web.client_actions.add('example.action', 'instance.web_example.Action');
instance.web_example.Action = instance.web.Widget.extend({

View File

@ -1,12 +1,9 @@
--- web_example/static/src/js/first_module.js
+++ web_example/static/src/js/first_module.js
@@ -1,19 +1,52 @@
// static/src/js/first_module.js
openerp.web_example = function (instance) {
instance.web.client_actions.add('example.action', 'instance.web_example.Action');
instance.web_example.Action = instance.web.Widget.extend({
template: 'web_example.action',
events: {
# HG changeset patch
# Parent 2921a545adc3406d3139be7951f3225e94493466
diff --git a/static/src/js/first_module.js b/static/src/js/first_module.js
--- a/static/src/js/first_module.js
+++ b/static/src/js/first_module.js
@@ -7,13 +7,46 @@ openerp.web_example = function (instance
'click .oe_web_example_start button': 'watch_start',
'click .oe_web_example_stop button': 'watch_stop'
},

View File

@ -1,6 +1,9 @@
--- web_example/__init__.py
+++ web_example/__init__.py
@@ -1,1 +1,14 @@
# HG changeset patch
# Parent e0cc13c2b2ec4d6f6bfdb033b189a32e44106f2e
diff --git a/__init__.py b/__init__.py
--- a/__init__.py
+++ b/__init__.py
@@ -0,0 +1,13 @@
+# __init__.py
+from openerp.osv import orm, fields
+

View File

@ -1,25 +1,17 @@
--- web_example/static/src/js/first_module.js
+++ web_example/static/src/js/first_module.js
@@ -1,52 +1,60 @@
// static/src/js/first_module.js
openerp.web_example = function (instance) {
instance.web.client_actions.add('example.action', 'instance.web_example.Action');
instance.web_example.Action = instance.web.Widget.extend({
template: 'web_example.action',
events: {
'click .oe_web_example_start button': 'watch_start',
'click .oe_web_example_stop button': 'watch_stop'
},
init: function () {
this._super.apply(this, arguments);
# HG changeset patch
# Parent 05797cc75b49634e640f44b24347f2905b464022
diff --git a/static/src/js/first_module.js b/static/src/js/first_module.js
--- a/static/src/js/first_module.js
+++ b/static/src/js/first_module.js
@@ -12,11 +12,13 @@ openerp.web_example = function (instance
this._start = null;
this._watch = null;
},
- update_counter: function () {
+ current: function () {
+ // Subtracting javascript dates returns the difference in milliseconds
+ return new Date() - this._start;
+ },
- update_counter: function () {
+ update_counter: function (time) {
var h, m, s;
- // Subtracting javascript dates returns the difference in milliseconds
@ -29,12 +21,7 @@
m = Math.floor(s / 60);
s -= 60*m;
h = Math.floor(m / 60);
m -= 60*h;
this.$('.oe_web_example_timer').text(
_.str.sprintf("%02d:%02d:%02d", h, m, s));
},
watch_start: function () {
this.$el.addClass('oe_web_example_started')
@@ -29,18 +31,24 @@ openerp.web_example = function (instance
.removeClass('oe_web_example_stopped');
this._start = new Date();
// Update the UI to the current time
@ -50,8 +37,8 @@
},
watch_stop: function () {
clearInterval(this._watch);
+ var time = this.current();
- this.update_counter();
+ var time = this.current();
+ this.update_counter(time);
this._start = this._watch = null;
this.$el.removeClass('oe_web_example_started')
@ -63,9 +50,3 @@
},
destroy: function () {
if (this._watch) {
clearInterval(this._watch);
}
this._super();
}
});
};

12
addons/web/doc/module/2 Normal file
View File

@ -0,0 +1,12 @@
# HG changeset patch
# Parent 8a986919a3e22cd7cca51210820c09d4545dc60d
diff --git a/__openerp__.py b/__openerp__.py
--- a/__openerp__.py
+++ b/__openerp__.py
@@ -3,5 +3,5 @@
'name': "Web Example",
'description': "Basic example of a (future) web module",
'category': 'Hidden',
- 'depends': ['base'],
+ 'depends': ['web'],
}

9
addons/web/doc/module/3 Normal file
View File

@ -0,0 +1,9 @@
# HG changeset patch
# Parent dcf661a5eef8f82503831bdb8e6c9d2f9beb285e
diff --git a/static/src/js/first_module.js b/static/src/js/first_module.js
new file mode 100644
--- /dev/null
+++ b/static/src/js/first_module.js
@@ -0,0 +1,2 @@
+// static/src/js/first_module.js
+console.log("Debug statement: file loaded");

11
addons/web/doc/module/4 Normal file
View File

@ -0,0 +1,11 @@
# HG changeset patch
# Parent 139dae60de67efa0017f5032f71ab774685c5507
diff --git a/__openerp__.py b/__openerp__.py
--- a/__openerp__.py
+++ b/__openerp__.py
@@ -4,4 +4,5 @@
'description': "Basic example of a (future) web module",
'category': 'Hidden',
'depends': ['web'],
+ 'js': ['static/src/js/first_module.js'],
}

11
addons/web/doc/module/5 Normal file
View File

@ -0,0 +1,11 @@
# HG changeset patch
# Parent c8ae7646cce3f271698c844eb2d67f9a8719650d
diff --git a/static/src/js/first_module.js b/static/src/js/first_module.js
--- a/static/src/js/first_module.js
+++ b/static/src/js/first_module.js
@@ -1,2 +1,4 @@
// static/src/js/first_module.js
-console.log("Debug statement: file loaded");
+openerp.web_example = function (instance) {
+ console.log("Module loaded");
+};

29
addons/web/doc/module/6 Normal file
View File

@ -0,0 +1,29 @@
# HG changeset patch
# Parent 0026cb80097a724db8d36371bc00da993a51a06f
diff --git a/__openerp__.py b/__openerp__.py
--- a/__openerp__.py
+++ b/__openerp__.py
@@ -4,5 +4,6 @@
'description': "Basic example of a (future) web module",
'category': 'Hidden',
'depends': ['web'],
+ 'data': ['web_example.xml'],
'js': ['static/src/js/first_module.js'],
}
diff --git a/web_example.xml b/web_example.xml
new file mode 100644
--- /dev/null
+++ b/web_example.xml
@@ -0,0 +1,11 @@
+<!-- web_example/web_example.xml -->
+<openerp>
+ <data>
+ <record model="ir.actions.client" id="action_client_example">
+ <field name="name">Example Client Action</field>
+ <field name="tag">example.action</field>
+ </record>
+ <menuitem action="action_client_example"
+ id="menu_client_example"/>
+ </data>
+</openerp>

View File

@ -1,5 +1,8 @@
--- web_example/static/src/js/first_module.js
+++ web_example/static/src/js/first_module.js
# HG changeset patch
# Parent d987c9edd884de1de30f2ceb70d2e554474b8dd1
diff --git a/static/src/js/first_module.js b/static/src/js/first_module.js
--- a/static/src/js/first_module.js
+++ b/static/src/js/first_module.js
@@ -1,4 +1,7 @@
// static/src/js/first_module.js
openerp.web_example = function (instance) {

View File

@ -1,5 +1,8 @@
--- web_example/static/src/js/first_module.js
+++ web_example/static/src/js/first_module.js
# HG changeset patch
# Parent 6a1a7240ea0e63182f60abb1eb5c631089d56dbe
diff --git a/static/src/js/first_module.js b/static/src/js/first_module.js
--- a/static/src/js/first_module.js
+++ b/static/src/js/first_module.js
@@ -1,7 +1,11 @@
// static/src/js/first_module.js
openerp.web_example = function (instance) {

View File

@ -1,7 +0,0 @@
# __openerp__.py
{
'name': "Web Example",
'description': "Basic example of a (future) web module",
'category': 'Hidden',
'depends': ['base'],
}

View File

@ -1,11 +0,0 @@
--- web_example/__openerp__.py
+++ web_example/__openerp__.py
@@ -1,7 +1,7 @@
# __openerp__.py
{
'name': "Web Example",
'description': "Basic example of a (future) web module",
'category': 'Hidden',
- 'depends': ['base'],
+ 'depends': ['web'],
}

View File

@ -1,11 +0,0 @@
--- web_example/__openerp__.py
+++ web_example/__openerp__.py
@@ -1,7 +1,8 @@
# __openerp__.py
{
'name': "Web Example",
'description': "Basic example of a (future) web module",
'category': 'Hidden',
'depends': ['web'],
+ 'js': ['static/src/js/first_module.js'],
}

View File

@ -1,12 +0,0 @@
--- web_example/__openerp__.py
+++ web_example/__openerp__.py
@@ -1,8 +1,9 @@
# __openerp__.py
{
'name': "Web Example",
'description': "Basic example of a (future) web module",
'category': 'Hidden',
'depends': ['web'],
+ 'data': ['web_example.xml'],
'js': ['static/src/js/first_module.js'],
}

View File

@ -1,13 +0,0 @@
--- web_example/__openerp__.py
+++ web_example/__openerp__.py
@@ -1,9 +1,10 @@
# __openerp__.py
{
'name': "Web Example",
'description': "Basic example of a (future) web module",
'category': 'Hidden',
'depends': ['web'],
'data': ['web_example.xml'],
'js': ['static/src/js/first_module.js'],
+ 'css': ['static/src/css/web_example.css'],
}

View File

@ -1,14 +0,0 @@
--- web_example/__openerp__.py
+++ web_example/__openerp__.py
@@ -1,10 +1,11 @@
# __openerp__.py
{
'name': "Web Example",
'description': "Basic example of a (future) web module",
'category': 'Hidden',
'depends': ['web'],
'data': ['web_example.xml'],
'js': ['static/src/js/first_module.js'],
'css': ['static/src/css/web_example.css'],
+ 'qweb': ['static/src/xml/web_example.xml'],
}

View File

@ -0,0 +1,17 @@
0
2
3
4
5
6
8
9
10
11
12
14
15
16
17
18
19

View File

@ -1,6 +0,0 @@
.openerp .oe_web_example {
color: white;
background-color: black;
height: 100%;
font-size: 400%;
}

View File

@ -1,2 +0,0 @@
// static/src/js/first_module.js
console.log("Debug statement: file loaded");

View File

@ -1,8 +0,0 @@
--- web_example/static/src/js/first_module.js
+++ web_example/static/src/js/first_module.js
@@ -1,2 +1,4 @@
// static/src/js/first_module.js
-console.log("Debug statement: file loaded");
+openerp.web_example = function (instance) {
+ console.log("Module loaded");
+};

View File

@ -1,11 +0,0 @@
<templates>
<div t-name="web_example.action" class="oe_web_example oe_web_example_stopped">
<h4 class="oe_web_example_timer">00:00:00</h4>
<p class="oe_web_example_start">
<button type="button">Start</button>
</p>
<p class="oe_web_example_stop">
<button type="button">Stop</button>
</p>
</div>
</templates>

View File

@ -1,11 +0,0 @@
<!-- web_example/web_example.xml -->
<openerp>
<data>
<record model="ir.actions.client" id="action_client_example">
<field name="name">Example Client Action</field>
<field name="tag">example.action</field>
</record>
<menuitem action="action_client_example"
id="menu_client_example"/>
</data>
</openerp>