|
@ -19,27 +19,28 @@ |
|
|
//
|
|
|
//
|
|
|
//#############################################################################
|
|
|
//#############################################################################
|
|
|
|
|
|
|
|
|
openerp.web_export_view = function(instance, m) { |
|
|
|
|
|
|
|
|
openerp.web_export_view = function (instance) { |
|
|
|
|
|
|
|
|
|
|
|
debugger; |
|
|
var _t = instance.web._t, |
|
|
var _t = instance.web._t, |
|
|
QWeb = instance.web.qweb; |
|
|
|
|
|
|
|
|
QWeb = instance.web.qweb; |
|
|
|
|
|
|
|
|
instance.web.Sidebar.include({ |
|
|
instance.web.Sidebar.include({ |
|
|
redraw: function() { |
|
|
|
|
|
|
|
|
redraw: function () { |
|
|
var self = this; |
|
|
var self = this; |
|
|
this._super.apply(this, arguments); |
|
|
this._super.apply(this, arguments); |
|
|
self.$el.find('.oe_sidebar').append(QWeb.render('AddExportViewMain', {widget: self})); |
|
|
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.$el.find('.oe_sidebar_export_view_xls').on('click', self.on_sidebar_export_view_xls); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
on_sidebar_export_view_xls: 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.getParent(), |
|
|
|
|
|
children = view.getChildren(); |
|
|
|
|
|
|
|
|
view = this.getParent(), |
|
|
|
|
|
children = view.getChildren(); |
|
|
if (children) { |
|
|
if (children) { |
|
|
children.every(function(child) { |
|
|
|
|
|
|
|
|
children.every(function (child) { |
|
|
if (child.field && child.field.type == 'one2many') { |
|
|
if (child.field && child.field.type == 'one2many') { |
|
|
view = child.viewmanager.views.list.controller; |
|
|
view = child.viewmanager.views.list.controller; |
|
|
return false; // break out of the loop
|
|
|
return false; // break out of the loop
|
|
@ -53,8 +54,8 @@ openerp.web_export_view = function(instance, m) { |
|
|
} |
|
|
} |
|
|
export_columns_keys = []; |
|
|
export_columns_keys = []; |
|
|
export_columns_names = []; |
|
|
export_columns_names = []; |
|
|
$.each(view.visible_columns, function(){ |
|
|
|
|
|
if(this.tag=='field'){ |
|
|
|
|
|
|
|
|
$.each(view.visible_columns, function () { |
|
|
|
|
|
if (this.tag == 'field') { |
|
|
// non-fields like `_group` or buttons
|
|
|
// non-fields like `_group` or buttons
|
|
|
export_columns_keys.push(this.id); |
|
|
export_columns_keys.push(this.id); |
|
|
export_columns_names.push(this.string); |
|
|
export_columns_names.push(this.string); |
|
@ -62,46 +63,47 @@ openerp.web_export_view = function(instance, m) { |
|
|
}); |
|
|
}); |
|
|
rows = view.$el.find('.oe_list_content > tbody > 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 = []; |
|
|
checked = $row.find('th input[type=checkbox]').attr("checked"); |
|
|
checked = $row.find('th input[type=checkbox]').attr("checked"); |
|
|
if (children && checked === "checked"){ |
|
|
|
|
|
$.each(export_columns_keys,function(){ |
|
|
|
|
|
cell = $row.find('td[data-field="'+this+'"]').get(0); |
|
|
|
|
|
|
|
|
if (children && checked === "checked") { |
|
|
|
|
|
$.each(export_columns_keys, function () { |
|
|
|
|
|
cell = $row.find('td[data-field="' + this + '"]').get(0); |
|
|
text = cell.text || cell.textContent || cell.innerHTML || ""; |
|
|
text = cell.text || cell.textContent || cell.innerHTML || ""; |
|
|
if (cell.classList.contains("oe_list_field_float")){ |
|
|
|
|
|
|
|
|
if (cell.classList.contains("oe_list_field_float")) { |
|
|
export_row.push(instance.web.parse_value(text, {'type': "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){ |
|
|
|
|
|
export_row.push(_t("True")); |
|
|
|
|
|
|
|
|
else if (cell.classList.contains("oe_list_field_boolean")) { |
|
|
|
|
|
var data_id = $('<div>' + cell.innerHTML + '</div>'); |
|
|
|
|
|
if (data_id.find('input').get(0).checked) { |
|
|
|
|
|
export_row.push(_t("True")); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
export_row.push(_t("False")); |
|
|
|
|
|
|
|
|
export_row.push(_t("False")); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else if (cell.classList.contains("oe_list_field_integer")){ |
|
|
|
|
|
export_row.push(parseInt(text)); |
|
|
|
|
|
|
|
|
else if (cell.classList.contains("oe_list_field_integer")) { |
|
|
|
|
|
export_row.push(parseInt(text)); |
|
|
} |
|
|
} |
|
|
else{ |
|
|
|
|
|
export_row.push(text.trim()); |
|
|
|
|
|
|
|
|
else { |
|
|
|
|
|
export_row.push(text.trim()); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
export_rows.push(export_row); |
|
|
export_rows.push(export_row); |
|
|
}; |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
; |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
$.blockUI(); |
|
|
$.blockUI(); |
|
|
view.session.get_file({ |
|
|
view.session.get_file({ |
|
|
url: '/web/export/xls_view', |
|
|
url: '/web/export/xls_view', |
|
|
data: {data: JSON.stringify({ |
|
|
data: {data: JSON.stringify({ |
|
|
model : view.model, |
|
|
|
|
|
headers : export_columns_names, |
|
|
|
|
|
rows : export_rows, |
|
|
|
|
|
|
|
|
model: view.model, |
|
|
|
|
|
headers: export_columns_names, |
|
|
|
|
|
rows: export_rows, |
|
|
})}, |
|
|
})}, |
|
|
complete: $.unblockUI |
|
|
complete: $.unblockUI |
|
|
}); |
|
|
}); |