fixed the upper right menu and made it dynamic

The menu did not work because `this['$'+view.id]=...` was called with the wrong scope. Besides this fix, the template now looks at the actual `sidebarViews` array and renders the buttons dynamically.
This commit is contained in:
Felix Gnass
2012-08-23 14:29:22 +02:00
parent a7baa1739d
commit 831d656477

View File

@@ -111,8 +111,9 @@ my.MultiView = Backbone.View.extend({
</div> \ </div> \
<div class="menu-right"> \ <div class="menu-right"> \
<div class="btn-group" data-toggle="buttons-checkbox"> \ <div class="btn-group" data-toggle="buttons-checkbox"> \
<a href="#" class="btn active" data-action="filters">Filters</a> \ {{#sidebarViews}} \
<a href="#" class="btn active" data-action="fields">Fields</a> \ <a href="#" data-action="{{id}}" class="btn active">{{label}}</a> \
{{/sidebarViews}} \
</div> \ </div> \
</div> \ </div> \
<div class="query-editor-here" style="display:inline;"></div> \ <div class="query-editor-here" style="display:inline;"></div> \
@@ -246,6 +247,7 @@ my.MultiView = Backbone.View.extend({
render: function() { render: function() {
var tmplData = this.model.toTemplateJSON(); var tmplData = this.model.toTemplateJSON();
tmplData.views = this.pageViews; tmplData.views = this.pageViews;
tmplData.sidebarViews = this.sidebarViews;
var template = Mustache.render(this.template, tmplData); var template = Mustache.render(this.template, tmplData);
$(this.el).html(template); $(this.el).html(template);
@@ -265,7 +267,7 @@ my.MultiView = Backbone.View.extend({
_.each(this.sidebarViews, function(view) { _.each(this.sidebarViews, function(view) {
this['$'+view.id] = view.view.el; this['$'+view.id] = view.view.el;
$dataSidebar.append(view.view.el); $dataSidebar.append(view.view.el);
}); }, this);
var pager = new recline.View.Pager({ var pager = new recline.View.Pager({
model: this.model.queryState model: this.model.queryState
@@ -308,13 +310,7 @@ my.MultiView = Backbone.View.extend({
_onMenuClick: function(e) { _onMenuClick: function(e) {
e.preventDefault(); e.preventDefault();
var action = $(e.target).attr('data-action'); var action = $(e.target).attr('data-action');
if (action === 'filters') { this['$'+action].toggle();
this.$filterEditor.toggle();
} else if (action === 'fields') {
this.$fieldsView.toggle();
} else if (action === 'transform') {
this.transformView.el.toggle();
}
}, },
_onSwitchView: function(e) { _onSwitchView: function(e) {