[FIX] selector for config overview widget: widget root has moved, .oe-dashboard-confi...
[odoo/odoo.git] / addons / base_dashboard / static / src / js / dashboard.js
index 0c58bb2..e5b06a1 100644 (file)
@@ -7,6 +7,7 @@ openerp.base.form.DashBoard = openerp.base.form.Widget.extend({
         this._super(view, node);
         this.template = 'DashBoard';
         this.actions_attrs = {};
+        this.action_managers = [];
     },
     start: function() {
         var self = this;
@@ -23,8 +24,9 @@ openerp.base.form.DashBoard = openerp.base.form.Widget.extend({
         this.$element.find('.oe-dashboard-link-reset').click(this.on_reset);
         this.$element.find('.oe-dashboard-link-add_widget').click(this.on_add_widget);
         this.$element.find('.oe-dashboard-link-change_layout').click(this.on_change_layout);
-        this.$element.find('.oe-dashboard-column .oe-dashboard-fold').click(this.on_fold_action);
-        this.$element.find('.oe-dashboard-column .ui-icon-closethick').click(this.on_close_action);
+
+        this.$element.delegate('.oe-dashboard-column .oe-dashboard-fold', 'click', this.on_fold_action);
+        this.$element.delegate('.oe-dashboard-column .ui-icon-closethick', 'click', this.on_close_action);
 
         this.actions_attrs = {};
         // Init actions
@@ -40,7 +42,10 @@ openerp.base.form.DashBoard = openerp.base.form.Widget.extend({
             });
         });
 
-        this.$element.find('a.oe-dashboard-action-rename').live('click', this.on_rename);
+        //this.$element.find('a.oe-dashboard-action-rename').live('click', this.on_rename);
+        this.$element.find('.oe-dashboard-action').live('mouseover mouseout', function(event) {
+            $(this).find('.oe-dashboard-action-header .ui-icon, .oe-dashboard-action-header .oe-dashboard-action-rename').toggle(event.type == 'mouseover');
+        });
     },
     on_undo: function() {
         this.rpc('/base/view/undo_custom', {
@@ -55,7 +60,23 @@ openerp.base.form.DashBoard = openerp.base.form.Widget.extend({
     },
     on_add_widget: function() {
         var self = this;
-        var action = {
+        var action_manager = new openerp.base.ActionManager(this);
+        var dialog = new openerp.base.Dialog(this, {
+            title : 'Actions',
+            width: 800,
+            height: 600,
+            buttons : {
+                Cancel : function() {
+                    $(this).dialog('destroy');
+                },
+                Add : function() {
+                    self.do_add_widget(action_manager.inner_viewmanager.views.list.controller);
+                    $(this).dialog('destroy');
+                }
+            }
+        }).start().open();
+        action_manager.appendTo(dialog.$element);
+        action_manager.do_action({
             res_model : 'ir.actions.actions',
             views : [[false, 'list']],
             type : 'ir.actions.act_window',
@@ -66,33 +87,12 @@ openerp.base.form.DashBoard = openerp.base.form.Widget.extend({
                 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 = $('<div id=' + dialog_id + '>').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) {
+    do_add_widget : function(listview) {
         var self = this,
-            actions = action_manager.viewmanager.views.list.controller.groups.get_selection().ids,
+            actions = listview.groups.get_selection().ids,
             results = [],
             qdict = { view : this.view };
         // TODO: should load multiple actions at once
@@ -225,9 +225,10 @@ openerp.base.form.DashBoard = openerp.base.form.Widget.extend({
             action_buttons : false,
             pager: false
         };
-        new openerp.base.ActionManager(
-                this.session, this.view.element_id + '_action_' + action.id)
-            .do_action(action);
+        var am = new openerp.base.ActionManager(this);
+        this.action_managers.push(am);
+        am.appendTo($("#"+this.view.element_id + '_action_' + action.id));
+        am.do_action(action);
     },
     render: function() {
         // We should start with three columns available
@@ -241,8 +242,12 @@ openerp.base.form.DashBoard = openerp.base.form.Widget.extend({
         return QWeb.render(this.template, this);
     },
     do_reload: function() {
-        this.view.view_manager.stop();
-        this.view.view_manager.start();
+        _.each(this.action_managers, function(am) {
+            am.stop();
+        });
+        this.action_managers = [];
+        this.view.stop();
+        this.view.start();
     }
 });
 openerp.base.form.DashBoardLegacy = openerp.base.form.DashBoard.extend({
@@ -280,17 +285,17 @@ if (!openerp.base_dashboard) {
     openerp.base_dashboard = {};
 }
 openerp.base_dashboard.ConfigOverview = openerp.base.View.extend({
-    init: function (parent_or_session, element_id) {
-        this._super(parent_or_session, element_id);
+    template: 'ConfigOverview',
+    init: function (parent, element_id) {
+        this._super(parent, element_id);
         this.dataset = new openerp.base.DataSetSearch(
-                this.session, 'ir.actions.todo');
-        this.dataset.domain = ['|', ['type', '=', 'recurring'],
-                                    '&', ['type', '!=', 'special'],
-                                         ['state', '=', 'open']];
+                this, 'ir.actions.todo');
+        this.dataset.domain = [['type', '=', 'manual']];
     },
     start: function () {
         $.when(this.dataset.read_slice(['state', 'action_id', 'category_id']),
-               this.dataset.call('progress')).then(this.on_records_loaded);
+               this.dataset.call('progress'))
+            .then(this.on_records_loaded);
     },
     on_records_loaded: function (read_response, progress_response) {
         var records = read_response[0].records,
@@ -299,7 +304,7 @@ openerp.base_dashboard.ConfigOverview = openerp.base.View.extend({
         var grouped_todos = _(records).chain()
             .map(function (record) {
                 return {
-                    action: record.action_id[0],
+                    id: record.id,
                     name: record.action_id[1],
                     done: record.state !== 'open',
                     to_do: record.state === 'open',
@@ -308,43 +313,47 @@ openerp.base_dashboard.ConfigOverview = openerp.base.View.extend({
             })
             .groupBy(function (record) {return record.category})
             .value();
-        this.$element.html(QWeb.render('ConfigOverview', {
+        this.$element.html(QWeb.render('ConfigOverview.content', {
             completion: 100 * progress.done / progress.total,
             groups: grouped_todos
         }));
-        var $progress = this.$element.find('div.oe-config-progress');
+        var $progress = this.$element.find('div.oe-config-progress-bar');
         $progress.progressbar({value: $progress.data('completion')});
 
         var self = this;
-        // allow for executing to-do and skipped action
-        this.$element.find('div.oe-dashboard-config-overview ul')
-                .delegate('li.ui-state-error', 'click', function () {
-            self.execute_action({
-                type: 'action',
-                name: $(this).data('action')
-            }, self.dataset,
-            new openerp.base.ActionManager(self.session, self.element_id),
-            null, null, function () {
-                // after action popup closed, refresh configuration thingie
-                self.start();
+        this.$element.find('dl')
+            .delegate('input', 'click', function (e) {
+                // switch todo status
+                e.stopImmediatePropagation();
+                var new_state = this.checked ? 'done' : 'open',
+                      todo_id = parseInt($(this).val(), 10);
+                self.dataset.write(todo_id, {state: new_state}, function () {
+                    self.start();
+                });
+            })
+            .delegate('li:not(.oe-done)', 'click', function () {
+                self.execute_action({
+                        type: 'object',
+                        name: 'action_launch'
+                    }, self.dataset,
+                    $(this).data('id'), function () {
+                        // after action popup closed, refresh configuration
+                        // thingie
+                        self.start();
+                    });
             });
-        });
     }
 });
 
 openerp.base.client_actions.add(
     'board.home.applications', 'openerp.base_dashboard.ApplicationTiles');
 openerp.base_dashboard.ApplicationTiles = openerp.base.View.extend({
-    init: function (parent_or_session, element_id) {
-        this._super(parent_or_session, element_id);
-        this.dataset = new openerp.base.DataSetSearch(
-                this.session, 'ir.ui.menu', null, [['parent_id', '=', false]]);
-    },
+    template: 'ApplicationTiles',
     start: function () {
         var self = this;
-        this.dataset.read_slice(
-            ['name', 'web_icon_data', 'web_icon_hover_data'],
-            null, null, function (applications) {
+        return new openerp.base.DataSetSearch(
+                this, 'ir.ui.menu', null, [['parent_id', '=', false]])
+            .read_slice( ['name', 'web_icon_data', 'web_icon_hover_data'], {}, function (applications) {
                 // Create a matrix of 3*x applications
                 var rows = [];
                 while (applications.length) {
@@ -352,30 +361,26 @@ openerp.base_dashboard.ApplicationTiles = openerp.base.View.extend({
                 }
                 self.$element
                     .append(QWeb.render(
-                        'ApplicationTiles', {rows: rows}))
+                        'ApplicationTiles.content', {rows: rows}))
                     .find('.oe-dashboard-home-tile')
                         .click(function () {
                             var $this = $(this);
                             $this.closest('.openerp')
                                  .find('.menu a[data-menu=' + $this.data('menuid') + ']')
                                  .click();});
-        });
+            });
     }
 });
 openerp.base.client_actions.add(
     'board.home.widgets', 'openerp.base_dashboard.Widgets');
 openerp.base_dashboard.Widgets = openerp.base.View.extend({
-    init: function (parent_or_session, element_id) {
-        this._super(parent_or_session, element_id);
-        this.user_widgets = new openerp.base.DataSetSearch(
-                this.session, 'res.widget.user', null,
-                ['|', ['user_id', '=', false],
-                      ['user_id', '=', parseInt(this.session.uid, 10)]]);
-        this.widgets = new openerp.base.DataSetSearch(this.session, 'res.widget');
-    },
+    template: 'HomeWidgets',
     start: function () {
-        this.user_widgets.read_slice(['widget_id', 'user_id'], null, null,
-            this.on_widgets_list_loaded);
+        return new openerp.base.DataSetSearch(
+                this, 'res.widget.user', null,
+                ['|', ['user_id', '=', false],
+                      ['user_id', '=', parseInt(this.session.uid, 10)]])
+            .read_slice(['widget_id', 'user_id'], {}, this.on_widgets_list_loaded);
     },
     on_widgets_list_loaded: function (user_widgets) {
         var self = this;
@@ -387,18 +392,19 @@ openerp.base_dashboard.Widgets = openerp.base.View.extend({
                 user_widget_id: widget['id']
             };
         });
-        this.widgets.read_ids(_(user_widgets).pluck('widget_id'), ['title'], function (widgets) {
-            _(widgets).each(function (widget) {
-                _.extend(widget, widget_user[widget['id']]);
+        new openerp.base.DataSetSearch(this, 'res.widget')
+            .read_ids(_(user_widgets).pluck('widget_id'), ['title'], function (widgets) {
+                _(widgets).each(function (widget) {
+                    _.extend(widget, widget_user[widget['id']]);
+                });
+                var url = _.sprintf(
+                    '/base_dashboard/widgets/content?session_id=%s&widget_id=',
+                    self.session.session_id);
+                self.$element.html(QWeb.render('HomeWidgets', {
+                    widgets: widgets,
+                    url: url
+                }));
             });
-            var url = _.sprintf(
-                '/base_dashboard/widgets/content?session_id=%s&widget_id=',
-                self.session.session_id);
-            self.$element.html(QWeb.render('HomeWidgets', {
-                widgets: widgets,
-                url: url
-            }));
-        })
     }
 });
 };