summaryrefslogtreecommitdiff
path: root/addons/base/static/src
diff options
context:
space:
mode:
authorniv-openerp <nicolas.vanhoren@openerp.com>2011-05-04 14:03:48 +0200
committerniv-openerp <nicolas.vanhoren@openerp.com>2011-05-04 14:03:48 +0200
commit15617cb37231b7aaa3fa5652fa03b9098eb73c2f (patch)
tree66e637a9eb8a13fbb6ee5d10817915f6779e8ae1 /addons/base/static/src
parente21e58e65a2b32ad1bd4f6169e5b6943451ed35b (diff)
parentd45786c01b1a6769ccac190bf493f72311e32632 (diff)
[MERGE]
bzr revid: nicolas.vanhoren@openerp.com-20110504120348-dnwkd6ea22xfgsjp
Diffstat (limited to 'addons/base/static/src')
-rw-r--r--addons/base/static/src/base.html4
-rw-r--r--addons/base/static/src/js/form.js35
-rw-r--r--addons/base/static/src/js/list.js17
-rw-r--r--addons/base/static/src/js/views.js52
-rw-r--r--addons/base/static/src/xml/base.xml7
5 files changed, 81 insertions, 34 deletions
diff --git a/addons/base/static/src/base.html b/addons/base/static/src/base.html
index d04afe03cec..5f6e2a8e96c 100644
--- a/addons/base/static/src/base.html
+++ b/addons/base/static/src/base.html
@@ -8,7 +8,10 @@
<script type="text/javascript" src="/base/static/lib/LABjs/LAB.js"></script>
<script type="text/javascript" src="/base/static/lib/underscore/underscore.js"></script>
<script type="text/javascript" src="/base/static/lib/underscore/underscore.strings.js"></script>
+ <script type="text/javascript" src="/base/static/lib/qweb/qweb2.js"></script>
+ <!-- Uncomment in order to use legacy QWeb
<script type="text/javascript" src="/base/static/lib/qweb/qweb.js"></script>
+ -->
<script type="text/javascript" src="/base/static/lib/jquery/jquery-1.5.2.js"></script>
<script type="text/javascript" src="/base/static/lib/jquery.ui/js/jquery-ui-1.8.9.custom.min.js"></script>
<script type="text/javascript" src="/base/static/lib/jquery.ui/js/jquery-ui-timepicker-addon.js"></script>
@@ -35,6 +38,7 @@
<script type="text/javascript">
$(function() {
+ QWeb = window.QWeb || new QWeb2.Engine();
var oe = openerp.init();
oe.base.webclient("oe");
});
diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js
index 1f6719ba5ba..3a2db9e4e53 100644
--- a/addons/base/static/src/js/form.js
+++ b/addons/base/static/src/js/form.js
@@ -530,34 +530,19 @@ openerp.base.form.WidgetButton = openerp.base.form.Widget.extend({
}
},
on_confirmed: function() {
- var attrs = this.node.attrs;
- if (attrs.special) {
- this.on_button_action({
- result : { type: 'ir.actions.act_window_close' }
+ var self = this;
+
+ this.execute_action(
+ this.node.attrs, this.view.dataset, this.session.action_manager,
+ this.view.datarecord.id, function (result) {
+ self.log("Button returned", result);
+ self.view.reload();
});
- } else {
- var type = attrs.type || 'workflow';
- var context = _.extend({}, this.view.dataset.context, attrs.context || {});
- switch(type) {
- case 'object':
- return this.view.dataset.call(attrs.name, [this.view.datarecord.id], [context], this.on_button_action);
- case 'action':
- return this.rpc('/base/action/load', { action_id: parseInt(attrs.name) }, this.on_button_action);
- default:
- return this.view.dataset.exec_workflow(this.view.datarecord.id, attrs.name, this.on_button_action);
- }
- }
- },
- on_button_action: function(r) {
- console.log("Got reesonse button", r)
- if (r.result && r.result.constructor == Object) {
- this.session.action_manager.do_action(r.result);
- } else {
- this.log("Button returned", r.result);
- this.view.reload();
- }
}
});
+// let WidgetButton execute actions
+_.extend(openerp.base.form.WidgetButton.prototype,
+ openerp.base.ActionExecutor);
openerp.base.form.WidgetLabel = openerp.base.form.Widget.extend({
init: function(view, node) {
diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js
index 728ec19bc6f..62abdc6f106 100644
--- a/addons/base/static/src/js/list.js
+++ b/addons/base/static/src/js/list.js
@@ -40,6 +40,8 @@ openerp.base.ListView = openerp.base.Controller.extend(
* @param {null|String} [options.addable="New"] should the new-record button be displayed, and what should its label be. Use ``null`` to hide the button.
* @param {Boolean} [options.sortable=true] is it possible to sort the table by clicking on column headers
* @param {Boolean} [options.reorderable=true] is it possible to reorder list rows
+ *
+ * @borrows openerp.base.ActionExecutor#execute_action as #execute_action
*/
init: function(view_manager, session, element_id, dataset, view_id, options) {
this._super(session, element_id);
@@ -145,20 +147,20 @@ openerp.base.ListView = openerp.base.Controller.extend(
});
$table.delegate(
'td.oe-field-cell button', 'click', function (e) {
+ e.stopImmediatePropagation();
+
var $cell = $(e.currentTarget).closest('td');
+
var col_index = $cell.prevAll('td').length;
var field = self.visible_columns[col_index];
- var action = field.name;
var $row = $cell.parent('tr');
var row = self.rows[$row.prevAll().length];
- var context = _.extend(
- {}, self.dataset.context, field.context || {});
- self.notification.notify(
- '[Dummy] Execute action', self.dataset.model + '#' + action + "([" + row.data.id.value + '])');
- // TODO: implement actions correctly once the corresponding manager has been extracted (and filled)
- e.stopImmediatePropagation();
+ // TODO: we should probably only reload content, also maybe diff records or something, instead of replacing every single row
+ self.execute_action(
+ field, self.dataset, self.session.action_manager,
+ row.data.id.value, self.do_reload);
});
$table.delegate(
'td.oe-record-delete button', 'click', this.do_delete);
@@ -393,6 +395,7 @@ openerp.base.ListView = openerp.base.Controller.extend(
// TODO: implement sort (click on column headers), if sorted, the list can not be reordered anymore
// TODO: implement reorder (drag and drop rows)
});
+_.extend(openerp.base.ListView.prototype, openerp.base.ActionExecutor);
openerp.base.TreeView = openerp.base.Controller.extend({
});
diff --git a/addons/base/static/src/js/views.js b/addons/base/static/src/js/views.js
index 7af2e6b38e9..92609e166be 100644
--- a/addons/base/static/src/js/views.js
+++ b/addons/base/static/src/js/views.js
@@ -64,6 +64,58 @@ openerp.base.ActionManager = openerp.base.Controller.extend({
});
/**
+ * Mixin for action-executing objects, provides handling of OpenERP actions to
+ * all clients.
+ *
+ * Mix into existing classes via ``_.extend`` of the class's prototype.
+ *
+ * @class
+ */
+openerp.base.ActionExecutor =
+/**
+ * @lends openerp.base.ActionExecutor#
+ */ {
+ /**
+ * Fetches and executes the action identified by ``action_data``.
+ *
+ * @param {Object} action_data the action descriptor data
+ * @param {String} action_data.name the action name, used to uniquely identify the action to find and execute it
+ * @param {String} [action_data.special=null] special action handlers (currently: only ``'cancel'``)
+ * @param {String} [action_data.type='workflow'] the action type, if present, one of ``'object'``, ``'action'`` or ``'workflow'``
+ * @param {Object} [action_data.context=null] additional action context, to add to the current context
+ * @param {openerp.base.DataSet} dataset a dataset object used to communicate with the server
+ * @param {openerp.base.ActionManager} action_manager object able to actually execute the action, if any is fetched
+ * @param {Number} [record_id] the identifier of the object on which the action is to be applied
+ * @param {Function} on_no_action callback to execute if the action does not generate any result (no new action)
+ */
+ execute_action: function (action_data, dataset, action_manager, record_id, on_no_action) {
+ var handler = function (r) {
+ if (r.result && r.result.constructor == Object) {
+ action_manager.do_action(r.result);
+ } else {
+ on_no_action(r.result);
+ }
+ };
+
+ if (action_data.special) {
+ handler({
+ result : { type: 'ir.actions.act_window_close' }
+ });
+ } else {
+ var context = _.extend({}, dataset.context, action_data.context || {});
+ switch(action_data.type) {
+ case 'object':
+ return dataset.call(action_data.name, [record_id], [context], handler);
+ case 'action':
+ return this.rpc('/base/action/load', { action_id: parseInt(action_data.name, 10) }, handler);
+ default:
+ return dataset.exec_workflow(record_id, action_data.name, handler);
+ }
+ }
+ }
+};
+
+/**
* Registry for all the main views
*/
openerp.base.views = new openerp.base.Registry();
diff --git a/addons/base/static/src/xml/base.xml b/addons/base/static/src/xml/base.xml
index fa4d2720f36..f697d5b1fa7 100644
--- a/addons/base/static/src/xml/base.xml
+++ b/addons/base/static/src/xml/base.xml
@@ -534,8 +534,11 @@
</div>
</t>
<t t-name="ViewManager.sidebar.internal">
- <t t-set="the_condition" t-value="sections.length &gt; 0 &amp;&amp; _.detect(sections, function(x)
- {return x.elements.length &gt; 0;}) != undefined"/>
+ <t t-js="d">
+ d.the_condition = d.sections.length &gt; 0 &amp;&amp; d._.detect(d.sections, function(x) {
+ return x.elements.length &gt; 0;
+ }) != undefined
+ </t>
<t t-if="the_condition">
<a class="toggle-sidebar"></a>
<div t-att-id="element_id" class="sidebar-sub-div">