couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [1/2] git commit: updated refs/heads/beforeunload to 476845d
Date Mon, 09 Dec 2013 12:52:21 GMT
Updated Branches:
  refs/heads/beforeunload [created] 476845d4f


first


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

Branch: refs/heads/beforeunload
Commit: c309e117c2ca67e619f0ba067b4d3f1296449553
Parents: f28dd6f
Author: Garren Smith <garren.smith@gmail.com>
Authored: Thu Dec 5 17:51:39 2013 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Mon Dec 9 10:49:44 2013 +0200

----------------------------------------------------------------------
 src/fauxton/app/api.js                        |  3 +++
 src/fauxton/app/main.js                       |  6 ++----
 src/fauxton/app/modules/documents/views.js    |  6 +++++-
 src/fauxton/app/modules/fauxton/components.js | 21 ++++++++++++++++++++-
 src/fauxton/app/router.js                     | 10 ++++++++++
 src/fauxton/tasks/fauxton.js                  |  2 +-
 6 files changed, 41 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/c309e117/src/fauxton/app/api.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/api.js b/src/fauxton/app/api.js
index a71c5f8..f305c33 100644
--- a/src/fauxton/app/api.js
+++ b/src/fauxton/app/api.js
@@ -61,6 +61,9 @@ function(app, Fauxton) {
     app.router.navigate(url,options);
   };
 
+  FauxtonAPI.beforeUnload = app.router.beforeUnload;
+  FauxtonAPI.removeBeforeUnload = app.router.removeBeforeUnload;
+
   FauxtonAPI.addHeaderLink = function(link) {
     app.masterLayout.navBar.addLink(link);
   };

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c309e117/src/fauxton/app/main.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/main.js b/src/fauxton/app/main.js
index 2182f2c..6fe9991 100644
--- a/src/fauxton/app/main.js
+++ b/src/fauxton/app/main.js
@@ -40,10 +40,8 @@ function(app, Router) {
       // refresh.
       evt.preventDefault();
 
-      // `Backbone.history.navigate` is sufficient for all Routers and will
-      // trigger the correct events. The Router's internal `navigate` method
-      // calls this anyways.  The fragment is sliced from the root.
-      Backbone.history.navigate(href.attr, true);
+      //User app navigate so that navigate goes through a central place
+      app.router.navigate(href.attr, true);
     }
 
   });

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c309e117/src/fauxton/app/modules/documents/views.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/views.js b/src/fauxton/app/modules/documents/views.js
index af3c4c3..a7f1824 100644
--- a/src/fauxton/app/modules/documents/views.js
+++ b/src/fauxton/app/modules/documents/views.js
@@ -715,7 +715,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
       _.bindAll(this);
     },
     goback: function(){
-      window.history.back();
+      FauxtonAPI.navigate(this.database.url("index") + "?limit=100");
     },
     destroy: function(event) {
       if (this.model.isNewDoc()) {
@@ -906,6 +906,10 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
resizeColum
       });
       this.editor.render();
       this.model.on("sync", this.updateValues, this);
+    },
+
+    cleanup: function () {
+      this.editor.remove();
     }
   });
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c309e117/src/fauxton/app/modules/fauxton/components.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/fauxton/components.js b/src/fauxton/app/modules/fauxton/components.js
index bcc9226..7248010 100644
--- a/src/fauxton/app/modules/fauxton/components.js
+++ b/src/fauxton/app/modules/fauxton/components.js
@@ -207,6 +207,7 @@ function(app, FauxtonAPI, ace) {
       this.commands = options.commands;
       this.theme = options.theme || 'crimson_editor';
       this.couchJSHINT = options.couchJSHINT;
+      this.edited = false;
     },
 
     afterRender: function () {
@@ -224,10 +225,28 @@ function(app, FauxtonAPI, ace) {
       }
 
       var that = this;
-
       this.editor.getSession().on('change', function () {
         that.setHeightToLineCount();
+        that.edited = true;
+        console.log('edited');
       });
+
+      $(window).on('beforeunload.editor', function() {
+        if (that.edited) {
+          return 'Your changes have not been saved. Click cancel to return to the document.';
+        }
+      });
+
+      api.beforeUnload("editor", function (deferred) {
+        if (that.edited) {
+          return 'Your changes have not been saved. Click cancel to return to the document.');
+        }
+      });
+    },
+
+    cleanup: function () {
+      $(window).off('beforeunload.editor');
+      api.removeBeforeunload("editor");
     },
 
     setHeightToLineCount: function () {

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c309e117/src/fauxton/app/router.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/router.js b/src/fauxton/app/router.js
index 9dac80c..3d8b125 100644
--- a/src/fauxton/app/router.js
+++ b/src/fauxton/app/router.js
@@ -47,9 +47,19 @@ function(req, app, Initialize, FauxtonAPI, Fauxton, Layout, Databases,
Documents
   // TODO: auto generate this list if possible
   var modules = [Databases, Documents];
 
+  var beforeUnloads = {};
+
   var Router = app.router = Backbone.Router.extend({
     routes: {},
 
+    beforeUnload: function (name, fn) {
+      beforeUnload[name] = fn;
+    },
+
+    navigate: function (fragment, trigger) {
+      Backbone.Router.prototype.navigate(fragment, trigger);
+    },
+
     addModuleRouteObject: function(RouteObject) {
       var that = this;
       var masterLayout = this.masterLayout,

http://git-wip-us.apache.org/repos/asf/couchdb/blob/c309e117/src/fauxton/tasks/fauxton.js
----------------------------------------------------------------------
diff --git a/src/fauxton/tasks/fauxton.js b/src/fauxton/tasks/fauxton.js
index bb68ddb..e54bab8 100644
--- a/src/fauxton/tasks/fauxton.js
+++ b/src/fauxton/tasks/fauxton.js
@@ -102,7 +102,7 @@ module.exports = function(grunt) {
 
     _.defaults(app, settings.app, {
       root: '/',
-      host: '../../',
+      host: '../..',
       version: "0.0"
     });
 


Mime
View raw message