[IMP] allow export of selected records only
bzr revid: xmo@openerp.com-20130530100556-yidc2yyx8mm4au1q
This commit is contained in:
commit
890ea99146
|
@ -4,15 +4,34 @@ var QWeb = instance.web.qweb,
|
|||
instance.web.DataExport = instance.web.Dialog.extend({
|
||||
template: 'ExportTreeView',
|
||||
dialog_title: {toString: function () { return _t("Export Data"); }},
|
||||
events: {
|
||||
'click #add_field': function () {
|
||||
var self = this;
|
||||
this.$('#field-tree-structure tr.ui-selected')
|
||||
.removeClass('ui-selected')
|
||||
.find('a').each(function () {
|
||||
var id = $(this).attr('id').split('-')[1];
|
||||
var string = $(this).attr('string');
|
||||
self.add_field(id, string);
|
||||
});
|
||||
},
|
||||
'click #remove_field': function () {
|
||||
this.$('#fields_list option:selected').remove();
|
||||
},
|
||||
'click #remove_all_field': function () {
|
||||
this.$('#fields_list').empty();
|
||||
},
|
||||
'click #export_new_list': 'on_show_save_list',
|
||||
},
|
||||
init: function(parent, dataset) {
|
||||
var self = this;
|
||||
options = {
|
||||
buttons : [
|
||||
{text: _t("Close"), click: function() { self.close(); }},
|
||||
{text: _t("Export To File"), click: function() { self.on_click_export_data(); }}
|
||||
var options = {
|
||||
buttons: [
|
||||
{text: _t("Close"), click: function () { self.close(); }},
|
||||
{text: _t("Export To File"), click: function () { self.on_click_export_data(); }}
|
||||
],
|
||||
close: function(event, ui){ self.close();}
|
||||
}
|
||||
close: function () { self.close();}
|
||||
};
|
||||
this._super(parent, options);
|
||||
this.records = {};
|
||||
this.dataset = dataset;
|
||||
|
@ -23,24 +42,6 @@ instance.web.DataExport = instance.web.Dialog.extend({
|
|||
var self = this;
|
||||
this._super.apply(this, arguments);
|
||||
self.$el.removeClass('ui-dialog-content ui-widget-content');
|
||||
self.$el.find('#add_field').click(function() {
|
||||
if ($('#field-tree-structure tr.ui-selected')) {
|
||||
var fld = self.$el.find('#field-tree-structure tr.ui-selected').find('a');
|
||||
for (var i = 0; i < fld.length; i++) {
|
||||
var id = $(fld[i]).attr('id').split('-')[1];
|
||||
var string = $(fld[i]).attr('string');
|
||||
self.add_field(id, string);
|
||||
}
|
||||
self.$el.find('#field-tree-structure tr').removeClass('ui-selected');
|
||||
}
|
||||
});
|
||||
self.$el.find('#remove_field').click(function() {
|
||||
self.$el.find('#fields_list option:selected').remove();
|
||||
});
|
||||
self.$el.find('#remove_all_field').click(function() {
|
||||
self.$el.find('#fields_list').empty();
|
||||
});
|
||||
this.$el.find('#export_new_list').click(this.on_show_save_list);
|
||||
|
||||
var got_fields = new $.Deferred();
|
||||
this.$el.find('#import_compat').change(function() {
|
||||
|
@ -49,7 +50,7 @@ instance.web.DataExport = instance.web.Dialog.extend({
|
|||
var import_comp = self.$el.find("#import_compat").val();
|
||||
self.rpc("/web/export/get_fields", {
|
||||
model: self.dataset.model,
|
||||
import_compat: Boolean(import_comp)
|
||||
import_compat: !!import_comp,
|
||||
}).done(function (records) {
|
||||
got_fields.resolve();
|
||||
self.on_show_data(records);
|
||||
|
@ -79,7 +80,7 @@ instance.web.DataExport = instance.web.Dialog.extend({
|
|||
var self = this;
|
||||
if (self.$el.find('#saved_export_list').is(':hidden')) {
|
||||
self.$el.find('#ExistsExportList').show();
|
||||
return;
|
||||
return $.when();
|
||||
}
|
||||
return this.exports.read_slice(['name'], {
|
||||
domain: [['resource', '=', this.dataset.model]]
|
||||
|
@ -192,7 +193,6 @@ instance.web.DataExport = instance.web.Dialog.extend({
|
|||
},
|
||||
on_show_data: function(result, after) {
|
||||
var self = this;
|
||||
var imp_cmpt = Boolean(self.$el.find("#import_compat").val());
|
||||
|
||||
if (after) {
|
||||
var current_tr = self.$el.find("tr[id='treerow-" + after + "']");
|
||||
|
@ -220,15 +220,16 @@ instance.web.DataExport = instance.web.Dialog.extend({
|
|||
frst_click = self.$el.find("tr[id^='treerow-']")[self.row_index-1];
|
||||
$(frst_click).addClass("ui-selected");
|
||||
} else {
|
||||
var i;
|
||||
if (this.rowIndex >=self.row_index) {
|
||||
for (var i = (self.row_index-1); i < this.rowIndex; i++) {
|
||||
for (i = (self.row_index-1); i < this.rowIndex; i++) {
|
||||
scnd_click = self.$el.find("tr[id^='treerow-']")[i];
|
||||
if (!$(scnd_click).find('#tree-column').hasClass("oe_export_readonlyfield")) {
|
||||
$(scnd_click).addClass("ui-selected");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var i = (self.row_index-1); i >= (this.rowIndex-1); i--) {
|
||||
for (i = (self.row_index-1); i >= (this.rowIndex-1); i--) {
|
||||
scnd_click = self.$el.find("tr[id^='treerow-']")[i];
|
||||
if (!$(scnd_click).find('#tree-column').hasClass("oe_export_readonlyfield")) {
|
||||
$(scnd_click).addClass("ui-selected");
|
||||
|
@ -263,6 +264,7 @@ instance.web.DataExport = instance.web.Dialog.extend({
|
|||
self.$el.find("tr[id='treerow-" + record.id + "']").keydown(function(e) {
|
||||
var keyCode = e.keyCode || e.which;
|
||||
var arrow = {left: 37, up: 38, right: 39, down: 40 };
|
||||
var elem;
|
||||
switch (keyCode) {
|
||||
case arrow.left:
|
||||
if ($(this).hasClass('open')) {
|
||||
|
@ -275,7 +277,7 @@ instance.web.DataExport = instance.web.Dialog.extend({
|
|||
}
|
||||
break;
|
||||
case arrow.up:
|
||||
var elem = this;
|
||||
elem = this;
|
||||
$(elem).removeClass("ui-selected");
|
||||
while (!$(elem).prev().is(":visible")) {
|
||||
elem = $(elem).prev();
|
||||
|
@ -286,7 +288,7 @@ instance.web.DataExport = instance.web.Dialog.extend({
|
|||
$(elem).prev().find('a').focus();
|
||||
break;
|
||||
case arrow.down:
|
||||
var elem = this;
|
||||
elem = this;
|
||||
$(elem).removeClass("ui-selected");
|
||||
while(!$(elem).next().is(":visible")) {
|
||||
elem = $(elem).next();
|
||||
|
@ -353,14 +355,13 @@ instance.web.DataExport = instance.web.Dialog.extend({
|
|||
}
|
||||
},
|
||||
get_fields: function() {
|
||||
var export_field = [];
|
||||
this.$el.find("#fields_list option").each(function() {
|
||||
export_field.push($(this).val());
|
||||
});
|
||||
if (!export_field.length) {
|
||||
var export_fields = this.$("#fields_list option").map(function() {
|
||||
return $(this).val();
|
||||
}).get();
|
||||
if (!export_fields.length) {
|
||||
alert(_t("Please select fields to save export list..."));
|
||||
}
|
||||
return export_field;
|
||||
return export_fields;
|
||||
},
|
||||
on_click_export_data: function() {
|
||||
var self = this;
|
||||
|
@ -374,21 +375,24 @@ instance.web.DataExport = instance.web.Dialog.extend({
|
|||
alert(_t("Please select fields to export..."));
|
||||
return;
|
||||
}
|
||||
|
||||
exported_fields.unshift({name: 'id', label: 'External ID'});
|
||||
|
||||
var export_format = this.$el.find("#export_format").val();
|
||||
var ids_to_export = this.$('#export_selection_only').prop('checked')
|
||||
? this.getParent().get_selected_ids()
|
||||
: this.dataset.ids;
|
||||
|
||||
instance.web.blockUI();
|
||||
this.session.get_file({
|
||||
url: '/web/export/' + export_format,
|
||||
data: {data: JSON.stringify({
|
||||
model: this.dataset.model,
|
||||
fields: exported_fields,
|
||||
ids: this.dataset.ids,
|
||||
ids: ids_to_export,
|
||||
domain: this.dataset.domain,
|
||||
import_compat: Boolean(
|
||||
this.$el.find("#import_compat").val())
|
||||
import_compat: !!this.$el.find("#import_compat").val(),
|
||||
})},
|
||||
complete: instance.web.unblockUI
|
||||
complete: instance.web.unblockUI,
|
||||
});
|
||||
},
|
||||
close: function() {
|
||||
|
|
|
@ -1699,6 +1699,9 @@
|
|||
|
||||
<label for="export_format">Export Formats</label>
|
||||
<select id="export_format" name="export_format"></select>
|
||||
|
||||
<label for="export_selection_only">Only export selection:</label>
|
||||
<input type="checkbox" id="export_selection_only"/>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
|
Loading…
Reference in New Issue