You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2014/08/12 15:21:13 UTC

[2/4] fauxton commit: updated refs/heads/backbone.layout-upgrade to 6f4e4f6

Upgrade backbone.layoutmanager

Work off Tim's initial commits and adjust to cater for the use of
establish functions in views and routeObjects.
We don't want to immediately render the view. We first want any pending
promises returned from a routeObjects establish and a view's establish
to complete before rendering the view.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/9738389f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/9738389f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/9738389f

Branch: refs/heads/backbone.layout-upgrade
Commit: 9738389f918c542df106ddb04fd47a3fb0a2c3c4
Parents: c48962c
Author: Garren Smith <ga...@gmail.com>
Authored: Mon Aug 11 12:06:21 2014 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Mon Aug 11 12:06:21 2014 +0200

----------------------------------------------------------------------
 app/core/layout.js      | 84 ++++++++++++++++++++++++++++++++++++++++++--
 app/core/routeObject.js | 11 ++++--
 2 files changed, 90 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/9738389f/app/core/layout.js
----------------------------------------------------------------------
diff --git a/app/core/layout.js b/app/core/layout.js
index 0a45e62..11992cb 100644
--- a/app/core/layout.js
+++ b/app/core/layout.js
@@ -10,7 +10,7 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-define(function(require, exports, module) {
+/*define(function(require, exports, module) {
   var Backbone = require("backbone");
   var LayoutManager = require("plugins/backbone.layoutmanager");
 
@@ -19,7 +19,7 @@ define(function(require, exports, module) {
 
     // Either tests or source are expecting synchronous renders, so disable
     // asynchronous rendering improvements.
-    useRAF: false,
+    useRAF: true,
 
     setTemplate: function(template) {
       if (template.prefix){
@@ -37,4 +37,84 @@ define(function(require, exports, module) {
 
   module.exports = Layout;
 
+});*/
+
+define([
+  "backbone", 
+  "plugins/backbone.layoutmanager"
+], function(Backbone) {
+
+  // A wrapper of the main Backbone.layoutmanager
+  // Allows the main layout of the page to be changed by any plugin.
+  var Layout = function () {
+    this.layout = new Backbone.Layout({
+      template: "templates/layouts/with_sidebar",
+    });
+
+    this.layoutViews = {};
+    this.el = this.layout.el;
+  };
+
+  Layout.configure = function (options) {
+    Backbone.Layout.configure(options);
+  };
+
+  // creatings the dashboard object same way backbone does
+  _.extend(Layout.prototype, {
+    render: function () {
+      return this.layout.render();
+    },
+
+    setTemplate: function(template) {
+      if (template.prefix){
+        this.layout.template = template.prefix + template.name;
+      } else{
+        this.layout.template = "templates/layouts/" + template;
+      }
+      // If we're changing layouts all bets are off, so kill off all the
+      // existing views in the layout.
+      _.each(this.layoutViews, function(view){view.removeView();});
+      this.layoutViews = {};
+      this.render();
+    },
+
+    setView: function(selector, view, keep) {
+      this.layout.setView(selector, view, false);
+
+      if (!keep) {
+        this.layoutViews[selector] = view;
+      }
+
+      return view;
+    },
+
+    renderView: function(selector) {
+      var view = this.layoutViews[selector];
+      if (!view) {
+        return false;
+      } else {
+        return view.render();
+      }
+    },
+
+    removeView: function (selector) {
+      var view = this.layout.getView(selector);
+
+      if (!view) {
+        return false;
+        }
+
+      this.layout.removeView(selector);
+      
+      if (this.layoutViews[selector]) {
+        delete this.layoutViews[selector];
+      }
+
+      return true;
+    }
+
+  });
+
+  return Layout;
+
 });

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/9738389f/app/core/routeObject.js
----------------------------------------------------------------------
diff --git a/app/core/routeObject.js b/app/core/routeObject.js
index f8a238f..898afcb 100644
--- a/app/core/routeObject.js
+++ b/app/core/routeObject.js
@@ -149,12 +149,17 @@ function(FauxtonAPI, Backbone) {
     },
 
     renderViewOnLayout: function(viewInfo, resp, xhr){
-      var masterLayout = viewInfo.masterLayout;
+      var masterLayout = viewInfo.masterLayout,
+          triggerBroadcast = _.bind(this.triggerBroadcast, this);
 
       masterLayout.setView(viewInfo.selector, viewInfo.view);
-      masterLayout.renderView(viewInfo.selector);
+      var promise = masterLayout.renderView(viewInfo.selector).promise();
 
-      this.triggerBroadcast('afterRender', viewInfo.view, viewInfo.selector);
+      promise.then(function () {
+        triggerBroadcast('afterRender', viewInfo.view, viewInfo.selector);
+      });
+
+      return promise;
     },
 
     establishError: function(resp){