Browse Source

[FIX]-web_export_view: change the js content, create a new item section

pull/461/head
Rodney Vargas 9 years ago
committed by Simone Orsi
parent
commit
d87d629e5c
  1. 3
      web_export_view/__openerp__.py
  2. 54
      web_export_view/static/src/js/web_export_view.js
  3. 12
      web_export_view/static/src/xml/web_export_view_template.xml

3
web_export_view/__openerp__.py

@ -16,9 +16,6 @@
'data': [
'view/web_export_view.xml',
],
'qweb': [
'static/src/xml/web_export_view_template.xml',
],
'installable': True,
'auto_install': False,
}

54
web_export_view/static/src/js/web_export_view.js

@ -3,20 +3,37 @@
//# © 2012 Therp BV
//# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
openerp.web_export_view = function (instance) {
odoo.define('web_export_view.Sidebar', function (require) {
"use strict";
var _t = instance.web._t, QWeb = instance.web.qweb;
var core = require('web.core');
var Sidebar = require('web.Sidebar');
instance.web.Sidebar.include({
redraw: function () {
var _t = core._t;
Sidebar.include({
init: function () {
var self = this;
this._super.apply(this, arguments);
if (self.getParent().ViewManager.active_view.type == '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);
self.sections.push({
name: 'export_current_view',
label: _t('Export Current View')
});
self.items['export_current_view'] = [];
var view = self.getParent();
if (view.fields_view && view.fields_view.type === "tree") {
self.web_export_add_items();
}
},
web_export_add_items: function () {
var self = this;
self.add_items('export_current_view', [{
label: 'Excel',
callback: self.on_sidebar_export_view_xls,
},]);
},
on_sidebar_export_view_xls: function () {
// Select the first list of the current (form) view
// or assume the main view is a list view and use that
@ -36,8 +53,8 @@ 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') {
// non-fields like `_group` or buttons
@ -45,18 +62,18 @@ openerp.web_export_view = function (instance) {
export_columns_names.push(this.string);
}
});
rows = view.$el.find('.oe_list_content > tbody > tr');
export_rows = [];
var rows = view.$el.find('.oe_list_content > 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]').is(':checked');
var export_row = [];
var checked = $row.find('th 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 || "";
var cell = $row.find('td[data-field="' + this + '"]').get(0);
var 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"}));
}
@ -96,7 +113,8 @@ openerp.web_export_view = function (instance) {
})},
complete: $.unblockUI
});
}
},
});
});
};

12
web_export_view/static/src/xml/web_export_view_template.xml

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="AddExportViewMain">
<div class="oe_form_dropdown_section btn-group btn-group-sm">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button">Export Current View</button>
<ul class="dropdown-menu" role="menu">
<li class="oe_sidebar_export_view_xls"><span>Excel</span></li>
</ul>
</div>
</t>
</templates>
Loading…
Cancel
Save