Skip to content

Commit

Permalink
Add 'toggle editor' button
Browse files Browse the repository at this point in the history
  • Loading branch information
timwis committed Jan 6, 2016
1 parent 7876ece commit 4608667
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
11 changes: 9 additions & 2 deletions app/views/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = Backbone.View.extend({

// Events from sidebar
this.listenTo(this.sidebar, 'destroy', this.destroy);
this.listenTo(this.sidebar, 'toggle-editor', this.toggleEditor);
this.listenTo(this.sidebar, 'draft', this.draft);
this.listenTo(this.sidebar, 'cancel', this.cancel);
this.listenTo(this.sidebar, 'confirm', this.updateFile);
Expand Down Expand Up @@ -308,6 +309,11 @@ module.exports = Backbone.View.extend({
return _.escape(content);
},

toggleEditor: function() {
this.disableCSVEditor = !this.disableCSVEditor;
this.render();
},

parseCSV: function(csvString) {
return Papa.parse(util.trim(csvString), { // remove trailing whitespace, mholt/PapaParse#279
skipEmptyLines: true
Expand Down Expand Up @@ -554,7 +560,8 @@ module.exports = Backbone.View.extend({

var file = {
markdown: this.model.get('markdown'),
lang: this.model.get('lang')
lang: this.model.get('lang'),
useCSVEditor: (['csv', 'tsv'].indexOf(this.model.get('lang')) !== -1 && !this.disableCSVEditor)
};

this.$el.empty().append(_.template(this.template, file, {
Expand All @@ -565,7 +572,7 @@ module.exports = Backbone.View.extend({
this.config = this.model.get('collection').config;

// initialize the subviews
if (['csv', 'tsv'].indexOf(this.model.get('lang')) !== -1) {
if (file.useCSVEditor) {
this.initCSVEditor();
} else {
this.initEditor();
Expand Down
1 change: 1 addition & 0 deletions app/views/sidebar/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = Backbone.View.extend({

events: {
'click a.delete': 'emit',
'click a.toggle-editor': 'emit',
'click a.translate': 'emit',
'click a.draft': 'emit',
'change input.filepath': 'setPath'
Expand Down
2 changes: 1 addition & 1 deletion templates/file.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h2><%= t('main.file.metaTitle') %><br />
</div>
</div>
<div id='drop' class='drop-mask'></div>
<% if (['csv', 'tsv'].indexOf(file.lang) !== -1) { %>
<% if (file.useCSVEditor) { %>
<div id='csv-container'>
<div id='csv'></div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions templates/sidebar/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ <h2 class='label'><%= t('sidebar.settings.title') %></h2>
<% } %>
<% }); %>
<% } %>

<% if (['csv', 'tsv'].indexOf(settings.lang) !== -1) { %>
<a class='toggle-editor button round' href='#' data-action='toggle-editor'><%= t('sidebar.settings.toggleEditor') %></a>
<% } %>

<!-- if !isNew() and is writable -->
<a class='delete button round' href='#' data-action='destroy'><%= t('sidebar.settings.delete') %></a>
Expand Down
3 changes: 2 additions & 1 deletion translations/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@
"fileInputLabel": "File Path",
"delete": "Delete This File",
"translate": "Translate to",
"draft": "Create Draft"
"draft": "Create Draft",
"toggleEditor": "Toggle Editor"
}
},
"dialogs": {
Expand Down

0 comments on commit 4608667

Please sign in to comment.