diff --git a/addons/base/controllers/main.py b/addons/base/controllers/main.py index 51d7ed91547..b289259b1f1 100644 --- a/addons/base/controllers/main.py +++ b/addons/base/controllers/main.py @@ -239,7 +239,6 @@ def eval_context_and_domain(session, context, domain=None): return (e_context, e_domain) def load_actions_from_ir_values(req, key, key2, models, meta, context): - context['bin_size'] = False # Possible upstream bug. Antony says not to loose time on this. Values = req.session.model('ir.values') actions = Values.get(key, key2, models, meta, context) @@ -757,7 +756,6 @@ class Action(openerpweb.Controller): Actions = req.session.model('ir.actions.actions') value = False context = req.session.eval_context(req.context) - context["bin_size"] = False action_type = Actions.read([action_id], ['type'], context) if action_type: action = req.session.model(action_type[0]['type']).read([action_id], False, diff --git a/addons/base/static/src/js/chrome.js b/addons/base/static/src/js/chrome.js index b019d7f1867..556c715d339 100644 --- a/addons/base/static/src/js/chrome.js +++ b/addons/base/static/src/js/chrome.js @@ -137,6 +137,29 @@ openerp.base.Registry = Class.extend( /** @lends openerp.base.Registry# */ { } return object_match; }, + /** + * Tries a number of keys, and returns the first object matching one of + * the keys. + * + * @param {Array} keys a sequence of keys to fetch the object for + * @returns {Class} the first class found matching an object + * + * @throws {openerp.base.KeyNotFound} if none of the keys was in the mapping + * @trows {openerp.base.ObjectNotFound} if a found object path was invalid + */ + get_any: function (keys) { + for (var i=0; i= 1 && value[0] instanceof Array) { var ids = []; - _each(value, function(command) { - if(command[0] == 0) { - var obj = {id: _.uniqueId(self.dataset.virtual_id_prefix), values: command[2]}; - self.dataset.to_create.push(obj); - self.dataset.cache.push(_.clone(obj)); - ids.push(obj.id); - } else if(command[0] == 1) { - var obj = {id: command[1], values: command[2]}; - self.dataset.to_write.push(obj); - self.dataset.cache.push(_.clone(obj)); - ids.push(obj.id); - } else if(command[0] == 2) { - self.dataset.to_delete.push({id: command[1]}); - } else if(command[0] == 4) { - ids.push(command[1]); + _.each(value, function(command) { + var obj = {values: command[2]}; + switch (command[0]) { + case commands.CREATE: + obj['id'] = _.uniqueId(self.dataset.virtual_id_prefix); + self.dataset.to_create.push(obj); + self.dataset.cache.push(_.clone(obj)); + ids.push(obj.id); + return; + case commands.UPDATE: + obj['id'] = command[1]; + self.dataset.to_write.push(obj); + self.dataset.cache.push(_.clone(obj)); + ids.push(obj.id); + return; + case commands.DELETE: + self.dataset.to_delete.push({id: command[1]}); + return; + case commands.LINK_TO: + ids.push(command[1]); + return; } }); this._super(ids); @@ -1431,16 +1469,17 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({ var val = _.map(this.dataset.ids, function(id) { var alter_order = _.detect(self.dataset.to_create, function(x) {return x.id === id;}); if (alter_order) { - return [0, 0, alter_order.values]; + return commands.create(alter_order.values); } alter_order = _.detect(self.dataset.to_write, function(x) {return x.id === id;}); if (alter_order) { - return [1, alter_order.id, alter_order.values]; + return commands.update(alter_order.id, alter_order.values); } - return [4, id]; + return commands.link_to(id); }); - val = val.concat(_.map(this.dataset.to_delete, function(v, k) {return [2, x.id];})); - return val; + return val.concat(_.map( + this.dataset.to_delete, function(x) { + return commands['delete'](x.id);})); }, validate: function() { this.invalid = false; @@ -1509,7 +1548,7 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({ }); }, get_value: function() { - return [[6,false,this.dataset.ids]]; + return [commands.replace_with(this.dataset.ids)]; } }); diff --git a/addons/base/static/src/js/views.js b/addons/base/static/src/js/views.js index 8b87d9cbdbe..e9774fe478c 100644 --- a/addons/base/static/src/js/views.js +++ b/addons/base/static/src/js/views.js @@ -18,7 +18,7 @@ openerp.base.ActionManager = openerp.base.Controller.extend({ * Process an action * Supported actions: act_window */ - do_action: function(action) { + do_action: function(action, on_closed) { var self = this; action.flags = _.extend({ sidebar : action.target != 'new', @@ -31,6 +31,9 @@ openerp.base.ActionManager = openerp.base.Controller.extend({ // instantiate the right controllers by understanding the action switch (action.type) { case 'ir.actions.act_window': + if (!action.target && this.dialog_stack.length) { + action.flags.new_window = true; + } if (action.target == 'new') { var element_id = _.uniqueId("act_window_dialog"); $('
', {id: element_id}).dialog({ @@ -44,6 +47,8 @@ openerp.base.ActionManager = openerp.base.Controller.extend({ }); var viewmanager = new openerp.base.ViewManagerAction(this.session, element_id, action); viewmanager.start(); + viewmanager.on_act_window_closed.add(on_closed); + viewmanager.is_dialog = true; this.dialog_stack.push(viewmanager); } else if (action.flags.new_window) { action.flags.new_window = false; @@ -62,6 +67,9 @@ openerp.base.ActionManager = openerp.base.Controller.extend({ break; case 'ir.actions.act_window_close': var dialog = this.dialog_stack.pop(); + if (!action.special) { + dialog.on_act_window_closed(); + } dialog.$element.dialog('destroy'); dialog.stop(); break; @@ -84,6 +92,7 @@ openerp.base.ViewManager = openerp.base.Controller.extend({ this.flags = this.flags || {}; this.sidebar = new openerp.base.NullSidebar(); this.registry = openerp.base.views; + this.is_dialog = false; }, /** * @returns {jQuery.Deferred} initial view loading promise @@ -127,16 +136,19 @@ openerp.base.ViewManager = openerp.base.Controller.extend({ } if (view_type === 'list' && this.flags.search_view === false && this.action && this.action['auto_search']) { // In case the search view is not instanciated: manually call ListView#search + var domains = !_(self.action.domain).isEmpty() + ? [self.action.domain] : [], + contexts = !_(self.action.context).isEmpty() + ? [self.action.context] : []; controller.on_loaded.add({ callback: function () { - controller.do_search([self.action.domain], [self.action.context], []); + controller.do_search(domains, contexts, []); }, position: 'last', unique: true }); } view_promise = controller.start(); - var self = this; $.when(view_promise).then(function() { self.on_controller_inited(view_type, controller); }); @@ -157,12 +169,13 @@ openerp.base.ViewManager = openerp.base.Controller.extend({ .filter('[data-view-type="' + view_type + '"]') .attr('disabled', true); - for (var i in this.views) { - if (this.views[i].controller) { - if (i === view_type) { - $.when(view_promise).then(this.views[i].controller.do_show); + for (var view_name in this.views) { + if (!this.views.hasOwnProperty(view_name)) { continue; } + if (this.views[view_name].controller) { + if (view_name === view_type) { + $.when(view_promise).then(this.views[view_name].controller.do_show); } else { - this.views[i].controller.do_hide(); + this.views[view_name].controller.do_hide(); } } } @@ -197,6 +210,11 @@ openerp.base.ViewManager = openerp.base.Controller.extend({ }); return this.searchview.start(); }, + /** + * Called when this view manager has been created by an action 'act_window@target=new' is closed + */ + on_act_window_closed : function() { + }, /** * Called when one of the view want to execute an action */ @@ -238,12 +256,14 @@ openerp.base.NullViewManager = openerp.base.generate_null_object_class(openerp.b openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({ init: function(session, element_id, action) { var dataset; - if(!action.res_id) { - dataset = new openerp.base.DataSetSearch(session, action.res_model); + if (!action.res_id) { + dataset = new openerp.base.DataSetSearch(session, action.res_model, action.context || null); } else { - dataset = new openerp.base.DataSetStatic(session, action.res_model); - dataset.ids = [action.res_id]; - dataset.count = 1; + dataset = new openerp.base.DataSetStatic(session, action.res_model, [action.res_id]); + if (action.context) { + // TODO fme: should normalize all DataSets constructors to (session, model, context, ...) + dataset.context = action.context; + } } this._super(session, element_id, dataset, action.views); this.action = action; @@ -409,14 +429,17 @@ openerp.base.View = openerp.base.Controller.extend({ * @param {Object} [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) { + execute_action: function (action_data, dataset, action_manager, record_id, on_no_action, on_closed) { + var self = this; var handler = function (r) { var action = r.result; if (action && action.constructor == Object) { action.context = action.context || {}; - action.context['active_id'] = dataset.ids[dataset.index]; - action.context['active_ids'] = [dataset.ids[dataset.index]]; - action.context['active_model'] = dataset.model; + _.extend(action.context, { + active_id: dataset.ids[dataset.index], + active_ids: [dataset.ids[dataset.index]], + active_model: dataset.model + }); action.flags = { sidebar : false, search_view : false, @@ -424,7 +447,12 @@ openerp.base.View = openerp.base.Controller.extend({ action_buttons : false, pager : false }; - action_manager.do_action(action); + action_manager.do_action(action, on_closed); + if (self.view_manager.is_dialog && action.type != 'ir.actions.act_window_close') { + handler({ + result : { type: 'ir.actions.act_window_close' } + }); + } } else { on_no_action(action); } @@ -432,7 +460,7 @@ openerp.base.View = openerp.base.Controller.extend({ if (action_data.special) { handler({ - result : { type: 'ir.actions.act_window_close' } + result : { type: 'ir.actions.act_window_close', special: action_data.special } }); } else { var context = new openerp.base.CompoundContext(dataset.context).add(action_data.context || {}); @@ -476,7 +504,7 @@ openerp.base.json_node_to_xml = function(node, single_quote, indent) { throw("Node a json node"); } indent = indent || 0; - var sindent = Array(indent + 1).join('\t'), + var sindent = new Array(indent + 1).join('\t'), r = sindent + '<' + node.tag; for (var attr in node.attrs) { var vattr = node.attrs[attr]; diff --git a/openerpweb/nonliterals.py b/openerpweb/nonliterals.py index 097ba54fe01..a99e2215a00 100644 --- a/openerpweb/nonliterals.py +++ b/openerpweb/nonliterals.py @@ -197,9 +197,9 @@ class CompoundDomain(BaseDomain): final_domain = [] for domain in self.domains: if not isinstance(domain, (list, BaseDomain)): - raise TypeError("Domain %r is not a list or a nonliteral Domain", - domain) - + raise TypeError( + "Domain %r is not a list or a nonliteral Domain" % domain) + if isinstance(domain, list): final_domain.extend(domain) continue @@ -237,9 +237,9 @@ class CompoundContext(BaseContext): final_context = {} for context_to_eval in self.contexts: if not isinstance(context_to_eval, (dict, BaseContext)): - raise TypeError("Context %r is not a dict or a nonliteral Context", - context_to_eval) - + raise TypeError( + "Context %r is not a dict or a nonliteral Context" % context_to_eval) + if isinstance(context_to_eval, dict): final_context.update(context_to_eval) continue diff --git a/openerpweb/openerpweb.py b/openerpweb/openerpweb.py index 9da14d5ace0..dcdf981533a 100644 --- a/openerpweb/openerpweb.py +++ b/openerpweb/openerpweb.py @@ -138,15 +138,13 @@ class OpenERPSession(object): """ assert self._uid, "The user needs to be logged-in to initialize his context" self.context = self.model('res.users').context_get(self.context) - # set bin_size to True all the time self.context = self.context or {} - self.context["bin_size"] = True - + self.client_timezone = self.context.get("tz", False) # invalid code, anyway we decided the server will be in UTC #if self.client_timezone: # self.remote_timezone = self.execute('common', 'timezone_get') - + self._locale = self.context.get('lang','en_US') lang_ids = self.execute('res.lang','search', [('code', '=', self._locale)]) if lang_ids: