Browse Source

[11.0][IMP] web_export_view: Linter

pull/1272/merge
Alexandre Díaz 6 years ago
committed by Dennis Sluijk
parent
commit
47c968b250
  1. 134
      web_export_view/static/src/js/web_export_view.js

134
web_export_view/static/src/js/web_export_view.js

@ -1,5 +1,5 @@
odoo.define('web_export_view', function (require) {
"use strict";
"use strict";
var core = require('web.core');
var Sidebar = require('web.Sidebar');
@ -15,33 +15,37 @@ odoo.define('web_export_view', function (require) {
_redraw: function () {
var self = this;
this._super.apply(this, arguments);
if (self.getParent().renderer.viewType == 'list') {
session.user_has_group('web_export_view.group_disallow_export_view_data_excel').then(function (has_group) {
if (!has_group) {
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);
}
});
if (self.getParent().renderer.viewType === 'list') {
session.user_has_group(
'web_export_view.group_disallow_export_view_data_excel')
.then(function (has_group) {
if (!has_group) {
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_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,
view = this.getParent(),
var view = this.getParent(),
children = view.getChildren();
var c = crash_manager;
if (children) {
children.every(function (child) {
if (child.field && child.field.type == 'one2many') {
if (child.field && child.field.type === 'one2many') {
view = child.viewmanager.views.list.controller;
return false; // break out of the loop
return false;
}
if (child.field && child.field.type == 'many2many') {
if (child.field && child.field.type === 'many2many') {
view = child.list_view;
return false; // break out of the loop
return false;
}
return true;
});
@ -52,70 +56,80 @@ odoo.define('web_export_view', function (require) {
var column_header_selector = '';
var isGrouped = view.renderer.state.groupedBy.length > 0;
$.each(view.renderer.columns, function () {
if (this.tag == 'field' && (this.attrs.widget === undefined || this.attrs.widget != 'handle')) {
// non-fields like `_group` or buttons
if (this.tag === 'field' &&
(this.attrs.widget === undefined ||
this.attrs.widget !== 'handle')) {
export_columns_keys.push(column_index);
var css_selector_index = isGrouped
? column_index+1 : column_index;
column_header_selector = '.o_list_view > thead > tr> th:not([class*="o_list_record_selector"]):eq('+css_selector_index+')';
export_columns_names.push(view.$el.find(column_header_selector)[0].textContent);
column_header_selector = '.o_list_view > thead > tr> ' +
'th:not([class*="o_list_record_selector"]):eq(' +
css_selector_index + ')';
export_columns_names.push(
view.$el.find(column_header_selector)[0].textContent);
}
++column_index;
});
var export_rows = [];
$.blockUI();
if (children) {
// find only rows with data
view.$el.find('.o_list_view > tbody > tr.o_data_row:has(.o_list_record_selector input:checkbox:checked)')
.each(function () {
var $row = $(this);
var export_row = [];
$.each(export_columns_keys, function () {
var $cell = $row.find('td.o_data_cell:eq('+this+')')
var $cellcheckbox = $cell.find('.o_checkbox input:checkbox');
if ($cellcheckbox.length) {
export_row.push(
$cellcheckbox.is(":checked")
? _t("True") : _t("False")
);
}
else {
var text = $cell.text().trim();
var is_number = (
$cell.hasClass('o_list_number') &&
!$cell.hasClass('o_float_time_cell')
);
if (is_number) {
export_row.push(parseFloat(
text
// Remove thousands separator
.split(_t.database.parameters.thousands_sep)
.join("")
// Always use a `.` as decimal separator
.replace(_t.database.parameters.decimal_point, ".")
// Remove non-numeric characters
.replace(/[^\d\.-]/g, "")
));
// Find only rows with data
view.$el.find('.o_list_view > tbody > tr.o_data_row:' +
'has(.o_list_record_selector input:checkbox:checked)')
.each(function () {
var $row = $(this);
var export_row = [];
$.each(export_columns_keys, function () {
var $cell = $row.find(
'td.o_data_cell:eq('+this+')');
var $cellcheckbox = $cell.find(
'.o_checkbox input:checkbox');
if ($cellcheckbox.length) {
export_row.push(
$cellcheckbox.is(":checked")
? _t("True") : _t("False")
);
} else {
export_row.push(text);
var text = $cell.text().trim();
var is_number =
$cell.hasClass('o_list_number') &&
!$cell.hasClass('o_float_time_cell');
if (is_number) {
var db_params = _t.database.parameters;
export_row.push(parseFloat(
text
// Remove thousands separator
.split(db_params.thousands_sep)
.join("")
// Always use a `.` as decimal
// separator
.replace(db_params.decimal_point,
".")
// Remove non-numeric characters
.replace(/[^\d.-]/g, "")
));
} else {
export_row.push(text);
}
}
}
});
export_rows.push(export_row);
});
export_rows.push(export_row);
});
}
session.get_file({
url: '/web/export/xls_view',
data: {data: JSON.stringify({
model: view.modelName,
headers: export_columns_names,
rows: export_rows
})},
data: {
data: JSON.stringify({
model: view.modelName,
headers: export_columns_names,
rows: export_rows,
}),
},
complete: $.unblockUI,
error: c.rpc_error.bind(c)
error: c.rpc_error.bind(c),
});
}
},
});
});
Loading…
Cancel
Save