X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=addons%2Fweb%2Fstatic%2Fsrc%2Fjs%2Fviews.js;h=7b58818bec0064edaedda4fb8704a7a95b97f2ab;hb=bf29cecca3d412add5d764137835a5028de44c95;hp=9d12faf608f38a8865e0c0bfe625993efe6d553b;hpb=a83724caae1e968268e330ca8b2051763056b7e4;p=odoo%2Fodoo.git diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 9d12faf..7b58818 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -24,11 +24,9 @@ instance.web.ActionManager = instance.web.Widget.extend({ }, dialog_stop: function () { if (this.dialog) { - this.dialog_widget.destroy(); - this.dialog_widget = null; this.dialog.destroy(); - this.dialog = null; } + this.dialog = null; }, /** * Add a new item to the breadcrumb @@ -99,6 +97,10 @@ instance.web.ActionManager = instance.web.Widget.extend({ this.select_breadcrumb(index, subindex); }, select_breadcrumb: function(index, subindex) { + var next_item = this.breadcrumbs[index + 1]; + if (next_item && next_item.on_reverse_breadcrumb) { + next_item.on_reverse_breadcrumb(this.breadcrumbs[index].widget); + } for (var i = this.breadcrumbs.length - 1; i >= 0; i--) { if (i > index) { if (this.remove_breadcrumb(i) === false) { @@ -109,6 +111,7 @@ instance.web.ActionManager = instance.web.Widget.extend({ var item = this.breadcrumbs[index]; item.show(subindex); this.inner_widget = item.widget; + this.inner_action = item.action; return true; }, clear_breadcrumbs: function() { @@ -127,6 +130,7 @@ instance.web.ActionManager = instance.web.Widget.extend({ if (!dups.length) { if (this.getParent().has_uncommitted_changes()) { this.inner_widget = item.widget; + this.inner_action = item.action; this.breadcrumbs.splice(index, 0, item); return false; } else { @@ -135,7 +139,10 @@ instance.web.ActionManager = instance.web.Widget.extend({ } } var last_widget = this.breadcrumbs.slice(-1)[0]; - this.inner_widget = last_widget && last_widget.widget; + if (last_widget) { + this.inner_widget = last_widget.widget; + this.inner_action = last_widget.action; + } }, get_title: function() { var titles = []; @@ -160,15 +167,28 @@ instance.web.ActionManager = instance.web.Widget.extend({ state = state || {}; if (this.getParent() && this.getParent().do_push_state) { if (this.inner_action) { + if (this.inner_action._push_me === false) { + // this action has been explicitly marked as not pushable + return; + } state['title'] = this.inner_action.name; if(this.inner_action.type == 'ir.actions.act_window') { state['model'] = this.inner_action.res_model; } + if (this.inner_action.menu_id) { + state['menu_id'] = this.inner_action.menu_id; + } if (this.inner_action.id) { state['action'] = this.inner_action.id; } else if (this.inner_action.type == 'ir.actions.client') { state['action'] = this.inner_action.tag; - //state = _.extend(this.inner_action.params || {}, state); + var params = {}; + _.each(this.inner_action.params, function(v, k) { + if(_.isString(v) || _.isNumber(v)) { + params[k] = v; + } + }); + state = _.extend(params || {}, state); } } if(!this.dialog) { @@ -181,7 +201,12 @@ instance.web.ActionManager = instance.web.Widget.extend({ action_loaded; if (state.action) { if (_.isString(state.action) && instance.web.client_actions.contains(state.action)) { - var action_client = {type: "ir.actions.client", tag: state.action, params: state}; + var action_client = { + type: "ir.actions.client", + tag: state.action, + params: state, + _push_me: state._push_me, + }; this.null_action(); action_loaded = this.do_action(action_client); } else { @@ -189,8 +214,12 @@ instance.web.ActionManager = instance.web.Widget.extend({ if (run_action) { this.null_action(); action_loaded = this.do_action(state.action); - instance.webclient.menu.has_been_loaded.then(function() { - instance.webclient.menu.open_action(state.action); + $.when(action_loaded || null).done(function() { + instance.webclient.menu.has_been_loaded.done(function() { + if (self.inner_action && self.inner_action.id) { + instance.webclient.menu.open_action(self.inner_action.id); + } + }); }); } } @@ -207,29 +236,48 @@ instance.web.ActionManager = instance.web.Widget.extend({ } else if (state.sa) { // load session action this.null_action(); - action_loaded = this.rpc('/web/session/get_session_action', {key: state.sa}).pipe(function(action) { + action_loaded = this.rpc('/web/session/get_session_action', {key: state.sa}).then(function(action) { if (action) { return self.do_action(action); } }); } - $.when(action_loaded || null).then(function() { + $.when(action_loaded || null).done(function() { if (self.inner_widget && self.inner_widget.do_load_state) { self.inner_widget.do_load_state(state, warm); } }); }, - do_action: function(action, on_close, clear_breadcrumbs) { - if (_.isString(action) && instance.web.client_actions.contains(action)) { - var action_client = { type: "ir.actions.client", tag: action }; - return this.do_action(action_client, on_close, clear_breadcrumbs); + do_action: function(action, options) { + options = _.defaults(options || {}, { + clear_breadcrumbs: false, + on_reverse_breadcrumb: function() {}, + on_close: function() {}, + action_menu_id: null, + }); + if (action === false) { + action = { type: 'ir.actions.act_window_close' }; + } else if (_.isString(action) && instance.web.client_actions.contains(action)) { + var action_client = { type: "ir.actions.client", tag: action, params: {} }; + return this.do_action(action_client, options); } else if (_.isNumber(action) || _.isString(action)) { var self = this; - return self.rpc("/web/action/load", { action_id: action }).pipe(function(result) { - return self.do_action(result.result, on_close, clear_breadcrumbs); + return self.rpc("/web/action/load", { action_id: action }).then(function(result) { + return self.do_action(result, options); }); } + + // Ensure context & domain are evaluated and can be manipulated/used + if (action.context) { + action.context = instance.web.pyeval.eval( + 'context', action.context); + } + if (action.domain) { + action.domain = instance.web.pyeval.eval( + 'domain', action.domain); + } + if (!action.type) { console.error("No type for action", action); return $.Deferred().reject(); @@ -245,113 +293,152 @@ instance.web.ActionManager = instance.web.Widget.extend({ pager : !popup && !inline, display_title : !popup }, action.flags || {}); + action.menu_id = options.action_menu_id; if (!(type in this)) { console.error("Action manager can't handle action of type " + action.type, action); return $.Deferred().reject(); } - return this[type](action, on_close, clear_breadcrumbs); + return this[type](action, options); }, null_action: function() { this.dialog_stop(); this.clear_breadcrumbs(); }, - ir_actions_common: function(action, on_close, clear_breadcrumbs) { - var self = this, klass, widget, post_process; - if (this.inner_widget && (action.type === 'ir.actions.client' || action.target !== 'new')) { + /** + * + * @param {Object} executor + * @param {Object} executor.action original action + * @param {Function} executor.widget function used to fetch the widget instance + * @param {String} executor.klass CSS class to add on the dialog root, if action.target=new + * @param {Function} executor.post_process cleanup called after a widget has been added as inner_widget + * @param {Object} options + * @return {*} + */ + ir_actions_common: function(executor, options) { + if (this.inner_widget && executor.action.target !== 'new') { if (this.getParent().has_uncommitted_changes()) { return $.Deferred().reject(); - } else if (clear_breadcrumbs) { + } else if (options.clear_breadcrumbs) { this.clear_breadcrumbs(); } } - if (action.type === 'ir.actions.client') { - var ClientWidget = instance.web.client_actions.get_object(action.tag); - widget = new ClientWidget(this, action.params); - klass = 'oe_act_client'; - post_process = function() { - self.push_breadcrumb({ - widget: widget, - title: action.name - }); - if (action.tag !== 'reload') { - self.do_push_state({}); - } - }; - } else { - widget = new instance.web.ViewManagerAction(this, action); - klass = 'oe_act_window'; - post_process = widget.proxy('add_breadcrumb'); - } - if (action.target === 'new') { - if (this.dialog === null) { - // These buttons will be overwrited by