From 9de40c4451c5efd310838a137ed4c2a9323f4cab Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Mon, 6 Jun 2011 15:34:24 +0200 Subject: [PATCH] [ADD] Add Widget feature in dashboards bzr revid: fme@openerp.com-20110606133424-7ffjdm5kbvktht9k --- .../static/src/css/dashboard.css | 3 +- .../base_dashboard/static/src/js/dashboard.js | 63 +++++++++++++++++++ .../static/src/xml/base_dashboard.xml | 21 ++++--- 3 files changed, 76 insertions(+), 11 deletions(-) diff --git a/addons/base_dashboard/static/src/css/dashboard.css b/addons/base_dashboard/static/src/css/dashboard.css index 9dd03284eff..4fd734b2e7c 100644 --- a/addons/base_dashboard/static/src/css/dashboard.css +++ b/addons/base_dashboard/static/src/css/dashboard.css @@ -50,7 +50,8 @@ .openerp .oe-dashboard-layout_1 .oe-dashboard-column { width: 100%; } -.openerp .oe-dashboard-layout_1 .oe-dashboard-column.index_1 .oe-dashboard-column.index_2 { +.openerp .oe-dashboard-layout_1 .oe-dashboard-column.index_1, +.openerp .oe-dashboard-layout_1 .oe-dashboard-column.index_2 { display: none; } diff --git a/addons/base_dashboard/static/src/js/dashboard.js b/addons/base_dashboard/static/src/js/dashboard.js index 6e6a0a5a1f1..23c784d9a50 100644 --- a/addons/base_dashboard/static/src/js/dashboard.js +++ b/addons/base_dashboard/static/src/js/dashboard.js @@ -6,6 +6,7 @@ openerp.base.form.DashBoard = openerp.base.form.Widget.extend({ init: function(view, node) { this._super(view, node); this.template = "DashBoard"; + this.actions_attrs = {}; }, start: function() { var self = this; @@ -50,6 +51,68 @@ openerp.base.form.DashBoard = openerp.base.form.Widget.extend({ }, this.do_reload); }, on_add_widget: function() { + var self = this; + var action = { + res_model : 'ir.actions.actions', + views : [[false,"list"]], + type : 'ir.actions.act_window', + view_type : 'list', + view_mode : 'list', + limit : 80, + auto_search : true, + domain : [['type', '=', 'ir.actions.act_window']], + flags : { + sidebar : false, + views_switcher : false, + action_buttons : false + } + }; + // TODO: create a Dialog controller which optionally takes an action + // Should set width & height automatically and take buttons & views callback + var dialog_id = _.uniqueId("act_window_dialog"); + var action_manager = new openerp.base.ActionManager(this.session, dialog_id); + var $dialog = $('
').dialog({ + modal : true, + title : 'Actions', + width : 800, + height : 600, + buttons : { + Cancel : function() { + $(this).dialog("destroy"); + }, + Add : function() { + self.do_add_widget(action_manager); + $(this).dialog("destroy"); + } + } + }); + action_manager.start(); + action_manager.do_action(action); + // TODO: should bind ListView#select_record in order to catch record clicking + }, + do_add_widget : function(action_manager) { + var self = this, + actions = action_manager.viewmanager.views.list.controller.groups.get_selection().ids, + results = [], + qdict = { view : this.view }; + console.log(this.actions_attrs) + // TODO: should load multiple actions at once + _.each(actions, function(aid) { + self.rpc('/base/action/load', { + action_id: aid + }, function(result) { + self.actions_attrs[aid] = { + name: aid, + string: _.trim(result.result.name) + } + qdict.action = { + attrs : self.actions_attrs[aid] + } + self.$element.find('.oe-dashboard-column:first').prepend(QWeb.render('DashBoard.action', qdict)); + self.do_save_dashboard(); + self.on_load_action(result) + }); + }); }, on_change_layout: function() { var self = this; diff --git a/addons/base_dashboard/static/src/xml/base_dashboard.xml b/addons/base_dashboard/static/src/xml/base_dashboard.xml index fbe34a3892b..dc65a71b8fc 100644 --- a/addons/base_dashboard/static/src/xml/base_dashboard.xml +++ b/addons/base_dashboard/static/src/xml/base_dashboard.xml @@ -22,19 +22,20 @@
-
- -
- - - -
-
-
+
+ +
+
+ + + +
+
+
+