Permalink
Browse files

Number format for CSV output is now adjustable through config.json.

  • Loading branch information...
1 parent a1629cb commit 1441071a867c3d173647a6119b4b470828c46cdc Michael Aufreiter committed Jun 20, 2011
Showing with 15 additions and 6 deletions.
  1. +5 −5 public/javascripts/views/sheet.js
  2. +9 −0 server.js
  3. +1 −1 templates/app.html
@@ -265,24 +265,24 @@ var Sheet = Backbone.View.extend({
toCSV: function() {
var that = this;
function formatValue(text) {
- return /[";\n]/.test(text)
+ return new RegExp("[\";"+config.csv_separator+"\\n]").test(text)
? "\"" + text.replace(/\"/g, "\"\"") + "\""
: text;
}
var res = "";
// Headers
properties = this.groupedItems.properties().map(function(p) { return formatValue(p.name); }).values();
- res += properties.join(';')+"\n";
+ res += properties.join(config.csv_separator)+"\n";
// Items
this.groupedItems.items().each(function(item) {
var values = that.groupedItems.properties().map(function(p) {
- return formatValue(item.get(p.key));
+ return _.include(p.expectedTypes, "number") ? formatValue((item.get(p.key)+"").replace(".", ","))
+ : formatValue(item.get(p.key));
}).values();
- res += values.join(';')+"\n";
+ res += values.join(config.csv_separator)+"\n";
});
-
return res;
},
View
@@ -284,12 +284,21 @@ function findDatasources(req, callback) {
}
+function clientConfig() {
+ return {
+ "number_format": config.number_format,
+ "csv_separator": config.csv_separator
+ };
+}
+
+
// Routes
// -----------
app.get('/', function(req, res) {
html = fs.readFileSync(__dirname+ '/templates/app.html', 'utf-8');
res.send(html.replace('{{{{seed}}}}', JSON.stringify(seed))
+ .replace('{{{{config}}}}', JSON.stringify(clientConfig()))
.replace('{{{{session}}}}', JSON.stringify(req.session)));
});
View
@@ -7,6 +7,7 @@
<script>
var seed = {{{{seed}}}};
var session = {{{{session}}}};
+ var config = {{{{config}}}};
</script>
<script type="text/x-ejs-template" name="header">
@@ -54,7 +55,6 @@
<div class="user-name">
<%= username %> / <b><%= project_name %></b>
</div>
- <!--<input type="text" id="project_name" name="project_name" value="foo"/>-->
</script>
<script type="text/x-ejs-template" name="browser">

0 comments on commit 1441071

Please sign in to comment.