diff options
| author | Xavier Morel <xmo@openerp.com> | 2011-09-23 14:22:02 +0200 |
|---|---|---|
| committer | Xavier Morel <xmo@openerp.com> | 2011-09-23 14:22:02 +0200 |
| commit | 25c38ca653ff24773f68e2dbd90310a13c247786 (patch) | |
| tree | 09222aa4da0d07f7f12c8f13d0b131c8b6c23a8d /addons/web/static/src/js/data_import.js | |
| parent | 633c27ab79e5aa007da06f06c878cc5d99606e47 (diff) | |
[IMP] move more import logic to javascript
bzr revid: xmo@openerp.com-20110923122202-hnp6o1ybwgugive4
Diffstat (limited to 'addons/web/static/src/js/data_import.js')
| -rw-r--r-- | addons/web/static/src/js/data_import.js | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/addons/web/static/src/js/data_import.js b/addons/web/static/src/js/data_import.js index c62901e4795..70cb9ef9755 100644 --- a/addons/web/static/src/js/data_import.js +++ b/addons/web/static/src/js/data_import.js @@ -14,14 +14,18 @@ var QWeb = openerp.web.qweb; * @param {Function} callback function to call with the returned data */ function jsonp(form, attributes, callback) { + attributes = attributes || {}; var options = {jsonp: _.uniqueId('import_callback_')}; window[options.jsonp] = function () { delete window[options.jsonp]; callback.apply(null, arguments); }; - $(form).ajaxSubmit(_.extend({ - data: options - }, attributes)); + if ('data' in attributes) { + _.extend(attributes.data, options); + } else { + _.extend(attributes, {data: options}); + } + $(form).ajaxSubmit(attributes); } openerp.web.DataImport = openerp.web.Dialog.extend({ @@ -113,8 +117,31 @@ openerp.web.DataImport = openerp.web.Dialog.extend({ }, do_import: function() { if(!this.$element.find('#csvfile').val()) { return; } + var lines_to_skip = parseInt(this.$element.find('#csv_skip').val(), 10); + var with_headers = this.$element.find('#file_has_headers').prop('checked'); + if (!lines_to_skip && with_headers) { + lines_to_skip = 1; + } + var indices = [], fields = []; + this.$element.find(".sel_fields").each(function(index, element) { + var val = element.value; + if (!val) { + return; + } + indices.push(index); + fields.push(val); + }); + jsonp(this.$element.find('#import_data'), { - url: '/web/import/import_data' + url: '/web/import/import_data', + data: { + model: this.model, + meta: JSON.stringify({ + skip: lines_to_skip, + indices: indices, + fields: fields + }) + } }, this.on_import_results); }, on_autodetect_data: function() { |
