Use tab name for CSV Export/Import
issue7640 review48571002
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Use tab name in CSV Export/Import
|
||||
* Add bus management
|
||||
* Load custom CSS and Javascript
|
||||
* New icons
|
||||
|
||||
+7
-4
@@ -3362,10 +3362,13 @@
|
||||
}
|
||||
};
|
||||
|
||||
Sao.common.download_file = function(data, name) {
|
||||
var type = Sao.common.guess_mimetype(
|
||||
name ? name.split('.').pop() : undefined);
|
||||
var blob = new Blob([data], {type: type});
|
||||
Sao.common.download_file = function(data, name, options) {
|
||||
if (options === undefined) {
|
||||
var type = Sao.common.guess_mimetype(
|
||||
name ? name.split('.').pop() : undefined);
|
||||
options = {type: type};
|
||||
}
|
||||
var blob = new Blob([data], options);
|
||||
|
||||
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
|
||||
window.navigator.msSaveOrOpenBlob(blob, name);
|
||||
|
||||
+3
-2
@@ -999,7 +999,8 @@
|
||||
}.bind(this));
|
||||
},
|
||||
export: function(){
|
||||
new Sao.Window.Export(this.screen,
|
||||
new Sao.Window.Export(
|
||||
this.title.text(), this.screen,
|
||||
this.screen.current_view.selected_records().map(function(r) {
|
||||
return r.id;
|
||||
}),
|
||||
@@ -1007,7 +1008,7 @@
|
||||
this.screen.context());
|
||||
},
|
||||
import: function(){
|
||||
new Sao.Window.Import(this.screen);
|
||||
new Sao.Window.Import(this.title.text(), this.screen);
|
||||
},
|
||||
get_url: function() {
|
||||
return this.screen.get_url(this.attributes.name);
|
||||
|
||||
+8
-12
@@ -1011,13 +1011,14 @@
|
||||
});
|
||||
|
||||
Sao.Window.Import = Sao.class_(Sao.Window.CSV, {
|
||||
init: function(screen) {
|
||||
init: function(name, screen) {
|
||||
this.name = name;
|
||||
this.screen = screen;
|
||||
this.session = Sao.Session.current_session;
|
||||
this.fields_data = {}; // Ask before Removing this.
|
||||
this.fields_invert = {};
|
||||
Sao.Window.Import._super.init.call(this,
|
||||
Sao.i18n.gettext('Import from CSV'));
|
||||
Sao.i18n.gettext('CSV Import: %1', name));
|
||||
|
||||
jQuery('<button/>', {
|
||||
'class': 'btn btn-default btn-block',
|
||||
@@ -1313,13 +1314,14 @@
|
||||
});
|
||||
|
||||
Sao.Window.Export = Sao.class_(Sao.Window.CSV, {
|
||||
init: function(screen, ids, names, context) {
|
||||
init: function(name, screen, ids, names, context) {
|
||||
this.name = name;
|
||||
this.ids = ids;
|
||||
this.screen = screen;
|
||||
this.session = Sao.Session.current_session;
|
||||
this.context = context;
|
||||
Sao.Window.Export._super.init.call(this,
|
||||
Sao.i18n.gettext('Export to CSV')).then(function() {
|
||||
Sao.i18n.gettext('CSV Export: %1',name)).then(function() {
|
||||
var fields = this.screen.model.fields;
|
||||
names.forEach(function(name) {
|
||||
var type = fields[name].description.type;
|
||||
@@ -1716,14 +1718,8 @@
|
||||
quoteChar: this.el_csv_quotechar.val(),
|
||||
delimiter: this.el_csv_delimiter.val()
|
||||
});
|
||||
var blob = new Blob([csv], {type: 'text/csv;charset=' + encoding});
|
||||
var blob_url = window.URL.createObjectURL(blob);
|
||||
if (this.blob_url) {
|
||||
window.URL.revokeObjectURL(this.blob_url);
|
||||
}
|
||||
this.blob_url = blob_url;
|
||||
window.open(blob_url);
|
||||
|
||||
Sao.common.download_file(
|
||||
csv, this.name + '.csv', {type: 'text/csv;charset=' + encoding});
|
||||
return Sao.common.message.run(
|
||||
Sao.i18n.ngettext('%1 record saved', '%1 records saved',
|
||||
data.length));
|
||||
|
||||
Reference in New Issue
Block a user