[IMP] have the export dialog fetch possible export formats from the server
authorXavier Morel <xmo@openerp.com>
Tue, 30 Aug 2011 13:23:26 +0000 (15:23 +0200)
committerXavier Morel <xmo@openerp.com>
Tue, 30 Aug 2011 13:23:26 +0000 (15:23 +0200)
bzr revid: xmo@openerp.com-20110830132326-ac0f7xs3h1jr3a7j

addons/base/controllers/main.py
addons/base/static/src/js/data_export.js
addons/base/static/src/xml/base.xml

index 5f39160..ab583d9 100644 (file)
@@ -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):
index 1823dbd..c555a3b 100644 (file)
@@ -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;
index d3e91f2..75593d6 100644 (file)
                 <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>