[IMP] have the export dialog fetch possible export formats from the server
bzr revid: xmo@openerp.com-20110830132326-ac0f7xs3h1jr3a7j
This commit is contained in:
parent
c276c2d67c
commit
9df1318f4f
|
@ -1066,6 +1066,20 @@ class TreeView(View):
|
|||
class Export(View):
|
||||
_cp_path = "/base/export"
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def formats(self, req):
|
||||
""" Returns all valid export formats
|
||||
|
||||
:returns: for each export format, a pair of identifier and printable name
|
||||
:rtype: [(str, str)]
|
||||
"""
|
||||
return sorted([
|
||||
controller.fmt
|
||||
for path, controller in openerpweb.controllers_path.iteritems()
|
||||
if path.startswith(self._cp_path)
|
||||
if hasattr(controller, 'fmt')
|
||||
], key=operator.itemgetter(1))
|
||||
|
||||
def fields_get(self, req, model):
|
||||
Model = req.session.model(model)
|
||||
fields = Model.fields_get(False, req.session.eval_context(req.context))
|
||||
|
@ -1236,6 +1250,7 @@ class Export(View):
|
|||
|
||||
class CSVExport(Export):
|
||||
_cp_path = '/base/export/csv'
|
||||
fmt = ('csv', 'CSV')
|
||||
|
||||
@property
|
||||
def content_type(self):
|
||||
|
@ -1270,6 +1285,7 @@ class CSVExport(Export):
|
|||
|
||||
class ExcelExport(Export):
|
||||
_cp_path = '/base/export/xls'
|
||||
fmt = ('xls', 'Excel')
|
||||
|
||||
@property
|
||||
def content_type(self):
|
||||
|
|
|
@ -65,6 +65,15 @@ openerp.base.DataExport = openerp.base.Dialog.extend({
|
|||
self.rpc("/base/export/get_fields", { model: self.dataset.model, params: params}, self.on_show_data);
|
||||
}
|
||||
});
|
||||
self.rpc('/base/export/formats', {}, function (formats) {
|
||||
self.setup_export_formats(formats);
|
||||
});
|
||||
},
|
||||
setup_export_formats: function (formats) {
|
||||
var $fmts = this.$element.find('#export_format');
|
||||
_(formats).each(function (format) {
|
||||
$fmts.append(new Option(format[1], format[0]));
|
||||
});
|
||||
},
|
||||
on_show_exists_export_list: function() {
|
||||
var self = this;
|
||||
|
|
|
@ -1237,11 +1237,8 @@
|
|||
<option value="0">Export all Data</option>
|
||||
</select>
|
||||
|
||||
<label for="export_format">Export Format</label>
|
||||
<select id="export_format" name="export_format">
|
||||
<option value="csv">CSV</option>
|
||||
<option value="xls">Excel</option>
|
||||
</select>
|
||||
<label for="export_format">Export Formats</label>
|
||||
<select id="export_format" name="export_format"></select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
|
Loading…
Reference in New Issue