mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[MIG 10.0] web_export_view (#444)
This commit is contained in:
committed by
Pedro M. Baeza
parent
66af04f833
commit
be736df3ad
@@ -1,38 +1,24 @@
|
||||
// @@@ web_export_view custom JS @@@
|
||||
//#############################################################################
|
||||
//
|
||||
// Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
|
||||
// Copyright (C) 2012 Therp BV (<http://therp.nl>)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published
|
||||
// by the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//#############################################################################
|
||||
openerp.web_export_view = function (instance) {
|
||||
odoo.define('web_export_view', function (require) {
|
||||
"use strict";
|
||||
|
||||
var _t = instance.web._t, QWeb = instance.web.qweb;
|
||||
var core = require('web.core');
|
||||
var Sidebar = require('web.Sidebar');
|
||||
var QWeb = core.qweb;
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
Sidebar.include({
|
||||
|
||||
instance.web.Sidebar.include({
|
||||
redraw: function () {
|
||||
var self = this;
|
||||
this._super.apply(this, arguments);
|
||||
if (self.getParent().ViewManager.active_view == 'list') {
|
||||
self.$el.find('.oe_sidebar').append(QWeb.render('AddExportViewMain', {widget: self}));
|
||||
self.$el.find('.oe_sidebar_export_view_xls').on('click', self.on_sidebar_export_view_xls);
|
||||
if (self.getParent().ViewManager.active_view.type == 'list') {
|
||||
self.$el.find('.o_dropdown').last().append(QWeb.render('WebExportTreeViewXls', {widget: self}));
|
||||
self.$el.find('.export_treeview_xls').on('click', self.on_sidebar_export_treeview_xls);
|
||||
}
|
||||
},
|
||||
|
||||
on_sidebar_export_view_xls: function () {
|
||||
on_sidebar_export_treeview_xls: function () {
|
||||
// Select the first list of the current (form) view
|
||||
// or assume the main view is a list view and use that
|
||||
var self = this,
|
||||
@@ -51,50 +37,51 @@ openerp.web_export_view = function (instance) {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
export_columns_keys = [];
|
||||
export_columns_names = [];
|
||||
var export_columns_keys = [];
|
||||
var export_columns_names = [];
|
||||
$.each(view.visible_columns, function () {
|
||||
if (this.tag == 'field') {
|
||||
if (this.tag == 'field' && (this.widget === undefined || this.widget != 'handle')) {
|
||||
// non-fields like `_group` or buttons
|
||||
export_columns_keys.push(this.id);
|
||||
export_columns_names.push(this.string);
|
||||
}
|
||||
});
|
||||
rows = view.$el.find('.oe_list_content > tbody > tr');
|
||||
export_rows = [];
|
||||
var rows = view.$el.find('.o_list_view > tbody > tr');
|
||||
var export_rows = [];
|
||||
$.each(rows, function () {
|
||||
$row = $(this);
|
||||
var $row = $(this);
|
||||
// find only rows with data
|
||||
if ($row.attr('data-id')) {
|
||||
export_row = [];
|
||||
checked = $row.find('th input[type=checkbox]').attr("checked");
|
||||
if (children && checked === "checked") {
|
||||
var export_row = [];
|
||||
var checked = $row.find('.o_list_record_selector input[type=checkbox]').is(':checked');
|
||||
if (children && checked === true) {
|
||||
$.each(export_columns_keys, function () {
|
||||
cell = $row.find('td[data-field="' + this + '"]').get(0);
|
||||
text = cell.text || cell.textContent || cell.innerHTML || "";
|
||||
if (cell.classList.contains("oe_list_field_float")) {
|
||||
export_row.push(instance.web.parse_value(text, {'type': "float"}));
|
||||
}
|
||||
else if (cell.classList.contains("oe_list_field_boolean")) {
|
||||
var data_id = $('<div>' + cell.innerHTML + '</div>');
|
||||
if (data_id.find('input').get(0).checked) {
|
||||
var $cell = $row.find('td[data-field="' + this + '"]')
|
||||
var $cellcheckbox = $cell.find('.o_checkbox input[type=checkbox]');
|
||||
if ($cellcheckbox.length) {
|
||||
if ($cellcheckbox.is(':checked')) {
|
||||
export_row.push(_t("True"));
|
||||
}
|
||||
else {
|
||||
export_row.push(_t("False"));
|
||||
}
|
||||
}
|
||||
else if (cell.classList.contains("oe_list_field_integer")) {
|
||||
var tmp2 = text;
|
||||
do {
|
||||
tmp = tmp2;
|
||||
tmp2 = tmp.replace(instance.web._t.database.parameters.thousands_sep, "");
|
||||
} while (tmp !== tmp2);
|
||||
|
||||
export_row.push(parseInt(tmp2));
|
||||
}
|
||||
else {
|
||||
export_row.push(text.trim());
|
||||
var cell = $cell.get(0);
|
||||
var text = cell.text || cell.textContent || cell.innerHTML || "";
|
||||
|
||||
if (cell.classList.contains("o_list_number")) {
|
||||
var tmp2 = text;
|
||||
do {
|
||||
var tmp = tmp2;
|
||||
tmp2 = tmp.replace(_t.database.parameters.thousands_sep, "");
|
||||
} while (tmp !== tmp2);
|
||||
tmp2 = tmp.replace(_t.database.parameters.decimal_point, ".");
|
||||
export_row.push(parseFloat(tmp2));
|
||||
}
|
||||
else {
|
||||
export_row.push(text.trim());
|
||||
}
|
||||
}
|
||||
});
|
||||
export_rows.push(export_row);
|
||||
@@ -112,6 +99,6 @@ openerp.web_export_view = function (instance) {
|
||||
complete: $.unblockUI
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<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>
|
||||
<t t-name="WebExportTreeViewXls">
|
||||
<div class="o_cp_sidebar btn-group btn-group-sm">
|
||||
<button class="btn btn-default export_treeview_xls" type="button" title="Export xls">
|
||||
<i t-translation="off" class="fa fa-file-excel-o"></i>
|
||||
</button>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
</templates>
|
||||
|
||||
Reference in New Issue
Block a user