couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [11/13] fauxton commit: updated refs/heads/backbone.layout-upgrade to 755eb7a
Date Tue, 12 Aug 2014 14:56:19 GMT
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/09805dd9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/09805dd9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/09805dd9

Branch: refs/heads/backbone.layout-upgrade
Commit: 09805dd97406b0ec11fb2af7eb2ff0983816f59f
Parents: 3d1dd84
Author: Garren Smith <garren.smith@gmail.com>
Authored: Mon Aug 11 12:06:21 2014 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Tue Aug 12 16:49:56 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/09805dd9/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/09805dd9/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){


Mime
View raw message