mirror of https://github.com/OCA/web.git
[add] port web_export_view to OpenERP 7
parent
c24afa8cf6
commit
88a27905a2
|
@ -4,3 +4,4 @@ Authors
|
||||||
Simone Orsi <simone.orsi@domsense.com> [simahawk]
|
Simone Orsi <simone.orsi@domsense.com> [simahawk]
|
||||||
Lorenzo Battistini <lorenzo.battistini@agilebg.com>
|
Lorenzo Battistini <lorenzo.battistini@agilebg.com>
|
||||||
Stefan Rijnhart <stefan@therp.nl>
|
Stefan Rijnhart <stefan@therp.nl>
|
||||||
|
Leonardo Pistone <leonardo.pistone@agilebg.com>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
|
# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
|
||||||
# Copyright (C) 2012-2013 Agile Business Group sagl
|
# Copyright (C) 2012-2013 Agile Business Group sagl
|
||||||
# (<http://www.agilebg.com>)
|
# (<http://www.agilebg.com>)
|
||||||
|
@ -22,32 +22,38 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Export Current View',
|
'name': 'Export Current View',
|
||||||
'version': '1.0',
|
'version': '1.1',
|
||||||
'category': 'Web',
|
'category': 'Web',
|
||||||
'description': """
|
'description': """
|
||||||
WEB EXPORT VIEW
|
WEB EXPORT VIEW
|
||||||
===============
|
===============
|
||||||
|
|
||||||
One of the best OpenERP’s features is exporting custom data to CSV/XLS. You can do it by clicking on the export link in the sidebar. The export action allows use to configure what to be exported by selecting fields, etc, and allows you to save your export as a template so that you can export it once again without having to configure it again.
|
One of the best OpenERP’s features is exporting custom data to CSV/XLS. You can
|
||||||
|
do it by clicking on the export link in the sidebar. The export action allows
|
||||||
|
use to configure what to be exported by selecting fields, etc, and allows you
|
||||||
|
to save your export as a template so that you can export it once again without
|
||||||
|
having to configure it again.
|
||||||
|
|
||||||
That feature is as great and advanced as limited for an everyday-customer-experience. A lot of customers want simply to export the tree view they are looking to.
|
That feature is as great and advanced as limited for an everyday experience.
|
||||||
|
A lot of customers want simply to export the tree view they are looking to.
|
||||||
|
|
||||||
If you miss this feature as us, probably you’ll find an answer into our web_export_view module.
|
If you miss this feature as us, probably you’ll find an answer into our
|
||||||
|
web_export_view module.
|
||||||
|
|
||||||
After you installed it, you’ll find an additional link ‘Export current view’ right below the ‘Export’ one. By clicking on it you’ll get a XLS file contains the same data of the tree view you are looking at, headers included.
|
After you installed it, you’ll find an additional link ‘Export current view’
|
||||||
|
right below the ‘Export’ one. By clicking on it you’ll get a XLS file contains
|
||||||
|
the same data of the tree view you are looking at, headers included.
|
||||||
""",
|
""",
|
||||||
'author': 'Agile Business Group',
|
'author': 'Agile Business Group',
|
||||||
'website': 'http://www.agilebg.com',
|
'website': 'http://www.agilebg.com',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'depends': ['web'],
|
'depends': ['web'],
|
||||||
'external_dependencies' : {
|
# 'external_dependencies': {
|
||||||
'python' : ['xlwt'],
|
# 'python': ['xlwt'],
|
||||||
},
|
# },
|
||||||
'data': [],
|
'js': ['static/*/*.js', 'static/*/js/*.js'],
|
||||||
'active': False,
|
'qweb': ['static/xml/web_advanced_export.xml'],
|
||||||
|
'installable': True,
|
||||||
'auto_install': False,
|
'auto_install': False,
|
||||||
'js': [
|
'web_preload': False,
|
||||||
'static/js/web_advanced_export.js',
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
|
# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
|
||||||
# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
|
# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
|
||||||
#
|
#
|
||||||
|
@ -23,7 +23,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
|
|
||||||
import web.common.http as openerpweb
|
import web.http as openerpweb
|
||||||
|
|
||||||
from web.controllers.main import ExcelExport
|
from web.controllers.main import ExcelExport
|
||||||
|
|
||||||
|
@ -34,13 +34,16 @@ class ExcelExportView(ExcelExport):
|
||||||
@openerpweb.httprequest
|
@openerpweb.httprequest
|
||||||
def index(self, req, data, token):
|
def index(self, req, data, token):
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
model = data.get('model',[])
|
model = data.get('model', [])
|
||||||
columns_headers = data.get('headers',[])
|
columns_headers = data.get('headers', [])
|
||||||
rows = data.get('rows',[])
|
rows = data.get('rows', [])
|
||||||
|
|
||||||
context = req.session.eval_context(req.context)
|
return req.make_response(
|
||||||
|
self.from_data(columns_headers, rows),
|
||||||
return req.make_response(self.from_data(columns_headers, rows),
|
headers=[
|
||||||
headers=[('Content-Disposition', 'attachment; filename="%s"' % self.filename(model)),
|
('Content-Disposition', 'attachment; filename="%s"'
|
||||||
('Content-Type', self.content_type)],
|
% self.filename(model)),
|
||||||
cookies={'fileToken': int(token)})
|
('Content-Type', self.content_type)
|
||||||
|
],
|
||||||
|
cookies={'fileToken': int(token)}
|
||||||
|
)
|
||||||
|
|
|
@ -19,48 +19,25 @@
|
||||||
//
|
//
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
|
|
||||||
openerp.web_export_view = function(openerp) {
|
openerp.web_export_view = function(instance, m) {
|
||||||
|
|
||||||
_t = openerp.web._t;
|
var _t = instance.web._t,
|
||||||
|
QWeb = instance.web.qweb;
|
||||||
|
|
||||||
openerp.web.Sidebar = openerp.web.Sidebar.extend({
|
instance.web.Sidebar.include({
|
||||||
|
redraw: function() {
|
||||||
add_default_sections: function() {
|
var self = this;
|
||||||
// IMHO sections should be registered objects
|
this._super.apply(this, arguments);
|
||||||
// as views and retrieved using a specific registry
|
self.$el.find('.oe_sidebar').append(QWeb.render('AddExportViewMain', {widget: self}));
|
||||||
// so that we don't have to override this
|
self.$el.find('.oe_sidebar_export_view_xls').on('click', self.on_sidebar_export_view_xls);
|
||||||
|
|
||||||
var self = this,
|
|
||||||
view = this.widget_parent,
|
|
||||||
view_manager = view.widget_parent,
|
|
||||||
action = view_manager.action;
|
|
||||||
if (this.session.uid === 1) {
|
|
||||||
this.add_section(_t('Customize'), 'customize');
|
|
||||||
this.add_items('customize', [{
|
|
||||||
label: _t("Translate"),
|
|
||||||
callback: view.on_sidebar_translate,
|
|
||||||
title: _t("Technical translation")
|
|
||||||
}]);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.add_section(_t('Other Options'), 'other');
|
|
||||||
this.add_items('other', [
|
|
||||||
{
|
|
||||||
label: _t("Export"),
|
|
||||||
callback: view.on_sidebar_export
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: _t("Export current view"),
|
|
||||||
callback: this.on_sidebar_export_view
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
on_sidebar_export_view: function() {
|
on_sidebar_export_view_xls: function() {
|
||||||
// Select the first list of the current (form) view
|
// Select the first list of the current (form) view
|
||||||
// or assume the main view is a list view and use that
|
// or assume the main view is a list view and use that
|
||||||
var self = this,
|
var self = this,
|
||||||
view = this.widget_parent; // valid for list view
|
view = this.getParent(),
|
||||||
|
columns = view.visible_columns;
|
||||||
if (view.widget_children) {
|
if (view.widget_children) {
|
||||||
view.widget_children.every(function(child) {
|
view.widget_children.every(function(child) {
|
||||||
if (child.field && child.field.type == 'one2many') {
|
if (child.field && child.field.type == 'one2many') {
|
||||||
|
@ -74,7 +51,6 @@ openerp.web_export_view = function(openerp) {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var columns = view.visible_columns;
|
|
||||||
export_columns_keys = [];
|
export_columns_keys = [];
|
||||||
export_columns_names = [];
|
export_columns_names = [];
|
||||||
$.each(columns,function(){
|
$.each(columns,function(){
|
||||||
|
@ -84,19 +60,22 @@ openerp.web_export_view = function(openerp) {
|
||||||
export_columns_names.push(this.string);
|
export_columns_names.push(this.string);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
rows = view.$element.find('.ui-widget-content tr');
|
rows = view.$el.find('.oe_list_content > tbody > tr');
|
||||||
export_rows = [];
|
export_rows = [];
|
||||||
$.each(rows,function(){
|
$.each(rows,function(){
|
||||||
$row = $(this);
|
$row = $(this);
|
||||||
// find only rows with data
|
// find only rows with data
|
||||||
if($row.attr('data-id')){
|
if($row.attr('data-id')){
|
||||||
export_row = [];
|
export_row = [];
|
||||||
$.each(export_columns_keys,function(){
|
checked = $row.find('th input[type=checkbox]').attr("checked");
|
||||||
cell = $row.find('td[data-field="'+this+'"]').get(0);
|
if (checked === "checked"){
|
||||||
text = cell.text || cell.textContent || cell.innerHTML || "";
|
$.each(export_columns_keys,function(){
|
||||||
export_row.push(text.trim());
|
cell = $row.find('td[data-field="'+this+'"]').get(0);
|
||||||
});
|
text = cell.text || cell.textContent || cell.innerHTML || "";
|
||||||
export_rows.push(export_row);
|
export_row.push(text.trim());
|
||||||
|
});
|
||||||
|
export_rows.push(export_row);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$.blockUI();
|
$.blockUI();
|
||||||
|
@ -113,4 +92,4 @@ openerp.web_export_view = function(openerp) {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- vim:fdl=1:
|
||||||
|
-->
|
||||||
|
<templates id="template" xml:space="preserve">
|
||||||
|
<t t-name="AddExportViewMain">
|
||||||
|
<div class="oe_form_dropdown_section">
|
||||||
|
<button class="oe_dropdown_toggle oe_dropdown_arrow">Export Current View</button>
|
||||||
|
<ul class="oe_dropdown_menu">
|
||||||
|
<li class="oe_sidebar_export_view_xls"><span>Excel</span></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</templates>
|
Loading…
Reference in New Issue