1
// @@@ web_export_view custom JS @@@
2
//#############################################################################
4
// Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
5
// Copyright (C) 2012 Therp BV (<http://therp.nl>)
7
// This program is free software: you can redistribute it and/or modify
8
// it under the terms of the GNU Affero General Public License as published
9
// by the Free Software Foundation, either version 3 of the License, or
10
// (at your option) any later version.
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU Affero General Public License for more details.
17
// You should have received a copy of the GNU Affero General Public License
18
// along with this program. If not, see <http://www.gnu.org/licenses/>.
20
//#############################################################################
22
openerp.web_export_view = function(openerp) {
26
openerp.web.Sidebar = openerp.web.Sidebar.extend({
28
add_default_sections: function() {
29
// IMHO sections should be registered objects
30
// as views and retrieved using a specific registry
31
// so that we don't have to override this
34
view = this.widget_parent,
35
view_manager = view.widget_parent,
36
action = view_manager.action;
37
if (this.session.uid === 1) {
38
this.add_section(_t('Customize'), 'customize');
39
this.add_items('customize', [{
40
label: _t("Translate"),
41
callback: view.on_sidebar_translate,
42
title: _t("Technical translation")
46
this.add_section(_t('Other Options'), 'other');
47
this.add_items('other', [
50
callback: view.on_sidebar_export
53
label: _t("Export current view"),
54
callback: this.on_sidebar_export_view
59
on_sidebar_export_view: function() {
60
// Select the first list of the current (form) view
61
// or assume the main view is a list view and use that
63
view = this.widget_parent; // valid for list view
64
if (view.widget_children) {
65
view.widget_children.every(function(child) {
66
if (child.field && child.field.type == 'one2many') {
67
view = child.viewmanager.views.list.controller;
68
return false; // break out of the loop
70
if (child.field && child.field.type == 'many2many') {
71
view = child.list_view;
72
return false; // break out of the loop
77
var columns = view.visible_columns;
78
export_columns_keys = [];
79
export_columns_names = [];
80
$.each(columns,function(){
81
if(this.tag=='field'){
82
// non-fields like `_group` or buttons
83
export_columns_keys.push(this.id);
84
export_columns_names.push(this.string);
87
rows = view.$element.find('.ui-widget-content tr');
89
$.each(rows,function(){
91
// find only rows with data
92
if($row.attr('data-id')){
94
$.each(export_columns_keys,function(){
95
cell = $row.find('td[data-field="'+this+'"]').get(0);
96
text = cell.text || cell.textContent || cell.innerHTML || "";
97
export_row.push(text.trim());
99
export_rows.push(export_row);
103
view.session.get_file({
104
url: '/web/export/xls_view',
105
data: {data: JSON.stringify({
107
headers : export_columns_names,
110
complete: $.unblockUI