From d43b9633ec25d1d300735d2a32ae89fc4cd8527a Mon Sep 17 00:00:00 2001 From: Krzysztof Trzewiczek Date: Fri, 10 Aug 2012 12:29:24 +0200 Subject: [PATCH] [closes #182,view/multiview] Sidebar views moved to initialize options --- src/view.multiview.js | 59 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/src/view.multiview.js b/src/view.multiview.js index 3168689b..cdc8c268 100644 --- a/src/view.multiview.js +++ b/src/view.multiview.js @@ -50,6 +50,30 @@ this.recline.View = this.recline.View || {}; // ]; // // +// **sidebarViews**: (optional) the sidebar views (Filters, Fields) for +// MultiView to show. This is an array of view hashes. If not provided +// initialize with (recline.View.)FilterEditor and Fields views (with obvious +// id and labels!). +// +//
+// var sidebarViews = [
+//   {
+//     id: 'filterEditor', // used for routing
+//     label: 'Filters', // used for view switcher
+//     view: new recline.View.FielterEditor({
+//       model: dataset
+//     })
+//   },
+//   {
+//     id: 'fieldsView',
+//     label: 'Fields',
+//     view: new recline.View.Fields({
+//       model: dataset
+//     })
+//   }
+// ];
+// 
+// // **state**: standard state config for this view. This state is slightly // special as it includes config of many of the subviews. // @@ -107,6 +131,7 @@ my.MultiView = Backbone.View.extend({ var self = this; this.el = $(this.el); this._setupState(options.state); + // Hash of 'page' views (i.e. those for whole page) keyed by page name if (options.views) { this.pageViews = options.views; @@ -147,6 +172,24 @@ my.MultiView = Backbone.View.extend({ }) }]; } + // Hashes of sidebar elements + if(options.sidebarViews) { + this.sidebarViews = options.sidebarViews; + } else { + this.sidebarViews = [{ + id: 'filterEditor', + label: 'Filters', + view: new my.FilterEditor({ + model: this.model + }) + }, { + id: 'fieldsView', + label: 'Fields', + view: new my.Fields({ + model: this.model + }) + }]; + } // these must be called after pageViews are created this.render(); this._bindStateChanges(); @@ -218,6 +261,11 @@ my.MultiView = Backbone.View.extend({ } }); + _.each(this.sidebarViews, function(view) { + this['$'+view.id] = view.view.el; + $dataSidebar.append(view.view.el); + }); + var pager = new recline.View.Pager({ model: this.model.queryState }); @@ -228,17 +276,6 @@ my.MultiView = Backbone.View.extend({ }); this.el.find('.query-editor-here').append(queryEditor.el); - var filterEditor = new recline.View.FilterEditor({ - model: this.model - }); - this.$filterEditor = filterEditor.el; - $dataSidebar.append(filterEditor.el); - - var fieldsView = new recline.View.Fields({ - model: this.model - }); - this.$fieldsView = fieldsView.el; - $dataSidebar.append(fieldsView.el); }, updateNav: function(pageName) {