openerp-dev-web team mailing list archive
-
openerp-dev-web team
-
Mailing list archive
-
Message #01139
[Merge] lp:~openerp-dev/openobject-client-web/listview-button-action into lp:openobject-client-web
vda(Open ERP) has proposed merging lp:~openerp-dev/openobject-client-web/listview-button-action into lp:openobject-client-web.
Requested reviews:
OpenERP SA's Web Client R&D (openerp-dev-web)
Related bugs:
#686572 [trunk]Wizard actions from tree views not working
https://bugs.launchpad.net/bugs/686572
Improved ListView's button action
Working perfect using doLoadingSuccess except 1 case where:
button is used to change the state and reload the list to reflect changed state.(Ex:Sales > Opportunities > Any record > Click on any Stage button/img)
In this case only `True` is written and no target in xhr and no url.
So doLoadingSuccess can't handle this case.
--
https://code.launchpad.net/~openerp-dev/openobject-client-web/listview-button-action/+merge/43200
Your team OpenERP SA's Web Client R&D is requested to review the proposed merge of lp:~openerp-dev/openobject-client-web/listview-button-action into lp:openobject-client-web.
=== modified file 'addons/openerp/controllers/listgrid.py'
--- addons/openerp/controllers/listgrid.py 2010-11-24 09:57:01 +0000
+++ addons/openerp/controllers/listgrid.py 2010-12-09 12:57:56 +0000
@@ -308,7 +308,6 @@
@expose('json')
def button_action(self, **kw):
params, data = TinyDict.split(kw)
-
error = None
reload = (params.context or {}).get('reload', False)
result = {}
@@ -326,20 +325,24 @@
try:
if btype == 'workflow':
- rpc.session.execute('object', 'exec_workflow', model, name, id)
+ res = rpc.session.execute('object', 'exec_workflow', model, name, id)
+ if isinstance(res, dict):
+ import actions
+ return actions.execute(res, ids=[id])
+ else:
+ return True
elif btype == 'object':
ctx = params.context or {}
ctx.update(rpc.session.context.copy())
res = rpc.session.execute('object', 'execute', model, name, ids, ctx)
- if isinstance(res, dict) and res.get('type'):
- if res['type'] == 'ir.actions.act_url':
- result = res
- elif res['type'] == 'ir.actions.act_window':
- import actions
- res = actions.execute(res)
- return dict(res = res)
+ if isinstance(res, dict):
+ import actions
+ return actions.execute(res, ids=[id])
+ else:
+ return True
+
elif btype == 'action':
import actions
@@ -352,19 +355,15 @@
cherrypy.session['wizard_parent_params'] = params
res = actions.execute_by_id(action_id, type=action_type, model=model, id=id, ids=ids, context=ctx or {})
- if isinstance(res, dict) and res.get('type') == 'ir.actions.act_url':
- result = res
- elif isinstance(res, basestring):
- return dict(res = res)
+ if res:
+ return res
else:
- error = "Button action has returned another view.."
+ return True
else:
- error = "Unallowed button type"
+ return dict(error = "Unallowed button type")
except Exception, e:
- error = ustr(e)
-
- return dict(error=error, result=result, reload=reload)
+ return dict(error = ustr(e))
@expose('json', methods=('POST',))
def groupbyDrag(self, model, children, domain):
=== modified file 'addons/openerp/static/javascript/listgrid.js'
--- addons/openerp/static/javascript/listgrid.js 2010-12-08 15:38:44 +0000
+++ addons/openerp/static/javascript/listgrid.js 2010-12-09 12:57:56 +0000
@@ -437,10 +437,11 @@
if (sure && !confirm(sure)) {
return;
}
-
+
var self = this;
+ var _list = this.name;
var prefix = this.name == '_terp_list' ? '' : this.name + '/';
-
+ console.log('Prefix', prefix, this.name)
if (btype == "open") {
return window.open(get_form_action('/openerp/form/edit', {
id: id,
@@ -465,36 +466,23 @@
var req = eval_domain_context_request({source: this.name, context : context || '{}',active_id: id, active_ids: openobject.dom.get(prefix + '_terp_ids').value});
req.addCallback(function(res) {
- params['_terp_context'] = res.context;
- var req = openobject.http.postJSON('/openerp/listgrid/button_action', params);
- req.addCallback(function(obj) {
- if (obj.error) {
- return error_display(obj.error);
- }
-
- if (obj.result && obj.result.url) {
- window.open(obj.result.url);
- }
-
- if(obj.res) {
- var popup_win = openobject.tools.openWindow("");
- if(window.browser.isGecko) {
- popup_win.document.write(obj.res);
- popup_win.document.close();
- }
- else {
- popup_win.document.close();
- popup_win.document.write(obj.res);
- }
- return false;
- }
-
- if (obj.reload) {
- window.location.reload();
- } else {
- self.reload();
- }
- });
+ var $form = jQuery('#listgrid_button_action');
+ params['_terp_context'] = res.context || '{}';
+ if($form.length) {
+ $form.remove();
+ }
+ var $form = jQuery('<form>', {
+ 'id': 'listgrid_button_action',
+ 'name': 'listgrid_button_action',
+ 'action':'/openerp/listgrid/button_action',
+ 'method': 'post',
+ 'enctype': 'multipart/form-data'
+ }).appendTo(document.documentElement);
+ $form.ajaxSubmit({
+ data: params,
+ success: doLoadingSuccess(jQuery('#appContent')),
+ error: loadingError()
+ });
});
}
});
Follow ups