2011-05-31 22:28:38 +00:00
|
|
|
openerp.base_dashboard = function(openerp) {
|
2011-04-27 10:24:56 +00:00
|
|
|
|
2011-04-21 05:23:16 +00:00
|
|
|
QWeb.add_template('/base_dashboard/static/src/xml/base_dashboard.xml');
|
2011-04-27 10:24:56 +00:00
|
|
|
|
2011-05-31 22:28:38 +00:00
|
|
|
openerp.base.form.DashBoard = openerp.base.form.Widget.extend({
|
2011-04-27 10:24:56 +00:00
|
|
|
init: function(view, node) {
|
2011-04-21 05:23:16 +00:00
|
|
|
this._super(view, node);
|
2011-05-31 22:28:38 +00:00
|
|
|
this.template = "DashBoard";
|
2011-06-06 13:34:24 +00:00
|
|
|
this.actions_attrs = {};
|
2011-04-21 05:23:16 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2011-05-31 22:28:38 +00:00
|
|
|
var self = this;
|
2011-04-21 05:23:16 +00:00
|
|
|
this._super.apply(this, arguments);
|
2011-06-01 13:48:00 +00:00
|
|
|
|
2011-05-31 22:28:38 +00:00
|
|
|
this.$element.find(".oe-dashboard-column").sortable({
|
|
|
|
connectWith: ".oe-dashboard-column",
|
2011-05-18 13:56:43 +00:00
|
|
|
scroll: false
|
2011-05-31 22:28:38 +00:00
|
|
|
}).disableSelection().bind('sortstop', self.do_save_dashboard);
|
2011-06-01 13:48:00 +00:00
|
|
|
|
|
|
|
// Events
|
|
|
|
this.$element.find('.oe-dashboard-link-undo').click(this.on_undo);
|
2011-06-06 10:54:36 +00:00
|
|
|
this.$element.find('.oe-dashboard-link-reset').click(this.on_reset);
|
2011-05-31 22:28:38 +00:00
|
|
|
this.$element.find('.oe-dashboard-link-add_widget').click(this.on_add_widget);
|
2011-06-06 10:13:05 +00:00
|
|
|
this.$element.find('.oe-dashboard-link-change_layout').click(this.on_change_layout);
|
2011-06-01 13:48:00 +00:00
|
|
|
this.$element.find('.oe-dashboard-column .ui-icon-minusthick').click(this.on_fold_action);
|
|
|
|
this.$element.find('.oe-dashboard-column .ui-icon-closethick').click(this.on_close_action);
|
2011-04-21 05:23:16 +00:00
|
|
|
|
2011-05-31 22:28:38 +00:00
|
|
|
this.actions_attrs = {};
|
|
|
|
// Init actions
|
|
|
|
_.each(this.node.children, function(column) {
|
|
|
|
_.each(column.children, function(action) {
|
|
|
|
delete(action.attrs.width);
|
|
|
|
delete(action.attrs.height);
|
|
|
|
delete(action.attrs.colspan);
|
|
|
|
self.actions_attrs[action.attrs.name] = action.attrs;
|
|
|
|
self.rpc('/base/action/load', {
|
|
|
|
action_id: parseInt(action.attrs.name, 10)
|
|
|
|
}, self.on_load_action);
|
|
|
|
});
|
|
|
|
});
|
2011-06-06 14:29:27 +00:00
|
|
|
|
|
|
|
this.$element.find('a.oe-dashboard-action-rename').live('click', this.on_rename);
|
2011-04-21 05:23:16 +00:00
|
|
|
},
|
2011-06-01 13:48:00 +00:00
|
|
|
on_undo: function() {
|
|
|
|
this.rpc('/base/view/undo_custom', {
|
|
|
|
view_id: this.view.fields_view.view_id
|
|
|
|
}, this.do_reload);
|
|
|
|
},
|
2011-06-06 10:54:36 +00:00
|
|
|
on_reset: function() {
|
|
|
|
this.rpc('/base/view/undo_custom', {
|
|
|
|
view_id: this.view.fields_view.view_id,
|
|
|
|
reset: true
|
|
|
|
}, this.do_reload);
|
|
|
|
},
|
2011-05-31 22:28:38 +00:00
|
|
|
on_add_widget: function() {
|
2011-06-06 13:34:24 +00:00
|
|
|
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 = $('<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) {
|
|
|
|
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)
|
|
|
|
});
|
|
|
|
});
|
2011-05-31 22:28:38 +00:00
|
|
|
},
|
2011-06-06 14:29:27 +00:00
|
|
|
on_rename : function(e) {
|
|
|
|
var self = this,
|
|
|
|
id = $(e.currentTarget).parents('.oe-dashboard-action:first').attr('data-id'),
|
|
|
|
$header = $(e.currentTarget).parents('.oe-dashboard-action-header:first'),
|
|
|
|
$rename = $header.find('a.oe-dashboard-action-rename').hide(),
|
|
|
|
$title = $header.find('span.oe-dashboard-action-title').hide(),
|
|
|
|
$input = $header.find('input[name=title]');
|
|
|
|
$input.val($title.text()).show().focus().bind('keydown', function(e) {
|
|
|
|
if (e.which == 13 || e.which == 27) {
|
|
|
|
if (e.which == 13) { //enter
|
|
|
|
var val = $input.val();
|
|
|
|
if (!val) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$title.text(val);
|
|
|
|
self.actions_attrs[id].string = val;
|
|
|
|
self.do_save_dashboard();
|
|
|
|
}
|
|
|
|
$input.unbind('keydown').hide();
|
|
|
|
$rename.show();
|
|
|
|
$title.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2011-06-06 10:13:05 +00:00
|
|
|
on_change_layout: function() {
|
|
|
|
var self = this;
|
|
|
|
var qdict = {
|
|
|
|
current_layout : this.$element.find('.oe-dashboard').attr('data-layout')
|
|
|
|
};
|
|
|
|
var $dialog = $('<div>').dialog({
|
|
|
|
modal: true,
|
|
|
|
title: 'Edit Layout',
|
|
|
|
width: 'auto',
|
|
|
|
height: 'auto',
|
|
|
|
}).html(QWeb.render('DashBoard.layouts', qdict));
|
|
|
|
$dialog.find('li').click(function() {
|
|
|
|
var layout = $(this).attr('data-layout');
|
|
|
|
$dialog.dialog("destroy");
|
|
|
|
self.do_change_layout(layout);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
do_change_layout: function(new_layout) {
|
|
|
|
var $dashboard = this.$element.find('.oe-dashboard');
|
|
|
|
var current_layout = $dashboard.attr('data-layout');
|
|
|
|
if (current_layout != new_layout) {
|
|
|
|
var clayout = current_layout.split('-').length,
|
|
|
|
nlayout = new_layout.split('-').length,
|
|
|
|
column_diff = clayout - nlayout;
|
|
|
|
if (column_diff > 0) {
|
|
|
|
var $last_column = $();
|
|
|
|
$dashboard.find('.oe-dashboard-column').each(function(k, v) {
|
|
|
|
if (k >= nlayout) {
|
|
|
|
$(v).find('.oe-dashboard-action').appendTo($last_column);
|
|
|
|
} else {
|
|
|
|
$last_column = $(v);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$dashboard.toggleClass('oe-dashboard-layout_' + current_layout + ' oe-dashboard-layout_' + new_layout);
|
|
|
|
$dashboard.attr('data-layout', new_layout);
|
|
|
|
this.do_save_dashboard();
|
|
|
|
}
|
2011-05-31 22:28:38 +00:00
|
|
|
},
|
2011-06-01 13:48:00 +00:00
|
|
|
on_fold_action: function(e) {
|
|
|
|
var $e = $(e.currentTarget);
|
|
|
|
$e.toggleClass('ui-icon-minusthick ui-icon-plusthick');
|
|
|
|
$e.parents('.oe-dashboard-action:first').find('.oe-dashboard-action-content').toggle();
|
|
|
|
},
|
|
|
|
on_close_action: function(e) {
|
|
|
|
$(e.currentTarget).parents('.oe-dashboard-action:first').remove();
|
|
|
|
this.do_save_dashboard();
|
|
|
|
},
|
2011-05-31 22:28:38 +00:00
|
|
|
do_save_dashboard: function() {
|
|
|
|
var self = this;
|
|
|
|
var board = {
|
2011-06-01 13:48:00 +00:00
|
|
|
form_title : this.view.fields_view.arch.attrs.string,
|
2011-05-31 22:28:38 +00:00
|
|
|
style : this.$element.find('.oe-dashboard').attr('data-layout'),
|
|
|
|
columns : []
|
|
|
|
};
|
|
|
|
this.$element.find('.oe-dashboard-column').each(function() {
|
|
|
|
var actions = [];
|
|
|
|
$(this).find('.oe-dashboard-action').each(function() {
|
|
|
|
var action_id = $(this).attr('data-id');
|
|
|
|
actions.push(self.actions_attrs[action_id]);
|
|
|
|
});
|
|
|
|
board.columns.push(actions);
|
|
|
|
});
|
2011-06-01 13:48:00 +00:00
|
|
|
var arch = QWeb.render('DashBoard.xml', board);
|
|
|
|
this.rpc('/base/view/add_custom', {
|
|
|
|
view_id: this.view.fields_view.view_id,
|
|
|
|
arch: arch
|
|
|
|
}, function() {
|
2011-06-06 10:54:36 +00:00
|
|
|
self.$element.find('.oe-dashboard-link-undo, .oe-dashboard-link-reset').show();
|
2011-06-01 13:48:00 +00:00
|
|
|
});
|
2011-04-21 05:23:16 +00:00
|
|
|
},
|
2011-04-27 10:24:56 +00:00
|
|
|
on_load_action: function(result) {
|
2011-05-31 22:28:38 +00:00
|
|
|
var action = result.result;
|
2011-05-17 09:26:27 +00:00
|
|
|
action.flags = {
|
|
|
|
search_view : false,
|
|
|
|
sidebar : false,
|
2011-05-18 12:52:51 +00:00
|
|
|
views_switcher : false,
|
2011-05-31 22:28:38 +00:00
|
|
|
action_buttons : false,
|
|
|
|
pager: false
|
2011-05-17 09:26:27 +00:00
|
|
|
}
|
2011-05-31 22:28:38 +00:00
|
|
|
var element_id = this.view.element_id + '_action_' + action.id;
|
|
|
|
var view = new openerp.base.ViewManagerAction(this.session, element_id, action);
|
|
|
|
view.start();
|
2011-04-28 10:45:21 +00:00
|
|
|
},
|
2011-05-31 22:28:38 +00:00
|
|
|
render: function() {
|
2011-06-06 10:13:05 +00:00
|
|
|
// We should start with three columns available
|
|
|
|
for (var i = this.node.children.length; i < 3; i++) {
|
|
|
|
this.node.children.push({
|
|
|
|
tag: 'column',
|
|
|
|
attrs: {},
|
|
|
|
children: []
|
|
|
|
});
|
|
|
|
}
|
2011-05-31 22:28:38 +00:00
|
|
|
return QWeb.render(this.template, this);
|
2011-06-01 13:48:00 +00:00
|
|
|
},
|
|
|
|
do_reload: function() {
|
|
|
|
this.view.view_manager.stop();
|
|
|
|
this.view.view_manager.start();
|
2011-05-31 22:28:38 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
openerp.base.form.DashBoardLegacy = openerp.base.form.DashBoard.extend({
|
|
|
|
render: function() {
|
|
|
|
if (this.node.tag == 'hpaned') {
|
|
|
|
this.node.attrs.style = '1-1';
|
|
|
|
} else if (this.node.tag == 'vpaned') {
|
|
|
|
this.node.attrs.style = '1';
|
2011-04-28 10:45:21 +00:00
|
|
|
}
|
2011-05-31 22:28:38 +00:00
|
|
|
this.node.tag = 'board';
|
|
|
|
_.each(this.node.children, function(child) {
|
|
|
|
if (child.tag.indexOf('child') == 0) {
|
|
|
|
child.tag = 'column';
|
|
|
|
var actions = [], first_child = child.children[0];
|
|
|
|
if (first_child && first_child.tag == 'vpaned') {
|
|
|
|
_.each(first_child.children, function(subchild) {
|
|
|
|
actions.push.apply(actions, subchild.children);
|
|
|
|
});
|
|
|
|
child.children = actions;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-06-06 10:13:05 +00:00
|
|
|
return this._super(this, arguments);
|
2011-05-31 22:28:38 +00:00
|
|
|
}
|
|
|
|
});
|
2011-04-28 10:45:21 +00:00
|
|
|
|
2011-05-31 22:28:38 +00:00
|
|
|
openerp.base.form.widgets.add('hpaned', 'openerp.base.form.DashBoardLegacy');
|
|
|
|
openerp.base.form.widgets.add('vpaned', 'openerp.base.form.DashBoardLegacy');
|
|
|
|
openerp.base.form.widgets.add('board', 'openerp.base.form.DashBoard');
|
2011-05-17 09:26:27 +00:00
|
|
|
}
|