From 506a85c80e4de6ccd71bf33e71e086b5ee10d26b Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Thu, 24 Mar 2011 17:31:14 +0100 Subject: [PATCH] viewmanager part1 bzr revid: al@openerp.com-20110324163114-dvoi8l3nzmut5y63 --- addons/base/controllers/main.py | 2 + addons/base/static/openerp/base.xml | 25 +++-- addons/base/static/openerp/js/base_chrome.js | 2 +- addons/base/static/openerp/js/base_views.js | 111 +++++++++---------- 4 files changed, 70 insertions(+), 70 deletions(-) diff --git a/addons/base/controllers/main.py b/addons/base/controllers/main.py index 11db3d3a5c2..af790ad1357 100644 --- a/addons/base/controllers/main.py +++ b/addons/base/controllers/main.py @@ -156,8 +156,10 @@ class Menu(openerpweb.Controller): @openerpweb.jsonrequest def action(self, req, menu_id): + print "QUERY" m = req.session.model('ir.values') r = m.get('action', 'tree_but_open', [('ir.ui.menu', menu_id)], False, {}) + print r res = {"action": r} return res diff --git a/addons/base/static/openerp/base.xml b/addons/base/static/openerp/base.xml index c416d9cf093..094b732a928 100644 --- a/addons/base/static/openerp/base.xml +++ b/addons/base/static/openerp/base.xml @@ -124,6 +124,21 @@ + + +
+ + + + +
+
+ +
+
+
-
- - -
- -
-
-
diff --git a/addons/base/static/openerp/js/base_chrome.js b/addons/base/static/openerp/js/base_chrome.js index 08b69db7e6f..dedcdd0e61a 100644 --- a/addons/base/static/openerp/js/base_chrome.js +++ b/addons/base/static/openerp/js/base_chrome.js @@ -542,7 +542,7 @@ openerp.base.WebClient = openerp.base.Controller.extend({ this.menu.start(); }, on_loggued: function() { - this.action = new openerp.base.Action(this.session, "oe_application"); + this.action = new openerp.base.ActionManager(this.session, "oe_application"); this.action.start(); }, on_menu_action: function(action) { diff --git a/addons/base/static/openerp/js/base_views.js b/addons/base/static/openerp/js/base_views.js index 9fb79ca962d..913456053d3 100644 --- a/addons/base/static/openerp/js/base_views.js +++ b/addons/base/static/openerp/js/base_views.js @@ -6,12 +6,28 @@ openerp.base$views = function(openerp) { // process all kind of actions openerp.base.ActionManager = openerp.base.Controller.extend({ -// This controller should be used for one2many also or not ? -// to replace Action + init: function(session, element_id) { + this._super(session, element_id); + this.action = null; + this.viewmanager = null; + }, + /** + * Process an action + * Supported actions: act_window + */ + do_action: function(action) { + // instantiate the right controllers by understanding the action + this.action = action; + if(action.type == "ir.actions.act_window") { + this.viewmanager = new openerp.base.ViewManager(this.session,this.element_id); + this.viewmanager.do_action_window(action); + this.viewmanager.start(); + } + }, }); // This will be ViewManager Abstract/Common -openerp.base.Action = openerp.base.Controller.extend({ +openerp.base.ViewManager = openerp.base.Controller.extend({ init: function(session, element_id) { this._super(session, element_id); this.action = null; @@ -19,79 +35,56 @@ openerp.base.Action = openerp.base.Controller.extend({ this.searchview_id = false; this.searchview = null; this.search_visible = true; - - // this will be changed into // this.views = { "list": { "view_id":1234, "controller": instance} } - this.listview_id = false; - this.listview = null; - this.formview_id = false; - this.formview = null; + this.views = {}; }, start: function() { - this.$element.html(QWeb.render("Action", {"prefix":this.element_id})); - this.$element.find("#mode_list").bind('click',this.on_mode_list); - this.$element.find("#mode_form").bind('click',this.on_mode_form); - this.on_mode_list(); }, - // this will be changed into on_view_switch(kind_of_view) - on_mode_list: function() { - $("#oe_action_form").hide(); - $("#oe_action_search").show(); - $("#oe_action_list").show(); - }, - on_mode_form: function() { - $("#oe_action_form").show(); - $("#oe_action_search").hide(); - $("#oe_action_list").hide(); - }, - // This will move to actionmanager - do_action: function(action) { - // instantiate the right controllers by understanding the action - this.action = action; - this.log(action); -// debugger; - //this.log(action); - if(action.type == "ir.actions.act_window") { - this.do_action_window(action); + on_mode_switch: function(view_type) { + for (var i in this.views) { + if(i == view_type) { + this.views.i.controller.$element.show(); + } else { + this.views.i.controller.$element.hide(); + } } }, - // this will be renamed setup_view_manager_from_an_actwindow and will setup this.views do_action_window: function(action) { - // this will move into set_dataset() + var self = this; + var prefix_id = "#" + this.element_id; + this.action = action; this.dataset = new openerp.base.DataSet(this.session, action.res_model); this.dataset.start(); + this.$element.html(QWeb.render("ViewManager", {"prefix": this.element_id, views: action.views})); + this.searchview_id = false; - if(this.listview && action.search_view_id) { + if(this.search_visible && action.search_view_id) { this.searchview_id = action.search_view_id[0]; + this.searchview = new openerp.base.SearchView(this.session, this.element_id + "_search", this.dataset, this.searchview_id); + this.searchview.start(); } - this.searchview = new openerp.base.SearchView(this.session, "oe_action_search", this.dataset, this.searchview_id); - this.searchview.start(); - - // Those two will be a foreach kind of view - - // Locate first tree view - this.listview_id = false; for(var i = 0; i < action.views.length; i++) { + var view_id, controller; + view_id = action.views[i][0]; if(action.views[i][1] == "tree") { - this.listview_id = action.views[i][0]; - break; + controller = new openerp.base.ListView(this.session, this.element_id + "_view_tree", this.dataset, view_id); + controller.start(); + this.views.tree = { view_id: view_id, controller: controller }; + this.$element.find(prefix_id + "_button_tree").bind('click',function(){ + this.on_mode_switch("tree"); + }); + } else if(action.views[i][1] == "form") { + controller = new openerp.base.FormView(this.session, this.element_id + "_view_form", this.dataset, view_id); + controller.start(); + this.views.form = { view_id: view_id, controller: controller }; + this.$element.find(prefix_id + "_button_form").bind('click',function(){ + this.on_mode_switch("form"); + }); } } - this.listview = new openerp.base.ListView(this.session, "oe_action_list", this.dataset, this.listview_id); - this.listview.start(); - - // Locate first form view - this.formview_id = false; - for(var j = 0; j < action.views.length; j++) { - if(action.views[j][1] == "form") { - this.formview_id = action.views[j][0]; - break; - } - } - this.formview = new openerp.base.FormView(this.session, "oe_action_form", this.dataset, this.formview_id); - this.formview.start(); - + // switch to the first one in sequence + this.on_mode_switch("tree"); }, // create when root, also add to parent when o2m on_create: function() {